Skip to contentSkip to conversation

swsusp_restore crap

DISCUSSION Benjamin Herrenschmidt 3 participants 12 messages Mar 15, 2005 – Mar 16, 2005

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

Hi Pavel !

Please kill that swsusp_restore() call that itself calls flush_tlb_global(), it's junk. First, the flush_tlb_global() thing is arch specific, and that's all swsusp_restore() does. Then, the asm just calls this before returning to C code, so it makes no sense to have a hook there. The x86 asm can have it's own call to some arch stuff if it wants or just do the tlb flush in asm...

Ben.

#1 lore raw
Quoted 8 lines · Benjamin Herrenschmidt

Hi Pavel !

Please kill that swsusp_restore() call that itself calls flush_tlb_global(), it's junk. First, the flush_tlb_global() thing is arch specific, and that's all swsusp_restore() does. Then, the asm just calls this before returning to C code, so it makes no sense to have a hook there. The x86 asm can have it's own call to some arch stuff if it wants or just do the tlb flush in asm...

Better, here is a patch... (note: flush_tlb_global() is an x86'ism, doesn't exist on ppc, thus breaks compile, and that has nothing to do in the generic code imho, it should be clearly defined as the responsibility of the asm code).

--

This patch removes the quite x86-specific swsusp_restore() hook from the generic swsusp code and moves it to arch/i386. This also fixes build on ppc with swsusp enabled.

arch/i386/power/swsusp.S +1 -1
Index: linux-work/arch/i386/power/swsusp.S
===================================================================
@@ -58,5 +58,5 @@
 	movl saved_context_edi, %edi
 
 	pushl saved_context_eflags ; popfl
-	call swsusp_restore
+	call __swsusp_flush_tlb
 	ret
arch/i386/power/cpu.c +9 -0
Index: linux-work/arch/i386/power/cpu.c
===================================================================
@@ -147,6 +147,15 @@
 	__restore_processor_state(&saved_context);
 }
 
+asmlinkage int __swsusp_flush_tlb(void)
+{
+	BUG_ON (nr_copy_pages_check != nr_copy_pages);
+	
+	/* Even mappings of "global" things (vmalloc) need to be fixed */
+	__flush_tlb_global();
+	return 0;
+}
+
 /* Needed by apm.c */
 EXPORT_SYMBOL(save_processor_state);
 EXPORT_SYMBOL(restore_processor_state);
kernel/power/swsusp.c +0 -9
Index: linux-work/kernel/power/swsusp.c
===================================================================
@@ -907,15 +907,6 @@
 }
 
 
-asmlinkage int swsusp_restore(void)
-{
-	BUG_ON (nr_copy_pages_check != nr_copy_pages);
-	
-	/* Even mappings of "global" things (vmalloc) need to be fixed */
-	__flush_tlb_global();
-	return 0;
-}
-
 int swsusp_resume(void)
 {
 	int error;
#2 lore raw
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 8 lines · Benjamin Herrenschmidt

Hi Pavel !

Please kill that swsusp_restore() call that itself calls flush_tlb_global(), it's junk. First, the flush_tlb_global() thing is arch specific, and that's all swsusp_restore() does. Then, the asm just calls this before returning to C code, so it makes no sense to have a hook there. The x86 asm can have it's own call to some arch stuff if it wants or just do the tlb flush in asm...

Quoted 4 lines

Better, here is a patch... (note: flush_tlb_global() is an x86'ism, doesn't exist on ppc, thus breaks compile, and that has nothing to do in the generic code imho, it should be clearly defined as the responsibility of the asm code).

x86-64 needs this, too.... Otherwise it looks okay.

Quoted 60 lines

--

This patch removes the quite x86-specific swsusp_restore() hook from the generic swsusp code and moves it to arch/i386. This also fixes build on ppc with swsusp enabled.

Index: linux-work/arch/i386/power/swsusp.S
===================================================================

arch/i386/power/swsusp.S +1 -1
@@ -58,5 +58,5 @@
 	movl saved_context_edi, %edi
 
 	pushl saved_context_eflags ; popfl
-	call swsusp_restore
+	call __swsusp_flush_tlb
 	ret

Index: linux-work/arch/i386/power/cpu.c
===================================================================

arch/i386/power/cpu.c +9 -0
@@ -147,6 +147,15 @@
 	__restore_processor_state(&saved_context);
 }
 
+asmlinkage int __swsusp_flush_tlb(void)
+{
+	BUG_ON (nr_copy_pages_check != nr_copy_pages);
+	
+	/* Even mappings of "global" things (vmalloc) need to be fixed */
+	__flush_tlb_global();
+	return 0;
+}
+
 /* Needed by apm.c */
 EXPORT_SYMBOL(save_processor_state);
 EXPORT_SYMBOL(restore_processor_state);

Index: linux-work/kernel/power/swsusp.c
===================================================================

kernel/power/swsusp.c +0 -9
@@ -907,15 +907,6 @@
 }
 
 
-asmlinkage int swsusp_restore(void)
-{
-	BUG_ON (nr_copy_pages_check != nr_copy_pages);
-	
-	/* Even mappings of "global" things (vmalloc) need to be fixed */
-	__flush_tlb_global();
-	return 0;
-}
-
 int swsusp_resume(void)
 {
 	int error;
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#3 lore raw

Hi,

Quoted 11 lines · Pavel Machek
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 8 lines · Benjamin Herrenschmidt

Hi Pavel !

Please kill that swsusp_restore() call that itself calls flush_tlb_global(), it's junk. First, the flush_tlb_global() thing is arch specific, and that's all swsusp_restore() does. Then, the asm just calls this before returning to C code, so it makes no sense to have a hook there. The x86 asm can have it's own call to some arch stuff if it wants or just do the tlb flush in asm...

Quoted 6 lines
Quoted 4 lines

Better, here is a patch... (note: flush_tlb_global() is an x86'ism, doesn't exist on ppc, thus breaks compile, and that has nothing to do in the generic code imho, it should be clearly defined as the responsibility of the asm code).

x86-64 needs this, too.... Otherwise it looks okay.

It breaks compilation on i386 either, because nr_copy_pages_check is static in swsusp.c. May I propose the following patch instead (tested on x86-64 and i386)?

Greets,
Rafael

arch/i386/power/cpu.c +9 -0
diff -Nrup linux-2.6.11-bk10-a/arch/i386/power/cpu.c linux-2.6.11-bk10-b/arch/i386/power/cpu.c
@@ -147,6 +147,15 @@ void restore_processor_state(void)
 	__restore_processor_state(&saved_context);
 }
 
+asmlinkage int __swsusp_flush_tlb(void)
+{
+	swsusp_restore_check();
+
+	/* Even mappings of "global" things (vmalloc) need to be fixed */
+	__flush_tlb_global();
+	return 0;
+}
+
 /* Needed by apm.c */
 EXPORT_SYMBOL(save_processor_state);
 EXPORT_SYMBOL(restore_processor_state);
arch/i386/power/swsusp.S +2 -1
diff -Nrup linux-2.6.11-bk10-a/arch/i386/power/swsusp.S linux-2.6.11-bk10-b/arch/i386/power/swsusp.S
@@ -58,5 +58,6 @@ done:
 	movl saved_context_edi, %edi
 
 	pushl saved_context_eflags ; popfl
-	call swsusp_restore
+
+	call	__swsusp_flush_tlb
 	ret
arch/x86_64/kernel/suspend_asm.S +2 -1
diff -Nrup linux-2.6.11-bk10-a/arch/x86_64/kernel/suspend_asm.S linux-2.6.11-bk10-b/arch/x86_64/kernel/suspend_asm.S
@@ -89,5 +89,6 @@ done:
 	movq saved_context_r14(%rip), %r14
 	movq saved_context_r15(%rip), %r15
 	pushq saved_context_eflags(%rip) ; popfq
-	call	swsusp_restore
+
+	call	__swsusp_flush_tlb
 	ret
arch/x86_64/kernel/suspend.c +7 -0
diff -Nrup linux-2.6.11-bk10-a/arch/x86_64/kernel/suspend.c linux-2.6.11-bk10-b/arch/x86_64/kernel/suspend.c
@@ -154,4 +154,11 @@ void fix_processor_context(void)
 
 }
 
+int __swsusp_flush_tlb(void)
+{
+	swsusp_restore_check();
 
+	/* Even mappings of "global" things (vmalloc) need to be fixed */
+	__flush_tlb_global();
+	return 0;
+}
include/linux/suspend.h +2 -0
diff -Nrup linux-2.6.11-bk10-a/include/linux/suspend.h linux-2.6.11-bk10-b/include/linux/suspend.h
@@ -68,6 +68,8 @@ static inline void disable_nonboot_cpus(
 static inline void enable_nonboot_cpus(void) {}
 #endif
 
+void swsusp_restore_check(void);
+
 void save_processor_state(void);
 void restore_processor_state(void);
 struct saved_context;
kernel/power/swsusp.c +1 -6
diff -Nrup linux-2.6.11-bk10-a/kernel/power/swsusp.c linux-2.6.11-bk10-b/kernel/power/swsusp.c
@@ -906,14 +906,9 @@ int swsusp_suspend(void)
 	return error;
 }
 
-
-asmlinkage int swsusp_restore(void)
+void swsusp_restore_check(void)
 {
 	BUG_ON (nr_copy_pages_check != nr_copy_pages);
-	
-	/* Even mappings of "global" things (vmalloc) need to be fixed */
-	__flush_tlb_global();
-	return 0;
 }
 
 int swsusp_resume(void)
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here?
- That depends a good deal on where you want to get to.
		-- Lewis Carroll "Alice's Adventures in Wonderland"
#4 lore raw

Hi!

Quoted 19 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Please kill that swsusp_restore() call that itself calls flush_tlb_global(), it's junk. First, the flush_tlb_global() thing is arch specific, and that's all swsusp_restore() does. Then, the asm just calls this before returning to C code, so it makes no sense to have a hook there. The x86 asm can have it's own call to some arch stuff if it wants or just do the tlb flush in asm...

Quoted 6 lines
Quoted 4 lines

Better, here is a patch... (note: flush_tlb_global() is an x86'ism, doesn't exist on ppc, thus breaks compile, and that has nothing to do in the generic code imho, it should be clearly defined as the responsibility of the asm code).

x86-64 needs this, too.... Otherwise it looks okay.

It breaks compilation on i386 either, because nr_copy_pages_check is static in swsusp.c. May I propose the following patch instead (tested on x86-64 and i386)?

arch/i386/power/cpu.c void restore_processor_state(void) · line 152

Quoted 3 lines
arch/i386/power/cpu.c +3 -0
+asmlinkage int __swsusp_flush_tlb(void)
+{
+	swsusp_restore_check();

Someone will certainly forget this one, and it is probably nicer/easier to just move BUG_ON into swsusp_suspend(), just after restore_processor_state() or something like that...
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#5 lore raw
Quoted 9 lines

arch/i386/power/cpu.c void restore_processor_state(void) · line 152

Quoted 5 lines
arch/i386/power/cpu.c +3 -0
+asmlinkage int __swsusp_flush_tlb(void)
+{
+	swsusp_restore_check();

Someone will certainly forget this one, and it is probably nicer/easier to just move BUG_ON into swsusp_suspend(), just after restore_processor_state() or something like that...

Agreed.

Ben.

#6 lore raw
In reply to Pavel Machek

Hi,

Quoted 21 lines · Pavel Machek

Hi!

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Please kill that swsusp_restore() call that itself calls flush_tlb_global(), it's junk. First, the flush_tlb_global() thing is arch specific, and that's all swsusp_restore() does. Then, the asm just calls this before returning to C code, so it makes no sense to have a hook there. The x86 asm can have it's own call to some arch stuff if it wants or just do the tlb flush in asm...

Quoted 6 lines
Quoted 4 lines

Better, here is a patch... (note: flush_tlb_global() is an x86'ism, doesn't exist on ppc, thus breaks compile, and that has nothing to do in the generic code imho, it should be clearly defined as the responsibility of the asm code).

x86-64 needs this, too.... Otherwise it looks okay.

It breaks compilation on i386 either, because nr_copy_pages_check is static in swsusp.c. May I propose the following patch instead (tested on x86-64 and i386)?

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+asmlinkage int __swsusp_flush_tlb(void)
+{
+	swsusp_restore_check();

Someone will certainly forget this one, and it is probably nicer/easier to just move BUG_ON into swsusp_suspend(), just after restore_processor_state() or something like that...

... in which case __swsusp_flush_tlb() would only contain a "call" to __flush_tlb_global(), but this is a macro on both x86-64 and i386, so we can drop the __swsusp_flush_tlb() altogether and do it in assembly (before the GPRs are restored, perhaps). Patch follows.

Greets,
Rafael

arch/i386/power/swsusp.S +10 -1
diff -Nrup linux-2.6.11-bk10-a/arch/i386/power/swsusp.S linux-2.6.11-bk10-b/arch/i386/power/swsusp.S
@@ -51,6 +51,15 @@ copy_loop:
 	.p2align 4,,7
 
 done:
+	/* Flush TLB, including "global" things (vmalloc) */
+	movl	mmu_cr4_features, %eax
+	movl	%eax, %edx
+	andl	$~(1<<7), %edx;  # PGE
+	movl	%edx, %cr4;  # turn off PGE
+	movl	%cr3, %ecx;  # flush TLB
+	movl	%ecx, %cr3
+	movl	%eax, %cr4;  # turn PGE back on
+
 	movl saved_context_esp, %esp
 	movl saved_context_ebp, %ebp
 	movl saved_context_ebx, %ebx
@@ -58,5 +67,5 @@ done:
 	movl saved_context_edi, %edi
 
 	pushl saved_context_eflags ; popfl
-	call swsusp_restore
+
 	ret
arch/x86_64/kernel/suspend_asm.S +9 -1
diff -Nrup linux-2.6.11-bk10-a/arch/x86_64/kernel/suspend_asm.S linux-2.6.11-bk10-b/arch/x86_64/kernel/suspend_asm.S
@@ -69,6 +69,14 @@ loop:
 	movq	pbe_next(%rdx), %rdx
 	jmp	loop
 done:
+	/* Flush TLB, including "global" things (vmalloc) */
+	movq	%rax, %rdx;  # mmu_cr4_features(%rip)
+	andq	$~(1<<7), %rdx;  # PGE
+	movq	%rdx, %cr4;  # turn off PGE
+	movq	%cr3, %rcx;  # flush TLB
+	movq	%rcx, %cr3
+	movq	%rax, %cr4;  # turn PGE back on
+
 	movl	$24, %eax
 	movl	%eax, %ds
 
@@ -89,5 +97,5 @@ done:
 	movq saved_context_r14(%rip), %r14
 	movq saved_context_r15(%rip), %r15
 	pushq saved_context_eflags(%rip) ; popfq
-	call	swsusp_restore
+
 	ret
kernel/power/swsusp.c +1 -10
diff -Nrup linux-2.6.11-bk10-a/kernel/power/swsusp.c linux-2.6.11-bk10-b/kernel/power/swsusp.c
@@ -900,22 +900,13 @@ int swsusp_suspend(void)
 	error = swsusp_arch_suspend();
 	/* Restore control flow magically appears here */
 	restore_processor_state();
+	BUG_ON (nr_copy_pages_check != nr_copy_pages);
 	restore_highmem();
 	device_power_up();
 	local_irq_enable();
 	return error;
 }
 
-
-asmlinkage int swsusp_restore(void)
-{
-	BUG_ON (nr_copy_pages_check != nr_copy_pages);
-	
-	/* Even mappings of "global" things (vmalloc) need to be fixed */
-	__flush_tlb_global();
-	return 0;
-}
-
 int swsusp_resume(void)
 {
 	int error;
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here?
- That depends a good deal on where you want to get to.
		-- Lewis Carroll "Alice's Adventures in Wonderland"
#7 lore raw

Hi!

Quoted 30 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

x86-64 needs this, too.... Otherwise it looks okay.

It breaks compilation on i386 either, because nr_copy_pages_check is static in swsusp.c. May I propose the following patch instead (tested on x86-64 and i386)?

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+asmlinkage int __swsusp_flush_tlb(void)
+{
+	swsusp_restore_check();

Someone will certainly forget this one, and it is probably nicer/easier to just move BUG_ON into swsusp_suspend(), just after restore_processor_state() or something like that...

... in which case __swsusp_flush_tlb() would only contain a "call" to __flush_tlb_global(), but this is a macro on both x86-64 and i386, so we can drop the __swsusp_flush_tlb() altogether and do it in assembly (before the GPRs are restored, perhaps). Patch follows.

Greets,
Rafael

diff -Nrup linux-2.6.11-bk10-a/arch/x86_64/kernel/suspend_asm.S linux-2.6.11-bk10-b/arch/x86_64/kernel/suspend_asm.S

arch/x86_64/kernel/suspend_asm.S loop: · line 73

Quoted 5 lines
arch/x86_64/kernel/suspend_asm.S +2 -0
@@ -69,6 +69,14 @@ loop:
 	movq	pbe_next(%rdx), %rdx
 	jmp	loop
 done:
+	/* Flush TLB, including "global" things (vmalloc) */
+	movq	%rax, %rdx;  # mmu_cr4_features(%rip)

I somehow don't think %rax contains mmu_cr4_features at this point. Otherwise it seems to look ok.
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#8 lore raw
Quoted 28 lines · Pavel Machek

Hi!

Quoted 25 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

x86-64 needs this, too.... Otherwise it looks okay.

It breaks compilation on i386 either, because nr_copy_pages_check is static in swsusp.c. May I propose the following patch instead (tested on x86-64 and i386)?

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+asmlinkage int __swsusp_flush_tlb(void)
+{
+	swsusp_restore_check();

Someone will certainly forget this one, and it is probably nicer/easier to just move BUG_ON into swsusp_suspend(), just after restore_processor_state() or something like that...

... in which case __swsusp_flush_tlb() would only contain a "call" to __flush_tlb_global(), but this is a macro on both x86-64 and i386, so we can drop the __swsusp_flush_tlb() altogether and do it in assembly (before the GPRs are restored, perhaps). Patch follows.

Greets,
Rafael

Quoted 12 lines

arch/x86_64/kernel/suspend_asm.S loop: · line 73

Quoted 9 lines

diff -Nrup linux-2.6.11-bk10-a/arch/x86_64/kernel/suspend_asm.S linux-2.6.11-bk10-b/arch/x86_64/kernel/suspend_asm.S

arch/x86_64/kernel/suspend_asm.S +2 -0
@@ -69,6 +69,14 @@ loop:
 	movq	pbe_next(%rdx), %rdx
 	jmp	loop
 done:
+	/* Flush TLB, including "global" things (vmalloc) */
+	movq	%rax, %rdx;  # mmu_cr4_features(%rip)

I somehow don't think %rax contains mmu_cr4_features at this point. Otherwise it seems to look ok.

Yes, it does, because on x86-64 the TLBs are flushed before the loop, right after %cr3 is loaded with init_level4_pgt. %rax is not touched afterwards, so it contains the right value. Here's the relevant code from suspend_asm.S (with the patch applied):

ENTRY(swsusp_arch_resume)

	/* set up cr3 */	
	leaq	init_level4_pgt(%rip),%rax
	subq	$__START_KERNEL_map,%rax
	movq	%rax,%cr3

	movq	mmu_cr4_features(%rip), %rax
	movq	%rax, %rdx
	andq	$~(1<<7), %rdx	# PGE
	movq	%rdx, %cr4;  # turn off PGE
	movq	%cr3, %rcx;  # flush TLB
	movq	%rcx, %cr3;
	movq	%rax, %cr4;  # turn PGE back on

	movq	pagedir_nosave(%rip), %rdx
loop:
	testq	%rdx, %rdx
	jz	done

	/* get addresses from the pbe and copy the page */
	movq	pbe_address(%rdx), %rsi
	movq	pbe_orig_address(%rdx), %rdi
	movq	$512, %rcx
	rep
	movsq

	/* progress to the next pbe */
	movq	pbe_next(%rdx), %rdx
	jmp	loop
done:
	/* Flush TLB, including "global" things (vmalloc) */
	movq	%rax, %rdx;  # mmu_cr4_features(%rip)
	andq	$~(1<<7), %rdx;  # PGE
	movq	%rdx, %cr4;  # turn off PGE
	movq	%cr3, %rcx;  # flush TLB
	movq	%rcx, %cr3
	movq	%rax, %cr4;  # turn PGE back on

Greets,
Rafael

Signature · 3 lines
- Would you tell me, please, which way I ought to go from here?
- That depends a good deal on where you want to get to.
		-- Lewis Carroll "Alice's Adventures in Wonderland"
#9 lore raw

Hi!

Quoted 15 lines
Quoted 14 lines

arch/x86_64/kernel/suspend_asm.S loop: · line 73

Quoted 11 lines

diff -Nrup linux-2.6.11-bk10-a/arch/x86_64/kernel/suspend_asm.S linux-2.6.11-bk10-b/arch/x86_64/kernel/suspend_asm.S

arch/x86_64/kernel/suspend_asm.S +2 -0
@@ -69,6 +69,14 @@ loop:
 	movq	pbe_next(%rdx), %rdx
 	jmp	loop
 done:
+	/* Flush TLB, including "global" things (vmalloc) */
+	movq	%rax, %rdx;  # mmu_cr4_features(%rip)

I somehow don't think %rax contains mmu_cr4_features at this point. Otherwise it seems to look ok.

Quoted 4 lines

Yes, it does, because on x86-64 the TLBs are flushed before the loop, right after %cr3 is loaded with init_level4_pgt. %rax is not touched afterwards, so it contains the right value. Here's the relevant code from suspend_asm.S (with the patch applied):

Well, it is mmu_cr4_features from "old" kernel, while you are flushing tlb in "new" kernel. It is probably same anyway, but.... %rax is commonly-used scratch register, and memory load is not that expensive. Can you just load it from memory?
Pavel

Quoted 43 lines

ENTRY(swsusp_arch_resume)

	/* set up cr3 */	
	leaq	init_level4_pgt(%rip),%rax
	subq	$__START_KERNEL_map,%rax
	movq	%rax,%cr3

	movq	mmu_cr4_features(%rip), %rax
	movq	%rax, %rdx
	andq	$~(1<<7), %rdx	# PGE
	movq	%rdx, %cr4;  # turn off PGE
	movq	%cr3, %rcx;  # flush TLB
	movq	%rcx, %cr3;
	movq	%rax, %cr4;  # turn PGE back on

	movq	pagedir_nosave(%rip), %rdx
loop:
	testq	%rdx, %rdx
	jz	done

	/* get addresses from the pbe and copy the page */
	movq	pbe_address(%rdx), %rsi
	movq	pbe_orig_address(%rdx), %rdi
	movq	$512, %rcx
	rep
	movsq

	/* progress to the next pbe */
	movq	pbe_next(%rdx), %rdx
	jmp	loop
done:
	/* Flush TLB, including "global" things (vmalloc) */
	movq	%rax, %rdx;  # mmu_cr4_features(%rip)
	andq	$~(1<<7), %rdx;  # PGE
	movq	%rdx, %cr4;  # turn off PGE
	movq	%cr3, %rcx;  # flush TLB
	movq	%rcx, %cr3
	movq	%rax, %cr4;  # turn PGE back on

Greets,
Rafael

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#10 lore raw

Hi,

Quoted 22 lines · Pavel Machek

Hi!

Quoted 15 lines
Quoted 14 lines

arch/x86_64/kernel/suspend_asm.S loop: · line 73

Quoted 11 lines

diff -Nrup linux-2.6.11-bk10-a/arch/x86_64/kernel/suspend_asm.S linux-2.6.11-bk10-b/arch/x86_64/kernel/suspend_asm.S

arch/x86_64/kernel/suspend_asm.S +2 -0
@@ -69,6 +69,14 @@ loop:
 	movq	pbe_next(%rdx), %rdx
 	jmp	loop
 done:
+	/* Flush TLB, including "global" things (vmalloc) */
+	movq	%rax, %rdx;  # mmu_cr4_features(%rip)

I somehow don't think %rax contains mmu_cr4_features at this point. Otherwise it seems to look ok.

Quoted 4 lines

Yes, it does, because on x86-64 the TLBs are flushed before the loop, right after %cr3 is loaded with init_level4_pgt. %rax is not touched afterwards, so it contains the right value. Here's the relevant code from suspend_asm.S (with the patch applied):

Quoted 4 lines

Well, it is mmu_cr4_features from "old" kernel, while you are flushing tlb in "new" kernel. It is probably same anyway, but.... %rax is commonly-used scratch register, and memory load is not that expensive. Can you just load it from memory?

Sure, revised patch follows.

Greets,
Rafael

arch/i386/power/swsusp.S +10 -1
diff -Nrup linux-2.6.11-bk10-a/arch/i386/power/swsusp.S linux-2.6.11-bk10-b/arch/i386/power/swsusp.S
@@ -51,6 +51,15 @@ copy_loop:
 	.p2align 4,,7
 
 done:
+	/* Flush TLB, including "global" things (vmalloc) */
+	movl	mmu_cr4_features, %eax
+	movl	%eax, %edx
+	andl	$~(1<<7), %edx;  # PGE
+	movl	%edx, %cr4;  # turn off PGE
+	movl	%cr3, %ecx;  # flush TLB
+	movl	%ecx, %cr3
+	movl	%eax, %cr4;  # turn PGE back on
+
 	movl saved_context_esp, %esp
 	movl saved_context_ebp, %ebp
 	movl saved_context_ebx, %ebx
@@ -58,5 +67,5 @@ done:
 	movl saved_context_edi, %edi
 
 	pushl saved_context_eflags ; popfl
-	call swsusp_restore
+
 	ret
arch/x86_64/kernel/suspend_asm.S +10 -1
diff -Nrup linux-2.6.11-bk10-a/arch/x86_64/kernel/suspend_asm.S linux-2.6.11-bk10-b/arch/x86_64/kernel/suspend_asm.S
@@ -69,6 +69,15 @@ loop:
 	movq	pbe_next(%rdx), %rdx
 	jmp	loop
 done:
+	/* Flush TLB, including "global" things (vmalloc) */
+	movq	mmu_cr4_features(%rip), %rax
+	movq	%rax, %rdx
+	andq	$~(1<<7), %rdx;  # PGE
+	movq	%rdx, %cr4;  # turn off PGE
+	movq	%cr3, %rcx;  # flush TLB
+	movq	%rcx, %cr3
+	movq	%rax, %cr4;  # turn PGE back on
+
 	movl	$24, %eax
 	movl	%eax, %ds
 
@@ -89,5 +98,5 @@ done:
 	movq saved_context_r14(%rip), %r14
 	movq saved_context_r15(%rip), %r15
 	pushq saved_context_eflags(%rip) ; popfq
-	call	swsusp_restore
+
 	ret
kernel/power/swsusp.c +1 -10
diff -Nrup linux-2.6.11-bk10-a/kernel/power/swsusp.c linux-2.6.11-bk10-b/kernel/power/swsusp.c
@@ -900,22 +900,13 @@ int swsusp_suspend(void)
 	error = swsusp_arch_suspend();
 	/* Restore control flow magically appears here */
 	restore_processor_state();
+	BUG_ON (nr_copy_pages_check != nr_copy_pages);
 	restore_highmem();
 	device_power_up();
 	local_irq_enable();
 	return error;
 }
 
-
-asmlinkage int swsusp_restore(void)
-{
-	BUG_ON (nr_copy_pages_check != nr_copy_pages);
-	
-	/* Even mappings of "global" things (vmalloc) need to be fixed */
-	__flush_tlb_global();
-	return 0;
-}
-
 int swsusp_resume(void)
 {
 	int error;
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here?
- That depends a good deal on where you want to get to.
		-- Lewis Carroll "Alice's Adventures in Wonderland"
#11 lore raw
In reply to Rafael J. Wysocki
Quoted 14 lines

It breaks compilation on i386 either, because nr_copy_pages_check is static in swsusp.c. May I propose the following patch instead (tested on x86-64 and i386)?

Greets,
Rafael

diff -Nrup linux-2.6.11-bk10-a/arch/i386/power/cpu.c linux-2.6.11-bk10-b/arch/i386/power/cpu.c

arch/i386/power/cpu.c void restore_processor_state(void) · line 153

Quoted 7 lines
arch/i386/power/cpu.c +4 -0
@@ -147,6 +147,15 @@ void restore_processor_state(void)
 	__restore_processor_state(&saved_context);
 }
 
+asmlinkage int __swsusp_flush_tlb(void)
+{
+	swsusp_restore_check();
+

Do we really need that check there ? Can't it be moved elsewhere ?

Ben.