From patchwork Mon Feb 13 11:59:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Kai" X-Patchwork-Id: 13138297 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 5C034C636D7 for ; Mon, 13 Feb 2023 12:00:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDFA76B0074; Mon, 13 Feb 2023 07:00:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E68C86B0075; Mon, 13 Feb 2023 07:00:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE2B96B0078; Mon, 13 Feb 2023 07:00:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B7CD96B0074 for ; Mon, 13 Feb 2023 07:00:20 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3A77A4175F for ; Mon, 13 Feb 2023 12:00:20 +0000 (UTC) X-FDA: 80462125800.15.6ADE4E2 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf14.hostedemail.com (Postfix) with ESMTP id CB82610002C for ; Mon, 13 Feb 2023 12:00:17 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="TLEJrUg/"; spf=pass (imf14.hostedemail.com: domain of kai.huang@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=kai.huang@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=1676289618; 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=Ip0oMz2jOEenkcraaNJSgJNrAK3sP+BIFTa74KSFMhQ=; b=S5wFXn/tM4JkguHOdU53xlTWIYl78J1ocRslRp5cSnp7IGQYzeK1UiFf3X5BlEPcYcfQBH 6PRR/aGZJPxFch02jW9qfzhl+sueEOND5ZkR+D1pJQnvLSBjHDaS8n08Jw1CX1VF2Uxijh 5AYG/IS2QpAAud5W02XsLMbG6tzNg8s= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="TLEJrUg/"; spf=pass (imf14.hostedemail.com: domain of kai.huang@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=kai.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676289618; a=rsa-sha256; cv=none; b=LnYc3/XaTQ8fqZmfH6V6ULi04FG7ZOPUPeEG/wIz/HsBuz5FR81JyK2D/2g7988UTGeScn kkN5AcwWl7eMCbqeXrA1RrIjEsRZCOOR9SaUhd9PVp/eXb6NB7OtL566aVXSkmqNc9Zsib U4WTcB5XE20IWRj5jkQjz8N+EP/wPas= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676289617; x=1707825617; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QEso+vBOOoVux/wtjNoZkk+xLB3AIptATSZNTVaGYfg=; b=TLEJrUg/CZcZE2QzVS+AhOWYkyAQTzzZNh7twhou09OFQX7Xnm3AX7Mx jkBFukoVjO90gybjj5A34AB1isf930QcZcipzdHsOhebMLCSQjoql3ebQ 5ZOvaoHs3HgJSymed6hpgg+ZS+KHZrg6/hV4HmuJZz8xrK/tVpLNfSeTA ztaVzC2mfFM+TTAw46lnXQav74OEPAd+3/qCZgMwRQfxUNhbK1clgf10q 1nKPZkXf9WceWJoqL1oB6ckgKEqz7uzkE5ZZbVCQBr8254DX688N0MWVv Dn2NaolDdKFdkS+E2CYK0/gCbCXI8NKgk3Ros0Q3Hdr0213H6S4FujMSz w==; X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="358283041" X-IronPort-AV: E=Sophos;i="5.97,293,1669104000"; d="scan'208";a="358283041" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 04:00:17 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="701243098" X-IronPort-AV: E=Sophos;i="5.97,293,1669104000"; d="scan'208";a="701243098" Received: from wonger-mobl.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.209.188.34]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 04:00:10 -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 v9 01/18] x86/tdx: Define TDX supported page sizes as macros Date: Tue, 14 Feb 2023 00:59:08 +1300 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: CB82610002C X-Stat-Signature: ez5omqh7e3jy16bqz8qgn96q153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K3o5F9UbNmCI7cg86vFhXsZimtPSNdVhXAdfUPun1R2wzf5fsmspE1C1XuKzv/wCl9i0qtZUKCj7gdEMzSjtUrhwd7OMO8KwEJOHlLXfUlc151lAcsy3Icjr3n3AzSlJVSvwz5WcHMOdUKP1bG6k9OWhsxxSzr/TAcehnjML+EMpqwC00ECvLK778c2CXlA== 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 --- 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.