mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: "Pratik R. Sampat" <prsampat@amd.com>,
	mcgrof@kernel.org, russ.weight@linux.dev, dakr@kernel.org,
	ashish.kalra@amd.com, herbert@gondor.apana.org.au,
	davem@davemloft.net
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	gregkh@linuxfoundation.org, rafael@kernel.org,
	chao.gao@intel.com, aik@amd.com, tycho@kernel.org,
	nikunj@amd.com, michael.roth@amd.com, shansinha@google.com
Subject: Re: [Patch v4 4/7] crypto: ccp - Factor out the release of the SEV firmware buffers
Date: Thu, 15 Oct 2026 12:53:13 -0500	[thread overview]
Message-ID: <e409b256-4df6-4d16-bdb0-e9a4479912cf@amd.com> (raw)
In-Reply-To: <d7eb100a9d91641e24f3a03a01f746d20204983f.1792014060.git.prsampat@amd.com>

On 10/14/26 21:14, Pratik R. Sampat wrote:
> __sev_firmware_shutdown() reclaims and frees the TMR and the INIT_EX NV
> area once the platform has been taken down. Move that into a helper so
> that other paths which de-initialize the platform can reuse the same
> path.
> 
> No functional change intended.
> 
> Suggested-by: Shantanu Sinha <shansinha@google.com>
> Signed-off-by: Pratik R. Sampat <prsampat@amd.com>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
> v3..v4:
> No change
> ---
>  drivers/crypto/ccp/sev-dev.c | 55 ++++++++++++++++++++----------------
>  1 file changed, 30 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index f833cb7e4da3..1ed9e61a95cc 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -1881,6 +1881,35 @@ static int __sev_platform_shutdown_locked(int *error)
>  	return ret;
>  }
>  
> +static void __sev_release_firmware_buffers(bool panic)
> +{
> +	if (sev_es_tmr) {
> +		/*
> +		 * The TMR area was encrypted, flush it from the cache.
> +		 *
> +		 * If invoked during panic handling, local interrupts are
> +		 * disabled and all CPUs are stopped, so wbinvd_on_all_cpus()
> +		 * can't be used. In that case, wbinvd() is done on remote CPUs
> +		 * via the NMI callback, and done for this CPU later during
> +		 * SNP shutdown, so wbinvd_on_all_cpus() can be skipped.
> +		 */
> +		if (!panic)
> +			wbinvd_on_all_cpus();
> +
> +		__snp_free_firmware_pages(virt_to_page(sev_es_tmr),
> +					  get_order(sev_es_tmr_size),
> +					  true);
> +		sev_es_tmr = NULL;
> +	}
> +
> +	if (sev_init_ex_buffer) {
> +		__snp_free_firmware_pages(virt_to_page(sev_init_ex_buffer),
> +					  get_order(NV_LENGTH),
> +					  true);
> +		sev_init_ex_buffer = NULL;
> +	}
> +}
> +
>  static int sev_get_platform_state(int *state, int *error)
>  {
>  	struct sev_user_data_status data;
> @@ -2906,31 +2935,7 @@ static void __sev_firmware_shutdown(struct sev_device *sev, bool panic)
>  
>  	__sev_platform_shutdown_locked(&error);
>  
> -	if (sev_es_tmr) {
> -		/*
> -		 * The TMR area was encrypted, flush it from the cache.
> -		 *
> -		 * If invoked during panic handling, local interrupts are
> -		 * disabled and all CPUs are stopped, so wbinvd_on_all_cpus()
> -		 * can't be used. In that case, wbinvd() is done on remote CPUs
> -		 * via the NMI callback, and done for this CPU later during
> -		 * SNP shutdown, so wbinvd_on_all_cpus() can be skipped.
> -		 */
> -		if (!panic)
> -			wbinvd_on_all_cpus();
> -
> -		__snp_free_firmware_pages(virt_to_page(sev_es_tmr),
> -					  get_order(sev_es_tmr_size),
> -					  true);
> -		sev_es_tmr = NULL;
> -	}
> -
> -	if (sev_init_ex_buffer) {
> -		__snp_free_firmware_pages(virt_to_page(sev_init_ex_buffer),
> -					  get_order(NV_LENGTH),
> -					  true);
> -		sev_init_ex_buffer = NULL;
> -	}
> +	__sev_release_firmware_buffers(panic);
>  
>  	__sev_snp_shutdown_locked(&error, panic);
>  }


  reply	other threads:[~2026-10-15 17:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  2:14 [Patch v4 0/7] Implement SNP live firmware update support Pratik R. Sampat
2026-10-15  2:14 ` [Patch v4 1/7] firmware_loader: Stop pinning modules on registration Pratik R. Sampat
2026-10-15  2:14 ` [Patch v4 2/7] firmware_loader: Stop pinning parent device per workqueue invocation Pratik R. Sampat
2026-10-15  2:14 ` [Patch v4 3/7] treewide: firmware_loader: Drop the unused @module argument Pratik R. Sampat
2026-10-15  2:14 ` [Patch v4 4/7] crypto: ccp - Factor out the release of the SEV firmware buffers Pratik R. Sampat
2026-10-15 17:53   ` Tom Lendacky [this message]
2026-10-15  2:14 ` [Patch v4 5/7] crypto: ccp - Allow SNP platform data to be queried after SNP INIT Pratik R. Sampat
2026-10-15 18:02   ` Tom Lendacky
2026-10-15  2:14 ` [Patch v4 6/7] crypto/ccp: Register with fw_uploader and always fail Pratik R. Sampat
2026-10-15  2:14 ` [Patch v4 7/7] crypto/ccp: Implement SNP Download Firmware EX Pratik R. Sampat
2026-10-15 19:38   ` Tycho Andersen
2026-10-15 21:09     ` Pratik R. Sampat
2026-10-16  1:22       ` Shantanu Sinha

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=e409b256-4df6-4d16-bdb0-e9a4479912cf@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=aik@amd.com \
    --cc=ashish.kalra@amd.com \
    --cc=chao.gao@intel.com \
    --cc=dakr@kernel.org \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=michael.roth@amd.com \
    --cc=nikunj@amd.com \
    --cc=prsampat@amd.com \
    --cc=rafael@kernel.org \
    --cc=russ.weight@linux.dev \
    --cc=shansinha@google.com \
    --cc=tycho@kernel.org \
    /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

all inboxes | Powered by JetHome®