[Patch v2 5/7] crypto: ccp - Allow SNP platform data to be queried after SNP INIT

From: Pratik R. Sampat

Date: Fri Sep 18 2026 - 13:17:50 EST


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@xxxxxxxxxx>
Signed-off-by: Tycho Andersen (AMD) <tycho@xxxxxxxxxx>
Signed-off-by: Pratik R. Sampat <prsampat@xxxxxxx>
---
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