Skip to contentSkip to conversation

tpm: provide a way to override the chip returned durations

PATCH In review Alexey Klimov 3 participants 8 messages Dec 14, 2018 – Jan 21, 2019

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

PATCH 1/2 tpm: provide a way to override the chip returned durations

Patch adds method ->update_durations to override returned durations in case TPM chip misbehaves for TPM 1.2 drivers.

Cc Jerry Snitselaar <[email protected]>
---
 drivers/char/tpm/tpm-interface.c | 18 ++++++++++++++++++
 include/linux/tpm.h              |  2 ++
 2 files changed, 20 insertions(+)
drivers/char/tpm/tpm-interface.c +18 -0
index 129f640424b7..5cb90918938d 100644
@@ -768,6 +768,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 {
 	cap_t cap;
 	unsigned long timeout_old[4], timeout_chip[4], timeout_eff[4];
+	unsigned long durations[3];
 	ssize_t rc;
 
 	if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS)
@@ -877,6 +878,23 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 		usecs_to_jiffies(be32_to_cpu(cap.duration.tpm_long));
 	chip->duration[TPM_LONG_LONG] = 0; /* not used under 1.2 */
 
+	/*
+	 * Provide ability for vendor overrides of duration values in case
+	 * of misreporting.
+	 */
+	if (chip->ops->update_durations != NULL)
+		chip->duration_adjusted =
+			chip->ops->update_durations(chip, durations);
+
+	/* Report and set adjusted timeouts */
+	if (chip->duration_adjusted) {
+
+		dev_info(&chip->dev, HW_ERR "Adjusting reported durations\n");
+		chip->duration[TPM_SHORT] = durations[0];
+		chip->duration[TPM_MEDIUM] = durations[1];
+		chip->duration[TPM_LONG] = durations[2];
+	}
+
 	/* The Broadcom BCM0102 chipset in a Dell Latitude D820 gets the above
 	 * value wrong and apparently reports msecs rather than usecs. So we
 	 * fix up the resulting too-small TPM_SHORT value to make things work.
include/linux/tpm.h +2 -0
index 4609b94142d4..d6018431b478 100644
@@ -43,6 +43,8 @@ struct tpm_class_ops {
 	u8 (*status) (struct tpm_chip *chip);
 	bool (*update_timeouts)(struct tpm_chip *chip,
 				unsigned long *timeout_cap);
+	bool (*update_durations)(struct tpm_chip *chip,
+				unsigned long *durations_cap);
 	int (*go_idle)(struct tpm_chip *chip);
 	int (*cmd_ready)(struct tpm_chip *chip);
 	int (*request_locality)(struct tpm_chip *chip, int loc);
Signature · 1 line
2.14.4
#1 lore raw

PATCH 2/2 tpm_tis: override durations for STM tpm with firmware 1.2.8.28

There was revealed a bug in the STM TPM chipset used in Dell R415s. Bug is observed so far only on chipset firmware 1.2.8.28 (1.2 TPM, device-id 0x0, rev-id 78). After some number of operations chipset hangs and stays in inconsistent state:

tpm_tis 00:09: Operation Timed out
tpm_tis 00:09: tpm_transmit: tpm_send: error -5

Durations returned by the chip are the same like on other firmware revisions but apparently with specifically 1.2.8.28 fw durations should be reset to 2 minutes to enable tpm chip work properly. No working way of updating firmware was found.

This patch adds implementation of ->update_durations method that matches only STM devices with specific firmware version.

Cc Jerry Snitselaar <[email protected]>
---
 drivers/char/tpm/tpm_tis_core.c | 90 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
drivers/char/tpm/tpm_tis_core.c +90 -0
index d2345d9fd7b5..e0bdca647460 100644
@@ -514,6 +514,95 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	return rc;
 }
 
+struct tis_vendor_durations_override {
+	u32 did_vid;
+	struct tpm_version_t tpm_version;
+	unsigned long durs[3];
+};
+
+static
+const struct tis_vendor_durations_override vendor_dur_overrides[] = {
+	/* STMicroelectronics 0x104a */
+	{ 0x0000104A,
+	{ 1, 2, 8, 28 },
+	{ (2 * 60 * HZ), (2 * 60 * HZ), (2 * 60 * HZ) } },
+};
+
+static bool tpm_tis_update_durations(struct tpm_chip *chip,
+					unsigned long *duration_cap)
+{
+	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
+	u32 did_vid;
+	int i, rc;
+	cap_t cap;
+
+	if (chip->ops->clk_enable != NULL)
+		chip->ops->clk_enable(chip, true);
+
+	rc = tpm_tis_read32(priv, TPM_DID_VID(0), &did_vid);
+	if (rc < 0)
+		goto out;
+
+	for (i = 0; i != ARRAY_SIZE(vendor_dur_overrides); i++) {
+		if (vendor_dur_overrides[i].did_vid != did_vid)
+			continue;
+
+		/* Try to get a TPM version 1.2 TPM_CAP_VERSION_INFO */
+		rc = tpm_getcap(chip, TPM_CAP_VERSION_1_2, &cap,
+			"attempting to determine the 1.2 version",
+			sizeof(cap.tpm_version_1_2));
+		if (!rc) {
+			if ((cap.tpm_version_1_2.Major ==
+				vendor_dur_overrides[i].tpm_version.Major) &&
+				(cap.tpm_version_1_2.Minor ==
+				vendor_dur_overrides[i].tpm_version.Minor) &&
+				(cap.tpm_version_1_2.revMajor ==
+				vendor_dur_overrides[i].tpm_version.revMajor) &&
+				(cap.tpm_version_1_2.revMinor ==
+				vendor_dur_overrides[i].tpm_version.revMinor)) {
+
+				memcpy(duration_cap,
+					vendor_dur_overrides[i].durs,
+					sizeof(vendor_dur_overrides[i].durs));
+				rc = true;
+				goto out;
+			}
+		} else {
+			rc = tpm_getcap(chip, TPM_CAP_VERSION_1_1, &cap,
+				"attempting to determine the 1.1 version",
+				sizeof(cap.tpm_version));
+			if (rc) {
+				rc = false;
+				goto out;
+			}
+			if ((cap.tpm_version.Major ==
+				vendor_dur_overrides[i].tpm_version.Major) &&
+				(cap.tpm_version.Minor ==
+				vendor_dur_overrides[i].tpm_version.Minor) &&
+				(cap.tpm_version.revMajor ==
+				vendor_dur_overrides[i].tpm_version.revMajor) &&
+				(cap.tpm_version.revMinor ==
+				vendor_dur_overrides[i].tpm_version.revMinor)) {
+
+				memcpy(duration_cap,
+					vendor_dur_overrides[i].durs,
+					sizeof(vendor_dur_overrides[i].durs));
+				rc = true;
+				goto out;
+			}
+		}
+	}
+
+	rc = false;
+
+out:
+	if (chip->ops->clk_enable != NULL)
+		chip->ops->clk_enable(chip, false);
+
+	return rc;
+}
+
+
 struct tis_vendor_timeout_override {
 	u32 did_vid;
 	unsigned long timeout_us[4];
@@ -847,6 +936,7 @@ static const struct tpm_class_ops tpm_tis = {
 	.send = tpm_tis_send,
 	.cancel = tpm_tis_ready,
 	.update_timeouts = tpm_tis_update_timeouts,
+	.update_durations = tpm_tis_update_durations,
 	.req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
 	.req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
 	.req_canceled = tpm_tis_req_canceled,
Signature · 1 line
2.14.4
#2 lore raw

Re: [PATCH REVIEW 2/2] tpm_tis: override durations for STM tpm with firmware 1.2.8.28

Quoted 27 lines · Alexey Klimov

There was revealed a bug in the STM TPM chipset used in Dell R415s. Bug is observed so far only on chipset firmware 1.2.8.28 (1.2 TPM, device-id 0x0, rev-id 78). After some number of operations chipset hangs and stays in inconsistent state:

tpm_tis 00:09: Operation Timed out
tpm_tis 00:09: tpm_transmit: tpm_send: error -5

Durations returned by the chip are the same like on other firmware revisions but apparently with specifically 1.2.8.28 fw durations should be reset to 2 minutes to enable tpm chip work properly. No working way of updating firmware was found.

This patch adds implementation of ->update_durations method that matches only STM devices with specific firmware version.

Cc Jerry Snitselaar <[email protected]>
---
 drivers/char/tpm/tpm_tis_core.c | 90 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
drivers/char/tpm/tpm_tis_core.c +0 -0
index d2345d9fd7b5..e0bdca647460 100644

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 520

Quoted 7 lines
drivers/char/tpm/tpm_tis_core.c +4 -0
@@ -514,6 +514,95 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	return rc;
 }
 
+struct tis_vendor_durations_override {
+	u32 did_vid;
+	struct tpm_version_t tpm_version;
+	unsigned long durs[3];

I would rather have just "unsigned long durations[3];".

Quoted 23 lines
drivers/char/tpm/tpm_tis_core.c +23 -0
+};
+
+static
+const struct tis_vendor_durations_override vendor_dur_overrides[] = {
+	/* STMicroelectronics 0x104a */
+	{ 0x0000104A,
+	{ 1, 2, 8, 28 },
+	{ (2 * 60 * HZ), (2 * 60 * HZ), (2 * 60 * HZ) } },
+};
+
+static bool tpm_tis_update_durations(struct tpm_chip *chip,
+					unsigned long *duration_cap)
+{
+	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
+	u32 did_vid;
+	int i, rc;
+	cap_t cap;
+
+	if (chip->ops->clk_enable != NULL)
+		chip->ops->clk_enable(chip, true);
+
+	rc = tpm_tis_read32(priv, TPM_DID_VID(0), &did_vid);
+	if (rc < 0)

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 553

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +10 -0
+		goto out;
+
+	for (i = 0; i != ARRAY_SIZE(vendor_dur_overrides); i++) {
+		if (vendor_dur_overrides[i].did_vid != did_vid)
+			continue;
+
+		/* Try to get a TPM version 1.2 TPM_CAP_VERSION_INFO */
+		rc = tpm_getcap(chip, TPM_CAP_VERSION_1_2, &cap,
+			"attempting to determine the 1.2 version",
+			sizeof(cap.tpm_version_1_2));

Not properly aligned.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 562

Quoted 9 lines
drivers/char/tpm/tpm_tis_core.c +9 -0
+		if (!rc) {
+			if ((cap.tpm_version_1_2.Major ==
+				vendor_dur_overrides[i].tpm_version.Major) &&
+				(cap.tpm_version_1_2.Minor ==
+				vendor_dur_overrides[i].tpm_version.Minor) &&
+				(cap.tpm_version_1_2.revMajor ==
+				vendor_dur_overrides[i].tpm_version.revMajor) &&
+				(cap.tpm_version_1_2.revMinor ==
+				vendor_dur_overrides[i].tpm_version.revMinor)) {

Same.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 566

Quoted 4 lines
drivers/char/tpm/tpm_tis_core.c +4 -0
+
+				memcpy(duration_cap,
+					vendor_dur_overrides[i].durs,
+					sizeof(vendor_dur_overrides[i].durs));

Same.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 573

Quoted 7 lines
drivers/char/tpm/tpm_tis_core.c +7 -0
+				rc = true;
+				goto out;
+			}
+		} else {
+			rc = tpm_getcap(chip, TPM_CAP_VERSION_1_1, &cap,
+				"attempting to determine the 1.1 version",
+				sizeof(cap.tpm_version));

Same.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 585

Quoted 12 lines
drivers/char/tpm/tpm_tis_core.c +12 -0
+			if (rc) {
+				rc = false;
+				goto out;
+			}
+			if ((cap.tpm_version.Major ==
+				vendor_dur_overrides[i].tpm_version.Major) &&
+				(cap.tpm_version.Minor ==
+				vendor_dur_overrides[i].tpm_version.Minor) &&
+				(cap.tpm_version.revMajor ==
+				vendor_dur_overrides[i].tpm_version.revMajor) &&
+				(cap.tpm_version.revMinor ==
+				vendor_dur_overrides[i].tpm_version.revMinor)) {

Same.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 566

Quoted 4 lines
drivers/char/tpm/tpm_tis_core.c +4 -0
+
+				memcpy(duration_cap,
+					vendor_dur_overrides[i].durs,
+					sizeof(vendor_dur_overrides[i].durs));

Same.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 596

Quoted 7 lines
drivers/char/tpm/tpm_tis_core.c +7 -0
+				rc = true;
+				goto out;
+			}
+		}
+	}
+
+	rc = false;

Shoud return proper rc instead of bool.

Quoted 23 lines
drivers/char/tpm/tpm_tis_core.c +10 -0
+
+out:
+	if (chip->ops->clk_enable != NULL)
+		chip->ops->clk_enable(chip, false);
+
+	return rc;
+}
+
+
 struct tis_vendor_timeout_override {
 	u32 did_vid;
 	unsigned long timeout_us[4];
@@ -847,6 +936,7 @@ static const struct tpm_class_ops tpm_tis = {
 	.send = tpm_tis_send,
 	.cancel = tpm_tis_ready,
 	.update_timeouts = tpm_tis_update_timeouts,
+	.update_durations = tpm_tis_update_durations,
 	.req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
 	.req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
 	.req_canceled = tpm_tis_req_canceled,
Signature · 1 line
2.14.4

/Jarkko

#3 lore raw

Re: [PATCH REVIEW 2/2] tpm_tis: override durations for STM tpm with firmware 1.2.8.28

Quoted 125 lines · Jarkko Sakkinen
Quoted 27 lines · Alexey Klimov

There was revealed a bug in the STM TPM chipset used in Dell R415s. Bug is observed so far only on chipset firmware 1.2.8.28 (1.2 TPM, device-id 0x0, rev-id 78). After some number of operations chipset hangs and stays in inconsistent state:

tpm_tis 00:09: Operation Timed out
tpm_tis 00:09: tpm_transmit: tpm_send: error -5

Durations returned by the chip are the same like on other firmware revisions but apparently with specifically 1.2.8.28 fw durations should be reset to 2 minutes to enable tpm chip work properly. No working way of updating firmware was found.

This patch adds implementation of ->update_durations method that matches only STM devices with specific firmware version.

Cc Jerry Snitselaar <[email protected]>
---
 drivers/char/tpm/tpm_tis_core.c | 90 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
drivers/char/tpm/tpm_tis_core.c +0 -0
index d2345d9fd7b5..e0bdca647460 100644

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 520

Quoted 7 lines
drivers/char/tpm/tpm_tis_core.c +4 -0
@@ -514,6 +514,95 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	return rc;
 }
 
+struct tis_vendor_durations_override {
+	u32 did_vid;
+	struct tpm_version_t tpm_version;
+	unsigned long durs[3];

I would rather have just "unsigned long durations[3];".

Quoted 23 lines
drivers/char/tpm/tpm_tis_core.c +23 -0
+};
+
+static
+const struct tis_vendor_durations_override vendor_dur_overrides[] = {
+	/* STMicroelectronics 0x104a */
+	{ 0x0000104A,
+	{ 1, 2, 8, 28 },
+	{ (2 * 60 * HZ), (2 * 60 * HZ), (2 * 60 * HZ) } },
+};
+
+static bool tpm_tis_update_durations(struct tpm_chip *chip,
+					unsigned long *duration_cap)
+{
+	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
+	u32 did_vid;
+	int i, rc;
+	cap_t cap;
+
+	if (chip->ops->clk_enable != NULL)
+		chip->ops->clk_enable(chip, true);
+
+	rc = tpm_tis_read32(priv, TPM_DID_VID(0), &did_vid);
+	if (rc < 0)

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 553

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +10 -0
+		goto out;
+
+	for (i = 0; i != ARRAY_SIZE(vendor_dur_overrides); i++) {
+		if (vendor_dur_overrides[i].did_vid != did_vid)
+			continue;
+
+		/* Try to get a TPM version 1.2 TPM_CAP_VERSION_INFO */
+		rc = tpm_getcap(chip, TPM_CAP_VERSION_1_2, &cap,
+			"attempting to determine the 1.2 version",
+			sizeof(cap.tpm_version_1_2));

Not properly aligned.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 562

Quoted 9 lines
drivers/char/tpm/tpm_tis_core.c +9 -0
+		if (!rc) {
+			if ((cap.tpm_version_1_2.Major ==
+				vendor_dur_overrides[i].tpm_version.Major) &&
+				(cap.tpm_version_1_2.Minor ==
+				vendor_dur_overrides[i].tpm_version.Minor) &&
+				(cap.tpm_version_1_2.revMajor ==
+				vendor_dur_overrides[i].tpm_version.revMajor) &&
+				(cap.tpm_version_1_2.revMinor ==
+				vendor_dur_overrides[i].tpm_version.revMinor)) {

Same.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 566

Quoted 4 lines
drivers/char/tpm/tpm_tis_core.c +4 -0
+
+				memcpy(duration_cap,
+					vendor_dur_overrides[i].durs,
+					sizeof(vendor_dur_overrides[i].durs));

Same.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 573

Quoted 7 lines
drivers/char/tpm/tpm_tis_core.c +7 -0
+				rc = true;
+				goto out;
+			}
+		} else {
+			rc = tpm_getcap(chip, TPM_CAP_VERSION_1_1, &cap,
+				"attempting to determine the 1.1 version",
+				sizeof(cap.tpm_version));

Same.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 585

Quoted 12 lines
drivers/char/tpm/tpm_tis_core.c +12 -0
+			if (rc) {
+				rc = false;
+				goto out;
+			}
+			if ((cap.tpm_version.Major ==
+				vendor_dur_overrides[i].tpm_version.Major) &&
+				(cap.tpm_version.Minor ==
+				vendor_dur_overrides[i].tpm_version.Minor) &&
+				(cap.tpm_version.revMajor ==
+				vendor_dur_overrides[i].tpm_version.revMajor) &&
+				(cap.tpm_version.revMinor ==
+				vendor_dur_overrides[i].tpm_version.revMinor)) {

Same.

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 566

Quoted 4 lines
drivers/char/tpm/tpm_tis_core.c +4 -0
+
+				memcpy(duration_cap,
+					vendor_dur_overrides[i].durs,
+					sizeof(vendor_dur_overrides[i].durs));

Same.

Quoted 10 lines

drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 596

Quoted 7 lines
drivers/char/tpm/tpm_tis_core.c +7 -0
+				rc = true;
+				goto out;
+			}
+		}
+	}
+
+	rc = false;

Shoud return proper rc instead of bool.

Alexey was following the example of tpm_tis_update_timeouts() which returns true if the timeouts were updated, and otherwise returns false. The bool here makes sense to me, but what rc would you suggest in this case?

Regards,
Jerry

Quoted 25 lines
Quoted 21 lines
drivers/char/tpm/tpm_tis_core.c +10 -1
+
+out:
+	if (chip->ops->clk_enable != NULL)
+		chip->ops->clk_enable(chip, false);
+
+	return rc;
+}
+
+
 struct tis_vendor_timeout_override {
 	u32 did_vid;
 	unsigned long timeout_us[4];
@@ -847,6 +936,7 @@ static const struct tpm_class_ops tpm_tis = {
 	.send = tpm_tis_send,
 	.cancel = tpm_tis_ready,
 	.update_timeouts = tpm_tis_update_timeouts,
+	.update_durations = tpm_tis_update_durations,
 	.req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
 	.req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
 	.req_canceled = tpm_tis_req_canceled,
--
Quoted 2 lines

2.14.4

/Jarkko

#4 lore raw

Re: [PATCH REVIEW 2/2] tpm_tis: override durations for STM tpm with firmware 1.2.8.28

Quoted 4 lines · Jerry Snitselaar

Alexey was following the example of tpm_tis_update_timeouts() which returns true if the timeouts were updated, and otherwise returns false. The bool here makes sense to me, but what rc would you suggest in this case?

Maybe the pattern used there is not that great then.

The callback should simply be update_durations(chip), and it would do whatever updates needed and either return zero or -errno. And of course update durations_adjusted flag because that is needed in sysfs.

/Jarkko

#5 lore raw

Re: [PATCH REVIEW 2/2] tpm_tis: override durations for STM tpm with firmware 1.2.8.28

Quoted 6 lines · Jarkko Sakkinen
Quoted 4 lines · Jerry Snitselaar

Alexey was following the example of tpm_tis_update_timeouts() which returns true if the timeouts were updated, and otherwise returns false. The bool here makes sense to me, but what rc would you suggest in this case?

Quoted 7 lines

Maybe the pattern used there is not that great then.

The callback should simply be update_durations(chip), and it would do whatever updates needed and either return zero or -errno. And of course update durations_adjusted flag because that is needed in sysfs.

/Jarkko

Taking a quick look, they already track whether the adjustment occurred in the tpm_chip struct, so that could be used instead for what the bool return was being used for. I'll post a patch for the timeout updates code, and work with Alexey to rework his patchset.

Regards,
Jerry

#6 lore raw

Re: [PATCH REVIEW 2/2] tpm_tis: override durations for STM tpm with firmware 1.2.8.28

Quoted 13 lines · Jerry Snitselaar
Quoted 12 lines · Jarkko Sakkinen
Quoted 4 lines · Jerry Snitselaar

Alexey was following the example of tpm_tis_update_timeouts() which returns true if the timeouts were updated, and otherwise returns false. The bool here makes sense to me, but what rc would you suggest in this case?

Maybe the pattern used there is not that great then.

The callback should simply be update_durations(chip), and it would do whatever updates needed and either return zero or -errno. And of course update durations_adjusted flag because that is needed in sysfs.

Quoted 6 lines
Quoted 1 line

/Jarkko

Taking a quick look, they already track whether the adjustment occurred in the tpm_chip struct, so that could be used instead for what the bool return was being used for. I'll post a patch for the timeout updates code, and work with Alexey to rework his patchset.

Awesome, thank you!

/Jarkko

#7 lore raw
In reply to Alexey Klimov
Quoted 27 lines · Alexey Klimov

Patch adds method ->update_durations to override returned durations in case TPM chip misbehaves for TPM 1.2 drivers.

Cc Jerry Snitselaar <[email protected]>
---
 drivers/char/tpm/tpm-interface.c | 18 ++++++++++++++++++
 include/linux/tpm.h              |  2 ++
 2 files changed, 20 insertions(+)
drivers/char/tpm/tpm-interface.c +2 -0
index 129f640424b7..5cb90918938d 100644
@@ -768,6 +768,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 {
 	cap_t cap;
 	unsigned long timeout_old[4], timeout_chip[4], timeout_eff[4];
+	unsigned long durations[3];
 	ssize_t rc;
 
 	if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS)
@@ -877,6 +878,23 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 		usecs_to_jiffies(be32_to_cpu(cap.duration.tpm_long));
 	chip->duration[TPM_LONG_LONG] = 0; /* not used under 1.2 */
 
+	/*

drivers/char/tpm/tpm-interface.c int tpm_get_timeouts(struct tpm_chip *chip) · line 891

Quoted 10 lines
drivers/char/tpm/tpm-interface.c +10 -0
+	 * Provide ability for vendor overrides of duration values in case
+	 * of misreporting.
+	 */
+	if (chip->ops->update_durations != NULL)
+		chip->duration_adjusted =
+			chip->ops->update_durations(chip, durations);
+
+	/* Report and set adjusted timeouts */
+	if (chip->duration_adjusted) {
+

Can you remove the extra newline?

Quoted 25 lines
drivers/char/tpm/tpm-interface.c +6 -0
+		dev_info(&chip->dev, HW_ERR "Adjusting reported durations\n");
+		chip->duration[TPM_SHORT] = durations[0];
+		chip->duration[TPM_MEDIUM] = durations[1];
+		chip->duration[TPM_LONG] = durations[2];
+	}
+
 	/* The Broadcom BCM0102 chipset in a Dell Latitude D820 gets the above
 	 * value wrong and apparently reports msecs rather than usecs. So we
 	 * fix up the resulting too-small TPM_SHORT value to make things work.
include/linux/tpm.h +2 -0
index 4609b94142d4..d6018431b478 100644
@@ -43,6 +43,8 @@ struct tpm_class_ops {
 	u8 (*status) (struct tpm_chip *chip);
 	bool (*update_timeouts)(struct tpm_chip *chip,
 				unsigned long *timeout_cap);
+	bool (*update_durations)(struct tpm_chip *chip,
+				unsigned long *durations_cap);
 	int (*go_idle)(struct tpm_chip *chip);
 	int (*cmd_ready)(struct tpm_chip *chip);
 	int (*request_locality)(struct tpm_chip *chip, int loc);
Signature · 1 line
2.14.4

/Jarkko