Skip to contentSkip to conversation

don't use flush_tlb_all in suspend time

PATCH In review Shaohua Li 3 participants 13 messages Apr 30, 2006 – May 20, 2006

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 don't use flush_tlb_all in suspend time

flush_tlb_all uses on_each_cpu, which will disable/enable interrupt. In suspend/resume time, this will make interrupt wrongly enabled.

---

 linux-2.6.17-rc3-root/arch/i386/kernel/acpi/sleep.c   |    2 +-
 linux-2.6.17-rc3-root/arch/i386/mm/init.c             |    5 ++++-
 linux-2.6.17-rc3-root/arch/x86_64/kernel/acpi/sleep.c |    4 ++--
 3 files changed, 7 insertions(+), 4 deletions(-)
arch/i386/kernel/acpi/sleep.c renamed from arch/i386/kernel/acpi/sleep.c~flush_tlb_all_check +1 -1
diff -puN arch/i386/kernel/acpi/sleep.c~flush_tlb_all_check arch/i386/kernel/acpi/sleep.c
@@ -29,7 +29,7 @@ static void init_low_mapping(pgd_t * pgd
 		set_pgd(pgd, *(pgd + USER_PTRS_PER_PGD));
 		pgd_ofs++, pgd++;
 	}
-	flush_tlb_all();
+	local_flush_tlb();
 }
 
 /**
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +4 -1
diff -puN arch/i386/mm/init.c~flush_tlb_all_check arch/i386/mm/init.c
@@ -420,7 +420,10 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	flush_tlb_all();
+	if (cpus_weight(cpu_online_map) == 1)
+		local_flush_tlb();
+	else
+		flush_tlb_all();
 }
 
 static int disable_nx __initdata = 0;
arch/x86_64/kernel/acpi/sleep.c renamed from arch/x86_64/kernel/acpi/sleep.c~flush_tlb_all_check +2 -2
diff -puN arch/x86_64/kernel/acpi/sleep.c~flush_tlb_all_check arch/x86_64/kernel/acpi/sleep.c
@@ -66,7 +66,7 @@ static void init_low_mapping(void)
 	pgd_t *slot0 = pgd_offset(current->mm, 0UL);
 	low_ptr = *slot0;
 	set_pgd(slot0, *pgd_offset(current->mm, PAGE_OFFSET));
-	flush_tlb_all();
+	local_flush_tlb();
 }
 
 /**
@@ -92,7 +92,7 @@ int acpi_save_state_mem(void)
 void acpi_restore_state_mem(void)
 {
 	set_pgd(pgd_offset(current->mm, 0UL), low_ptr);
-	flush_tlb_all();
+	local_flush_tlb();
 }
 
 /**

_

#1 lore raw

Hi!

Quoted 7 lines

flush_tlb_all uses on_each_cpu, which will disable/enable interrupt. In suspend/resume time, this will make interrupt wrongly enabled.

diff -puN arch/i386/mm/init.c~flush_tlb_all_check arch/i386/mm/init.c

arch/i386/mm/init.c void zap_low_mappings (void) · line 428

Quoted 10 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +4 -1
@@ -420,7 +420,10 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	flush_tlb_all();
+	if (cpus_weight(cpu_online_map) == 1)
+		local_flush_tlb();
+	else
+		flush_tlb_all();
 }
 

Either it is okay to enable interrupts here -> unneccessary and ugly test, or it is not, and then we are broken in SMP case.

Pavel

Signature · 1 line
Thanks, Sharp!
author
#2 lore raw
Quoted 14 lines · Pavel Machek

Hi!

Quoted 12 lines

flush_tlb_all uses on_each_cpu, which will disable/enable interrupt. In suspend/resume time, this will make interrupt wrongly enabled.

diff -puN arch/i386/mm/init.c~flush_tlb_all_check arch/i386/mm/init.c

arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +1 -1
@@ -420,7 +420,10 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	flush_tlb_all();
+	if (cpus_weight(cpu_online_map) == 1)
Quoted 8 lines

arch/i386/mm/init.c void zap_low_mappings (void) · line 428

Quoted 5 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +3 -0
+		local_flush_tlb();
+	else
+		flush_tlb_all();
 }
 

Either it is okay to enable interrupts here -> unneccessary and ugly test, or it is not, and then we are broken in SMP case.

It's not broken in SMP case, APs are offlined here in suspend/resume.

Thanks,
Shaohua

#3 lore raw
Quoted 24 lines · Shaohua Li
Quoted 14 lines · Pavel Machek

Hi!

Quoted 12 lines

flush_tlb_all uses on_each_cpu, which will disable/enable interrupt. In suspend/resume time, this will make interrupt wrongly enabled.

diff -puN arch/i386/mm/init.c~flush_tlb_all_check arch/i386/mm/init.c

arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +1 -1
@@ -420,7 +420,10 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	flush_tlb_all();
+	if (cpus_weight(cpu_online_map) == 1)
Quoted 8 lines

arch/i386/mm/init.c void zap_low_mappings (void) · line 428

Quoted 5 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +3 -0
+		local_flush_tlb();
+	else
+		flush_tlb_all();
 }
 

Either it is okay to enable interrupts here -> unneccessary and ugly test, or it is not, and then we are broken in SMP case.

Quoted 2 lines

It's not broken in SMP case, APs are offlined here in suspend/resume.

In which case, how's about this?

 arch/i386/kernel/acpi/sleep.c   |    3 +++
 arch/i386/mm/init.c             |   10 +++++++++-
 arch/x86_64/kernel/acpi/sleep.c |    3 +++
 3 files changed, 15 insertions(+), 1 deletion(-)
arch/i386/kernel/acpi/sleep.c renamed from arch/i386/kernel/acpi/sleep.c~dont-use-flush_tlb_all-in-suspend-time-tidy +3 -0
diff -puN arch/i386/kernel/acpi/sleep.c~dont-use-flush_tlb_all-in-suspend-time-tidy arch/i386/kernel/acpi/sleep.c
@@ -8,6 +8,8 @@
 #include <linux/acpi.h>
 #include <linux/bootmem.h>
 #include <linux/dmi.h>
+#include <linux/cpumask.h>
+
 #include <asm/smp.h>
 #include <asm/tlbflush.h>
 
@@ -29,6 +31,7 @@ static void init_low_mapping(pgd_t * pgd
 		set_pgd(pgd, *(pgd + USER_PTRS_PER_PGD));
 		pgd_ofs++, pgd++;
 	}
+	WARN_ON(num_online_cpus() != 1);
 	local_flush_tlb();
 }
 
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~dont-use-flush_tlb_all-in-suspend-time-tidy +9 -1
diff -puN arch/i386/mm/init.c~dont-use-flush_tlb_all-in-suspend-time-tidy arch/i386/mm/init.c
@@ -29,6 +29,7 @@
 #include <linux/efi.h>
 #include <linux/memory_hotplug.h>
 #include <linux/initrd.h>
+#include <linux/cpumask.h>
 
 #include <asm/processor.h>
 #include <asm/system.h>
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();
arch/x86_64/kernel/acpi/sleep.c renamed from arch/x86_64/kernel/acpi/sleep.c~dont-use-flush_tlb_all-in-suspend-time-tidy +3 -0
diff -puN arch/x86_64/kernel/acpi/sleep.c~dont-use-flush_tlb_all-in-suspend-time-tidy arch/x86_64/kernel/acpi/sleep.c
@@ -35,6 +35,8 @@
 #include <linux/pci.h>
 #include <linux/bootmem.h>
 #include <linux/acpi.h>
+#include <linux/cpumask.h>
+
 #include <asm/mpspec.h>
 #include <asm/io.h>
 #include <asm/apic.h>
@@ -66,6 +68,7 @@ static void init_low_mapping(void)
 	pgd_t *slot0 = pgd_offset(current->mm, 0UL);
 	low_ptr = *slot0;
 	set_pgd(slot0, *pgd_offset(current->mm, PAGE_OFFSET));
+	WARN_ON(num_online_cpus() != 1);
 	local_flush_tlb();
 }
 

_

author
#4 lore raw
Quoted 25 lines · Andrew Morton
Quoted 24 lines · Shaohua Li
Quoted 22 lines · Pavel Machek

Hi!

Quoted 7 lines

flush_tlb_all uses on_each_cpu, which will disable/enable interrupt. In suspend/resume time, this will make interrupt wrongly enabled.

diff -puN arch/i386/mm/init.c~flush_tlb_all_check arch/i386/mm/init.c

arch/i386/mm/init.c void zap_low_mappings (void) · line 428

Quoted 10 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +4 -1
@@ -420,7 +420,10 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	flush_tlb_all();
+	if (cpus_weight(cpu_online_map) == 1)
+		local_flush_tlb();
+	else
+		flush_tlb_all();
 }
 

Either it is okay to enable interrupts here -> unneccessary and ugly test, or it is not, and then we are broken in SMP case.

Quoted 4 lines
Quoted 2 lines

It's not broken in SMP case, APs are offlined here in suspend/resume.

In which case, how's about this?

Yes, this is great. Thanks!

Quoted 73 lines
 arch/i386/kernel/acpi/sleep.c   |    3 +++
 arch/i386/mm/init.c             |   10 +++++++++-
 arch/x86_64/kernel/acpi/sleep.c |    3 +++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff -puN arch/i386/kernel/acpi/sleep.c~dont-use-flush_tlb_all-in-suspend-time-tidy arch/i386/kernel/acpi/sleep.c

arch/i386/kernel/acpi/sleep.c renamed from arch/i386/kernel/acpi/sleep.c~dont-use-flush_tlb_all-in-suspend-time-tidy +3 -0
@@ -8,6 +8,8 @@
 #include <linux/acpi.h>
 #include <linux/bootmem.h>
 #include <linux/dmi.h>
+#include <linux/cpumask.h>
+
 #include <asm/smp.h>
 #include <asm/tlbflush.h>
 
@@ -29,6 +31,7 @@ static void init_low_mapping(pgd_t * pgd
 		set_pgd(pgd, *(pgd + USER_PTRS_PER_PGD));
 		pgd_ofs++, pgd++;
 	}
+	WARN_ON(num_online_cpus() != 1);
 	local_flush_tlb();
 }
 

diff -puN arch/i386/mm/init.c~dont-use-flush_tlb_all-in-suspend-time-tidy arch/i386/mm/init.c

arch/i386/mm/init.c renamed from arch/i386/mm/init.c~dont-use-flush_tlb_all-in-suspend-time-tidy +9 -1
@@ -29,6 +29,7 @@
 #include <linux/efi.h>
 #include <linux/memory_hotplug.h>
 #include <linux/initrd.h>
+#include <linux/cpumask.h>
 
 #include <asm/processor.h>
 #include <asm/system.h>
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();

diff -puN arch/x86_64/kernel/acpi/sleep.c~dont-use-flush_tlb_all-in-suspend-time-tidy arch/x86_64/kernel/acpi/sleep.c

arch/x86_64/kernel/acpi/sleep.c renamed from arch/x86_64/kernel/acpi/sleep.c~dont-use-flush_tlb_all-in-suspend-time-tidy +3 -0
@@ -35,6 +35,8 @@
 #include <linux/pci.h>
 #include <linux/bootmem.h>
 #include <linux/acpi.h>
+#include <linux/cpumask.h>
+
 #include <asm/mpspec.h>
 #include <asm/io.h>
 #include <asm/apic.h>
@@ -66,6 +68,7 @@ static void init_low_mapping(void)
 	pgd_t *slot0 = pgd_offset(current->mm, 0UL);
 	low_ptr = *slot0;
 	set_pgd(slot0, *pgd_offset(current->mm, PAGE_OFFSET));
+	WARN_ON(num_online_cpus() != 1);
 	local_flush_tlb();
 }
 

_

Signature · 1 line
Shaohua Li <[email protected]>
#5 lore raw
In reply to Andrew Morton
Quoted 25 lines · Andrew Morton
Quoted 24 lines · Shaohua Li
Quoted 22 lines · Pavel Machek

Hi!

Quoted 7 lines

flush_tlb_all uses on_each_cpu, which will disable/enable interrupt. In suspend/resume time, this will make interrupt wrongly enabled.

diff -puN arch/i386/mm/init.c~flush_tlb_all_check arch/i386/mm/init.c

arch/i386/mm/init.c void zap_low_mappings (void) · line 428

Quoted 10 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +4 -1
@@ -420,7 +420,10 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	flush_tlb_all();
+	if (cpus_weight(cpu_online_map) == 1)
+		local_flush_tlb();
+	else
+		flush_tlb_all();
 }
 

Either it is okay to enable interrupts here -> unneccessary and ugly test, or it is not, and then we are broken in SMP case.

Quoted 4 lines
Quoted 2 lines

It's not broken in SMP case, APs are offlined here in suspend/resume.

In which case, how's about this?

Certainly better, I'd say.

Quoted 6 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~dont-use-flush_tlb_all-in-suspend-time-tidy +1 -1
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*

arch/i386/mm/init.c void zap_low_mappings (void) · line 434

Quoted 10 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~dont-use-flush_tlb_all-in-suspend-time-tidy +7 -0
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();

But this still scares. It means calling convention is "may enable interrupts with >1 cpu, may not with == 1 cpu".

Pavel

Signature · 1 line
Thanks for all the (sleeping) penguins.
author
#6 lore raw
Quoted 33 lines · Pavel Machek
Quoted 25 lines · Andrew Morton
Quoted 24 lines · Shaohua Li
Quoted 22 lines · Pavel Machek

Hi!

Quoted 7 lines

flush_tlb_all uses on_each_cpu, which will disable/enable interrupt. In suspend/resume time, this will make interrupt wrongly enabled.

diff -puN arch/i386/mm/init.c~flush_tlb_all_check arch/i386/mm/init.c

arch/i386/mm/init.c void zap_low_mappings (void) · line 428

Quoted 10 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +4 -1
@@ -420,7 +420,10 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	flush_tlb_all();
+	if (cpus_weight(cpu_online_map) == 1)
+		local_flush_tlb();
+	else
+		flush_tlb_all();
 }
 

Either it is okay to enable interrupts here -> unneccessary and ugly test, or it is not, and then we are broken in SMP case.

Quoted 4 lines
Quoted 2 lines

It's not broken in SMP case, APs are offlined here in suspend/resume.

In which case, how's about this?

Certainly better, I'd say.

Quoted 16 lines
Quoted 6 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~dont-use-flush_tlb_all-in-suspend-time-tidy +1 -1
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*

arch/i386/mm/init.c void zap_low_mappings (void) · line 434

Quoted 10 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~dont-use-flush_tlb_all-in-suspend-time-tidy +7 -0
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();

Sorry for the delay. Last week is holiday here.

Quoted 2 lines

But this still scares. It means calling convention is "may enable interrupts with >1 cpu, may not with == 1 cpu".

Then we need port x86_64's implementation. I'll try if I can work it out.

Thanks,
Shaohua

author
#7 lore raw
In reply to Pavel Machek
Quoted 44 lines · Pavel Machek
Quoted 25 lines · Andrew Morton
Quoted 24 lines · Shaohua Li
Quoted 22 lines · Pavel Machek

Hi!

Quoted 7 lines

flush_tlb_all uses on_each_cpu, which will disable/enable interrupt. In suspend/resume time, this will make interrupt wrongly enabled.

diff -puN arch/i386/mm/init.c~flush_tlb_all_check arch/i386/mm/init.c

arch/i386/mm/init.c void zap_low_mappings (void) · line 428

Quoted 10 lines
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~flush_tlb_all_check +4 -1
@@ -420,7 +420,10 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	flush_tlb_all();
+	if (cpus_weight(cpu_online_map) == 1)
+		local_flush_tlb();
+	else
+		flush_tlb_all();
 }
 

Either it is okay to enable interrupts here -> unneccessary and ugly test, or it is not, and then we are broken in SMP case.

Quoted 4 lines
Quoted 2 lines

It's not broken in SMP case, APs are offlined here in suspend/resume.

In which case, how's about this?

Certainly better, I'd say.

Quoted 11 lines
(quoted diff) +6 -1
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
Quoted 8 lines

Review void zap_low_mappings (void) · line 434

Quoted 5 lines
(quoted diff) +2 -0
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();

But this still scares. It means calling convention is "may enable interrupts with >1 cpu, may not with == 1 cpu".

Below patch should make things clean. How do you think?

---

 linux-2.6.17-rc4-mm1-root/arch/i386/kernel/acpi/sleep.c  |   10 +++-------
 linux-2.6.17-rc4-mm1-root/arch/i386/kernel/acpi/wakeup.S |    2 +-
 linux-2.6.17-rc4-mm1-root/arch/i386/mm/init.c            |   13 +------------
 3 files changed, 5 insertions(+), 20 deletions(-)
arch/i386/kernel/acpi/wakeup.S renamed from arch/i386/kernel/acpi/wakeup.S~i386_direct_mapping +1 -1
diff -puN arch/i386/kernel/acpi/wakeup.S~i386_direct_mapping arch/i386/kernel/acpi/wakeup.S
@@ -56,7 +56,7 @@ wakeup_code:
 1:
 
 	# set up page table
-	movl	$swapper_pg_dir-__PAGE_OFFSET, %eax
+	movl	$sleep_pg_dir-__PAGE_OFFSET, %eax
 	movl	%eax, %cr3
 
 	testl	$1, real_efer_save_restore - wakeup_code
arch/i386/kernel/acpi/sleep.c renamed from arch/i386/kernel/acpi/sleep.c~i386_direct_mapping +3 -7
diff -puN arch/i386/kernel/acpi/sleep.c~i386_direct_mapping arch/i386/kernel/acpi/sleep.c
@@ -11,16 +11,14 @@
 #include <linux/cpumask.h>
 
 #include <asm/smp.h>
-#include <asm/tlbflush.h>
 
 /* address in low memory of the wakeup routine. */
 unsigned long acpi_wakeup_address = 0;
 unsigned long acpi_video_flags;
 extern char wakeup_start, wakeup_end;
 
-extern void zap_low_mappings(void);
-
 extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
+char sleep_pg_dir[PAGE_SIZE];
 
 static void init_low_mapping(pgd_t * pgd, int pgd_limit)
 {
@@ -31,8 +29,6 @@ static void init_low_mapping(pgd_t * pgd
 		set_pgd(pgd, *(pgd + USER_PTRS_PER_PGD));
 		pgd_ofs++, pgd++;
 	}
-	WARN_ON(num_online_cpus() != 1);
-	local_flush_tlb();
 }
 
 /**
@@ -45,7 +41,8 @@ int acpi_save_state_mem(void)
 {
 	if (!acpi_wakeup_address)
 		return 1;
-	init_low_mapping(swapper_pg_dir, USER_PTRS_PER_PGD);
+	memcpy(sleep_pg_dir, swapper_pg_dir, PAGE_SIZE);
+	init_low_mapping((pgd_t *)sleep_pg_dir, USER_PTRS_PER_PGD);
 	memcpy((void *)acpi_wakeup_address, &wakeup_start,
 	       &wakeup_end - &wakeup_start);
 	acpi_copy_wakeup_routine(acpi_wakeup_address);
@@ -58,7 +55,6 @@ int acpi_save_state_mem(void)
  */
 void acpi_restore_state_mem(void)
 {
-	zap_low_mappings();
 }
 
 /**
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~i386_direct_mapping +1 -12
diff -puN arch/i386/mm/init.c~i386_direct_mapping arch/i386/mm/init.c
@@ -422,18 +422,7 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	/*
-	 * We can be called at suspend/resume time, with local interrupts
-	 * disabled.  But flush_tlb_all() requires that local interrupts be
-	 * enabled.
-	 *
-	 * Happily, the APs are not yet started, so we can use local_flush_tlb()
-	 * in that case
-	 */
-	if (num_online_cpus() == 1)
-		local_flush_tlb();
-	else
-		flush_tlb_all();
+	flush_tlb_all();
 }
 
 static int disable_nx __initdata = 0;

_

#8 lore raw

Hi!

Quoted 23 lines
Quoted 15 lines
Quoted 1 line

In which case, how's about this?

Certainly better, I'd say.

Quoted 11 lines
(quoted diff) +6 -1
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
Quoted 8 lines

Review void zap_low_mappings (void) · line 434

Quoted 5 lines
(quoted diff) +2 -0
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();

But this still scares. It means calling convention is "may enable interrupts with >1 cpu, may not with == 1 cpu".

Quoted 1 line

Below patch should make things clean. How do you think?

Nice...

Could we perhaps reuse swsusp_pg_dir (just make it used for swsusp & suspend-to-ram) to save a bit more code? It is in arch/i386/mm/init.c .

Pavel

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

Hi!

Quoted 23 lines
Quoted 23 lines
Quoted 1 line

In which case, how's about this?

Certainly better, I'd say.

Quoted 6 lines
(quoted diff) +1 -1
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*

Review void zap_low_mappings (void) · line 434

Quoted 10 lines
(quoted diff) +7 -0
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();

But this still scares. It means calling convention is "may enable interrupts with >1 cpu, may not with == 1 cpu".

Quoted 6 lines
Quoted 1 line

Below patch should make things clean. How do you think?

Nice...

Could we perhaps reuse swsusp_pg_dir (just make it used for swsusp & suspend-to-ram) to save a bit more code? It is in arch/i386/mm/init.c

Sure. But it's under CONFIG_SOFTWARE_SUSPEND. That part needs cleanup I think and it's a little strange to me (why should we simply copy swapper_pg_dir to swsusp_pg_dir, instead do it in zap_low_mappings?).

Thanks,
Shaohua

#10 lore raw
Quoted 26 lines · Shaohua Li
Quoted 25 lines · Pavel Machek

Hi!

Quoted 23 lines
Quoted 23 lines
Quoted 1 line

In which case, how's about this?

Certainly better, I'd say.

Quoted 6 lines
(quoted diff) +1 -1
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*

Review void zap_low_mappings (void) · line 434

Quoted 10 lines
(quoted diff) +7 -0
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();

But this still scares. It means calling convention is "may enable interrupts with >1 cpu, may not with == 1 cpu".

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Below patch should make things clean. How do you think?

Nice...

Could we perhaps reuse swsusp_pg_dir (just make it used for swsusp & suspend-to-ram) to save a bit more code? It is in arch/i386/mm/init.c

Sure. But it's under CONFIG_SOFTWARE_SUSPEND.

Yes, #ifdef definitely does need to change there.

Quoted 3 lines

That part needs cleanup I
think and it's a little strange to me (why should we simply copy swapper_pg_dir to swsusp_pg_dir, instead do it in zap_low_mappings?).

?? Sorry, I do not understand. "instead of doing"?
Pavel

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

Hi!

Quoted 23 lines
Quoted 23 lines
Quoted 1 line

In which case, how's about this?

Certainly better, I'd say.

Quoted 6 lines
(quoted diff) +1 -1
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*

Review void zap_low_mappings (void) · line 434

Quoted 10 lines
(quoted diff) +7 -0
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();

But this still scares. It means calling convention is "may enable interrupts with >1 cpu, may not with == 1 cpu".

Quoted 6 lines
Quoted 1 line

Below patch should make things clean. How do you think?

Nice...

Could we perhaps reuse swsusp_pg_dir (just make it used for swsusp & suspend-to-ram) to save a bit more code? It is in arch/i386/mm/init.c

Ok, I guess this is what you want.

---

 linux-2.6.17-rc4-mm1-root/arch/i386/kernel/acpi/sleep.c  |   18 ---------------
 linux-2.6.17-rc4-mm1-root/arch/i386/kernel/acpi/wakeup.S |    2 -
 linux-2.6.17-rc4-mm1-root/arch/i386/mm/init.c            |   15 +-----------
 3 files changed, 3 insertions(+), 32 deletions(-)
arch/i386/kernel/acpi/wakeup.S renamed from arch/i386/kernel/acpi/wakeup.S~i386_direct_mapping +1 -1
diff -puN arch/i386/kernel/acpi/wakeup.S~i386_direct_mapping arch/i386/kernel/acpi/wakeup.S
@@ -56,7 +56,7 @@ wakeup_code:
 1:
 
 	# set up page table
-	movl	$swapper_pg_dir-__PAGE_OFFSET, %eax
+	movl	$swsusp_pg_dir-__PAGE_OFFSET, %eax
 	movl	%eax, %cr3
 
 	testl	$1, real_efer_save_restore - wakeup_code
arch/i386/kernel/acpi/sleep.c renamed from arch/i386/kernel/acpi/sleep.c~i386_direct_mapping +0 -18
diff -puN arch/i386/kernel/acpi/sleep.c~i386_direct_mapping arch/i386/kernel/acpi/sleep.c
@@ -11,30 +11,14 @@
 #include <linux/cpumask.h>
 
 #include <asm/smp.h>
-#include <asm/tlbflush.h>
 
 /* address in low memory of the wakeup routine. */
 unsigned long acpi_wakeup_address = 0;
 unsigned long acpi_video_flags;
 extern char wakeup_start, wakeup_end;
 
-extern void zap_low_mappings(void);
-
 extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
 
-static void init_low_mapping(pgd_t * pgd, int pgd_limit)
-{
-	int pgd_ofs = 0;
-
-	while ((pgd_ofs < pgd_limit)
-	       && (pgd_ofs + USER_PTRS_PER_PGD < PTRS_PER_PGD)) {
-		set_pgd(pgd, *(pgd + USER_PTRS_PER_PGD));
-		pgd_ofs++, pgd++;
-	}
-	WARN_ON(num_online_cpus() != 1);
-	local_flush_tlb();
-}
-
 /**
  * acpi_save_state_mem - save kernel state
  *
@@ -45,7 +29,6 @@ int acpi_save_state_mem(void)
 {
 	if (!acpi_wakeup_address)
 		return 1;
-	init_low_mapping(swapper_pg_dir, USER_PTRS_PER_PGD);
 	memcpy((void *)acpi_wakeup_address, &wakeup_start,
 	       &wakeup_end - &wakeup_start);
 	acpi_copy_wakeup_routine(acpi_wakeup_address);
@@ -58,7 +41,6 @@ int acpi_save_state_mem(void)
  */
 void acpi_restore_state_mem(void)
 {
-	zap_low_mappings();
 }
 
 /**
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~i386_direct_mapping +2 -13
diff -puN arch/i386/mm/init.c~i386_direct_mapping arch/i386/mm/init.c
@@ -386,7 +386,7 @@ static void __init pagetable_init (void)
 #endif
 }
 
-#ifdef CONFIG_SOFTWARE_SUSPEND
+#if defined(CONFIG_SOFTWARE_SUSPEND) || defined(CONFIG_ACPI_SLEEP)
 /*
  * Swap suspend & friends need this for resume because things like the intel-agp
  * driver might have split up a kernel 4MB mapping.
@@ -422,18 +422,7 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	/*
-	 * We can be called at suspend/resume time, with local interrupts
-	 * disabled.  But flush_tlb_all() requires that local interrupts be
-	 * enabled.
-	 *
-	 * Happily, the APs are not yet started, so we can use local_flush_tlb()
-	 * in that case
-	 */
-	if (num_online_cpus() == 1)
-		local_flush_tlb();
-	else
-		flush_tlb_all();
+	flush_tlb_all();
 }
 
 static int disable_nx __initdata = 0;

_

Acked-by
#12 lore raw

Hi!

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 6 lines
(quoted diff) +1 -1
@@ -420,7 +421,14 @@ void zap_low_mappings (void)
 #else
 		set_pgd(swapper_pg_dir+i, __pgd(0));
 #endif
-	if (cpus_weight(cpu_online_map) == 1)
+	/*

Review void zap_low_mappings (void) · line 434

Quoted 10 lines
(quoted diff) +7 -0
+	 * We can be called at suspend/resume time, with local interrupts
+	 * disabled.  But flush_tlb_all() requires that local interrupts be
+	 * enabled.
+	 *
+	 * Happily, the APs are not yet started, so we can use local_flush_tlb()	 * in that case
+	 */
+	if (num_online_cpus() == 1)
 		local_flush_tlb();
 	else
 		flush_tlb_all();

But this still scares. It means calling convention is "may enable interrupts with >1 cpu, may not with == 1 cpu".

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Below patch should make things clean. How do you think?

Nice...

Could we perhaps reuse swsusp_pg_dir (just make it used for swsusp & suspend-to-ram) to save a bit more code? It is in arch/i386/mm/init.c

Ok, I guess this is what you want.

Yes, thanks a lot for patience.

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