]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tpm: Re-enable TPM chip boostrapping non-tpm_tis TPM drivers
authorJarkko Sakkinen <jarkko@kernel.org>
Wed, 26 Apr 2023 18:49:37 +0000 (21:49 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 May 2023 13:03:16 +0000 (14:03 +0100)
[ Upstream commit 0c8862de05c1a087795ee0a87bf61a6394306cc0 ]

TPM chip bootstrapping was removed from tpm_chip_register(), and it
was relocated to tpm_tis_core. This breaks all drivers which are not
based on tpm_tis because the chip will not get properly initialized.

Take the corrective steps:
1. Rename tpm_chip_startup() as tpm_chip_bootstrap() and make it one-shot.
2. Call tpm_chip_bootstrap() in tpm_chip_register(), which reverts the
   things  as tehy used to be.

Cc: Lino Sanfilippo <l.sanfilippo@kunbus.com>
Fixes: 548eb516ec0f ("tpm, tpm_tis: startup chip before testing for interrupts")
Reported-by: Pengfei Xu <pengfei.xu@intel.com>
Link: https://lore.kernel.org/all/ZEjqhwHWBnxcaRV5@xpf.sh.intel.com/
Tested-by: Pengfei Xu <pengfei.xu@intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Stable-dep-of: 99d464506255 ("tpm: Prevent hwrng from activating during resume")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/char/tpm/tpm-chip.c
drivers/char/tpm/tpm.h
drivers/char/tpm/tpm_tis_core.c
include/linux/tpm.h

index 47c2861af45a323fdda986066de83752a233a34d..31d8074821524c28123322eaeaf4464af9c95d4a 100644 (file)
@@ -602,13 +602,19 @@ static int tpm_get_pcr_allocation(struct tpm_chip *chip)
 }
 
 /*
- * tpm_chip_startup() - performs auto startup and allocates the PCRs
+ * tpm_chip_bootstrap() - Boostrap TPM chip after power on
  * @chip: TPM chip to use.
+ *
+ * Initialize TPM chip after power on. This a one-shot function: subsequent
+ * calls will have no effect.
  */
-int tpm_chip_startup(struct tpm_chip *chip)
+int tpm_chip_bootstrap(struct tpm_chip *chip)
 {
        int rc;
 
+       if (chip->flags & TPM_CHIP_FLAG_BOOTSTRAPPED)
+               return 0;
+
        rc = tpm_chip_start(chip);
        if (rc)
                return rc;
@@ -621,9 +627,15 @@ int tpm_chip_startup(struct tpm_chip *chip)
 stop:
        tpm_chip_stop(chip);
 
+       /*
+        * Unconditionally set, as driver initialization should cease, when the
+        * boostrapping process fails.
+        */
+       chip->flags |= TPM_CHIP_FLAG_BOOTSTRAPPED;
+
        return rc;
 }
-EXPORT_SYMBOL_GPL(tpm_chip_startup);
+EXPORT_SYMBOL_GPL(tpm_chip_bootstrap);
 
 /*
  * tpm_chip_register() - create a character device for the TPM chip
@@ -640,6 +652,10 @@ int tpm_chip_register(struct tpm_chip *chip)
 {
        int rc;
 
+       rc = tpm_chip_bootstrap(chip);
+       if (rc)
+               return rc;
+
        tpm_sysfs_add_device(chip);
 
        tpm_bios_log_setup(chip);
index 88d3bd76e0760dbaabe4f038d06f5ea103835b9c..f6c99b3f004589fe784e3c1b5d22b4bf60effa68 100644 (file)
@@ -263,7 +263,7 @@ static inline void tpm_msleep(unsigned int delay_msec)
                     delay_msec * 1000);
 };
 
-int tpm_chip_startup(struct tpm_chip *chip);
+int tpm_chip_bootstrap(struct tpm_chip *chip);
 int tpm_chip_start(struct tpm_chip *chip);
 void tpm_chip_stop(struct tpm_chip *chip);
 struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
index 9f76c9a5aa42237539bffc49aea7d57bc7ba790e..f02b583005a53243f07668380c74dd3816610f3e 100644 (file)
@@ -1125,7 +1125,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
        init_waitqueue_head(&priv->read_queue);
        init_waitqueue_head(&priv->int_queue);
 
-       rc = tpm_chip_startup(chip);
+       rc = tpm_chip_bootstrap(chip);
        if (rc)
                goto out_err;
 
index dfeb25a0362deee6d00a831fcd3d2b14354e0629..cea64d58ef9f70b3fcfbc9e1c0502a346c82edb8 100644 (file)
@@ -273,13 +273,14 @@ enum tpm2_cc_attrs {
 #define TPM_VID_ATML     0x1114
 
 enum tpm_chip_flags {
-       TPM_CHIP_FLAG_TPM2              = BIT(1),
-       TPM_CHIP_FLAG_IRQ               = BIT(2),
-       TPM_CHIP_FLAG_VIRTUAL           = BIT(3),
-       TPM_CHIP_FLAG_HAVE_TIMEOUTS     = BIT(4),
-       TPM_CHIP_FLAG_ALWAYS_POWERED    = BIT(5),
+       TPM_CHIP_FLAG_BOOTSTRAPPED              = BIT(0),
+       TPM_CHIP_FLAG_TPM2                      = BIT(1),
+       TPM_CHIP_FLAG_IRQ                       = BIT(2),
+       TPM_CHIP_FLAG_VIRTUAL                   = BIT(3),
+       TPM_CHIP_FLAG_HAVE_TIMEOUTS             = BIT(4),
+       TPM_CHIP_FLAG_ALWAYS_POWERED            = BIT(5),
        TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED    = BIT(6),
-       TPM_CHIP_FLAG_FIRMWARE_UPGRADE  = BIT(7),
+       TPM_CHIP_FLAG_FIRMWARE_UPGRADE          = BIT(7),
 };
 
 #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)