Skip to content

Commit 1f112ce

Browse files
committed
PM / Hibernate: Introduce CONFIG_HIBERNATE_CALLBACKS
Xen save/restore is going to use hibernate device callbacks for quiescing devices and putting them back to normal operations and it would need to select CONFIG_HIBERNATION for this purpose. However, that also would cause the hibernate interfaces for user space to be enabled, which might confuse user space, because the Xen kernels don't support hibernation. Moreover, it would be wasteful, as it would make the Xen kernels include a substantial amount of code that they would never use. To address this issue introduce new power management Kconfig option CONFIG_HIBERNATE_CALLBACKS, such that it will only select the code that is necessary for the hibernate device callbacks to work and make CONFIG_HIBERNATION select it. Then, Xen save/restore will be able to select CONFIG_HIBERNATE_CALLBACKS without dragging the entire hibernate code along with it. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Tested-by: Shriram Rajagopalan <rshriram@cs.ubc.ca>
1 parent b42282e commit 1f112ce

8 files changed

Lines changed: 27 additions & 28 deletions

File tree

‎arch/powerpc/kernel/ibmebus.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static int ibmebus_bus_pm_resume_noirq(struct device *dev)
527527

528528
#endif /* !CONFIG_SUSPEND */
529529

530-
#ifdef CONFIG_HIBERNATION
530+
#ifdef CONFIG_HIBERNATE_CALLBACKS
531531

532532
static int ibmebus_bus_pm_freeze(struct device *dev)
533533
{
@@ -665,7 +665,7 @@ static int ibmebus_bus_pm_restore_noirq(struct device *dev)
665665
return ret;
666666
}
667667

668-
#else /* !CONFIG_HIBERNATION */
668+
#else /* !CONFIG_HIBERNATE_CALLBACKS */
669669

670670
#define ibmebus_bus_pm_freeze NULL
671671
#define ibmebus_bus_pm_thaw NULL
@@ -676,7 +676,7 @@ static int ibmebus_bus_pm_restore_noirq(struct device *dev)
676676
#define ibmebus_bus_pm_poweroff_noirq NULL
677677
#define ibmebus_bus_pm_restore_noirq NULL
678678

679-
#endif /* !CONFIG_HIBERNATION */
679+
#endif /* !CONFIG_HIBERNATE_CALLBACKS */
680680

681681
static struct dev_pm_ops ibmebus_bus_dev_pm_ops = {
682682
.prepare = ibmebus_bus_pm_prepare,

‎drivers/amba/bus.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static int amba_pm_resume_noirq(struct device *dev)
214214

215215
#endif /* !CONFIG_SUSPEND */
216216

217-
#ifdef CONFIG_HIBERNATION
217+
#ifdef CONFIG_HIBERNATE_CALLBACKS
218218

219219
static int amba_pm_freeze(struct device *dev)
220220
{
@@ -352,7 +352,7 @@ static int amba_pm_restore_noirq(struct device *dev)
352352
return ret;
353353
}
354354

355-
#else /* !CONFIG_HIBERNATION */
355+
#else /* !CONFIG_HIBERNATE_CALLBACKS */
356356

357357
#define amba_pm_freeze NULL
358358
#define amba_pm_thaw NULL
@@ -363,7 +363,7 @@ static int amba_pm_restore_noirq(struct device *dev)
363363
#define amba_pm_poweroff_noirq NULL
364364
#define amba_pm_restore_noirq NULL
365365

366-
#endif /* !CONFIG_HIBERNATION */
366+
#endif /* !CONFIG_HIBERNATE_CALLBACKS */
367367

368368
#ifdef CONFIG_PM
369369

‎drivers/base/platform.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ int __weak platform_pm_resume_noirq(struct device *dev)
771771

772772
#endif /* !CONFIG_SUSPEND */
773773

774-
#ifdef CONFIG_HIBERNATION
774+
#ifdef CONFIG_HIBERNATE_CALLBACKS
775775

776776
static int platform_pm_freeze(struct device *dev)
777777
{
@@ -909,7 +909,7 @@ static int platform_pm_restore_noirq(struct device *dev)
909909
return ret;
910910
}
911911

912-
#else /* !CONFIG_HIBERNATION */
912+
#else /* !CONFIG_HIBERNATE_CALLBACKS */
913913

914914
#define platform_pm_freeze NULL
915915
#define platform_pm_thaw NULL
@@ -920,7 +920,7 @@ static int platform_pm_restore_noirq(struct device *dev)
920920
#define platform_pm_poweroff_noirq NULL
921921
#define platform_pm_restore_noirq NULL
922922

923-
#endif /* !CONFIG_HIBERNATION */
923+
#endif /* !CONFIG_HIBERNATE_CALLBACKS */
924924

925925
#ifdef CONFIG_PM_RUNTIME
926926

‎drivers/base/power/main.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static int pm_op(struct device *dev,
233233
}
234234
break;
235235
#endif /* CONFIG_SUSPEND */
236-
#ifdef CONFIG_HIBERNATION
236+
#ifdef CONFIG_HIBERNATE_CALLBACKS
237237
case PM_EVENT_FREEZE:
238238
case PM_EVENT_QUIESCE:
239239
if (ops->freeze) {
@@ -260,7 +260,7 @@ static int pm_op(struct device *dev,
260260
suspend_report_result(ops->restore, error);
261261
}
262262
break;
263-
#endif /* CONFIG_HIBERNATION */
263+
#endif /* CONFIG_HIBERNATE_CALLBACKS */
264264
default:
265265
error = -EINVAL;
266266
}
@@ -308,7 +308,7 @@ static int pm_noirq_op(struct device *dev,
308308
}
309309
break;
310310
#endif /* CONFIG_SUSPEND */
311-
#ifdef CONFIG_HIBERNATION
311+
#ifdef CONFIG_HIBERNATE_CALLBACKS
312312
case PM_EVENT_FREEZE:
313313
case PM_EVENT_QUIESCE:
314314
if (ops->freeze_noirq) {
@@ -335,7 +335,7 @@ static int pm_noirq_op(struct device *dev,
335335
suspend_report_result(ops->restore_noirq, error);
336336
}
337337
break;
338-
#endif /* CONFIG_HIBERNATION */
338+
#endif /* CONFIG_HIBERNATE_CALLBACKS */
339339
default:
340340
error = -EINVAL;
341341
}

‎drivers/pci/pci-driver.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ static int pci_pm_resume(struct device *dev)
781781

782782
#endif /* !CONFIG_SUSPEND */
783783

784-
#ifdef CONFIG_HIBERNATION
784+
#ifdef CONFIG_HIBERNATE_CALLBACKS
785785

786786
static int pci_pm_freeze(struct device *dev)
787787
{
@@ -970,7 +970,7 @@ static int pci_pm_restore(struct device *dev)
970970
return error;
971971
}
972972

973-
#else /* !CONFIG_HIBERNATION */
973+
#else /* !CONFIG_HIBERNATE_CALLBACKS */
974974

975975
#define pci_pm_freeze NULL
976976
#define pci_pm_freeze_noirq NULL
@@ -981,7 +981,7 @@ static int pci_pm_restore(struct device *dev)
981981
#define pci_pm_restore NULL
982982
#define pci_pm_restore_noirq NULL
983983

984-
#endif /* !CONFIG_HIBERNATION */
984+
#endif /* !CONFIG_HIBERNATE_CALLBACKS */
985985

986986
#ifdef CONFIG_PM_RUNTIME
987987

‎drivers/xen/manage.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void xen_post_suspend(int cancelled)
6161
xen_mm_unpin_all();
6262
}
6363

64-
#ifdef CONFIG_HIBERNATION
64+
#ifdef CONFIG_HIBERNATE_CALLBACKS
6565
static int xen_suspend(void *data)
6666
{
6767
struct suspend_info *si = data;
@@ -173,7 +173,7 @@ static void do_suspend(void)
173173
#endif
174174
shutting_down = SHUTDOWN_INVALID;
175175
}
176-
#endif /* CONFIG_HIBERNATION */
176+
#endif /* CONFIG_HIBERNATE_CALLBACKS */
177177

178178
struct shutdown_handler {
179179
const char *command;
@@ -202,7 +202,7 @@ static void shutdown_handler(struct xenbus_watch *watch,
202202
{ "poweroff", do_poweroff },
203203
{ "halt", do_poweroff },
204204
{ "reboot", do_reboot },
205-
#ifdef CONFIG_HIBERNATION
205+
#ifdef CONFIG_HIBERNATE_CALLBACKS
206206
{ "suspend", do_suspend },
207207
#endif
208208
{NULL, NULL},

‎include/linux/suspend.h‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
249249
extern int hibernate(void);
250250
extern bool system_entering_hibernation(void);
251251
#else /* CONFIG_HIBERNATION */
252+
static inline void register_nosave_region(unsigned long b, unsigned long e) {}
253+
static inline void register_nosave_region_late(unsigned long b, unsigned long e) {}
252254
static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
253255
static inline void swsusp_set_page_free(struct page *p) {}
254256
static inline void swsusp_unset_page_free(struct page *p) {}
@@ -297,14 +299,7 @@ static inline bool pm_wakeup_pending(void) { return false; }
297299

298300
extern struct mutex pm_mutex;
299301

300-
#ifndef CONFIG_HIBERNATION
301-
static inline void register_nosave_region(unsigned long b, unsigned long e)
302-
{
303-
}
304-
static inline void register_nosave_region_late(unsigned long b, unsigned long e)
305-
{
306-
}
307-
302+
#ifndef CONFIG_HIBERNATE_CALLBACKS
308303
static inline void lock_system_sleep(void) {}
309304
static inline void unlock_system_sleep(void) {}
310305

‎kernel/power/Kconfig‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ config SUSPEND_FREEZER
1818

1919
Turning OFF this setting is NOT recommended! If in doubt, say Y.
2020

21+
config HIBERNATE_CALLBACKS
22+
bool
23+
2124
config HIBERNATION
2225
bool "Hibernation (aka 'suspend to disk')"
2326
depends on SWAP && ARCH_HIBERNATION_POSSIBLE
27+
select HIBERNATE_CALLBACKS
2428
select LZO_COMPRESS
2529
select LZO_DECOMPRESS
2630
---help---
@@ -85,7 +89,7 @@ config PM_STD_PARTITION
8589

8690
config PM_SLEEP
8791
def_bool y
88-
depends on SUSPEND || HIBERNATION || XEN_SAVE_RESTORE
92+
depends on SUSPEND || HIBERNATE_CALLBACKS || XEN_SAVE_RESTORE
8993

9094
config PM_SLEEP_SMP
9195
def_bool y

0 commit comments

Comments
 (0)