Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2005360rwl; Thu, 30 Mar 2023 04:53:14 -0700 (PDT) X-Google-Smtp-Source: AKy350YzvET2qZowS4FxbobBbmmnyFHp4r27WP/xDt+r4cuUSEtV1atZLCtmfsdb01mHh0pg86HP X-Received: by 2002:a17:90a:d195:b0:236:7144:669f with SMTP id fu21-20020a17090ad19500b002367144669fmr19106358pjb.2.1680177193909; Thu, 30 Mar 2023 04:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680177193; cv=none; d=google.com; s=arc-20160816; b=ZOrzv1cRJY748fszXyH2jBGm9+AJkaaW8uNmQhgF+JwXRRV8ucWTx64GBLgWOHJLwe MYGV9Fkm6bFWviDSFjL1gRdwog2tECXnDTlyCWr7rAbTMi2CS+WPUHJpdQJb23/rDsoh dGtMEGHdGhWbGaXQz/By0NM+0s4EOimhJfDW2I5xgHuFrmzPiGQYMpzzlyd93lXkm4XV HO8lYikIKskJJ6BSHNudE0lRjCNV8hYTsMEI+tprTkq6iZHRa2rhWjrtt4v+Sy2Few9q alo9ov4C5qCrx07Zjnkbqxh5QW6zgs38fMFfL0eKfs9fcTvlbC+fHxh7A1ai5pJ8ACk6 eOoA== 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=4u4GBPVn1QeuU6neCfosEZSZ/2o4Hx9YEYk8G/HGEwU=; b=f0aw7ASUkMa9kwEsefnwTbrIoZe5hp266heLIIKdJOetT7Ef4/qC3cGZ6g/Q1f+5yg a5Akb2mYi20fwrG62TSp7yv4UH53siJ/07fKv4i4HcF6X0HqK76j/u38nmHjTMM1IH4P RDd8TNPwwhYf9c0Kq7jPHZBQfHSvuEAuyj+jIz7jCwBG/9K366uHdNb6BZ1KrQimtDaz D0NP1M2hj2r0c+UWcngTcM9pqab41AcEagtWMxNGr484nEZvkVE7FCwt76ZxOnko06do 9kImd1w5rGkdOgDrJXaY2JV2jsy0i+V6r9KOfYVoW3JobNd9W00qcYZvJztNHJCh5USj i/rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="gixM1Vv/"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a170902bb8200b001a1f44d31b5si215504pls.565.2023.03.30.04.53.00; Thu, 30 Mar 2023 04:53:13 -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="gixM1Vv/"; 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 S230469AbjC3Lux (ORCPT + 99 others); Thu, 30 Mar 2023 07:50:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbjC3Lub (ORCPT ); Thu, 30 Mar 2023 07:50:31 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2924AD25; Thu, 30 Mar 2023 04:50:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680177028; x=1711713028; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MmsAbUP+stG7qEWYYDNAAzwlLkIUGBDyKypaxDlWzw4=; b=gixM1Vv/IWcSlPvQWBV6n8Uxde6NK5DZ8oMoyDzCXsc/h68FHi+JKgVP rFQ78xSh5JFWf9icQ/y7jhGe90REKnG84CxoYQAcK7FYUTUNnoR3T5rO6 f7v3JKq9R6jWr7mehIYVCZHNY1obCxBoG02QH52RRTSbU2ljPgeldJu3P cS5Q/0FrMqM3ns6bim24f8sKTN2cVUbaa33t6Criy+Mnr6REBUMzNIQUV HdYm/EhjAUWRrqOertVPR9sJY3L9PxpL/mokhu0pabfz8k6tTxL6IJQsN dPJr69GmO4EYw76iGCiaBQHclc/u88Y/439lj2B8/I07nkxc1ojo3LoRA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="339868533" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="339868533" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="1014401458" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="1014401458" Received: from ngreburx-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.209.91]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:18 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 75D41104D1D; Thu, 30 Mar 2023 14:50:00 +0300 (+03) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , 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 , Dave Hansen , 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: [PATCHv9 13/14] x86/tdx: Refactor try_accept_one() Date: Thu, 30 Mar 2023 14:49:55 +0300 Message-Id: <20230330114956.20342-14-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> References: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 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 a9893f44288f..9e6557d7514c 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; -- 2.39.2