Skip to contentSkip to conversation

tpm: Enable hwrng only for Pluton on AMD CPUs

PATCH Superseded Jarkko Sakkinen 2 participants 3 messages Aug 22, 2023

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH v2 1/1 tpm: Enable hwrng only for Pluton on AMD CPUs

The vendor check introduced by commit 554b841d4703 ("tpm: Disable RNG for all AMD fTPMs") doesn't work properly on a number of Intel fTPMs. On the reported systems the TPM doesn't reply at bootup and returns back the command code. This makes the TPM fail probe.

Since only Microsoft Pluton is the only known combination of AMD CPU and fTPM from other vendor, disable hwrng otherwise. In order to make sysadmin aware of this, print also info message to the klog.

Fixes 554b841d4703 ("tpm: Disable RNG for all AMD fTPMs")

---
v2:
* CONFIG_X86
* Removed "Reviewed-by: Jarkko Sakkinen <[email protected]>"
* Removed "Signed-off-by: Mario Limonciello <[email protected]>"

---
 drivers/char/tpm/tpm_crb.c | 31 ++++++-------------------------
 1 file changed, 6 insertions(+), 25 deletions(-)
drivers/char/tpm/tpm_crb.c +6 -25
index 65ff4d2fbe8d..28448bfd4062 100644
@@ -463,28 +463,6 @@ static bool crb_req_canceled(struct tpm_chip *chip, u8 status)
 	return (cancel & CRB_CANCEL_INVOKE) == CRB_CANCEL_INVOKE;
 }
 
-static int crb_check_flags(struct tpm_chip *chip)
-{
-	u32 val;
-	int ret;
-
-	ret = crb_request_locality(chip, 0);
-	if (ret)
-		return ret;
-
-	ret = tpm2_get_tpm_pt(chip, TPM2_PT_MANUFACTURER, &val, NULL);
-	if (ret)
-		goto release;
-
-	if (val == 0x414D4400U /* AMD */)
-		chip->flags |= TPM_CHIP_FLAG_HWRNG_DISABLED;
-
-release:
-	crb_relinquish_locality(chip, 0);
-
-	return ret;
-}
-
 static const struct tpm_class_ops tpm_crb = {
 	.flags = TPM_OPS_AUTO_STARTUP,
 	.status = crb_status,
@@ -827,9 +805,12 @@ static int crb_acpi_add(struct acpi_device *device)
 	if (rc)
 		goto out;
 
-	rc = crb_check_flags(chip);
-	if (rc)
-		goto out;
+	/* A quirk for https://www.amd.com/en/support/kb/faq/pa-410 */
+	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+	    priv->sm != ACPI_TPM2_COMMAND_BUFFER_WITH_PLUTON) {
+		dev_info(dev, "Disabling hwrng\n");
+		chip->flags |= TPM_CHIP_FLAG_HWRNG_DISABLED;
+	}
 
 	rc = tpm_chip_register(chip);
 
Signature · 1 line
2.39.2
#1 lore raw
Quoted 9 lines · Jarkko Sakkinen

The vendor check introduced by commit 554b841d4703 ("tpm: Disable RNG for all AMD fTPMs") doesn't work properly on a number of Intel fTPMs. On the reported systems the TPM doesn't reply at bootup and returns back the command code. This makes the TPM fail probe.

Since only Microsoft Pluton is the only known combination of AMD CPU and fTPM from other vendor, disable hwrng otherwise. In order to make sysadmin aware of this, print also info message to the klog.

Quoted 8 lines
Fixes 554b841d4703 ("tpm: Disable RNG for all AMD fTPMs")

---
v2:
* CONFIG_X86

Did you mean to wrap the crb_acpi_add chunk with CONFIG_X86?

Quoted 58 lines

* Removed "Reviewed-by: Jarkko Sakkinen <[email protected]>"
* Removed "Signed-off-by: Mario Limonciello <[email protected]>"

---
 drivers/char/tpm/tpm_crb.c | 31 ++++++-------------------------
 1 file changed, 6 insertions(+), 25 deletions(-)
drivers/char/tpm/tpm_crb.c +6 -25
index 65ff4d2fbe8d..28448bfd4062 100644
@@ -463,28 +463,6 @@ static bool crb_req_canceled(struct tpm_chip *chip, u8 status)
 	return (cancel & CRB_CANCEL_INVOKE) == CRB_CANCEL_INVOKE;
 }
 
-static int crb_check_flags(struct tpm_chip *chip)
-{
-	u32 val;
-	int ret;
-
-	ret = crb_request_locality(chip, 0);
-	if (ret)
-		return ret;
-
-	ret = tpm2_get_tpm_pt(chip, TPM2_PT_MANUFACTURER, &val, NULL);
-	if (ret)
-		goto release;
-
-	if (val == 0x414D4400U /* AMD */)
-		chip->flags |= TPM_CHIP_FLAG_HWRNG_DISABLED;
-
-release:
-	crb_relinquish_locality(chip, 0);
-
-	return ret;
-}
-
 static const struct tpm_class_ops tpm_crb = {
 	.flags = TPM_OPS_AUTO_STARTUP,
 	.status = crb_status,
@@ -827,9 +805,12 @@ static int crb_acpi_add(struct acpi_device *device)
 	if (rc)
 		goto out;
 
-	rc = crb_check_flags(chip);
-	if (rc)
-		goto out;
+	/* A quirk for https://www.amd.com/en/support/kb/faq/pa-410 */
+	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+	    priv->sm != ACPI_TPM2_COMMAND_BUFFER_WITH_PLUTON) {
+		dev_info(dev, "Disabling hwrng\n");
+		chip->flags |= TPM_CHIP_FLAG_HWRNG_DISABLED;
+	}
 
 	rc = tpm_chip_register(chip);
 
Signature · 1 line
2.39.2
author maintainer
#2 lore raw
Quoted 19 lines · Jerry Snitselaar
Quoted 9 lines · Jarkko Sakkinen

The vendor check introduced by commit 554b841d4703 ("tpm: Disable RNG for all AMD fTPMs") doesn't work properly on a number of Intel fTPMs. On the reported systems the TPM doesn't reply at bootup and returns back the command code. This makes the TPM fail probe.

Since only Microsoft Pluton is the only known combination of AMD CPU and fTPM from other vendor, disable hwrng otherwise. In order to make sysadmin aware of this, print also info message to the klog.

Quoted 8 lines
Fixes 554b841d4703 ("tpm: Disable RNG for all AMD fTPMs")

---
v2:
* CONFIG_X86

Quoted 1 line

Did you mean to wrap the crb_acpi_add chunk with CONFIG_X86?

Yup :-/

$ git diff
drivers/char/tpm/tpm_crb.c +2 -0
index 28448bfd4062..ea085b14ab7c 100644
@@ -805,12 +805,14 @@ static int crb_acpi_add(struct acpi_device *device)
        if (rc)
                goto out;
 
+#ifdef CONFIG_X86
        /* A quirk for https://www.amd.com/en/support/kb/faq/pa-410 */
        if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
            priv->sm != ACPI_TPM2_COMMAND_BUFFER_WITH_PLUTON) {
                dev_info(dev, "Disabling hwrng\n");
                chip->flags |= TPM_CHIP_FLAG_HWRNG_DISABLED;
        }
+#endif /* CONFIG_X86 */
 
        rc = tpm_chip_register(chip);
 

[also linux-sgx leaked by mistake to my git-send-email command line]

I sent a new one:
https://lkml.org/lkml/2023/8/22/1288

BR, Jarkko