Skip to contentSkip to conversation

Improve U-Boot's TPM handling in the non-EFI case

PATCH Superseded Ludwig Nussel 2 participants 8 messages Apr 29 – May 4 Library code

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Improve U-Boot's TPM handling in the non-EFI case

U-Boot might be the first component to start the event log, eg when used in qemu. So allocate and attach the TPM event log to the TPM device if not initialized yet. The address is copied into the device tree for the kernel so the event log is accessible from Linux userspace too.

I am not sure the allocation is the right way to do it for stuff that gets passed to the kernel though. Advice welcome.

Ludwig Nussel (3):
test: include mapmem.h explicitly
tpm: make pcr_read command more useful
tpm: allocate tpm event log if missing

 boot/Kconfig            |   1 +
 boot/bootm.c            |  18 +++----
 boot/image-fdt.c        |  67 ++++++++++++++++++++++++++
 cmd/tpm-v2.c            |  54 ++++++++++++++-------
 include/tpm-common.h    |   1 +
 include/tpm_tcg2.h      |   9 ++--
 lib/tpm_tcg2.c          | 101 +++++++++++++++++++++++++++++++---------
 test/boot/measurement.c |   1 +
 8 files changed, 197 insertions(+), 55 deletions(-)
Signature · 4 lines
2.43.0

base-commit: 70cb0b8232246c5157802cc26536258a1a446603
branch: us-tpm
#1 lore raw

PATCH 1/3 test: include mapmem.h explicitly

The file uses map_to_sysmem() from mapmem.h but relies on implicit includes which may not work in all circumstances

---

 test/boot/measurement.c | 1 +
 1 file changed, 1 insertion(+)
test/boot/measurement.c +1 -0
index 71f503f1567..de4f7ff6196 100644
@@ -9,6 +9,7 @@
 #include <bootm.h>
 #include <env.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <test/test.h>
 #include <test/ut.h>
 #include <asm/io.h>
Signature · 1 line
2.43.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] test: include mapmem.h explicitly

Quoted 9 lines · Ludwig Nussel

test: include mapmem.h explicitly

The file uses map_to_sysmem() from mapmem.h but relies on implicit includes which may not work in all circumstances

test/boot/measurement.c | 1 +

 1 file changed, 1 insertion(+)
#3 lore raw

PATCH 2/3 tpm: make pcr_read command more useful

In reply to Ludwig Nussel

Output now more similar to Linux userspace tool "tpm2_pcrread".

Without arguments the command now prints contents of all PCR registers

---

 cmd/tpm-v2.c | 54 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 18 deletions(-)
cmd/tpm-v2.c +36 -18
index 847b2691581..3bcb11a8de6 100644
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <log.h>
 #include <mapmem.h>
+#include <malloc.h>
 #include <tpm-common.h>
 #include <tpm-v2.h>
 #include "tpm-user-utils.h"
@@ -150,10 +151,11 @@ static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc,
 	u32 index, rc;
 	int algo_len;
 	unsigned int updates;
-	void *data;
+	u8 *data;
 	int ret;
+	u32 pcr_start, pcr_end;
 
-	if (argc < 3 || argc > 4)
+	if (argc > 4)
 		return CMD_RET_USAGE;
 	if (argc == 4) {
 		algo = tpm2_name_to_algorithm(argv[3]);
@@ -164,28 +166,44 @@ static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	ret = get_tpm(&dev);
 	if (ret)
-		return ret;
+		goto out;
 
 	priv = dev_get_uclass_priv(dev);
 	if (!priv)
-		return -EINVAL;
-
-	index = simple_strtoul(argv[1], NULL, 0);
-	if (index >= priv->pcr_count)
-		return -EINVAL;
-
-	data = map_sysmem(simple_strtoul(argv[2], NULL, 0), 0);
+		goto out;
 
-	rc = tpm2_pcr_read(dev, index, priv->pcr_select_min, algo,
-			   data, algo_len, &updates);
-	if (!rc) {
-		printf("PCR #%u %s %d byte content (%u known updates):\n", index,
-		       tpm2_algorithm_name(algo), algo_len, updates);
-		print_byte_string(data, algo_len);
+	if (argc >= 2) {
+		pcr_start = simple_strtoul(argv[1], NULL, 0);
+		if (pcr_start >= priv->pcr_count)
+			return -EINVAL;
+		pcr_end = pcr_start + 1;
+	} else {
+		pcr_start = 0;
+		pcr_end = priv->pcr_count;
 	}
 
-	unmap_sysmem(data);
+	if (argc >= 3)
+		data = map_sysmem(simple_strtoul(argv[2], NULL, 0), 0);
+	else
+		data = malloc(algo_len);
+
+	printf("%8s:\n", tpm2_algorithm_name(algo));
+	for (index = pcr_start; index < pcr_end; ++index) {
+		rc = tpm2_pcr_read(dev, index, priv->pcr_select_min, algo,
+				   data, algo_len, &updates);
+		if (!rc) {
+			printf("%6u: 0x", index);
+			for (int i = 0; i < algo_len; ++i)
+				printf("%02X", data[i]);
+			printf(" (%u known updates)\n", updates);
+		}
+	}
+	if (argc >= 3)
+		unmap_sysmem(data);
+	else
+		free(data);
 
+out:
 	return report_return_code(rc);
 }
 
@@ -548,7 +566,7 @@ U_BOOT_CMD(tpm2, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    Extend PCR #<pcr> with digest at <digest_addr> with digest_algo.\n"
 "    <pcr>: index of the PCR\n"
 "    <digest_addr>: address of digest of digest_algo type (defaults to SHA256)\n"
-"pcr_read <pcr> <digest_addr> [<digest_algo>]\n"
+"pcr_read [<pcr> [<digest_addr> [<digest_algo>]]]\n"
 "    Read PCR #<pcr> to memory address <digest_addr> with <digest_algo>.\n"
 "    <pcr>: index of the PCR\n"
 "    <digest_addr>: address of digest of digest_algo type (defaults to SHA256)\n"
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH 2/3] tpm: make pcr_read command more useful

Hi Ludwig,

Quoted 14 lines · Ludwig Nussel

tpm: make pcr_read command more useful

Output now more similar to Linux userspace tool 'tpm2_pcrread'.

Without arguments the command now prints contents of all PCR registers

cmd/tpm-v2.c | 54 ++++++++++++++++++++++++++++++++++++------------------

 1 file changed, 36 insertions(+), 18 deletions(-)
cmd/tpm-v2.c +0 -0
@@ -150,10 +151,11 @@ static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc,
      u32 index, rc;

cmd/tpm-v2.c static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc, · line 159

Quoted 10 lines
cmd/tpm-v2.c +3 -2
      int algo_len;
      unsigned int updates;
-     void *data;
+     u8 *data;
      int ret;
+     u32 pcr_start, pcr_end;
 
-     if (argc < 3 || argc > 4)
+     if (argc > 4)
              return CMD_RET_USAGE;

Please mention the new behaviour explicitly in the commit message - something like "with no arguments all PCRs are read; with only the PCR index a buffer is allocated internally."

The subject is also a bit vague - how about 'tpm: print all PCRs from pcr_read'

Quoted 11 lines
cmd/tpm-v2.c +1 -2
@@ -164,28 +166,44 @@ static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc,
 
      ret = get_tpm(&dev);
      if (ret)
-             return ret;
+             goto out;
 
      priv = dev_get_uclass_priv(dev);
      if (!priv)
-             return -EINVAL;

...

Quoted 2 lines

+out:

      return report_return_code(rc);

rc is never assigned on either of these paths, so report_return_code() reads an uninitialised value. Either drop the goto and return ret/-EINVAL as before, or assign rc before the jump.

This return -EINVAL bypasses the out: label you just added...

cmd/tpm-v2.c static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc, · line 169

Quoted 6 lines
cmd/tpm-v2.c +4 -0
@@ -164,28 +166,44 @@ static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc,
+     if (argc >= 3)
+             data = map_sysmem(simple_strtoul(argv[2], NULL, 0), 0);
+     else
+             data = malloc(algo_len);

malloc() can fail and the result is dereferenced via tpm2_pcr_read() without a check. Please bail out cleanly if data is NULL.

cmd/tpm-v2.c static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc, · line 176

Quoted 13 lines
cmd/tpm-v2.c +11 -0
@@ -164,28 +166,44 @@ static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc,
+     printf('%8s:\n', tpm2_algorithm_name(algo));
+     for (index = pcr_start; index < pcr_end; ++index) {
+             rc = tpm2_pcr_read(dev, index, priv->pcr_select_min, algo,
+                                data, algo_len, &updates);
+             if (!rc) {
+                     printf("%6u: 0x", index);
+                     for (int i = 0; i < algo_len; ++i)
+                             printf('%02X', data[i]);
+                     printf(" (%u known updates)\n", updates);
+             }
+     }

A failing read in the middle of the loop is silently swallowed - the user sees a gap and then a bogus banner with no error. At minimum log_err() the failure, and consider whether to keep going or abort. Also rc from the last iteration is what gets reported, which is misleading if an earlier PCR failed.

cmd/tpm-v2.c U_BOOT_CMD(tpm2, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command", · line 572

Quoted 10 lines
cmd/tpm-v2.c +1 -1
@@ -548,7 +566,7 @@ U_BOOT_CMD(tpm2, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    Extend PCR #<pcr> with digest at <digest_addr> with digest_algo.\n"
 "    <pcr>: index of the PCR\n"
 "    <digest_addr>: address of digest of digest_algo type (defaults to SHA256)\n"
-"pcr_read <pcr> <digest_addr> [<digest_algo>]\n"
+"pcr_read [<pcr> [<digest_addr> [<digest_algo>]]]\n"
 "    Read PCR #<pcr> to memory address <digest_addr> with <digest_algo>.\n"
 "    <pcr>: index of the PCR\n"
 "    <digest_addr>: address of digest of digest_algo type (defaults to SHA256)\n"

The description still says "Read PCR #<pcr> to memory address <digest_addr>" - please update it to mention that with no <pcr> all PCRs are printed, and that <digest_addr> is now optional.

Regards,
Simon

#5 lore raw

PATCH 3/3 tpm: allocate tpm event log if missing

In reply to Ludwig Nussel

Allocate and attach the TPM event log to the TPM device if not initialized yet. The address is copied into the device tree for the kernel so the event log is accessible from Linux userspace too.

---

 boot/Kconfig         |   1 +
 boot/bootm.c         |  18 +++-----
 boot/image-fdt.c     |  67 ++++++++++++++++++++++++++++
 include/tpm-common.h |   1 +
 include/tpm_tcg2.h   |   9 ++--
 lib/tpm_tcg2.c       | 101 +++++++++++++++++++++++++++++++++----------
 6 files changed, 160 insertions(+), 37 deletions(-)
boot/Kconfig +1 -0
index ae6f09a6ede..a4e23f9c78a 100644
@@ -1041,6 +1041,7 @@ config MEASURED_BOOT
 	select SHA384
 	select SHA512
 	select SM3
+	select DEVRES
 	help
 	  This option enables measurement of the boot process when booting
 	  without UEFI . Measurement involves creating cryptographic hashes
boot/bootm.c +7 -11
index 4836d6b2d41..701ec010e01 100644
@@ -921,23 +921,19 @@ int bootm_measure(struct bootm_headers *images)
 		return ret;
 
 	if (IS_ENABLED(CONFIG_MEASURED_BOOT)) {
-		struct tcg2_event_log elog;
 		struct udevice *dev;
 		void *initrd_buf;
 		void *image_buf;
 		const char *s;
 		u32 rd_len;
-		bool ign;
 
-		elog.log_size = 0;
-		ign = IS_ENABLED(CONFIG_MEASURE_IGNORE_LOG);
-		ret = tcg2_measurement_init(&dev, &elog, ign);
-		if (ret)
+		ret = tcg2_measurement_init(&dev, NULL);
+		if (ret && ret != -EEXIST)
 			return ret;
 
 		image_buf = map_sysmem(images->os.image_start,
 				       images->os.image_len);
-		ret = tcg2_measure_data(dev, &elog, 8, images->os.image_len,
+		ret = tcg2_measure_data(dev, NULL, 8, images->os.image_len,
 					image_buf, EV_COMPACT_HASH,
 					strlen("linux") + 1, (u8 *)"linux");
 		if (ret)
@@ -945,14 +941,14 @@ int bootm_measure(struct bootm_headers *images)
 
 		rd_len = images->rd_end - images->rd_start;
 		initrd_buf = map_sysmem(images->rd_start, rd_len);
-		ret = tcg2_measure_data(dev, &elog, 9, rd_len, initrd_buf,
+		ret = tcg2_measure_data(dev, NULL, 9, rd_len, initrd_buf,
 					EV_COMPACT_HASH, strlen("initrd") + 1,
 					(u8 *)"initrd");
 		if (ret)
 			goto unmap_initrd;
 
 		if (IS_ENABLED(CONFIG_MEASURE_DEVICETREE)) {
-			ret = tcg2_measure_data(dev, &elog, 1, images->ft_len,
+			ret = tcg2_measure_data(dev, NULL, 1, images->ft_len,
 						(u8 *)images->ft_addr,
 						EV_TABLE_OF_DEVICES,
 						strlen("dts") + 1,
@@ -964,7 +960,7 @@ int bootm_measure(struct bootm_headers *images)
 		s = env_get("bootargs");
 		if (!s)
 			s = "";
-		ret = tcg2_measure_data(dev, &elog, 1, strlen(s) + 1, (u8 *)s,
+		ret = tcg2_measure_data(dev, NULL, 1, strlen(s) + 1, (u8 *)s,
 					EV_PLATFORM_CONFIG_FLAGS,
 					strlen(s) + 1, (u8 *)s);
 
@@ -973,7 +969,7 @@ unmap_initrd:
 
 unmap_image:
 		unmap_sysmem(image_buf);
-		tcg2_measurement_term(dev, &elog, ret != 0);
+		tcg2_measurement_term(dev, NULL, ret != 0);
 	}
 
 	return ret;
boot/image-fdt.c +67 -0

85 lines not on this page · raw message

include/tpm-common.h +1 -0
index bfb84a931d1..f02dae679bd 100644
@@ -83,6 +83,7 @@ struct tpm_chip_priv {
 	u32 active_banks[TPM2_NUM_PCR_BANKS];
 #endif
 	bool plat_hier_disabled;
+	void *log; /* struct tcg2_event_log */
 };
 
 /**
include/tpm_tcg2.h +5 -4
index eb6afe49e77..db3f6f486e9 100644
@@ -162,12 +162,14 @@ struct tcg_efi_spec_id_event {
  * @log_position:	Current entry position
  * @log_size:		Log space available
  * @found:		Boolean indicating if an existing log was discovered
+ * @allocated:		Boolean indicating that the log was allocated by u-boot
  */
 struct tcg2_event_log {
 	u8 *log;
 	u32 log_position;
 	u32 log_size;
 	bool found;
+	bool allocated;
 };
 
 /**
@@ -291,13 +293,10 @@ int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,
  *			memory region, in which case any existing log
  *			discovered will be copied to the specified memory
  *			region.
- * @ignore_existing_log Boolean to indicate whether or not to ignore an
- *			existing platform log in memory
  *
  * Return: zero on success, negative errno otherwise
  */
-int tcg2_measurement_init(struct udevice **dev, struct tcg2_event_log *elog,
-			  bool ignore_existing_log);
+int tcg2_measurement_init(struct udevice **dev, struct tcg2_event_log *elog);
 
 /**
  * Stop measurements and record separator events.
@@ -345,4 +344,6 @@ void tcg2_platform_startup_error(struct udevice *dev, int rc);
  */
 u32 tcg2_algorithm_to_mask(enum tpm2_algorithms);
 
+struct tcg2_event_log *tcg2_platform_get_dev_log(struct udevice *dev);
+
 #endif /* __TPM_TCG_V2_H */
lib/tpm_tcg2.c +79 -22

165 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH 3/3] tpm: allocate tpm event log if missing

Hi Ludwig,

Quoted 18 lines · Ludwig Nussel

tpm: allocate tpm event log if missing

Allocate and attach the TPM event log to the TPM device if not initialized yet. The address is copied into the device tree for the kernel so the event log is accessible from Linux userspace too.

boot/Kconfig         |   1 +
 boot/bootm.c         |  18 ++++-----
 boot/image-fdt.c     |  67 ++++++++++++++++++++++++++++++++++
 include/tpm-common.h |   1 +
 include/tpm_tcg2.h   |   9 +++--
 lib/tpm_tcg2.c       | 101 ++++++++++++++++++++++++++++++++++++++++-----------
 6 files changed, 160 insertions(+), 37 deletions(-)

boot/bootm.c unmap_initrd: · line 972

Quoted 5 lines
boot/bootm.c +1 -1
@@ -973,7 +969,7 @@ unmap_initrd:
 
 unmap_image:
              unmap_sysmem(image_buf);
-             tcg2_measurement_term(dev, &elog, ret != 0);
+             tcg2_measurement_term(dev, NULL, ret != 0);

This passes NULL for elog, but tcg2_measurement_term() still does if (elog->log) unmap_physmem(...) and calls tcg2_measure_event() which ends up in tcg2_log_append_check() doing if (!elog->log_size). Both deref a NULL pointer. tcg2_measure_data() looks the log up via tcg2_platform_get_dev_log() when elog is NULL - so _term and tcg2_measure_event() need the same treatment.

boot/image-fdt.c line 30

Quoted 9 lines
boot/image-fdt.c +4 -0
@@ -24,6 +24,10 @@
 #include <asm/io.h>
 #include <dm/ofnode.h>
 #include <tee/optee.h>
+#if defined(CONFIG_MEASURED_BOOT)
+#include <tpm_tcg2.h>
+#include <dm/device.h>
+#endif

Please drop the #if around the includes, and inside the function body prefer if (IS_ENABLED(CONFIG_MEASURED_BOOT)) over #if defined(...) so the compiler still type-checks the body when the option is off. That is the U-Boot convention.

boot/image-fdt.c __weak int arch_fixup_fdt(void *blob) · line 599

Quoted 9 lines
boot/image-fdt.c +7 -0
@@ -589,6 +593,67 @@ __weak int arch_fixup_fdt(void *blob)
+     strlcat(path, '/linux,sml-base', sizeof(path));
+     if (fdt_path_offset(blob, path) >= 0) {
+             log_warning("kernel dt already defines an event log address at %s\n", path);
+             return 0;
+     }
+     end = strrchr(path, '/');
+     *end = 0;

fdt_path_offset() resolves nodes, not properties, so this never matches - linux,sml-base is a property of the TPM node. Use fdt_getprop() against the node offset you already located above.

boot/image-fdt.c __weak int arch_fixup_fdt(void *blob) · line 594

Quoted 4 lines
boot/image-fdt.c +2 -0
@@ -589,6 +593,67 @@ __weak int arch_fixup_fdt(void *blob)
+     fdt64_t a = cpu_to_fdt64((u64)virt_to_phys(log->log));
+     fdt32_t s = cpu_to_fdt32((u32)log->log_position);

linux,sml-size is documented (and used by Linux) as the size of the reserved buffer, not the bytes written so far. Otherwise the kernel cannot append further entries. This should be log->log_size. Please also give the locals descriptive names (sml_base/sml_size).

boot/image-fdt.c int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb) · line 697

Quoted 4 lines
boot/image-fdt.c +2 -0
@@ -631,6 +696,8 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb)
+     copy_tpm_event_log(blob);
+

The return value is silently dropped. At minimum log a warning when it fails with anything other than -ENOENT, otherwise misconfigurations (e.g. allocation succeeded but fdt_find_and_setprop failed) will be invisible.

Quoted 12 lines
lib/tpm_tcg2.c +7 -1
@@ -564,11 +576,29 @@ int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,
+     } else if (tcg2_platform_get_dev_log(dev)) {
+             return -EEXIST;
+     }
 
      rc = tcg2_platform_get_log(dev, (void **)&log.log, &log.log_size);
-     if (!rc) {
+     /* no existing event log found and none allocated yet */
+     if (rc && !elog) {
+             /* magic size value. Same as in acpi_table.c */
+             log.log_size = 0x10000;

lib/tpm_tcg2.c int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog, · line 594

Quoted 10 lines
lib/tpm_tcg2.c +10 -0
+             log.log = devm_kzalloc(dev, log.log_size, 0);
+             if (log.log) {
+                     log.allocated = true;
+                     ignore_existing_log = true;
+             } else {
+                     log_err("Failed to allocate %u bytes event log\n", log.log_size);
+             }
+     }
+
+     if (log.log) {

When tcg2_platform_get_log() fails and elog is non-NULL we fall through with log.log uninitialised, then test if (log.log) on stack garbage. Either zero-initialise struct tcg2_event_log log = {} at the top, or skip the block explicitly.

For 0x10000, please introduce a named constant (e.g. TPM2_EVENT_LOG_SIZE) shared with acpi_table.c rather than duplicating the comment.

lib/tpm_tcg2.c int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog, · line 615

Quoted 8 lines
lib/tpm_tcg2.c +5 -0
@@ -580,26 +610,40 @@ int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,
+             } else {
+                     struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
+
+                     elog = devm_kzalloc(dev, sizeof(struct tcg2_event_log), 0);
+
                      elog->log = log.log;

devm_kzalloc() can return NULL - this dereferences it immediately, and on failure leaks the 64KB buffer allocated above. Please check and unwind cleanly.

lib/tpm_tcg2.c void tcg2_measurement_term(struct udevice *dev, struct tcg2_event_log *elog, · line 717

Quoted 10 lines
lib/tpm_tcg2.c +8 -0
@@ -662,6 +710,15 @@ void tcg2_measurement_term(struct udevice *dev, struct tcg2_event_log *elog,
+struct tcg2_event_log *tcg2_platform_get_dev_log(struct udevice *dev)
+{
+     struct tpm_chip_priv *priv;
+
+     priv = dev_get_uclass_priv(dev);
+
+     return priv->log;
+}

Missing kernel-doc.

include/tpm-common.h struct tpm_chip_priv { · line 86

Quoted 6 lines
include/tpm-common.h +1 -0
@@ -83,6 +83,7 @@ struct tpm_chip_priv {
      u32 active_banks[TPM2_NUM_PCR_BANKS];
 #endif
      bool plat_hier_disabled;
+     void *log; /* struct tcg2_event_log */

Please use a forward declaration ('struct tcg2_event_log;') and type the field properly as struct tcg2_event_log *log. Hiding the type behind void * loses compiler checking and forces every reader to trust the comment.

Regards,
Simon

#7 lore raw
In reply to Ludwig Nussel

Hi Ludwig,

Quoted 3 lines · Ludwig Nussel

U-Boot might be the first component to start the event log, eg when used in qemu. So allocate and attach the TPM event log to the TPM device if not initialized yet.

Thanks for looking at this. The cover letter should really mention patches 1 and 2 - the pcr_read changes are definitely user-visible.

Quoted 2 lines

I am not sure the allocation is the right way to do it for stuff that gets passed to the kernel though. Advice welcome.

Handing devm-allocated memory to the kernel is risky - devres can free it on device removal, and the kernel expects the buffer to live forever once linux,sml-base points at it. For memory the kernel will own you want a reserved-memory region (or at least an lmb_reserve()) so it isn't reused later in the boot. What do you think?

Can we have a test and a note in doc/usage/ describing the new behaviour and the linux,sml-base/linux,sml-size handoff?

Regards,
Simon