WSL2-Linux-Kernel/drivers/crypto/ccp
Jeremi Piotrowski 21ad89e197 crypto: ccp - Clear PSP interrupt status register before calling handler
[ Upstream commit 45121ad4a1 ]

The PSP IRQ is edge-triggered (MSI or MSI-X) in all cases supported by
the psp module so clear the interrupt status register early in the
handler to prevent missed interrupts. sev_irq_handler() calls wake_up()
on a wait queue, which can result in a new command being submitted from
a different CPU. This then races with the clearing of isr and can result
in missed interrupts. A missed interrupt results in a command waiting
until it times out, which results in the psp being declared dead.

This is unlikely on bare metal, but has been observed when running
virtualized. In the cases where this is observed, sev->cmdresp_reg has
PSP_CMDRESP_RESP set which indicates that the command was processed
correctly but no interrupt was asserted.

The full sequence of events looks like this:

CPU 1: submits SEV cmd #1
CPU 1: calls wait_event_timeout()
CPU 0: enters psp_irq_handler()
CPU 0: calls sev_handler()->wake_up()
CPU 1: wakes up; finishes processing cmd #1
CPU 1: submits SEV cmd #2
CPU 1: calls wait_event_timeout()
PSP:   finishes processing cmd #2; interrupt status is still set; no interrupt
CPU 0: clears intsts
CPU 0: exits psp_irq_handler()
CPU 1: wait_event_timeout() times out; psp_dead=true

Fixes: 200664d523 ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")
Cc: stable@vger.kernel.org
Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-05-17 11:50:13 +02:00
..
Kconfig
Makefile
ccp-crypto-aes-cmac.c
ccp-crypto-aes-galois.c
ccp-crypto-aes-xts.c
ccp-crypto-aes.c
ccp-crypto-des3.c
ccp-crypto-main.c crypto: ccp - Use DEFINE_SPINLOCK() for spinlock 2021-04-09 17:41:06 +10:00
ccp-crypto-rsa.c
ccp-crypto-sha.c
ccp-crypto.h
ccp-debugfs.c
ccp-dev-v3.c
ccp-dev-v5.c
ccp-dev.c crypto: ccp: ccp-dev: Fix a little doc-rot 2021-05-28 15:11:45 +08:00
ccp-dev.h
ccp-dmaengine.c crypto: ccp - Failure on re-initialization due to duplicate sysfs filename 2023-03-10 09:39:11 +01:00
ccp-ops.c crypto: ccp - fix resource leaks in ccp_run_aes_gcm_cmd() 2021-09-24 15:58:41 +08:00
psp-dev.c crypto: ccp - Clear PSP interrupt status register before calling handler 2023-05-17 11:50:13 +02:00
psp-dev.h
sev-dev.c crypto: ccp - Flush the SEV-ES TMR memory before giving it to firmware 2023-03-10 09:39:13 +01:00
sev-dev.h crypto: ccp: Use the stack and common buffer for INIT command 2021-04-21 12:20:07 -04:00
sp-dev.c crypto: ccp - Make ccp_dev_suspend and ccp_dev_resume void functions 2021-04-22 17:31:31 +10:00
sp-dev.h crypto: ccp - Make ccp_dev_suspend and ccp_dev_resume void functions 2021-04-22 17:31:31 +10:00
sp-pci.c crypto: ccp - Add support for TEE for PCI ID 0x14CA 2023-01-12 11:58:58 +01:00
sp-platform.c
tee-dev.c crypto: ccp - fix command queuing to TEE ring buffer 2021-03-26 20:02:34 +11:00
tee-dev.h crypto: ccp - fix command queuing to TEE ring buffer 2021-03-26 20:02:34 +11:00