]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: ccp - Fix SNP panic notifier unregistration
authorAshish Kalra <ashish.kalra@amd.com>
Mon, 16 Jun 2025 21:50:27 +0000 (21:50 +0000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 23 Jun 2025 09:00:27 +0000 (17:00 +0800)
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.

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Cc: stable@vger.kernel.org
Fixes: 19860c3274fb ("crypto: ccp - Register SNP panic notifier only if SNP is enabled")
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/ccp/sev-dev.c

index 8fb94c5f006ae9a0299c71d285ef6d5b1a6c8168..17edc6bf56224f194f79b209313c62cd3113dd8f 100644 (file)
@@ -1787,8 +1787,14 @@ 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);
+       /*
+        * __sev_snp_shutdown_locked() deadlocks when it tries to unregister
+        * itself during panic as the panic notifier is called with RCU read
+        * lock held and notifier unregistration does RCU synchronization.
+        */
+       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;