Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp197895pxb; Fri, 29 Oct 2021 08:14:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeUgYnUQMdQ8JAI6frsMoEUkK3LySlm8Xyud4Kuk2AwQM6/A67O8ICEt8vqOiF94ISRxn+ X-Received: by 2002:a05:6638:1355:: with SMTP id u21mr8783157jad.34.1635520484294; Fri, 29 Oct 2021 08:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635520484; cv=none; d=google.com; s=arc-20160816; b=nQmqpFaKpmQYK5sa5uixtAD6/WrLVJtAtDY7ZxxcWLHgwoQMpZk6WhVJG3LsnTTtxq G4O6bOOWMVXaJEWL+aHyl3v+vV5QrbYPGiwcTH5Y3xzYhjKHmDaIGa2gziHykWsAbf6w AVfMhpb74okmY19CvCsNcORUmEbEHboVyJJkMX2CJ3y3vBDUed9Yy6JIaUh07UJNMPp2 MHBOvRWG/au3s6XvrxKhKmOIEQx7+yGniNpTGYAzV5q14SrA+TnsV48nGBLI5sw/VK4E EkAv6qbrfFREyi0VFWfLMCAHWIdZvN4tqdBaEuFnkWSJEZ6QHjDL7jHKsN+kHPh/H0Is wrPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qii+ptLF2i7+SBSvvUusnkbqd6rgIzG2RDHpMl1N+B4=; b=W7b8HgxZu1K4zlGZ/sTL5QztAKpB8p2Q9inNJei6yRKIjmHl5Ki0USTKZjT+pYGUtR 8uqIz4jf5oTHJ52hjidUd2oCsyAdKf+KI234eBy3bEhQunnp/Hl/agtNCx8sexMcE8YE qCK3hvaYhnAR75smA0hwf6DsJCCEjwLgvfz9NUAvRAeN/lzKn4cbNxBOQ2oBYuHM1ZQs Gz2fK5T+AmTvhv6DNVuxviADb6ZW453hlTFcQWc3l2SK93QOH+NRo+wByqeeaxY26l13 QQ9hO2Gw66FOMQBF9tfPVLD3RX0zC2SN0CleBXS+f6NCjkjPD/uirs+d4eNZHs8JQy8t ZEjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=h54gEsdy; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y13si10418994jat.0.2021.10.29.08.13.57; Fri, 29 Oct 2021 08:14:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=h54gEsdy; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbhJ2PQY (ORCPT + 99 others); Fri, 29 Oct 2021 11:16:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbhJ2PQY (ORCPT ); Fri, 29 Oct 2021 11:16:24 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66A7EC061714 for ; Fri, 29 Oct 2021 08:13:55 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id l2so17424372lji.6 for ; Fri, 29 Oct 2021 08:13:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qii+ptLF2i7+SBSvvUusnkbqd6rgIzG2RDHpMl1N+B4=; b=h54gEsdylR2vq6nHL+siTQXNFLt8HFCuK+/DSk/JuLE08Uig08MkvvcKcXosuQdmbj OqGRezQf8OATz2mbRTsYLII13C0LVXjjjSPY8MkkPTYFS5k8l/rovFyJGstwtOI5rCNU 7LNOLYgt4YK2jSSk4xwOsDbArGaBSkRjX3O47KWt3QksRkO4YbZwL24MPn1taShCxUJ2 JmjaRCRxK7PpNwC9Ypk97iugAIYa0PqDovTqSlcurVIHxoZny+KcRw2yoMuINeGP5sq4 P5G6GFFtwRslP2a5808+I3lTUyB6OAOnJ/38SA7uhPEypV5bXja0L4lcdVhW4t+3Yrxz DA8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qii+ptLF2i7+SBSvvUusnkbqd6rgIzG2RDHpMl1N+B4=; b=bztPPg5sOtbU3OAOUvmhd6ixmQceVQvvoLyBDmS8kNstMCeGJcozotQGrh30knEDz2 2nHjo/xu8Yqs4AaiTSVs32gfm1i/JOpcqOEu1lsK/P+cYYiSbU+SpB5pLHHrDbPb32CA daD3Jpt9qmFKnmCO3HTCqxY71MaAbI1N2PDvRpPCFR0JoZ0+84zvzVfjmboZAy9WjSrQ m2drNW8df0yTwXm4tlgppiZVIvxvny8xpo6bawX3UeA/S/4d8SQYWmXF+kX0Qf1RKigg GgAN1InXInFyYPVLV96gep/+SgW2FbW9OBATmmeDMZvIFXCxkr0cd6HeP+mC/nkd2Kim IiFQ== X-Gm-Message-State: AOAM532rkdcISdO6mzyxDNztAU3pN6zPYAlVvNpK7xE8IA6Mo9Uvdz1F x65xbM6w02OcOPAzvkmdeJnovEjW9+wKsD+OQs375Q== X-Received: by 2002:a2e:a90b:: with SMTP id j11mr12135141ljq.282.1635520433458; Fri, 29 Oct 2021 08:13:53 -0700 (PDT) MIME-Version: 1.0 References: <20211028175749.1219188-1-pgonda@google.com> <20211028175749.1219188-4-pgonda@google.com> In-Reply-To: From: Peter Gonda Date: Fri, 29 Oct 2021 09:13:41 -0600 Message-ID: Subject: Re: [PATCH 3/4] crypto: ccp - Refactor out sev_fw_alloc() To: Tom Lendacky Cc: David Rientjes , Brijesh Singh , Marc Orr , Joerg Roedel , Herbert Xu , John Allen , "David S. Miller" , Paolo Bonzini , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Oct 29, 2021 at 7:48 AM Tom Lendacky wrote: > > 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 > > Acked-by: David Rientjes > > Cc: Tom Lendacky > > Cc: Brijesh Singh > > Cc: Marc Orr > > Cc: Joerg Roedel > > Cc: Herbert Xu > > Cc: David Rientjes > > Cc: John Allen > > Cc: "David S. Miller" > > Cc: Paolo Bonzini ( > > 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. Oh I missed that. Removed. > > > + > > + page = alloc_pages(GFP_KERNEL, order); > > Without the above check, you can just replace the 'order' variable with > 'get_order(len)'. Moved the get_order() inline here as suggested. > > 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); > >