mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tpm: fix interrupt timeouts
@ 2014-08-25  7:14 Scot Doyle
  2014-08-25 18:03 ` Jason Gunthorpe
  2014-09-09 19:44 ` Peter Hüwe
  0 siblings, 2 replies; 4+ messages in thread
From: Scot Doyle @ 2014-08-25  7:14 UTC (permalink / raw)
  To: Peter Huewe, Ashley Lai, Marcel Selhorst
  Cc: Jason Gunthorpe, Stefan Berger, Luigi Semenzato, tpmdd-devel,
	linux-kernel

commit 4c663cfc523a88d97a8309b04a089c27dc57fd7e
    wait: fix false timeouts when using wait_event_timeout()

changed the semantics of wait_event_interruptible_timeout so that a
condition check is performed after timeout and 1 is returned if true.

The TPM chip may not send interrupts even though the tpm module is
attempting to receive interrupts. In this case, after the module
sends a command to the TPM chip it performs a blocking wait on the
interrupt queue. No interrupts are sent from the chip, the queue is
not woken up and the blocking wait times out. Despite timing out,
the command has completed and the condition check performed by
wait_event_interruptible_timeout after timeout is true, resulting in
a return value of 1. Since the expected return value on timeout is 0
the timeout is not detected.

To fix, assume a return value of 1 or less indicates an elapsed
timeout. It is possible for the return value to be 1 after receiving
an interrupt, but this should be rare. The condition is not double-
checked because of possible side effects.

Signed-off-by: Scot Doyle
---
Patch for wait_event_interruptible_timeout documentation:
https://lkml.kernel.org/g/alpine.LNX.2.11.1408241710070.6462@localhost.localdomain

 drivers/char/tpm/tpm-interface.c   | 2 +-
 drivers/char/tpm/tpm_i2c_nuvoton.c | 2 +-
 drivers/char/tpm/tpm_tis.c         | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 6af1700..cceda56 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -863,7 +863,7 @@ again:
 			wait_for_tpm_stat_cond(chip, mask, check_cancel,
 					       &canceled),
 			timeout);
-		if (rc > 0) {
+		if (rc > 1) {
 			if (canceled)
 				return -ECANCELED;
 			return 0;
diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c
index 7b158ef..fce0c70 100644
--- a/drivers/char/tpm/tpm_i2c_nuvoton.c
+++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
@@ -185,7 +185,7 @@ static int i2c_nuvoton_wait_for_stat(struct tpm_chip *chip, u8 mask, u8 value,
 		rc = wait_event_interruptible_timeout(*queue,
 						      cur_intrs != priv->intrs,
 						      timeout);
-		if (rc > 0)
+		if (rc > 1)
 			return 0;
 		/* At this point we know that the SINT pin is asserted, so we
 		 * do not need to do i2c_nuvoton_check_status */
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 2c46734..6cb0f7a 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -158,7 +158,7 @@ again:
 						      (check_locality
 						       (chip, l) >= 0),
 						      timeout);
-		if (rc > 0)
+		if (rc > 1)
 			return l;
 		if (rc == -ERESTARTSYS && freezing(current)) {
 			clear_thread_flag(TIF_SIGPENDING);
-- 
2.0.4


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

* Re: [PATCH] tpm: fix interrupt timeouts
  2014-08-25  7:14 [PATCH] tpm: fix interrupt timeouts Scot Doyle
@ 2014-08-25 18:03 ` Jason Gunthorpe
  2014-09-09 19:44 ` Peter Hüwe
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2014-08-25 18:03 UTC (permalink / raw)
  To: Scot Doyle
  Cc: Peter Huewe, Ashley Lai, Marcel Selhorst, Stefan Berger,
	Luigi Semenzato, tpmdd-devel, linux-kernel

On Mon, Aug 25, 2014 at 07:14:03AM +0000, Scot Doyle wrote:
> commit 4c663cfc523a88d97a8309b04a089c27dc57fd7e
>     wait: fix false timeouts when using wait_event_timeout()
> 
> changed the semantics of wait_event_interruptible_timeout so that a
> condition check is performed after timeout and 1 is returned if true.
> 
> The TPM chip may not send interrupts even though the tpm module is
> attempting to receive interrupts. In this case, after the module
> sends a command to the TPM chip it performs a blocking wait on the
> interrupt queue. No interrupts are sent from the chip, the queue is
> not woken up and the blocking wait times out. Despite timing out,
> the command has completed and the condition check performed by
> wait_event_interruptible_timeout after timeout is true, resulting in
> a return value of 1. Since the expected return value on timeout is 0
> the timeout is not detected.
> 
> To fix, assume a return value of 1 or less indicates an elapsed
> timeout. It is possible for the return value to be 1 after receiving
> an interrupt, but this should be rare. The condition is not double-
> checked because of possible side effects.

Hum.. Okay, so I see what you are trying to fix here, but the code is
actually using wait_event_interruptible_timeout correctly as is. 

The TPM actually did complete the operation, and the test sentinal
checks directly at the TPM - which makes sense to me..

I think you'll have to directly test in the tis driver if the
interrupt is working.

The ordering in the TIS driver is wrong, interrupts should be turned
on before any TPM commands are issued. This is what other drivers are
doing.
	
If you fix this, tis can then just count interrupts recieved and check
if that is 0 to detect failure and then turn them off.

Jason

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

* Re: [PATCH] tpm: fix interrupt timeouts
  2014-08-25  7:14 [PATCH] tpm: fix interrupt timeouts Scot Doyle
  2014-08-25 18:03 ` Jason Gunthorpe
@ 2014-09-09 19:44 ` Peter Hüwe
  2014-09-09 20:03   ` Jason Gunthorpe
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Hüwe @ 2014-09-09 19:44 UTC (permalink / raw)
  To: Scot Doyle
  Cc: Ashley Lai, Marcel Selhorst, Jason Gunthorpe, Stefan Berger,
	Luigi Semenzato, tpmdd-devel, linux-kernel

Hi Scot,
Am Montag, 25. August 2014, 09:14:03 schrieb Scot Doyle:
> commit 4c663cfc523a88d97a8309b04a089c27dc57fd7e
>     wait: fix false timeouts when using wait_event_timeout()
> 
> changed the semantics of wait_event_interruptible_timeout so that a
> condition check is performed after timeout and 1 is returned if true.

is this one still valid or superseeded by one of the other patches?

Thanks,
Peter


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

* Re: [PATCH] tpm: fix interrupt timeouts
  2014-09-09 19:44 ` Peter Hüwe
@ 2014-09-09 20:03   ` Jason Gunthorpe
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2014-09-09 20:03 UTC (permalink / raw)
  To: Peter Hüwe
  Cc: Scot Doyle, Ashley Lai, Marcel Selhorst, Stefan Berger,
	Luigi Semenzato, tpmdd-devel, linux-kernel

On Tue, Sep 09, 2014 at 09:44:35PM +0200, Peter Hüwe wrote:
> Hi Scot,
> Am Montag, 25. August 2014, 09:14:03 schrieb Scot Doyle:
> > commit 4c663cfc523a88d97a8309b04a089c27dc57fd7e
> >     wait: fix false timeouts when using wait_event_timeout()
> > 
> > changed the semantics of wait_event_interruptible_timeout so that a
> > condition check is performed after timeout and 1 is returned if true.
> 
> is this one still valid or superseeded by one of the other patches?

It is not correct, so NAK on this patch.

Jason

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

end of thread, other threads:[~2014-09-09 20:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-25  7:14 [PATCH] tpm: fix interrupt timeouts Scot Doyle
2014-08-25 18:03 ` Jason Gunthorpe
2014-09-09 19:44 ` Peter Hüwe
2014-09-09 20:03   ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome