Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1496168lqo; Sun, 12 May 2024 05:22:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWsG3Fwnz8RUUE6v57x/0lijIOInjKJ/nngrgstdevOmDgqSHuHPe/ZoASGKqIjHYAMS0EwSpwlz+wmTbodyOcLVXwVhu+9s8yi3Vv9xQ== X-Google-Smtp-Source: AGHT+IGGEQEKMD1Ri5cKrtO9rhxkOs5mfxIOZyWId8Cw7Ktb9yyu5VwMT7wOYGEcoFV0CTQro1d3 X-Received: by 2002:a50:aa91:0:b0:56e:34e0:4699 with SMTP id 4fb4d7f45d1cf-5734d67eb8bmr5129704a12.30.1715516532001; Sun, 12 May 2024 05:22:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715516531; cv=pass; d=google.com; s=arc-20160816; b=HbIMl9TMGg89+yL+uTatncyZfrDlX3z9aiKwLAhkHpHLIFCURtLBVdk8svS/4hkDMD FDmG1mJpD+O6f14E5h34uF/ZcuX6uUB91pwP3XEPoeXU9ycig+R9m0f1TTuNtuyTVj3v QTRepd9Apr8uKknAGSSFQddQgdpdAnAEml5dft5WMYt4Zlk+oYXtGVizdPgu1oUr8V/L Jzo+EGOb5QUHsthd0nsYHr5aA23E+Z2YJVjqW5CKj5KZzVxy+kKo/HFsShZ/dzRPxVVZ T1aIMZG2O1m9VeNOidn86RJyxw5fK//YwNCbDDsAvWqfsv9oWz6jOsgJm+4T+c+kYV6x 9rCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sqpsnwb7r8SYBk9SEIYCwOfXhNMzx5BwAh5ljPaSgsc=; fh=EX3xgfA35ZrmQvF3iQjPnQBNbPC0IslQ8YH4YoBxFtU=; b=jOJ8JQePlXi1uJy9nwHr5J1rTw4NsHuiA5sIx3Zyw+vERZovpKZF8nLH3eCqw1v7oA 29ysryoNRx1QIQUiImTIQhEc2kX1sb4i/TQtPHY91mUqu2BNa4Ms8dSLhsO/dpHEy7fu sN88fcoDlHjYr3Vi7N3cwm8GDtDW3o+OF0xDxOgWmUTcVv1OmzZ6DBsDuKK+lc9wXeo1 fld+odW3dbSHG7TT6GwlR+5VwI0x0muldm2bvTYHjYxtmsEVYrI4jjSO4O59G7Kc4s+z 9iDPXYECxFamAaihOiJCTxnb0ASEPVieBqUjjplufRkPdZq+Q+SUcj0SlrcSHp876HJm FwuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FuELW9xs; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-176873-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176873-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733beac9cdsi3795364a12.12.2024.05.12.05.22.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 05:22:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176873-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FuELW9xs; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-176873-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176873-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8613B1F2133A for ; Sun, 12 May 2024 12:22:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D3AF2233A; Sun, 12 May 2024 12:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FuELW9xs" 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 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