Skip to contentSkip to conversation

crypto: ccp - Refactor out sev_fw_alloc()

PATCH In review Peter Gonda 2 participants 2 messages Dec 3, 2021 – Dec 5, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 3/5 crypto: ccp - Refactor out sev_fw_alloc()

Create a helper function sev_fw_alloc() which can be used to allocate aligned memory regions for use by the PSP firmware. Currently only used for the SEV-ES TMR region but will be used for the SEV_INIT_EX NV memory region.

Cc Tom Lendacky <[email protected]>
Cc Brijesh Singh <[email protected]>
Cc Marc Orr <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Herbert Xu <[email protected]>
Cc David Rientjes <[email protected]>
Cc John Allen <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Paolo Bonzini <[email protected]>

---

Mistakenly send old patch, this is the fixed version.

---
 drivers/crypto/ccp/sev-dev.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/crypto/ccp/sev-dev.c +13 -7
index ef7e8b4c6e02..8ea362ac014f 100644
@@ -141,6 +141,17 @@ static int sev_cmd_buffer_len(int cmd)
 	return 0;
 }
 
+static void *sev_fw_alloc(unsigned long len)
+{
+	struct page *page;
+
+	page = alloc_pages(GFP_KERNEL, get_order(len));
+	if (!page)
+		return NULL;
+
+	return page_address(page);
+}
+
 static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
 {
 	struct psp_device *psp = psp_master;
@@ -1078,7 +1089,6 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user);
 void sev_pci_init(void)
 {
 	struct sev_device *sev = psp_master->sev_data;
-	struct page *tmr_page;
 	int error, rc;
 
 	if (!sev)
@@ -1094,14 +1104,10 @@ void sev_pci_init(void)
 		sev_get_api_version();
 
 	/* Obtain the TMR memory area for SEV-ES use */
-	tmr_page = alloc_pages(GFP_KERNEL, get_order(SEV_ES_TMR_SIZE));
-	if (tmr_page) {
-		sev_es_tmr = page_address(tmr_page);
-	} else {
-		sev_es_tmr = NULL;
+	sev_es_tmr = sev_fw_alloc(SEV_ES_TMR_SIZE);
+	if (!sev_es_tmr)
 		dev_warn(sev->dev,
 			 "SEV: TMR allocation failed, SEV-ES support unavailable\n");
-	}
 
 	/* Initialize the platform */
 	rc = sev_platform_init(&error);
Signature · 1 line
2.34.1.400.ga245620fadb-goog
maintainer
#1 lore raw
Quoted 19 lines · Peter Gonda

Create a helper function sev_fw_alloc() which can be used to allocate aligned memory regions for use by the PSP firmware. Currently only used for the SEV-ES TMR region but will be used for the SEV_INIT_EX NV memory region.

Cc Tom Lendacky <[email protected]>
Cc Brijesh Singh <[email protected]>
Cc Marc Orr <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Herbert Xu <[email protected]>
Cc David Rientjes <[email protected]>
Cc John Allen <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 7 lines

---

Mistakenly send old patch, this is the fixed version.

---
 drivers/crypto/ccp/sev-dev.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

Please resubmit the whole series.

Otherwise automatic testing won't pick this up.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt