linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tpm_tis_core: Choose appropriate timeout for reading burstcount
@ 2017-02-16 15:33 Peter Huewe
  2017-02-22 21:13 ` Jarkko Sakkinen
  2017-02-24 17:41 ` Jarkko Sakkinen
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Huewe @ 2017-02-16 15:33 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: Jason Gunthorpe, tpmdd-devel, linux-kernel, peterhuewe,
	Alexander Steffen, stable, Peter Huewe

From: Alexander Steffen <Alexander.Steffen@infineon.com>

TIS v1.3 for TPM 1.2 and PTP for TPM 2.0 disagree about which timeout
value applies to reading a valid burstcount. It is TIMEOUT_D according to
TIS, but TIMEOUT_A according to PTP, so choose the appropriate value
depending on whether we deal with a TPM 1.2 or a TPM 2.0.

This is important since according to the PTP TIMEOUT_D is much smaller
than TIMEOUT_A. So the previous implementation could run into timeouts
with a TPM 2.0, even though the TPM was behaving perfectly fine.

During tpm2_probe TIMEOUT_D will be used even with a TPM 2.0, because
TPM_CHIP_FLAG_TPM2 is not yet set. This is fine, since the timeout values
will only be changed afterwards by tpm_get_timeouts. Until then
TIS_TIMEOUT_D_MAX applies, which is large enough.

Cc: stable@vger.kernel.org
Fixes: aec04cbdf723 ("tpm: TPM 2.0 FIFO Interface")

Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com>
Signed-off-by: Peter Huewe <peter.huewe@infineon.com>
---
 drivers/char/tpm/tpm_tis_core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index c0f296b5d413..fc0e9a2734ed 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -160,8 +160,10 @@ static int get_burstcount(struct tpm_chip *chip)
 	u32 value;
 
 	/* wait for burstcount */
-	/* which timeout value, spec has 2 answers (c & d) */
-	stop = jiffies + chip->timeout_d;
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		stop = jiffies + chip->timeout_a;
+	else
+		stop = jiffies + chip->timeout_d;
 	do {
 		rc = tpm_tis_read32(priv, TPM_STS(priv->locality), &value);
 		if (rc < 0)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tpm_tis_core: Choose appropriate timeout for reading burstcount
  2017-02-16 15:33 [PATCH] tpm_tis_core: Choose appropriate timeout for reading burstcount Peter Huewe
@ 2017-02-22 21:13 ` Jarkko Sakkinen
  2017-02-24 17:41 ` Jarkko Sakkinen
  1 sibling, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2017-02-22 21:13 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Jason Gunthorpe, tpmdd-devel, linux-kernel, peterhuewe,
	Alexander Steffen, stable

On Thu, Feb 16, 2017 at 03:33:36PM +0000, Peter Huewe wrote:
> From: Alexander Steffen <Alexander.Steffen@infineon.com>
> 
> TIS v1.3 for TPM 1.2 and PTP for TPM 2.0 disagree about which timeout
> value applies to reading a valid burstcount. It is TIMEOUT_D according to
> TIS, but TIMEOUT_A according to PTP, so choose the appropriate value
> depending on whether we deal with a TPM 1.2 or a TPM 2.0.
> 
> This is important since according to the PTP TIMEOUT_D is much smaller
> than TIMEOUT_A. So the previous implementation could run into timeouts
> with a TPM 2.0, even though the TPM was behaving perfectly fine.
> 
> During tpm2_probe TIMEOUT_D will be used even with a TPM 2.0, because
> TPM_CHIP_FLAG_TPM2 is not yet set. This is fine, since the timeout values
> will only be changed afterwards by tpm_get_timeouts. Until then
> TIS_TIMEOUT_D_MAX applies, which is large enough.
> 
> Cc: stable@vger.kernel.org
> Fixes: aec04cbdf723 ("tpm: TPM 2.0 FIFO Interface")
> 
> Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com>
> Signed-off-by: Peter Huewe <peter.huewe@infineon.com>

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  drivers/char/tpm/tpm_tis_core.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index c0f296b5d413..fc0e9a2734ed 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -160,8 +160,10 @@ static int get_burstcount(struct tpm_chip *chip)
>  	u32 value;
>  
>  	/* wait for burstcount */
> -	/* which timeout value, spec has 2 answers (c & d) */
> -	stop = jiffies + chip->timeout_d;
> +	if (chip->flags & TPM_CHIP_FLAG_TPM2)
> +		stop = jiffies + chip->timeout_a;
> +	else
> +		stop = jiffies + chip->timeout_d;
>  	do {
>  		rc = tpm_tis_read32(priv, TPM_STS(priv->locality), &value);
>  		if (rc < 0)
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tpm_tis_core: Choose appropriate timeout for reading burstcount
  2017-02-16 15:33 [PATCH] tpm_tis_core: Choose appropriate timeout for reading burstcount Peter Huewe
  2017-02-22 21:13 ` Jarkko Sakkinen
@ 2017-02-24 17:41 ` Jarkko Sakkinen
  1 sibling, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2017-02-24 17:41 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Jason Gunthorpe, tpmdd-devel, linux-kernel, peterhuewe,
	Alexander Steffen, stable

On Thu, Feb 16, 2017 at 03:33:36PM +0000, Peter Huewe wrote:
> From: Alexander Steffen <Alexander.Steffen@infineon.com>
> 
> TIS v1.3 for TPM 1.2 and PTP for TPM 2.0 disagree about which timeout
> value applies to reading a valid burstcount. It is TIMEOUT_D according to
> TIS, but TIMEOUT_A according to PTP, so choose the appropriate value
> depending on whether we deal with a TPM 1.2 or a TPM 2.0.
> 
> This is important since according to the PTP TIMEOUT_D is much smaller
> than TIMEOUT_A. So the previous implementation could run into timeouts
> with a TPM 2.0, even though the TPM was behaving perfectly fine.
> 
> During tpm2_probe TIMEOUT_D will be used even with a TPM 2.0, because
> TPM_CHIP_FLAG_TPM2 is not yet set. This is fine, since the timeout values
> will only be changed afterwards by tpm_get_timeouts. Until then
> TIS_TIMEOUT_D_MAX applies, which is large enough.
> 
> Cc: stable@vger.kernel.org
> Fixes: aec04cbdf723 ("tpm: TPM 2.0 FIFO Interface")
> 
> Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com>
> Signed-off-by: Peter Huewe <peter.huewe@infineon.com>

Pushed.

/Jarkko

> ---
>  drivers/char/tpm/tpm_tis_core.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index c0f296b5d413..fc0e9a2734ed 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -160,8 +160,10 @@ static int get_burstcount(struct tpm_chip *chip)
>  	u32 value;
>  
>  	/* wait for burstcount */
> -	/* which timeout value, spec has 2 answers (c & d) */
> -	stop = jiffies + chip->timeout_d;
> +	if (chip->flags & TPM_CHIP_FLAG_TPM2)
> +		stop = jiffies + chip->timeout_a;
> +	else
> +		stop = jiffies + chip->timeout_d;
>  	do {
>  		rc = tpm_tis_read32(priv, TPM_STS(priv->locality), &value);
>  		if (rc < 0)
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-24 17:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-16 15:33 [PATCH] tpm_tis_core: Choose appropriate timeout for reading burstcount Peter Huewe
2017-02-22 21:13 ` Jarkko Sakkinen
2017-02-24 17:41 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).