Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1838707pxb; Thu, 28 Oct 2021 10:58:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyG4goy/oA2ZapMndHSe667KoQja7MbgK67gF9uYsiYIsxGSGskIUToUoft+GTy++0tpdd8 X-Received: by 2002:a05:6a00:13a3:b0:47c:126:3596 with SMTP id t35-20020a056a0013a300b0047c01263596mr5756114pfg.5.1635443922545; Thu, 28 Oct 2021 10:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635443922; cv=none; d=google.com; s=arc-20160816; b=WuokRtcUkxS9u0/bqWqWGMHDCy6lIAAoiExB574y8yM31ncPFOUWqMqD8q6dAoditH yU7T1RTHPi8t8lXlayD1RD3fQfG/tZPhjTKPkMf84Vn1FiJ5uiG0pUE82TbUP7TdgNWM NXX6Lsa2RyWtOpRv3xIWFSXNZSxQasKJdQMplAjk8c7tfJORG8qpLHCRrvp44ANfcPDl 5Vjw2wz61eMsA9peJYtnHmUQQOB3QD7p6+263DxmLLX2IUSom620U+t8eEmSg/NJtAUN CRYpSUtDLwKJ5V/jCNHuTVdZuRBuUkrdEfTUwu3/4+CFPmEowRAl7vd5D1hpuLpkdNLL e5Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=pUbRXJ25fy+xevW413+zLfvLf6jaUw9jcscxCVLb4Cs=; b=uixsZd1P2yuW6koDtCWrQlSPIVhzJEuPPJeUQ61m4OxHuyOKCgAMayUdE9QLxYBEvs z5bPd4yTBvUS5mFARNaVu63jJh7ENz/rqj8X4FEnypU+dIMLeLfzA4sXi3RB4OPneC7W PodOO5u2bTu7ycBQDyTnxlub7Dy+4sPxJH+9/Yv7IvVJG9i+rqLhRFE52O+qAlWNILSo pTWUJY3pZ7rDKu7uGv0FE18D41WG6UsJIxNsxnXCqat64Y7ncxFpBHUgxy4B0IK7yd43 2/8OReaTXqYuwz9RHslQM9/KAe9su3pZqzxJP+59IcxjoksBgJx75T6eFip4chyb12LU IffA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tkzxxgdJ; 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 o13si5282528pgv.352.2021.10.28.10.58.23; Thu, 28 Oct 2021 10:58:42 -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=tkzxxgdJ; 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 S231208AbhJ1SAf (ORCPT + 99 others); Thu, 28 Oct 2021 14:00:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231127AbhJ1SAa (ORCPT ); Thu, 28 Oct 2021 14:00:30 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05A87C061243 for ; Thu, 28 Oct 2021 10:58:00 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id p19-20020a17090a429300b001a1fd412f57so3697883pjg.9 for ; Thu, 28 Oct 2021 10:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=pUbRXJ25fy+xevW413+zLfvLf6jaUw9jcscxCVLb4Cs=; b=tkzxxgdJUgne+bl6xlY7dEKbNgEmlTUQE+6kwYO8iNVjnyzADc9loZ30ez3Q9ahv9y ojmm355V9dEk71j5eJIdmHNGrx8kvDHcy1Ru1wuQ34r26D+8e/1yHrbxoG0LZZ3G3W1q bwOTwtAkcVgC4ZUyxtGoqdcF1xanaCvfMzf5GqYcCaK0XLod7MxB5T4mmYNCmLrihBuj DK+AhwB7Knr5qV2tpy+xleOBBgzI03/bZ9WfG/GfM5A9Gax0UmGX1xpjiDmPNtVxg4rL 9qKzQv/MeC2x60x1oi5LP02ZNETRklZWkVnlwl9zFHIMx8kuUMtVZvnokxW7VQnVlD5I jdbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=pUbRXJ25fy+xevW413+zLfvLf6jaUw9jcscxCVLb4Cs=; b=aQYqL09GUHApKkv8pE04sEko3kq3N18vSRk7UDBbMAT9nngunJPhY6rDVamHd0qFfd +jnN55rPaJ4MqffcA+nePwCbFNZcRj3773SRnYaj6xHcK3bVr9sjnCXxREwAzdItK0Kv JEmp+Qtrtv/Zp44EludeTNVMl8DLMlIUOu5OdF++CHQrBCoZIHGOqM0uykflpJgpnBPf d5x1hPLTL+52A02byWxUSjC76lxtlUU9swtmNxd/NXzBFFB+blq+ZE4BtdT4QlYpZ7aX FUDvE8i5rQGM/qj3p4XchlHqCstOjpQrZDpZrvrllHMhLXA7UiIZRaoid3+8lGABlglZ v4uA== X-Gm-Message-State: AOAM532OkobYXihSvOdygk8JkyknuLLEk5K/+hsrgxb9YdSTNUroBMQx 4DVFPeUcn63AoQkVlpPOSV2FZOtBEvY= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:204:41d0:ac84:3b61:5938]) (user=pgonda job=sendgmr) by 2002:a63:5646:: with SMTP id g6mr3803105pgm.216.1635443879499; Thu, 28 Oct 2021 10:57:59 -0700 (PDT) Date: Thu, 28 Oct 2021 10:57:48 -0700 In-Reply-To: <20211028175749.1219188-1-pgonda@google.com> Message-Id: <20211028175749.1219188-4-pgonda@google.com> Mime-Version: 1.0 References: <20211028175749.1219188-1-pgonda@google.com> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [PATCH 3/4] crypto: ccp - Refactor out sev_fw_alloc() From: Peter Gonda To: thomas.lendacky@amd.com Cc: Peter Gonda , 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 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); + struct page *page; + + if (order > MAX_ORDER-1) + return NULL; + + page = alloc_pages(GFP_KERNEL, order); + 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); -- 2.33.1.1089.g2158813163f-goog