]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
tpm: Lazily flush auth session when getting random data
authorJonathan McDowell <noodles@meta.com>
Fri, 7 Mar 2025 10:58:13 +0000 (10:58 +0000)
committerJarkko Sakkinen <jarkko@kernel.org>
Thu, 27 Mar 2025 13:34:04 +0000 (15:34 +0200)
Lazy flushing of TPM auth sessions was introduced to speed up IMA
measurments into the TPM. Make use of it in tpm2_get_random as well,
which has the added benefit of not needlessly cleaning up the session
that IMA is using when there are no userspace accesses taking place.

Command trace before for every call:

hwrng (0x00000161): 14 (52965242 ns)
hwrng (0x00000176): 48 (161612432 ns)
hwrng (0x00000165): 10 (2410494 ns)
hwrng (0x0000017B): 117 (70699883 ns)
hwrng (0x0000017B): 117 (70959666 ns)
hwrng (0x00000165): 10 (2756827 ns)

After, with repeated calls showing no setup:

hwrng (0x00000161): 14 (53044582 ns)
hwrng (0x00000176): 48 (160491333 ns)
hwrng (0x00000165): 10 (2408220 ns)
hwrng (0x0000017B): 117 (70695037 ns)
hwrng (0x0000017B): 117 (70994984 ns)
hwrng (0x0000017B): 117 (70195388 ns)
hwrng (0x0000017B): 117 (70973835 ns)

Signed-off-by: Jonathan McDowell <noodles@meta.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
drivers/char/tpm/tpm2-cmd.c

index dfdcbd009720607cc1fb8acd3ee6ba5edf695cae..524d802ede26d6e5160a0f34d474a47c09c441e1 100644 (file)
@@ -359,7 +359,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
        } while (retries-- && total < max);
 
        tpm_buf_destroy(&buf);
-       tpm2_end_auth_session(chip);
 
        return total ? total : -EIO;
 out: