From: "Pratik R. Sampat" <prsampat@amd.com>
To: <mcgrof@kernel.org>, <russ.weight@linux.dev>, <dakr@kernel.org>,
<ashish.kalra@amd.com>, <thomas.lendacky@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>,
<prsampat@amd.com>
Subject: [Patch v4 5/7] crypto: ccp - Allow SNP platform data to be queried after SNP INIT
Date: Thu, 15 Oct 2026 02:14:07 +0000 [thread overview]
Message-ID: <d79a84d4fa9da4c02d21a6a88f0651c66b0e2ef3.1792014060.git.prsampat@amd.com> (raw)
In-Reply-To: <cover.1792014060.git.prsampat@amd.com>
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.
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
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>
---
v3..v4:
* Collected reviewed-by tags
* Simplify snp_alloc_firmware_pages() error handing - Tom
---
drivers/crypto/ccp/sev-dev.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 1ed9e61a95cc..76698a7a1a3c 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,7 +1292,7 @@ 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);
+ page = __snp_alloc_firmware_pages(GFP_KERNEL, 0, true);
if (!page)
return -ENOMEM;
@@ -1306,14 +1301,14 @@ static int snp_get_platform_data(struct sev_device *sev, int *error)
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);
--
2.43.0
next prev parent reply other threads:[~2026-10-15 2:15 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
2026-10-15 2:14 ` Pratik R. Sampat [this message]
2026-10-15 18:02 ` [Patch v4 5/7] crypto: ccp - Allow SNP platform data to be queried after SNP INIT 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=d79a84d4fa9da4c02d21a6a88f0651c66b0e2ef3.1792014060.git.prsampat@amd.com \
--to=prsampat@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=rafael@kernel.org \
--cc=russ.weight@linux.dev \
--cc=shansinha@google.com \
--cc=thomas.lendacky@amd.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®