crypto: ccp - Refactor out sev_fw_alloc()
authorPeter Gonda <pgonda@google.com>
Tue, 7 Dec 2021 23:33:04 +0000 (15:33 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 17 Dec 2021 05:59:47 +0000 (16:59 +1100)
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.

Signed-off-by: Peter Gonda <pgonda@google.com>
Reviewed-by: Marc Orr <marcorr@google.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Brijesh Singh <brijesh.singh@amd.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Marc Orr <marcorr@google.com>
Cc: Joerg Roedel <jroedel@suse.de>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: David Rientjes <rientjes@google.com>
Cc: John Allen <john.allen@amd.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-crypto@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/ccp/sev-dev.c

index ef7e8b4..8ea362a 100644 (file)
@@ -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);