Re: [PATCH v11 00/16] Remove nested TPM operations

From: Alexander Steffen
Date: Fri Feb 08 2019 - 08:29:01 EST


On 08.02.2019 03:14, Stefan Berger wrote:
On 2/7/19 8:51 PM, Stefan Berger wrote:
On 2/7/19 7:33 PM, Jarkko Sakkinen wrote:
On Thu, Feb 07, 2019 at 06:29:43PM -0500, Stefan Berger wrote:
On 2/7/19 4:29 PM, Jarkko Sakkinen wrote:



diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index e74c5b7b64bf..52afe20cc8a1 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -799,7 +799,9 @@ int tpm2_probe(struct tpm_chip *chip)
ÂÂÂÂÂ tpm_buf_append_u32(&buf, TPM2_CAP_TPM_PROPERTIES);
ÂÂÂÂÂ tpm_buf_append_u32(&buf, TPM_PT_TOTAL_COMMANDS);
ÂÂÂÂÂ tpm_buf_append_u32(&buf, 1);
+ÂÂÂ tpm_chip_start(chip);
ÂÂÂÂÂ rc = tpm_transmit_cmd(chip, &buf, 0, NULL);
+ÂÂÂ tpm_chip_stop(chip);
Thanks Stefan! I added call to tpm_tis_core as tpm2-cmd.c is to be kept
out of chip management common case being that you call tpm_try_get_ops(),
do 1-N TPM commands and release with tpm_put_ops(). These functions take
care starting and stopping the chip.

I fixed the 2nd issue in the master.

You also need to export the tpm_chip_start/stop symbols.


Master now seems to (still) have a problem when rmmod'ing:

A TPM error (325) occurred stopping the TPM. This happens at the same patch where I had to add the tpm_chip_start/stop above.



Here's my current overall patch against your master. I suppose the other tpm2_shutdown() for power management doesn't need the chip start ?

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 9865776ee2cd..f7147706a9c3 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -115,6 +115,7 @@ int tpm_chip_start(struct tpm_chip *chip)

ÂÂÂÂ return 0;
Â}
+EXPORT_SYMBOL_GPL(tpm_chip_start);

Â/**
 * tpm_chip_stop() - power off the TPM
@@ -131,7 +132,7 @@ void tpm_chip_stop(struct tpm_chip *chip)
ÂÂÂÂ if (chip->ops->clk_enable)
ÂÂÂÂ ÂÂÂ chip->ops->clk_enable(chip, false);
Â}
-
+EXPORT_SYMBOL_GPL(tpm_chip_stop);

Â/**
 * tpm_try_get_ops() - Get a ref to the tpm_chip
@@ -474,8 +475,11 @@ static void tpm_del_char_device(struct tpm_chip *chip)

ÂÂÂÂ /* Make the driver uncallable. */
ÂÂÂÂ down_write(&chip->ops_sem);
-ÂÂÂ if (chip->flags & TPM_CHIP_FLAG_TPM2)
+ÂÂÂ if (chip->flags & TPM_CHIP_FLAG_TPM2) {
+ÂÂÂ ÂÂÂ tpm_chip_start(chip, 0);
ÂÂÂÂ ÂÂÂ tpm2_shutdown(chip, TPM2_SU_CLEAR);
+ÂÂÂ ÂÂÂ tpm_chip_stop(chip, 0);
+ÂÂÂ }
ÂÂÂÂ chip->ops = NULL;
ÂÂÂÂ up_write(&chip->ops_sem);
Â}
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 02e8cffd1163..fcd845ad8c3c 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -124,6 +124,8 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
ÂÂÂÂ ÂÂÂ dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc);
ÂÂÂÂ } else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length))
ÂÂÂÂ ÂÂÂ rc = -EFAULT;
+ÂÂÂ else
+ÂÂÂ ÂÂÂ rc = 0;

ÂÂÂÂ return rc ? rc : len;
Â}

Applying those changes fixes all the issues I saw, thanks. I'll retest Jarkko's tree without custom patches, once you've agreed on the rc question.

Alexander