From patchwork Fri Mar 10 13:34:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 67455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp946616wrd; Fri, 10 Mar 2023 07:49:49 -0800 (PST) X-Google-Smtp-Source: AK7set/Hgzys/iWvqYf/vloGVZIuhdTQVjh9FW90eZo4Nah6zBq22Oap0TXweU+xVCrGjXkYCY7e X-Received: by 2002:a17:90b:1c86:b0:230:c41b:4d87 with SMTP id oo6-20020a17090b1c8600b00230c41b4d87mr26440834pjb.6.1678463389456; Fri, 10 Mar 2023 07:49:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678463389; cv=none; d=google.com; s=arc-20160816; b=lMkhngSG5fEZeFMPXt4gb6X/cTL3foV3u0zsB67NabL0/V2D+StPFBsPGuFOGhRzJp w8xbaKYXACccCWNG1WfMYgPFc5bB/J7peDKv4QA1EkzaSXEGHbo0zfMhQMtYA1bnHhc1 9o71vaUZ03sxQJeTAaX6mkAML5ZzQLKJT8kh+7ts665UoyEHz8HGMUM0lVVUWiQZXOI7 PNZdqdZcmVUe77XLhOjrLwdOk8zFC/xWOPFD7vZOgHmfy/wKbItbvIYbN1DebUbwQw0e 3LYTPDV3jSKQd7txtxFkGJalSl0VFHZUiw/EQTPzasifni5enA0Mp4C6wqeKk8QA59ra hwFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Bm0bzsqSLZkOul3xD5VB0bLZOuoiQqM3tqyAl+zL+Mo=; b=MlDNc35Tluh/nhPfjNao0vIyR4uoehzrn5d8wZsk9JRytG/nIjjZR4K68Ya4TZbW8C yaz5vAnJhQr0w9sXkAlCDegvNxVjRO7tVR4CQuoGS/I+N4q5FsTMKT3nGZDXAeuzmA87 N5OabLLyw0w3TeEHSv4+SwNeeS18KlLJEu8jg5ebeVGFwNyB3kktUmY5uPszvjSWxhnZ DQ1G3PF8r2yGn9y2sraqx6JvbGM9CKp2kIpFWT+2npzAuPBN3aXmuBQmJF7K6SEarYbX PvA+LNodsNFeGxNidS90HLPW17GirRkaRyqgO3S7/wWbsSJJOwbec2jynHlAQ01h7J5N K0TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NLiooeUW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a17090b078f00b002308d9212d2si173407pjz.35.2023.03.10.07.49.36; Fri, 10 Mar 2023 07:49:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NLiooeUW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233205AbjCJOyQ (ORCPT + 99 others); Fri, 10 Mar 2023 09:54:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233481AbjCJOxi (ORCPT ); Fri, 10 Mar 2023 09:53:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33362123DC9; Fri, 10 Mar 2023 06:49:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C52ABB822F6; Fri, 10 Mar 2023 14:49:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9C93C4339B; Fri, 10 Mar 2023 14:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678459772; bh=7cV37WX5fhX5n94WfRto4O9PuxBVxADgFaMZPcBzxqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NLiooeUWb6e5aMEG9Ynfty4wPipTIkvYCf+o7ZLReOQnRSMqIoOco0JImYk9EmnnE 03QbMccVcjSkXAIURZBLRVnzpeQGY878bsoYu8RaJR78bw0Kuq64vDdnM5+eM3kXtL mKLiJ2k2Wkp2h0yNTzpnbZj+77Zl5/XJ32jIGdIQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Peter Gonda , Marc Orr , David Rientjes , Brijesh Singh , Tom Lendacky , Joerg Roedel , Herbert Xu , John Allen , "David S. Miller" , Paolo Bonzini , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Sasha Levin Subject: [PATCH 5.10 113/529] crypto: ccp - Refactor out sev_fw_alloc() Date: Fri, 10 Mar 2023 14:34:16 +0100 Message-Id: <20230310133810.229873777@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310133804.978589368@linuxfoundation.org> References: <20230310133804.978589368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759996426782645027?= X-GMAIL-MSGID: =?utf-8?q?1759996426782645027?= From: Peter Gonda [ Upstream commit cc17982d58d1e67eab831e7023ede999dda56173 ] 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 Reviewed-by: Marc Orr Acked-by: David Rientjes Acked-by: Brijesh Singh 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 Signed-off-by: Herbert Xu Stable-dep-of: 46a334a98f58 ("crypto: ccp - Flush the SEV-ES TMR memory before giving it to firmware") Signed-off-by: Sasha Levin --- drivers/crypto/ccp/sev-dev.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index e70ae98de1189..8a900226d73a3 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -138,6 +138,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; @@ -1040,7 +1051,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) @@ -1056,14 +1066,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);