Skip to content

Commit 20b87bb

Browse files
stefanbergersrajiv
authored andcommitted
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: Stefan Berger <stefanb@linux.vnet.ibm.com> Signed-off-by: Rajiv Andrade <srajiv@linux.vnet.ibm.com>
1 parent 45baa1d commit 20b87bb

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

‎drivers/char/tpm/tpm_tis.c‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/interrupt.h>
2727
#include <linux/wait.h>
2828
#include <linux/acpi.h>
29+
#include <linux/freezer.h>
2930
#include "tpm.h"
3031

3132
#define TPM_HEADER_SIZE 10
@@ -120,7 +121,7 @@ static void release_locality(struct tpm_chip *chip, int l, int force)
120121

121122
static int request_locality(struct tpm_chip *chip, int l)
122123
{
123-
unsigned long stop;
124+
unsigned long stop, timeout;
124125
long rc;
125126

126127
if (check_locality(chip, l) >= 0)
@@ -129,17 +130,25 @@ static int request_locality(struct tpm_chip *chip, int l)
129130
iowrite8(TPM_ACCESS_REQUEST_USE,
130131
chip->vendor.iobase + TPM_ACCESS(l));
131132

133+
stop = jiffies + chip->vendor.timeout_a;
134+
132135
if (chip->vendor.irq) {
136+
again:
137+
timeout = stop - jiffies;
138+
if ((long)timeout <= 0)
139+
return -1;
133140
rc = wait_event_interruptible_timeout(chip->vendor.int_queue,
134141
(check_locality
135142
(chip, l) >= 0),
136-
chip->vendor.timeout_a);
143+
timeout);
137144
if (rc > 0)
138145
return l;
139-
146+
if (rc == -ERESTARTSYS && freezing(current)) {
147+
clear_thread_flag(TIF_SIGPENDING);
148+
goto again;
149+
}
140150
} else {
141151
/* wait for burstcount */
142-
stop = jiffies + chip->vendor.timeout_a;
143152
do {
144153
if (check_locality(chip, l) >= 0)
145154
return l;
@@ -196,15 +205,24 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
196205
if ((status & mask) == mask)
197206
return 0;
198207

208+
stop = jiffies + timeout;
209+
199210
if (chip->vendor.irq) {
211+
again:
212+
timeout = stop - jiffies;
213+
if ((long)timeout <= 0)
214+
return -ETIME;
200215
rc = wait_event_interruptible_timeout(*queue,
201216
((tpm_tis_status
202217
(chip) & mask) ==
203218
mask), timeout);
204219
if (rc > 0)
205220
return 0;
221+
if (rc == -ERESTARTSYS && freezing(current)) {
222+
clear_thread_flag(TIF_SIGPENDING);
223+
goto again;
224+
}
206225
} else {
207-
stop = jiffies + timeout;
208226
do {
209227
msleep(TPM_TIMEOUT);
210228
status = tpm_tis_status(chip);

0 commit comments

Comments
 (0)