Skip to content

Commit 157266e

Browse files
committed
x86/boot/e820: Simplify append_e820_table() and remove restriction on single-entry tables
So append_e820_table() begins with this weird condition that checks 'nr_entries': static int __init append_e820_table(struct boot_e820_entry *entries, u32 nr_entries) { /* Only one memory region (or negative)? Ignore it */ if (nr_entries < 2) return -1; Firstly, 'nr_entries' has been an u32 since 2017 and cannot be negative. Secondly, there's nothing inherently wrong with single-entry E820 maps, especially in virtualized environments. So remove this restriction and remove the __append_e820_table() indirection. Also: - fix/update comments - remove obsolete comments This shrinks the generated code a bit as well: text data bss dec hex filename 7549 44072 0 51621 c9a5 e820.o.before 7533 44072 0 51605 c995 e820.o.after Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Andy Shevchenko <andy@kernel.org> Cc: Arnd Bergmann <arnd@kernel.org> Cc: David Woodhouse <dwmw@amazon.co.uk> Cc: H . Peter Anvin <hpa@zytor.com> Cc: Juergen Gross <jgross@suse.com> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Rapoport <rppt@kernel.org> Cc: Paul Menzel <pmenzel@molgen.mpg.de> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://patch.msgid.link/20250515120549.2820541-26-mingo@kernel.org
1 parent af0cf16 commit 157266e

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

arch/x86/kernel/e820.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,22 @@ __init int e820__update_table(struct e820_table *table)
441441
return 0;
442442
}
443443

444-
__init static int __append_e820_table(struct boot_e820_entry *entries, u32 nr_entries)
444+
/*
445+
* Copy the BIOS E820 map into the kernel's e820_table.
446+
*
447+
* Sanity-check it while we're at it..
448+
*/
449+
__init static int append_e820_table(struct boot_e820_entry *entries, u32 nr_entries)
445450
{
446451
struct boot_e820_entry *entry = entries;
447452

448453
while (nr_entries) {
449454
u64 start = entry->addr;
450-
u64 size = entry->size;
451-
u64 end = start + size - 1;
452-
u32 type = entry->type;
455+
u64 size = entry->size;
456+
u64 end = start + size-1;
457+
u32 type = entry->type;
453458

454-
/* Ignore the entry on 64-bit overflow: */
459+
/* Ignore the remaining entries on 64-bit overflow: */
455460
if (start > end && likely(size))
456461
return -1;
457462

@@ -463,24 +468,6 @@ __init static int __append_e820_table(struct boot_e820_entry *entries, u32 nr_en
463468
return 0;
464469
}
465470

466-
/*
467-
* Copy the BIOS E820 map into a safe place.
468-
*
469-
* Sanity-check it while we're at it..
470-
*
471-
* If we're lucky and live on a modern system, the setup code
472-
* will have given us a memory map that we can use to properly
473-
* set up memory. If we aren't, we'll fake a memory map.
474-
*/
475-
__init static int append_e820_table(struct boot_e820_entry *entries, u32 nr_entries)
476-
{
477-
/* Only one memory region (or negative)? Ignore it */
478-
if (nr_entries < 2)
479-
return -1;
480-
481-
return __append_e820_table(entries, nr_entries);
482-
}
483-
484471
__init static u64
485472
__e820__range_update(struct e820_table *table, u64 start, u64 size, enum e820_type old_type, enum e820_type new_type)
486473
{
@@ -754,7 +741,7 @@ __init void e820__memory_setup_extended(u64 phys_addr, u32 data_len)
754741
entries = sdata->len / sizeof(*extmap);
755742
extmap = (struct boot_e820_entry *)(sdata->data);
756743

757-
__append_e820_table(extmap, entries);
744+
append_e820_table(extmap, entries);
758745
e820__update_table(e820_table);
759746

760747
memcpy(e820_table_kexec, e820_table, sizeof(*e820_table_kexec));

0 commit comments

Comments
 (0)