From patchwork Tue Mar 7 16:57:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 65776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2623447wrd; Tue, 7 Mar 2023 11:39:06 -0800 (PST) X-Google-Smtp-Source: AK7set/kmQHgC+y8qQ2ob/kzqAIfP5ZMsA48BgxSVOb/DKBxG0Mml+e/j2NvE2GFY1+TyhctNUtW X-Received: by 2002:a17:906:4a5a:b0:87b:bbdc:468 with SMTP id a26-20020a1709064a5a00b0087bbbdc0468mr16067067ejv.70.1678217946382; Tue, 07 Mar 2023 11:39:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678217946; cv=none; d=google.com; s=arc-20160816; b=h75b/oPevHxeXwZQ18noWWtpJf/AgXCxR4AMSmTNk6gdWpnTzcO1H/LTv64U2Fp2uQ tuKtI2cj+EfMzL+B+1R7fljTlrj9RJWHCFuTmOFCNAZ+jQA+kWbZ10DRB336JP/XufXs rammg4j67mf01I3D1V4nUaKWWfVmVUTeXAMRo5SI0y62yMo3/qw1Law2C5JYr3uW3htL gpDDFs7AwQTNXawrhsmn2EPm9cB9tpXe5mbShN6uMbPoNdtc0FRBteIav0SAR15sdhOw 2rkQHxhOPygDDzz/NBPuLu7qHHSLEeLY+sKukM/mvMidS0qhcBG3GVOyuIgF8znWaiac QLmg== 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=BgEbS7bkm00ra4n0hZLUOhrmrjGbGr+vjTvfF6SIPVI=; b=let4holpEg2jWQuDuuPL4DN4Vp8Szik2ojeauzl6SLVOfjgwefQ7W65fuvtHs7udG2 vHScN3d2vo0uXD34L0SwVmWUs04KhUvdyFTScY7Fo9FMz4/QsgMWUmXGoN504ViwAjDP BUMCMtbkjOGXsYR1z0zJgLgdstsCkw3wY5NRfQH1fKV1cEu/2XReT7OYfDunwpMFoymz TF+Vk2koDTf2yQLKOFb7OE5ROac0MxZJhLNtdevV1wxLdaKodgZnvsBckF32VmV0qgK3 9k2nCEzcFVAazQIWHg+9Qo/zONiz/SDEuZxy6cJV30ONm8BXyCiiYYUOZGJ33bSXOXae RZEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zCGCEZrf; 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 ne8-20020a1709077b8800b008c7986cbd76si203544ejc.745.2023.03.07.11.38.42; Tue, 07 Mar 2023 11:39:06 -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=zCGCEZrf; 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 S233685AbjCGTGr (ORCPT + 99 others); Tue, 7 Mar 2023 14:06:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbjCGTGV (ORCPT ); Tue, 7 Mar 2023 14:06:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 207C1C6E71; Tue, 7 Mar 2023 10:51:43 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A188A61520; Tue, 7 Mar 2023 18:51:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8809BC433EF; Tue, 7 Mar 2023 18:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678215094; bh=j4WV0doVcqcXU/GoQxcUE4PFr43m0wuP6FLx2M2TvIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zCGCEZrflMf84XHxAMAsfLG9jd+V5D7ubfppyEFQQizWSwGsDtOK1ahi3hNtS483U hUfw03oabzYt6f1+qI2Rg9QccWCJZzD7Uo1PKkL1TON64ui85fwENpBIvoPbAZIJUj uyruVmuEGW6lmZFwoh586aQ/RrArX900/V4t6bL4= 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.15 122/567] crypto: ccp - Refactor out sev_fw_alloc() Date: Tue, 7 Mar 2023 17:57:38 +0100 Message-Id: <20230307165911.189186313@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307165905.838066027@linuxfoundation.org> References: <20230307165905.838066027@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1759739061174196537?= X-GMAIL-MSGID: =?utf-8?q?1759739061174196537?= 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 15ef60cd4b149..7c9149492970d 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -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; @@ -1087,7 +1098,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) @@ -1103,14 +1113,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);