Skip to contentSkip to conversation

x86/boot/e820: Re-enable fallback if e820 table is empty

PATCH Applied David Gow 4 participants 4 messages Apr 16 – May 7

Subsystems (2)
lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH v2 1/1 x86/boot/e820: Re-enable fallback if e820 table is empty

In commit 157266edcc56 ("x86/boot/e820: Simplify append_e820_table() and remove restriction on single-entry tables"), the check that 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 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 so doing, 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.

Fixes 157266edcc56 ("x86/boot/e820: Simplify append_e820_table() and remove restriction on single-entry tables")

---

Changes since v2:
https://lore.kernel.org/lkml/[email protected]/
- Return -ENOENT instead of -1
- Return -EINVAL instead of -1 for the case where an entry looks invalid due to an overflow (Thanks, Andy)

---
 arch/x86/kernel/e820.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kernel/e820.c +5 -1
index 2a9992758933..3db9c364b833 100644
@@ -450,6 +450,10 @@ __init static int append_e820_table(struct boot_e820_entry *entries, u32 nr_entr
 {
 	struct boot_e820_entry *entry = entries;
 
+	/* If there aren't any entries, we'll want to fall-back to another source. */
+	if (!nr_entries)
+		return -ENOENT;
+
 	while (nr_entries) {
 		u64 start = entry->addr;
 		u64 size  = entry->size;
@@ -458,7 +462,7 @@ __init static int append_e820_table(struct boot_e820_entry *entries, u32 nr_entr
 
 		/* Ignore the remaining entries on 64-bit overflow: */
 		if (start > end && likely(size))
-			return -1;
+			return -EINVAL;
 
 		e820__range_add(start, size, type);
 
Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 23 lines · David Gow

In commit 157266edcc56 ("x86/boot/e820: Simplify append_e820_table() and remove restriction on single-entry tables"), the check that 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 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 so doing, 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.

...

Quoted 5 lines

Changes since v2:
https://lore.kernel.org/lkml/[email protected]/
- Return -ENOENT instead of -1
- Return -EINVAL instead of -1 for the case where an entry looks invalid due to an overflow (Thanks, Andy)

Oh, I didn't noticed it's overflow condition, so -ERANGE may suit better. Whatever, the change looks good enough and it's up to you to follow the above.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Applied
#2 lore raw
Quoted 33 lines · Andy Shevchenko
Quoted 23 lines · David Gow

In commit 157266edcc56 ("x86/boot/e820: Simplify append_e820_table() and remove restriction on single-entry tables"), the check that 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 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 so doing, 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.

...

Quoted 5 lines

Changes since v2:
https://lore.kernel.org/lkml/[email protected]/
- Return -ENOENT instead of -1
- Return -EINVAL instead of -1 for the case where an entry looks invalid due to an overflow (Thanks, Andy)

Quoted 4 lines

Oh, I didn't noticed it's overflow condition, so -ERANGE may suit better. Whatever, the change looks good enough and it's up to you to follow the above.

Applied, thanks!

Ingo

merge bot Applied
#3 lore raw

[tip: x86/urgent] x86/boot/e820: Re-enable BIOS fallback if e820 table is empty

In reply to David Gow
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     5772f6535227ebd104065d80afa8ed3478d34c5c
Gitweb:        https://git.kernel.org/tip/5772f6535227ebd104065d80afa8ed3478d34c5c
Author:        David Gow <[email protected]>
AuthorDate:    Thu, 16 Apr 2026 14:57:43 +08:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 07 May 2026 10:04:54 +02:00

x86/boot/e820: Re-enable BIOS fallback if e820 table is empty

In commit:

157266edcc56 ("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 157266edcc56 ("x86/boot/e820: Simplify append_e820_table() and remove restriction on single-entry tables")
Cc Arnd Bergmann <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/e820.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kernel/e820.c +5 -1
index 2a99927..eb72537 100644
@@ -450,6 +450,10 @@ __init static int append_e820_table(struct boot_e820_entry *entries, u32 nr_entr
 {
 	struct boot_e820_entry *entry = entries;
 
+	/* If there aren't any entries, we'll want to fall back to another source: */
+	if (!nr_entries)
+		return -ENOENT;
+
 	while (nr_entries) {
 		u64 start = entry->addr;
 		u64 size  = entry->size;
@@ -458,7 +462,7 @@ __init static int append_e820_table(struct boot_e820_entry *entries, u32 nr_entr
 
 		/* Ignore the remaining entries on 64-bit overflow: */
 		if (start > end && likely(size))
-			return -1;
+			return -EINVAL;
 
 		e820__range_add(start, size, type);