Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7194895rwd; Tue, 6 Jun 2023 07:33:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+2gMcaQrX9nYtn8jRt21YAM0vMH9hUud7ZDJdEJpURbHHqwX84A7kHOookIFgaYaKkv/7 X-Received: by 2002:a05:6214:3018:b0:628:3833:764e with SMTP id ke24-20020a056214301800b006283833764emr2140733qvb.28.1686062015119; Tue, 06 Jun 2023 07:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062015; cv=none; d=google.com; s=arc-20160816; b=jPRUAtujZ388sflqoBGdT/OTtGOD58wZKzj07tZ/WnB4pFZCP5ojuxpqKao8m5qU0v D6J/B/a+v6E9syLrOtYAioxEXwqHzezNGRtqKXB24Vmhn4lWlM4fdeKkdQ6mRFOtd4aC NJBp0D3raG6Cox1DzJ80cmKA5qCtL59kYDFulrgos3tkj1WwenszYewEQ+Bz2n3p3BOS uzHf3Oll4vWXoQu63OWzymGNoV22A29OorIc96WJ2s52Bt8fJdEpL4EIa9BV5iVaBnGl lQ2izafa8QPxY7S1o6O0lEqRsVCApKt1GB99ZhDxGOlT+qBsLEYjOydK0SEo6TEEQ0to qszg== 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=QqzBfMyTXyYazGByjbikDNmF1gl5pCR0rFWE8YIKWRemwglHAHX+OziCznhNZYiE7S b/ZViv6/Luu/iAqWSgySFm/SWTI1cTM8oEvo2cT018crrS4/bUStsA1o4WpnAhUKREag MZNKc/NNH38yfS7oiLIXZTBTUkM3ZG13FQvcnylB4p6Au3dNkhtp0bmifHMsZXuxKA88 hJ9u4EQz4ylN8IG7xEq7LLWivv5/2esd+13LDI3xU+ku7Iife31pzRkxw1ZZzbDcaKJj akaxGdMELkoa0xd9VWCca618NJ7bGUfS7KWrJ4yJt2K/TzEOkaO6TD2ejdfl5rhD18dg 3ECA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jh0o0hSs; 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 m7-20020a0562141bc700b0056c23bb1597si6398938qvc.88.2023.06.06.07.33.19; Tue, 06 Jun 2023 07:33:35 -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=jh0o0hSs; 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 S237551AbjFFO1t (ORCPT + 99 others); Tue, 6 Jun 2023 10:27:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237625AbjFFO1h (ORCPT ); Tue, 6 Jun 2023 10:27:37 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0672170F; Tue, 6 Jun 2023 07:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686061651; x=1717597651; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZRWbbgKJS3P7pe8ruC5AYEzSpFJMHJrlR+e2/skszlg=; b=jh0o0hSsBcyChqCU65b0OAV/xHFc87ivBOLdEjKMlz4t6pJ9Hl12+j5i RwaQURJqGbxr7Nd5CsyyKLrwJeMtR5e07xlbaYQQEX55cvKXUoFm5d7WR HEJ4u1IApRDezu7adp371IJme3GAmiAuzUOssxiTUTnB4uQVmyqt9hXOO +EPuHQJnXyNoknC2F3RH+8ZqCF7X3B8zCtdvaQO2kCQz9jWYD3L1A6ejc FtmNLlqj87z5RlLgxqfPsIpIlU7vVbYYWBhiHUQ9Lz9irmpvctlU9+XJs 9fxE1exYYJdkDpvlkR57LxXDs6N8lNiZvW6TRhQr1ze/30IEhZN5YEk9e Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="359147243" X-IronPort-AV: E=Sophos;i="6.00,221,1681196400"; d="scan'208";a="359147243" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2023 07:27:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10733"; a="659543356" X-IronPort-AV: E=Sophos;i="6.00,221,1681196400"; d="scan'208";a="659543356" Received: from rgraefe-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.58.173]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2023 07:26:54 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 7395310DB52; Tue, 6 Jun 2023 17:26:42 +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: [PATCHv14 8/9] x86/tdx: Refactor try_accept_one() Date: Tue, 6 Jun 2023 17:26:36 +0300 Message-Id: <20230606142637.5171-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230606142637.5171-1-kirill.shutemov@linux.intel.com> References: <20230606142637.5171-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,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 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; -- 2.39.3