Skip to contentSkip to conversation

Hibernate: Do not assume the first e820 area to be RAM

PATCH Superseded Lee, Chun-Yi 5 participants 6 messages Aug 11, 2014 – Sep 10, 2014 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Hibernate: Do not assume the first e820 area to be RAM

In arch/x86/kernel/setup.c::trim_bios_range(), the codes introduced by 1b5576e6 (base on d8a9e6a5), it updates the first 4Kb of memory to be E820_RESERVED region. That's because it's a BIOS owned area but generally not listed in the E820 table:

[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000096fff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000097000-0x0000000000097fff] reserved
...
[    0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable

But the region of first 4Kb didn't register to nosave memory:

[    0.000000] PM: Registered nosave memory: [mem 0x00097000-0x00097fff]
[    0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]

The codes in e820_mark_nosave_regions() assumes the first e820 area to be RAM, so it causes the first 4Kb E820_RESERVED region ignored when register to nosave. This patch removed assumption of the first e820 area.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/e820.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/e820.c +3 -4
index 988c00a..d595240 100644
@@ -682,18 +682,17 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
  * hibernation (32 bit) or software suspend and suspend to RAM (64 bit).
  *
  * This function requires the e820 map to be sorted and without any
- * overlapping entries and assumes the first e820 area to be RAM.
+ * overlapping entries.
  */
 void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 {
 	int i;
 	unsigned long pfn;
 
-	pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
-	for (i = 1; i < e820.nr_map; i++) {
+	for (i = 0; i < e820.nr_map; i++) {
 		struct e820entry *ei = &e820.map[i];
 
-		if (pfn < PFN_UP(ei->addr))
+		if (i > 0 && pfn < PFN_UP(ei->addr))
 			register_nosave_region(pfn, PFN_UP(ei->addr));
 
 		pfn = PFN_DOWN(ei->addr + ei->size);
Signature · 1 line
1.8.4.5
Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Chun-Yi

In arch/x86/kernel/setup.c::trim_bios_range(), the codes introduced by 1b5576e6 (base on d8a9e6a5), it updates the first 4Kb of memory to be E820_RESERVED region. That's because it's a BIOS owned area but generally not listed in the E820 table:

[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000096fff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000097000-0x0000000000097fff] reserved
...
[    0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable

But the region of first 4Kb didn't register to nosave memory:

[    0.000000] PM: Registered nosave memory: [mem 0x00097000-0x00097fff]
[    0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]
Quoted 6 lines

The codes in e820_mark_nosave_regions() assumes the first e820 area to be RAM, so it causes the first 4Kb E820_RESERVED region ignored when register to nosave. This patch removed assumption of the first e820 area.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw
In reply to Lee, Chun-Yi
Quoted 21 lines · Chun-Yi

In arch/x86/kernel/setup.c::trim_bios_range(), the codes introduced by 1b5576e6 (base on d8a9e6a5), it updates the first 4Kb of memory to be E820_RESERVED region. That's because it's a BIOS owned area but generally not listed in the E820 table:

[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000096fff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000097000-0x0000000000097fff] reserved
...
[    0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable

But the region of first 4Kb didn't register to nosave memory:

[    0.000000] PM: Registered nosave memory: [mem 0x00097000-0x00097fff]
[    0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]

The codes in e820_mark_nosave_regions() assumes the first e820 area to be RAM, so it causes the first 4Kb E820_RESERVED region ignored when register to nosave. This patch removed assumption of the first e820 area.

Quoted 7 lines
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>

Thomas, Ingo, Peter, any objections here?

If not, do you want to handle it or do you want me to do that?

Quoted 31 lines
---
 arch/x86/kernel/e820.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/e820.c +3 -4
index 988c00a..d595240 100644
@@ -682,18 +682,17 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
  * hibernation (32 bit) or software suspend and suspend to RAM (64 bit).
  *
  * This function requires the e820 map to be sorted and without any
- * overlapping entries and assumes the first e820 area to be RAM.
+ * overlapping entries.
  */
 void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 {
 	int i;
 	unsigned long pfn;
 
-	pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
-	for (i = 1; i < e820.nr_map; i++) {
+	for (i = 0; i < e820.nr_map; i++) {
 		struct e820entry *ei = &e820.map[i];
 
-		if (pfn < PFN_UP(ei->addr))
+		if (i > 0 && pfn < PFN_UP(ei->addr))
 			register_nosave_region(pfn, PFN_UP(ei->addr));
 
 		pfn = PFN_DOWN(ei->addr + ei->size);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
Acked-by
#3 lore raw
Quoted 22 lines · Rafael J. Wysocki
Quoted 21 lines · Chun-Yi

In arch/x86/kernel/setup.c::trim_bios_range(), the codes introduced by 1b5576e6 (base on d8a9e6a5), it updates the first 4Kb of memory to be E820_RESERVED region. That's because it's a BIOS owned area but generally not listed in the E820 table:

[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000096fff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000097000-0x0000000000097fff] reserved
...
[    0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable

But the region of first 4Kb didn't register to nosave memory:

[    0.000000] PM: Registered nosave memory: [mem 0x00097000-0x00097fff]
[    0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]

The codes in e820_mark_nosave_regions() assumes the first e820 area to be RAM, so it causes the first 4Kb E820_RESERVED region ignored when register to nosave. This patch removed assumption of the first e820 area.

Quoted 7 lines
Quoted 7 lines
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#4 lore raw
In reply to Rafael J. Wysocki
Quoted 30 lines · Rafael J. Wysocki
Quoted 21 lines · Chun-Yi

In arch/x86/kernel/setup.c::trim_bios_range(), the codes introduced by 1b5576e6 (base on d8a9e6a5), it updates the first 4Kb of memory to be E820_RESERVED region. That's because it's a BIOS owned area but generally not listed in the E820 table:

[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000096fff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000097000-0x0000000000097fff] reserved
...
[    0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable

But the region of first 4Kb didn't register to nosave memory:

[    0.000000] PM: Registered nosave memory: [mem 0x00097000-0x00097fff]
[    0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]

The codes in e820_mark_nosave_regions() assumes the first e820 area to be RAM, so it causes the first 4Kb E820_RESERVED region ignored when register to nosave. This patch removed assumption of the first e820 area.

Quoted 7 lines
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Quoted 3 lines

Thomas, Ingo, Peter, any objections here?

If not, do you want to handle it or do you want me to do that?

Did it address any regression?

Quoted 21 lines
Quoted 21 lines
---
 arch/x86/kernel/e820.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/e820.c +1 -1
index 988c00a..d595240 100644
@@ -682,18 +682,17 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
  * hibernation (32 bit) or software suspend and suspend to RAM (64 bit).
  *
  * This function requires the e820 map to be sorted and without any
- * overlapping entries and assumes the first e820 area to be RAM.
+ * overlapping entries.
  */
 void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 {
      int i;
      unsigned long pfn;
 
Quoted 8 lines

arch/x86/kernel/e820.c void __init parse_e820_ext(u64 phys_addr, u32 data_len) · line 696

Quoted 8 lines
arch/x86/kernel/e820.c +2 -3
-     pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
-     for (i = 1; i < e820.nr_map; i++) {
+     for (i = 0; i < e820.nr_map; i++) {
              struct e820entry *ei = &e820.map[i];
 
-             if (pfn < PFN_UP(ei->addr))
+             if (i > 0 && pfn < PFN_UP(ei->addr))
                      register_nosave_region(pfn, PFN_UP(ei->addr));

could avoid the i > 0 checking.

Quoted 4 lines

arch/x86/kernel/e820.c void __init parse_e820_ext(u64 phys_addr, u32 data_len) · line 698

Quoted 3 lines
arch/x86/kernel/e820.c +0 -0
              pfn = PFN_DOWN(ei->addr + ei->size);
 

following would be better ?

@@ -682,15 +682,14 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
* hibernation (32 bit) or software suspend and suspend to RAM (64 bit). *
* This function requires the e820 map to be sorted and without any
- * overlapping entries and assumes the first e820 area to be RAM.
+ * overlapping entries.
*/
void __init e820_mark_nosave_regions(unsigned long limit_pfn)

 {
     int i;

- unsigned long pfn;
+ unsigned long pfn = 0;

-    pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
-    for (i = 1; i < e820.nr_map; i++) {
+    for (i = 0; i < e820.nr_map; i++) {
         struct e820entry *ei = &e820.map[i];

         if (pfn < PFN_UP(ei->addr))
#5 lore raw

Hi Yinghai,

Thanks for your review, first!

Quoted 31 lines · Yinghai Lu
Quoted 30 lines · Rafael J. Wysocki
Quoted 28 lines · Chun-Yi

In arch/x86/kernel/setup.c::trim_bios_range(), the codes introduced by 1b5576e6 (base on d8a9e6a5), it updates the first 4Kb of memory to be E820_RESERVED region. That's because it's a BIOS owned area but generally not listed in the E820 table:

[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000096fff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000097000-0x0000000000097fff] reserved
...
[    0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable

But the region of first 4Kb didn't register to nosave memory:

[    0.000000] PM: Registered nosave memory: [mem 0x00097000-0x00097fff]
[    0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]

The codes in e820_mark_nosave_regions() assumes the first e820 area to be RAM, so it causes the first 4Kb E820_RESERVED region ignored when register to nosave. This patch removed assumption of the first e820 area.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Quoted 6 lines
Quoted 3 lines

Thomas, Ingo, Peter, any objections here?

If not, do you want to handle it or do you want me to do that?

Did it address any regression?

I found this situation when comparing the e820 region with nosave memory address. But, I don't know any real machine which has bug report against this.

Quoted 48 lines
Quoted 21 lines
Quoted 21 lines
---
 arch/x86/kernel/e820.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/e820.c +1 -1
index 988c00a..d595240 100644
@@ -682,18 +682,17 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
  * hibernation (32 bit) or software suspend and suspend to RAM (64 bit).
  *
  * This function requires the e820 map to be sorted and without any
- * overlapping entries and assumes the first e820 area to be RAM.
+ * overlapping entries.
  */
 void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 {
      int i;
      unsigned long pfn;
 
Quoted 8 lines

arch/x86/kernel/e820.c void __init parse_e820_ext(u64 phys_addr, u32 data_len) · line 696

Quoted 8 lines
arch/x86/kernel/e820.c +2 -3
-     pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
-     for (i = 1; i < e820.nr_map; i++) {
+     for (i = 0; i < e820.nr_map; i++) {
              struct e820entry *ei = &e820.map[i];
 
-             if (pfn < PFN_UP(ei->addr))
+             if (i > 0 && pfn < PFN_UP(ei->addr))
                      register_nosave_region(pfn, PFN_UP(ei->addr));

could avoid the i > 0 checking.

Quoted 4 lines

arch/x86/kernel/e820.c void __init parse_e820_ext(u64 phys_addr, u32 data_len) · line 698

Quoted 3 lines
arch/x86/kernel/e820.c +0 -0
              pfn = PFN_DOWN(ei->addr + ei->size);
 

following would be better ?

arch/x86/kernel/e820.c +1 -1
@@ -682,15 +682,14 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len)
  * hibernation (32 bit) or software suspend and suspend to RAM (64 bit).
  *
  * This function requires the e820 map to be sorted and without any
- * overlapping entries and assumes the first e820 area to be RAM.
+ * overlapping entries.
  */
 void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 {

arch/x86/kernel/e820.c void __init parse_e820_ext(u64 phys_addr, u32 data_len) · line 695

Quoted 10 lines
arch/x86/kernel/e820.c +2 -3
     int i;
-    unsigned long pfn;
+    unsigned long pfn = 0;
 
-    pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
-    for (i = 1; i < e820.nr_map; i++) {
+    for (i = 0; i < e820.nr_map; i++) {
         struct e820entry *ei = &e820.map[i];
 
         if (pfn < PFN_UP(ei->addr))

Yes, thanks for your suggestion, your change can avoid the i > 0 checking. I will send v2 patch to add your improvement.

Thanks a lot!
Joey Lee