Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp112433rwb; Tue, 6 Dec 2022 18:07:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf4K6jD0Q6jvLoqREJnCVlKss7gCNlYEVv8SqxgWm4VlrjInpR2VGPcAG9tIMqU6uF0gPeMr X-Received: by 2002:a17:907:6d0d:b0:7c0:e5c8:dbf1 with SMTP id sa13-20020a1709076d0d00b007c0e5c8dbf1mr11533169ejc.328.1670378830057; Tue, 06 Dec 2022 18:07:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670378830; cv=none; d=google.com; s=arc-20160816; b=felbNDZlklvZSdhr96rzRb9b3htgFpZ94KmMhai8L0v2nPJEWJgqa2jBqKAShMIXFr 7c3+6yM8fQ8teH6vLNyLHCzvEU38ig5WMB6ER9JO6BICp3ulSqrBe2XPTeyAWBJOB/c3 Ee3dSBYVV/FCns8g3pMS9+Xqr9+CjPqF/bmHIhEu25cRNS71d1zeJdVNn6Ka/2Wpvvre cTp07w41mofnPVs0W75wCU/q3fO0mMBKIjRFHnV3G1yiHt7SHYrRr1VVvZO7NquuplPv L+1LOHxw3WAyC735r0k3idTdwmAWGYbdkVjDVoqDYsQcjlpPlfnBfvFUNKpNBQDXJq1r 2ARA== 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=u5eXy8raN7nY7Im1G/xDbIuFNC7MzRo5Pkm1h411bjY=; b=uTpd+tRppD+YkfnQXnV17shOdUu8RwVle+ep0SzPderPmD+h+vWC9V11RgsuyOI/Oz oJzY7txcpPObukwJaZm/Od3e+KIURdrMHNwmdJdh4Yg/GBwcAftNpY0wHyUTKEWw+HC8 e4DNqeJbVxEn9uLe6ngo0GK7xpDcPqgYBwmJ0JIjyV+nOl4flBSzlLy/g/ioq2UcZ7c7 s02N5PJH9r/K7UzhqtQp+0H2MKXQaABlnr3LxOA6XKA9FFwIhcwn5+kvIhGyt+kTJDIi +lvXfJT4KWiUoP0H31/x9glXjkicEvl03aK4N5Qfu7MPi9INqT9zU2iTaK+ppYwpjkiF hmzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cKBynRfv; 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 m9-20020a170906848900b007c10f6a46c5si1952803ejx.219.2022.12.06.18.06.51; Tue, 06 Dec 2022 18:07:10 -0800 (PST) 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=cKBynRfv; 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 S230117AbiLGBv0 (ORCPT + 78 others); Tue, 6 Dec 2022 20:51:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbiLGBum (ORCPT ); Tue, 6 Dec 2022 20:50:42 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AEC0537F4; Tue, 6 Dec 2022 17:50:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670377809; x=1701913809; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SfxCo98L571pSepCQHUd/DhlAMN+hwpTgH7KtlWdFyw=; b=cKBynRfvF+15QWSzbGOp+v7F/JLuA0Beqk0zwYWtIBQzXT/M7zrNeWiJ S9J1AbQOnKeHSG+JVRiR5q9wE8B1FRFxwYSGzTVzkfqBdDSvNYKXC3bIN ypfXdKsRdFyJCIeqtfexIq1/nN1fjhSZ87DPcvkivvNsyZ7OEeX5lXBED qOx6qTIwYcyWgykdMllOAbE0Zu71oveEqxDuYJHQo57glFwzc3uJalaOK pRYCxh2shatQpqn250AR1dcfQAOWc8M5vgfP6L3Vpkjl056fLwNCQVy6O L5mzEqJ8YKkHGLkiQS2wu/jCYuORaVOKr/jl/wXxFmr+OQtMR3QJ14tNY w==; X-IronPort-AV: E=McAfee;i="6500,9779,10553"; a="315494588" X-IronPort-AV: E=Sophos;i="5.96,223,1665471600"; d="scan'208";a="315494588" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2022 17:50:02 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10553"; a="646427711" X-IronPort-AV: E=Sophos;i="5.96,223,1665471600"; d="scan'208";a="646427711" Received: from puneets1-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.38.123]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2022 17:49:53 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id B99B6109C91; Wed, 7 Dec 2022 04:49:39 +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: [PATCHv8 13/14] x86/tdx: Refactor try_accept_one() Date: Wed, 7 Dec 2022 04:49:32 +0300 Message-Id: <20221207014933.8435-14-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221207014933.8435-1-kirill.shutemov@linux.intel.com> References: <20221207014933.8435-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,SPF_HELO_NONE, SPF_NONE 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 12c14affa5f2..cf6d9a0968d8 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -674,18 +674,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 @@ -704,15 +704,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; } /* @@ -749,21 +748,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.38.0