From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 1E36820B0F for ; Sun, 12 May 2024 12:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715516523; cv=none; b=anZ7QP+OrhyDn8cIYzLt2rqd/iF4xE/rMmzwt5pvsED/CA6EKoVFcsLLZjJeLiZK+YkwjUkbAYUJnxOSxiunq94JSxWNwerSySEosbIYMGUe5HMm0BkuIAuBTitq11ewlBQXEeA7utlwo0rGxdbTUtuSyNQdKbYf2GL+M8M2pjU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715516523; c=relaxed/simple; bh=1L/LeMCvdG95GfQutp5DhkXxXFbSvEvxpQI1cazpUQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SRRlYWhhA1O9+xF6kUjvDHQDU5eCkeZuqugLnnTDGDiLKlGKXjJXvz7z1gSX0G+4H+IKAVOgCr9JI+oTrN96Jc23AyHpg8rveUsL5JNWjSMRvJTaKVMRdmcXh2+EEZoMQQfp0XIe5VDEh88yJxGa2U//bnilRgnfTsXP8aidtaE= 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=FuELW9xs; arc=none smtp.client-ip=198.175.65.21 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="FuELW9xs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715516522; x=1747052522; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1L/LeMCvdG95GfQutp5DhkXxXFbSvEvxpQI1cazpUQA=; b=FuELW9xsPzP//XCtqUGDDl0ugNfs1Qj5JtMz7FOTpsRhFfmx0rbrSZSr IL2pHkat/IIPcztekk1fyHutMDElzC+SE7XVTXv7hSxfAQnRp3OJgVhhN DgX7FtrfIRa5FekPIjIvWg6Lz9nKNOb3h2KXduT1R2sVPQcZpYDjuSRHZ DXfyl7fbDCllB16MqLKQ9/o3/RghFF1fYyKHZlpbXGVbDN9KeZDvwXwu2 zff+gE4sogenAEQxY/ng+eu1sNAxoVoPPcwz//++ZJ1pa6tPKYCx+gfeM 5X1wnbn1M1cCYssHEVQxaWz6E32wuCOKnQswwLjIl5Y7uhJKjWFoiYg5u A==; X-CSE-ConnectionGUID: +Q1vAMjER1eqOQ4v7/tS0Q== X-CSE-MsgGUID: D/ONP/MvQqGOUoe7v8lHQw== X-IronPort-AV: E=McAfee;i="6600,9927,11071"; a="11397027" X-IronPort-AV: E=Sophos;i="6.08,155,1712646000"; d="scan'208";a="11397027" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2024 05:22:01 -0700 X-CSE-ConnectionGUID: b8CjFX4xSV6XLwWbmvIoFw== X-CSE-MsgGUID: I5V4C1HATNOjYEwub3/XUw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,155,1712646000"; d="scan'208";a="67579699" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 12 May 2024 05:21:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 3A21B317; Sun, 12 May 2024 15:21:58 +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 Subject: [PATCHv4 4/4] x86/tdx: Enable CPU topology enumeration Date: Sun, 12 May 2024 15:21:54 +0300 Message-ID: <20240512122154.2655269-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240512122154.2655269-1-kirill.shutemov@linux.intel.com> References: <20240512122154.2655269-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit TDX 1.0 defines baseline behaviour of TDX guest platform. In 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 --- 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 ba37f4306f4e..53d0b9df5a7f 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.43.0