From patchwork Fri Dec 9 06:52:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 13069295 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 39B75C10F1B for ; Fri, 9 Dec 2022 06:53:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8E6B8E0005; Fri, 9 Dec 2022 01:53:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A3CF08E0001; Fri, 9 Dec 2022 01:53:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B88F8E0005; Fri, 9 Dec 2022 01:53:08 -0500 (EST) 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 7A49A8E0001 for ; Fri, 9 Dec 2022 01:53:08 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 347FDC079F for ; Fri, 9 Dec 2022 06:53:08 +0000 (UTC) X-FDA: 80221850856.06.FD98FFD Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf20.hostedemail.com (Postfix) with ESMTP id 75AB51C0002 for ; Fri, 9 Dec 2022 06:53:06 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SR5fs889; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf20.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=1670568786; 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=tVAujMrv60WB/19grcF7ewhShpqe3rdG2V0XV+0aN1M=; b=TgyyuIS1gcq0CTj14XJwEDO/0YyR+bKBN5nazrHGeDCa2y8S2tY0ETq1J5G9Fu6DDtwhCX uuHVwp0gur2mTva6SkrwIyHIotoJkPJJpbsXQ0ZkfpZjCSee4J/UoMVctCBoJDjbnnWsdz n4pk+w47hOScKU52W3/S9kzGM4pZNfM= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SR5fs889; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf20.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=1670568786; a=rsa-sha256; cv=none; b=tG9+Ho13LvrzFJvs1G70XLk0foxe6AAF9+vxiCYjJApbDoDjINEpCJHsRnlgNGdAzzItyi qdNE+udF3kOrcmfxuxToejxRcBzAHA/boH/vrAnzF90l2FBE8Mkg2PgFUgQNFU8xcmhUHv Pc2mL5sJZQP9IU6IWGKur0lU3tGVUEY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670568786; x=1702104786; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tpNWTLiIlps42i61R7np9UDYahZOICSBhQnhpwefLwQ=; b=SR5fs889scheak+u+Ts2Zs1nPhUdXNVNs+YR7+OztS3dzl3ahrlIIydp Zpn2RuYR+CaoiLoLEIPCCKS1kTuIlUjigGVOy4tc1Y4eiUlaeDOHfoJwJ i1NzXz2KJDSxrRM2l7rg8DLgMfKWnv2bxJXmZmdfR9gohWlNNVe6TqS/E 9UfLxgLtMsdC4DkYlOP8YStZddqywCpPkXifyLE4maG5wChGIZHig82Z9 BKCgJr4YUiGwdtpjGLJJAHGCuspJbvW1kw1d58MKZFO6mg74wk3PmiBq8 DhcaEwuYPJmuCe8BJAXY+bb57vNmMblBl1Av1PsGHK0A0i375XkMe3NVJ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="318551256" X-IronPort-AV: E=Sophos;i="5.96,230,1665471600"; d="scan'208";a="318551256" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2022 22:53:05 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="679836792" X-IronPort-AV: E=Sophos;i="5.96,230,1665471600"; d="scan'208";a="679836792" Received: from omiramon-mobl1.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.212.28.82]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2022 22:53:00 -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, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com, kai.huang@intel.com Subject: [PATCH v8 01/16] x86/tdx: Define TDX supported page sizes as macros Date: Fri, 9 Dec 2022 19:52:22 +1300 Message-Id: <2436106b4de8df75ab304c43128fe5b174bb0bf4.1670566861.git.kai.huang@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 75AB51C0002 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: t654wqkwm43wxysyma3c95hjkuri14rs X-HE-Tag: 1670568786-576626 X-HE-Meta: U2FsdGVkX1+kuCbSL/8bPTZ5PAvl9t80w1w/J+sygWCSObUUspXp/SzkrP2ilmsvcdZGLgmLiChJYj3x5vwJ0qP4AwdvpEJ/3KVRVZZlerrjDsOv6oyRBaLcn/k51oTRbDzWgER+jAm7a9ZAvvQO+Qx2FoCO3h7mkOXebzHQYT89JTOldgsUuA5Mm1APQdlT6qDUOWCM6ddXXMiWIlGs2gxzRF7RKCyibwpdGcay4wlwHknvE0cgJu4FqoiG+78JcEI1YYSfaCq5Ys4zMrRjJJ37S80W0SGjojCli4di8j0W6grYK8ovGEZw/zwXgXK8qKZWGLANEQE79MPHRboymJC0nrZx6DPCiMHWVRksnK3NT5F1IzqJznYSUYHx3UjtptzvxJwgcn9jr6kjEU5+lfz+R4ffa8zgKW/XX4Zh9zw+aG9Of4I5m48HYUWeENO0/UF49nyO6d4Vll/yWcQKIfxCLt2VRru8QPyMBzk63nmnuXUZx7SOwiwtB7uS9E8EzRGC0MifNUNr98ppuhT778IKuk5h+yCoHXBnBU68Rxvm7lZKGF5dv7NITlq5XYDTs8TYKi4lSoaj9AZWb7GDOGjwkpkj7st4JQdBDqA0gLsZSr59kBpKLQ8cLZve6NvsZDfaMMtYN5LLGg1c2JvnSnb1aVaZqa92pnYWbklhbtHQYpaB8bJW3cNH+xAcPrWpm9ZaRBAsbPQGI99gsApSo39qhFm5Uizadt2BsjHzwSV8nBlKhDW6wzmhoxj+lqOlgtdOVIUEAQW2o9V14ioo4PQHqentwuEjHwI/zyjyHjgsBAs+0+UV5i7P04n8Kj4TNhpRW6b33dclOoDRJnnBo+KeZ8ixw4wyijvJ2YXQgh93K+F+3x0tv6JhZfCyUKPg4dkKBWPrk7liRyAie/Bk3A== 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. Reviewed-by: Kirill A. Shutemov Signed-off-by: Kai Huang Reviewed-by: Dave Hansen --- 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 cfd4c95b9f04..7fa7fb54f438 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -722,13 +722,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.