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 v2 5/7] crypto: ccp - Allow SNP platform data to be queried after SNP INIT
Date: Fri, 18 Sep 2026 16:40:59 +0000 [thread overview]
Message-ID: <0f67392979b8db85aacd62fe547d9e2937a93393.1789749016.git.prsampat@amd.com> (raw)
In-Reply-To: <cover.1789749016.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, and allocate the SNP_FEATURE_INFO output page with
snp_alloc_firmware_page(), which transitions the page to firmware-owned
when SNP is initialized. snp_free_firmware_page() reclaims it once the
feature information has been copied out.
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>
---
v1..v2:
Use snp_[alloc|free]_firmware_page() to transition pages to and from
firmware-owned state - Tom
---
drivers/crypto/ccp/sev-dev.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 1ed9e61a95cc..3704f52bd08d 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,11 @@ 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;
-
- buf.address = __psp_pa(&sev->snp_plat_status);
- rc = sev_do_cmd(SEV_CMD_SNP_PLATFORM_STATUS, &buf, error);
+ mutex_lock(&sev_cmd_mutex);
+ rc = __sev_do_snp_platform_status(&sev->snp_plat_status, error);
+ mutex_unlock(&sev_cmd_mutex);
if (rc) {
dev_err(sev->dev, "SNP PLATFORM_STATUS command failed, ret = %d, error = %#x\n",
rc, *error);
@@ -1297,11 +1291,10 @@ 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)
+ feat_info = snp_alloc_firmware_page(GFP_KERNEL);
+ if (!feat_info)
return -ENOMEM;
- feat_info = page_address(page);
snp_feat_info.length = sizeof(snp_feat_info);
snp_feat_info.ecx_in = 0;
snp_feat_info.feature_info_paddr = __psp_pa(feat_info);
@@ -1313,7 +1306,7 @@ static int snp_get_platform_data(struct sev_device *sev, int *error)
dev_err(sev->dev, "SNP FEATURE_INFO command failed, ret = %d, error = %#x\n",
rc, *error);
- __free_page(page);
+ snp_free_firmware_page(feat_info);
return rc;
}
--
2.43.0
next prev parent reply other threads:[~2026-09-18 16:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 16:40 [Patch v2 0/7] Implement SNP live firmware update support Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 1/7] firmware_loader: Stop pinning modules on registration Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 2/7] firmware_loader: Stop pinning parent device per workqueue invocation Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 3/7] treewide: firmware_loader: Drop the unused @module argument Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 4/7] crypto: ccp - Factor out the release of the SEV firmware buffers Pratik R. Sampat
2026-09-18 16:40 ` Pratik R. Sampat [this message]
2026-09-18 16:41 ` [Patch v2 6/7] crypto/ccp: Register with fw_uploader and always fail Pratik R. Sampat
2026-09-18 16:41 ` [Patch v2 7/7] crypto/ccp: Implement SNP Download Firmware EX Pratik R. Sampat
2026-09-24 21:37 ` Shantanu Sinha
2026-09-25 21:11 ` Pratik R. Sampat
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=0f67392979b8db85aacd62fe547d9e2937a93393.1789749016.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®