Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp345744lqk; Sat, 9 Mar 2024 13:03:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUAF5ShtVPJzNrC/w6Wu3lXXA+JSVtAQzeRyEnJwbyztyh9cEtHfpPe6Rocdhr7cTR01GQWhjljZQ9IfVLqE5MqwxzJevp8BGmp7KaUPA== X-Google-Smtp-Source: AGHT+IEhyTukl7owlcgCHTFie9CjFiWKxGmWBejn4d1fasK67C4nb9lwIKNxz6EZoddBBZYETWlr X-Received: by 2002:a05:6a21:9204:b0:1a2:f4fd:b1fd with SMTP id tl4-20020a056a21920400b001a2f4fdb1fdmr2907058pzb.39.1710018187241; Sat, 09 Mar 2024 13:03:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1710018187; cv=pass; d=google.com; s=arc-20160816; b=0uHn+hUe2HfTsHhRb4v/NbcwwDZkd81iCSIJb5pa1IBxaYzO7fVZ+zfpdz1L1/JCOw E3q96534tS3Kb/ReWmP5H24Uv5xKoIvBY0ammZJmX9QC8kmwUcmtpJ7ntfYNMVyH3J6M yTPUFBNNVf0CVfz78HmWcI4VIgYOu2dKUzE4bp3+Kb/gXajVmbZvPRPWlW2gfzCIYJ27 k1ZZ60Dkxrw8fXvGUyYZ5fmZ0pAHD/X/u/EkpcOj4xhuVT5BoV/nlUX4otvF9040TVfx MKfWX//uJImqpvfLTV58fvhXU96QryTXySlun3bYDiB4a0pomJ3cM8PmWjnzApMYUguc lr2Q== 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=v/gfab6v/LjVfWzQBeHTsboPVSpMAbFL9NbeWHi+54A=; fh=YMuuNPyUXI0AJwiZjqysmCxLaSvj2OpzRe8RWUogZnA=; b=ubD6RqvxENb4fWR7nWcVLmAvDdR58FFPVEQPulFveZ4NUbPOcl+f3PIdNE2Vb9C6r2 cyvx9SJUhDCq2FgZmgMPDN4a5D0wlWkltUY9v6jHJq8XQ5ZrJ8Hilr+yKlVkaZruKvEX 0q0SqVrYXrAUpY3R+NYvU1IviBMC2H0egFx4girtqUWl1BM7X5GAkdZoT8QCUKWV2WK0 pbSqnVvHWE9Zit7Ab3XkVjtquTQjY3sk/uGLNd3qoqws5vYdw/Jc7P5HK1JRzE1WaXhM q0Ts+ldWR7Mz/7Sr2BKHkpYOWEnTnXx5/h6CQH+/tklACW7NsU0ASNh/VHMKC7m0m7YY Xh3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="B/CYXRBT"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-98040-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98040-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n36-20020a635924000000b005e456b2d72bsi2030857pgb.473.2024.03.09.13.03.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 13:03:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98040-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="B/CYXRBT"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-98040-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98040-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4B838281E12 for ; Sat, 9 Mar 2024 21:03:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0233524A6; Sat, 9 Mar 2024 21:02:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="B/CYXRBT" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 9DC6B4F200 for ; Sat, 9 Mar 2024 21:02:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710018170; cv=none; b=d0Er4zXf2EECZoTtst/nujoG8p7es3Dh0lvQ9cnav+AsQ9bye7uQXMt5xTpBby7aC1Nw792bVJTvzE2lZrNVPdHFb/0qbLbykJB6EYqgdMnsHJlOYcYRO2qlEUDNY3Wnu9ydEMP/zslLBUaTeji6GLY8wIU/PDouc25ycpC/rws= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710018170; c=relaxed/simple; bh=Jk5tt+gSzYYhQIlktRhIlr+6QKg9CrR+h9qHi82xD1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=peCJ4klOpCwqtiUCpQ+pTaKH39kUA4ujM1ofYYkCz3UghGIZxHkAUVeY273GPact8sdSTHf+UA5TP38zifrpGW3ZryQItlm/CIOHddsNQDqbgvtxpPD8bzYm5noNNSH6Y+VpLdVBjlkyX4EOXRuUZGMH5o9B9xvI+v/tHRc/hXQ= 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=B/CYXRBT; arc=none smtp.client-ip=198.175.65.17 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=1710018169; x=1741554169; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jk5tt+gSzYYhQIlktRhIlr+6QKg9CrR+h9qHi82xD1w=; b=B/CYXRBTq1CO3EIP5Bf+ynumSwyEWPIJGWLeCiNd2m74alrDz1BcWVux H0k1oI8ph34TXas9b/dJoKMcSALlFjEU4YipIeGxGlg3U+GpYp19T10SR mQFQoqyLsxk6q4pjBSlKHvCC0oXUJ7OxO84z/lPZkicHmxJ6ozXVtOycm xaocAc9bDOI4qXsLzKcgaL5VDq5snXVX9/EQJVMA8diAm+l5SRLYMu9qj /Bk+toN/eQ1VaBe4scpCzbk7hYd/EjP539wYaw1X0E02/X9KCImuu8fWe IOiFx+K9hVooD/rXrQxmzi8RabhEiI0BEexq4lUE8o2xX7jB+jK6iEvwk g==; X-IronPort-AV: E=McAfee;i="6600,9927,11008"; a="4861561" X-IronPort-AV: E=Sophos;i="6.07,113,1708416000"; d="scan'208";a="4861561" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2024 13:02:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11008"; a="937048389" X-IronPort-AV: E=Sophos;i="6.07,113,1708416000"; d="scan'208";a="937048389" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 09 Mar 2024 13:02:43 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 6402B385; Sat, 9 Mar 2024 23:02:42 +0200 (EET) From: "Kirill A. Shutemov" To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com Cc: sathyanarayanan.kuppuswamy@linux.intel.com, hpa@zytor.com, seanjc@google.com, ele.reshetova@intel.com, rick.p.edgecombe@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 4/4] x86/tdx: Enable ENUM_TOPOLOGY Date: Sat, 9 Mar 2024 23:02:30 +0200 Message-ID: <20240309210230.239045-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240309210230.239045-1-kirill.shutemov@linux.intel.com> References: <20240309210230.239045-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 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 to the guest in a safe manner. 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 | 20 ++++++++++++++++++++ arch/x86/include/asm/shared/tdx.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index d9ea82f8772d..291e45db8d54 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -280,6 +280,26 @@ static void tdx_setup(u64 *cc_mask) else tdx_panic(msg); } + + /* + * 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 to the guest in a safe manner. 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. + */ + if ((features & TDX_FEATURES0_ENUM_TOPOLOGY) && + tdg_vm_rd(TDCS_TOPOLOGY_ENUM_CONFIGURED)) { + tdg_vm_wr(TDCS_TD_CTLS, + TD_CTLS_ENUM_TOPOLOGY, + TD_CTLS_ENUM_TOPOLOGY); + } } /* diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h index 29a61c72e4dd..2964c506b241 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -27,15 +27,18 @@ #define TDCS_CONFIG_FLAGS 0x1110000300000016 #define TDCS_TD_CTLS 0x1110000300000017 #define TDCS_NOTIFY_ENABLES 0x9100000000000010 +#define TDCS_TOPOLOGY_ENUM_CONFIGURED 0x9100000000000019 /* TDCS_TDX_FEATURES0 bits */ #define TDX_FEATURES0_PENDING_EPT_VIOLATION_V2 BIT_ULL(16) +#define TDX_FEATURES0_ENUM_TOPOLOGY BIT_ULL(20) /* 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