]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
tpm2-cmd: allow more attempts for selftest execution
authorAlexander.Steffen@infineon.com <Alexander.Steffen@infineon.com>
Mon, 11 Dec 2017 16:05:25 +0000 (17:05 +0100)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Mon, 8 Jan 2018 10:58:37 +0000 (12:58 +0200)
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>
drivers/char/tpm/tpm2-cmd.c

index f40d20671a78fd8469c87074f18b5e81b5d3536d..c17e75348a991e355236f2040f931e940541049f 100644 (file)
@@ -849,28 +849,26 @@ static const struct tpm_input_header tpm2_selftest_header = {
 static int tpm2_do_selftest(struct tpm_chip *chip)
 {
        int rc;
-       unsigned int delay_msec = 20;
+       unsigned int delay_msec = 10;
        long duration;
        struct tpm2_cmd cmd;
 
        duration = jiffies_to_msecs(
                tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST));
 
-       while (duration > 0) {
+       while (1) {
                cmd.header.in = tpm2_selftest_header;
                cmd.params.selftest_in.full_test = 0;
 
                rc = tpm_transmit_cmd(chip, NULL, &cmd, TPM2_SELF_TEST_IN_SIZE,
                                      0, 0, "continue selftest");
 
-               if (rc != TPM2_RC_TESTING)
+               if (rc != TPM2_RC_TESTING || delay_msec >= duration)
                        break;
 
-               tpm_msleep(delay_msec);
-               duration -= delay_msec;
-
-               /* wait longer the next round */
+               /* wait longer than before */
                delay_msec *= 2;
+               tpm_msleep(delay_msec);
        }
 
        return rc;