Skip to content

Commit bd6eae1

Browse files
msizanoen1gregkh
authored andcommitted
x86/e820: Fix handling of subpage regions when calculating nosave ranges in e820__register_nosave_regions()
commit f2f29da upstream. While debugging kexec/hibernation hangs and crashes, it turned out that the current implementation of e820__register_nosave_regions() suffers from multiple serious issues: - The end of last region is tracked by PFN, causing it to find holes that aren't there if two consecutive subpage regions are present - The nosave PFN ranges derived from holes are rounded out (instead of rounded in) which makes it inconsistent with how explicitly reserved regions are handled Fix this by: - Treating reserved regions as if they were holes, to ensure consistent handling (rounding out nosave PFN ranges is more correct as the kernel does not use partial pages) - Tracking the end of the last RAM region by address instead of pages to detect holes more precisely These bugs appear to have been introduced about ~18 years ago with the very first version of e820_mark_nosave_regions(), and its flawed assumptions were carried forward uninterrupted through various waves of rewrites and renames. [ mingo: Added Git archeology details, for kicks and giggles. ] Fixes: e8eff5a ("[PATCH] Make swsusp avoid memory holes and reserved memory regions on x86_64") Reported-by: Roberto Ricci <[email protected]> Tested-by: Roberto Ricci <[email protected]> Signed-off-by: Myrrh Periwinkle <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Kees Cook <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Len Brown <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Closes: https://lore.kernel.org/all/Z4WFjBVHpndct7br@desktop0a/ Signed-off-by: Myrrh Periwinkle <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6a59b70 commit bd6eae1

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

arch/x86/kernel/e820.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -754,22 +754,21 @@ void __init e820__memory_setup_extended(u64 phys_addr, u32 data_len)
754754
void __init e820__register_nosave_regions(unsigned long limit_pfn)
755755
{
756756
int i;
757-
unsigned long pfn = 0;
757+
u64 last_addr = 0;
758758

759759
for (i = 0; i < e820_table->nr_entries; i++) {
760760
struct e820_entry *entry = &e820_table->entries[i];
761761

762-
if (pfn < PFN_UP(entry->addr))
763-
register_nosave_region(pfn, PFN_UP(entry->addr));
764-
765-
pfn = PFN_DOWN(entry->addr + entry->size);
766-
767762
if (entry->type != E820_TYPE_RAM && entry->type != E820_TYPE_RESERVED_KERN)
768-
register_nosave_region(PFN_UP(entry->addr), pfn);
763+
continue;
769764

770-
if (pfn >= limit_pfn)
771-
break;
765+
if (last_addr < entry->addr)
766+
register_nosave_region(PFN_DOWN(last_addr), PFN_UP(entry->addr));
767+
768+
last_addr = entry->addr + entry->size;
772769
}
770+
771+
register_nosave_region(PFN_DOWN(last_addr), limit_pfn);
773772
}
774773

775774
#ifdef CONFIG_ACPI

0 commit comments

Comments
 (0)