* [PATCH v2] crypto: ccp: Fix SNP panic notifier unregistration
@ 2025-06-05 20:38 Ashish Kalra
2025-06-16 20:46 ` Tom Lendacky
0 siblings, 1 reply; 2+ messages in thread
From: Ashish Kalra @ 2025-06-05 20:38 UTC (permalink / raw)
To: thomas.lendacky, john.allen, herbert, davem
Cc: aik, dionnaglaze, michael.roth, linux-crypto, linux-kernel
From: Ashish Kalra <ashish.kalra@amd.com>
Panic notifiers are invoked with RCU read lock held and when the
SNP panic notifier tries to unregister itself from the panic
notifier callback itself it causes a deadlock as notifier
unregistration does RCU synchronization.
Code flow for SNP panic notifier:
snp_shutdown_on_panic() ->
__sev_firmware_shutdown() ->
__sev_snp_shutdown_locked() ->
atomic_notifier_chain_unregister(.., &snp_panic_notifier)
Fix SNP panic notifier to unregister itself during SNP shutdown
only if panic is not in progress.
Fixes: 19860c3274fb ("crypto: ccp - Register SNP panic notifier only if SNP is enabled")
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
---
drivers/crypto/ccp/sev-dev.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 8fb94c5f006a..0ba5fe3b7883 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -1787,8 +1787,9 @@ static int __sev_snp_shutdown_locked(int *error, bool panic)
sev->snp_initialized = false;
dev_dbg(sev->dev, "SEV-SNP firmware shutdown\n");
- atomic_notifier_chain_unregister(&panic_notifier_list,
- &snp_panic_notifier);
+ if (!panic)
+ atomic_notifier_chain_unregister(&panic_notifier_list,
+ &snp_panic_notifier);
/* Reset TMR size back to default */
sev_es_tmr_size = SEV_TMR_SIZE;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] crypto: ccp: Fix SNP panic notifier unregistration
2025-06-05 20:38 [PATCH v2] crypto: ccp: Fix SNP panic notifier unregistration Ashish Kalra
@ 2025-06-16 20:46 ` Tom Lendacky
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lendacky @ 2025-06-16 20:46 UTC (permalink / raw)
To: Ashish Kalra, john.allen, herbert, davem
Cc: aik, dionnaglaze, michael.roth, linux-crypto, linux-kernel
On 6/5/25 15:38, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
>
> Panic notifiers are invoked with RCU read lock held and when the
> SNP panic notifier tries to unregister itself from the panic
> notifier callback itself it causes a deadlock as notifier
> unregistration does RCU synchronization.
>
> Code flow for SNP panic notifier:
> snp_shutdown_on_panic() ->
> __sev_firmware_shutdown() ->
> __sev_snp_shutdown_locked() ->
> atomic_notifier_chain_unregister(.., &snp_panic_notifier)
>
> Fix SNP panic notifier to unregister itself during SNP shutdown
> only if panic is not in progress.
>
> Fixes: 19860c3274fb ("crypto: ccp - Register SNP panic notifier only if SNP is enabled")
> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
Looks good code-wise. A nice comment that explains the deadlock if
called during a panic would be good to add above the check for panic.
With that added:
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
> drivers/crypto/ccp/sev-dev.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 8fb94c5f006a..0ba5fe3b7883 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -1787,8 +1787,9 @@ static int __sev_snp_shutdown_locked(int *error, bool panic)
> sev->snp_initialized = false;
> dev_dbg(sev->dev, "SEV-SNP firmware shutdown\n");
>
> - atomic_notifier_chain_unregister(&panic_notifier_list,
> - &snp_panic_notifier);
> + if (!panic)
> + atomic_notifier_chain_unregister(&panic_notifier_list,
> + &snp_panic_notifier);
>
> /* Reset TMR size back to default */
> sev_es_tmr_size = SEV_TMR_SIZE;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-16 20:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-05 20:38 [PATCH v2] crypto: ccp: Fix SNP panic notifier unregistration Ashish Kalra
2025-06-16 20:46 ` Tom Lendacky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox