From patchwork Thu Jun 1 18:25:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 102129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp538542vqr; Thu, 1 Jun 2023 11:41:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5IemVFtfkEfiwXX9S0MId5DMDctYoK3hm0VLNFKxp9RS34ysYJrBQlL3zxFhz3zbCi6jew X-Received: by 2002:a17:902:f54b:b0:1b1:b0ec:462d with SMTP id h11-20020a170902f54b00b001b1b0ec462dmr246993plf.39.1685644894211; Thu, 01 Jun 2023 11:41:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685644894; cv=none; d=google.com; s=arc-20160816; b=Ui0IGuWK+nxImH1Ucbw1uqNm+ETq+PEatjTneP9w2Mar7n3B2z2GtT3d99qSgo3aIX NUhr7F3ZFrQbjNWpysPykvpTrNOSFcoWVKydZVEwJxWytOdrcGBV5CH/anFG+8LMWCb0 q9l7S3ZPv21zrGYf06EsQQXCBV7WgytkwTKgA9SO6ugIH1FsS87LO9O34cR2WzA+78jm TWyNxzQBctEfVrcfR90ca5SF6Upr4V0NynBEejmiEbecsao98WNq8alyjAVu466WRGy+ 2Sych4IgBZnyNjuCNip/+YQ1NKOM3v3bsl1eSW1ViOw/9fgrqsdwZfnCzz4Aj8GDyVN+ SQww== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5QNweM8SAaqY0llbQtMpYPXKIrYhie9z8hDfHUvFa6Y=; b=iXH+PKnf90oOWEkVmT4953Ie2M3hVK+52phJctvrTDbCMC92fgJpA/qGiicsh9aRHe oZy9furVDiGZp6LSGwWpvtWEGN2Nev4Un/RZPCw9PLFyQAt3cWvS8RN7w8Sj2u9K4e6/ Ay1a85zlWI6lrnPs6652lb09/V1Ruk3BD8E9Nb2oyxks5i7XbeIpYG4dqqtHGYiRR6vE Pj7Fk+wJ8AwTQrbN2GZlx3juIruZeKqu+JY8CmXeL/3v1R7WYhWMzLBcbV+7xhQryfIR pn40k1GY6YGnmc4cEPXr57RZgQU4J2t6s003HjlixSSbjgoimoWrQo1mWZMD4UijHBPc sneg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ViqbFaTq; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 12-20020a170902e9cc00b001aad9b73ff2si2940951plk.285.2023.06.01.11.41.21; Thu, 01 Jun 2023 11:41:34 -0700 (PDT) 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=@intel.com header.s=Intel header.b=ViqbFaTq; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231732AbjFAS0x (ORCPT + 99 others); Thu, 1 Jun 2023 14:26:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232496AbjFAS0a (ORCPT ); Thu, 1 Jun 2023 14:26:30 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36921E40; Thu, 1 Jun 2023 11:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685643981; x=1717179981; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZRWbbgKJS3P7pe8ruC5AYEzSpFJMHJrlR+e2/skszlg=; b=ViqbFaTqk69w6fwdLIvIUaQsoutSpujAdAf5MRMjlW9DkxbzJPeRcFqn dTRG+AUr8booV/46nk/3Op2keKWHa/h8xzFD5UpJI/JnGPbghnFa2fY8A cYV1lUE1IgS+X+cDkqJtGkdAm/x9nQj2gneEh96ikdbrCHTGyIGlU36yq Y7IwiEKUm2umu++x+mo8JnO2tppJ2XXNY7Zdj/zWCW7xKHsoFPv3kk9bn 2WHYrPQuHvPdbIfjQepBT9UbGDu/5Opstw3VOYOH9M6bLvU+41iGodpPx WyCQxSdVOhAgrmJDwxtTtc4kb/xDz+VnjVYU1RAVH0JZ4vIIrzAZUrPa/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="335266306" X-IronPort-AV: E=Sophos;i="6.00,210,1681196400"; d="scan'208";a="335266306" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2023 11:26:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="777329805" X-IronPort-AV: E=Sophos;i="6.00,210,1681196400"; d="scan'208";a="777329805" Received: from fmaislin-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.47.213]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2023 11:26:04 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id A336F10B6AF; Thu, 1 Jun 2023 21:25:52 +0300 (+03) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , Dave Hansen , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel Cc: Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Dario Faggioli , Mike Rapoport , David Hildenbrand , Mel Gorman , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, aarcange@redhat.com, peterx@redhat.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen Subject: [PATCHv13 8/9] x86/tdx: Refactor try_accept_one() Date: Thu, 1 Jun 2023 21:25:42 +0300 Message-Id: <20230601182543.19036-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230601182543.19036-1-kirill.shutemov@linux.intel.com> References: <20230601182543.19036-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE 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?1767526780511586277?= X-GMAIL-MSGID: =?utf-8?q?1767526780511586277?= Rework try_accept_one() to return accepted size instead of modifying 'start' inside the helper. It makes 'start' in-only argument and streamlines code on the caller side. Signed-off-by: Kirill A. Shutemov Suggested-by: Borislav Petkov Reviewed-by: Dave Hansen --- arch/x86/coco/tdx/tdx.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index e6f4c2758a68..0d5fe6e24e45 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -713,18 +713,18 @@ static bool tdx_cache_flush_required(void) return true; } -static bool try_accept_one(phys_addr_t *start, unsigned long len, - enum pg_level pg_level) +static unsigned long try_accept_one(phys_addr_t start, unsigned long len, + enum pg_level pg_level) { unsigned long accept_size = page_level_size(pg_level); u64 tdcall_rcx; u8 page_size; - if (!IS_ALIGNED(*start, accept_size)) - return false; + if (!IS_ALIGNED(start, accept_size)) + return 0; if (len < accept_size) - return false; + return 0; /* * Pass the page physical address to the TDX module to accept the @@ -743,15 +743,14 @@ static bool try_accept_one(phys_addr_t *start, unsigned long len, page_size = 2; break; default: - return false; + return 0; } - tdcall_rcx = *start | page_size; + tdcall_rcx = start | page_size; if (__tdx_module_call(TDX_ACCEPT_PAGE, tdcall_rcx, 0, 0, 0, NULL)) - return false; + return 0; - *start += accept_size; - return true; + return accept_size; } /* @@ -788,21 +787,22 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) */ while (start < end) { unsigned long len = end - start; + unsigned long accept_size; /* * Try larger accepts first. It gives chance to VMM to keep - * 1G/2M SEPT entries where possible and speeds up process by - * cutting number of hypercalls (if successful). + * 1G/2M Secure EPT entries where possible and speeds up + * process by cutting number of hypercalls (if successful). */ - if (try_accept_one(&start, len, PG_LEVEL_1G)) - continue; - - if (try_accept_one(&start, len, PG_LEVEL_2M)) - continue; - - if (!try_accept_one(&start, len, PG_LEVEL_4K)) + accept_size = try_accept_one(start, len, PG_LEVEL_1G); + if (!accept_size) + accept_size = try_accept_one(start, len, PG_LEVEL_2M); + if (!accept_size) + accept_size = try_accept_one(start, len, PG_LEVEL_4K); + if (!accept_size) return false; + start += accept_size; } return true;