mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jasmeet (Jazz) Bhatia" <jasmeet.bhatia.us@gmail.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	rafael@kernel.org, Pavel Machek <pavel@ucw.cz>,
	linux-efi@vger.kernel.org, linux-pm@vger.kernel.org,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	"Jasmeet (Jazz) Bhatia" <jasmeet.bhatia.us@gmail.com>
Subject: [PATCH v1 2/2] efi/tpm: Persistently reserve the TPM event log
Date: Tue,  1 Sep 2026 04:34:08 -0700	[thread overview]
Message-ID: <f6a746a26d2d02ce9de279db9d5928da72eba610.1788259938.git.jasmeet.bhatia.us@gmail.com> (raw)
In-Reply-To: <cover.1788259938.git.jasmeet.bhatia.us@gmail.com>

Commit 77d48d39e991 ("efistub/tpm: Use ACPI reclaim memory for event
log to avoid corruption") changed the TPM event log allocation from
EFI_LOADER_DATA to EFI_ACPI_RECLAIM_MEMORY so that the memory would
remain reserved across kexec.

On x86, EFI_ACPI_RECLAIM_MEMORY is represented as ACPI data in the
E820 map. If the EFI allocator places the event log at a different
physical address on a subsequent boot, this changes the firmware E820
map.

x86 hibernation records architecture-specific information derived
from that map and rejects the image when it differs on resume:

  Hibernate inconsistent memory map detected!
  PM: hibernation: Image mismatch: architecture specific data

This occurs on a Framework Laptop 16 (AMD Ryzen AI 300 Series), where
the EFI allocation backing the TPM event log was observed at different
addresses across otherwise ordinary boots.

Allocate the event log from EFI_LOADER_DATA again so that the
Linux-created allocation does not appear as an E820 ACPI region.
Preserve the kexec protection provided by commit 77d48d39e991
("efistub/tpm: Use ACPI reclaim memory for event log to avoid corruption")
by adding the event log range to the Linux EFI persistent memreserve
table.

On Linux 7.2, the stock kernel failed hibernation resume because of the
E820 mismatch, while both an EFI_LOADER_DATA-only diagnostic build and
this series resumed successfully.

With this series, the TPM event log range remained reserved across
both kexec_file_load() and kexec_load(). The contents exported through
binary_bios_measurements were byte-for-byte identical before and after
both kexec tests.

Fixes: 77d48d39e991 ("efistub/tpm: Use ACPI reclaim memory for event log to avoid corruption")
Link: https://lore.kernel.org/all/DL3MNWW4VEBR.K3K6A92WMHUY@gmail.com/
Signed-off-by: Jasmeet (Jazz) Bhatia <jasmeet.bhatia.us@gmail.com>
---
 drivers/firmware/efi/libstub/tpm.c |  2 +-
 drivers/firmware/efi/tpm.c         | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c
index a5c6c4f163fc..8e04aaf428d0 100644
--- a/drivers/firmware/efi/libstub/tpm.c
+++ b/drivers/firmware/efi/libstub/tpm.c
@@ -96,7 +96,7 @@ static void efi_retrieve_tcg2_eventlog(int version, efi_physical_addr_t log_loca
 	}
 
 	/* Allocate space for the logs and copy them. */
-	status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY,
+	status = efi_bs_call(allocate_pool, EFI_LOADER_DATA,
 			     sizeof(*log_tbl) + log_size, (void **)&log_tbl);
 
 	if (status != EFI_SUCCESS) {
diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
index cdd431027065..9771cc91d71e 100644
--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -15,6 +15,9 @@
 
 int efi_tpm_final_log_size;
 EXPORT_SYMBOL(efi_tpm_final_log_size);
+#ifdef CONFIG_KEXEC_CORE
+static unsigned int efi_tpm_eventlog_size __initdata;
+#endif
 
 static int __init tpm2_calc_event_log_size(void *data, int count, void *size_info)
 {
@@ -68,6 +71,10 @@ int __init efi_tpm_eventlog_init(void)
 		goto out;
 	}
 
+#ifdef CONFIG_KEXEC_CORE
+	efi_tpm_eventlog_size = tbl_size;
+#endif
+
 	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR) {
 		pr_info("TPM Final Events table not present\n");
 		goto out;
@@ -114,3 +121,23 @@ int __init efi_tpm_eventlog_init(void)
 	return ret;
 }
 
+#ifdef CONFIG_KEXEC_CORE
+static int __init efi_tpm_eventlog_reserve_persistent(void)
+{
+	int ret;
+
+	if (efi.tpm_log == EFI_INVALID_TABLE_ADDR ||
+	    !efi_tpm_eventlog_size)
+		return 0;
+
+	ret = efi_mem_reserve_persistent(efi.tpm_log,
+					 efi_tpm_eventlog_size);
+	if (ret)
+		pr_warn("Failed to persistently reserve TPM Event Log: %d\n",
+			ret);
+
+	return 0;
+}
+late_initcall(efi_tpm_eventlog_reserve_persistent);
+#endif
+
-- 
2.55.0


  parent reply	other threads:[~2026-09-01 11:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 11:34 [PATCH v1 0/2] efi/tpm: Preserve event log without changing x86 E820 Jasmeet (Jazz) Bhatia
2026-09-01 11:34 ` [PATCH v1 1/2] efi/libstub: Install memreserve table on x86 Jasmeet (Jazz) Bhatia
2026-09-01 11:34 ` Jasmeet (Jazz) Bhatia [this message]
2026-09-03 14:18 ` [PATCH v1 0/2] efi/tpm: Preserve event log without changing x86 E820 Ard Biesheuvel
2026-09-04 15:45   ` Jasmeet (Jazz) Bhatia
2026-09-04 16:38     ` Ard Biesheuvel
2026-09-07 15:57       ` Ilias Apalodimas
2026-09-11  3:03         ` Jasmeet (Jazz) Bhatia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f6a746a26d2d02ce9de279db9d5928da72eba610.1788259938.git.jasmeet.bhatia.us@gmail.com \
    --to=jasmeet.bhatia.us@gmail.com \
    --cc=ardb@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®