linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Jason Andryuk <jandryuk@gmail.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
	Omar Sandoval <osandov@osandov.com>,
	Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>,
	linux-integrity@vger.kernel.org
Subject: Re: [PATCH] tpm_tis: work around status register bug in STMicroelectronics TPM
Date: Sat, 29 Aug 2020 02:18:38 +0300	[thread overview]
Message-ID: <20200828231823.GA20705@linux.intel.com> (raw)
In-Reply-To: <20200827152445.15439-1-jandryuk@gmail.com>

On Thu, Aug 27, 2020 at 11:24:45AM -0400, Jason Andryuk wrote:
> James Bottomley wrote:
> >On Wed, 2020-04-15 at 15:45 -0700, Omar Sandoval wrote:
> >> From: Omar Sandoval <osandov@fb.com>
> >> 
> >> We've encountered a particular model of STMicroelectronics TPM that
> >> transiently returns a bad value in the status register. This causes
> >> the kernel to believe that the TPM is ready to receive a command when
> >> it actually isn't, which in turn causes the send to time out in
> >> get_burstcount(). In testing, reading the status register one extra
> >> time convinces the TPM to return a valid value.
> >
> >Interesting, I've got a very early upgradeable nuvoton that seems to be
> >behaving like this.
> >
> >> Signed-off-by: Omar Sandoval <osandov@fb.com>
> >> ---
> >>  drivers/char/tpm/tpm_tis_core.c | 12 ++++++++++++
> >>  1 file changed, 12 insertions(+)
> >> 
> >> diff --git a/drivers/char/tpm/tpm_tis_core.c
> >> b/drivers/char/tpm/tpm_tis_core.c
> >> index 27c6ca031e23..277a21027fc7 100644
> >> --- a/drivers/char/tpm/tpm_tis_core.c
> >> +++ b/drivers/char/tpm/tpm_tis_core.c
> >> @@ -238,6 +238,18 @@ static u8 tpm_tis_status(struct tpm_chip *chip)
> >>  	rc = tpm_tis_read8(priv, TPM_STS(priv->locality), &status);
> >>  	if (rc < 0)
> >>  		return 0;
> >> +	/*
> >> +	 * Some STMicroelectronics TPMs have a bug where the status
> >> register is
> >> +	 * sometimes bogus (all 1s) if read immediately after the
> >> access
> >> +	 * register is written to. Bits 0, 1, and 5 are always
> >> supposed to read
> >> +	 * as 0, so this is clearly invalid. Reading the register a
> >> second time
> >> +	 * returns a valid value.
> >> +	 */
> >> +	if (unlikely(status == 0xff)) {
> >> +		rc = tpm_tis_read8(priv, TPM_STS(priv->locality),
> >> &status);
> >> +		if (rc < 0)
> >> +			return 0;
> >> +	}
> >
> >You theorize that your case is fixed by the second read, but what if it
> >isn't and the second read also returns 0xff?  Shouldn't we have a line
> >here saying
> >
> >if (unlikely(status == 0xff))
> >	status = 0;
> >
> >So if we get a second 0xff we just pretend the thing isn't ready?
> 
> Thanks for the fix, Omar!
> 
> I tried the patch and it helps with STM TPM2 issues where commands fail
> with the kernel reporting:
> tpm tpm0: Unable to read burstcount
> tpm tpm0: tpm_try_transmit: send(): error -16
> 
> My testing was with 5.4, and I'd like to see this CC-ed stable.
> 
> When trying to diagnose the issue before finding this patch, I found it
> was timing sensitive.  I was seeing failures in the OpenXT installer.
> The system is basically idle when issuing TPM commands which frequently
> failed.  The same hardware booted into a Fedora Live USB image didn't
> have any TPM command failures.  One notable difference between the two
> is Fedora is CONFIG_PREEMPT=y and OpenXT is CONFIG_PREEMPT_NONE=y.
> Switching OpenXT to PREEMPT=y helped some, but there were still some
> issues with commands failing.  The second interesting thing was running tpm
> commands in OpenXT under trace-cmd let them succeed.  I guess that was enough
> to throw the timing off.
> 
> Anyway, I'd like to see this patch applied, please.
> 
> Thanks,
> Jason

There was v2 sent after this:

https://patchwork.kernel.org/patch/11492125/

Unfortunately it lacks changelog. What was changed between v1 and v2?
Why v3 has not been sent yet? I see a discussion with no final
conclusion.

/Jarkko

  reply	other threads:[~2020-08-28 23:18 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-15 22:45 [PATCH] tpm_tis: work around status register bug in STMicroelectronics TPM Omar Sandoval
2020-04-15 23:51 ` James Bottomley
2020-04-16  0:16   ` Omar Sandoval
2020-04-16  0:24     ` Omar Sandoval
2020-04-16 18:02       ` James Bottomley
2020-04-17 23:55         ` Jarkko Sakkinen
2020-04-18  0:12           ` James Bottomley
2020-04-20 20:46             ` Jarkko Sakkinen
2020-04-20 22:28               ` James Bottomley
2020-04-21 14:36                 ` Mimi Zohar
2020-04-21 20:25                   ` Jarkko Sakkinen
2020-04-21 20:31                     ` Mimi Zohar
2020-04-21 20:23                 ` Jarkko Sakkinen
2020-04-21 22:08                   ` James Bottomley
2020-04-16 17:09   ` Jarkko Sakkinen
2020-04-16 17:56     ` James Bottomley
2020-08-27 15:24   ` Jason Andryuk
2020-08-28 23:18     ` Jarkko Sakkinen [this message]
2020-08-29  0:12       ` Jason Andryuk
2020-08-31 13:55         ` Jarkko Sakkinen
2020-09-04 12:03         ` Jarkko Sakkinen
2020-04-16 17:08 ` Jarkko Sakkinen
2020-04-16 18:54   ` Omar Sandoval
2020-04-17 23:54     ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200828231823.GA20705@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=jandryuk@gmail.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=osandov@osandov.com \
    --cc=peterhuewe@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).