From patchwork Sun May 7 23:46:17 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: 90889 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1813000vqo; Sun, 7 May 2023 16:47:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RWHWSYprdnTh7641xNzunHR9EWi4hmpdqX5yk9mUwJ9hZoXcshBpiv3taJpJNDkzUikO2 X-Received: by 2002:a05:6a00:a96:b0:640:dbe5:e2ee with SMTP id b22-20020a056a000a9600b00640dbe5e2eemr11973654pfl.10.1683503266280; Sun, 07 May 2023 16:47:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683503266; cv=none; d=google.com; s=arc-20160816; b=ezJ65QvB35vMheS7c++T8I6nifIBva+FBFCa6zmF9MlWmNxnVN1a5P0bRmicT0vsJI YN084RiNxSbiGVuOmonQXn/3Acf5SqFOQgm/Rp/E1KEbRCnh7wZA6as7a+UiS83abZFO YkGWz1lAIoX1MLGHDUUrmI31P3WljuICmPgW5YJIQEESFlwxtzZFIRYposa8hGoOoVV0 lcJfTy1MV0LIlAoz4rZqLbsrNvvOVjzkSbzEkGKPrbuh1KschW53zAvI+M/OrawIWDss A+bHth8OkAWp6bULCX0MDCpoAvQ/WDkm6A5p4fb5kBFnIiNioH9nWzKP87Bf1YmpGKeA 7H6Q== 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=CTAcA4wuJGXr1qEPk0LXJ1KKlaY3y3WYYnNfsivdIAyIF3t+9u5E50mn4EZHn6dQxg Cp5eHOyR45iqF6CG9YCnOiCF1TxHpIN3yAFWtUZGmMRXKs8da6v7uAhb1GxqbM5+sJOW Lrhbr7/+AM5OC/MqRacpwBoGEo0HGVTSUWHyncb9XjOonj5+sA/Mm25dC8rYiCO6BEzY RCvTEos7ffvaC1zBBgByaZY0nyin/WREG3p66A39icL678d4IY8aSdmLQSAJbSfiZXt5 29OPkPrIbLaF80WkNXLKle3VDLn4d5bE2ZaP+weQfvkNxM1Ei+rVK3SMdgbBdgm8P87D 2feA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J2AIh8T3; 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 f194-20020a6238cb000000b0064105588e53si6138979pfa.359.2023.05.07.16.47.32; Sun, 07 May 2023 16:47:46 -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=J2AIh8T3; 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 S231827AbjEGXqx (ORCPT + 99 others); Sun, 7 May 2023 19:46:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232050AbjEGXqs (ORCPT ); Sun, 7 May 2023 19:46:48 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71651132BC; Sun, 7 May 2023 16:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683503202; x=1715039202; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZRWbbgKJS3P7pe8ruC5AYEzSpFJMHJrlR+e2/skszlg=; b=J2AIh8T3MvmbLELGmR2DHoLXatzo1PFpVYaks7vVvO7aI80IDsivNrgZ ZercZeUXmog4R6pQ51pCxGo8ONfcwlWs8obCXQKv6MCnn8Kf324cMn82y c1FbrWMSRMz8yilLYX67NrtMwya7GPBlB8ishv8P+GsD8FbrCC5QZappN 5wfPGXoLo52diaNXsRyKirh9fN6NuDX6b1+6nDrKbFaDIQHOmCnkuh8he dcL7cQ40CuXfY9MR01Ck7wsOY9PzHS/O4i5q/TMsE2Ae5zzSEj0V0ermY SYIfDeLNGZQDiE4/2LeC+npzOJLTpLdpTHC4VEfMtcUXxaEnX/UZUqFGn A==; X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="333953560" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="333953560" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2023 16:46:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="675852971" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="675852971" Received: from dancaspi-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.61.73]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2023 16:46:33 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 76D6610D48D; Mon, 8 May 2023 02:46:20 +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: [PATCHv10 10/11] x86/tdx: Refactor try_accept_one() Date: Mon, 8 May 2023 02:46:17 +0300 Message-Id: <20230507234618.18067-11-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230507234618.18067-1-kirill.shutemov@linux.intel.com> References: <20230507234618.18067-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,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?1765281120743550528?= X-GMAIL-MSGID: =?utf-8?q?1765281120743550528?= 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;