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 v3 5/7] crypto: ccp - Allow SNP platform data to be queried after SNP INIT
Date: Tue, 6 Oct 2026 09:45:12 -0500	[thread overview]
Message-ID: <134b622e-fb3d-41eb-82ac-b5c73b871ff0@amd.com> (raw)
In-Reply-To: <c09108e28dbf9f54cbf63f8c912fd5815b564f33.1791212077.git.prsampat@amd.com>

On 10/5/26 11:15, Pratik R. Sampat wrote:
> In preparation for refreshing the cached SNP platform status and feature
> information after a successful firmware live update from
> DOWNLOAD_FIRMWARE_EX, allow snp_get_platform_data() to be called while
> the SNP firmware is in the INIT state.
> 
> Once SNP is initialized the firmware requires the output page of both
> commands to be firmware-owned. sev->snp_plat_status cannot satisfy that
> as it is embedded in struct sev_device, so use
> __sev_do_snp_platform_status(), which stages the output through a
> dedicated page. Allocate the SNP_FEATURE_INFO output page with
> __snp_alloc_firmware_pages(), which transitions the page to
> firmware-owned when SNP is initialized, and release it with
> __snp_free_firmware_pages(), which reclaims it before freeing.
> 
> Typically this was only ever exercised during initialization. However
> DOWNLOAD_FIRMWARE_EX can change that. Live firmware update can race with
> IOCTLs such as SEV_FACTORY_RESET which could cause operations performed
> on incorrect cached platform states. Avoid this race by wrapping the
> function under the sev_cmd_mutex.
> 
> Co-developed-by: Tycho Andersen (AMD) <tycho@kernel.org>
> Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
> Signed-off-by: Pratik R. Sampat <prsampat@amd.com>

Just a minor comment below.

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

> ---
>  drivers/crypto/ccp/sev-dev.c | 27 ++++++++++++---------------
>  1 file changed, 12 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 1ed9e61a95cc..c40401c861d3 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -131,6 +131,8 @@ static void __sev_firmware_shutdown(struct sev_device *sev, bool panic);
>  
>  static int snp_shutdown_on_panic(struct notifier_block *nb,
>  				 unsigned long reason, void *arg);
> +static int __sev_do_snp_platform_status(struct sev_user_data_snp_status *status,
> +					int *error);
>  
>  static struct notifier_block snp_panic_notifier = {
>  	.notifier_call = snp_shutdown_on_panic,
> @@ -1261,19 +1263,12 @@ static int snp_get_platform_data(struct sev_device *sev, int *error)
>  {
>  	struct sev_data_snp_feature_info snp_feat_info;
>  	struct snp_feature_info *feat_info;
> -	struct sev_data_snp_addr buf;
>  	struct page *page;
>  	int rc;
>  
> -	/*
> -	 * This function is expected to be called before SNP is
> -	 * initialized.
> -	 */
> -	if (sev->snp_initialized)
> -		return -EINVAL;
> +	lockdep_assert_held(&sev_cmd_mutex);
>  
> -	buf.address = __psp_pa(&sev->snp_plat_status);
> -	rc = sev_do_cmd(SEV_CMD_SNP_PLATFORM_STATUS, &buf, error);
> +	rc = __sev_do_snp_platform_status(&sev->snp_plat_status, error);
>  	if (rc) {
>  		dev_err(sev->dev, "SNP PLATFORM_STATUS command failed, ret = %d, error = %#x\n",
>  			rc, *error);
> @@ -1297,23 +1292,23 @@ static int snp_get_platform_data(struct sev_device *sev, int *error)
>  	 * command to ensure structure is 8-byte aligned, and does not
>  	 * cross a page boundary.
>  	 */
> -	page = alloc_page(GFP_KERNEL);
> -	if (!page)
> +	page = __snp_alloc_firmware_pages(GFP_KERNEL, 0, true);
> +	feat_info =  page ? page_address(page) : NULL;
> +	if (!feat_info)
>  		return -ENOMEM;
>  
> -	feat_info = page_address(page);

This is a bit of churn when all you have to do is replace alloc_page()
with __snp_alloc_firmware_pages(), right?

Thanks,
Tom

>  	snp_feat_info.length = sizeof(snp_feat_info);
>  	snp_feat_info.ecx_in = 0;
>  	snp_feat_info.feature_info_paddr = __psp_pa(feat_info);
>  
> -	rc = sev_do_cmd(SEV_CMD_SNP_FEATURE_INFO, &snp_feat_info, error);
> +	rc = __sev_do_cmd_locked(SEV_CMD_SNP_FEATURE_INFO, &snp_feat_info, error);
>  	if (!rc)
>  		sev->snp_feat_info_0 = *feat_info;
>  	else
>  		dev_err(sev->dev, "SNP FEATURE_INFO command failed, ret = %d, error = %#x\n",
>  			rc, *error);
>  
> -	__free_page(page);
> +	__snp_free_firmware_pages(page, 0, true);
>  
>  	return rc;
>  }
> @@ -2097,6 +2092,8 @@ static int sev_get_api_version(void)
>  	struct sev_user_data_status status;
>  	int error = 0, ret;
>  
> +	guard(mutex)(&sev_cmd_mutex);
> +
>  	/*
>  	 * Cache SNP platform status and SNP feature information
>  	 * if SNP is available.
> @@ -2107,7 +2104,7 @@ static int sev_get_api_version(void)
>  			return 1;
>  	}
>  
> -	ret = sev_platform_status(&status, &error);
> +	ret = __sev_do_cmd_locked(SEV_CMD_PLATFORM_STATUS, &status, &error);
>  	if (ret) {
>  		dev_err(sev->dev,
>  			"SEV: failed to get status. Error: %#x\n", error);


  reply	other threads:[~2026-10-06 14:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05 16:15 [Patch v3 0/7] Implement SNP live firmware update support Pratik R. Sampat
2026-10-05 16:15 ` [Patch v3 1/7] firmware_loader: Stop pinning modules on registration Pratik R. Sampat
2026-10-05 16:15 ` [Patch v3 2/7] firmware_loader: Stop pinning parent device per workqueue invocation Pratik R. Sampat
2026-10-05 16:15 ` [Patch v3 3/7] treewide: firmware_loader: Drop the unused @module argument Pratik R. Sampat
2026-10-05 16:15 ` [Patch v3 4/7] crypto: ccp - Factor out the release of the SEV firmware buffers Pratik R. Sampat
2026-10-05 16:15 ` [Patch v3 5/7] crypto: ccp - Allow SNP platform data to be queried after SNP INIT Pratik R. Sampat
2026-10-06 14:45   ` Tom Lendacky [this message]
2026-10-06 14:50     ` Pratik R. Sampat
2026-10-05 16:15 ` [Patch v3 6/7] crypto/ccp: Register with fw_uploader and always fail Pratik R. Sampat
2026-10-06 20:24   ` Shantanu Sinha
2026-10-05 16:15 ` [Patch v3 7/7] crypto/ccp: Implement SNP Download Firmware EX Pratik R. Sampat
2026-10-06 16:10   ` Tom Lendacky
2026-10-06 16:41     ` Pratik R. Sampat
2026-10-06 17:32       ` Tom Lendacky
2026-10-06 17:55         ` Pratik R. Sampat
2026-10-06 21:09           ` 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=134b622e-fb3d-41eb-82ac-b5c73b871ff0@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®