Skip to content

Commit 5a43859

Browse files
sulixgregkh
authored andcommitted
x86/boot/e820: Re-enable BIOS fallback if e820 table is empty
commit 5772f65 upstream. In commit: 157266e ("x86/boot/e820: Simplify append_e820_table() and remove restriction on single-entry tables") the check on the number of entries in the e820 table was removed. The intention was to support single-entry maps, but by removing the check entirely, we also skip the fallback (to, e.g., the BIOS 88h function). This means that if no E820 map is passed in from the bootloader (which is the case on some bootloaders, like linld), we end up with an empty memory map, and the kernel fails to boot (either by deadlocking on OOM, or by failing to allocate the real mode trampoline, or similar). Re-instate the check in append_e820_table(), but only check that nr_entries is non-zero. This allows e820__memory_setup_default() to fall back to other memory size sources, and doesn't affect e820__memory_setup_extended(), as the latter ignores the return value from append_e820_table(). In doing so, we also update the return values to be proper error codes, with -ENOENT for this case (there are no entries), and -EINVAL for the case where an entry appears invalid. Given none of the callers check the actual value -- just whether it's nonzero -- this is largely aesthetic in practice. Tested against linld, and the kernel boots again fine. [ mingo: Readability edits to the comment and the changelog. ] Fixes: 157266e ("x86/boot/e820: Simplify append_e820_table() and remove restriction on single-entry tables") Signed-off-by: David Gow <david@davidgow.net> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Cc: stable@vger.kernel.org Cc: Arnd Bergmann <arnd@kernel.org> Cc: "H. Peter Anvin" <hpa@zytor.com> Link: https://patch.msgid.link/20260416065746.1896647-1-david@davidgow.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fdb26e6 commit 5a43859

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

arch/x86/kernel/e820.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ __init static int append_e820_table(struct boot_e820_entry *entries, u32 nr_entr
450450
{
451451
struct boot_e820_entry *entry = entries;
452452

453+
/* If there aren't any entries, we'll want to fall back to another source: */
454+
if (!nr_entries)
455+
return -ENOENT;
456+
453457
while (nr_entries) {
454458
u64 start = entry->addr;
455459
u64 size = entry->size;
@@ -458,7 +462,7 @@ __init static int append_e820_table(struct boot_e820_entry *entries, u32 nr_entr
458462

459463
/* Ignore the remaining entries on 64-bit overflow: */
460464
if (start > end && likely(size))
461-
return -1;
465+
return -EINVAL;
462466

463467
e820__range_add(start, size, type);
464468

0 commit comments

Comments
 (0)