From patchwork Thu May 18 23:14:33 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: 13247511 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 83F4DC77B73 for ; Thu, 18 May 2023 23:15:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8495690000B; Thu, 18 May 2023 19:15:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D354900009; Thu, 18 May 2023 19:15:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D76090000B; Thu, 18 May 2023 19:15:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 41A03900009 for ; Thu, 18 May 2023 19:15:07 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E436FAE414 for ; Thu, 18 May 2023 23:15:06 +0000 (UTC) X-FDA: 80804933412.19.CD19028 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf05.hostedemail.com (Postfix) with ESMTP id D216210000B for ; Thu, 18 May 2023 23:15:03 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=idvJUdtF; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf05.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.20) 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=1684451704; 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=ZSfKxAtwTteWFUtVi4dkqXkG9jnF1t2smrbg6SY5OQYRSjxCw1CYh4Rg578hEMQC+6P4s5 h8X9LjFK9X4wjJYkKAtO0Ziau9m3Je5XCPH4KF9j03xYw8d1f3NNdihySmRNqR2UIiPZzD C52w4crQEHrm9OquKCctqjt9UflwEhY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=idvJUdtF; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf05.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.20) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684451704; a=rsa-sha256; cv=none; b=r85CvABwGY+G7jKOeZHosE0TeDCX7QwmKZEeljKKO2YQ7LSd972Qk9FMV01C1MonzwS3EU cH/7tm6fmfJfRJbfzJ5PwKUAhzeH0RbD8vpY4bhE8hT/T343FEzgfC+Hnl5lcmTevqXY+Q RrN5l62XYMubRYj++ODuAUhxhPWqCa4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684451703; x=1715987703; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZRWbbgKJS3P7pe8ruC5AYEzSpFJMHJrlR+e2/skszlg=; b=idvJUdtFGGXroHMxtHb8rHYNPhDbuvhY/8m3b3wSoenZvFT15+ON/xLj +N/VyzM5bkGKDIJAupu6i9wZsdTt97me/EsrstLTQXZBYBoSPDRUNLxqF pr8OkOIcKvihvUQHd1vOlKzPfpPWmiNMBL8WTp1uQbSBHwb8mVv50oilT z7Shumpy/ezU90tzfFdEYnYeOTuA8ntGWn1d/dPkTbnddySTVz55c0d1a NbdBG07ZAb4lXiBY3LKna8IMql9gbzRL1F+gaOFgsIn/loeKUiZWxvnAG a4n4U+vtruazGI3EmkMBUM6PH3Enfjo49Uv89O/67GXOWF7K+bBTPp/Ry A==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="341652126" X-IronPort-AV: E=Sophos;i="6.00,175,1681196400"; d="scan'208";a="341652126" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 16:15:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="772065103" X-IronPort-AV: E=Sophos;i="6.00,175,1681196400"; d="scan'208";a="772065103" Received: from rkiyama-mobl1.amr.corp.intel.com (HELO box.shutemov.name) ([10.251.222.16]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 16:14:52 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 6D73610DFD6; Fri, 19 May 2023 02:14:40 +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: [PATCHv12 8/9] x86/tdx: Refactor try_accept_one() Date: Fri, 19 May 2023 02:14:33 +0300 Message-Id: <20230518231434.26080-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230518231434.26080-1-kirill.shutemov@linux.intel.com> References: <20230518231434.26080-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D216210000B X-Stat-Signature: wekcqcpz7fs6oiuujqhur7adfecgob8o X-HE-Tag: 1684451703-252579 X-HE-Meta: U2FsdGVkX18taP9D/Yp9mpvgrJ4RxtarOufw1q32ePSHAjHggrFqVM2H9Qv7O7WNeCBz8KWvVH/9++bBln7f+PApjYDmIMgr9LeQT4XJ0gxggPfQAzW5IAdt9FsI3XY/KEiJNNrIH6joI84IVp8a2yBWQaRPpslDXgdDHmdmr6nBCChqhVmBKQFKUneFq/e2DTDoa1vfR4IR1LVefDxy8XQHhBKCSTtDECI+WXR141NVncQSSRbXZ4OdfRfIbQl+ucjyIoZTs/VrorO+pflv5Xq44xz8Z7g23aWDxXlXu74zX2Et2IIuiwPU4ujCbHn+sCkQ434Npfz5qIJBJIEeODY3w/4RHu5QUC940AY/aDIDxvQ8qJNbHEDovnOl+4S8KBlSF2pxiIc1VPAc+OL/v9L+bhB+BXf21dYhSistve0XlnPbt2WEQj4VzIl4DFgwh7ZXZopdEZKwIlK2JIuaBI2B8AigLT6V9/L+tnaM5P31JafMat49/0lxYEe03X3ZNfHtTzbHHbQrixztP4XBaGM8jSDm0JymHkCNXQJN71oF3SM24m5JXZKRf9h2eaOpv4n8SFzOneBC4rXy+GfwMtd++uKjqCcmGg5qjnldqW8jmcsIP1GH1tA4XjbllQCox7uKapttsyosfIGckvU3SgxUeJqIMRbUqHB2X8g2x23xeIEdrawfGIGqdU4CS7DBiJoEjuV7IgxvfKw88KnfjItadPwmXTeESSd7ndywN7cM8QTo0/PlkcAFrFlFF/vPIknl5ZSjHAbOXxvtWb6YYIUH3AnlOd4SfvSBB/AU00j7EkqtXIOdN4h6HCJAxI1qCrNhEWzInKbgnVUZhu5qWNg9vAM0Q65CbhlI8oyvr8xvhx6jtBWFmNeQtW5DQBCr+E4eiR1x7VmtWcPuOcpavNcmk5wfOaQK8LYOj4v35cH16DFOhyXLladIy3ZoJLXRVIQsG78/M7KXNkT6x8W mg5vSg4M YOUu3wcv2vhvm8e0K29zXPLEj/AT6nvWLlDEXRj6OqvGQh0AiENL9vivKiC8MusyVtHJLr/wRvOHEJZAf0OjjISTNQr+DHb+VbBwH+bpi/63VG5KGoAuC0z9XU2hDgs9HuN7lwdR39UBx+b0rW6ltNb99knHrk6vIwBOVsNgvX9BbR5jNhUDxyruYSA== 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;