tpm_tis: Check for an error after exhausting send retires
Subsystems (2)
PATCH 1/1 tpm_tis: Check for an error after exhausting send retires
From: Jordan Hand <[email protected]>
tpm_tis_send_main() will attempt to retry sending data TPM_RETRY times. Currently, if those retries are exhausted, the driver will attempt to call execute. The TPM will be in the wrong state, leading to the operation simply timing out.
Instead, if there is still an error after retries are exhausted, return that error immediately.
Additionally, add logging to more easily determine reason for transmit failure.
--- drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +10 -1
@@ -471,6 +471,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) status =tpm_tis_status (chip);if (!itpm && (status &TPM_STS_DATA_EXPECT ) ==0 ) { rc = -EIO ; +dev_err (&chip->dev,"TPM_STS_DATA_EXPECT should be set. sts = 0x%08x\n" , + status); goto out_err; } }
@@ -491,6 +493,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) status =tpm_tis_status (chip);if (!itpm && (status &TPM_STS_DATA_EXPECT ) !=0 ) { rc = -EIO ; +dev_err (&chip->dev,"TPM_STS_DATA_EXPECT should be unset. sts = 0x%08x\n" , + status); goto out_err; }
@@ -552,11 +556,16 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)break ; else if (rc != -EAGAIN && rc != -EIO)/* Data transfer failed, not recoverable */ -return rc; + goto out_err;usleep_range (priv->timeout_min, priv->timeout_max); } +if (rc == -EAGAIN || rc == -EIO ) { +dev_err (&chip->dev,"Exhausted tpm_tis_send_data retries\n" ); + goto out_err; + } +/* go and do it */ rc =tpm_tis_write8 (priv,TPM_STS (priv->locality),TPM_STS_GO );if (rc <0 )
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Dear Jacqueline,
Thank you for your patch.
Am 10.04.26 um 23:13 schrieb Jacqueline Wong:
Quoted 7 lines
From: Jordan Hand <[email protected]>
tpm_tis_send_main()will attempt to retry sending dataTPM_RETRYtimes. Currently, if those retries are exhausted, the driver will attempt to call execute. The TPM will be in the wrong state, leading to the operation simply timing out.
Quoted 5 lines
Instead, if there is still an error after retries are exhausted, return that error immediately.
Additionally, add logging to more easily determine reason for transmit failure.
Please paste the logs without and with your patch of an effected system.
*Additionally* is often a good indicator to split the patch into even smaller pieces. ;-)
Quoted 30 lines
Fixes 280db21e153d8 ("tpm_tis: Resend command to recover from data transfer errors")Signed-off-by Jordan Hand <[email protected]>--- drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/char/tpm/tpm_tis_core.c +4
-0@@ -471,6 +471,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) status =tpm_tis_status (chip);if (!itpm && (status &TPM_STS_DATA_EXPECT ) ==0 ) { rc = -EIO ; +dev_err (&chip->dev,"TPM_STS_DATA_EXPECT should be set. sts = 0x%08x\n" , + status); goto out_err; } }@@ -491,6 +493,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) status =tpm_tis_status (chip);if (!itpm && (status &TPM_STS_DATA_EXPECT ) !=0 ) { rc = -EIO ; +dev_err (&chip->dev,"TPM_STS_DATA_EXPECT should be unset. sts = 0x%08x\n" , + status); goto out_err; }@@ -552,11 +556,16 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)break ;
drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) · line 565
Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +3
-1else if (rc != -EAGAIN && rc != -EIO )/* Data transfer failed, not recoverable */ -return rc; + goto out_err;usleep_range (priv->timeout_min, priv->timeout_max); } +if (rc == -EAGAIN || rc == -EIO ) { +dev_err (&chip->dev,"Exhausted tpm_tis_send_data retries\n" );
Please also print the number of retries.
drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) · line 571
Quoted 6 lines
drivers/char/tpm/tpm_tis_core.c +3
-0+ goto out_err; + } +/* go and do it */ rc =tpm_tis_write8 (priv,TPM_STS (priv->locality),TPM_STS_GO );if (rc <0 )
Kind regards,
Paul
Quoted 62 lines · Jacqueline Wong
From: Jordan Hand <[email protected]>
tpm_tis_send_main()will attempt to retry sending dataTPM_RETRYtimes. Currently, if those retries are exhausted, the driver will attempt to call execute. The TPM will be in the wrong state, leading to the operation simply timing out.Instead, if there is still an error after retries are exhausted, return that error immediately.
Additionally, add logging to more easily determine reason for transmit failure.
Fixes 280db21e153d8 ("tpm_tis: Resend command to recover from data transfer errors")Signed-off-by Jordan Hand <[email protected]>--- drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/char/tpm/tpm_tis_core.c +10
-1@@ -471,6 +471,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) status =tpm_tis_status (chip);if (!itpm && (status &TPM_STS_DATA_EXPECT ) ==0 ) { rc = -EIO ; +dev_err (&chip->dev,"TPM_STS_DATA_EXPECT should be set. sts = 0x%08x\n" , + status); goto out_err; } }@@ -491,6 +493,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) status =tpm_tis_status (chip);if (!itpm && (status &TPM_STS_DATA_EXPECT ) !=0 ) { rc = -EIO ; +dev_err (&chip->dev,"TPM_STS_DATA_EXPECT should be unset. sts = 0x%08x\n" , + status); goto out_err; }@@ -552,11 +556,16 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)break ; else if (rc != -EAGAIN && rc != -EIO)/* Data transfer failed, not recoverable */ -return rc; + goto out_err;usleep_range (priv->timeout_min, priv->timeout_max); } +if (rc == -EAGAIN || rc == -EIO ) { +dev_err (&chip->dev,"Exhausted tpm_tis_send_data retries\n" ); + goto out_err; + } +/* go and do it */ rc =tpm_tis_write8 (priv,TPM_STS (priv->locality),TPM_STS_GO );if (rc <0 )Signature · 1 line
2.53.0.1213.gd9a14994de-goog
CHECK: Alignment should match open parenthesis
#35: FILE: drivers/char/tpm/tpm_tis_core.c:475:
+ dev_err(&chip->dev, "TPM_STS_DATA_EXPECT should be set. sts = 0x%08x\n",
+ status);
CHECK: Alignment should match open parenthesis
#44: FILE: drivers/char/tpm/tpm_tis_core.c:497:
+ dev_err(&chip->dev, "TPM_STS_DATA_EXPECT should be unset. sts = 0x%08x\n",
+ status);
I fixed these manually.
Good catch, thanks:
Applied.
BR, Jarkko