aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander.Steffen@infineon.com <Alexander.Steffen@infineon.com>2017-12-11 11:05:25 -0500
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>2018-01-08 05:58:37 -0500
commit0b66f2a05a8095f8b1dd30a156b971bf893cd1a9 (patch)
tree5fae750a137b6c66a616eea4f65a6847938535ec
parent095531f891e627e408606f2da4008d3d53e6748a (diff)
tpm2-cmd: allow more attempts for selftest execution
Previously, if the last attempt to execute the selftest command failed with RC_TESTING, there was still a call to tpm_msleep, even though no further attempt would be made. This causes an unnecessary delay, therefore ensure that if the last attempt fails the function is left immediately. Also, instead of ensuring that the cumulated runtime of all attempts is larger than the command duration for TPM2_SelfTest, ensure that there is at least one attempt for which the delay is larger than the expected command duration. This allows slow TPMs to execute all their tests in the background, without slowing down faster TPMs that have finished their tests earlier. If tests are still not finished even with this long delay, then something is broken and the TPM is not used. Fixes: 125a22105410 ("tpm: React correctly to RC_TESTING from TPM 2.0 self tests") Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
-rw-r--r--drivers/char/tpm/tpm2-cmd.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index f40d20671a78..c17e75348a99 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -849,28 +849,26 @@ static const struct tpm_input_header tpm2_selftest_header = {
849static int tpm2_do_selftest(struct tpm_chip *chip) 849static int tpm2_do_selftest(struct tpm_chip *chip)
850{ 850{
851 int rc; 851 int rc;
852 unsigned int delay_msec = 20; 852 unsigned int delay_msec = 10;
853 long duration; 853 long duration;
854 struct tpm2_cmd cmd; 854 struct tpm2_cmd cmd;
855 855
856 duration = jiffies_to_msecs( 856 duration = jiffies_to_msecs(
857 tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST)); 857 tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST));
858 858
859 while (duration > 0) { 859 while (1) {
860 cmd.header.in = tpm2_selftest_header; 860 cmd.header.in = tpm2_selftest_header;
861 cmd.params.selftest_in.full_test = 0; 861 cmd.params.selftest_in.full_test = 0;
862 862
863 rc = tpm_transmit_cmd(chip, NULL, &cmd, TPM2_SELF_TEST_IN_SIZE, 863 rc = tpm_transmit_cmd(chip, NULL, &cmd, TPM2_SELF_TEST_IN_SIZE,
864 0, 0, "continue selftest"); 864 0, 0, "continue selftest");
865 865
866 if (rc != TPM2_RC_TESTING) 866 if (rc != TPM2_RC_TESTING || delay_msec >= duration)
867 break; 867 break;
868 868
869 tpm_msleep(delay_msec); 869 /* wait longer than before */
870 duration -= delay_msec;
871
872 /* wait longer the next round */
873 delay_msec *= 2; 870 delay_msec *= 2;
871 tpm_msleep(delay_msec);
874 } 872 }
875 873
876 return rc; 874 return rc;