From patchwork Sat May 13 22:04: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: 13240349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81068C77B7F for ; Sat, 13 May 2023 22:05:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3D39280004; Sat, 13 May 2023 18:04:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ED14280001; Sat, 13 May 2023 18:04:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88D50280004; Sat, 13 May 2023 18:04:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 771F4280001 for ; Sat, 13 May 2023 18:04:58 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4A4D11C8525 for ; Sat, 13 May 2023 22:04:58 +0000 (UTC) X-FDA: 80786612676.30.340E627 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf14.hostedemail.com (Postfix) with ESMTP id 2A816100006 for ; Sat, 13 May 2023 22:04:54 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ah3NZ56C; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf14.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.88) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684015495; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5QNweM8SAaqY0llbQtMpYPXKIrYhie9z8hDfHUvFa6Y=; b=lvwYMjiPNZPy+XU2NkdYDx+fKP78N3A550+WcnIsySLHTeLAzw6u28eWT+VWg/EfuO4XhY LfuEUhArfyYPqSVDZnw5eG/vLE1IFQpeFZ3g5Lx+r4rwldCcW0BobRlFCQpPOQyZXciqs0 324J3RRG7ClzM38MEYLgthnPE6yRfoM= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ah3NZ56C; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf14.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.88) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684015495; a=rsa-sha256; cv=none; b=Qv2y/DbzQvJXS71CA3Pa28pWAgoR+LdDqlKm27eIaFuje5o2N8UyFK0TbmpeixMEU8d7+J d+/v59rhGVsp19U/eYOjfgHPrqWxLJDwepeGGDFQRUdCFBfNQ6NVg8EVX8AsYvBGZig36M vqP3eKMw3KMb+1OsDfy+Sv/Xfh5lIxY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684015495; x=1715551495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZRWbbgKJS3P7pe8ruC5AYEzSpFJMHJrlR+e2/skszlg=; b=ah3NZ56CmUsdBetq7x6PhQ2LZ36WStTjZJk95B5qJRg+IDk4X/AZ4IG2 AtlNBfOeorSY1UyjEvCIG2GG8LU6U8SnYsoghrGbg5yb4dXsN22Twg9xH 8P/OXo0vCjG/vbMu3mNq//+AtvSmJFffw33p8WEvrqISOA5Gf0n/fInl+ HdVLJm9QGuTmOf08DPEsipTLaNBPWyULlPVZWpYJBhIKX0qBERg7PSiuX ZdmIbyRSmFiF+JAsbaL9Eud1P7hPApk2WmbPkNln9H8cWyQW+CnKRmAaR eSz6imkA5agVOnkL6U8DL5UtwflSShcSQD4zwzQwixLny/1J/LqKBTG7W A==; X-IronPort-AV: E=McAfee;i="6600,9927,10709"; a="379142571" X-IronPort-AV: E=Sophos;i="5.99,273,1677571200"; d="scan'208";a="379142571" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2023 15:04:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10709"; a="733429556" X-IronPort-AV: E=Sophos;i="5.99,273,1677571200"; d="scan'208";a="733429556" Received: from sorinaau-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.62.145]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2023 15:04:45 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 2F03A10CF7E; Sun, 14 May 2023 01:04:34 +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: [PATCHv11 8/9] x86/tdx: Refactor try_accept_one() Date: Sun, 14 May 2023 01:04:17 +0300 Message-Id: <20230513220418.19357-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230513220418.19357-1-kirill.shutemov@linux.intel.com> References: <20230513220418.19357-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Stat-Signature: fgx9wukp1rkzxs737axzn8uikttjiugb X-Rspam-User: X-Rspamd-Queue-Id: 2A816100006 X-Rspamd-Server: rspam07 X-HE-Tag: 1684015494-521142 X-HE-Meta: U2FsdGVkX19JzK91gvmrhSulSI2UV/6k7GHqIbMhYqj9LOChsD/d7ZD23mbsRyjMST4L2A07ZPBjlTsXnelRddXZLk/kttlETy6TaLpunF9tmmCRXY/DUZsKh6WwbAFIuWFGrzbKIzFB6YqLkDQYEVUDJIAZJNQsrO1hF9Y13QDSVBb0jyK0bZi6KCvGoFpNIyyPyiJrMRLMsKmQNQ/728mZCGqNjbE5PXZqRjoxMoO/0Ab4vz2Mni74eyQ+GYpJavTmF/YsFWkwZqSulDCgQ6wuWKXa+QHEKuK8QhhnJw3I3sUGm/IXJI/8tmzWdVqzdsYykE34zx05Qq4tQgK4xcjS5YioaG1xfrnAM/vcjqk8V/yhaRgWIQORsrhlUJsELtxxGdIhG/jQ0jL0fG5wc+/G/wkHerF0V8AWJewohCBKIV+H1qKvdwy1/sUYO3SiTS5Nl/bEB5PQpcf8494+bTM1C/pMq7CNuOc5pSb2YZjVIvhOCS5zxfJnVN9ipiu4iuujxvQRILDKQl3z2PKvsley/4SZhhcFd/o1MTnREUCqTt9G4KrtQ2TD79HXpFleQQOVWrZ8Ivu4e80IfiF0zRo6aTaSkXZH9y4ggyqPd0XKpSgv15EK3dIRtep6VRuPs/ZrzgrlfCrp79DAqq3FYSZ+IYATO/SQgN8FZpN6AATSYVameiSQbT5qiZSbenTVtK/junknbjOIQaMaRgDiYZY2ybeeb3t8LKWmVqSsiqLKZHuQMhsCltdioW9N3+xqvCpw5tTL6btK7lh8uE2IwnzCP8300G0v320gNJxyiDmBgmQy6OaDtpGWdqnct7irdLhmXCPuEoyYmDjuAfAX4Cxkm2wAC9Vua2sZfJY9oWhftXWQW+UcuBuT0OSSEwHk42fEcBvKkCJ/sg8s36PZEjp3LI0Hg3doxUHAjM1ATlYTNO6uXrWeV+9/X870yR4XeJ0+9tPh10JzKODsTb8 EDBshP4h Fva3VhlBQXFRAIEO8XCbX0i0uSxhFAaXbMLaD4sF8kZUEhdgscm4TiLXLRV/SNjF12cHohkh3zUcVWbJihlgKXeyb9uZH+wNj1SQtY9lLUUY6P+DqEtTcWA2nm5L4uBwoUDPAhREH1xHWJdEbAkjssIBswfhHm9g89deBGLLz2rnwsUv/mF6sQfF2Og== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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;