Skip to content

Commit d8d74ea

Browse files
stefanbergerJarkko Sakkinen
authored andcommitted
tpm: ibmvtpm: Wait for buffer to be set before proceeding
Synchronize with the results from the CRQs before continuing with the initialization. This avoids trying to send TPM commands while the rtce buffer has not been allocated, yet. This patch fixes an existing race condition that may occurr if the hypervisor does not quickly respond to the VTPM_GET_RTCE_BUFFER_SIZE request sent during initialization and therefore the ibmvtpm->rtce_buf has not been allocated at the time the first TPM command is sent. Fixes: 132f762 ("drivers/char/tpm: Add new device driver to support IBM vTPM") Signed-off-by: Stefan Berger <[email protected]> Acked-by: Nayna Jain <[email protected]> Tested-by: Nayna Jain <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 5cb2ace commit d8d74ea

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

drivers/char/tpm/tpm_ibmvtpm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ static irqreturn_t ibmvtpm_interrupt(int irq, void *vtpm_instance)
571571
*/
572572
while ((crq = ibmvtpm_crq_get_next(ibmvtpm)) != NULL) {
573573
ibmvtpm_crq_process(crq, ibmvtpm);
574+
wake_up_interruptible(&ibmvtpm->crq_queue.wq);
574575
crq->valid = 0;
575576
smp_wmb();
576577
}
@@ -618,6 +619,7 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
618619
}
619620

620621
crq_q->num_entry = CRQ_RES_BUF_SIZE / sizeof(*crq_q->crq_addr);
622+
init_waitqueue_head(&crq_q->wq);
621623
ibmvtpm->crq_dma_handle = dma_map_single(dev, crq_q->crq_addr,
622624
CRQ_RES_BUF_SIZE,
623625
DMA_BIDIRECTIONAL);
@@ -670,6 +672,13 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
670672
if (rc)
671673
goto init_irq_cleanup;
672674

675+
if (!wait_event_timeout(ibmvtpm->crq_queue.wq,
676+
ibmvtpm->rtce_buf != NULL,
677+
HZ)) {
678+
dev_err(dev, "CRQ response timed out\n");
679+
goto init_irq_cleanup;
680+
}
681+
673682
return tpm_chip_register(chip);
674683
init_irq_cleanup:
675684
do {

drivers/char/tpm/tpm_ibmvtpm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct ibmvtpm_crq_queue {
2626
struct ibmvtpm_crq *crq_addr;
2727
u32 index;
2828
u32 num_entry;
29+
wait_queue_head_t wq;
2930
};
3031

3132
struct ibmvtpm_dev {

0 commit comments

Comments
 (0)