]>
Commit | Line | Data |
---|---|---|
68404aa3 GKH |
1 | From f426d2b20f1cd63818873593031593e15c3db20b Mon Sep 17 00:00:00 2001 |
2 | From: Tom Lendacky <thomas.lendacky@amd.com> | |
3 | Date: Tue, 3 Jul 2018 12:11:33 -0500 | |
4 | Subject: crypto: ccp - Fix command completion detection race | |
5 | ||
6 | From: Tom Lendacky <thomas.lendacky@amd.com> | |
7 | ||
8 | commit f426d2b20f1cd63818873593031593e15c3db20b upstream. | |
9 | ||
10 | The wait_event() function is used to detect command completion. The | |
11 | interrupt handler will set the wait condition variable when the interrupt | |
12 | is triggered. However, the variable used for wait_event() is initialized | |
13 | after the command has been submitted, which can create a race condition | |
14 | with the interrupt handler and result in the wait_event() never returning. | |
15 | Move the initialization of the wait condition variable to just before | |
16 | command submission. | |
17 | ||
18 | Fixes: 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support") | |
19 | Cc: <stable@vger.kernel.org> # 4.16.x- | |
20 | Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> | |
21 | Reviewed-by: Brijesh Singh <brijesh.singh@amd.com> | |
22 | Acked-by: Gary R Hook <gary.hook@amd.com> | |
23 | Acked-by: Gary R Hook <gary.hook@amd.com> | |
24 | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | |
25 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
26 | ||
27 | --- | |
28 | drivers/crypto/ccp/psp-dev.c | 4 ++-- | |
29 | 1 file changed, 2 insertions(+), 2 deletions(-) | |
30 | ||
31 | --- a/drivers/crypto/ccp/psp-dev.c | |
32 | +++ b/drivers/crypto/ccp/psp-dev.c | |
33 | @@ -84,8 +84,6 @@ done: | |
34 | ||
35 | static void sev_wait_cmd_ioc(struct psp_device *psp, unsigned int *reg) | |
36 | { | |
37 | - psp->sev_int_rcvd = 0; | |
38 | - | |
39 | wait_event(psp->sev_int_queue, psp->sev_int_rcvd); | |
40 | *reg = ioread32(psp->io_regs + PSP_CMDRESP); | |
41 | } | |
42 | @@ -148,6 +146,8 @@ static int __sev_do_cmd_locked(int cmd, | |
43 | iowrite32(phys_lsb, psp->io_regs + PSP_CMDBUFF_ADDR_LO); | |
44 | iowrite32(phys_msb, psp->io_regs + PSP_CMDBUFF_ADDR_HI); | |
45 | ||
46 | + psp->sev_int_rcvd = 0; | |
47 | + | |
48 | reg = cmd; | |
49 | reg <<= PSP_CMDRESP_CMD_SHIFT; | |
50 | reg |= PSP_CMDRESP_IOC; |