Skip to contentSkip to conversation

crypto: ccp: Fix SNP panic notifier unregistration

PATCH RESEND In review Ashish Kalra 2 participants 2 messages Jun 16, 2025 – Jun 23, 2025

Subsystems (4)
lore
Share & tools
lore

Ashish Kalra

author maintainer
#0 lore raw

PATCH RESEND v3 1/1 crypto: ccp: Fix SNP panic notifier unregistration

From: Ashish Kalra <[email protected]>

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")
---
 drivers/crypto/ccp/sev-dev.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/crypto/ccp/sev-dev.c +8 -2
index 8fb94c5f006a..17edc6bf5622 100644
@@ -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;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 16 lines · Ashish Kalra

From: Ashish Kalra <[email protected]>

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.

Quoted 7 lines
Fixes 19860c3274fb ("crypto: ccp - Register SNP panic notifier only if SNP is enabled")
---
 drivers/crypto/ccp/sev-dev.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt