Commit 20b87bbf authored by Stefan Berger's avatar Stefan Berger Committed by Rajiv Andrade

tpm_tis: Delay ACPI S3 suspend while the TPM is busy

This patch delays the (ACPI S3) suspend while the TPM is busy processing a
command and the TPM TIS driver is run in interrupt mode. This is the same
behavior as we already have it for the TPM TIS driver in polling mode.

Reasoning: Some of the TPM's commands advance the internal state of the TPM.
An example would be the extending of one of its PCR registers. Upper layers,
such as IMA or TSS (TrouSerS), would certainly want to be sure that the
command succeeded rather than getting an error code (-62 = -ETIME) that may
not give a conclusive answer as for what reason the command failed. Reissuing
such a command would put the TPM into the wrong state, so waiting for it to
finish is really the only option.

The downside is that some commands (key creation) can take a long time and
actually prevent the machine from entering S3 at all before the 20 second
timeout of the power management subsystem arrives.
Signed-off-by: default avatarStefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: default avatarRajiv Andrade <srajiv@linux.vnet.ibm.com>
parent 45baa1d1
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/freezer.h>
#include "tpm.h" #include "tpm.h"
#define TPM_HEADER_SIZE 10 #define TPM_HEADER_SIZE 10
...@@ -120,7 +121,7 @@ static void release_locality(struct tpm_chip *chip, int l, int force) ...@@ -120,7 +121,7 @@ static void release_locality(struct tpm_chip *chip, int l, int force)
static int request_locality(struct tpm_chip *chip, int l) static int request_locality(struct tpm_chip *chip, int l)
{ {
unsigned long stop; unsigned long stop, timeout;
long rc; long rc;
if (check_locality(chip, l) >= 0) if (check_locality(chip, l) >= 0)
...@@ -129,17 +130,25 @@ static int request_locality(struct tpm_chip *chip, int l) ...@@ -129,17 +130,25 @@ static int request_locality(struct tpm_chip *chip, int l)
iowrite8(TPM_ACCESS_REQUEST_USE, iowrite8(TPM_ACCESS_REQUEST_USE,
chip->vendor.iobase + TPM_ACCESS(l)); chip->vendor.iobase + TPM_ACCESS(l));
stop = jiffies + chip->vendor.timeout_a;
if (chip->vendor.irq) { if (chip->vendor.irq) {
again:
timeout = stop - jiffies;
if ((long)timeout <= 0)
return -1;
rc = wait_event_interruptible_timeout(chip->vendor.int_queue, rc = wait_event_interruptible_timeout(chip->vendor.int_queue,
(check_locality (check_locality
(chip, l) >= 0), (chip, l) >= 0),
chip->vendor.timeout_a); timeout);
if (rc > 0) if (rc > 0)
return l; return l;
if (rc == -ERESTARTSYS && freezing(current)) {
clear_thread_flag(TIF_SIGPENDING);
goto again;
}
} else { } else {
/* wait for burstcount */ /* wait for burstcount */
stop = jiffies + chip->vendor.timeout_a;
do { do {
if (check_locality(chip, l) >= 0) if (check_locality(chip, l) >= 0)
return l; return l;
...@@ -196,15 +205,24 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, ...@@ -196,15 +205,24 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
if ((status & mask) == mask) if ((status & mask) == mask)
return 0; return 0;
stop = jiffies + timeout;
if (chip->vendor.irq) { if (chip->vendor.irq) {
again:
timeout = stop - jiffies;
if ((long)timeout <= 0)
return -ETIME;
rc = wait_event_interruptible_timeout(*queue, rc = wait_event_interruptible_timeout(*queue,
((tpm_tis_status ((tpm_tis_status
(chip) & mask) == (chip) & mask) ==
mask), timeout); mask), timeout);
if (rc > 0) if (rc > 0)
return 0; return 0;
if (rc == -ERESTARTSYS && freezing(current)) {
clear_thread_flag(TIF_SIGPENDING);
goto again;
}
} else { } else {
stop = jiffies + timeout;
do { do {
msleep(TPM_TIMEOUT); msleep(TPM_TIMEOUT);
status = tpm_tis_status(chip); status = tpm_tis_status(chip);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment