1 | Handle better cases where there might be non-page-aligned RAM e820 | 1 | The current implementation of e820__register_nosave_regions suffers from |
---|---|---|---|
2 | regions so we don't end up marking kernel memory as nosave. | 2 | multiple serious issues: |
3 | - The end of last region is tracked by PFN, causing it to find holes | ||
4 | that aren't there if two consecutive subpage regions are present | ||
5 | - The nosave PFN ranges derived from holes are rounded out (instead of | ||
6 | rounded in) which makes it inconsistent with how explicitly reserved | ||
7 | regions are handled | ||
3 | 8 | ||
4 | This also simplifies the calculation of nosave ranges by treating | 9 | Fix this by: |
5 | non-RAM regions as holes. | 10 | - Treating reserved regions as if they were holes, to ensure consistent |
11 | handling (rounding out nosave PFN ranges is more correct as the | ||
12 | kernel does not use partial pages) | ||
13 | - Tracking the end of the last RAM region by address instead of pages | ||
14 | to detect holes more precisely | ||
6 | 15 | ||
16 | Cc: stable@vger.kernel.org | ||
7 | Fixes: e5540f875404 ("x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names") | 17 | Fixes: e5540f875404 ("x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names") |
8 | Tested-by: Roberto Ricci <io@r-ricci.it> | ||
9 | Reported-by: Roberto Ricci <io@r-ricci.it> | 18 | Reported-by: Roberto Ricci <io@r-ricci.it> |
10 | Closes: https://lore.kernel.org/all/Z4WFjBVHpndct7br@desktop0a/ | 19 | Closes: https://lore.kernel.org/all/Z4WFjBVHpndct7br@desktop0a/ |
11 | Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz> | 20 | Signed-off-by: Myrrh Periwinkle <myrrhperiwinkle@qtmlabs.xyz> |
12 | Cc: stable@vger.kernel.org | ||
13 | --- | 21 | --- |
14 | The issue of the kernel failing to resume from hibernation after | 22 | The issue of the kernel failing to resume from hibernation after |
15 | kexec_load() is used is likely due to kexec-tools passing in a different | 23 | kexec_load() is used is likely due to kexec-tools passing in a different |
16 | e820 memory map from the one provided by system firmware, causing the | 24 | e820 memory map from the one provided by system firmware, causing the |
17 | e820 consistency check to fail. That issue is not addressed in this | 25 | e820 consistency check to fail. That issue is not addressed in this |
18 | patch and will need to be fixed in kexec-tools instead. | 26 | patch and will need to be fixed in kexec-tools instead. |
27 | |||
28 | Changes in v3: | ||
29 | - Round out nosave PFN ranges since the kernel does not use partial | ||
30 | pages | ||
31 | - Link to v2: https://lore.kernel.org/r/20250405-fix-e820-nosave-v2-1-d40dbe457c95@qtmlabs.xyz | ||
32 | |||
33 | Changes in v2: | ||
34 | - Updated author details | ||
35 | - Rewrote commit message | ||
36 | - Link to v1: https://lore.kernel.org/r/20250405-fix-e820-nosave-v1-1-162633199548@qtmlabs.xyz | ||
19 | --- | 37 | --- |
20 | arch/x86/kernel/e820.c | 17 ++++++++--------- | 38 | arch/x86/kernel/e820.c | 17 ++++++++--------- |
21 | 1 file changed, 8 insertions(+), 9 deletions(-) | 39 | 1 file changed, 8 insertions(+), 9 deletions(-) |
22 | 40 | ||
23 | diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c | 41 | diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c |
... | ... | ||
44 | + continue; | 62 | + continue; |
45 | 63 | ||
46 | - if (pfn >= limit_pfn) | 64 | - if (pfn >= limit_pfn) |
47 | - break; | 65 | - break; |
48 | + if (last_addr < entry->addr) | 66 | + if (last_addr < entry->addr) |
49 | + register_nosave_region(PFN_UP(last_addr), PFN_DOWN(entry->addr)); | 67 | + register_nosave_region(PFN_DOWN(last_addr), PFN_UP(entry->addr)); |
50 | + | 68 | + |
51 | + last_addr = entry->addr + entry->size; | 69 | + last_addr = entry->addr + entry->size; |
52 | } | 70 | } |
53 | + | 71 | + |
54 | + register_nosave_region(PFN_UP(last_addr), limit_pfn); | 72 | + register_nosave_region(PFN_DOWN(last_addr), limit_pfn); |
55 | } | 73 | } |
56 | 74 | ||
57 | #ifdef CONFIG_ACPI | 75 | #ifdef CONFIG_ACPI |
58 | 76 | ||
59 | --- | 77 | --- |
60 | base-commit: e48e99b6edf41c69c5528aa7ffb2daf3c59ee105 | 78 | base-commit: a8662bcd2ff152bfbc751cab20f33053d74d0963 |
61 | change-id: 20250405-fix-e820-nosave-c43779583abe | 79 | change-id: 20250405-fix-e820-nosave-f5cb985a9a61 |
62 | 80 | ||
63 | Best regards, | 81 | Best regards, |
64 | -- | 82 | -- |
65 | msizanoen <msizanoen@qtmlabs.xyz> | 83 | Myrrh Periwinkle <myrrhperiwinkle@qtmlabs.xyz> | diff view generated by jsdifflib |