Skip to content

Commit 047d422

Browse files
stefanbergerjarkkojs
authored andcommitted
tpm: ibmvtpm: Avoid error message when process gets signal while waiting
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]>
1 parent a4aed36 commit 047d422

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
/**
@@ -457,7 +454,7 @@ static const struct tpm_class_ops tpm_ibmvtpm = {
457454
.send = tpm_ibmvtpm_send,
458455
.cancel = tpm_ibmvtpm_cancel,
459456
.status = tpm_ibmvtpm_status,
460-
.req_complete_mask = 0,
457+
.req_complete_mask = 1,
461458
.req_complete_val = 0,
462459
.req_canceled = tpm_ibmvtpm_req_canceled,
463460
};
@@ -550,7 +547,7 @@ static void ibmvtpm_crq_process(struct ibmvtpm_crq *crq,
550547
case VTPM_TPM_COMMAND_RES:
551548
/* len of the data in rtce buffer */
552549
ibmvtpm->res_len = be16_to_cpu(crq->len);
553-
ibmvtpm->tpm_processing_cmd = false;
550+
ibmvtpm->tpm_processing_cmd = 0;
554551
wake_up_interruptible(&ibmvtpm->wq);
555552
return;
556553
default:
@@ -688,8 +685,15 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
688685
goto init_irq_cleanup;
689686
}
690687

691-
if (!strcmp(id->compat, "IBM,vtpm20")) {
688+
689+
if (!strcmp(id->compat, "IBM,vtpm20"))
692690
chip->flags |= TPM_CHIP_FLAG_TPM2;
691+
692+
rc = tpm_get_timeouts(chip);
693+
if (rc)
694+
goto init_irq_cleanup;
695+
696+
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
693697
rc = tpm2_get_cc_attrs_tbl(chip);
694698
if (rc)
695699
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)