Skip to content

Commit

Permalink
crypto: ccp - Fix command completion detection race
Browse files Browse the repository at this point in the history
The wait_event() function is used to detect command completion.  The
interrupt handler will set the wait condition variable when the interrupt
is triggered.  However, the variable used for wait_event() is initialized
after the command has been submitted, which can create a race condition
with the interrupt handler and result in the wait_event() never returning.
Move the initialization of the wait condition variable to just before
command submission.

Fixes: 200664d ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")
Cc: <[email protected]> # 4.16.x-
Signed-off-by: Tom Lendacky <[email protected]>
Reviewed-by: Brijesh Singh <[email protected]>
Acked-by: Gary R Hook <[email protected]>
Acked-by: Gary R Hook <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
tlendacky authored and herbertx committed Jul 13, 2018
1 parent 5c324a2 commit f426d2b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/crypto/ccp/psp-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ static irqreturn_t psp_irq_handler(int irq, void *data)

static void sev_wait_cmd_ioc(struct psp_device *psp, unsigned int *reg)
{
psp->sev_int_rcvd = 0;

wait_event(psp->sev_int_queue, psp->sev_int_rcvd);
*reg = ioread32(psp->io_regs + PSP_CMDRESP);
}
Expand Down Expand Up @@ -148,6 +146,8 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
iowrite32(phys_lsb, psp->io_regs + PSP_CMDBUFF_ADDR_LO);
iowrite32(phys_msb, psp->io_regs + PSP_CMDBUFF_ADDR_HI);

psp->sev_int_rcvd = 0;

reg = cmd;
reg <<= PSP_CMDRESP_CMD_SHIFT;
reg |= PSP_CMDRESP_IOC;
Expand Down

0 comments on commit f426d2b

Please sign in to comment.