From patchwork Mon Jun 26 14:12:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Kai" X-Patchwork-Id: 13292969 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 20A0AEB64DC for ; Mon, 26 Jun 2023 14:13:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE2618D0002; Mon, 26 Jun 2023 10:13:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A930D8D0001; Mon, 26 Jun 2023 10:13:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95BD18D0002; Mon, 26 Jun 2023 10:13:43 -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 882D18D0001 for ; Mon, 26 Jun 2023 10:13:43 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4B56312069D for ; Mon, 26 Jun 2023 14:13:43 +0000 (UTC) X-FDA: 80945092326.09.DECBF67 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf01.hostedemail.com (Postfix) with ESMTP id 0A1BD40022 for ; Mon, 26 Jun 2023 14:13:40 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=e06N000Q; spf=pass (imf01.hostedemail.com: domain of kai.huang@intel.com designates 134.134.136.126 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=1687788821; 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=p4DTLo54iegSkS9sYaMOi473XFN2/OAaN6fXny9U4ho=; b=0iKBotkoeL4oKU62VzXe05lllJxt+uPXfXYrXbFEVtSTW4g6gbZYPhMRtFDMJNylpovz3N c7HczD5XLYCU56ePoJomUtkoqJmuMDlqV/IJCSurpO6cZT6xCdDDhcrz+cBNBDImD6vE7a DvgV+kRZKiuRqiGjWC1EC9WR5d7l8Ew= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687788821; a=rsa-sha256; cv=none; b=iPV+n5tKCBi6M144ZB3aAwrwMkrUkZXZJvIT4Ko+QcfUgE2iS4QLAwGX65qokgLEhJZHk0 VgfxTjPJO7Wg+xSackZtiEbCbd0I2Q6ul7wXJohqlbGaa5qPLRbA5Mp+af0uLiF1vPaKLn CNO9HH8LJa54E0/bZN1PII5sdE+Pdxg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=e06N000Q; spf=pass (imf01.hostedemail.com: domain of kai.huang@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=kai.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687788821; x=1719324821; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IazzBZEPaJdhzuSVqXgULVuwNqeSBeuaUYlXXc8k87w=; b=e06N000Qtzi9PbRnJA48hfhnE6jhxyBMc8YB8Nlx5JXhKFH9eBRxi2kN 4CEjUdQHqzbPBFLAYk6aYev+Yo2ZYYlR0aOxxa00Ro4s9HLrGEDfIxula yQlo1pwNtxfMURRAVSILO1c4cmCRyhiBolJrhT+NxwWveQ6B+32ZR/a+F 3emzUvzZ5q392L8ipdPSYn/4FR/9d9JDR8JCv00MtaHEUw+mqhSFrz8cP +M8OmN/lr6uHup0NLvsmsQaqL6gj/UyZsszXPLI3ceZ7y9O2OY5VwR2ZJ hQcKRDGvdMtH1iwxbzAu1NtdKv762zMpOOe5dER7VrQDHIDPkxV9Z49Jh A==; X-IronPort-AV: E=McAfee;i="6600,9927,10753"; a="346033487" X-IronPort-AV: E=Sophos;i="6.01,159,1684825200"; d="scan'208";a="346033487" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2023 07:13:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10753"; a="890292212" X-IronPort-AV: E=Sophos;i="6.01,159,1684825200"; d="scan'208";a="890292212" Received: from smithau-mobl1.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.213.179.223]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2023 07:13:31 -0700 From: Kai Huang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: linux-mm@kvack.org, x86@kernel.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, tony.luck@intel.com, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ashok.raj@intel.com, reinette.chatre@intel.com, len.brown@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, ying.huang@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, nik.borisov@suse.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com, kai.huang@intel.com Subject: [PATCH v12 01/22] x86/tdx: Define TDX supported page sizes as macros Date: Tue, 27 Jun 2023 02:12:31 +1200 Message-Id: <05adfd0b3f59b1f3eb10a1a1d045b01b9bba4379.1687784645.git.kai.huang@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: y3tajzjen7jrhsx49rjwjr81miwh3j4j X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0A1BD40022 X-Rspam-User: X-HE-Tag: 1687788820-921416 X-HE-Meta: U2FsdGVkX1/WMh9bNRpgrKaGnkTqfbrMG6JzxhOhIt4T/JvI+wKvWCDNCj+yBFi0js+rp6q+lX2qvHCXUtXIrahSzcWmRjk19tlPqY+26cRvVe95u1cabKzjVz4nPCRf0WvAUOR6J1++G06ujZlXLn/q7izT+4ETVYsHABIX6C5oytcmCEktDeRjF+3h4D5BPCILeyq6Eezda65EIXLWQmu7W/+FZbXVspMUw4oJLSnov8lS9N6B7dso2esMee90QVTR7MsI+6UFxfr5vpJicO7UieCWznaSVnb7cayeuUZDBg+HpMiB/Bcjv+6Q+qFS4t+mh/GN39lyj3OMPnoqTM+Ho065HiLshNsW85QzWqL6qCSnkH0stpzSxWK9QJhhSLqOgUkHJ4i7m8lTCEpoT5DPDje2W9T/d8VMT5Q64jkoRDAbZ6XIfrKGwG92ybnl2Jqiy6UiHoW/DUxAHc4kKhvvxAhGHQyPdJ+ENQNJd664bMyuVj5KTGmodnCWiWAdQZQ6S2ktUet4GK71KuredD5SnyBewXJKYjHY/5L86sQipmzXOBEs/bJsbnTVSReVd4F8CeNIQ7RQ24OTBKcdxXP9WLu8lj5exWQW4cv7rwYX5IKsvHYcXYCkHeGaak3Npl7EfZX5kmETgfQ8hGOG/CPlLLjimxmdldGgAJCyhkkIhbEZ4CncPu6C9ggaakjAS2oEWqs2szZZhUeyFihb/dZq30dnjl3E312IS+tFb9Ltd6p15ewfMwrKLVkclcg6rD4Pi5RkItYUC3j8dFy7ojNGRzKrTuyX6ytwiezw/OJ00Gmc1jhW3hbnkUp6zQxNsQZnMW7OxtHk8rNkdYv+xiydMoJD1FJXHkooLYRuarMyQHx7Oknu4A/ZXiPT0omlEWoR5lmBq5CMsCDjrkpshCLCONOBAHvAQ299Hc/9EtxwOffeZAtUpzNHz94gDwWWc9ACF5iPXVluqUPhX0D 3lT7hj01 HJ7UKKcH3/iozrq72dPcUQZdUJOeh1uj/fMKnR0RP1PAM1rfj0ADGPlukmGLjiebXJVU+9rxYiWtMnwbNTjlSNo6+w7bSmoegMQrSkLxoEcok2UBYrzSdCyiKEEcF1U/DGAI61zUe2EaO7iqBXWVshE5XX7iloLrcWoU3UfBGg/dz3AbL+hph4x/WHQ== 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 --- v11 -> v12: - No change. v10 -> v11: - Added David's Reviewed-by. 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 5b8056f6c83f..b34851297ae5 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -755,13 +755,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.