]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: allocate cleanup pages below 4GiB only on x86
authorandre4ik3 <andre4ik3@fastmail.com>
Wed, 13 Nov 2024 14:53:25 +0000 (18:53 +0400)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 14 Nov 2024 13:12:13 +0000 (13:12 +0000)
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 6e207b370e91e681efb08c497a6c8ad78e3c8d83.

src/boot/efi/boot.c
src/boot/efi/stub.c

index ecbb4e0509eac73a32f5d2070234f0cff7309efd..8d08fe01f71ddcdf2c0d8c80536849fb6a8a570e 100644 (file)
@@ -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) {
index 9aa605b7563e06c7b4db37bbaf73782b075fa399..0d3df16ef6b05539726d4d7e2442d7b39e40b0e6 100644 (file)
@@ -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])