Skip to contentSkip to conversation

Current status, suspend-to-disk support on ARM

RFC PATCH In review Frank Hofmann 5 participants 25 messages Apr 4, 2011 – Apr 21, 2011

Subsystems (12)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Hi,

some status on making hibernation (suspend-to-disk) work on ARM.

I've simplified an updated patch set again, to make the pieces obvious. The attached patch set also cleanly compiles when adding TuxOnIce to it.

Pls. don't take this as a formal patch submission; this is discussion material and hence not currently based on any specific kernel revision.

The code essentially splits into two - a generic bit supplying the glue code that the framework needs, and SoC-specific code to do the core state suspend/resume.

The generic bits do two things:

* implement some glue the suspend-to-disk framework requires:

- pfn_is_nosave
- save/restore_processor_state
- swsusp_arch_suspend/resume entrypoints

* ARM assembly for the "guts" of swsusp_arch_suspend/resume

- save/restore current regset, CPSR and svc stack/lr
- page restore loop to copy the pageset back
- redirect to SoC-specific code for core suspend/resume

Hopefully what's in there is actually agnostic enough to qualify as "ARM generic". This stuff is quite clean by now.

There's one ugly thing in this set - I've changed a generic kernel header, <linux/suspend.h> to #define save/restore_processor_state() on ARM so that it only does preempt_disable/enable(). It's surprising that this isn't the default behaviour; all platforms need swsusp_arch_suspend/resume anyway so why force the existance of _two_ arch-specific hooks ?

In addition to this glue, one needs:

* a SoC-dependent __save/__restore_processor_state. There's two examples attached for that, OMAP3 and Samsung 6450.

This bit is the "hacky" part of the patch; on ARM, the platform code is blissfully unaware of suspend-to-disk while suspend-to-ram is partially very complex code.

The shown diffs hook into the "inner guts" of existing suspend-to-ram on ARM, and while that looks like it does a large part of the job, there's surely a better way.

I've supplied those as merely illustrative... to show that the inline assembly orgies from previous patches are just unnecessarily duplicating already-existing functionality. The way this is reused here might not be the perfect way - intent only was to show how much code re-use is actually possible in the area.

Whoever wishes can instead substitute the __save/__restore_processor_state inline assembly orgies from previously posted patches here - it all hooks in very cleanly.

To test / extend this code on an ARM architecture other than the two shown, one can start with the generic bits and simply make NOP-impls for the SoC-specific bits; that should at the very least allow a snapshot to be created, and so validate that device tree quiesce/freeze resume/thaw work correctly. Resume from such an image wouldn't work, though. At least the MMU state is absolutely critical.

Re, how (if at all) to get this towards mainline:

It looks like the various ARM boards have _very_ different views towards what suspend_ops.enter() will have to do; some are quite simple there, others are exceedingly complex.

One would ultimately hope for as much code sharing between hibernation and suspend-to-mem as possible, for sure, but the current code isn't aware of this; in many cases, saving/restoring state is done all over the place in the "arch framework" bits of suspend_ops.enter(), before the actual CPU core state is saved/resumed. ARM is heavily biased towards optimizing the hell out of suspend-to-mem, and a "grand central store" for system state isn't really there, all boards have their own strategy for this, and their own assumptions on what the CPU state is when resumed from RAM. This is even harder to do for "secure" SoCs, where part of the functionality is handled by (non-kernel) internal ROM code.

Russell King has recently done a change to the CPU suspend core code to make that use a "more generic" interface (have them all dump state into a caller-supplied buffer, at the least). The attached patches aren't yet fully aware of that because of the need _not_ to suspend (but return after state save) when called through the hibernation code. My brain hasn't yet grown big enough to solve this well ...

Re, success with this patch: On OMAP3, I've got issues; the console doesn't properly suspend/resume and using no_console_suspend keeps the messages but looses console input after resume. Also, graphics doesn't come back, and successive hibernation attempts cause crashes in the USB stack. It works much better on the Samsung 64xx boards, for me at least. But then, quite a few people reported success with the older patches on OMAP, hence I wonder, who's got it "fully working" ?

Any comments ? What can be improved ?

Have fun,
FrankH.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hibernate-core-04Apr2011.patch
Type: text/x-diff
Size: 9586 bytes
Desc:
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110404/10ee57ea/attachment-0001.bin>
-------------- next part --------------

arch/arm/plat-omap/Kconfig +1 -0
index df5ce56..b4713ba 100644
@@ -23,6 +23,7 @@ config ARCH_OMAP3
 	select CPU_V7
 	select COMMON_CLKDEV
 	select OMAP_IOMMU
+	select ARCH_HIBERNATION_POSSIBLE
 
 config ARCH_OMAP4
 	bool "TI OMAP4"
arch/arm/mach-omap2/sleep34xx.S +30 -0
index ea4e498..fd48417 100644
@@ -328,6 +328,17 @@ restore:
 	.word	0xE1600071		@ call SMI monitor (smi #1)
 #endif
 	b	logic_l1_restore
+#ifdef CONFIG_HIBERNATION
+ENTRY(__restore_processor_state)
+	stmfd	sp!, { r0 - r12, lr }
+	str	sp, [r0]		@ fixup saved stack pointer
+	str	lr, [r0, #8]		@ fixup saved link register
+	mov	r3, r0
+	mov	r1, #1
+	b	.Llogic_l1_restore_internal
+ENDPROC(__restore_processor_state)
+#endif
+
 l2_inv_api_params:
 	.word   0x1, 0x00
 l2_inv_gp:
@@ -358,6 +369,7 @@ logic_l1_restore:
 	ldr	r4, scratchpad_base
 	ldr	r3, [r4,#0xBC]
 	adds	r3, r3, #16
+.Llogic_l1_restore_internal:
 	ldmia	r3!, {r4-r6}
 	mov	sp, r4
 	msr	spsr_cxsf, r5
@@ -433,6 +445,10 @@ ttbr_error:
 	*/
 	b	ttbr_error
 usettbr0:
+#ifdef CONFIG_HIBERNATION
+	cmp	r1, #1
+	ldmeqfd	sp!, { r0 - r12, pc }	@ early return from __restore_processor_state
+#endif
 	mrc	p15, 0, r2, c2, c0, 0
 	ldr	r5, ttbrbit_mask
 	and	r2, r5
@@ -471,6 +487,16 @@ usettbr0:
 	mcr	p15, 0, r4, c1, c0, 0
 
 	ldmfd	sp!, {r0-r12, pc}		@ restore regs and return
+
+#ifdef CONFIG_HIBERNATION
+ENTRY(__save_processor_state)
+	stmfd	sp!, {r0-r12, lr}
+	mov	r1, #0x4
+	mov	r8, r0
+	b	l1_logic_lost
+ENDPROC(__save_processor_state)
+#endif
+
 save_context_wfi:
 	/*b	save_context_wfi*/	@ enable to debug save code
 	mov	r8, r0 /* Store SDRAM address in r8 */
@@ -545,6 +571,10 @@ l1_logic_lost:
 	mrc	p15, 0, r4, c1, c0, 0
 	/* save control register */
 	stmia	r8!, {r4}
+#ifdef CONFIG_HIBERNATION
+	cmp	r1, #4
+	ldmeqfd	sp!, {r0-r12, pc}	@ early return from __save_processor_state
+#endif
 clean_caches:
 	/* Clean Data or unified cache to POU*/
 	/* How to invalidate only L1 cache???? - #FIX_ME# */

-------------- next part --------------

arch/arm/plat-s5p/sleep.S +28 -3
index 2cdae4a..fd2b0a1 100644
@@ -48,10 +48,17 @@
 	 *
 	 * entry:
 	 *	r0 = save address (virtual addr of s3c_sleep_save_phys)
-	*/
+	 *	r1 (_internal_ only) = CPU sleep trampoline (if any)
+	 */
 
-ENTRY(s3c_cpu_save)
+ENTRY(__save_processor_state)
+	mov	r1, #0
+	b	.Ls3c_cpu_save_internal
+ENDPROC(__save_processor_state)
 
+ENTRY(s3c_cpu_save)
+	ldr	r1, =pm_cpu_sleep	@ set trampoline
+.Ls3c_cpu_save_internal:
 	stmfd	sp!, { r3 - r12, lr }
 
 	mrc	p15, 0, r4, c13, c0, 0	@ FCSE/PID
@@ -67,11 +74,13 @@ ENTRY(s3c_cpu_save)
 
 	stmia	r0, { r3 - r13 }
 
+	mov	r4, r1
 	@@ write our state back to RAM
 	bl	s3c_pm_cb_flushcache
 
+	mov	r0, r4
+	ldmeqfd	sp!, { r3 - r12, pc }	@ if there was no trampoline, return
 	@@ jump to final code to send system to sleep
-	ldr	r0, =pm_cpu_sleep
 	@@ldr	pc, [ r0 ]
 	ldr	r0, [ r0 ]
 	mov	pc, r0
@@ -86,9 +95,19 @@ resume_with_mmu:
 	str	r12, [r4]
 
 	ldmfd	sp!, { r3 - r12, pc }
+ENDPROC(s3c_cpu_save)
+
+ENTRY(__restore_processor_state)
+	stmfd	sp!, { r3 - r12, lr }
+	ldr	r2, =.Ls3c_cpu_resume_internal
+	mov	r1, #1
+	str	sp, [r0, #40]		@ fixup sp in restore context
+	mov	pc, r2
+ENDPROC(__restore_processor_state)
 
 	.ltorg
 
+
 	@@ the next bits sit in the .data segment, even though they
 	@@ happen to be code... the s5pv210_sleep_save_phys needs to be
 	@@ accessed by the resume code before it can restore the MMU.
@@ -131,6 +150,7 @@ ENTRY(s3c_cpu_resume)
 	mcr	p15, 0, r1, c7, c5, 0		@@ invalidate I Cache
 
 	ldr	r0, s3c_sleep_save_phys	@ address of restore block
+.Ls3c_cpu_resume_internal:
 	ldmia	r0, { r3 - r13 }
 
 	mcr	p15, 0, r4, c13, c0, 0	@ FCSE/PID
@@ -152,6 +172,9 @@ ENTRY(s3c_cpu_resume)
 	mcr	p15, 0, r12, c10, c2, 0	@ write PRRR
 	mcr	p15, 0, r3, c10, c2, 1	@ write NMRR
 
+	cmp	r1, #0
+	bne	0f			@ only do MMU phys init
+					@ not called by __restore_processor_state
 	/* calculate first section address into r8 */
 	mov	r4, r6
 	ldr	r5, =0x3fff
@@ -175,6 +198,7 @@ ENTRY(s3c_cpu_resume)
 	str	r10, [r4]
 
 	ldr	r2, =resume_with_mmu
+0:
 	mcr	p15, 0, r9, c1, c0, 0		@ turn on MMU, etc
 
         nop
@@ -183,6 +207,7 @@ ENTRY(s3c_cpu_resume)
         nop
         nop					@ second-to-last before mmu
 
+	ldmnefd	sp!, { r3 - r12, pc }
 	mov	pc, r2				@ go back to virtual address
 
 	.ltorg
#1 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Hi,

sorry for double posting, the mailing list processor tells me "a non-text attachment was scrubbed"; just for the critical piece ...

Hopefully this one goes through. It's only "git diff" output; what could it have tripped over ?

Thanks,
FrankH.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hibernate-core-04Apr2011.patch
Type: text/x-diff
Size: 9586 bytes
Desc:
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110404/bae266a3/attachment.bin>

#2 lore raw
In reply to Frank Hofmann

Hi,

sorry for double posting, the mailing list processor tells me "a non-text attachment was scrubbed"; just for the critical piece ...

Hopefully this one goes through. It's only "git diff" output; what could it have tripped over ?

Thanks,
FrankH.

arch/arm/Kconfig +7 -0
index 6b6786c..b3c271f 100644
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+
 config ARCH_HAS_CPU_IDLE_WAIT
 	def_bool y
 
arch/arm/include/asm/memory.h +1 -0
index 5421d82..23e93a6 100644
@@ -191,6 +191,7 @@ static inline void *phys_to_virt(unsigned long x)
  */
 #define __pa(x)			__virt_to_phys((unsigned long)(x))
 #define __va(x)			((void *)__phys_to_virt((unsigned long)(x)))
+#define __pa_symbol(x)		__pa(RELOC_HIDE((unsigned long)(x),0))
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
 
 /*
arch/arm/include/asm/suspend.h new file +6 -0
new file mode 100644
index 0000000..8857c79
@@ -0,0 +1,6 @@
+#ifndef __ASM_ARM_SUSPEND_H
+#define __ASM_ARM_SUSPEND_H
+
+static inline int arch_prepare_suspend(void) { return 0; }
+
+#endif	/* __ASM_ARM_SUSPEND_H */
arch/arm/kernel/Makefile +1 -0
index c9b00bb..541ac3a 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_ARM_THUMBEE)	+= thumbee.o
 obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_ARM_UNWIND)	+= unwind.o
 obj-$(CONFIG_HAVE_TCM)		+= tcm.o
+obj-$(CONFIG_HIBERNATION)	+= cpu.o swsusp.o
 
 obj-$(CONFIG_CRUNCH)		+= crunch.o crunch-bits.o
 AFLAGS_crunch-bits.o		:= -Wa,-mcpu=ep9312
arch/arm/kernel/cpu.c new file +63 -0

63 lines not on this page · raw message

arch/arm/kernel/swsusp.S new file +142 -0

142 lines not on this page · raw message

arch/arm/kernel/vmlinux.lds.S +2 -1
index 4957e13..e691c77 100644
@@ -153,7 +153,6 @@ SECTIONS
 		__init_end = .;
 #endif
 
-		NOSAVE_DATA
 		CACHELINE_ALIGNED_DATA(32)
 
 		/*
@@ -176,6 +175,8 @@ SECTIONS
 	}
 	_edata_loc = __data_loc + SIZEOF(.data);
 
+	NOSAVE_DATA
+
 #ifdef CONFIG_HAVE_TCM
         /*
 	 * We align everything to a page boundary so we can
include/asm-generic/vmlinux.lds.h +1 -1
index b6e818f..0d39ae0 100644
@@ -171,7 +171,7 @@
 #define NOSAVE_DATA							\
 	. = ALIGN(PAGE_SIZE);						\
 	VMLINUX_SYMBOL(__nosave_begin) = .;				\
-	*(.data.nosave)							\
+	.data.nosave : { *(.data.nosave) }				\
 	. = ALIGN(PAGE_SIZE);						\
 	VMLINUX_SYMBOL(__nosave_end) = .;
 
include/linux/suspend.h +5 -0
index 5e781d8..476d4c3 100644
@@ -274,8 +274,13 @@ static inline void hibernate_nvs_restore(void) {}
 #endif /* CONFIG_HIBERNATION_NVS */
 
 #ifdef CONFIG_PM_SLEEP
+#ifndef CONFIG_ARM
 void save_processor_state(void);
 void restore_processor_state(void);
+#else
+#define	save_processor_state	preempt_disable
+#define	restore_processor_state	preempt_enable
+#endif
 
 /* kernel/power/main.c */
 extern int register_pm_notifier(struct notifier_block *nb);
#3 lore raw

RFC PATCH v2 1/1 Current status, suspend-to-disk support on ARM

In reply to Frank Hofmann

Updated version of yesterday's core ARM hibernation code bits.

I've found that the use of cpu_switch_mm() breaks resume on OMAP3; leaving it out for now. It's unnecessary for direct resume (via kernel command line or TuxOnIce), only needed for uswsusp.

Also, me bad, apologies for posting refactored code one too early ... I've tried many ways of getting the actual swsusp_arch_suspend/resume entrypoints to be C code (and only the absolute essentials assembly), but for the case of swsusp_arch_suspend, assembly entry is mandatory because the framework relies on resuming into to the caller (i.e. no change can be made to the return address / LR reg before storing it, that makes it impossible to use a C wrapper function).

Thanks for any thoughts, feedback, reviews on this.

FrankH.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hibernate-core-05Apr2011.patch
Type: text/x-diff
Size: 9758 bytes
Desc:
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110405/ed330412/attachment-0001.bin>

#4 lore raw
In reply to Frank Hofmann

Updated version of yesterday's core ARM hibernation code bits.

I've found that the use of cpu_switch_mm() breaks resume on OMAP3; leaving it out for now. It's unnecessary for direct resume (via kernel command line or TuxOnIce), only needed for uswsusp.

Also, me bad, apologies for posting refactored code one too early ... I've tried many ways of getting the actual swsusp_arch_suspend/resume entrypoints to be C code (and only the absolute essentials assembly), but for the case of swsusp_arch_suspend, assembly entry is mandatory because the framework relies on resuming into to the caller (i.e. no change can be made to the return address / LR reg before storing it, that makes it impossible to use a C wrapper function).

Thanks for any thoughts, feedback, reviews on this.

FrankH.

arch/arm/Kconfig +8 -0
index 6b6786c..b3c271f 100644
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	depends on !SMP
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+
 config ARCH_HAS_CPU_IDLE_WAIT
 	def_bool y
 
arch/arm/include/asm/memory.h +1 -0
index 5421d82..23e93a6 100644
@@ -191,6 +191,7 @@ static inline void *phys_to_virt(unsigned long x)
  */
 #define __pa(x)			__virt_to_phys((unsigned long)(x))
 #define __va(x)			((void *)__phys_to_virt((unsigned long)(x)))
+#define __pa_symbol(x)		__pa(RELOC_HIDE((unsigned long)(x),0))
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
 
 /*
arch/arm/include/asm/suspend.h new file +6 -0
new file mode 100644
index 0000000..8857c79
@@ -0,0 +1,6 @@
+#ifndef __ASM_ARM_SUSPEND_H
+#define __ASM_ARM_SUSPEND_H
+
+static inline int arch_prepare_suspend(void) { return 0; }
+
+#endif	/* __ASM_ARM_SUSPEND_H */
arch/arm/kernel/Makefile +1 -0
index c9b00bb..541ac3a 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_ARM_THUMBEE)	+= thumbee.o
 obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_ARM_UNWIND)	+= unwind.o
 obj-$(CONFIG_HAVE_TCM)		+= tcm.o
+obj-$(CONFIG_HIBERNATION)	+= cpu.o swsusp.o
 
 obj-$(CONFIG_CRUNCH)		+= crunch.o crunch-bits.o
 AFLAGS_crunch-bits.o		:= -Wa,-mcpu=ep9312
arch/arm/kernel/cpu.c new file +36 -0
new file mode 100644
index 0000000..07d2f45
@@ -0,0 +1,36 @@
+/*
+ * Hibernation support specific for ARM
+ *
+ * Based on work by:
+ *
+ * Ubuntu project, hibernation support for mach-dove,
+ *	https://lkml.org/lkml/2010/6/18/4
+ *
+ * Copyright (C) 2010 Nokia Corporation
+ *	Contact: Hiroshi DOYU <[email protected]>
+ *	https://lists.linux-foundation.org/pipermail/linux-pm/2010-June/027422.html
+ *
+ * Copyright (C) 2010 Texas Instruments, Inc.
+ *	via linux-omap mailing list, Teerth Reddy et al.
+ *	https://patchwork.kernel.org/patch/96442/
+ *
+ * Copyright (C) 2006 Rafael J. Wysocki <[email protected]>
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include <linux/mm.h>
+
+/* References to section boundaries */
+extern const void __nosave_begin, __nosave_end;
+
+/*
+ * pfn_is_nosave - check if given pfn is in the 'nosave' section
+ */
+int pfn_is_nosave(unsigned long pfn)
+{
+	unsigned long nosave_begin_pfn = __pa_symbol(&__nosave_begin) >> PAGE_SHIFT;
+	unsigned long nosave_end_pfn = PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT;
+
+	return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn);
+}
arch/arm/kernel/swsusp.S new file +167 -0

167 lines not on this page · raw message

arch/arm/kernel/vmlinux.lds.S +2 -1
index 4957e13..e691c77 100644
@@ -153,7 +153,6 @@ SECTIONS
 		__init_end = .;
 #endif
 
-		NOSAVE_DATA
 		CACHELINE_ALIGNED_DATA(32)
 
 		/*
@@ -176,6 +175,8 @@ SECTIONS
 	}
 	_edata_loc = __data_loc + SIZEOF(.data);
 
+	NOSAVE_DATA
+
 #ifdef CONFIG_HAVE_TCM
         /*
 	 * We align everything to a page boundary so we can
include/asm-generic/vmlinux.lds.h +1 -1
index b6e818f..0d39ae0 100644
@@ -171,7 +171,7 @@
 #define NOSAVE_DATA							\
 	. = ALIGN(PAGE_SIZE);						\
 	VMLINUX_SYMBOL(__nosave_begin) = .;				\
-	*(.data.nosave)							\
+	.data.nosave : { *(.data.nosave) }				\
 	. = ALIGN(PAGE_SIZE);						\
 	VMLINUX_SYMBOL(__nosave_end) = .;
 
include/linux/suspend.h +5 -0
index 5e781d8..476d4c3 100644
@@ -274,8 +274,13 @@ static inline void hibernate_nvs_restore(void) {}
 #endif /* CONFIG_HIBERNATION_NVS */
 
 #ifdef CONFIG_PM_SLEEP
+#ifndef CONFIG_ARM
 void save_processor_state(void);
 void restore_processor_state(void);
+#else
+#define	save_processor_state	preempt_disable
+#define	restore_processor_state	preempt_enable
+#endif
 
 /* kernel/power/main.c */
 extern int register_pm_notifier(struct notifier_block *nb);
#5 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

In reply to Frank Hofmann

Hi!

Quoted 6 lines

There's one ugly thing in this set - I've changed a generic kernel header, <linux/suspend.h> to #define save/restore_processor_state() on ARM so that it only does preempt_disable/enable(). It's surprising that this isn't the default behaviour; all platforms need swsusp_arch_suspend/resume anyway so why force the existance of _two_ arch-specific hooks ?

Can you submit separate patch cleaning it up?

Review config VECTORS_BASE · line 204

Quoted 11 lines
(quoted diff) +7 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#6 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Quoted 10 lines · Pavel Machek

Hi!

Quoted 6 lines

There's one ugly thing in this set - I've changed a generic kernel header, <linux/suspend.h> to #define save/restore_processor_state() on ARM so that it only does preempt_disable/enable(). It's surprising that this isn't the default behaviour; all platforms need swsusp_arch_suspend/resume anyway so why force the existance of _two_ arch-specific hooks ?

Can you submit separate patch cleaning it up?

How about the attached ?

It's for discussion, and hence not tested (admittedly, I need an x86 test system ...).

The diff is against RMK's devel-stable tree, as of commit 5f183860d5007ec76ea36bfa6c36d66e37f0dbcf

There's a few hurdles here:

a) who knows all assembly calling conventions for all architectures supported by linux ?

This applies to SH and S390; save/restore_processor_state on those are primitive and should be inlined within swsusp_arch_suspend/resume, just like the attached patch does for the powerpc variants.

I've done a bounce call within S390 but don't know enough about SH3 for arch/sh/kernel/cpu/sh3/swsusp.S - i.e. add a call in assembly to init_cpu(current), and then ditch save_processor_state.

b) some architectures do things _beyond_ register/state saving in those two functions, and hence rely on them being called paired.

c) CONFIG_KEXEC_JUMP (ab-)uses them. I don't know that subsystem at all, but this sort of re-use means the symbols can't just be ditched. They become arch-dependent though, no non-arch/ code calls them anymore.

What I've attached might break SH3 swsusp, as save_processor_state is no longer called there (it stores FPU state).

I've also been wondering:
The comments in kernel/power/hibernate.c mention the need to get preempt counts "right" as major motivator to call save/restore_processor_state. effect" of save/restore_processor_state).

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

What is and what is not necessary, really ?

Finally, on things like e.g. the floating point context saves: Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ?
I wonder why e.g. powerpc does it explicitly; not doing so on ARM doesn't seem to cause problems.

Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
Quoted 9 lines

Review config VECTORS_BASE · line 204

Quoted 7 lines
(quoted diff) +7 -0
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

How would this be done better ?

FrankH.

Quoted 5 lines
Signature · 3 lines
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: remove-save_processor_state.patch
Type: text/x-diff
Size: 10417 bytes
Desc:
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110412/6de02f2b/attachment.bin>

#7 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Hi!

Quoted 13 lines
Quoted 8 lines
Quoted 6 lines

There's one ugly thing in this set - I've changed a generic kernel header, <linux/suspend.h> to #define save/restore_processor_state() on ARM so that it only does preempt_disable/enable(). It's surprising that this isn't the default behaviour; all platforms need swsusp_arch_suspend/resume anyway so why force the existance of _two_ arch-specific hooks ?

Can you submit separate patch cleaning it up?

How about the attached ?

It's for discussion, and hence not tested (admittedly, I need an x86 test system ...).

...

Quoted 10 lines

I've also been wondering:
The comments in kernel/power/hibernate.c mention the need to get preempt counts "right" as major motivator to call save/restore_processor_state.
effect" of save/restore_processor_state).

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

You might need to dig a bit more. IIRC it manipulated FPU or something long time ago.

Quoted 3 lines

Finally, on things like e.g. the floating point context saves:
Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ?

Are you sure? I thought we have (had?) concept of lazy FPU saving... and occassionaly kernel uses FPU too (with some precautions).

Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
Quoted 9 lines

Review config VECTORS_BASE · line 204

Quoted 7 lines
(quoted diff) +7 -0
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Quoted 1 line

How would this be done better ?

Just set the ARCH_HIBERNATION_POSSIBLE=y in the ARM code now that ARM can do it. No need to ask user.

Review static int resume_target_kernel(bool platform_mode) · line 419

Quoted 10 lines
(quoted diff) +1 -2
@@ -412,8 +413,7 @@ static int resume_target_kernel(bool platform_mode)
 	if (error)
 		goto Enable_irqs;
 
-	/* We'll ignore saved state, but this gets preempt count (etc) right */
-	save_processor_state();
+	preempt_disable();
 	error = restore_highmem();
 	if (!error) {
 		error = swsusp_arch_resume();

Yep. save_processor_state() on x86 does kernel_fpu_begin(), and than one needs to be balanced IIRC.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#8 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Quoted 1 line · Pavel Machek

Hi!

[ ... ]

Quoted 7 lines
Quoted 4 lines

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

You might need to dig a bit more. IIRC it manipulated FPU or something long time ago.

Actually, it's the other way round - kernel_fpu_begin/end are users of preempt_disable/enable, quote Documentation/preempt-locking.txt:

Note, some FPU functions are already explicitly preempt safe. For example, kernel_fpu_begin and kernel_fpu_end will disable and enable preemption. However, math_state_restore must be called with preemption disabled.

But kernel_fpu_begin/end functions are x86-specific. At best, that makes the comment in hibernate.c (which refers to "needing" preempt_dis/enable) misleading.

x86, in this, is an odd one out, though, in ; On ARM, for example, saving the FP context happens through a PM notifier.

In addition, it seems that the code (at least in hibernate.c, create_image) does anyway:

- go single-cpu (disables all but current)
- switch interrupts off (local_irq_disable)

before going into save_processor_state - wouldn't that mean all conditions for nonpreemptable (or all conditions for a stable FP state) are already met by that time ?

Quoted 8 lines
Quoted 4 lines

Finally, on things like e.g. the floating point context saves:
Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ?

Are you sure? I thought we have (had?) concept of lazy FPU saving... and occassionaly kernel uses FPU too (with some precautions).

speaking in particular for ARM, I'd deflect the answer to:

http://www.spinics.net/lists/linux-pm/msg22839.html

It's lazy but it does happen ... without any specific need to have the "bracketing" that save/restore_processor_state are doing.

Food for thought:

I mean, the code in hibernate.c really looks like this (quote):

static int create_image(int platform_mode)

{
         int error;

         error = arch_prepare_suspend();				<===== platform hook 1
[ ... ]
         error = dpm_suspend_noirq(PMSG_FREEZE);			<===== platform hook 2
[ ... ]
         error = platform_pre_snapshot(platform_mode);		<===== platform hook 3
[ ... ]
         error = disable_nonboot_cpus();				<===== platform hook 4
[ ... ]
         error = sysdev_suspend(PMSG_FREEZE);			<===== ...
         if (!error)
                 error = syscore_suspend();			<===== ...
[ ... ]
         in_suspend = 1;
         save_processor_state();					<===== platform hook N-1
         error = swsusp_arch_suspend();				<===== platform hook N
[ ... ]
         restore_processor_state();				<===== platform hook N+1

[ ... ]

And that's _without_ the platform hibernation ops hooks code in hibernate(), which calls this one.

This code is full of places where to plug save/restore code (or any sort of "bracketing" begin/finish hooks) into.
It's surprising that with all these hooks existing already, "bracketing" of swsusp_arch_suspend() by save/restore_processor state is so sacrosanct.

These are _three_ arch-dependent hooks in three consecutive lines of code.

If a platform requires the bracketing, why can it not do that part in syscore_suspend() ? Or why not simply embed it in swsusp_arch_suspend() ?

As said, wrt. to save/restore_processor_state, x86 is definitely the odd one out (and not a good example) with the monstrosity of code; all other architectures either have trivial or even completely empty code for save/restore_processor_state().

Should we really force everyone to provide an (as good as) empty hook just because x86@one point had chosen to have it ?

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

Review config VECTORS_BASE · line 204

Quoted 12 lines
(quoted diff) +7 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Quoted 4 lines
Quoted 1 line

How would this be done better ?

Just set the ARCH_HIBERNATION_POSSIBLE=y in the ARM code now that ARM can do it. No need to ask user.

I.e. preferrably:

config ARCH_HIBERNATION_POSSIBLE
def_bool n

plus the "select" within the actual platform config subsection for those that have it.

To stress the point: "ARM can do it" would be an exaggeration even if those changes went in, because only some ARM types will have it.

The situation on ARM is identical to e.g. SuperH, see arch/sh/Kconfig,

config SUPERH32
def_bool ARCH = "sh"
[ ... various ... ]
select ARCH_HIBERNATION_POSSIBLE if MMU

config ARCH_HIBERNATION_POSSIBLE
def_bool n

Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
@@ -412,8 +413,7 @@ static int resume_target_kernel(bool platform_mode)
 	if (error)
 		goto Enable_irqs;
 
Quoted 9 lines

Review static int resume_target_kernel(bool platform_mode) · line 419

Quoted 6 lines
(quoted diff) +1 -2
-	/* We'll ignore saved state, but this gets preempt count (etc) right */
-	save_processor_state();
+	preempt_disable();
 	error = restore_highmem();
 	if (!error) {
 		error = swsusp_arch_resume();

Yep. save_processor_state() on x86 does kernel_fpu_begin(), and than one needs to be balanced IIRC.

The needs of x86 force generic kernel changes ;-)

FrankH.

Quoted 6 lines

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#9 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Quoted 20 lines · Frank Hofmann
Quoted 1 line · Pavel Machek

Hi!

[ ... ]

Quoted 7 lines
Quoted 4 lines

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

You might need to dig a bit more. IIRC it manipulated FPU or something long time ago.

Actually, it's the other way round - kernel_fpu_begin/end are users of preempt_disable/enable, quote Documentation/preempt-locking.txt:

(quoted diff) +0 -0
 	Note, some FPU functions are already explicitly preempt safe.  For example,
 	kernel_fpu_begin and kernel_fpu_end will disable and enable preemption.
 	However, math_state_restore must be called with preemption disabled.
Quoted 3 lines

But kernel_fpu_begin/end functions are x86-specific. At best, that makes the comment in hibernate.c (which refers to "needing" preempt_dis/enable) misleading.

This comment is outright wrong in fact, sorry about that. Evidently, restore_processor_state() is called right after the "restore control flow magically appears here" comment and it _does_ use the saved state.

I'll remove that comment.

Quoted 9 lines

x86, in this, is an odd one out, though, in ; On ARM, for example, saving the FP context happens through a PM notifier.

In addition, it seems that the code (at least in hibernate.c, create_image) does anyway:

(quoted diff) +0 -0
 	- go single-cpu (disables all but current)
 	- switch interrupts off (local_irq_disable)
Quoted 3 lines

before going into save_processor_state - wouldn't that mean all conditions for nonpreemptable (or all conditions for a stable FP state) are already met by that time ?

Yes, it does.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Finally, on things like e.g. the floating point context saves:
Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ?

Are you sure? I thought we have (had?) concept of lazy FPU saving... and occassionaly kernel uses FPU too (with some precautions).

Quoted 6 lines

speaking in particular for ARM, I'd deflect the answer to:

http://www.spinics.net/lists/linux-pm/msg22839.html

It's lazy but it does happen ... without any specific need to have the "bracketing" that save/restore_processor_state are doing.

save/restore_processor_state() are arch-specific and do whatever is necessary or useful for the given architecture. The saving/restoring of the FPU state at those points happens to be useful for x86 IIRC.

Quoted 10 lines

Food for thought:

I mean, the code in hibernate.c really looks like this (quote):

static int create_image(int platform_mode)

{
         int error;

         error = arch_prepare_suspend();				<===== platform hook 1

Architecture hook rather and it would have been one if there had been any architecture actually providing anything different from a NOP. IOW, to be removed (forgot about it last time I did a code cleanup).

Quoted 2 lines

[ ... ]

         error = dpm_suspend_noirq(PMSG_FREEZE);			<===== platform hook 2

Not really. This is a device core callback for the last stage of device freeze.

Quoted 2 lines

[ ... ]

         error = platform_pre_snapshot(platform_mode);		<===== platform hook 3

This is a platform hook.

Quoted 2 lines

[ ... ]

         error = disable_nonboot_cpus();				<===== platform hook 4

Not a platform hook. This one disables the nonboot CPUs using hotplug and this mechanism is supposed to work that way on all platforms.

Quoted 5 lines

[ ... ]

         error = sysdev_suspend(PMSG_FREEZE);			<===== ...
         if (!error)
                 error = syscore_suspend();			<===== ...

[ ... ]

These suspend things that are "below" devices (like interrupt controllers and such stuff) and by no means are platform hooks.

Quoted 2 lines
         in_suspend = 1;
         save_processor_state();					<===== platform hook N-1

This is an architecture hook for saving the state of the boot CPU.

Quoted 1 line
         error = swsusp_arch_suspend();				<===== platform hook N

This one is needed on x86 so that we can point the CPU to the original page tables after we've restored the target kernel from the image.

Quoted 6 lines

[ ... ]

         restore_processor_state();				<===== platform hook N+1

[ ... ]

And that's _without_ the platform hibernation ops hooks code in hibernate(), which calls this one.

Actually not without, platform_pre_snapshot() is one of those.

Quoted 9 lines

This code is full of places where to plug save/restore code (or any sort of "bracketing" begin/finish hooks) into.
It's surprising that with all these hooks existing already, "bracketing" of swsusp_arch_suspend() by save/restore_processor state is so sacrosanct.

These are _three_ arch-dependent hooks in three consecutive lines of code.

If a platform requires the bracketing, why can it not do that part in syscore_suspend() ? Or why not simply embed it in swsusp_arch_suspend() ?

save/restore_processor_state() are also used by the x86's suspend to RAM code. Of course, you can argue that they should be kept x86-specific, but since those features were originally developed on x86, the code still remains x86-centric in that respect.

Quoted 7 lines

As said, wrt. to save/restore_processor_state, x86 is definitely the odd one out (and not a good example) with the monstrosity of code; all other architectures either have trivial or even completely empty code for save/restore_processor_state().

Should we really force everyone to provide an (as good as) empty hook just because x86 at one point had chosen to have it ?

I don't see much reason for that, but since none of the guys who implemented those empty hooks has ever complained and/or attempted to change things, there has not been much reason to work in that direction. :-)

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

Review config VECTORS_BASE · line 204

Quoted 11 lines
(quoted diff) +7 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Quoted 4 lines
Quoted 1 line

How would this be done better ?

Just set the ARCH_HIBERNATION_POSSIBLE=y in the ARM code now that ARM can do it. No need to ask user.

I.e. preferrably:

Review

Quoted 2 lines
(quoted diff) +0 -0
 	config ARCH_HIBERNATION_POSSIBLE
 		def_bool n

You don't need to use "def_bool n", "bool" alone will do just fine.

Quoted 8 lines

plus the "select" within the actual platform config subsection for those that have it.

To stress the point: "ARM can do it" would be an exaggeration even if those changes went in, because only some ARM types will have it.

The situation on ARM is identical to e.g. SuperH, see arch/sh/Kconfig,

Quoted 8 lines

config SUPERH32
def_bool ARCH = "sh"
[ ... various ... ]
select ARCH_HIBERNATION_POSSIBLE if MMU

config ARCH_HIBERNATION_POSSIBLE
def_bool n

Yes, something like this.

Quoted 7 lines
Quoted 7 lines

Review static int resume_target_kernel(bool platform_mode) · line 416

Quoted 7 lines
(quoted diff) +1 -2
@@ -412,8 +413,7 @@ static int resume_target_kernel(bool platform_mode)
 	if (error)
 		goto Enable_irqs;
 
-	/* We'll ignore saved state, but this gets preempt count (etc) right */
-	save_processor_state();
+	preempt_disable();

Why do you need that preempt_disable() here?

Quoted 9 lines
Quoted 6 lines

Review static int resume_target_kernel(bool platform_mode) · line 419

Quoted 3 lines
(quoted diff) +0 -0
 	error = restore_highmem();
 	if (!error) {
 		error = swsusp_arch_resume();

Yep. save_processor_state() on x86 does kernel_fpu_begin(), and than one needs to be balanced IIRC.

The needs of x86 force generic kernel changes ;-)

Not necessarily. In fact, implementing that feature on different architectures is a good opportunity to clean up the code if necessary.

Thanks,
Rafael

#10 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Hi Rafael, hi Pavel,

thanks for your comments, this makes history and purpose of the save/restore_processor_functions a lot clearer.
Yes, x86 does a lot more in those than other architectures, but even on non-x86, they have a purpose even if one decides to do the "core" work inside swsusp_arch_suspend/resume().

I'll go back to the drawing board for the ARM patch again for a bit.

It might be useful/necessary to delegate some of the functionality actually into save/restore_processor_state, like powerpc does (call flush_thread() to store lazy-save state, and maybe, if necessary, do some of the things the cpu_idle code on ARM does before going down into cpu_suspend).

John reported a crash on resume (on OMAP4) related to FP state; I've done some tracing here to see whether the PM notifiers for storing the VFP/FPU state on ARM are actually triggering with the suggested change and they're not, which means there's still some work to do here.

The last thing here in my setup that's obviously not correctly suspending / resuming is the OMAP display driver; I'm not the only one with that problem, Matt's previous report:

http://blog.gmane.org/gmane.linux.swsusp.devel/month=20101201

has the same thing, "omapdss DISPC error: SYNC_LOST, disabling LCD".

I'll provide an update before Easter.

Thanks for the help so far!
FrankH.

Quoted 222 lines · Rafael J. Wysocki
Quoted 20 lines · Frank Hofmann
Quoted 1 line · Pavel Machek

Hi!

[ ... ]

Quoted 7 lines
Quoted 4 lines

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

You might need to dig a bit more. IIRC it manipulated FPU or something long time ago.

Actually, it's the other way round - kernel_fpu_begin/end are users of preempt_disable/enable, quote Documentation/preempt-locking.txt:

(quoted diff) +0 -0
 	Note, some FPU functions are already explicitly preempt safe.  For example,
 	kernel_fpu_begin and kernel_fpu_end will disable and enable preemption.
 	However, math_state_restore must be called with preemption disabled.
Quoted 3 lines

But kernel_fpu_begin/end functions are x86-specific. At best, that makes the comment in hibernate.c (which refers to "needing" preempt_dis/enable) misleading.

This comment is outright wrong in fact, sorry about that. Evidently, restore_processor_state() is called right after the "restore control flow magically appears here" comment and it _does_ use the saved state.

I'll remove that comment.

Quoted 9 lines

x86, in this, is an odd one out, though, in ; On ARM, for example, saving the FP context happens through a PM notifier.

In addition, it seems that the code (at least in hibernate.c, create_image) does anyway:

(quoted diff) +0 -0
 	- go single-cpu (disables all but current)
 	- switch interrupts off (local_irq_disable)
Quoted 3 lines

before going into save_processor_state - wouldn't that mean all conditions for nonpreemptable (or all conditions for a stable FP state) are already met by that time ?

Yes, it does.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Finally, on things like e.g. the floating point context saves:
Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ?

Are you sure? I thought we have (had?) concept of lazy FPU saving... and occassionaly kernel uses FPU too (with some precautions).

Quoted 6 lines

speaking in particular for ARM, I'd deflect the answer to:

http://www.spinics.net/lists/linux-pm/msg22839.html

It's lazy but it does happen ... without any specific need to have the "bracketing" that save/restore_processor_state are doing.

save/restore_processor_state() are arch-specific and do whatever is necessary or useful for the given architecture. The saving/restoring of the FPU state at those points happens to be useful for x86 IIRC.

Quoted 10 lines

Food for thought:

I mean, the code in hibernate.c really looks like this (quote):

static int create_image(int platform_mode)

{
         int error;

         error = arch_prepare_suspend();				<===== platform hook 1

Architecture hook rather and it would have been one if there had been any architecture actually providing anything different from a NOP. IOW, to be removed (forgot about it last time I did a code cleanup).

Quoted 2 lines

[ ... ]

         error = dpm_suspend_noirq(PMSG_FREEZE);			<===== platform hook 2

Not really. This is a device core callback for the last stage of device freeze.

Quoted 2 lines

[ ... ]

         error = platform_pre_snapshot(platform_mode);		<===== platform hook 3

This is a platform hook.

Quoted 2 lines

[ ... ]

         error = disable_nonboot_cpus();				<===== platform hook 4

Not a platform hook. This one disables the nonboot CPUs using hotplug and this mechanism is supposed to work that way on all platforms.

Quoted 5 lines

[ ... ]

         error = sysdev_suspend(PMSG_FREEZE);			<===== ...
         if (!error)
                 error = syscore_suspend();			<===== ...

[ ... ]

These suspend things that are "below" devices (like interrupt controllers and such stuff) and by no means are platform hooks.

Quoted 2 lines
         in_suspend = 1;
         save_processor_state();					<===== platform hook N-1

This is an architecture hook for saving the state of the boot CPU.

Quoted 1 line
         error = swsusp_arch_suspend();				<===== platform hook N

This one is needed on x86 so that we can point the CPU to the original page tables after we've restored the target kernel from the image.

Quoted 6 lines

[ ... ]

         restore_processor_state();				<===== platform hook N+1

[ ... ]

And that's _without_ the platform hibernation ops hooks code in hibernate(), which calls this one.

Actually not without, platform_pre_snapshot() is one of those.

Quoted 9 lines

This code is full of places where to plug save/restore code (or any sort of "bracketing" begin/finish hooks) into.
It's surprising that with all these hooks existing already, "bracketing" of swsusp_arch_suspend() by save/restore_processor state is so sacrosanct.

These are _three_ arch-dependent hooks in three consecutive lines of code.

If a platform requires the bracketing, why can it not do that part in syscore_suspend() ? Or why not simply embed it in swsusp_arch_suspend() ?

save/restore_processor_state() are also used by the x86's suspend to RAM code. Of course, you can argue that they should be kept x86-specific, but since those features were originally developed on x86, the code still remains x86-centric in that respect.

Quoted 7 lines

As said, wrt. to save/restore_processor_state, x86 is definitely the odd one out (and not a good example) with the monstrosity of code; all other architectures either have trivial or even completely empty code for save/restore_processor_state().

Should we really force everyone to provide an (as good as) empty hook just because x86 at one point had chosen to have it ?

I don't see much reason for that, but since none of the guys who implemented those empty hooks has ever complained and/or attempted to change things, there has not been much reason to work in that direction. :-)

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

Review config VECTORS_BASE · line 204

Quoted 11 lines
(quoted diff) +7 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Quoted 4 lines
Quoted 1 line

How would this be done better ?

Just set the ARCH_HIBERNATION_POSSIBLE=y in the ARM code now that ARM can do it. No need to ask user.

I.e. preferrably:

Review

Quoted 2 lines
(quoted diff) +0 -0
 	config ARCH_HIBERNATION_POSSIBLE
 		def_bool n

You don't need to use "def_bool n", "bool" alone will do just fine.

Quoted 8 lines

plus the "select" within the actual platform config subsection for those that have it.

To stress the point: "ARM can do it" would be an exaggeration even if those changes went in, because only some ARM types will have it.

The situation on ARM is identical to e.g. SuperH, see arch/sh/Kconfig,

Quoted 8 lines

config SUPERH32
def_bool ARCH = "sh"
[ ... various ... ]
select ARCH_HIBERNATION_POSSIBLE if MMU

config ARCH_HIBERNATION_POSSIBLE
def_bool n

Yes, something like this.

Quoted 7 lines
Quoted 7 lines

Review static int resume_target_kernel(bool platform_mode) · line 416

Quoted 7 lines
(quoted diff) +1 -2
@@ -412,8 +413,7 @@ static int resume_target_kernel(bool platform_mode)
 	if (error)
 		goto Enable_irqs;
 
-	/* We'll ignore saved state, but this gets preempt count (etc) right */
-	save_processor_state();
+	preempt_disable();

Why do you need that preempt_disable() here?

Quoted 9 lines
Quoted 6 lines

Review static int resume_target_kernel(bool platform_mode) · line 419

Quoted 3 lines
(quoted diff) +0 -0
 	error = restore_highmem();
 	if (!error) {
 		error = swsusp_arch_resume();

Yep. save_processor_state() on x86 does kernel_fpu_begin(), and than one needs to be balanced IIRC.

The needs of x86 force generic kernel changes ;-)

Not necessarily. In fact, implementing that feature on different architectures is a good opportunity to clean up the code if necessary.

Thanks,
Rafael

#11 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Quoted 6 lines

The last thing here in my setup that's obviously not correctly suspending / resuming is the OMAP display driver; I'm not the only one with that problem, Matt's previous report:

Quoted 6 lines

http://blog.gmane.org/gmane.linux.swsusp.devel/month=20101201

has the same thing, "omapdss DISPC error: SYNC_LOST, disabling LCD".

Hi FrankH,

Above issue could be resolved by:

- CONFIG_FB_OMAP2_FORCE_AUTO_UPDATE=y
- the following patch

(quoted diff) +0 -0

b/drivers/video/omap2/dss/dispc.c
index 8b3ac80..a188732 100644

drivers/video/omap2/dss/dispc.c +0 -0
@@ -2784,7 +2784,6 @@ static void dispc_error_worker(struct work_struct

*work)

                bool enable = false;

                DSSERR("SYNC_LOST, disabling LCD\n");

                for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
                        struct omap_overlay_manager *mgr;
                        mgr = omap_dss_get_overlay_manager(i);
@@ -2815,6 +2814,9 @@ static void dispc_error_worker(struct work_struct
*work)
                        if (enable)
                                manager->device->enable(manager->device);
                }

+
+ dispc_enable_lcd_out(false);
+ dispc_enable_lcd_out(true);

Although this patch is somehow nasty, but it work anyway.

- Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110418/b205e44d/attachment.html>

#12 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Quoted 6 lines · Matt Hsu
Quoted 6 lines

The last thing here in my setup that's obviously not correctly suspending / resuming is the OMAP display driver; I'm not the only one with that problem, Matt's previous report:

Quoted 8 lines
Quoted 6 lines

http://blog.gmane.org/gmane.linux.swsusp.devel/month=20101201

has the same thing, "omapdss DISPC error: SYNC_LOST, disabling LCD".

Hi FrankH,

Above issue could be resolved by:

Thanks Matt.

It didn't do the trick for me, but then a solution was found; we were using the omap dss vrfb component and that didn't resume properly (not from ram, nor from disk). We've disabled it and behold, screen comes back now ;-)

New patch set once I've done a bit more testing. I've found a way to use swapper_pg_dir (i.e. should allow for uswsusp - how would I test that ?) that seems to do the job on OMAP as well, but I'd rather validate thoroughly.

Also, I'd like to investigate whether ARM will require a set of platform_hibernation_ops - Samsung's patch from last December,

http://www.spinics.net/lists/arm-kernel/msg108565.html

seems to indicate that they believe it's necessary at least on some ARM hardware. OMAP has similar functions to that, it'd be great to unify.

FrankH.

Quoted 31 lines

- CONFIG_FB_OMAP2_FORCE_AUTO_UPDATE=y
- the following patch

drivers/video/omap2/dss/dispc.c +3 -1
index 8b3ac80..a188732 100644
@@ -2784,7 +2784,6 @@ static void dispc_error_worker(struct work_struct
 *work)
               bool enable = false;
 
               DSSERR("SYNC_LOST, disabling LCD\n");
 
               for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
                       struct omap_overlay_manager *mgr;
                       mgr = omap_dss_get_overlay_manager(i);
@@ -2815,6 +2814,9 @@ static void dispc_error_worker(struct work_struct
 *work)
                       if (enable)
                               manager->device->enable(manager->device);
               }
+
+               dispc_enable_lcd_out(false);
+               dispc_enable_lcd_out(true);
 
    Although this patch is somehow nasty, but it work anyway.
 
- Matt
#13 lore raw
Quoted 6 lines

Also, I'd like to investigate whether ARM will require a set of platform_hibernation_ops - Samsung's patch from last December,

http://www.spinics.net/lists/arm-kernel/msg108565.html

Hi FrankH,

The patch seems has connection with this

www.kernel.org/doc/ols/2010/ols2010-pages-9-18.pdf

You can see the section 4.3 fast device reactivation. It does the similar thing as STR, but drivers status are kept in
hibernation image instead of main memory.
I guess this is why this patch comes out.

In the current device driver model, there are no appropriate handling
specific to
hibernation_suspend/hibernation_resume ops.

So they make their own interface/platform drivers.

Quoted 8 lines

seems to indicate that they believe it's necessary at least on some ARM hardware. OMAP has similar functions to that, it'd be great to unify.

FrankH.

--

- Matt

#14 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

In reply to Frank Hofmann
Quoted 6 lines

Also, I'd like to investigate whether ARM will require a set of platform_hibernation_ops - Samsung's patch from last December,

http://www.spinics.net/lists/arm-kernel/msg108565.html

Hi FrankH,

The patch seems has connection with this

www.kernel.org/doc/ols/2010/ols2010-pages-9-18.pdf

You can see the section 4.3 fast device reactivation. It does the similar thing as STR, but drivers status are kept in
hibernation image instead of main memory.
I guess this is why this patch comes out.

In the current device driver model, there are no appropriate handling
specific to
hibernation_suspend/hibernation_resume ops.

So they make their own interface/platform drivers.

Quoted 8 lines

seems to indicate that they believe it's necessary at least on some ARM hardware. OMAP has similar functions to that, it'd be great to unify.

FrankH.

--

- Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110420/37618720/attachment-0001.html>

#15 lore raw

RFC PATCH 1/1 Current status, suspend-to-disk support on ARM

Hello Matt,

Quoted 5 lines · Matt Hsu
Quoted 5 lines

Also, I'd like to investigate whether ARM will require a set of platform_hibernation_ops - Samsung's patch from last December,

Quoted 7 lines
Quoted 1 line

http://www.spinics.net/lists/arm-kernel/msg108565.html

??? Hi FrankH,

???? The patch seems has connection with this

???? www.kernel.org/doc/ols/2010/ols2010-pages-9-18.pdf

Actually, those patches had no direct connections with that anyway. :)

Quoted 5 lines

? ? You can see the section 4.3 fast device reactivation. ? ? It does the similar thing? as STR, but drivers status are kept in hibernation image instead of main memory.
??? I guess this is why this patch comes out.

Yes, this SoC has registers that require STR/Hibernation to save the status. They include power, clock, memory-control, gpio, uart related registers.

Quoted 6 lines

??? In the current device driver model, there are no appropriate handling specific to
??? hibernation_suspend/hibernation_resume ops.

??? So they make their own interface/platform drivers.

Correct.

If the interface looks like dev_pm_ops, it would be virtually perfect. :)

Quoted 16 lines
Quoted 8 lines

seems to indicate that they believe it's necessary at least on some ARM hardware. OMAP has similar functions to that, it'd be great to unify.

FrankH.

--
- Matt

_______________________________________________
linux-pm mailing list
linux-pm at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

Signature · 5 lines
MyungJoo Ham, Ph.D.
Mobile Software Platform Lab,
Digital Media and Communications (DMC) Business
Samsung Electronics
cell: 82-10-6714-2858
#16 lore raw
In reply to Matt Hsu

Hello Matt,

Quoted 5 lines · Matt Hsu
Quoted 5 lines

Also, I'd like to investigate whether ARM will require a set of platform_hibernation_ops - Samsung's patch from last December,

Quoted 7 lines
Quoted 1 line

http://www.spinics.net/lists/arm-kernel/msg108565.html

    Hi FrankH,

     The patch seems has connection with this

     www.kernel.org/doc/ols/2010/ols2010-pages-9-18.pdf

Actually, those patches had no direct connections with that anyway. :)

Quoted 5 lines

    You can see the section 4.3 fast device reactivation. It does the similar thing  as STR, but drivers status are kept in hibernation image instead of main memory.
    I guess this is why this patch comes out.

Yes, this SoC has registers that require STR/Hibernation to save the status. They include power, clock, memory-control, gpio, uart related registers.

Quoted 6 lines

    In the current device driver model, there are no appropriate handling specific to
    hibernation_suspend/hibernation_resume ops.

    So they make their own interface/platform drivers.

Correct.

If the interface looks like dev_pm_ops, it would be virtually perfect. :)

Quoted 16 lines
Quoted 8 lines

seems to indicate that they believe it's necessary at least on some ARM hardware. OMAP has similar functions to that, it'd be great to unify.

FrankH.

--
- Matt

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

Signature · 5 lines
MyungJoo Ham, Ph.D.
Mobile Software Platform Lab,
Digital Media and Communications (DMC) Business
Samsung Electronics
cell: 82-10-6714-2858
#17 lore raw
In reply to Matt Hsu
Quoted 6 lines · Matt Hsu
Quoted 6 lines

The last thing here in my setup that's obviously not correctly suspending / resuming is the OMAP display driver; I'm not the only one with that problem, Matt's previous report:

Quoted 8 lines
Quoted 6 lines

http://blog.gmane.org/gmane.linux.swsusp.devel/month=20101201

has the same thing, "omapdss DISPC error: SYNC_LOST, disabling LCD".

Hi FrankH,

Above issue could be resolved by:

Thanks Matt.

It didn't do the trick for me, but then a solution was found; we were using the omap dss vrfb component and that didn't resume properly (not from ram, nor from disk). We've disabled it and behold, screen comes back now ;-)

New patch set once I've done a bit more testing. I've found a way to use swapper_pg_dir (i.e. should allow for uswsusp - how would I test that ?) that seems to do the job on OMAP as well, but I'd rather validate thoroughly.

Also, I'd like to investigate whether ARM will require a set of platform_hibernation_ops - Samsung's patch from last December,

http://www.spinics.net/lists/arm-kernel/msg108565.html

seems to indicate that they believe it's necessary at least on some ARM hardware. OMAP has similar functions to that, it'd be great to unify.

FrankH.

Quoted 31 lines

- CONFIG_FB_OMAP2_FORCE_AUTO_UPDATE=y
- the following patch

drivers/video/omap2/dss/dispc.c +3 -1
index 8b3ac80..a188732 100644
@@ -2784,7 +2784,6 @@ static void dispc_error_worker(struct work_struct
 *work)
               bool enable = false;
 
               DSSERR("SYNC_LOST, disabling LCD\n");
 
               for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
                       struct omap_overlay_manager *mgr;
                       mgr = omap_dss_get_overlay_manager(i);
@@ -2815,6 +2814,9 @@ static void dispc_error_worker(struct work_struct
 *work)
                       if (enable)
                               manager->device->enable(manager->device);
               }
+
+               dispc_enable_lcd_out(false);
+               dispc_enable_lcd_out(true);
 
    Although this patch is somehow nasty, but it work anyway.
 
- Matt
#18 lore raw
In reply to Frank Hofmann
Quoted 6 lines

The last thing here in my setup that's obviously not correctly suspending / resuming is the OMAP display driver; I'm not the only one with that problem, Matt's previous report:

Quoted 6 lines

http://blog.gmane.org/gmane.linux.swsusp.devel/month=20101201

has the same thing, "omapdss DISPC error: SYNC_LOST, disabling LCD".

Hi FrankH,

Above issue could be resolved by:

- CONFIG_FB_OMAP2_FORCE_AUTO_UPDATE=y
- the following patch

(quoted diff) +0 -0

b/drivers/video/omap2/dss/dispc.c
index 8b3ac80..a188732 100644

drivers/video/omap2/dss/dispc.c +0 -0
@@ -2784,7 +2784,6 @@ static void dispc_error_worker(struct work_struct

*work)

                bool enable = false;

                DSSERR("SYNC_LOST, disabling LCD\n");

                for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
                        struct omap_overlay_manager *mgr;
                        mgr = omap_dss_get_overlay_manager(i);
@@ -2815,6 +2814,9 @@ static void dispc_error_worker(struct work_struct
*work)
                        if (enable)
                                manager->device->enable(manager->device);
                }

+
+ dispc_enable_lcd_out(false);
+ dispc_enable_lcd_out(true);

Although this patch is somehow nasty, but it work anyway.

- Matt

#19 lore raw
In reply to Rafael J. Wysocki

Hi Rafael, hi Pavel,

thanks for your comments, this makes history and purpose of the save/restore_processor_functions a lot clearer.
Yes, x86 does a lot more in those than other architectures, but even on non-x86, they have a purpose even if one decides to do the "core" work inside swsusp_arch_suspend/resume().

I'll go back to the drawing board for the ARM patch again for a bit.

It might be useful/necessary to delegate some of the functionality actually into save/restore_processor_state, like powerpc does (call flush_thread() to store lazy-save state, and maybe, if necessary, do some of the things the cpu_idle code on ARM does before going down into cpu_suspend).

John reported a crash on resume (on OMAP4) related to FP state; I've done some tracing here to see whether the PM notifiers for storing the VFP/FPU state on ARM are actually triggering with the suggested change and they're not, which means there's still some work to do here.

The last thing here in my setup that's obviously not correctly suspending / resuming is the OMAP display driver; I'm not the only one with that problem, Matt's previous report:

http://blog.gmane.org/gmane.linux.swsusp.devel/month=20101201

has the same thing, "omapdss DISPC error: SYNC_LOST, disabling LCD".

I'll provide an update before Easter.

Thanks for the help so far!
FrankH.

Quoted 222 lines · Rafael J. Wysocki
Quoted 20 lines · Frank Hofmann
Quoted 1 line · Pavel Machek

Hi!

[ ... ]

Quoted 7 lines
Quoted 4 lines

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

You might need to dig a bit more. IIRC it manipulated FPU or something long time ago.

Actually, it's the other way round - kernel_fpu_begin/end are users of preempt_disable/enable, quote Documentation/preempt-locking.txt:

(quoted diff) +0 -0
 	Note, some FPU functions are already explicitly preempt safe.  For example,
 	kernel_fpu_begin and kernel_fpu_end will disable and enable preemption.
 	However, math_state_restore must be called with preemption disabled.
Quoted 3 lines

But kernel_fpu_begin/end functions are x86-specific. At best, that makes the comment in hibernate.c (which refers to "needing" preempt_dis/enable) misleading.

This comment is outright wrong in fact, sorry about that. Evidently, restore_processor_state() is called right after the "restore control flow magically appears here" comment and it _does_ use the saved state.

I'll remove that comment.

Quoted 9 lines

x86, in this, is an odd one out, though, in ; On ARM, for example, saving the FP context happens through a PM notifier.

In addition, it seems that the code (at least in hibernate.c, create_image) does anyway:

(quoted diff) +0 -0
 	- go single-cpu (disables all but current)
 	- switch interrupts off (local_irq_disable)
Quoted 3 lines

before going into save_processor_state - wouldn't that mean all conditions for nonpreemptable (or all conditions for a stable FP state) are already met by that time ?

Yes, it does.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Finally, on things like e.g. the floating point context saves:
Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ?

Are you sure? I thought we have (had?) concept of lazy FPU saving... and occassionaly kernel uses FPU too (with some precautions).

Quoted 6 lines

speaking in particular for ARM, I'd deflect the answer to:

http://www.spinics.net/lists/linux-pm/msg22839.html

It's lazy but it does happen ... without any specific need to have the "bracketing" that save/restore_processor_state are doing.

save/restore_processor_state() are arch-specific and do whatever is necessary or useful for the given architecture. The saving/restoring of the FPU state at those points happens to be useful for x86 IIRC.

Quoted 10 lines

Food for thought:

I mean, the code in hibernate.c really looks like this (quote):

static int create_image(int platform_mode)

{
         int error;

         error = arch_prepare_suspend();				<===== platform hook 1

Architecture hook rather and it would have been one if there had been any architecture actually providing anything different from a NOP. IOW, to be removed (forgot about it last time I did a code cleanup).

Quoted 2 lines

[ ... ]

         error = dpm_suspend_noirq(PMSG_FREEZE);			<===== platform hook 2

Not really. This is a device core callback for the last stage of device freeze.

Quoted 2 lines

[ ... ]

         error = platform_pre_snapshot(platform_mode);		<===== platform hook 3

This is a platform hook.

Quoted 2 lines

[ ... ]

         error = disable_nonboot_cpus();				<===== platform hook 4

Not a platform hook. This one disables the nonboot CPUs using hotplug and this mechanism is supposed to work that way on all platforms.

Quoted 5 lines

[ ... ]

         error = sysdev_suspend(PMSG_FREEZE);			<===== ...
         if (!error)
                 error = syscore_suspend();			<===== ...

[ ... ]

These suspend things that are "below" devices (like interrupt controllers and such stuff) and by no means are platform hooks.

Quoted 2 lines
         in_suspend = 1;
         save_processor_state();					<===== platform hook N-1

This is an architecture hook for saving the state of the boot CPU.

Quoted 1 line
         error = swsusp_arch_suspend();				<===== platform hook N

This one is needed on x86 so that we can point the CPU to the original page tables after we've restored the target kernel from the image.

Quoted 6 lines

[ ... ]

         restore_processor_state();				<===== platform hook N+1

[ ... ]

And that's _without_ the platform hibernation ops hooks code in hibernate(), which calls this one.

Actually not without, platform_pre_snapshot() is one of those.

Quoted 9 lines

This code is full of places where to plug save/restore code (or any sort of "bracketing" begin/finish hooks) into.
It's surprising that with all these hooks existing already, "bracketing" of swsusp_arch_suspend() by save/restore_processor state is so sacrosanct.

These are _three_ arch-dependent hooks in three consecutive lines of code.

If a platform requires the bracketing, why can it not do that part in syscore_suspend() ? Or why not simply embed it in swsusp_arch_suspend() ?

save/restore_processor_state() are also used by the x86's suspend to RAM code. Of course, you can argue that they should be kept x86-specific, but since those features were originally developed on x86, the code still remains x86-centric in that respect.

Quoted 7 lines

As said, wrt. to save/restore_processor_state, x86 is definitely the odd one out (and not a good example) with the monstrosity of code; all other architectures either have trivial or even completely empty code for save/restore_processor_state().

Should we really force everyone to provide an (as good as) empty hook just because x86 at one point had chosen to have it ?

I don't see much reason for that, but since none of the guys who implemented those empty hooks has ever complained and/or attempted to change things, there has not been much reason to work in that direction. :-)

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

Review config VECTORS_BASE · line 204

Quoted 11 lines
(quoted diff) +7 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Quoted 4 lines
Quoted 1 line

How would this be done better ?

Just set the ARCH_HIBERNATION_POSSIBLE=y in the ARM code now that ARM can do it. No need to ask user.

I.e. preferrably:

Review

Quoted 2 lines
(quoted diff) +0 -0
 	config ARCH_HIBERNATION_POSSIBLE
 		def_bool n

You don't need to use "def_bool n", "bool" alone will do just fine.

Quoted 8 lines

plus the "select" within the actual platform config subsection for those that have it.

To stress the point: "ARM can do it" would be an exaggeration even if those changes went in, because only some ARM types will have it.

The situation on ARM is identical to e.g. SuperH, see arch/sh/Kconfig,

Quoted 8 lines

config SUPERH32
def_bool ARCH = "sh"
[ ... various ... ]
select ARCH_HIBERNATION_POSSIBLE if MMU

config ARCH_HIBERNATION_POSSIBLE
def_bool n

Yes, something like this.

Quoted 7 lines
Quoted 7 lines

Review static int resume_target_kernel(bool platform_mode) · line 416

Quoted 7 lines
(quoted diff) +1 -2
@@ -412,8 +413,7 @@ static int resume_target_kernel(bool platform_mode)
 	if (error)
 		goto Enable_irqs;
 
-	/* We'll ignore saved state, but this gets preempt count (etc) right */
-	save_processor_state();
+	preempt_disable();

Why do you need that preempt_disable() here?

Quoted 9 lines
Quoted 6 lines

Review static int resume_target_kernel(bool platform_mode) · line 419

Quoted 3 lines
(quoted diff) +0 -0
 	error = restore_highmem();
 	if (!error) {
 		error = swsusp_arch_resume();

Yep. save_processor_state() on x86 does kernel_fpu_begin(), and than one needs to be balanced IIRC.

The needs of x86 force generic kernel changes ;-)

Not necessarily. In fact, implementing that feature on different architectures is a good opportunity to clean up the code if necessary.

Thanks,
Rafael

#20 lore raw
In reply to Frank Hofmann
Quoted 20 lines · Frank Hofmann
Quoted 1 line · Pavel Machek

Hi!

[ ... ]

Quoted 7 lines
Quoted 4 lines

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

You might need to dig a bit more. IIRC it manipulated FPU or something long time ago.

Actually, it's the other way round - kernel_fpu_begin/end are users of preempt_disable/enable, quote Documentation/preempt-locking.txt:

(quoted diff) +0 -0
 	Note, some FPU functions are already explicitly preempt safe.  For example,
 	kernel_fpu_begin and kernel_fpu_end will disable and enable preemption.
 	However, math_state_restore must be called with preemption disabled.
Quoted 3 lines

But kernel_fpu_begin/end functions are x86-specific. At best, that makes the comment in hibernate.c (which refers to "needing" preempt_dis/enable) misleading.

This comment is outright wrong in fact, sorry about that. Evidently, restore_processor_state() is called right after the "restore control flow magically appears here" comment and it _does_ use the saved state.

I'll remove that comment.

Quoted 9 lines

x86, in this, is an odd one out, though, in ; On ARM, for example, saving the FP context happens through a PM notifier.

In addition, it seems that the code (at least in hibernate.c, create_image) does anyway:

(quoted diff) +0 -0
 	- go single-cpu (disables all but current)
 	- switch interrupts off (local_irq_disable)
Quoted 3 lines

before going into save_processor_state - wouldn't that mean all conditions for nonpreemptable (or all conditions for a stable FP state) are already met by that time ?

Yes, it does.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Finally, on things like e.g. the floating point context saves:
Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ?

Are you sure? I thought we have (had?) concept of lazy FPU saving... and occassionaly kernel uses FPU too (with some precautions).

Quoted 6 lines

speaking in particular for ARM, I'd deflect the answer to:

http://www.spinics.net/lists/linux-pm/msg22839.html

It's lazy but it does happen ... without any specific need to have the "bracketing" that save/restore_processor_state are doing.

save/restore_processor_state() are arch-specific and do whatever is necessary or useful for the given architecture. The saving/restoring of the FPU state at those points happens to be useful for x86 IIRC.

Quoted 10 lines

Food for thought:

I mean, the code in hibernate.c really looks like this (quote):

static int create_image(int platform_mode)

{
         int error;

         error = arch_prepare_suspend();				<===== platform hook 1

Architecture hook rather and it would have been one if there had been any architecture actually providing anything different from a NOP. IOW, to be removed (forgot about it last time I did a code cleanup).

Quoted 2 lines

[ ... ]

         error = dpm_suspend_noirq(PMSG_FREEZE);			<===== platform hook 2

Not really. This is a device core callback for the last stage of device freeze.

Quoted 2 lines

[ ... ]

         error = platform_pre_snapshot(platform_mode);		<===== platform hook 3

This is a platform hook.

Quoted 2 lines

[ ... ]

         error = disable_nonboot_cpus();				<===== platform hook 4

Not a platform hook. This one disables the nonboot CPUs using hotplug and this mechanism is supposed to work that way on all platforms.

Quoted 5 lines

[ ... ]

         error = sysdev_suspend(PMSG_FREEZE);			<===== ...
         if (!error)
                 error = syscore_suspend();			<===== ...

[ ... ]

These suspend things that are "below" devices (like interrupt controllers and such stuff) and by no means are platform hooks.

Quoted 2 lines
         in_suspend = 1;
         save_processor_state();					<===== platform hook N-1

This is an architecture hook for saving the state of the boot CPU.

Quoted 1 line
         error = swsusp_arch_suspend();				<===== platform hook N

This one is needed on x86 so that we can point the CPU to the original page tables after we've restored the target kernel from the image.

Quoted 6 lines

[ ... ]

         restore_processor_state();				<===== platform hook N+1

[ ... ]

And that's _without_ the platform hibernation ops hooks code in hibernate(), which calls this one.

Actually not without, platform_pre_snapshot() is one of those.

Quoted 9 lines

This code is full of places where to plug save/restore code (or any sort of "bracketing" begin/finish hooks) into.
It's surprising that with all these hooks existing already, "bracketing" of swsusp_arch_suspend() by save/restore_processor state is so sacrosanct.

These are _three_ arch-dependent hooks in three consecutive lines of code.

If a platform requires the bracketing, why can it not do that part in syscore_suspend() ? Or why not simply embed it in swsusp_arch_suspend() ?

save/restore_processor_state() are also used by the x86's suspend to RAM code. Of course, you can argue that they should be kept x86-specific, but since those features were originally developed on x86, the code still remains x86-centric in that respect.

Quoted 7 lines

As said, wrt. to save/restore_processor_state, x86 is definitely the odd one out (and not a good example) with the monstrosity of code; all other architectures either have trivial or even completely empty code for save/restore_processor_state().

Should we really force everyone to provide an (as good as) empty hook just because x86 at one point had chosen to have it ?

I don't see much reason for that, but since none of the guys who implemented those empty hooks has ever complained and/or attempted to change things, there has not been much reason to work in that direction. :-)

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

Review config VECTORS_BASE · line 204

Quoted 11 lines
(quoted diff) +7 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Quoted 4 lines
Quoted 1 line

How would this be done better ?

Just set the ARCH_HIBERNATION_POSSIBLE=y in the ARM code now that ARM can do it. No need to ask user.

I.e. preferrably:

Review

Quoted 2 lines
(quoted diff) +0 -0
 	config ARCH_HIBERNATION_POSSIBLE
 		def_bool n

You don't need to use "def_bool n", "bool" alone will do just fine.

Quoted 8 lines

plus the "select" within the actual platform config subsection for those that have it.

To stress the point: "ARM can do it" would be an exaggeration even if those changes went in, because only some ARM types will have it.

The situation on ARM is identical to e.g. SuperH, see arch/sh/Kconfig,

Quoted 8 lines

config SUPERH32
def_bool ARCH = "sh"
[ ... various ... ]
select ARCH_HIBERNATION_POSSIBLE if MMU

config ARCH_HIBERNATION_POSSIBLE
def_bool n

Yes, something like this.

Quoted 7 lines
Quoted 7 lines

Review static int resume_target_kernel(bool platform_mode) · line 416

Quoted 7 lines
(quoted diff) +1 -2
@@ -412,8 +413,7 @@ static int resume_target_kernel(bool platform_mode)
 	if (error)
 		goto Enable_irqs;
 
-	/* We'll ignore saved state, but this gets preempt count (etc) right */
-	save_processor_state();
+	preempt_disable();

Why do you need that preempt_disable() here?

Quoted 9 lines
Quoted 6 lines

Review static int resume_target_kernel(bool platform_mode) · line 419

Quoted 3 lines
(quoted diff) +0 -0
 	error = restore_highmem();
 	if (!error) {
 		error = swsusp_arch_resume();

Yep. save_processor_state() on x86 does kernel_fpu_begin(), and than one needs to be balanced IIRC.

The needs of x86 force generic kernel changes ;-)

Not necessarily. In fact, implementing that feature on different architectures is a good opportunity to clean up the code if necessary.

Thanks,
Rafael

#21 lore raw
In reply to Pavel Machek
Quoted 1 line · Pavel Machek

Hi!

[ ... ]

Quoted 7 lines
Quoted 4 lines

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

You might need to dig a bit more. IIRC it manipulated FPU or something long time ago.

Actually, it's the other way round - kernel_fpu_begin/end are users of preempt_disable/enable, quote Documentation/preempt-locking.txt:

Note, some FPU functions are already explicitly preempt safe. For example, kernel_fpu_begin and kernel_fpu_end will disable and enable preemption. However, math_state_restore must be called with preemption disabled.

But kernel_fpu_begin/end functions are x86-specific. At best, that makes the comment in hibernate.c (which refers to "needing" preempt_dis/enable) misleading.

x86, in this, is an odd one out, though, in ; On ARM, for example, saving the FP context happens through a PM notifier.

In addition, it seems that the code (at least in hibernate.c, create_image) does anyway:

- go single-cpu (disables all but current)
- switch interrupts off (local_irq_disable)

before going into save_processor_state - wouldn't that mean all conditions for nonpreemptable (or all conditions for a stable FP state) are already met by that time ?

Quoted 8 lines
Quoted 4 lines

Finally, on things like e.g. the floating point context saves:
Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ?

Are you sure? I thought we have (had?) concept of lazy FPU saving... and occassionaly kernel uses FPU too (with some precautions).

speaking in particular for ARM, I'd deflect the answer to:

http://www.spinics.net/lists/linux-pm/msg22839.html

It's lazy but it does happen ... without any specific need to have the "bracketing" that save/restore_processor_state are doing.

Food for thought:

I mean, the code in hibernate.c really looks like this (quote):

static int create_image(int platform_mode)

{
         int error;

         error = arch_prepare_suspend();				<===== platform hook 1
[ ... ]
         error = dpm_suspend_noirq(PMSG_FREEZE);			<===== platform hook 2
[ ... ]
         error = platform_pre_snapshot(platform_mode);		<===== platform hook 3
[ ... ]
         error = disable_nonboot_cpus();				<===== platform hook 4
[ ... ]
         error = sysdev_suspend(PMSG_FREEZE);			<===== ...
         if (!error)
                 error = syscore_suspend();			<===== ...
[ ... ]
         in_suspend = 1;
         save_processor_state();					<===== platform hook N-1
         error = swsusp_arch_suspend();				<===== platform hook N
[ ... ]
         restore_processor_state();				<===== platform hook N+1

[ ... ]

And that's _without_ the platform hibernation ops hooks code in hibernate(), which calls this one.

This code is full of places where to plug save/restore code (or any sort of "bracketing" begin/finish hooks) into.
It's surprising that with all these hooks existing already, "bracketing" of swsusp_arch_suspend() by save/restore_processor state is so sacrosanct.

These are _three_ arch-dependent hooks in three consecutive lines of code.

If a platform requires the bracketing, why can it not do that part in syscore_suspend() ? Or why not simply embed it in swsusp_arch_suspend() ?

As said, wrt. to save/restore_processor_state, x86 is definitely the odd one out (and not a good example) with the monstrosity of code; all other architectures either have trivial or even completely empty code for save/restore_processor_state().

Should we really force everyone to provide an (as good as) empty hook just because x86 at one point had chosen to have it ?

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

Review config VECTORS_BASE · line 204

Quoted 12 lines
(quoted diff) +7 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Quoted 4 lines
Quoted 1 line

How would this be done better ?

Just set the ARCH_HIBERNATION_POSSIBLE=y in the ARM code now that ARM can do it. No need to ask user.

I.e. preferrably:

config ARCH_HIBERNATION_POSSIBLE
def_bool n

plus the "select" within the actual platform config subsection for those that have it.

To stress the point: "ARM can do it" would be an exaggeration even if those changes went in, because only some ARM types will have it.

The situation on ARM is identical to e.g. SuperH, see arch/sh/Kconfig,

config SUPERH32
def_bool ARCH = "sh"
[ ... various ... ]
select ARCH_HIBERNATION_POSSIBLE if MMU

config ARCH_HIBERNATION_POSSIBLE
def_bool n

Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
@@ -412,8 +413,7 @@ static int resume_target_kernel(bool platform_mode)
 	if (error)
 		goto Enable_irqs;
 
Quoted 9 lines

Review static int resume_target_kernel(bool platform_mode) · line 419

Quoted 6 lines
(quoted diff) +1 -2
-	/* We'll ignore saved state, but this gets preempt count (etc) right */
-	save_processor_state();
+	preempt_disable();
 	error = restore_highmem();
 	if (!error) {
 		error = swsusp_arch_resume();

Yep. save_processor_state() on x86 does kernel_fpu_begin(), and than one needs to be balanced IIRC.

The needs of x86 force generic kernel changes ;-)

FrankH.

Quoted 6 lines

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#22 lore raw
In reply to Frank Hofmann

Hi!

Quoted 13 lines
Quoted 8 lines
Quoted 6 lines

There's one ugly thing in this set - I've changed a generic kernel header, <linux/suspend.h> to #define save/restore_processor_state() on ARM so that it only does preempt_disable/enable(). It's surprising that this isn't the default behaviour; all platforms need swsusp_arch_suspend/resume anyway so why force the existance of _two_ arch-specific hooks ?

Can you submit separate patch cleaning it up?

How about the attached ?

It's for discussion, and hence not tested (admittedly, I need an x86 test system ...).

...

Quoted 10 lines

I've also been wondering:
The comments in kernel/power/hibernate.c mention the need to get preempt counts "right" as major motivator to call save/restore_processor_state.
effect" of save/restore_processor_state).

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

You might need to dig a bit more. IIRC it manipulated FPU or something long time ago.

Quoted 3 lines

Finally, on things like e.g. the floating point context saves:
Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ?

Are you sure? I thought we have (had?) concept of lazy FPU saving... and occassionaly kernel uses FPU too (with some precautions).

Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
Quoted 9 lines

Review config VECTORS_BASE · line 204

Quoted 7 lines
(quoted diff) +7 -0
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Quoted 1 line

How would this be done better ?

Just set the ARCH_HIBERNATION_POSSIBLE=y in the ARM code now that ARM can do it. No need to ask user.

Review static int resume_target_kernel(bool platform_mode) · line 419

Quoted 10 lines
(quoted diff) +1 -2
@@ -412,8 +413,7 @@ static int resume_target_kernel(bool platform_mode)
 	if (error)
 		goto Enable_irqs;
 
-	/* We'll ignore saved state, but this gets preempt count (etc) right */
-	save_processor_state();
+	preempt_disable();
 	error = restore_highmem();
 	if (!error) {
 		error = swsusp_arch_resume();

Yep. save_processor_state() on x86 does kernel_fpu_begin(), and than one needs to be balanced IIRC.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#23 lore raw
In reply to Pavel Machek
Quoted 10 lines · Pavel Machek

Hi!

Quoted 6 lines

There's one ugly thing in this set - I've changed a generic kernel header, <linux/suspend.h> to #define save/restore_processor_state() on ARM so that it only does preempt_disable/enable(). It's surprising that this isn't the default behaviour; all platforms need swsusp_arch_suspend/resume anyway so why force the existance of _two_ arch-specific hooks ?

Can you submit separate patch cleaning it up?

How about the attached ?

It's for discussion, and hence not tested (admittedly, I need an x86 test system ...).

The diff is against RMK's devel-stable tree, as of commit 5f183860d5007ec76ea36bfa6c36d66e37f0dbcf

There's a few hurdles here:

a) who knows all assembly calling conventions for all architectures supported by linux ?

This applies to SH and S390; save/restore_processor_state on those are primitive and should be inlined within swsusp_arch_suspend/resume, just like the attached patch does for the powerpc variants.

I've done a bounce call within S390 but don't know enough about SH3 for arch/sh/kernel/cpu/sh3/swsusp.S - i.e. add a call in assembly to init_cpu(current), and then ditch save_processor_state.

b) some architectures do things _beyond_ register/state saving in those two functions, and hence rely on them being called paired.

c) CONFIG_KEXEC_JUMP (ab-)uses them. I don't know that subsystem at all, but this sort of re-use means the symbols can't just be ditched. They become arch-dependent though, no non-arch/ code calls them anymore.

What I've attached might break SH3 swsusp, as save_processor_state is no longer called there (it stores FPU state).

I've also been wondering:
The comments in kernel/power/hibernate.c mention the need to get preempt counts "right" as major motivator to call save/restore_processor_state. effect" of save/restore_processor_state).

But then on all architectures in kernels as far back as 2.6.32 it doesn't look like save/restore_processor state are actually adjusting the preempt count; nowhere do they call preempt_enable/disable.

What is and what is not necessary, really ?

Finally, on things like e.g. the floating point context saves: Wouldn't this happen as part of freezing processes (in the early stages of suspend), and/or as part of device quiesce ? I wonder why e.g. powerpc does it explicitly; not doing so on ARM doesn't seem to cause problems.

Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
Quoted 9 lines

Review config VECTORS_BASE · line 204

Quoted 7 lines
(quoted diff) +7 -0
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

How would this be done better ?

FrankH.

Quoted 5 lines
Signature · 3 lines
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
 arch/mips/power/hibernate.S        |    8 ++++++-
 arch/powerpc/kernel/swsusp.c       |   39 ------------------------------------
 arch/powerpc/kernel/swsusp_32.S    |   18 ++++++++++++++++
 arch/powerpc/kernel/swsusp_asm64.S |   21 +++++++++++++++++++
 arch/powerpc/kernel/swsusp_booke.S |   19 +++++++++++++++++
 arch/s390/kernel/swsusp_asm64.S    |    6 +++++
 arch/sh/kernel/swsusp.c            |    5 ----
 arch/unicore32/kernel/hibernate.c  |    9 --------
 arch/x86/power/hibernate_asm_32.S  |    4 ++-
 arch/x86/power/hibernate_asm_64.S  |    2 +
 include/linux/suspend.h            |    2 +
 kernel/power/hibernate.c           |   10 ++++----
 12 files changed, 83 insertions(+), 60 deletions(-)
arch/mips/power/hibernate.S +7 -1
index dbb5c7b..1b12ae1 100644
@@ -27,6 +27,9 @@ LEAF(swsusp_arch_suspend)
 	PTR_S s5, PT_R21(t0)
 	PTR_S s6, PT_R22(t0)
 	PTR_S s7, PT_R23(t0)
+	jal save_processor_state
+	PTR_LA t0, saved_regs
+	PTR_L ra, PT_R31(t0)
 	j swsusp_save
 END(swsusp_arch_suspend)
 
@@ -45,7 +48,6 @@ LEAF(swsusp_arch_resume)
 	PTR_L t0, PBE_NEXT(t0)
 	bnez t0, 0b
 	PTR_LA t0, saved_regs
-	PTR_L ra, PT_R31(t0)
 	PTR_L sp, PT_R29(t0)
 	PTR_L fp, PT_R30(t0)
 	PTR_L gp, PT_R28(t0)
@@ -57,6 +59,10 @@ LEAF(swsusp_arch_resume)
 	PTR_L s5, PT_R21(t0)
 	PTR_L s6, PT_R22(t0)
 	PTR_L s7, PT_R23(t0)
+	jal restore_processor_state
+	PTR_LA t0, saved_regs
+	PTR_L ra, PT_R31(t0)
+
 	PTR_LI v0, 0x0
 	jr ra
 END(swsusp_arch_resume)
arch/powerpc/kernel/swsusp.c deleted +0 -39
deleted file mode 100644
index 560c961..0000000
@@ -1,39 +0,0 @@
-/*
- * Common powerpc suspend code for 32 and 64 bits
- *
- * Copyright 2007	Johannes Berg <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
-
-#include <linux/sched.h>
-#include <asm/suspend.h>
-#include <asm/system.h>
-#include <asm/current.h>
-#include <asm/mmu_context.h>
-
-void save_processor_state(void)
-{
-	/*
-	 * flush out all the special registers so we don't need
-	 * to save them in the snapshot
-	 */
-	flush_fp_to_thread(current);
-	flush_altivec_to_thread(current);
-	flush_spe_to_thread(current);
-
-#ifdef CONFIG_PPC64
-	hard_irq_disable();
-#endif
-
-}
-
-void restore_processor_state(void)
-{
-#ifdef CONFIG_PPC32
-	switch_mmu_context(NULL, current->active_mm);
-#endif
-}
arch/powerpc/kernel/swsusp_32.S +18 -0
index b0754e2..08137c5 100644
@@ -116,6 +116,16 @@ _GLOBAL(swsusp_arch_suspend)
 	/* Backup various CPU config stuffs */
 	bl	__save_cpu_setup
 #endif
+	/* flush out all the special registers so we don't need
+	 * to save them in the snapshot
+	 */
+	tophys(r4,r2);
+	bl	flush_fp_to_thread
+	tophys(r4,r2);
+	bl	flush_altivec_to_thread
+	tophys(r4,r2);
+	bl	flush_spe_to_thread
+
 	/* Call the low level suspend stuff (we should probably have made
 	 * a stackframe...
 	 */
@@ -323,6 +333,14 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
 	li	r0,1
 	mtdec	r0
 
+	/* restore MMU context - switch_mmu_context(NULL, current->mm); */
+	li	r3,0
+	/* 'current->mm' needs to be in r4 */
+	tophys(r4, r2)
+	lwz     r4, MM(r4)
+	tophys(r4, r4)
+	bl      switch_mmu_context
+
 	/* Restore the callee-saved registers and return */
 	lwz	r0,SL_CR(r11)
 	mtcr	r0
arch/powerpc/kernel/swsusp_asm64.S +21 -0
index 86ac1d9..e46786d 100644
@@ -76,8 +76,29 @@ restore_pblist_ptr:
 	.section .text
 	.align  5
 _GLOBAL(swsusp_arch_suspend)
+	/* Save LR first so that we can make function calls */
 	ld	r11,swsusp_save_area_ptr@toc(r2)
 	SAVE_SPECIAL(LR)
+
+	/* flush out all the special registers so we don't need
+	 * to save them in the snapshot
+	 */
+	ld	r3,PACACURRENT(r13)
+	bl flush_fp_to_thread
+	ld	r3,PACACURRENT(r13)
+	bl flush_altivec_to_thread
+	ld	r3,PACACURRENT(r13)
+	bl flush_spe_to_thread
+	/* Disable interrupts now */
+	mfmsr	r4		/* Get current interrupt state */
+	rldicu	r3,r4,48,1	/* clear MSR_EE */
+	rotldi	r3,r3,16
+	mtmsrd	r3,1		/* Update machine state */
+	li	r3,0
+	stb	r3,PACASOFTIRQEN(r13)
+	stb	r3,PACAHARDIRQEN(r13)
+
+	ld	r11,swsusp_save_area_ptr@toc(r2)
 	SAVE_REGISTER(r1)
 	SAVE_SPECIAL(CR)
 	SAVE_SPECIAL(TB)
arch/powerpc/kernel/swsusp_booke.S +19 -0
index 11a3930..529e95b 100644
@@ -50,8 +50,27 @@ _GLOBAL(swsusp_arch_suspend)
 	lis	r11,swsusp_save_area@h
 	ori	r11,r11,swsusp_save_area@l
 
+	/* save LR first so we can make function calls */
 	mflr	r0
 	stw	r0,SL_LR(r11)
+
+	/* flush out all the special registers so we don't need
+	 * to save them in the snapshot
+	 */
+	ld	r3,PACACURRENT(r13)
+	bl flush_fp_to_thread
+	ld	r3,PACACURRENT(r13)
+	bl flush_altivec_to_thread
+	ld	r3,PACACURRENT(r13)
+	bl flush_spe_to_thread
+	/* Disable interrupts now */
+	wrteei	0
+	li	r0,0
+	stb	r0,PACASOFTIRQEN(r13)
+	stb	r0,PACAHARDIRQEN(r13)
+
+	lis	r11,swsusp_save_area@h
+	ori	r11,r11,swsusp_save_area@l
 	mfcr	r0
 	stw	r0,SL_CR(r11)
 	stw	r1,SL_SP(r11)
arch/s390/kernel/swsusp_asm64.S +6 -0
index 1f066e4..00cceff 100644
@@ -25,6 +25,8 @@
 	.align	4
 	.globl swsusp_arch_suspend
 swsusp_arch_suspend:
+	brasl	%r14,save_processor_state	/* disables lowcore protection */
+
 	stmg	%r6,%r15,__SF_GPRS(%r15)
 	lgr	%r1,%r15
 	aghi	%r15,-STACK_FRAME_OVERHEAD
@@ -100,6 +102,8 @@ swsusp_arch_suspend:
 	/* Save image */
 	brasl	%r14,swsusp_save
 
+	brasl	%r14,restore_processor_state
+
 	/* Restore prefix register and return */
 	lghi	%r1,0x1000
 	spx	0x318(%r1)
@@ -259,6 +263,8 @@ restore_registers:
 	/* Reinitialize the channel subsystem */
 	brasl	%r14,channel_subsystem_reinit
 
+	/* reenable lowcore protection */
+	brasl	%r14,restore_processor_state
 	/* Return 0 */
 	lmg	%r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
 	lghi	%r2,0
arch/sh/kernel/swsusp.c +0 -5
index 12b64a0..65a964e 100644
@@ -31,8 +31,3 @@ void save_processor_state(void)
 {
 	init_fpu(current);
 }
-
-void restore_processor_state(void)
-{
-	local_flush_tlb_all();
-}
arch/unicore32/kernel/hibernate.c +0 -9
index 7d0f0b7..aba4ad4 100644
@@ -149,12 +149,3 @@ int pfn_is_nosave(unsigned long pfn)
 
 	return (pfn >= begin_pfn) && (pfn < end_pfn);
 }
-
-void save_processor_state(void)
-{
-}
-
-void restore_processor_state(void)
-{
-	local_flush_tlb_all();
-}
arch/x86/power/hibernate_asm_32.S +3 -1
index ad47dae..6827e1b 100644
@@ -15,6 +15,7 @@
 .text
 
 ENTRY(swsusp_arch_suspend)
+	call save_processor_state
 	movl %esp, saved_context_esp
 	movl %ebx, saved_context_ebx
 	movl %ebp, saved_context_ebp
@@ -22,7 +23,6 @@ ENTRY(swsusp_arch_suspend)
 	movl %edi, saved_context_edi
 	pushfl
 	popl saved_context_eflags
-
 	call swsusp_save
 	ret
 
@@ -75,6 +75,8 @@ done:
 	pushl saved_context_eflags
 	popfl
 
+	call restore_processor_state
+
 	xorl	%eax, %eax
 
 	ret
arch/x86/power/hibernate_asm_64.S +2 -0
index 9356547..1318398 100644
@@ -23,6 +23,7 @@
 #include <asm/processor-flags.h>
 
 ENTRY(swsusp_arch_suspend)
+	call save_processor_state
 	movq	$saved_context, %rax
 	movq	%rsp, pt_regs_sp(%rax)
 	movq	%rbp, pt_regs_bp(%rax)
@@ -139,6 +140,7 @@ ENTRY(restore_registers)
 	pushq	pt_regs_flags(%rax)
 	popfq
 
+	call restore_processor_state
 	xorq	%rax, %rax
 
 	/* tell the hibernation core that we've just restored the memory */
include/linux/suspend.h +2 -0
index 5a89e36..145d9a4 100644
@@ -259,8 +259,10 @@ static inline bool system_entering_hibernation(void) { return false; }
 #endif /* CONFIG_HIBERNATION */
 
 #ifdef CONFIG_PM_SLEEP
+#ifdef CONFIG_KEXEC_JUMP
 void save_processor_state(void);
 void restore_processor_state(void);
+#endif
 
 /* kernel/power/main.c */
 extern int register_pm_notifier(struct notifier_block *nb);
kernel/power/hibernate.c +5 -5
index aeabd26..554b741 100644
@@ -285,13 +285,14 @@ static int create_image(int platform_mode)
 		goto Power_up;
 
 	in_suspend = 1;
-	save_processor_state();
+	preempt_disable();
 	error = swsusp_arch_suspend();
 	if (error)
 		printk(KERN_ERR "PM: Error %d creating hibernation image\n",
 			error);
 	/* Restore control flow magically appears here */
-	restore_processor_state();
+	flush_tlb_all();
+	preempt_enable();
 	if (!in_suspend) {
 		events_check_enabled = false;
 		platform_leave(platform_mode);
@@ -412,8 +413,7 @@ static int resume_target_kernel(bool platform_mode)
 	if (error)
 		goto Enable_irqs;
 
-	/* We'll ignore saved state, but this gets preempt count (etc) right */
-	save_processor_state();
+	preempt_disable();
 	error = restore_highmem();
 	if (!error) {
 		error = swsusp_arch_resume();
@@ -432,7 +432,7 @@ static int resume_target_kernel(bool platform_mode)
 	 * subsequent failures
 	 */
 	swsusp_free();
-	restore_processor_state();
+	preempt_enable();
 	touch_softlockup_watchdog();
 
 	syscore_resume();
#24 lore raw
In reply to Frank Hofmann

Hi!

Quoted 6 lines

There's one ugly thing in this set - I've changed a generic kernel header, <linux/suspend.h> to #define save/restore_processor_state() on ARM so that it only does preempt_disable/enable(). It's surprising that this isn't the default behaviour; all platforms need swsusp_arch_suspend/resume anyway so why force the existance of _two_ arch-specific hooks ?

Can you submit separate patch cleaning it up?

Review config VECTORS_BASE · line 204

Quoted 11 lines
(quoted diff) +7 -0
@@ -195,6 +195,14 @@ config VECTORS_BASE
 	help
 	  The base address of exception vectors.
 
+config ARCH_HIBERNATION_POSSIBLE
+	bool
+	help
+	  If the machine architecture supports suspend-to-disk
+	  it should select this automatically for you.
+	  Otherwise, say 'Y' at your own peril.
+

Good for debugging, but not good for mainline.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html