Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] x86/e820: Fix handling of subpage regions when calculating nosave ranges
@ 2025-04-05  3:09 msizanoen
  2025-04-05  7:40 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: msizanoen @ 2025-04-05  3:09 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin
  Cc: Ingo Molnar, linux-kernel, Roberto Ricci, msizanoen, stable

Handle better cases where there might be non-page-aligned RAM e820
regions so we don't end up marking kernel memory as nosave.

This also simplifies the calculation of nosave ranges by treating
non-RAM regions as holes.

Fixes: e5540f875404 ("x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names")
Tested-by: Roberto Ricci <io@r-ricci.it>
Reported-by: Roberto Ricci <io@r-ricci.it>
Closes: https://lore.kernel.org/all/Z4WFjBVHpndct7br@desktop0a/
Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>
Cc: stable@vger.kernel.org
---
The issue of the kernel failing to resume from hibernation after
kexec_load() is used is likely due to kexec-tools passing in a different
e820 memory map from the one provided by system firmware, causing the
e820 consistency check to fail. That issue is not addressed in this
patch and will need to be fixed in kexec-tools instead.
---
 arch/x86/kernel/e820.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 57120f0749cc3c23844eeb36820705687e08bbf7..656ed7abd28de180b842a8d7993e9708f9f17026 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -753,22 +753,21 @@ void __init e820__memory_setup_extended(u64 phys_addr, u32 data_len)
 void __init e820__register_nosave_regions(unsigned long limit_pfn)
 {
 	int i;
-	unsigned long pfn = 0;
+	u64 last_addr = 0;
 
 	for (i = 0; i < e820_table->nr_entries; i++) {
 		struct e820_entry *entry = &e820_table->entries[i];
 
-		if (pfn < PFN_UP(entry->addr))
-			register_nosave_region(pfn, PFN_UP(entry->addr));
-
-		pfn = PFN_DOWN(entry->addr + entry->size);
-
 		if (entry->type != E820_TYPE_RAM)
-			register_nosave_region(PFN_UP(entry->addr), pfn);
+			continue;
 
-		if (pfn >= limit_pfn)
-			break;
+		if (last_addr < entry->addr)
+			register_nosave_region(PFN_UP(last_addr), PFN_DOWN(entry->addr));
+
+		last_addr = entry->addr + entry->size;
 	}
+
+	register_nosave_region(PFN_UP(last_addr), limit_pfn);
 }
 
 #ifdef CONFIG_ACPI

---
base-commit: e48e99b6edf41c69c5528aa7ffb2daf3c59ee105
change-id: 20250405-fix-e820-nosave-c43779583abe

Best regards,
-- 
msizanoen <msizanoen@qtmlabs.xyz>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86/e820: Fix handling of subpage regions when calculating nosave ranges
  2025-04-05  3:09 [PATCH] x86/e820: Fix handling of subpage regions when calculating nosave ranges msizanoen
@ 2025-04-05  7:40 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2025-04-05  7:40 UTC (permalink / raw)
  To: msizanoen
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Ingo Molnar, linux-kernel, Roberto Ricci, stable

On Sat, Apr 05, 2025 at 10:09:24AM +0700, msizanoen wrote:
> Handle better cases where there might be non-page-aligned RAM e820
> regions so we don't end up marking kernel memory as nosave.
> 
> This also simplifies the calculation of nosave ranges by treating
> non-RAM regions as holes.
> 
> Fixes: e5540f875404 ("x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names")
> Tested-by: Roberto Ricci <io@r-ricci.it>
> Reported-by: Roberto Ricci <io@r-ricci.it>
> Closes: https://lore.kernel.org/all/Z4WFjBVHpndct7br@desktop0a/
> Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>

Please use your name, not your email alias, for a signed-off-by line.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-05  7:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-05  3:09 [PATCH] x86/e820: Fix handling of subpage regions when calculating nosave ranges msizanoen
2025-04-05  7:40 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox