[PATCH for review] [3/48] i386: do not restore reserved memory after hibernation




From: Rafael J. Wysocki <rjw@xxxxxxx>

On some systems the ACPI NVS area is located in the first 1 MB of RAM and
it is overwritten by the i386 code during the restore after hibernation.
This confuses the ACPI platform firmware that doesn't update the AC adapter
status appropriately as a result
(http://bugzilla.kernel.org/show_bug.cgi?id=7995).

The solution is to register the reserved memory in the first 1 MB as
'nosave', so that swsusp doesn't touch it during the restore. Also, this
has been done on x86_64 for a long time now, so this patch makes the i386
restore code behave like the x86_64 one.

[akpm@xxxxxxxxxxxxxxxxxxxx: build fix]
Signed-off-by: Rafael J. Wysocki <rjw@xxxxxxx>
Signed-off-by: Andi Kleen <ak@xxxxxxx>
Acked-by: Pavel Machek <pavel@xxxxxx>
Cc: Andi Kleen <ak@xxxxxxx>
Cc: David Rientjes <rientjes@xxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

arch/i386/kernel/e820.c | 32 ++++++++++++++++++++++++++++++++
arch/i386/kernel/setup.c | 1 +
include/asm-i386/e820.h | 8 ++++++++
3 files changed, 41 insertions(+)

Index: linux/arch/i386/kernel/e820.c
===================================================================
--- linux.orig/arch/i386/kernel/e820.c
+++ linux/arch/i386/kernel/e820.c
@@ -10,6 +10,7 @@
#include <linux/efi.h>
#include <linux/pfn.h>
#include <linux/uaccess.h>
+#include <linux/suspend.h>

#include <asm/pgtable.h>
#include <asm/page.h>
@@ -320,6 +321,37 @@ static int __init request_standard_resou

subsys_initcall(request_standard_resources);

+#if defined(CONFIG_PM) && defined(CONFIG_SOFTWARE_SUSPEND)
+/**
+ * e820_mark_nosave_regions - Find the ranges of physical addresses that do not
+ * correspond to e820 RAM areas and mark the corresponding pages as nosave for
+ * hibernation.
+ *
+ * This function requires the e820 map to be sorted and without any
+ * overlapping entries and assumes the first e820 area to be RAM.
+ */
+void __init e820_mark_nosave_regions(void)
+{
+ int i;
+ unsigned long pfn;
+
+ pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
+ for (i = 1; i < e820.nr_map; i++) {
+ struct e820entry *ei = &e820.map[i];
+
+ if (pfn < PFN_UP(ei->addr))
+ register_nosave_region(pfn, PFN_UP(ei->addr));
+
+ pfn = PFN_DOWN(ei->addr + ei->size);
+ if (ei->type != E820_RAM)
+ register_nosave_region(PFN_UP(ei->addr), pfn);
+
+ if (pfn >= max_low_pfn)
+ break;
+ }
+}
+#endif
+
void __init add_memory_region(unsigned long long start,
unsigned long long size, int type)
{
Index: linux/arch/i386/kernel/setup.c
===================================================================
--- linux.orig/arch/i386/kernel/setup.c
+++ linux/arch/i386/kernel/setup.c
@@ -640,6 +640,7 @@ void __init setup_arch(char **cmdline_p)
#endif

e820_register_memory();
+ e820_mark_nosave_regions();

#ifdef CONFIG_VT
#if defined(CONFIG_VGA_CONSOLE)
Index: linux/include/asm-i386/e820.h
===================================================================
--- linux.orig/include/asm-i386/e820.h
+++ linux/include/asm-i386/e820.h
@@ -47,6 +47,14 @@ extern void e820_register_memory(void);
extern void limit_regions(unsigned long long size);
extern void print_memory_map(char *who);

+#if defined(CONFIG_PM) && defined(CONFIG_SOFTWARE_SUSPEND)
+extern void e820_mark_nosave_regions(void);
+#else
+static inline void e820_mark_nosave_regions(void)
+{
+}
+#endif
+
#endif/*!__ASSEMBLY__*/

#endif/*__E820_HEADER*/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • [PATCH -mm] i386: Do not restore reserved memory after hibernation
    ... On some systems the ACPI NVS area is located in the first 1 MB of RAM and ... it is overwritten by the i386 code during the restore after hibernation. ... extern void limit_regions; ...
    (Linux-Kernel)
  • Re: System Restore Problems
    ... The DVD player/writer has four options to change. ... > Your system has quite a bit of power with plenty of RAM. ... (Instead of using restore you ... > my windows wont start it say windows system32 configuration fi le is either corrupt or missing it wont start windows. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: System Restore Problems
    ... > anything other than 4 before the restore (from when I set it after I ... The DVD player/writer has four options to change. ... Your system has quite a bit of power with plenty of RAM. ... System Restore is not a backup tool. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: upgrade 4200hd or add more ram?
    ... > sounds like Windows is running out of free RAM and has to swap out. ... can I just buy any laptop hd and stick it in the ... > restore the laptop to original factory condition including software if ... > enclosure as a backup hard drive. ...
    (comp.sys.laptops)
  • Re: graphics
    ... RAM, with a AMD-K6 3D processor, and Pub 2002 used to be ... >> were choppy but had no problem editing Autoshapes. ... >> I did a Quick Restore on my hard drive, ... and I still have graphics problems in Pub. ...
    (microsoft.public.publisher)