Re: TPM selftest failure in 4.15

James Bottomley
2018-02-01T21:06:48Z

On Thu, 2018-02-01 at 13:35 -0700, Jason Gunthorpe wrote:
> On Thu, Feb 01, 2018 at 09:00:04PM +0100, James Bottomley wrote:
> >
> > On Thu, 2018-02-01 at 11:59 -0700, Jason Gunthorpe wrote:
> > >
> > > On Thu, Feb 01, 2018 at 07:46:04PM +0100, James Bottomley wrote:
> > >
> > > >
> > > >
> > > > I honestly don't think we should be waiting for the self test
> > > > at
> > > > all.
> > > > We should kick it off and treat any TPM_RC_TESTING error as
> > > > -EAGAIN.
> > > > We're already under fire for slow boot sequences and adding 2s
> > > > just
> > > > to
> > > > wait for the TPM to self test adds to that for no real value.
> > >
> > > Arguably the BIOS should have completed the selftest - this stuff
> > > generally only exists to support embedded.
> > >
> > > I don't like the idea of EAGAIN, that just expose all our users
> > > to
> > > this mess.
> > >
> > > I would support making transmit_cmd genericly wait and retry if
> > > the
> > > TPM insists we need to wait for selftest to complete the specific
> > > command though.
> >
> > OK, how about this then?
>
> Yeah, I like this concept much better, thanks

Great, I'll put it through a few tests then send a formal patch.

> > diff --git a/drivers/char/tpm/tpm-interface.c
> > b/drivers/char/tpm/tpm-interface.c
> > index 1d6729be4cd6..84ed271c060b 100644
> > +++ b/drivers/char/tpm/tpm-interface.c
> > @@ -521,12 +521,32 @@ ssize_t tpm_transmit_cmd(struct tpm_chip
> > *chip, struct tpm_space *space,
> > const struct tpm_output_header *header = buf;
> > int err;
> > ssize_t len;
> > + unsigned int delay_msec = 20;
> >
> > - len = tpm_transmit(chip, space, (u8 *)buf, bufsiz, flags);
> > - if (len < 0)
> > - return len;
> > + /*
> > + * on first probe we kick off a TPM self test in the
> > + * background This means the TPM may return RC_TESTING to
> > any
> > + * command that tries to use a subsystem under test, so do
> > an
> > + * exponential backoff wait if that happens
> > + */
> > + for (;;) {
> > + len = tpm_transmit(chip, space, (u8 *)buf, bufsiz,
> > flags);
> > + if (len < 0)
> > + return len;
> > +
> > + err = be32_to_cpu(header->return_code);
> > + if (err != TPM2_RC_TESTING ||
> > + (flags & TPM_TRANSMIT_NOWAIT))
> > + break;
>
> Do TPM and TPM2 use a different return code here?

Yes, TPM2_RC_TESTING is 0x90a and TPM_DOING_SELFTEST is 0x802

James