From patchwork Mon Mar 6 14:13:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Kai" X-Patchwork-Id: 13161216 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 26E4EC6FA99 for ; Mon, 6 Mar 2023 14:14:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7B406B0072; Mon, 6 Mar 2023 09:14:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B04AE280002; Mon, 6 Mar 2023 09:14:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F394280001; Mon, 6 Mar 2023 09:14:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8F3F16B0072 for ; Mon, 6 Mar 2023 09:14:37 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 522E51C5EA7 for ; Mon, 6 Mar 2023 14:14:37 +0000 (UTC) X-FDA: 80538668994.07.F0A7121 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf03.hostedemail.com (Postfix) with ESMTP id 1E6E62000B for ; Mon, 6 Mar 2023 14:14:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="cfd/g0uP"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf03.hostedemail.com: domain of kai.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=kai.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678112075; 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=uCwHynmI1Y/rCia0sOr4mdTqPBCpXkwR6NoZUQjizGs=; b=lk6Am/xYzsZKbEoYZqB0qxmJghNLJbXKNZuXIRh+Xt5T2B5R1ynj11e4Wm8KjT5ViR9P+7 z+3g41eJ2RL7ZYGwIcdWAKMvXOphiBaCokxetwwxU1PguZoNOx+PnarM3NDgA8n4C8+4Bm /Y9xAwLrdj81JG5yKeYhEd+GsZ/0rAI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="cfd/g0uP"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf03.hostedemail.com: domain of kai.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=kai.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678112075; a=rsa-sha256; cv=none; b=OiXh6mYyvSdZbonOKwOiqqxy9Vsl6Hzoyh6c16H9dZILgqf3XqNCebN/Ozr5KJYwFlFaCL hBAWLt+n9N9VBCuzxCcll4yCKFEV6s4SCRDHTSV5gxVAazqh8A5SbAIUs/Ep8v12/tIR19 QVy9Bct1i9I0/uOV18MTflzAhTtJzOc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678112075; x=1709648075; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VqcKARLycsk9x9FHwX2Ecm9BMNr+EPyvV4YYN1oDJ30=; b=cfd/g0uPStyqSwUnoQElLGCX2Y/kA8hEgFqIMGBs/+B3r1ZZLUDwbV98 FSxPm5mk/xcMH8qh74jidICVGwmPASAqgpkK/E2yf+zostktzH5VUFtmR Vm3Gr+xHakNF1+7srUVENofB2+SydG3FsbVGuw1bpRv2opQze68mouQOa Ee00mLKWZ4dG1ymqaUVc+/0FTfIMTcZkPOb2f0Sts/ocJBw2/dd2CHY3p sMrP57iABRolrBZDPhsD0zIfytyth/oKvktD8zN/23MomYaVDuQhvMgAC GBuTBWgPken6+o29chKC8iSKyxh8OvXwK6UD8T6un6dSjfLnSSeddpIBQ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10641"; a="337079981" X-IronPort-AV: E=Sophos;i="5.98,238,1673942400"; d="scan'208";a="337079981" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2023 06:14:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10641"; a="765231976" X-IronPort-AV: E=Sophos;i="5.98,238,1673942400"; d="scan'208";a="765231976" Received: from jwhisle1-mobl2.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.212.92.57]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2023 06:14:29 -0800 From: Kai Huang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: linux-mm@kvack.org, dave.hansen@intel.com, peterz@infradead.org, tglx@linutronix.de, seanjc@google.com, pbonzini@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, kirill.shutemov@linux.intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@intel.com, tony.luck@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, david@redhat.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com, kai.huang@intel.com Subject: [PATCH v10 01/16] x86/tdx: Define TDX supported page sizes as macros Date: Tue, 7 Mar 2023 03:13:46 +1300 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 1E6E62000B X-Rspamd-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kDfl1nA+CaaWvrxp/OrEzDaGUp0CwkKowVX1PZYwdXHAYwrKmGjr+MHgDdC/BryAyBydxq30o052KXWoLYO7MWbUA9GoFYR4Jrkviy90SrOWHMzcMGo5/Gw7cfUPA1Fy8PNdNyLjY9z2UTSZX7rVB7MJxVAGVYIUGwQ67bJ/KZBC6IDG7TzC/Q5YTWcfTZlBlx6DZWDG6pA== 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: TDX supports 4K, 2M and 1G page sizes. The corresponding values are defined by the TDX module spec and used as TDX module ABI. Currently, they are used in try_accept_one() when the TDX guest tries to accept a page. However currently try_accept_one() uses hard-coded magic values. Define TDX supported page sizes as macros and get rid of the hard-coded values in try_accept_one(). TDX host support will need to use them too. Signed-off-by: Kai Huang Reviewed-by: Kirill A. Shutemov Reviewed-by: Dave Hansen Reviewed-by: David Hildenbrand --- v9 -> v10: - No change. v8 -> v9: - Added Dave's Reviewed-by v7 -> v8: - Improved the comment of TDX supported page sizes macros (Dave) v6 -> v7: - Removed the helper to convert kernel page level to TDX page level. - Changed to use macro to define TDX supported page sizes. --- arch/x86/coco/tdx/tdx.c | 6 +++--- arch/x86/include/asm/tdx.h | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index b593009b30ab..e27c3cd97fcb 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -777,13 +777,13 @@ static bool try_accept_one(phys_addr_t *start, unsigned long len, */ switch (pg_level) { case PG_LEVEL_4K: - page_size = 0; + page_size = TDX_PS_4K; break; case PG_LEVEL_2M: - page_size = 1; + page_size = TDX_PS_2M; break; case PG_LEVEL_1G: - page_size = 2; + page_size = TDX_PS_1G; break; default: return false; diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 28d889c9aa16..25fd6070dc0b 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -20,6 +20,11 @@ #ifndef __ASSEMBLY__ +/* TDX supported page sizes from the TDX module ABI. */ +#define TDX_PS_4K 0 +#define TDX_PS_2M 1 +#define TDX_PS_1G 2 + /* * Used to gather the output registers values of the TDCALL and SEAMCALL * instructions when requesting services from the TDX module.