From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7A1F161901 for ; Wed, 28 Aug 2024 09:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724837717; cv=none; b=l5tKPyjlM+dT/H5kg8Am+2S0vnIpD7HpPgHPS+VmantAJ8xneEGDGk0ay7lmqa1ImvL+kHUOoIynu/ENv2Aez7kMnFQV7QFCT0bYYS80mrydVqJVZ0u0JfT4FAY7iC+KAkpSYAZo9yOcJ2vah0Ol434rIwX3yFxyoeu25D4E/pQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724837717; c=relaxed/simple; bh=po43unqAaIsTUVdSBbc9kKj7rhAu7QEs5DeNl1JT7Xs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gOAUhmK8Z71SXDb6pP/5M3MAxQDkSWphIOVsvmuwWbs8Gu/tkUpZyqsmwK9/xmakI1Jbw+D0dxB5gWfTYRX+bawFKa9sMJxUKoKb/vaVi42kKv7b0j78CKiO3pN229CD+NW0eM5UeMgl406M8tCHSQLhCL6vR2gjuAJTQi7E5AE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=A+Ku0FG9; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="A+Ku0FG9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724837716; x=1756373716; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=po43unqAaIsTUVdSBbc9kKj7rhAu7QEs5DeNl1JT7Xs=; b=A+Ku0FG9kKqS8JWdMMmdRtziAxIwJnI43pEKw/TWjGC79sde6jt9jqDL +gEqOg6vd7AA5aXMLeQ9YYsWORXdr+3sKFLI3heEz7bbdDfpqmwZCZJjD 4VuB9fsb3AIRpddyn+dypKN0VMpOEkc/BLA636nbtVovaFMV9F81o0ABa EQJZfYgkcfvlQ0IwKFq37dfku6LWHDDw8osb3vqEKl39bGDgiruXvrcWu 7LK5pNMaPj7MgGs+xry4fDv1ZJzEFeN6oVsqeBulPp+CXlaYFgDiGNbUt s2uOEBFStxkCJUUII0HffefsbhaUT6Xr0SuBhhRl4GON6FJQUd1SK3858 A==; X-CSE-ConnectionGUID: eetdd7ixTlqvxwvW+qtzPA== X-CSE-MsgGUID: lvFHQwM8Spu3Up95JnnbPQ== X-IronPort-AV: E=McAfee;i="6700,10204,11177"; a="27123861" X-IronPort-AV: E=Sophos;i="6.10,182,1719903600"; d="scan'208";a="27123861" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Aug 2024 02:35:14 -0700 X-CSE-ConnectionGUID: mE4SB/2cQ3udmPZuq77twg== X-CSE-MsgGUID: exjcmjNoRJO1eRNaXbGNbQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,182,1719903600"; d="scan'208";a="93879094" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa002.jf.intel.com with ESMTP; 28 Aug 2024 02:35:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id AB30C1F5; Wed, 28 Aug 2024 12:35:10 +0300 (EEST) From: "Kirill A. Shutemov" To: "Kirill A. Shutemov" , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Kai Huang Subject: [PATCHv6 4/4] x86/tdx: Enable CPU topology enumeration Date: Wed, 28 Aug 2024 12:35:05 +0300 Message-ID: <20240828093505.2359947-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240828093505.2359947-1-kirill.shutemov@linux.intel.com> References: <20240828093505.2359947-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit TDX 1.0 defines baseline behaviour of TDX guest platform. TDX 1.0 generates a #VE when accessing topology-related CPUID leafs (0xB and 0x1F) and the X2APIC_APICID MSR. The kernel returns all zeros on CPUID topology. In practice, this means that the kernel can only boot with a plain topology. Any complications will cause problems. The ENUM_TOPOLOGY feature allows the VMM to provide topology information to the guest. Enabling the feature eliminates topology-related #VEs: the TDX module virtualizes accesses to the CPUID leafs and the MSR. Enable ENUM_TOPOLOGY if it is available. Signed-off-by: Kirill A. Shutemov Acked-by: Kai Huang --- arch/x86/coco/tdx/tdx.c | 27 +++++++++++++++++++++++++++ arch/x86/include/asm/shared/tdx.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index f969f4f5ebf8..ca162a7ce4d1 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -249,6 +249,32 @@ static void disable_sept_ve(u64 td_attr) return; } +/* + * TDX 1.0 generates a #VE when accessing topology-related CPUID leafs (0xB and + * 0x1F) and the X2APIC_APICID MSR. The kernel returns all zeros on CPUID #VEs. + * In practice, this means that the kernel can only boot with a plain topology. + * Any complications will cause problems. + * + * The ENUM_TOPOLOGY feature allows the VMM to provide topology information. + * Enabling the feature eliminates topology-related #VEs: the TDX module + * virtualizes accesses to the CPUID leafs and the MSR. + * + * Enable ENUM_TOPOLOGY if it is available. + */ +static void enable_cpu_topology_enumeration(void) +{ + u64 configured; + + /* Has the VMM provided a valid topology configuration? */ + tdg_vm_rd(TDCS_TOPOLOGY_ENUM_CONFIGURED, &configured); + if (!configured) { + pr_err("VMM did not configure X2APIC_IDs properly\n"); + return; + } + + tdg_vm_wr(TDCS_TD_CTLS, TD_CTLS_ENUM_TOPOLOGY, TD_CTLS_ENUM_TOPOLOGY); +} + static void tdx_setup(u64 *cc_mask) { struct tdx_module_args args = {}; @@ -280,6 +306,7 @@ static void tdx_setup(u64 *cc_mask) tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL); disable_sept_ve(td_attr); + enable_cpu_topology_enumeration(); } /* diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h index fecb2a6e864b..89f7fcade8ae 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -23,12 +23,14 @@ #define TDCS_CONFIG_FLAGS 0x1110000300000016 #define TDCS_TD_CTLS 0x1110000300000017 #define TDCS_NOTIFY_ENABLES 0x9100000000000010 +#define TDCS_TOPOLOGY_ENUM_CONFIGURED 0x9100000000000019 /* TDCS_CONFIG_FLAGS bits */ #define TDCS_CONFIG_FLEXIBLE_PENDING_VE BIT_ULL(1) /* TDCS_TD_CTLS bits */ #define TD_CTLS_PENDING_VE_DISABLE BIT_ULL(0) +#define TD_CTLS_ENUM_TOPOLOGY BIT_ULL(1) /* TDX hypercall Leaf IDs */ #define TDVMCALL_MAP_GPA 0x10001 -- 2.45.2