Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Tycho Andersen <tycho@kernel.org>
To: Ashish Kalra <ashish.kalra@amd.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Tycho Andersen (AMD)" <tycho@kernel.org>
Subject: [PATCH v1 2/2] crypto: ccp - Drop support for SNP without INIT_EX
Date: Tue,  3 Nov 2026 11:10:02 -0700	[thread overview]
Message-ID: <20261103181002.2200214-2-tycho@kernel.org> (raw)
In-Reply-To: <20261103181002.2200214-1-tycho@kernel.org>

From: "Tycho Andersen (AMD)" <tycho@kernel.org>

Now that the minimum version of firmware allowed is 1.55,
__sev_snp_init_locked() no longer needs the special case for version 1.52
so delete it and its associated locals.

Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 drivers/crypto/ccp/sev-dev.c | 110 +++++++++++++++--------------------
 1 file changed, 46 insertions(+), 64 deletions(-)

diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 13e6af5549f5..ad296c5e94dd 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -1511,8 +1511,8 @@ static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid)
 	struct psp_device *psp = psp_master;
 	struct sev_data_snp_init_ex data = {};
 	struct sev_device *sev;
-	void *arg = &data;
-	int cmd, rc = 0;
+	bool tio_supp;
+	int rc = 0;
 
 	if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
 		return -ENODEV;
@@ -1532,73 +1532,56 @@ static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid)
 	if (rc)
 		return rc;
 
+	tio_supp = !!(sev->snp_feat_info_0.ebx & SNP_SEV_TIO_SUPPORTED);
+
 	/*
-	 * Starting in SNP firmware v1.52, the SNP_INIT_EX command takes a list
-	 * of system physical address ranges to convert into HV-fixed page
-	 * states during the RMP initialization.  For instance, the memory that
-	 * UEFI reserves should be included in the that list. This allows system
-	 * components that occasionally write to memory (e.g. logging to UEFI
-	 * reserved regions) to not fail due to RMP initialization and SNP
-	 * enablement.
-	 *
+	 * Firmware checks that the pages containing the ranges enumerated
+	 * in the RANGES structure are either in the default page state or in the
+	 * firmware page state.
 	 */
-	if (sev_version_greater_or_equal(SNP_MIN_API_MAJOR, 52)) {
-		bool tio_supp = !!(sev->snp_feat_info_0.ebx & SNP_SEV_TIO_SUPPORTED);
-
-		/*
-		 * Firmware checks that the pages containing the ranges enumerated
-		 * in the RANGES structure are either in the default page state or in the
-		 * firmware page state.
-		 */
-		snp_range_list = kzalloc(PAGE_SIZE, GFP_KERNEL);
-		if (!snp_range_list) {
-			dev_err(sev->dev,
-				"SEV: SNP_INIT_EX range list memory allocation failed\n");
-			return -ENOMEM;
-		}
-
-		/*
-		 * Retrieve all reserved memory regions from the e820 memory map
-		 * to be setup as HV-fixed pages.
-		 */
-		rc = walk_iomem_res_desc(IORES_DESC_NONE, IORESOURCE_MEM, 0, ~0,
-					 snp_range_list, snp_filter_reserved_mem_regions);
-		if (rc) {
-			dev_err(sev->dev,
-				"SEV: SNP_INIT_EX walk_iomem_res_desc failed rc = %d\n", rc);
-			return rc;
-		}
+	snp_range_list = kzalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!snp_range_list) {
+		dev_err(sev->dev,
+			"SEV: SNP_INIT_EX range list memory allocation failed\n");
+		return -ENOMEM;
+	}
 
-		/*
-		 * Add HV_Fixed pages from other PSP sub-devices, such as SFS to the
-		 * HV_Fixed page list.
-		 */
-		snp_add_hv_fixed_pages(sev, snp_range_list);
+	/*
+	 * Retrieve all reserved memory regions from the e820 memory map
+	 * to be setup as HV-fixed pages.
+	 */
+	rc = walk_iomem_res_desc(IORES_DESC_NONE, IORESOURCE_MEM, 0, ~0,
+				 snp_range_list, snp_filter_reserved_mem_regions);
+	if (rc) {
+		dev_err(sev->dev,
+			"SEV: SNP_INIT_EX walk_iomem_res_desc failed rc = %d\n", rc);
+		return rc;
+	}
 
-		if (max_snp_asid) {
-			data.ciphertext_hiding_en = 1;
-			data.max_snp_asid = max_snp_asid;
-		}
+	/*
+	 * Add HV_Fixed pages from other PSP sub-devices, such as SFS to the
+	 * HV_Fixed page list.
+	 */
+	snp_add_hv_fixed_pages(sev, snp_range_list);
 
-		data.init_rmp = 1;
-		data.list_paddr_en = 1;
-		data.list_paddr = __psp_pa(snp_range_list);
+	if (max_snp_asid) {
+		data.ciphertext_hiding_en = 1;
+		data.max_snp_asid = max_snp_asid;
+	}
 
-		data.tio_en = tio_supp && sev_tio_enabled && amd_iommu_sev_tio_supported();
+	data.init_rmp = 1;
+	data.list_paddr_en = 1;
+	data.list_paddr = __psp_pa(snp_range_list);
 
-		/*
-		 * When psp_init_on_probe is disabled, the userspace calling
-		 * SEV ioctl can inadvertently shut down SNP and SEV-TIO causing
-		 * unexpected state loss.
-		 */
-		if (data.tio_en && !psp_init_on_probe)
-			dev_warn(sev->dev, "SEV-TIO as incompatible with psp_init_on_probe=0\n");
+	data.tio_en = tio_supp && sev_tio_enabled && amd_iommu_sev_tio_supported();
 
-		cmd = SEV_CMD_SNP_INIT_EX;
-	} else {
-		cmd = SEV_CMD_SNP_INIT;
-		arg = NULL;
-	}
+	/*
+	 * When psp_init_on_probe is disabled, the userspace calling
+	 * SEV ioctl can inadvertently shut down SNP and SEV-TIO causing
+	 * unexpected state loss.
+	 */
+	if (data.tio_en && !psp_init_on_probe)
+		dev_warn(sev->dev, "SEV-TIO as incompatible with psp_init_on_probe=0\n");
 
 	/*
 	 * The following sequence must be issued before launching the first SNP
@@ -1612,10 +1595,9 @@ static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid)
 	 */
 	wbinvd_on_all_cpus();
 
-	rc = __sev_do_cmd_locked(cmd, arg, error);
+	rc = __sev_do_cmd_locked(SEV_CMD_SNP_INIT_EX, &data, error);
 	if (rc) {
-		dev_err(sev->dev, "SEV-SNP: %s failed rc %d, error %#x\n",
-			cmd == SEV_CMD_SNP_INIT_EX ? "SNP_INIT_EX" : "SNP_INIT",
+		dev_err(sev->dev, "SEV-SNP: SNP_INIT_EX failed rc %d, error %#x\n",
 			rc, *error);
 		return rc;
 	}
-- 
2.56.0


      reply	other threads:[~2026-11-03 18:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 18:10 [PATCH v1 1/2] crypto: ccp - Bump minimum firmware version for SEV-SNP support Tycho Andersen
2026-11-03 18:10 ` Tycho Andersen [this message]

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=20261103181002.2200214-2-tycho@kernel.org \
    --to=tycho@kernel.org \
    --cc=ashish.kalra@amd.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thomas.lendacky@amd.com \
    /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