Skip to content

Commit 06fa48d

Browse files
kirylbp3tk0v
authored andcommitted
x86/mm: Make e820__end_ram_pfn() cover E820_TYPE_ACPI ranges
e820__end_of_ram_pfn() is used to calculate max_pfn which, among other things, guides where direct mapping ends. Any memory above max_pfn is not going to be present in the direct mapping. e820__end_of_ram_pfn() finds the end of the RAM based on the highest E820_TYPE_RAM range. But it doesn't includes E820_TYPE_ACPI ranges into calculation. Despite the name, E820_TYPE_ACPI covers not only ACPI data, but also EFI tables and might be required by kernel to function properly. Usually the problem is hidden because there is some E820_TYPE_RAM memory above E820_TYPE_ACPI. But crashkernel only presents pre-allocated crash memory as E820_TYPE_RAM on boot. If the pre-allocated range is small, it can fit under the last E820_TYPE_ACPI range. Modify e820__end_of_ram_pfn() and e820__end_of_low_ram_pfn() to cover E820_TYPE_ACPI memory. The problem was discovered during debugging kexec for TDX guest. TDX guest uses E820_TYPE_ACPI to store the unaccepted memory bitmap and pass it between the kernels on kexec. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Tested-by: Tao Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 859e63b commit 06fa48d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

arch/x86/kernel/e820.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ u64 __init e820__memblock_alloc_reserved(u64 size, u64 align)
828828
/*
829829
* Find the highest page frame number we have available
830830
*/
831-
static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type type)
831+
static unsigned long __init e820__end_ram_pfn(unsigned long limit_pfn)
832832
{
833833
int i;
834834
unsigned long last_pfn = 0;
@@ -839,7 +839,8 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type
839839
unsigned long start_pfn;
840840
unsigned long end_pfn;
841841

842-
if (entry->type != type)
842+
if (entry->type != E820_TYPE_RAM &&
843+
entry->type != E820_TYPE_ACPI)
843844
continue;
844845

845846
start_pfn = entry->addr >> PAGE_SHIFT;
@@ -865,12 +866,12 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type
865866

866867
unsigned long __init e820__end_of_ram_pfn(void)
867868
{
868-
return e820_end_pfn(MAX_ARCH_PFN, E820_TYPE_RAM);
869+
return e820__end_ram_pfn(MAX_ARCH_PFN);
869870
}
870871

871872
unsigned long __init e820__end_of_low_ram_pfn(void)
872873
{
873-
return e820_end_pfn(1UL << (32 - PAGE_SHIFT), E820_TYPE_RAM);
874+
return e820__end_ram_pfn(1UL << (32 - PAGE_SHIFT));
874875
}
875876

876877
static void __init early_panic(char *msg)

0 commit comments

Comments
 (0)