linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] TPM: Work around buggy TPMs that block during continue self test
@ 2012-11-21 21:15 Jason Gunthorpe
  2013-01-22 23:29 ` [tpmdd-devel] " Kent Yoder
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Gunthorpe @ 2012-11-21 21:15 UTC (permalink / raw)
  To: linux-kernel, tpmdd-devel

We've been testing an alternative TPM for our embedded products and
found random kernel boot failures due to time outs after the continue
self test command.

This was happening randomly, and has been *very* hard to track down, but it
looks like with this chip there is some kind of race with the tpm_tis_status()
check of TPM_STS_COMMAND_READY. If things get there 'too fast' then
it sees the chip is ready, or tpm_tis_ready() works. Otherwise it takes
somewhere over 400ms before the chip will return TPM_STS_COMMAND_READY.

Adding some delay after tpm_continue_selftest() makes things reliably
hit the failure path, otherwise it is a crapshot.

The spec says it should be returning TPM_WARN_DOING_SELFTEST, not holding
off on ready..

Boot log during this event looks like this:

tpm_tis 70030000.tpm_tis: 1.2 TPM (device-id 0x3204, rev-id 64)
tpm_tis 70030000.tpm_tis: Issuing TPM_STARTUP
tpm_tis 70030000.tpm_tis: tpm_transmit: tpm_send: error -62
tpm_tis 70030000.tpm_tis: [Hardware Error]: TPM command timed out during continue self test
tpm_tis 70030000.tpm_tis: tpm_transmit: tpm_send: error -62
tpm_tis 70030000.tpm_tis: [Hardware Error]: TPM command timed out during continue self test
tpm_tis 70030000.tpm_tis: tpm_transmit: tpm_send: error -62
tpm_tis 70030000.tpm_tis: [Hardware Error]: TPM command timed out during continue self test
tpm_tis 70030000.tpm_tis: tpm_transmit: tpm_send: error -62
tpm_tis 70030000.tpm_tis: [Hardware Error]: TPM command timed out during continue self test

The other TPM vendor we use doesn't show this wonky behaviour:
tpm_tis 70030000.tpm_tis: 1.2 TPM (device-id 0xFE, rev-id 70)

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
---
 drivers/char/tpm/tpm.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 454e032..61d62c2 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -857,7 +857,7 @@ int tpm_do_selftest(struct tpm_chip *chip)
 {
 	int rc;
 	unsigned int loops;
-	unsigned int delay_msec = 1000;
+	unsigned int delay_msec = 100;
 	unsigned long duration;
 	struct tpm_cmd_t cmd;
 
@@ -878,6 +878,14 @@ int tpm_do_selftest(struct tpm_chip *chip)
 		cmd.header.in = pcrread_header;
 		cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0);
 		rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE);
+		/* Some buggy TPMs will not respond to tpm_tis_ready() for
+		 * around 300ms while the self test is ongoing, keep trying
+		 * until the self test duration expires. */
+		if (rc == -ETIME) {
+			dev_info(chip->dev, HW_ERR "TPM command timed out during continue self test");
+			msleep(delay_msec);
+			continue;
+		}
 
 		if (rc < TPM_HEADER_SIZE)
 			return -EFAULT;
-- 
1.7.5.4


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

* Re: [tpmdd-devel] [PATCH] TPM: Work around buggy TPMs that block during continue self test
  2012-11-21 21:15 [PATCH] TPM: Work around buggy TPMs that block during continue self test Jason Gunthorpe
@ 2013-01-22 23:29 ` Kent Yoder
  2013-01-25 20:25   ` Jason Gunthorpe
  0 siblings, 1 reply; 6+ messages in thread
From: Kent Yoder @ 2013-01-22 23:29 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: linux-kernel, tpmdd-devel

Hi Jason,

On Wed, Nov 21, 2012 at 3:15 PM, Jason Gunthorpe
<jgunthorpe@obsidianresearch.com> wrote:
> We've been testing an alternative TPM for our embedded products and
> found random kernel boot failures due to time outs after the continue
> self test command.
>
> This was happening randomly, and has been *very* hard to track down, but it
> looks like with this chip there is some kind of race with the tpm_tis_status()
> check of TPM_STS_COMMAND_READY. If things get there 'too fast' then
> it sees the chip is ready, or tpm_tis_ready() works. Otherwise it takes
> somewhere over 400ms before the chip will return TPM_STS_COMMAND_READY.
>
> Adding some delay after tpm_continue_selftest() makes things reliably
> hit the failure path, otherwise it is a crapshot.

  I've staged this patch here, please test:

https://github.com/shpedoikal/linux.git tpmdd-01-22-13

Thanks,
Kent

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

* Re: [tpmdd-devel] [PATCH] TPM: Work around buggy TPMs that block during continue self test
  2013-01-22 23:29 ` [tpmdd-devel] " Kent Yoder
@ 2013-01-25 20:25   ` Jason Gunthorpe
       [not found]     ` <20130128141153.GA3060@ennui.austin.ibm.com>
  2013-02-03 23:02     ` Peter Hüwe
  0 siblings, 2 replies; 6+ messages in thread
From: Jason Gunthorpe @ 2013-01-25 20:25 UTC (permalink / raw)
  To: Kent Yoder; +Cc: linux-kernel, tpmdd-devel

On Tue, Jan 22, 2013 at 05:29:23PM -0600, Kent Yoder wrote:
> Hi Jason,
> 
> On Wed, Nov 21, 2012 at 3:15 PM, Jason Gunthorpe
> <jgunthorpe@obsidianresearch.com> wrote:
> > We've been testing an alternative TPM for our embedded products and
> > found random kernel boot failures due to time outs after the continue
> > self test command.
> >
> > This was happening randomly, and has been *very* hard to track down, but it
> > looks like with this chip there is some kind of race with the tpm_tis_status()
> > check of TPM_STS_COMMAND_READY. If things get there 'too fast' then
> > it sees the chip is ready, or tpm_tis_ready() works. Otherwise it takes
> > somewhere over 400ms before the chip will return TPM_STS_COMMAND_READY.
> >
> > Adding some delay after tpm_continue_selftest() makes things reliably
> > hit the failure path, otherwise it is a crapshot.
> 
>   I've staged this patch here, please test:
> 
> https://github.com/shpedoikal/linux.git tpmdd-01-22-13

Thanks Kent, I will try to test your branch next week, if I am able.

Can you also grab

https://github.com/jgunthorpe/linux/commit/98b2a198b43b41b0535200bf475160786398f114

And did you have any comments on:

https://github.com/jgunthorpe/linux/commit/9981e3e622bf702394982117134bed731ffd6f7e

Both were posted to the list a bit ago.

Regards,
-- 
Jason Gunthorpe <jgunthorpe@obsidianresearch.com>        (780)4406067x832
Chief Technology Officer, Obsidian Research Corp         Edmonton, Canada

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

* Re: [tpmdd-devel] [PATCH] TPM: Work around buggy TPMs that block during continue self test
       [not found]     ` <20130128141153.GA3060@ennui.austin.ibm.com>
@ 2013-02-01 22:38       ` Kent Yoder
  2013-02-01 23:03         ` Jason Gunthorpe
  0 siblings, 1 reply; 6+ messages in thread
From: Kent Yoder @ 2013-02-01 22:38 UTC (permalink / raw)
  To: Kent Yoder
  Cc: Jason Gunthorpe, tpmdd-devel, linux-kernel, Peter Hüwe,
	Mathias Leblanc

On Mon, Jan 28, 2013 at 8:11 AM, Kent Yoder <key@linux.vnet.ibm.com> wrote:
> On Fri, Jan 25, 2013 at 01:25:38PM -0700, Jason Gunthorpe wrote:
>> On Tue, Jan 22, 2013 at 05:29:23PM -0600, Kent Yoder wrote:
>> > Hi Jason,
>> >
>> > On Wed, Nov 21, 2012 at 3:15 PM, Jason Gunthorpe
>> > <jgunthorpe@obsidianresearch.com> wrote:
>> > > We've been testing an alternative TPM for our embedded products and
>> > > found random kernel boot failures due to time outs after the continue
>> > > self test command.
>> > >
>> > > This was happening randomly, and has been *very* hard to track down, but it
>> > > looks like with this chip there is some kind of race with the tpm_tis_status()
>> > > check of TPM_STS_COMMAND_READY. If things get there 'too fast' then
>> > > it sees the chip is ready, or tpm_tis_ready() works. Otherwise it takes
>> > > somewhere over 400ms before the chip will return TPM_STS_COMMAND_READY.
>> > >
>> > > Adding some delay after tpm_continue_selftest() makes things reliably
>> > > hit the failure path, otherwise it is a crapshot.
>> >
>> >   I've staged this patch here, please test:
>> >
>> > https://github.com/shpedoikal/linux.git tpmdd-01-22-13
>>
>> Thanks Kent, I will try to test your branch next week, if I am able.
>>
>> Can you also grab
>>
>> https://github.com/jgunthorpe/linux/commit/98b2a198b43b41b0535200bf475160786398f114
>
>  Thanks, I missed this, I'll start testing it.

  Ok, after yet another round of fixes to the stm i2c driver, I have a
staging tree.  I'll submit this as-is next week unless something super
ground-breaking comes up.

https://github.com/shpedoikal/linux.git tpmdd-01-31-13

Thanks,
Kent

>> And did you have any comments on:
>>
>> https://github.com/jgunthorpe/linux/commit/9981e3e622bf702394982117134bed731ffd6f7e
>
>   This one is a bit out of date atm, for instance the __dev* stuff is
> going away.  The thing that most makes me hesitant though is the config
> if (X86 || OF).  A hardware platform or a firmware type..  What platform
> should this actually target?
>
> Kent
>
>> Both were posted to the list a bit ago.
>>
>> Regards,
>> --
>> Jason Gunthorpe <jgunthorpe@obsidianresearch.com>        (780)4406067x832
>> Chief Technology Officer, Obsidian Research Corp         Edmonton, Canada
>>
>> ------------------------------------------------------------------------------
>> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
>> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
>> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
>> MVPs and experts. ON SALE this month only -- learn more at:
>> http://p.sf.net/sfu/learnnow-d2d
>> _______________________________________________
>> tpmdd-devel mailing list
>> tpmdd-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/tpmdd-devel
>>

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

* Re: [tpmdd-devel] [PATCH] TPM: Work around buggy TPMs that block during continue self test
  2013-02-01 22:38       ` Kent Yoder
@ 2013-02-01 23:03         ` Jason Gunthorpe
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Gunthorpe @ 2013-02-01 23:03 UTC (permalink / raw)
  To: Kent Yoder
  Cc: Kent Yoder, tpmdd-devel, linux-kernel, Peter H?we, Mathias Leblanc

On Fri, Feb 01, 2013 at 04:38:42PM -0600, Kent Yoder wrote:

> >> > https://github.com/shpedoikal/linux.git tpmdd-01-22-13
> >>
> >> Thanks Kent, I will try to test your branch next week, if I am able.
> >>
> >> Can you also grab
> >>
> >> https://github.com/jgunthorpe/linux/commit/98b2a198b43b41b0535200bf475160786398f114
> >
> >  Thanks, I missed this, I'll start testing it.
> 
>   Ok, after yet another round of fixes to the stm i2c driver, I have a
> staging tree.  I'll submit this as-is next week unless something super
> ground-breaking comes up.

Great, I'll put this on my list..

I didn't receive your prior message, thank you for quoting it..

> >> https://github.com/jgunthorpe/linux/commit/9981e3e622bf702394982117134bed731ffd6f7e
> >
> >   This one is a bit out of date atm, for instance the __dev* stuff is
> > going away.  The thing that most makes me hesitant though is the config
> > if (X86 || OF).  A hardware platform or a firmware type..  What platform
> > should this actually target?

Right on the __dev stuff..

Well the 'depends on' buisness is only due to the unconditional
probing of TIS_MEM_BASE for a tpm, and then the autodetection of an
IRQ number. That procedure is very much X86 only.

My patch removes the unconditional probe when OF support is turned on,
so it is safe to use on any platform only when OF is enabled.

Yes it is really wonky, but unconditionally probing HW in a driver is
wonky these days too..

Jason

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

* Re: [tpmdd-devel] [PATCH] TPM: Work around buggy TPMs that block during continue self test
  2013-01-25 20:25   ` Jason Gunthorpe
       [not found]     ` <20130128141153.GA3060@ennui.austin.ibm.com>
@ 2013-02-03 23:02     ` Peter Hüwe
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Hüwe @ 2013-02-03 23:02 UTC (permalink / raw)
  To: tpmdd-devel; +Cc: Jason Gunthorpe, Kent Yoder, linux-kernel

Am Freitag, 25. Januar 2013, 21:25:38 schrieb Jason Gunthorpe:
> > https://github.com/shpedoikal/linux.git tpmdd-01-22-13
> 
> Thanks Kent, I will try to test your branch next week, if I am able.
> 
> Can you also grab
> 
> https://github.com/jgunthorpe/linux/commit/98b2a198b43b41b0535200bf47516078
> 6398f114
> 

This one looks good to me.
For this one please add my 
Reviewed-by: Peter Huewe <peterhuewe@gmx.de>

Thanks,
PeterH 

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

end of thread, other threads:[~2013-02-03 22:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-21 21:15 [PATCH] TPM: Work around buggy TPMs that block during continue self test Jason Gunthorpe
2013-01-22 23:29 ` [tpmdd-devel] " Kent Yoder
2013-01-25 20:25   ` Jason Gunthorpe
     [not found]     ` <20130128141153.GA3060@ennui.austin.ibm.com>
2013-02-01 22:38       ` Kent Yoder
2013-02-01 23:03         ` Jason Gunthorpe
2013-02-03 23:02     ` Peter Hüwe

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).