* [PATCH] efi/libstub: arm64: Work around EBS failure on T14s Gen 6
@ 2026-12-05 18:49 Christopher Obbard
2026-12-05 19:05 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Christopher Obbard @ 2026-12-05 18:49 UTC (permalink / raw)
To: Ard Biesheuvel, Ilias Apalodimas
Cc: Bjorn Andersson, Johan Hovold, Marc Zyngier, linux-efi,
linux-arm-msm, linux-kernel, stable, Christopher Obbard
The Lenovo ThinkPad T14s Gen 6 (Snapdragon X) suffers from intermittent
boot failures, with ExitBootServices() returning EFI_INVALID_PARAMETER
even after retrying.
This appears to be caused by the firmware allocating and freeing small
blocks of boot services data within ExitBootServices() before validating
the memory map key. These allocations seem to fall within the 256-byte
size class of the edk2 pool allocator. If no suitable free blocks are
available, the pool allocates a new page, changing the memory map and
invalidating the key.
Work around this issue by allocating 16 blocks of 200 bytes of boot
services data before obtaining the memory map. Free all but the last
block, which prevents its pool page from being returned to the page
allocator. This leaves suitable free blocks available for the firmware
without further changes to the memory map. The retained allocation is
reclaimed along with the rest of boot services memory.
Creating an event before ExitBootServices() and leaving it allocated
can also avoid the failure [1], but was not reliable across all boot
methods. This workaround addresses the underlying pool allocation
issue and was reliable across all tested boot methods.
Restrict the workaround to the affected machine by matching the
manufacturer and product family in SMBIOS. The failure was first
reported in 2024 and is still present in BIOS 2.30, so the workaround
is not restricted to specific firmware versions.
The workaround was tested on the affected machine across three boot
paths, with 75 boots in the failing state (60 forced, 15 natural), all
of which booted. Without the workaround, all 15 boots in the failing
state failed.
Link: https://lore.kernel.org/linux-arm-msm/Z0gn1N3IsP8r3gTA@hovoldconsulting.com/ [1]
Cc: stable@vger.kernel.org
Signed-off-by: Christopher Obbard <chris.obbard@oss.qualcomm.com>
---
The Lenovo ThinkPad T14s Gen 6 sometimes fails to boot because
ExitBootServices() returns EFI_INVALID_PARAMETER. The commit message
explains the cause and how this patch works around it.
Prior work
----------
Johan Hovold reported this failure on the T14s in November 2024 (see
the Link tag in the patch). He found that creating an event in the
BeforeExitBootServices group before calling ExitBootServices() can
make the call succeed, as long as the event stays allocated.
Signalling the event is often not needed. He also saw the failure
return on some boot paths, such as starting the kernel from a UEFI
shell startup.nsh.
This appears to work as a side effect of the firmware's pool
allocator. Creating the first event can cause the firmware to retain a
small allocation, keeping a pool page with free blocks available for
subsequent allocations. If this has already occurred during an earlier
boot stage, creating another event may not provide the same benefit.
The proposed workaround reserves suitable free blocks directly, without
relying on the side effects of event creation.
Testing
-------
The failure appears to occur when the boot services pool has no free
blocks of a suitable size when the kernel starts. This is the "failing
state" below. A test-only stub patch recorded whether each boot was in
that state. A boot services driver was used to force it by using up the
free blocks. Both can be posted if useful.
"Booted" means the kernel reached userspace; "failed" means it did not.
Forced failure state Natural failure state
Without workaround 5/5 failed 10/10 failed
With workaround 60/60 booted 15/15 booted
Freeing all 16 blocks 10/10 failed -
The patch was tested using three boot paths: shim and GRUB; systemd-boot
with a UKI; and the firmware boot menu with a UKI. Initrds ranged from
60 MB to ~300 MB.
The workaround appears to leave about 11 free blocks in the failing
state, where the firmware needs 2. This figure comes from a model of the
edk2 pool allocator that was consistent with the results of all 75
logged boots. It was not counted directly.
Scope
-----
I have only reproduced the issue on the ThinkPad T14s Gen 6, so the
workaround is deliberately restricted to this machine to avoid modifying
the boot services pool on unaffected platforms.
The issue has been reported to Lenovo. If a firmware update fixes it,
the workaround can be limited to older firmware versions.
Feedback on whether a machine-specific workaround is preferable to
applying it unconditionally would be appreciated.
AI assistance
-------------
Claude Code (Opus 5.5) was used to develop the test tooling, execute
tests on the target hardware and collate the results. The results
were manually verified.
---
drivers/firmware/efi/libstub/arm64.c | 28 ++++++++++++++++
drivers/firmware/efi/libstub/efi-stub-helper.c | 44 ++++++++++++++++++++++++++
drivers/firmware/efi/libstub/efistub.h | 1 +
3 files changed, 73 insertions(+)
diff --git a/drivers/firmware/efi/libstub/arm64.c b/drivers/firmware/efi/libstub/arm64.c
index c190a3ac97001..d9077381d03fa 100644
--- a/drivers/firmware/efi/libstub/arm64.c
+++ b/drivers/firmware/efi/libstub/arm64.c
@@ -55,6 +55,32 @@ static bool system_needs_vamap(void)
return false;
}
+static bool system_needs_ebs_pool_reserve(void)
+{
+ const struct efi_smbios_type1_record *record;
+ const u8 *str;
+
+ /*
+ * The Lenovo ThinkPad T14s Gen 6 requires the ExitBootServices()
+ * pool allocation workaround. Match the family string rather than
+ * the product name, which contains Lenovo's machine type code.
+ */
+ record = (struct efi_smbios_type1_record *)efi_get_smbios_record(1);
+ if (!record || record->header.length <
+ offsetofend(struct efi_smbios_type1_record, family))
+ return false;
+
+ str = efi_get_smbios_string(record, manufacturer);
+ if (!str || strcmp(str, "LENOVO"))
+ return false;
+
+ str = efi_get_smbios_string(record, family);
+ if (!str || strcmp(str, "ThinkPad T14s Gen 6"))
+ return false;
+
+ return true;
+}
+
efi_status_t check_platform_features(void)
{
u64 tg;
@@ -67,6 +93,8 @@ efi_status_t check_platform_features(void)
if (VA_BITS_MIN >= 48 && !system_needs_vamap())
efi_novamap = true;
+ efi_ebs_pool_reserve = system_needs_ebs_pool_reserve();
+
/* UEFI mandates support for 4 KB granularity, no need to check */
if (IS_ENABLED(CONFIG_ARM64_4K_PAGES))
return EFI_SUCCESS;
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index e50deec996865..9eb60ee0c8391 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -21,6 +21,7 @@
bool efi_nochunk;
bool efi_nokaslr = !IS_ENABLED(CONFIG_RANDOMIZE_BASE);
bool efi_novamap;
+bool efi_ebs_pool_reserve;
static bool efi_noinitrd;
static bool efi_nosoftreserve;
@@ -387,6 +388,46 @@ char *efi_convert_cmdline(efi_loaded_image_t *image)
return cmdline_addr;
}
+#define EFI_EBS_POOL_RESERVE_BLOCKS 16
+#define EFI_EBS_POOL_RESERVE_SIZE 200
+
+/*
+ * The Lenovo ThinkPad T14s Gen 6 firmware appears to allocate and free
+ * boot services data within ExitBootServices() before validating the
+ * memory map key. If the pool has no suitable free blocks, these
+ * operations can change the memory map and invalidate the key.
+ *
+ * A 200 byte allocation falls in the 256 byte size class of the edk2
+ * pool allocator once the pool header and tail are included. Allocate
+ * 16 blocks which provides sufficient headroom in the observed failing
+ * state, based on both modelling and testing.
+ *
+ * Free all but the last block. Retaining this allocation prevents its
+ * pool page from being returned to the page allocator, leaving free
+ * blocks available for the firmware. The retained allocation can be
+ * reclaimed along with the rest of boot services memory.
+ */
+static void efi_reserve_ebs_pool(void)
+{
+ void *blocks[EFI_EBS_POOL_RESERVE_BLOCKS];
+ int i, n;
+
+ efi_warn("Working around broken ExitBootServices()\n");
+
+ for (n = 0; n < EFI_EBS_POOL_RESERVE_BLOCKS; n++) {
+ if (efi_bs_call(allocate_pool, EFI_BOOT_SERVICES_DATA,
+ EFI_EBS_POOL_RESERVE_SIZE,
+ &blocks[n]) != EFI_SUCCESS)
+ break;
+ }
+
+ if (n != EFI_EBS_POOL_RESERVE_BLOCKS)
+ efi_warn("Failed to fully populate ExitBootServices() reserve pool\n");
+
+ for (i = 0; i < n - 1; i++)
+ efi_bs_call(free_pool, blocks[i]);
+}
+
/**
* efi_exit_boot_services() - Exit boot services
* @handle: handle of the exiting image
@@ -411,6 +452,9 @@ efi_status_t efi_exit_boot_services(void *handle, void *priv,
if (efi_disable_pci_dma)
efi_pci_disable_bridge_busmaster();
+ if (efi_ebs_pool_reserve)
+ efi_reserve_ebs_pool();
+
status = efi_get_memory_map(&map, true);
if (status != EFI_SUCCESS)
return status;
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index df3f88f4786b8..4a1b86d995eae 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -44,6 +44,7 @@ extern bool efi_nokaslr;
extern int efi_loglevel;
extern int efi_mem_encrypt;
extern bool efi_novamap;
+extern bool efi_ebs_pool_reserve;
extern const efi_system_table_t *efi_system_table;
typedef union efi_dxe_services_table efi_dxe_services_table_t;
---
base-commit: 697ced232513751c6924629ef8765911e613fd1c
change-id: 20261205-wip-obbardc-qcom-t14s-gen6-ebs-workaround-95b50b13211e
Best regards,
--
Christopher Obbard
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] efi/libstub: arm64: Work around EBS failure on T14s Gen 6
2026-12-05 18:49 [PATCH] efi/libstub: arm64: Work around EBS failure on T14s Gen 6 Christopher Obbard
@ 2026-12-05 19:05 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 19:05 UTC (permalink / raw)
To: Christopher Obbard, Ard Biesheuvel, Ilias Apalodimas
Cc: Bjorn Andersson, Johan Hovold, Marc Zyngier, linux-efi
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] efi/libstub: arm64 efi_reserve_ebs_pool() compiled into
non-arm64 stubs
- [Low] efi/libstub: leak of retained pool block in
efi_exit_boot_services() on error
--
commit c6e872fa5be104e9d917c78428320e753cde37d6
Author: Christopher Obbard <chris.obbard@oss.qualcomm.com>
efi/libstub: arm64: Work around EBS failure on T14s Gen 6
This commit works around intermittent ExitBootServices() failures on the
Lenovo ThinkPad T14s Gen 6 by pre-allocating and partially freeing 200-byte
boot services pool blocks before fetching the memory map.
Link: https://lore.kernel.org/linux-arm-msm/Z0gn1N3IsP8r3gTA@hovoldconsulting.com/ [1]
> diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
> index e50deec996865..9eb60ee0c8391 100644
> --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
[ ... ]
> @@ -387,6 +388,46 @@ char *efi_convert_cmdline(efi_loaded_image_t *image)
> return cmdline_addr;
> }
>
> +#define EFI_EBS_POOL_RESERVE_BLOCKS 16
> +#define EFI_EBS_POOL_RESERVE_SIZE 200
> +
[ ... ]
> +static void efi_reserve_ebs_pool(void)
> +{
> + void *blocks[EFI_EBS_POOL_RESERVE_BLOCKS];
> + int i, n;
> +
> + efi_warn("Working around broken ExitBootServices()\n");
> +
> + for (n = 0; n < EFI_EBS_POOL_RESERVE_BLOCKS; n++) {
> + if (efi_bs_call(allocate_pool, EFI_BOOT_SERVICES_DATA,
> + EFI_EBS_POOL_RESERVE_SIZE,
> + &blocks[n]) != EFI_SUCCESS)
> + break;
> + }
> +
> + if (n != EFI_EBS_POOL_RESERVE_BLOCKS)
> + efi_warn("Failed to fully populate ExitBootServices() reserve pool\n");
> +
> + for (i = 0; i < n - 1; i++)
> + efi_bs_call(free_pool, blocks[i]);
> +}
[Severity: Low]
Should efi_reserve_ebs_pool() and its call site be guarded with
IS_ENABLED(CONFIG_ARM64)?
efi_ebs_pool_reserve is only ever set in arm64.c's check_platform_features().
Because it has external linkage and LTO is disabled for libstub, the compiler
cannot eliminate efi_reserve_ebs_pool() or its warning strings on x86, ARM,
RISC-V, and LoongArch builds.
Guarding the call with IS_ENABLED(CONFIG_ARM64) or keeping the workaround in
arm64.c would avoid compiling dead code into other architectures.
[ ... ]
> @@ -411,6 +452,9 @@ efi_status_t efi_exit_boot_services(void *handle, void *priv,
> if (efi_disable_pci_dma)
> efi_pci_disable_bridge_busmaster();
>
> + if (efi_ebs_pool_reserve)
> + efi_reserve_ebs_pool();
> +
> status = efi_get_memory_map(&map, true);
> if (status != EFI_SUCCESS)
> return status;
[Severity: Low]
Does this leak the retained pool block if efi_get_memory_map() or priv_func()
fails?
efi_reserve_ebs_pool() leaves blocks[n - 1] allocated and discards its
pointer. If efi_get_memory_map() or priv_func() fails,
efi_exit_boot_services() returns before exit_boot_services() is called,
leaking the block and its pinned pool page to the bootloader or UEFI shell.
Returning the retained pointer from efi_reserve_ebs_pool() and storing it in
a __free(efi_pool) local variable, disarmed with no_free_ptr() before calling
exit_boot_services(), would free it on these error paths.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-wip-obbardc-qcom-t14s-gen6-ebs-workaround-v1-1-546dd3885e38@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 19:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 18:49 [PATCH] efi/libstub: arm64: Work around EBS failure on T14s Gen 6 Christopher Obbard
2026-12-05 19:05 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox