From patchwork Thu May 18 23:14:33 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: 96103 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp867566vqo; Thu, 18 May 2023 16:34:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ykxIdUIuXqLAfelaqQNu39y9s30Mhk8+orKTlQdYtEmqkmdOMI1MLeS/KY//i5ql2X/QJ X-Received: by 2002:a05:6a20:a59e:b0:106:5915:e888 with SMTP id bc30-20020a056a20a59e00b001065915e888mr63724pzb.43.1684452882484; Thu, 18 May 2023 16:34:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684452882; cv=none; d=google.com; s=arc-20160816; b=GVxfAl0Qukm79VGhI/mPyfnAd65xml9fFN5hnQTYiS/nFtiVqmJcrkqo9Doyqihwrr lGw8F9fO9qk5C8xdKLhH0/JsDiwK52Y2kZss5dTYmprTHuL1fi/2934x8L6sjneDJ1Hq 3oMr9sbA7hQXFS0ruCTCbg4iJycoxUKo/GgRMN5CFVeTP10fZtF81DM3cI2E6A8O99Do okLXx/Z7QYibR+9bm5LrH4VxzuTQR7LDGD2ZJc/099LhZnBilG1+5nkmpndRMeWQLEmG Xr6ZKTmtZP0T82I4vxaNQ6dpD7UPh48riDW5iui4Saz1PEOwILai26KgLaei/VYtPNsa slGg== 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=OKBnYNlYzzM2TpsX7+uPss6EqeA4G/9DcnAwpyt2hhxCFHE2kkRKdLBz8haDC4B42S 1MhB/u59cFnuS9y2nlvW1f3b+g4x5WLPhfnDc+N2pGAdMGRSAlTrqADjzCzhnPAhbUnC nI9VppNQqirK/32eJA+dPBeiwpnaNSyK0heVbKOCJEZPaRFmnmfVynfjxVC0fEAYyU/Z ewl0IZ9J0+uWih4b2HZKsGqdMULSM/+NWRwAuClPhsRTf4X4w0K0fwgfUJjCNrMhQNcL sTn5KPKHhPrTOvVcPS6Zn14QpY9kl2+uB63MlsJzrx10wMbOoA9IDn+GmNBGDRV44gLZ yrzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dONhJH02; 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 a21-20020aa79715000000b006436dfd441dsi2603705pfg.356.2023.05.18.16.34.30; Thu, 18 May 2023 16:34:42 -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=dONhJH02; 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 S230406AbjERXPt (ORCPT + 99 others); Thu, 18 May 2023 19:15:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230341AbjERXPD (ORCPT ); Thu, 18 May 2023 19:15:03 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F1B8E75; Thu, 18 May 2023 16:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684451702; x=1715987702; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZRWbbgKJS3P7pe8ruC5AYEzSpFJMHJrlR+e2/skszlg=; b=dONhJH02Sdqb1NFaheaqF4Yg4jfO0Iu3sMj9rgHTVkzLNpNERT/oOeVW kw/PYB9KMlJZXFQCs5lItmfFVnf/OXehdumk2OjsSlnu0viIxRHpJDm6B /NdUi7x1ZHuFF8/p4f77xBUE4gCll350H4fd1BFxR4Ms4OUeomBJeEQWZ xw0P7ktri3RUSDaPN9jHVlsQTPehEl1J0bvtnRK3okqL1W7GeAYAqySa8 z339K9dGQkNnoS70PH9VmjEIH2f7OHbRIM/8SlfEg/cDNPuyATva+pulK JHhDTBNgk9k/K8pOnvIbOfGbmTtkHepcvMypchDIN5h0Gtzq4MlibJ7TS g==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="341652124" X-IronPort-AV: E=Sophos;i="6.00,175,1681196400"; d="scan'208";a="341652124" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 16:15:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="772065103" X-IronPort-AV: E=Sophos;i="6.00,175,1681196400"; d="scan'208";a="772065103" Received: from rkiyama-mobl1.amr.corp.intel.com (HELO box.shutemov.name) ([10.251.222.16]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 16:14:52 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 6D73610DFD6; Fri, 19 May 2023 02:14:40 +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: [PATCHv12 8/9] x86/tdx: Refactor try_accept_one() Date: Fri, 19 May 2023 02:14:33 +0300 Message-Id: <20230518231434.26080-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230518231434.26080-1-kirill.shutemov@linux.intel.com> References: <20230518231434.26080-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,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?1766276866122009608?= X-GMAIL-MSGID: =?utf-8?q?1766276866122009608?= 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;