Skip to content

Commit

Permalink
boot: allocate cleanup pages below 4GiB only on x86
Browse files Browse the repository at this point in the history
Outside of x86, some machines (e.g. Apple silicon, AMD Opteron A1100) have
physical memory mapped above 4GiB, meaning this allocation will fail, causing
the entire boot process to fail on these machines.

This commit makes it so that the below-4GB address space allocation requirement
is only set on x86 platforms, and not on other platforms (that don't have the
specific Linux x86 boot protocol), thereby fixing boot on those that have no
memory mapped below 4GiB in their address space.

Tested on an Apple silicon M1 laptop and an AMD x86_64 desktop tower.

Fixes: #35026

Manual backport of 6e207b3.
  • Loading branch information
andre4ik3 authored and bluca committed Nov 14, 2024
1 parent 018c7fb commit a9d9db7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/boot/efi/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -2296,11 +2296,20 @@ static EFI_STATUS initrd_prepare(
return EFI_OUT_OF_RESOURCES;
}

#if defined(__i386__) || defined(__x86_64__)
_cleanup_pages_ Pages pages = xmalloc_pages(
AllocateMaxAddress,
EfiLoaderData,
EFI_SIZE_TO_PAGES(size),
UINT32_MAX /* Below 4G boundary. */);
#else
_cleanup_pages_ Pages pages = xmalloc_pages(
AllocateAnyPages,
EfiLoaderData,
EFI_SIZE_TO_PAGES(size),
0 /* Ignored. */);
#endif

uint8_t *p = PHYSICAL_ADDRESS_TO_POINTER(pages.addr);

STRV_FOREACH(i, entry->initrd) {
Expand Down
9 changes: 9 additions & 0 deletions src/boot/efi/stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@ static EFI_STATUS combine_initrds(
n += initrd_size;
}

#if defined(__i386__) || defined(__x86_64__)
_cleanup_pages_ Pages pages = xmalloc_pages(
AllocateMaxAddress,
EfiLoaderData,
EFI_SIZE_TO_PAGES(n),
UINT32_MAX /* Below 4G boundary. */);
#else
_cleanup_pages_ Pages pages = xmalloc_pages(
AllocateAnyPages,
EfiLoaderData,
EFI_SIZE_TO_PAGES(n),
0 /* Ignored. */);
#endif

uint8_t *p = PHYSICAL_ADDRESS_TO_POINTER(pages.addr);
for (size_t i = 0; i < n_initrds; i++) {
if (!initrds[i])
Expand Down

0 comments on commit a9d9db7

Please sign in to comment.