Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Ashish Kalra <Ashish.Kalra@amd.com>,
	john.allen@amd.com, herbert@gondor.apana.org.au,
	davem@davemloft.net
Cc: aik@amd.com, dionnaglaze@google.com, michael.roth@amd.com,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: ccp: Fix SNP panic notifier unregistration
Date: Wed, 4 Jun 2025 10:57:05 -0500	[thread overview]
Message-ID: <8cd27c20-6439-deec-f09c-e4f6f789761c@amd.com> (raw)
In-Reply-To: <20250602191017.60936-1-Ashish.Kalra@amd.com>

On 6/2/25 14:10, 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.

You mean that during a panic, __sev_snp_shutdown_locked() is trying to
unregister the notifier?

Wouldn't it be better to check if a panic is in progress and not try to
perform the unregister?

Or, is snp_panic_notifier() resilient enough to just always have it
registered / unregistered on module load/unload?

Also, wouldn't a better check be snp_panic_notifier.next != NULL during
sev_pci_exit()?

Thanks,
Tom

> 
> Fix SNP panic notifier to unregister itself during module unload
> if SNP is initialized.
> 
> 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 | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 8fb94c5f006a..942d93da1136 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -1787,9 +1787,6 @@ 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);
> -
>  	/* Reset TMR size back to default */
>  	sev_es_tmr_size = SEV_TMR_SIZE;
>  
> @@ -2562,4 +2559,8 @@ void sev_pci_exit(void)
>  		return;
>  
>  	sev_firmware_shutdown(sev);
> +
> +	if (sev->snp_initialized)
> +		atomic_notifier_chain_unregister(&panic_notifier_list,
> +						 &snp_panic_notifier);
>  }

  reply	other threads:[~2025-06-04 15:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-02 19:10 [PATCH] crypto: ccp: Fix SNP panic notifier unregistration Ashish Kalra
2025-06-04 15:57 ` Tom Lendacky [this message]
2025-06-04 21:31   ` Kalra, Ashish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8cd27c20-6439-deec-f09c-e4f6f789761c@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=Ashish.Kalra@amd.com \
    --cc=aik@amd.com \
    --cc=davem@davemloft.net \
    --cc=dionnaglaze@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=john.allen@amd.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox