Skip to contentSkip to conversation

x86: make sure wakeup code is below 1M

RFC PATCH In review Yinghai Lu 6 participants 42 messages Nov 9, 2009 – Nov 13, 2009

Subsystems (3)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

RFC PATCH 1/1 x86: make sure wakeup code is below 1M

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)
arch/x86/include/asm/acpi.h +1 -1
Index: linux-2.6/arch/x86/include/asm/acpi.h
===================================================================
@@ -118,7 +118,7 @@ extern void acpi_restore_state_mem(void)
 extern unsigned long acpi_wakeup_address;
 
 /* early initialization routine */
-extern void acpi_reserve_bootmem(void);
+extern void acpi_reserve_memory(void);
 
 /*
  * Check if the CPU can handle C2 and deeper
arch/x86/kernel/acpi/sleep.c +9 -6
Index: linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}
-
-	acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
+	acpi_realmode = (unsigned long) phys_to_virt(mem);
+	acpi_wakeup_address = mem;
+	reserve_early(mem, mem + WAKEUP_SIZE, "WAKEUP");
 }
 
 
arch/x86/kernel/setup.c +7 -6
Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
@@ -897,6 +897,13 @@ void __init setup_arch(char **cmdline_p)
 
 	reserve_brk();
 
+#ifdef CONFIG_ACPI_SLEEP
+	/*
+	 * Reserve low memory region for sleep support.
+	 * even before init_memory_mapping
+	 */
+	acpi_reserve_bootmem();
+#endif
 	init_gbpages();
 
 	/* max_pfn_mapped is updated here */
@@ -948,12 +955,6 @@ void __init setup_arch(char **cmdline_p)
 
 	initmem_init(0, max_pfn, acpi, k8);
 
-#ifdef CONFIG_ACPI_SLEEP
-	/*
-	 * Reserve low memory region for sleep support.
-	 */
-	acpi_reserve_bootmem();
-#endif
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
#1 lore raw
Quoted 6 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

I generally like it, two comments below.

Quoted 11 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Index: linux-2.6/arch/x86/include/asm/acpi.h
===================================================================

arch/x86/include/asm/acpi.h extern void acpi_restore_state_mem(void) · line 121

Quoted 5 lines
arch/x86/include/asm/acpi.h +1 -1
@@ -118,7 +118,7 @@ extern void acpi_restore_state_mem(void)
 extern unsigned long acpi_wakeup_address;
 
 /* early initialization routine */
-extern void acpi_reserve_bootmem(void);
+extern void acpi_reserve_memory(void);

If you change the name of the function, IMO it would be better to call it something like acpi_reserve_wakeup_memory(). This way it would be clear what the memory is reserved for.

Quoted 24 lines
arch/x86/include/asm/acpi.h +0 -0
 /*
  * Check if the CPU can handle C2 and deeper

Index: linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================

arch/x86/kernel/acpi/sleep.c +4 -2
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {

arch/x86/kernel/acpi/sleep.c void acpi_restore_state_mem(void) · line 141

Quoted 10 lines
arch/x86/kernel/acpi/sleep.c +2 -2
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {

Could we change the condition to avoid the "-1L" here? It doesn't look very nice.

arch/x86/kernel/acpi/sleep.c void acpi_restore_state_mem(void) · line 148

Quoted 9 lines
arch/x86/kernel/acpi/sleep.c +3 -2
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}
-
-	acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
+	acpi_realmode = (unsigned long) phys_to_virt(mem);
+	acpi_wakeup_address = mem;
+	reserve_early(mem, mem + WAKEUP_SIZE, "WAKEUP");
 }

Thanks,
Rafael

#41 lore raw
In reply to Yinghai Lu
Quoted 6 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

I generally like it, two comments below.

Quoted 11 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Index: linux-2.6/arch/x86/include/asm/acpi.h
===================================================================

arch/x86/include/asm/acpi.h extern void acpi_restore_state_mem(void) · line 121

Quoted 5 lines
arch/x86/include/asm/acpi.h +1 -1
@@ -118,7 +118,7 @@ extern void acpi_restore_state_mem(void)
 extern unsigned long acpi_wakeup_address;
 
 /* early initialization routine */
-extern void acpi_reserve_bootmem(void);
+extern void acpi_reserve_memory(void);

If you change the name of the function, IMO it would be better to call it something like acpi_reserve_wakeup_memory(). This way it would be clear what the memory is reserved for.

Quoted 24 lines
arch/x86/include/asm/acpi.h +0 -0
 /*
  * Check if the CPU can handle C2 and deeper

Index: linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================

arch/x86/kernel/acpi/sleep.c +4 -2
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {

arch/x86/kernel/acpi/sleep.c void acpi_restore_state_mem(void) · line 141

Quoted 10 lines
arch/x86/kernel/acpi/sleep.c +2 -2
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {

Could we change the condition to avoid the "-1L" here? It doesn't look very nice.

arch/x86/kernel/acpi/sleep.c void acpi_restore_state_mem(void) · line 148

Quoted 9 lines
arch/x86/kernel/acpi/sleep.c +3 -2
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}
-
-	acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
+	acpi_realmode = (unsigned long) phys_to_virt(mem);
+	acpi_wakeup_address = mem;
+	reserve_early(mem, mem + WAKEUP_SIZE, "WAKEUP");
 }

Thanks,
Rafael

author
#2 lore raw

PATCH 1/1 x86: make sure wakeup code is below 1M -v2

In reply to Rafael J. Wysocki

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)
arch/x86/include/asm/acpi.h +1 -1
Index: linux-2.6/arch/x86/include/asm/acpi.h
===================================================================
@@ -118,7 +118,7 @@ extern void acpi_restore_state_mem(void)
 extern unsigned long acpi_wakeup_address;
 
 /* early initialization routine */
-extern void acpi_reserve_bootmem(void);
+extern void acpi_reserve_wakeup_memory(void);
 
 /*
  * Check if the CPU can handle C2 and deeper
arch/x86/kernel/acpi/sleep.c +9 -6
Index: linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_wakeup_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_wakeup_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}
-
-	acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
+	acpi_realmode = (unsigned long) phys_to_virt(mem);
+	acpi_wakeup_address = mem;
+	reserve_early(mem, mem + WAKEUP_SIZE, "ACPI WAKEUP");
 }
 
 
arch/x86/kernel/setup.c +7 -6
Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
@@ -905,6 +905,13 @@ void __init setup_arch(char **cmdline_p)
 
 	reserve_brk();
 
+#ifdef CONFIG_ACPI_SLEEP
+	/*
+	 * Reserve low memory region for sleep support.
+	 * even before init_memory_mapping
+	 */
+	acpi_reserve_wakeup_memory();
+#endif
 	init_gbpages();
 
 	/* max_pfn_mapped is updated here */
@@ -956,12 +963,6 @@ void __init setup_arch(char **cmdline_p)
 
 	initmem_init(0, max_pfn, acpi, k8);
 
-#ifdef CONFIG_ACPI_SLEEP
-	/*
-	 * Reserve low memory region for sleep support.
-	 */
-	acpi_reserve_bootmem();
-#endif
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
author
#3 lore raw

PATCH 1/1 x86: make sure wakeup code is below 1M -v2

In reply to Rafael J. Wysocki

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)
arch/x86/include/asm/acpi.h +1 -1
Index: linux-2.6/arch/x86/include/asm/acpi.h
===================================================================
@@ -118,7 +118,7 @@ extern void acpi_restore_state_mem(void)
 extern unsigned long acpi_wakeup_address;
 
 /* early initialization routine */
-extern void acpi_reserve_bootmem(void);
+extern void acpi_reserve_wakeup_memory(void);
 
 /*
  * Check if the CPU can handle C2 and deeper
arch/x86/kernel/acpi/sleep.c +9 -6
Index: linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_wakeup_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_wakeup_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}
-
-	acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
+	acpi_realmode = (unsigned long) phys_to_virt(mem);
+	acpi_wakeup_address = mem;
+	reserve_early(mem, mem + WAKEUP_SIZE, "ACPI WAKEUP");
 }
 
 
arch/x86/kernel/setup.c +7 -6
Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
@@ -905,6 +905,13 @@ void __init setup_arch(char **cmdline_p)
 
 	reserve_brk();
 
+#ifdef CONFIG_ACPI_SLEEP
+	/*
+	 * Reserve low memory region for sleep support.
+	 * even before init_memory_mapping
+	 */
+	acpi_reserve_wakeup_memory();
+#endif
 	init_gbpages();
 
 	/* max_pfn_mapped is updated here */
@@ -956,12 +963,6 @@ void __init setup_arch(char **cmdline_p)
 
 	initmem_init(0, max_pfn, acpi, k8);
 
-#ifdef CONFIG_ACPI_SLEEP
-	/*
-	 * Reserve low memory region for sleep support.
-	 */
-	acpi_reserve_bootmem();
-#endif
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
#4 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

Quoted 7 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

Quoted 7 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Looks good. Rafael, Peter, does it look good to you too?

Ingo

#5 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 7 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

Quoted 7 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Looks good. Rafael, Peter, does it look good to you too?

Ingo

reviewer Acked-by
#6 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

Quoted 8 lines
Quoted 5 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Looks good. Rafael, Peter, does it look good to you too?

Looks sane to me.

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
reviewer Acked-by
#7 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Ingo Molnar
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

Quoted 8 lines
Quoted 5 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Looks good. Rafael, Peter, does it look good to you too?

Looks sane to me.

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#10 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

Thanks.

Quoted 100 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Index: linux-2.6/arch/x86/include/asm/acpi.h
===================================================================

arch/x86/include/asm/acpi.h +1 -1
@@ -118,7 +118,7 @@ extern void acpi_restore_state_mem(void)
 extern unsigned long acpi_wakeup_address;
 
 /* early initialization routine */
-extern void acpi_reserve_bootmem(void);
+extern void acpi_reserve_wakeup_memory(void);
 
 /*
  * Check if the CPU can handle C2 and deeper

Index: linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================

arch/x86/kernel/acpi/sleep.c +9 -6
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_wakeup_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_wakeup_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}
-
-	acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
+	acpi_realmode = (unsigned long) phys_to_virt(mem);
+	acpi_wakeup_address = mem;
+	reserve_early(mem, mem + WAKEUP_SIZE, "ACPI WAKEUP");
 }
 
 

Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================

arch/x86/kernel/setup.c +7 -7
@@ -905,6 +905,13 @@ void __init setup_arch(char **cmdline_p)
 
 	reserve_brk();
 
+#ifdef CONFIG_ACPI_SLEEP
+	/*
+	 * Reserve low memory region for sleep support.
+	 * even before init_memory_mapping
+	 */
+	acpi_reserve_wakeup_memory();
+#endif
 	init_gbpages();
 
 	/* max_pfn_mapped is updated here */
@@ -956,12 +963,6 @@ void __init setup_arch(char **cmdline_p)
 
 	initmem_init(0, max_pfn, acpi, k8);
 
-#ifdef CONFIG_ACPI_SLEEP
-	/*
-	 * Reserve low memory region for sleep support.
-	 */
-	acpi_reserve_bootmem();
-#endif
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
--

To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#27 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

Thanks.

Quoted 100 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Index: linux-2.6/arch/x86/include/asm/acpi.h
===================================================================

arch/x86/include/asm/acpi.h +1 -1
@@ -118,7 +118,7 @@ extern void acpi_restore_state_mem(void)
 extern unsigned long acpi_wakeup_address;
 
 /* early initialization routine */
-extern void acpi_reserve_bootmem(void);
+extern void acpi_reserve_wakeup_memory(void);
 
 /*
  * Check if the CPU can handle C2 and deeper

Index: linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================

arch/x86/kernel/acpi/sleep.c +9 -6
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_wakeup_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_wakeup_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}
-
-	acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
+	acpi_realmode = (unsigned long) phys_to_virt(mem);
+	acpi_wakeup_address = mem;
+	reserve_early(mem, mem + WAKEUP_SIZE, "ACPI WAKEUP");
 }
 
 

Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================

arch/x86/kernel/setup.c +7 -7
@@ -905,6 +905,13 @@ void __init setup_arch(char **cmdline_p)
 
 	reserve_brk();
 
+#ifdef CONFIG_ACPI_SLEEP
+	/*
+	 * Reserve low memory region for sleep support.
+	 * even before init_memory_mapping
+	 */
+	acpi_reserve_wakeup_memory();
+#endif
 	init_gbpages();
 
 	/* max_pfn_mapped is updated here */
@@ -956,12 +963,6 @@ void __init setup_arch(char **cmdline_p)
 
 	initmem_init(0, max_pfn, acpi, k8);
 
-#ifdef CONFIG_ACPI_SLEEP
-	/*
-	 * Reserve low memory region for sleep support.
-	 */
-	acpi_reserve_bootmem();
-#endif
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
--

To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Ingo Molnar
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

Quoted 7 lines
Quoted 5 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Looks good. Rafael, Peter, does it look good to you too?

Yes, it does.

#9 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Ingo Molnar
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

Quoted 7 lines
Quoted 5 lines
---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)

Looks good. Rafael, Peter, does it look good to you too?

Yes, it does.

author
#11 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to ykzhao
Quoted 5 lines · ykzhao
Quoted 4 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

Quoted 8 lines
Quoted 1 line

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

YH

author
#12 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to ykzhao
Quoted 5 lines · ykzhao
Quoted 4 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

Quoted 8 lines
Quoted 1 line

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

YH

#28 lore raw

[tip:x86/mm] x86: Make sure wakeup trampoline code is below 1MB

In reply to Yinghai Lu
Commit-ID:  196cf0d67acad70ebb2572da489d5cc7066cdd05
Gitweb:     http://git.kernel.org/tip/196cf0d67acad70ebb2572da489d5cc7066cdd05
Author:     Yinghai Lu <[email protected]>
AuthorDate: Tue, 10 Nov 2009 18:27:23 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 11 Nov 2009 20:14:32 +0100

x86: Make sure wakeup trampoline code is below 1MB

Instead of using bootmem, try find_e820_area()/reserve_early(), and call acpi_reserve_memory() early, to allocate the wakeup trampoline code area below 1M.

This is more reliable, and it also removes a dependency on bootmem.

-v2: change function name to acpi_reserve_wakeup_memory(),
as suggested by Rafael.

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)
arch/x86/include/asm/acpi.h +1 -1
index e3d4a0d..60d2b2d 100644
@@ -118,7 +118,7 @@ extern void acpi_restore_state_mem(void);
 extern unsigned long acpi_wakeup_address;
 
 /* early initialization routine */
-extern void acpi_reserve_bootmem(void);
+extern void acpi_reserve_wakeup_memory(void);
 
 /*
  * Check if the CPU can handle C2 and deeper
arch/x86/kernel/acpi/sleep.c +9 -6
index ca93638..4a41145 100644
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_wakeup_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_wakeup_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}
-
-	acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
+	acpi_realmode = (unsigned long) phys_to_virt(mem);
+	acpi_wakeup_address = mem;
+	reserve_early(mem, mem + WAKEUP_SIZE, "ACPI WAKEUP");
 }
 
 
arch/x86/kernel/setup.c +7 -6
index f891419..0a6e94a 100644
@@ -897,6 +897,13 @@ void __init setup_arch(char **cmdline_p)
 
 	reserve_brk();
 
+#ifdef CONFIG_ACPI_SLEEP
+	/*
+	 * Reserve low memory region for sleep support.
+	 * even before init_memory_mapping
+	 */
+	acpi_reserve_wakeup_memory();
+#endif
 	init_gbpages();
 
 	/* max_pfn_mapped is updated here */
@@ -948,12 +955,6 @@ void __init setup_arch(char **cmdline_p)
 
 	initmem_init(0, max_pfn, acpi, k8);
 
-#ifdef CONFIG_ACPI_SLEEP
-	/*
-	 * Reserve low memory region for sleep support.
-	 */
-	acpi_reserve_bootmem();
-#endif
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
#29 lore raw

[tip:x86/mm] x86: Make sure wakeup trampoline code is below 1MB

In reply to Yinghai Lu
Commit-ID:  196cf0d67acad70ebb2572da489d5cc7066cdd05
Gitweb:     http://git.kernel.org/tip/196cf0d67acad70ebb2572da489d5cc7066cdd05
Author:     Yinghai Lu <[email protected]>
AuthorDate: Tue, 10 Nov 2009 18:27:23 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 11 Nov 2009 20:14:32 +0100

x86: Make sure wakeup trampoline code is below 1MB

Instead of using bootmem, try find_e820_area()/reserve_early(), and call acpi_reserve_memory() early, to allocate the wakeup trampoline code area below 1M.

This is more reliable, and it also removes a dependency on bootmem.

-v2: change function name to acpi_reserve_wakeup_memory(),
as suggested by Rafael.

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/acpi.h  |    2 +-
 arch/x86/kernel/acpi/sleep.c |   15 +++++++++------
 arch/x86/kernel/setup.c      |   13 +++++++------
 3 files changed, 17 insertions(+), 13 deletions(-)
arch/x86/include/asm/acpi.h +1 -1
index e3d4a0d..60d2b2d 100644
@@ -118,7 +118,7 @@ extern void acpi_restore_state_mem(void);
 extern unsigned long acpi_wakeup_address;
 
 /* early initialization routine */
-extern void acpi_reserve_bootmem(void);
+extern void acpi_reserve_wakeup_memory(void);
 
 /*
  * Check if the CPU can handle C2 and deeper
arch/x86/kernel/acpi/sleep.c +9 -6
index ca93638..4a41145 100644
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_wakeup_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_wakeup_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}
-
-	acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
+	acpi_realmode = (unsigned long) phys_to_virt(mem);
+	acpi_wakeup_address = mem;
+	reserve_early(mem, mem + WAKEUP_SIZE, "ACPI WAKEUP");
 }
 
 
arch/x86/kernel/setup.c +7 -6
index f891419..0a6e94a 100644
@@ -897,6 +897,13 @@ void __init setup_arch(char **cmdline_p)
 
 	reserve_brk();
 
+#ifdef CONFIG_ACPI_SLEEP
+	/*
+	 * Reserve low memory region for sleep support.
+	 * even before init_memory_mapping
+	 */
+	acpi_reserve_wakeup_memory();
+#endif
 	init_gbpages();
 
 	/* max_pfn_mapped is updated here */
@@ -948,12 +955,6 @@ void __init setup_arch(char **cmdline_p)
 
 	initmem_init(0, max_pfn, acpi, k8);
 
-#ifdef CONFIG_ACPI_SLEEP
-	/*
-	 * Reserve low memory region for sleep support.
-	 */
-	acpi_reserve_bootmem();
-#endif
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
#13 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 12 lines · Yinghai Lu
Quoted 11 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

Quoted 4 lines
Quoted 2 lines

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

At the same time the acpi_reserve_bootmem is called after initializing the boot mem allocator. Can we continue to reserve some region by using find_e820_area?

thanks.

Quoted 2 lines

YH

#14 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 12 lines · Yinghai Lu
Quoted 11 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

Quoted 4 lines
Quoted 2 lines

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

At the same time the acpi_reserve_bootmem is called after initializing the boot mem allocator. Can we continue to reserve some region by using find_e820_area?

thanks.

Quoted 2 lines

YH

author
#15 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

Quoted 13 lines · ykzhao
Quoted 12 lines · Yinghai Lu
Quoted 11 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

right after that will use reserve_bootmem for those range in initmem_init.

also we could reserve_early there and let bootmem conversion to do that for us.

but for numa there is some chance to use other node bootmem to for that bootdata and bitmap. so make it simple just use reserve_bootmem there.

YH

author
#16 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to ykzhao
Quoted 13 lines · ykzhao
Quoted 12 lines · Yinghai Lu
Quoted 11 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

right after that will use reserve_bootmem for those range in initmem_init.

also we could reserve_early there and let bootmem conversion to do that for us.

but for numa there is some chance to use other node bootmem to for that bootdata and bitmap. so make it simple just use reserve_bootmem there.

YH

#17 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

Quoted 16 lines · Yinghai Lu
Quoted 15 lines · ykzhao
Quoted 14 lines · Yinghai Lu
Quoted 13 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

right after that will use reserve_bootmem for those range in initmem_init.

Yes. The reserve_bootmem is called for the range in initmem_init. But the reserved_early array is not updated.

Quoted 7 lines

also we could reserve_early there and let bootmem conversion to do that for us.

but for numa there is some chance to use other node bootmem to for that bootdata and bitmap. so make it simple just use reserve_bootmem there.

YH

#18 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 16 lines · Yinghai Lu
Quoted 15 lines · ykzhao
Quoted 14 lines · Yinghai Lu
Quoted 13 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

right after that will use reserve_bootmem for those range in initmem_init.

Yes. The reserve_bootmem is called for the range in initmem_init. But the reserved_early array is not updated.

Quoted 7 lines

also we could reserve_early there and let bootmem conversion to do that for us.

but for numa there is some chance to use other node bootmem to for that bootdata and bitmap. so make it simple just use reserve_bootmem there.

YH

author
#19 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

Quoted 17 lines · ykzhao
Quoted 16 lines · Yinghai Lu
Quoted 15 lines · ykzhao
Quoted 14 lines · Yinghai Lu
Quoted 13 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

right after that will use reserve_bootmem for those range in initmem_init.

Yes. The reserve_bootmem is called for the range in initmem_init. But the reserved_early array is not updated.

it is not needed anymore because bootmem for that node is ready at that point, could use reserve_bootmem_node directly. and before that early_res_to_bootmem will convert that early resource that fall into that node range to bootmem reserved too.

please check code setup_node_bootmem/early_node_mem/early_res_to_bootmem ...and reserve_bootmem_node...

YH

author
#26 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to ykzhao
Quoted 17 lines · ykzhao
Quoted 16 lines · Yinghai Lu
Quoted 15 lines · ykzhao
Quoted 14 lines · Yinghai Lu
Quoted 13 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

right after that will use reserve_bootmem for those range in initmem_init.

Yes. The reserve_bootmem is called for the range in initmem_init. But the reserved_early array is not updated.

it is not needed anymore because bootmem for that node is ready at that point, could use reserve_bootmem_node directly. and before that early_res_to_bootmem will convert that early resource that fall into that node range to bootmem reserved too.

please check code setup_node_bootmem/early_node_mem/early_res_to_bootmem ...and reserve_bootmem_node...

YH

#20 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 23 lines · Yinghai Lu
Quoted 22 lines · ykzhao
Quoted 21 lines · Yinghai Lu
Quoted 20 lines · ykzhao
Quoted 7 lines · Yinghai Lu
Quoted 6 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

Quoted 8 lines
Quoted 7 lines

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

right after that will use reserve_bootmem for those range in initmem_init.

Yes. The reserve_bootmem is called for the range in initmem_init. But the reserved_early array is not updated.

it is not needed anymore because bootmem for that node is ready at that point, could use reserve_bootmem_node directly. and before that early_res_to_bootmem will convert that early resource that fall into that node range to bootmem reserved too.

After the bootmem allocator is initialized, the early_res_to_bootmem will convert the resource in reserved_early array and reserve them in the bootmem.

In this patch the find_e820_area is used in the acpi_reserve_wakeup_memory, which is called after initializing the bootmem allocator.
Can we still use the find_e820_area after the bootmem allocator is initialized?
It seems that the bootmem bitmap is also found by using the find_e820_area. But we don't update the reserved_early array any more. Maybe we will get the overlap address with the bootmem bitmap for the wakeup code.

thanks.

Quoted 5 lines

please check code setup_node_bootmem/early_node_mem/early_res_to_bootmem ...and reserve_bootmem_node...

YH

#21 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 23 lines · Yinghai Lu
Quoted 22 lines · ykzhao
Quoted 21 lines · Yinghai Lu
Quoted 20 lines · ykzhao
Quoted 7 lines · Yinghai Lu
Quoted 6 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

Quoted 8 lines
Quoted 7 lines

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

right after that will use reserve_bootmem for those range in initmem_init.

Yes. The reserve_bootmem is called for the range in initmem_init. But the reserved_early array is not updated.

it is not needed anymore because bootmem for that node is ready at that point, could use reserve_bootmem_node directly. and before that early_res_to_bootmem will convert that early resource that fall into that node range to bootmem reserved too.

After the bootmem allocator is initialized, the early_res_to_bootmem will convert the resource in reserved_early array and reserve them in the bootmem.

In this patch the find_e820_area is used in the acpi_reserve_wakeup_memory, which is called after initializing the bootmem allocator.
Can we still use the find_e820_area after the bootmem allocator is initialized?
It seems that the bootmem bitmap is also found by using the find_e820_area. But we don't update the reserved_early array any more. Maybe we will get the overlap address with the bootmem bitmap for the wakeup code.

thanks.

Quoted 5 lines

please check code setup_node_bootmem/early_node_mem/early_res_to_bootmem ...and reserve_bootmem_node...

YH

#22 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

Quoted 6 lines · ykzhao

In this patch the find_e820_area is used in the acpi_reserve_wakeup_memory, which is called after initializing the bootmem allocator.
Can we still use the find_e820_area after the bootmem allocator is initialized?

Obviously not: the bootmem allocator now thinks it owns memory, and it wouldn't know not to allocate something that is later claimed by find_e820_area. Problem.

Quoted 4 lines

It seems that the bootmem bitmap is also found by using the find_e820_area. But we don't update the reserved_early array any more. Maybe we will get the overlap address with the bootmem bitmap for the wakeup code.

Not just the bitmap, but any bootmem allocation could conflict...

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#23 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to ykzhao
Quoted 6 lines · ykzhao

In this patch the find_e820_area is used in the acpi_reserve_wakeup_memory, which is called after initializing the bootmem allocator.
Can we still use the find_e820_area after the bootmem allocator is initialized?

Obviously not: the bootmem allocator now thinks it owns memory, and it wouldn't know not to allocate something that is later claimed by find_e820_area. Problem.

Quoted 4 lines

It seems that the bootmem bitmap is also found by using the find_e820_area. But we don't update the reserved_early array any more. Maybe we will get the overlap address with the bootmem bitmap for the wakeup code.

Not just the bitmap, but any bootmem allocation could conflict...

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#30 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 4 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

Does it fix anything? I can't tell from the changelog...

Quoted 1 line

Please CC me on suspend patches.

Quoted 27 lines

/*
* Check if the CPU can handle C2 and deeper
Index: linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================

arch/x86/kernel/acpi/sleep.c +4 -2
@@ -119,29 +119,32 @@ void acpi_restore_state_mem(void)
 
 
 /**
- * acpi_reserve_bootmem - do _very_ early ACPI initialisation
+ * acpi_reserve_wakeup_memory - do _very_ early ACPI initialisation
  *
  * We allocate a page from the first 1MB of memory for the wakeup
  * routine for when we come back from a sleep state. The
  * runtime allocator allows specification of <16MB pages, but not
  * <1MB pages.
  */
-void __init acpi_reserve_bootmem(void)
+void __init acpi_reserve_wakeup_memory(void)
 {
+	unsigned long mem;
+
 	if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
 		printk(KERN_ERR
 		       "ACPI: Wakeup code way too big, S3 disabled.\n");
 		return;

arch/x86/kernel/acpi/sleep.c void acpi_restore_state_mem(void) · line 144

Quoted 10 lines
arch/x86/kernel/acpi/sleep.c +2 -2
 	}
 
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}

How is it better then old code?

Pavel

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

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 24 lines · Yinghai Lu
Quoted 23 lines · ykzhao
Quoted 22 lines · Yinghai Lu
Quoted 13 lines · ykzhao
Quoted 12 lines · Yinghai Lu
Quoted 11 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

right after that will use reserve_bootmem for those range in initmem_init.

Quoted 8 lines
Quoted 2 lines

Yes. The reserve_bootmem is called for the range in initmem_init. But the reserved_early array is not updated.

it is not needed anymore because bootmem for that node is ready at that point, could use reserve_bootmem_node directly. and before that early_res_to_bootmem will convert that early resource that fall into that node range to bootmem reserved too.

please check code setup_node_bootmem/early_node_mem/early_res_to_bootmem ...and reserve_bootmem_node...

Sorry that I don't notice that the function
of acpi_reserve_wakeup_memory is also moved early before initializing the bootmem allocator.
If so, there is no problem.

thanks.

Quoted 2 lines

YH

#25 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Yinghai Lu
Quoted 24 lines · Yinghai Lu
Quoted 23 lines · ykzhao
Quoted 22 lines · Yinghai Lu
Quoted 13 lines · ykzhao
Quoted 12 lines · Yinghai Lu
Quoted 11 lines · ykzhao
Quoted 5 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

-v2: change function name to acpi_reserve_wakeup_memory according to Rafael

It seems that the function of find_e820_area is called in several places.

Quoted 1 line

Initmem_init: bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT,

bootmap_size, PAGE_SIZE);

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

If we also call it in the acpi_reserve_wakeup_memory, do we get the same base address as that obtained in initmem_init?

no. find_e820_area will check the reserve res array that could be updated by reserve_early.

It will check the reserved region array when calling the function of find_e820_area.
But it seems that the array is not updated when the find_e820_area is called in the function of initmem_init.

right after that will use reserve_bootmem for those range in initmem_init.

Quoted 8 lines
Quoted 2 lines

Yes. The reserve_bootmem is called for the range in initmem_init. But the reserved_early array is not updated.

it is not needed anymore because bootmem for that node is ready at that point, could use reserve_bootmem_node directly. and before that early_res_to_bootmem will convert that early resource that fall into that node range to bootmem reserved too.

please check code setup_node_bootmem/early_node_mem/early_res_to_bootmem ...and reserve_bootmem_node...

Sorry that I don't notice that the function
of acpi_reserve_wakeup_memory is also moved early before initializing the bootmem allocator.
If so, there is no problem.

thanks.

Quoted 2 lines

YH

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

author
#31 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Pavel Machek
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

arch/x86/kernel/acpi/sleep.c +1 -1
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
Quoted 7 lines

arch/x86/kernel/acpi/sleep.c void acpi_restore_state_mem(void) · line 144

Quoted 5 lines
arch/x86/kernel/acpi/sleep.c +1 -1
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}

How is it better then old code?

could get range below 1M.

alloc_bootmem_low can not make sure get that below 1M.

init_memory_mapping could use below 1M as page table...

so need to get some buffer for acpi wakeup realmode code.

YH

author
#32 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Pavel Machek
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

arch/x86/kernel/acpi/sleep.c +1 -1
-	acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
+	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
Quoted 7 lines

arch/x86/kernel/acpi/sleep.c void acpi_restore_state_mem(void) · line 144

Quoted 5 lines
arch/x86/kernel/acpi/sleep.c +1 -1
-	if (!acpi_realmode) {
+	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
 		return;
 	}

How is it better then old code?

could get range below 1M.

alloc_bootmem_low can not make sure get that below 1M.

init_memory_mapping could use below 1M as page table...

so need to get some buffer for acpi wakeup realmode code.

YH

#33 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Pavel Machek
Quoted 7 lines · Pavel Machek
Quoted 4 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

Does it fix anything? I can't tell from the changelog...

Yes, it does. If the area is above 1M, we can't run real mode code from it.

This matters for NUMA machines supporting S3 (yes, there are a few models out there).

Thanks,
Rafael

#40 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Pavel Machek
Quoted 7 lines · Pavel Machek
Quoted 4 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

Does it fix anything? I can't tell from the changelog...

Yes, it does. If the area is above 1M, we can't run real mode code from it.

This matters for NUMA machines supporting S3 (yes, there are a few models out there).

Thanks,
Rafael

#34 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Pavel Machek
Quoted 4 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

Quoted 7 lines
Quoted 1 line

Does it fix anything? I can't tell from the changelog...

Yes, it does. If the area is above 1M, we can't run real mode code from it.

This matters for NUMA machines supporting S3 (yes, there are a few models out there).

It might also matter in more exotic kernels that might do some large allocations. (say 'nopentium' can cause +1MB/+2MB of kernel page table allocations per one GB of RAM)

Physical constraints to allocations (which this is) should be expressed early and with high priority, to make sure they can be met.

Ingo

#35 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Pavel Machek
Quoted 4 lines · Yinghai Lu

try to find_e820_area/reserve_early, and call acpi_reserve_memory early

to get area is below 1M

Quoted 7 lines
Quoted 1 line

Does it fix anything? I can't tell from the changelog...

Yes, it does. If the area is above 1M, we can't run real mode code from it.

This matters for NUMA machines supporting S3 (yes, there are a few models out there).

It might also matter in more exotic kernels that might do some large allocations. (say 'nopentium' can cause +1MB/+2MB of kernel page table allocations per one GB of RAM)

Physical constraints to allocations (which this is) should be expressed early and with high priority, to make sure they can be met.

Ingo

#36 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

Quoted 4 lines · Ingo Molnar

Physical constraints to allocations (which this is) should be expressed early and with high priority, to make sure they can be met.

Indeed, and in this case this means before bootmem allocator initialization.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#37 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to Ingo Molnar
Quoted 4 lines · Ingo Molnar

Physical constraints to allocations (which this is) should be expressed early and with high priority, to make sure they can be met.

Indeed, and in this case this means before bootmem allocator initialization.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#38 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

Quoted 7 lines · H. Peter Anvin
Quoted 4 lines · Ingo Molnar

Physical constraints to allocations (which this is) should be expressed early and with high priority, to make sure they can be met.

Indeed, and in this case this means before bootmem allocator initialization.

The other advantage of Yinghai's patch is that it removes a bootmem usage from x86, which moves us a bit forward on the road to remove the bootmem allocator altogether and go from early allocators to slab straight away.

Ingo

#39 lore raw

Re: [PATCH] x86: make sure wakeup code is below 1M -v2

In reply to H. Peter Anvin
Quoted 7 lines · H. Peter Anvin
Quoted 4 lines · Ingo Molnar

Physical constraints to allocations (which this is) should be expressed early and with high priority, to make sure they can be met.

Indeed, and in this case this means before bootmem allocator initialization.

The other advantage of Yinghai's patch is that it removes a bootmem usage from x86, which moves us a bit forward on the road to remove the bootmem allocator altogether and go from early allocators to slab straight away.

Ingo