Commit 0cf577a0 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Jarkko Sakkinen

tpm: Fix handling of missing event log

The event log is an optional firmware feature, if the firmware
does not support it then the securityfs files should not be created
and no other notification given.

- Uniformly return -ENODEV from the tpm_bios_log_setup cone if
  no event log is detected.
- Check in ACPI if this node was discovered via ACPI.
- Improve the check in OF to make sure there is a parent and to
  fail detection if the two log properties are not declared
- Pass through all other error codes instead of filtering just some
Signed-off-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
parent 005451d4
...@@ -346,7 +346,7 @@ int tpm_chip_register(struct tpm_chip *chip) ...@@ -346,7 +346,7 @@ int tpm_chip_register(struct tpm_chip *chip)
tpm_sysfs_add_device(chip); tpm_sysfs_add_device(chip);
rc = tpm_bios_log_setup(chip); rc = tpm_bios_log_setup(chip);
if (rc == -ENODEV) if (rc != 0 && rc != -ENODEV)
return rc; return rc;
tpm_add_ppi(chip); tpm_add_ppi(chip);
......
...@@ -56,12 +56,18 @@ int tpm_read_log_acpi(struct tpm_chip *chip) ...@@ -56,12 +56,18 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
log = &chip->log; log = &chip->log;
/* Unfortuntely ACPI does not associate the event log with a specific
* TPM, like PPI. Thus all ACPI TPMs will read the same log.
*/
if (!chip->acpi_dev_handle)
return -ENODEV;
/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */ /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
status = acpi_get_table(ACPI_SIG_TCPA, 1, status = acpi_get_table(ACPI_SIG_TCPA, 1,
(struct acpi_table_header **)&buff); (struct acpi_table_header **)&buff);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -EIO; return -ENODEV;
switch(buff->platform_class) { switch(buff->platform_class) {
case BIOS_SERVER: case BIOS_SERVER:
......
...@@ -368,14 +368,21 @@ static int tpm_read_log(struct tpm_chip *chip) ...@@ -368,14 +368,21 @@ static int tpm_read_log(struct tpm_chip *chip)
} }
rc = tpm_read_log_acpi(chip); rc = tpm_read_log_acpi(chip);
if ((rc == 0) || (rc == -ENOMEM)) if (rc != -ENODEV)
return rc; return rc;
rc = tpm_read_log_of(chip); return tpm_read_log_of(chip);
return rc;
} }
/*
* tpm_bios_log_setup() - Read the event log from the firmware
* @chip: TPM chip to use.
*
* If an event log is found then the securityfs files are setup to
* export it to userspace, otherwise nothing is done.
*
* Returns -ENODEV if the firmware has no event log.
*/
int tpm_bios_log_setup(struct tpm_chip *chip) int tpm_bios_log_setup(struct tpm_chip *chip)
{ {
const char *name = dev_name(&chip->dev); const char *name = dev_name(&chip->dev);
...@@ -386,15 +393,8 @@ int tpm_bios_log_setup(struct tpm_chip *chip) ...@@ -386,15 +393,8 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
return 0; return 0;
rc = tpm_read_log(chip); rc = tpm_read_log(chip);
/* if (rc)
* read_log failure means event log is not supported except for ENOMEM. return rc;
*/
if (rc < 0) {
if (rc == -ENOMEM)
return -ENODEV;
else
return rc;
}
cnt = 0; cnt = 0;
chip->bios_dir[cnt] = securityfs_create_dir(name, NULL); chip->bios_dir[cnt] = securityfs_create_dir(name, NULL);
......
...@@ -29,13 +29,16 @@ int tpm_read_log_of(struct tpm_chip *chip) ...@@ -29,13 +29,16 @@ int tpm_read_log_of(struct tpm_chip *chip)
struct tpm_bios_log *log; struct tpm_bios_log *log;
log = &chip->log; log = &chip->log;
if (chip->dev.parent->of_node) if (chip->dev.parent && chip->dev.parent->of_node)
np = chip->dev.parent->of_node; np = chip->dev.parent->of_node;
else else
return -ENODEV; return -ENODEV;
sizep = of_get_property(np, "linux,sml-size", NULL); sizep = of_get_property(np, "linux,sml-size", NULL);
if (sizep == NULL) basep = of_get_property(np, "linux,sml-base", NULL);
if (sizep == NULL && basep == NULL)
return -ENODEV;
if (sizep == NULL || basep == NULL)
return -EIO; return -EIO;
if (*sizep == 0) { if (*sizep == 0) {
...@@ -43,10 +46,6 @@ int tpm_read_log_of(struct tpm_chip *chip) ...@@ -43,10 +46,6 @@ int tpm_read_log_of(struct tpm_chip *chip)
return -EIO; return -EIO;
} }
basep = of_get_property(np, "linux,sml-base", NULL);
if (basep == NULL)
return -EIO;
log->bios_event_log = kmalloc(*sizep, GFP_KERNEL); log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
if (!log->bios_event_log) if (!log->bios_event_log)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment