public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Peter Gonda <pgonda@google.com>
Cc: David Rientjes <rientjes@google.com>,
	Brijesh Singh <brijesh.singh@amd.com>,
	Marc Orr <marcorr@google.com>, Joerg Roedel <jroedel@suse.de>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	John Allen <john.allen@amd.com>,
	"David S. Miller" <davem@davemloft.net>,
	Paolo Bonzini <pbonzini@redhat.com>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] crypto: ccp - Refactor out sev_fw_alloc()
Date: Fri, 29 Oct 2021 08:48:32 -0500	[thread overview]
Message-ID: <d3235e92-e29a-3b52-540d-4a49ce53389b@amd.com> (raw)
In-Reply-To: <20211028175749.1219188-4-pgonda@google.com>

On 10/28/21 12:57 PM, Peter Gonda wrote:
> Creates 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>
> Acked-by: David Rientjes <rientjes@google.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
> ---
>   drivers/crypto/ccp/sev-dev.c | 24 +++++++++++++++++-------
>   1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index e4bc833949a0..b568ae734857 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -141,6 +141,21 @@ static int sev_cmd_buffer_len(int cmd)
>   	return 0;
>   }
>   
> +static void *sev_fw_alloc(unsigned long len)
> +{
> +	const int order = get_order(len);

This should be an unsigned int to match the function definition, but is 
probably not needed given the comment below.

> +	struct page *page;
> +
> +	if (order > MAX_ORDER-1)
> +		return NULL;

I believe alloc_pages() already does this check (and provides a warning 
unless requested not to), so this check isn't needed.

> +
> +	page = alloc_pages(GFP_KERNEL, order);

Without the above check, you can just replace the 'order' variable with 
'get_order(len)'.

Thanks,
Tom

> +	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;
> @@ -1076,7 +1091,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 = 0, rc;
>   
>   	if (!sev)
> @@ -1092,14 +1106,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);
> 

  reply	other threads:[~2021-10-29 13:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28 17:57 [PATCH 0/4] Add SEV_INIT_EX support Peter Gonda
2021-10-28 17:57 ` [PATCH 1/4] crypto: ccp - Fix SEV_INIT error logging on init Peter Gonda
2021-10-29 13:41   ` Tom Lendacky
2021-11-01 16:28   ` Marc Orr
2021-10-28 17:57 ` [PATCH 2/4] crypto: ccp - Move SEV_INIT retry for corrupted data Peter Gonda
2021-10-29 13:42   ` Tom Lendacky
2021-11-01 16:28   ` Marc Orr
2021-10-28 17:57 ` [PATCH 3/4] crypto: ccp - Refactor out sev_fw_alloc() Peter Gonda
2021-10-29 13:48   ` Tom Lendacky [this message]
2021-10-29 15:13     ` Peter Gonda
2021-11-01 16:29   ` Marc Orr
2021-10-28 17:57 ` [PATCH 4/4] crypto: ccp - Add SEV_INIT_EX support Peter Gonda
2021-10-29  9:27   ` kernel test robot
2021-10-29 14:45   ` Tom Lendacky
2021-10-29 17:26     ` Peter Gonda
2021-10-29 17:56       ` Tom Lendacky
2021-11-01 17:18         ` Peter Gonda
     [not found]       ` <SN6PR12MB27981792BC31C8FB0CB169B5F7879@SN6PR12MB2798.namprd12.prod.outlook.com>
2021-11-01 17:16         ` Peter Gonda
2021-11-01 16:30   ` Marc Orr
2021-11-01 16:31 ` [PATCH 0/4] " Marc Orr

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=d3235e92-e29a-3b52-540d-4a49ce53389b@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=brijesh.singh@amd.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=john.allen@amd.com \
    --cc=jroedel@suse.de \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcorr@google.com \
    --cc=pbonzini@redhat.com \
    --cc=pgonda@google.com \
    --cc=rientjes@google.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