From patchwork Thu Mar 30 11:49:55 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: 13194080 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 C83D3C6FD1D for ; Thu, 30 Mar 2023 11:50:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E25AA6B0089; Thu, 30 Mar 2023 07:50:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD69E6B008A; Thu, 30 Mar 2023 07:50:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4D27900002; Thu, 30 Mar 2023 07:50:42 -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 B35766B0089 for ; Thu, 30 Mar 2023 07:50:42 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8FB3080137 for ; Thu, 30 Mar 2023 11:50:42 +0000 (UTC) X-FDA: 80625397524.20.AB58D3E Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf28.hostedemail.com (Postfix) with ESMTP id 7082FC000B for ; Thu, 30 Mar 2023 11:50:40 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=XoioXYtM; spf=none (imf28.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680177040; 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=4u4GBPVn1QeuU6neCfosEZSZ/2o4Hx9YEYk8G/HGEwU=; b=1+8e5bSAzUYMnik4DgTEY0rvVxIoi0UPKut1C2bPpm3HONExfxg52T2k1+P+GQ4I7vrhik fPOgb8vJa39S0MI9zQCH+NgkHV5inKwG14wE6rHi/aMgIZrkqSlov9nZDYlUWkzISMDv64 1DLHpkikJOZ6Z8uHIYgz4jopUX5qHIQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=XoioXYtM; spf=none (imf28.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680177040; a=rsa-sha256; cv=none; b=oR7q6CaWW1HERpu6RyKdbEt1seuqGBVooNylvrTIPlmJBoI6WrEKn82eAkLTuBoFf6v3xN B7mI7mertO/t/oscdvuAua3jYn0oyCT6M0otgKUvEalQ5pjp2jPglkDX4AelEE85KUEZN5 /3aZkkbb+OolqJ3ldEuwiopsPQBZQa0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680177040; x=1711713040; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MmsAbUP+stG7qEWYYDNAAzwlLkIUGBDyKypaxDlWzw4=; b=XoioXYtMttTfk2MM/d0Mox/UXuuW4MubJ7m8b9TIg4pHZqv1oCvqTILc 2ftihksspSDm6rL+a/04WAWX9xgDwks+wLT6wp10IRfRCheHMyJOXjNuQ nGrIMYI/TB+XJtUigT3n1GM05u7mn4KggDshGZmsRUSxTTiL11sXtzkLS 2Z2yFHcAHFC/hIGyWR9H6vFFSiY+6v2bMH7Nr7qn07MNLgx90QzNluIhs 3JEe/ptu65TMWbPWlhU89brfmK2f/Hw6lpZLtAw6yg8q9tAj/wV5k5qYW hCgQdhvpwSFMISXtfeWeOF/7k+D2h+AVAFZhgX/uYt4RrhNdcQunBnEr5 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="339868546" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="339868546" 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 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: jm6t6rtx98cmih75ozzmayirnn8ickse X-Rspamd-Queue-Id: 7082FC000B X-HE-Tag: 1680177040-29315 X-HE-Meta: U2FsdGVkX18s5DiirCROTyFOollQ4UFDrLOlGht91phm/ITVqAzPESPpoMU1pe3l/JNLLql6Oay/S9CspPGl2QHMEyw2zkLYqMkWRS0aS8DAIN0SgQF1nK6dYyz5d3lUC2jDflT8zlSOzWeXNaegi9ssNHWmIAET2LfavcwFwU6AmN9dTEIE+CvFS9xlzYi9SrJriuPkdZkCNjRfRp78kWqjK2pq+bCL+7aCMMfEtwxxnpfPT4VRtKPtiZJsdrOqTfODi4wzEpKnbCU4Kle7K+gckzEGzzrA8nTzUQI/hSHj0FaNBlHEx0WzzvCS2C7WTgGvf+HjX19s7IuKjIPscNhKcm58cba4J9L6/iHKsavLPCsrZDsm/P4EnI6SaJqpEycnbuEssS9/ZKoo6W0EOZBkLUuVfW0TOS6y73QGUzGM6VpZR212DfVxJpd0mQB7UzgQL2zmsfnAtXzoPVbxIsgCnpcpHZF05f2DJCTVmjwJT7BlFFGuUap/lfM/lMsJOZhrv0T7/3L9grSvYUp1v7mTBaKAHfK+9RPRg3yat6U/U3Cs6nH9eGg2oif9hFzKvMAwwVkkOGlEiGdzZ6j+6eoUKJEAnPDFeAPhYYXG/cKUc79O+p2pPn2hMRjQQXF6S2PC1EwGpj3wpteKQP3GP5RI3LtMr38kE3LsYFOjTtJ91bYV4rTO/Qi74LUpX1b4EVPRoRlGM+GkfEo9apNClkrxwe+dQUYKAsRQ2Ok3AbRt/hHmUFUzgAl2G9bYWCdSQanFJYyDiKpoolFZJYMphKVwz4id6GxfHNWp2D/AoKvYL8Uzs/r/UQYPqggoGyt9Jy6KncTrrI8MQoBrU0aVoud2RIk1On5PCsb0nJjFM8/JE1ibPKi47G9ADqRT2kwe/eqkgBuYGUcIkdazKZQKjqcWc6rfjdxyb471mJ6j0mhNWhE7oHtwGLYniVxR/OrY3/4GR11VxuX+nKPVK4m V76hdTSR k3BZ7hwE/MK+VqFtJDgKJK6fUgrQ4Ei7ccxSsXhP/OPAm2AvDOzWM63a/enim5077CK0NWZBUzjGsd4ATZoAzvq9f1fHeb/oRJ+iSb2f8Je/RaxQKgowmgbKoHQLNfvq7r73g/NIzWiDSZFkaEQlNk5g10p9LtV1XfFGxKs94QQfIwbT89/PJgPcqOSQBQGmpF6/UT2S5+gqeWw8= 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 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;