Skip to content

Commit c0eb7a2

Browse files
stefanbergersmb49
authored andcommitted
tpm: ibmvtpm: Avoid error message when process gets signal while waiting
BugLink: https://bugs.launchpad.net/bugs/1946788 [ Upstream commit 047d422 ] When rngd is run as root then lots of these types of message will appear in the kernel log if the TPM has been configured to provide random bytes: [ 7406.275163] tpm tpm0: tpm_transmit: tpm_recv: error -4 The issue is caused by the following call that is interrupted while waiting for the TPM's response. sig = wait_event_interruptible(ibmvtpm->wq, !ibmvtpm->tpm_processing_cmd); Rather than waiting for the response in the low level driver, have it use the polling loop in tpm_try_transmit() that uses a command's duration to poll until a result has been returned by the TPM, thus ending when the timeout has occurred but not responding to signals and ctrl-c anymore. To stay in this polling loop extend tpm_ibmvtpm_status() to return 'true' for as long as the vTPM is indicated as being busy in tpm_processing_cmd. Since the loop requires the TPM's timeouts, get them now using tpm_get_timeouts() after setting the TPM2 version flag on the chip. To recreat the resolved issue start rngd like this: sudo rngd -r /dev/hwrng -t sudo rngd -r /dev/tpm0 -t Link: https://bugzilla.redhat.com/show_bug.cgi?id=1981473 Fixes: 6674ff1 ("tpm_ibmvtpm: properly handle interrupted packet receptions") Cc: Nayna Jain <[email protected]> Cc: George Wilson <[email protected]> Reported-by: Nageswara R Sastry <[email protected]> Signed-off-by: Stefan Berger <[email protected]> Tested-by: Nageswara R Sastry <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Kelsey Skunberg <[email protected]>
1 parent e6da87c commit c0eb7a2

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

drivers/char/tpm/tpm_ibmvtpm.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,12 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
106106
{
107107
struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
108108
u16 len;
109-
int sig;
110109

111110
if (!ibmvtpm->rtce_buf) {
112111
dev_err(ibmvtpm->dev, "ibmvtpm device is not ready\n");
113112
return 0;
114113
}
115114

116-
sig = wait_event_interruptible(ibmvtpm->wq, !ibmvtpm->tpm_processing_cmd);
117-
if (sig)
118-
return -EINTR;
119-
120115
len = ibmvtpm->res_len;
121116

122117
if (count < len) {
@@ -237,7 +232,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
237232
* set the processing flag before the Hcall, since we may get the
238233
* result (interrupt) before even being able to check rc.
239234
*/
240-
ibmvtpm->tpm_processing_cmd = true;
235+
ibmvtpm->tpm_processing_cmd = 1;
241236

242237
again:
243238
rc = ibmvtpm_send_crq(ibmvtpm->vdev,
@@ -255,7 +250,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
255250
goto again;
256251
}
257252
dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
258-
ibmvtpm->tpm_processing_cmd = false;
253+
ibmvtpm->tpm_processing_cmd = 0;
259254
}
260255

261256
spin_unlock(&ibmvtpm->rtce_lock);
@@ -269,7 +264,9 @@ static void tpm_ibmvtpm_cancel(struct tpm_chip *chip)
269264

270265
static u8 tpm_ibmvtpm_status(struct tpm_chip *chip)
271266
{
272-
return 0;
267+
struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
268+
269+
return ibmvtpm->tpm_processing_cmd;
273270
}
274271

275272
/**
@@ -459,7 +456,7 @@ static const struct tpm_class_ops tpm_ibmvtpm = {
459456
.send = tpm_ibmvtpm_send,
460457
.cancel = tpm_ibmvtpm_cancel,
461458
.status = tpm_ibmvtpm_status,
462-
.req_complete_mask = 0,
459+
.req_complete_mask = 1,
463460
.req_complete_val = 0,
464461
.req_canceled = tpm_ibmvtpm_req_canceled,
465462
};
@@ -552,7 +549,7 @@ static void ibmvtpm_crq_process(struct ibmvtpm_crq *crq,
552549
case VTPM_TPM_COMMAND_RES:
553550
/* len of the data in rtce buffer */
554551
ibmvtpm->res_len = be16_to_cpu(crq->len);
555-
ibmvtpm->tpm_processing_cmd = false;
552+
ibmvtpm->tpm_processing_cmd = 0;
556553
wake_up_interruptible(&ibmvtpm->wq);
557554
return;
558555
default:
@@ -690,8 +687,15 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
690687
goto init_irq_cleanup;
691688
}
692689

693-
if (!strcmp(id->compat, "IBM,vtpm20")) {
690+
691+
if (!strcmp(id->compat, "IBM,vtpm20"))
694692
chip->flags |= TPM_CHIP_FLAG_TPM2;
693+
694+
rc = tpm_get_timeouts(chip);
695+
if (rc)
696+
goto init_irq_cleanup;
697+
698+
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
695699
rc = tpm2_get_cc_attrs_tbl(chip);
696700
if (rc)
697701
goto init_irq_cleanup;

drivers/char/tpm/tpm_ibmvtpm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct ibmvtpm_dev {
4141
wait_queue_head_t wq;
4242
u16 res_len;
4343
u32 vtpm_version;
44-
bool tpm_processing_cmd;
44+
u8 tpm_processing_cmd;
4545
};
4646

4747
#define CRQ_RES_BUF_SIZE PAGE_SIZE

0 commit comments

Comments
 (0)