Skip to contentSkip to conversation

tpm: Add support for event log pointer found in TPM2 ACPI table

PATCH In review Stefan Berger 4 participants 5 messages Mar 31, 2020 – Apr 2, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 tpm: Add support for event log pointer found in TPM2 ACPI table

From: Stefan Berger <[email protected]>

In case a TPM2 is attached, search for a TPM2 ACPI table when trying to get the event log from ACPI. If one is found, use it to get the start and length of the log area. This allows non-UEFI systems, such as SeaBIOS, to pass an event log when using a TPM2.

---
 drivers/char/tpm/eventlog/acpi.c | 56 +++++++++++++++++++++++++---------------
 1 file changed, 35 insertions(+), 21 deletions(-)
drivers/char/tpm/eventlog/acpi.c +35 -21
index 63ada5e53f13..e714a2bd0423 100644
@@ -49,9 +49,8 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
 	void __iomem *virt;
 	u64 len, start;
 	struct tpm_bios_log *log;
-
-	if (chip->flags & TPM_CHIP_FLAG_TPM2)
-		return -ENODEV;
+	struct acpi_table_tpm2 *tbl;
+	int format;
 
 	log = &chip->log;
 
@@ -61,23 +60,38 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
 	if (!chip->acpi_dev_handle)
 		return -ENODEV;
 
-	/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
-	status = acpi_get_table(ACPI_SIG_TCPA, 1,
-				(struct acpi_table_header **)&buff);
-
-	if (ACPI_FAILURE(status))
-		return -ENODEV;
-
-	switch(buff->platform_class) {
-	case BIOS_SERVER:
-		len = buff->server.log_max_len;
-		start = buff->server.log_start_addr;
-		break;
-	case BIOS_CLIENT:
-	default:
-		len = buff->client.log_max_len;
-		start = buff->client.log_start_addr;
-		break;
+	if (chip->flags & TPM_CHIP_FLAG_TPM2) {
+		status = acpi_get_table("TPM2", 1,
+					(struct acpi_table_header **)&tbl);
+		if (ACPI_FAILURE(status))
+			return -ENODEV;
+		if (tbl->header.length < sizeof(*tbl))
+			return -ENODEV;
+		len = tbl->log_area_minimum_length;
+		start = tbl->log_area_start_address;
+		if (!start || !len)
+			return -ENODEV;
+		format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
+	} else {
+		/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
+		status = acpi_get_table(ACPI_SIG_TCPA, 1,
+					(struct acpi_table_header **)&buff);
+
+		if (ACPI_FAILURE(status))
+			return -ENODEV;
+
+		switch (buff->platform_class) {
+		case BIOS_SERVER:
+			len = buff->server.log_max_len;
+			start = buff->server.log_start_addr;
+			break;
+		case BIOS_CLIENT:
+		default:
+			len = buff->client.log_max_len;
+			start = buff->client.log_start_addr;
+			break;
+		}
+		format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
 	}
 	if (!len) {
 		dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__);
@@ -98,7 +112,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
 	memcpy_fromio(log->bios_event_log, virt, len);
 
 	acpi_os_unmap_iomem(virt, len);
-	return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
+	return format;
 
 err:
 	kfree(log->bios_event_log);
Signature · 1 line
2.14.5
#1 lore raw
Thank you for the patch! Yet something to improve:

Hi Stefan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v5.6 next-20200331]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Stefan-Berger/tpm-Add-support-for-event-log-pointer-found-in-TPM2-ACPI-table/20200401-055303
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 5caf6102e32ead7ed5d21b5309c1a4a7d70e6a9f
config: x86_64-randconfig-s1-20200401 (attached as .config)
compiler: gcc-7 (Debian 7.4.0-6) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

drivers/char/tpm/eventlog/acpi.c: In function 'tpm_read_log_acpi':

>> drivers/char/tpm/eventlog/acpi.c:70:12: error: 'struct acpi_table_tpm2' has no member named 'log_area_minimum_length'
      len = tbl->log_area_minimum_length;
               ^~
>> drivers/char/tpm/eventlog/acpi.c:71:14: error: 'struct acpi_table_tpm2' has no member named 'log_area_start_address'
      start = tbl->log_area_start_address;
                 ^~

vim +70 drivers/char/tpm/eventlog/acpi.c

    43	
    44	/* read binary bios log */
    45	int tpm_read_log_acpi(struct tpm_chip *chip)
    46	{
    47		struct acpi_tcpa *buff;
    48		acpi_status status;
    49		void __iomem *virt;
    50		u64 len, start;
    51		struct tpm_bios_log *log;
    52		struct acpi_table_tpm2 *tbl;
    53		int format;
    54	
    55		log = &chip->log;
    56	
    57		/* Unfortuntely ACPI does not associate the event log with a specific
    58		 * TPM, like PPI. Thus all ACPI TPMs will read the same log.
    59		 */
    60		if (!chip->acpi_dev_handle)
    61			return -ENODEV;
    62	
    63		if (chip->flags & TPM_CHIP_FLAG_TPM2) {
    64			status = acpi_get_table("TPM2", 1,
    65						(struct acpi_table_header **)&tbl);
    66			if (ACPI_FAILURE(status))
    67				return -ENODEV;
    68			if (tbl->header.length < sizeof(*tbl))
    69				return -ENODEV;
  > 70			len = tbl->log_area_minimum_length;
  > 71			start = tbl->log_area_start_address;
    72			if (!start || !len)
    73				return -ENODEV;
    74			format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
    75		} else {
    76			/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
    77			status = acpi_get_table(ACPI_SIG_TCPA, 1,
    78						(struct acpi_table_header **)&buff);
    79	
    80			if (ACPI_FAILURE(status))
    81				return -ENODEV;
    82	
    83			switch (buff->platform_class) {
    84			case BIOS_SERVER:
    85				len = buff->server.log_max_len;
    86				start = buff->server.log_start_addr;
    87				break;
    88			case BIOS_CLIENT:
    89			default:
    90				len = buff->client.log_max_len;
    91				start = buff->client.log_start_addr;
    92				break;
    93			}
    94			format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
    95		}
    96		if (!len) {
    97			dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__);
    98			return -EIO;
    99		}

100
101 /* malloc EventLog space */
102 log->bios_event_log = kmalloc(len, GFP_KERNEL);
103 if (!log->bios_event_log)
104 return -ENOMEM;
105
106 log->bios_event_log_end = log->bios_event_log + len;
107
108 virt = acpi_os_map_iomem(start, len);
109 if (!virt)
110 goto err;
111
112 memcpy_fromio(log->bios_event_log, virt, len);
113
114 acpi_os_unmap_iomem(virt, len);
115 return format;
116
117 err:
118 kfree(log->bios_event_log);
119 log->bios_event_log = NULL;
120 return -EIO;
121

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Stefan Berger
Quoted 8 lines · Stefan Berger

From: Stefan Berger <[email protected]>

In case a TPM2 is attached, search for a TPM2 ACPI table when trying to get the event log from ACPI. If one is found, use it to get the start and length of the log area. This allows non-UEFI systems, such as SeaBIOS, to pass an event log when using a TPM2.

Check the kbuild bot complain. I think otherwise this is sustainable. Thank you.

Does stock QEMU have all the support to test this?

/Jarkko

#3 lore raw
Quoted 11 lines · Jarkko Sakkinen
Quoted 8 lines · Stefan Berger

From: Stefan Berger <[email protected]>

In case a TPM2 is attached, search for a TPM2 ACPI table when trying to get the event log from ACPI. If one is found, use it to get the start and length of the log area. This allows non-UEFI systems, such as SeaBIOS, to pass an event log when using a TPM2.

Check the kbuild bot complain. I think otherwise this is sustainable. Thank you.

The kbuild bot did this due to the split of the patch series...

Quoted 2 lines

Does stock QEMU have all the support to test this?

Yes. You need SeaBIOS.

   Stefan

Quoted 2 lines

/Jarkko

#4 lore raw
Quoted 9 lines · Stefan Berger
Quoted 8 lines · Jarkko Sakkinen
Quoted 7 lines · Stefan Berger

From: Stefan Berger <[email protected]>

In case a TPM2 is attached, search for a TPM2 ACPI table when trying to get the event log from ACPI. If one is found, use it to get the start and length of the log area. This allows non-UEFI systems, such as SeaBIOS, to pass an event log when using a TPM2.

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

Check the kbuild bot complain. I think otherwise this is sustainable. Thank you.

The kbuild bot did this due to the split of the patch series...

Please resend them two patch series.

/Jarkko