From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 403E647A0D8; Wed, 13 May 2026 15:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685099; cv=none; b=Od0ERNmlsRhDWcPd7ooeJoqiS04fqfOexfxZluAGVGyfk+9J3CKkmmXp8TrBmZSDB5fFjVz4iXPz4Ifx/YU9Tgj4dQ5GHAUXuqHCP7KkCEQ1jnzRMv3UnLNqNcFjMjlhHaOZx4Ii7fFmHd1wWK85uFGDgOW97lAsk3/gDCX8tKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685099; c=relaxed/simple; bh=Q8zn3+57xVhPeBvtlErti71SyryRapBvOpJGYi2Iikc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MNGGRDajOfT553aLzye3kCuBVYnonj7uopfAU4Ncoj1T4m1nfKz++PqgkQZM79mxZZbffUuUS3TzAnsrfbCO/oaxZbHiqJYoQgl9voFGYRkG5C29J3vexQ4KaJSvEBm7XFZfU/qi5KGYxtygIHfhgFvziMdxMj7SfCkXtbHtMOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FLrbuqcf; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FLrbuqcf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685098; x=1810221098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q8zn3+57xVhPeBvtlErti71SyryRapBvOpJGYi2Iikc=; b=FLrbuqcfgPuUoM5Aa3XlKI8jItNt5GvcPotoXZq+LciuhLPnQGzZIcAH CH8OpwN/R2n6CBOqKiZHN2BJ6VHYsINx610Xqj3ucZMSuNnNB2XTiFx33 crIHNKhVsBAeePpInFS/xssC+LoH4gsAbqnbMsYkx+qE4VVzf+GvmWu1M crsbvhqPHYyttXnGOzHfM5cuOd73dzcrCpiFsYcMnzo6fBXXTHSx7zd4U vVo4QuEtEhT6bmGiIQGjp4nxQu6NrS9rYNBxQlfTWnRVZheQ97FBGFSCd DzO4H8BIRobcUI2XSM+LmroijLOy78OBWpNyoeG7kfmOTldqP5L4BKqLI g==; X-CSE-ConnectionGUID: YKxWKhidSSaFFeyW8CtyVg== X-CSE-MsgGUID: SGLrYdDmRMuofoSrpQJpGA== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921581" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921581" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:36 -0700 X-CSE-ConnectionGUID: gUe4APOGSDaDVrAFRgqSDg== X-CSE-MsgGUID: EK3lNoAYSYyJplpO0ga00Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716742" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:36 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 01/23] x86/virt/tdx: Consolidate TDX global initialization states Date: Wed, 13 May 2026 08:09:44 -0700 Message-ID: <20260513151045.1420990-2-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" The kernel uses several global flags to guard one-time TDX initialization flows and prevent them from being repeated. When the TDX module is updated, all of those states must be reset so that the module can be initialized again. Today those states are kept as separate global variables, which makes the reset path awkward and easy to miss when a new state is added. Group the states into a single structure so they can be reset together, for example with memset(), and so a newly added state won't be missed. Drop the __ro_after_init annotation from tdx_module_initialized because the other two states do not have it. And with TDX module update support, all the states need to be writable at runtime. Signed-off-by: Chao Gao --- arch/x86/virt/vmx/tdx/tdx.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index c0c6281b08a5..0172b432f229 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -44,6 +44,13 @@ #include #include "tdx.h" =20 +struct tdx_module_state { + bool initialized; + bool sysinit_done; + int sysinit_ret; +}; + +static struct tdx_module_state tdx_module_state; static u32 tdx_global_keyid __ro_after_init; static u32 tdx_guest_keyid_start __ro_after_init; static u32 tdx_nr_guest_keyids __ro_after_init; @@ -58,7 +65,6 @@ static struct tdmr_info_list tdx_tdmr_list; static LIST_HEAD(tdx_memlist); =20 static struct tdx_sys_info tdx_sysinfo __ro_after_init; -static bool tdx_module_initialized __ro_after_init; =20 typedef void (*sc_err_func_t)(u64 fn, u64 err, struct tdx_module_args *arg= s); =20 @@ -113,30 +119,28 @@ static int try_init_module_global(void) { struct tdx_module_args args =3D {}; static DEFINE_RAW_SPINLOCK(sysinit_lock); - static bool sysinit_done; - static int sysinit_ret; =20 raw_spin_lock(&sysinit_lock); =20 - if (sysinit_done) + if (tdx_module_state.sysinit_done) goto out; =20 /* RCX is module attributes and all bits are reserved */ args.rcx =3D 0; - sysinit_ret =3D seamcall_prerr(TDH_SYS_INIT, &args); + tdx_module_state.sysinit_ret =3D seamcall_prerr(TDH_SYS_INIT, &args); =20 /* * The first SEAMCALL also detects the TDX module, thus * it can fail due to the TDX module is not loaded. * Dump message to let the user know. */ - if (sysinit_ret =3D=3D -ENODEV) + if (tdx_module_state.sysinit_ret =3D=3D -ENODEV) pr_err("module not loaded\n"); =20 - sysinit_done =3D true; + tdx_module_state.sysinit_done =3D true; out: raw_spin_unlock(&sysinit_lock); - return sysinit_ret; + return tdx_module_state.sysinit_ret; } =20 /** @@ -1299,7 +1303,7 @@ static __init int tdx_enable(void) =20 register_syscore(&tdx_syscore); =20 - tdx_module_initialized =3D true; + tdx_module_state.initialized =3D true; pr_info("TDX-Module initialized\n"); return 0; } @@ -1554,7 +1558,7 @@ void __init tdx_init(void) =20 const struct tdx_sys_info *tdx_get_sysinfo(void) { - if (!tdx_module_initialized) + if (!tdx_module_state.initialized) return NULL; =20 return (const struct tdx_sys_info *)&tdx_sysinfo; --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 6A7C547A0DD; Wed, 13 May 2026 15:11:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685101; cv=none; b=lWqPqSgQ+IR1j/TrYkdECQh0Ip7jfaseewuINCKHqc5QFbgdwaEfyLADwMLREzS4QcBxZBAPrGcS/EH2aSpucpke5okFCRdS9L7ETAhPnUpf5+9go2ZobFhuxyB7wzrbcqkrKg9EeY4O4DWFUjhfpiug8H1t2ZbD54uoBNBBj1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685101; c=relaxed/simple; bh=lvO/bL79m2HL36etwJxBtAXykeqehbg7haklsgoA7Q4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lQ2tSvYBHfqVMQFmK+eyaNTzaC5GY6vxlqVcNZXyLI8MrLL+Mw7cyNBrd8T8i8nprcO7duuEGcwBWtisPDDHF6vIc8Kn5OcV2uqdrK3znvAQAVC+ASdHPMPxi1vYWi1qnQtMywMQP37y9Xp1MLfVJQc0OEyA3fyU9/Wl05PhHVg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=I6GJxkrQ; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="I6GJxkrQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685099; x=1810221099; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lvO/bL79m2HL36etwJxBtAXykeqehbg7haklsgoA7Q4=; b=I6GJxkrQxCmsTr0DtDVRGm8/aFhAklLcF6Op7Biv7WhlsUaSxE1lnX5U FVFzudOv2HfEtZHEp4EtxTo6ju95jAVSivwJdHo98WAuizI8KVBGvSFIx awGyzepwxAdCARrwh4/BeWDvjubKXnNpaiFesMYlFRBEiIBu3kXM4+Ulf TJL2x1GXBsOcx7i3V9b9yStsyc4Oelz0XsybTGtQ+gaD6b/sCURocR8Ee GIqcFscGrjhCm/gr/hM7BnvTsExAnzOLdddiTwQ2bpa/pIZeEb8RWVKWz Qfy6ViZWmlEj2bdx3HfGac55hEpHCfT6zvtqTZ0Z+zsfhvJFDqHAcemYI Q==; X-CSE-ConnectionGUID: D8/04h9PScuKYje16A2Z7Q== X-CSE-MsgGUID: zFoB6L9hS6Gv6GfTKswrVQ== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921591" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921591" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:37 -0700 X-CSE-ConnectionGUID: 1ZZltKsBThWz/+AgPvNWkQ== X-CSE-MsgGUID: sVkv/9D/S2OQx+UQJm6vZA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716752" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:37 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 02/23] x86/virt/tdx: Move TDX_FEATURES0 bits to asm/tdx.h Date: Wed, 13 May 2026 08:09:45 -0700 Message-ID: <20260513151045.1420990-3-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" Move the TDX_FEATURES0 bit definitions from the private TDX header to asm/tdx.h, and opportunistically switch to BIT_ULL() since TDX_FEATURES0 is 64-bit. This prepares for TDX module update [1] and Dynamic PAMT [2] support. Both add new TDX_FEATURES0 capability bits, and both need those capabilities to be queried from code outside arch/x86/virt. The corresponding feature-query helpers therefore need to live in the public asm/tdx.h header, so move the existing bit definitions there first. No functional change intended. Signed-off-by: Chao Gao Link: https://lore.kernel.org/kvm/20260427152854.101171-17-chao.gao@intel.c= om/ # [1] Link: https://lore.kernel.org/kvm/20251121005125.417831-16-rick.p.edgecombe= @intel.com/ # [2] --- arch/x86/include/asm/tdx.h | 3 +++ arch/x86/virt/vmx/tdx/tdx.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 15eac89b0afb..e2430dd0e4d5 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -32,6 +32,9 @@ #define TDX_SUCCESS 0ULL #define TDX_RND_NO_ENTROPY 0x8000020300000000ULL =20 +/* Bit definitions of TDX_FEATURES0 metadata field */ +#define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18) + #ifndef __ASSEMBLER__ =20 #include diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index e2cf2dd48755..76c5fb1e1ffe 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -85,9 +85,6 @@ struct tdmr_info { DECLARE_FLEX_ARRAY(struct tdmr_reserved_area, reserved_areas); } __packed __aligned(TDMR_INFO_ALIGNMENT); =20 -/* Bit definitions of TDX_FEATURES0 metadata field */ -#define TDX_FEATURES0_NO_RBP_MOD BIT(18) - /* * Do not put any hardware-defined TDX structure representations below * this comment! --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 88E0047B425; Wed, 13 May 2026 15:11:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685101; cv=none; b=Ydvb86IvGVgWTg8tFEtcwNt9dkhLhhi1R1k45zslqbw+BDCGgNMKrWgCkGkIgWQtAcFsoH3sp1zI0U9SUUoIpb9hBUkT+OKOQqMphYcQ9DOL1N/fG5ZeF11TrQMfjMZ5res4AY1df+3RRLpVHGbZIfyBnKr94AKBzOa6t9PfOos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685101; c=relaxed/simple; bh=9fwy8zpUHeDjFo7CjIow82JQQkjuiQ59WqYfugLc6jM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O2X86eKXWWNHxZOZzIM9WvYbSp7mOKVGqb286JgFGkK1pmkQv3Jib4G0gOLUPMlOGcwIAqL8mKtBqnijHc9MQUgx4GSeaqncNQD7uTfdzDrHgUDH1Vhh5Fwt/g97OG6IKFnTXQhEgOOPP76TsPbIpAgPFVZerSrNcTokx65/vow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YwF3Dc5o; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YwF3Dc5o" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685099; x=1810221099; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9fwy8zpUHeDjFo7CjIow82JQQkjuiQ59WqYfugLc6jM=; b=YwF3Dc5oH3JvbhSuvjUKJps8ViPEQNOWzIPNttfBcla/tTTyz0CMqJ/Q vLmYbM2mkc5GaiGlCTxvwvEqrzLHk1KOFTfuQYorywG+vxquezLhUP5xj 82h4EGkNxzUZxip9g6HdC6pb+kxeWc7vEt4upSwvXabseBPEsYAFqzIA0 Mi5qAlmjhnmDUeJ0wPOp9hIyBJmFVebvTliLi28AfzrgSFsCyI/ueZ92m jrsWcrojlCKjgsnlwUWcxsebo0EPRBDS+9T4Gg5Ruyqj4E3l2Rcl1Tw0n eYkQNhncktSQmI0PI0ATUSDFb+vbFVyXSbY1AAV0DJ+/obT750toPGikA Q==; X-CSE-ConnectionGUID: qRkQfN84R9Gy5b7WFlm8mw== X-CSE-MsgGUID: xskSrCu5RkKkCjxw5lLeZQ== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921602" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921602" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:39 -0700 X-CSE-ConnectionGUID: yvQIolPCRLa684uzpQ9t0A== X-CSE-MsgGUID: wVfJdzntQsyhbJzLLBNjtA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716760" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:38 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Zhenzhong Duan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 03/23] x86/virt/tdx: Move low level SEAMCALL helpers out of Date: Wed, 13 May 2026 08:09:46 -0700 Message-ID: <20260513151045.1420990-4-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kai Huang TDX host core code implements three seamcall*() helpers to make SEAMCALLs to the TDX module. Currently, they are implemented in and are exposed to other kernel code which includes . However, other than the TDX host core, seamcall*() are not expected to be used by other kernel code directly. For instance, for all SEAMCALLs that are used by KVM, the TDX host core exports a wrapper function for each of them. Move seamcall*() and related code out of and make them only visible to TDX host core. Since TDX host core tdx.c is already very heavy, don't put low level seamcall*() code there but to a new dedicated "seamcall_internal.h". Also, currently tdx.c has seamcall_prerr*() helpers which additionally print error message when calling seamcall*() fails. Move them to "seamcall_internal.h" as well. In such way all low level SEAMCALL helpers are in a dedicated place, which is much more readable. Copy the copyright notice from the original files and consolidate the date ranges to: Copyright (C) 2021-2023 Intel Corporation Signed-off-by: Kai Huang Signed-off-by: Chao Gao Reviewed-by: Zhenzhong Duan Reviewed-by: Binbin Wu Reviewed-by: Tony Lindgren Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Xiaoyao Li Reviewed-by: Vishal Annapurve Acked-by: Dave Hansen --- arch/x86/include/asm/tdx.h | 47 ---------- arch/x86/virt/vmx/tdx/seamcall_internal.h | 109 ++++++++++++++++++++++ arch/x86/virt/vmx/tdx/tdx.c | 47 +--------- 3 files changed, 111 insertions(+), 92 deletions(-) create mode 100644 arch/x86/virt/vmx/tdx/seamcall_internal.h diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index e2430dd0e4d5..8b739ac01479 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -100,54 +100,7 @@ static inline long tdx_kvm_hypercall(unsigned int nr, = unsigned long p1, #endif /* CONFIG_INTEL_TDX_GUEST && CONFIG_KVM_GUEST */ =20 #ifdef CONFIG_INTEL_TDX_HOST -u64 __seamcall(u64 fn, struct tdx_module_args *args); -u64 __seamcall_ret(u64 fn, struct tdx_module_args *args); -u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); void tdx_init(void); - -#include -#include -#include - -typedef u64 (*sc_func_t)(u64 fn, struct tdx_module_args *args); - -static __always_inline u64 __seamcall_dirty_cache(sc_func_t func, u64 fn, - struct tdx_module_args *args) -{ - lockdep_assert_preemption_disabled(); - - /* - * SEAMCALLs are made to the TDX module and can generate dirty - * cachelines of TDX private memory. Mark cache state incoherent - * so that the cache can be flushed during kexec. - * - * This needs to be done before actually making the SEAMCALL, - * because kexec-ing CPU could send NMI to stop remote CPUs, - * in which case even disabling IRQ won't help here. - */ - this_cpu_write(cache_state_incoherent, true); - - return func(fn, args); -} - -static __always_inline u64 sc_retry(sc_func_t func, u64 fn, - struct tdx_module_args *args) -{ - int retry =3D RDRAND_RETRY_LOOPS; - u64 ret; - - do { - preempt_disable(); - ret =3D __seamcall_dirty_cache(func, fn, args); - preempt_enable(); - } while (ret =3D=3D TDX_RND_NO_ENTROPY && --retry); - - return ret; -} - -#define seamcall(_fn, _args) sc_retry(__seamcall, (_fn), (_args)) -#define seamcall_ret(_fn, _args) sc_retry(__seamcall_ret, (_fn), (_args)) -#define seamcall_saved_ret(_fn, _args) sc_retry(__seamcall_saved_ret, (_fn= ), (_args)) const char *tdx_dump_mce_info(struct mce *m); const struct tdx_sys_info *tdx_get_sysinfo(void); =20 diff --git a/arch/x86/virt/vmx/tdx/seamcall_internal.h b/arch/x86/virt/vmx/= tdx/seamcall_internal.h new file mode 100644 index 000000000000..be5f446467df --- /dev/null +++ b/arch/x86/virt/vmx/tdx/seamcall_internal.h @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * SEAMCALL utilities for TDX host-side operations. + * + * Provides convenient wrappers around SEAMCALL assembly with retry logic, + * error reporting and cache coherency tracking. + * + * Copyright (C) 2021-2023 Intel Corporation + */ + +#ifndef _X86_VIRT_SEAMCALL_INTERNAL_H +#define _X86_VIRT_SEAMCALL_INTERNAL_H + +#include +#include +#include +#include +#include + +u64 __seamcall(u64 fn, struct tdx_module_args *args); +u64 __seamcall_ret(u64 fn, struct tdx_module_args *args); +u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); + +typedef u64 (*sc_func_t)(u64 fn, struct tdx_module_args *args); + +static __always_inline u64 __seamcall_dirty_cache(sc_func_t func, u64 fn, + struct tdx_module_args *args) +{ + lockdep_assert_preemption_disabled(); + + /* + * SEAMCALLs are made to the TDX module and can generate dirty + * cachelines of TDX private memory. Mark cache state incoherent + * so that the cache can be flushed during kexec. + * + * This needs to be done before actually making the SEAMCALL, + * because kexec-ing CPU could send NMI to stop remote CPUs, + * in which case even disabling IRQ won't help here. + */ + this_cpu_write(cache_state_incoherent, true); + + return func(fn, args); +} + +static __always_inline u64 sc_retry(sc_func_t func, u64 fn, + struct tdx_module_args *args) +{ + int retry =3D RDRAND_RETRY_LOOPS; + u64 ret; + + do { + preempt_disable(); + ret =3D __seamcall_dirty_cache(func, fn, args); + preempt_enable(); + } while (ret =3D=3D TDX_RND_NO_ENTROPY && --retry); + + return ret; +} + +#define seamcall(_fn, _args) sc_retry(__seamcall, (_fn), (_args)) +#define seamcall_ret(_fn, _args) sc_retry(__seamcall_ret, (_fn), (_args)) +#define seamcall_saved_ret(_fn, _args) sc_retry(__seamcall_saved_ret, (_fn= ), (_args)) + +typedef void (*sc_err_func_t)(u64 fn, u64 err, struct tdx_module_args *arg= s); + +static inline void seamcall_err(u64 fn, u64 err, struct tdx_module_args *a= rgs) +{ + pr_err("SEAMCALL (0x%016llx) failed: 0x%016llx\n", fn, err); +} + +static inline void seamcall_err_ret(u64 fn, u64 err, + struct tdx_module_args *args) +{ + seamcall_err(fn, err, args); + pr_err("RCX 0x%016llx RDX 0x%016llx R08 0x%016llx\n", + args->rcx, args->rdx, args->r8); + pr_err("R09 0x%016llx R10 0x%016llx R11 0x%016llx\n", + args->r9, args->r10, args->r11); +} + +static __always_inline int sc_retry_prerr(sc_func_t func, + sc_err_func_t err_func, + u64 fn, struct tdx_module_args *args) +{ + u64 sret =3D sc_retry(func, fn, args); + + if (sret =3D=3D TDX_SUCCESS) + return 0; + + if (sret =3D=3D TDX_SEAMCALL_VMFAILINVALID) + return -ENODEV; + + if (sret =3D=3D TDX_SEAMCALL_GP) + return -EOPNOTSUPP; + + if (sret =3D=3D TDX_SEAMCALL_UD) + return -EACCES; + + err_func(fn, sret, args); + return -EIO; +} + +#define seamcall_prerr(__fn, __args) \ + sc_retry_prerr(__seamcall, seamcall_err, (__fn), (__args)) + +#define seamcall_prerr_ret(__fn, __args) \ + sc_retry_prerr(__seamcall_ret, seamcall_err_ret, (__fn), (__args)) + +#endif /* _X86_VIRT_SEAMCALL_INTERNAL_H */ diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 0172b432f229..a0f8cf5e10d7 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -42,6 +42,8 @@ #include #include #include + +#include "seamcall_internal.h" #include "tdx.h" =20 struct tdx_module_state { @@ -66,51 +68,6 @@ static LIST_HEAD(tdx_memlist); =20 static struct tdx_sys_info tdx_sysinfo __ro_after_init; =20 -typedef void (*sc_err_func_t)(u64 fn, u64 err, struct tdx_module_args *arg= s); - -static inline void seamcall_err(u64 fn, u64 err, struct tdx_module_args *a= rgs) -{ - pr_err("SEAMCALL (0x%016llx) failed: 0x%016llx\n", fn, err); -} - -static inline void seamcall_err_ret(u64 fn, u64 err, - struct tdx_module_args *args) -{ - seamcall_err(fn, err, args); - pr_err("RCX 0x%016llx RDX 0x%016llx R08 0x%016llx\n", - args->rcx, args->rdx, args->r8); - pr_err("R09 0x%016llx R10 0x%016llx R11 0x%016llx\n", - args->r9, args->r10, args->r11); -} - -static __always_inline int sc_retry_prerr(sc_func_t func, - sc_err_func_t err_func, - u64 fn, struct tdx_module_args *args) -{ - u64 sret =3D sc_retry(func, fn, args); - - if (sret =3D=3D TDX_SUCCESS) - return 0; - - if (sret =3D=3D TDX_SEAMCALL_VMFAILINVALID) - return -ENODEV; - - if (sret =3D=3D TDX_SEAMCALL_GP) - return -EOPNOTSUPP; - - if (sret =3D=3D TDX_SEAMCALL_UD) - return -EACCES; - - err_func(fn, sret, args); - return -EIO; -} - -#define seamcall_prerr(__fn, __args) \ - sc_retry_prerr(__seamcall, seamcall_err, (__fn), (__args)) - -#define seamcall_prerr_ret(__fn, __args) \ - sc_retry_prerr(__seamcall_ret, seamcall_err_ret, (__fn), (__args)) - /* * Do the module global initialization once and return its result. * It can be done on any cpu, and from task or IRQ context. --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 4A7DA47ECCA; Wed, 13 May 2026 15:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685105; cv=none; b=CMG7s5rYotyFjnIdTin7s9CCnqvaz4Ja1SC+89q1Fv3ZH3r+fgRbqDC6CczhcQ1HckTErTU1Vx5xwPT0K5ypuvqSKH4mrmDiKm6RtytOJP9ixZcFRfOOaApwmVOn7gGLACpbqLDEjZIqqomfbrG5hOg7pAqSWLl8YIWUnZYQwAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685105; c=relaxed/simple; bh=zBGe14IW9iWe8WWpwh+0JIynUX5NdF3El/gNiGITGcA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EVv2lZebugQ6L0ITy8k7lalO5iVvtksQQjXpUfR36Fsiz3yx5jvaWq6s/sx1DVDsYLkHbip09o3MzV2Nx2DRQyf+o96xqPQpZ91PwkrH9AKuZQJ3sU7K4bBwBfPE/4YDZEP6RRLXwwAoZBDn5UTuOAPgW4ATZZjqFip+HqGyDww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Oq6pjAMk; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Oq6pjAMk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685101; x=1810221101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zBGe14IW9iWe8WWpwh+0JIynUX5NdF3El/gNiGITGcA=; b=Oq6pjAMkGxpTemcvk10Usgb/lU4uWuCHPTUftocJ3Jaob6ShwZO1EEqO nosD1LLOxZ504tJ3WwF3IwIcqRxO0PMGynn0Jq7lgFnl8LrlLH8ikacZ6 cp+qsLRgvJnIBcv+oCEKMP/axVLJBl//Y0u8aECjMPZ5UcJhdk5vav+Y8 Y0k/hs9hqoRlExUxfYfJDB+fbHfqy/dhmh1PvNpNY5qKy95FLQoMMMlv0 fEEHYZ78OUOTmbcO1XNEvjiRYtUcnMSuPoIjUy4I43tyrw+t2RZ0L2SdI Ccm8qaUdx8KEoED5Ug6fJ/rrjOlMqsOyItdi7qGCXsf9dTqnDfxS45n3C w==; X-CSE-ConnectionGUID: MkPHV+lWR6uqsukVkISY7w== X-CSE-MsgGUID: wKDOvjZDRaqCT2+/bxIZvA== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921618" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921618" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:40 -0700 X-CSE-ConnectionGUID: sL131AszSFKOd+Xwh7LJUg== X-CSE-MsgGUID: sE+bIgOkTWyM9slmCGp+Rg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716771" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:40 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Dan Williams , Jonathan Cameron , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 04/23] coco/tdx-host: Introduce a "tdx_host" device Date: Wed, 13 May 2026 08:09:47 -0700 Message-ID: <20260513151045.1420990-5-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" TDX depends on a platform firmware module that is invoked via instructions similar to vmenter (i.e. enter into a new privileged "root-mode" context to manage private memory and private device mechanisms). It is a software construct that depends on the CPU vmxon state to enable invocation of TDX module ABIs. Unlike other Trusted Execution Environment (TEE) platform implementations that employ a firmware module running on a PCI device with an MMIO mailbox for communication, TDX has no hardware device to point to as the TEE Secure Manager (TSM). Create a virtual device not only to align with other implementations but also to make it easier to - expose metadata (e.g., TDX module version, seamldr version etc) to the userspace as device attributes - implement firmware uploader APIs which are tied to a device. This is needed to support TDX module runtime updates - enable TDX Connect which will share a common infrastructure with other platform implementations. In the TDX Connect context, every architecture has a TSM, represented by a PCIe or virtual device. The new "tdx_host" device will serve the TSM role. A faux device is used for TDX because the TDX module is singular within the system and lacks associated platform resources. Using a faux device eliminates the need to create a stub bus. The call to tdx_get_sysinfo() ensures that the TDX module is ready to provide services. Note that AMD has a PCI device for the PSP for SEV and ARM CCA will likely have a faux device [1]. Co-developed-by: Xu Yilun Signed-off-by: Xu Yilun Signed-off-by: Dan Williams Signed-off-by: Chao Gao Reviewed-by: Jonathan Cameron Reviewed-by: Tony Lindgren Reviewed-by: Xu Yilun Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Xiaoyao Li Link: https://lore.kernel.org/all/2025073035-bulginess-rematch-b92e@gregkh/= # [1] --- arch/x86/virt/vmx/tdx/tdx.c | 2 +- drivers/virt/coco/Kconfig | 2 ++ drivers/virt/coco/Makefile | 1 + drivers/virt/coco/tdx-host/Kconfig | 10 +++++++ drivers/virt/coco/tdx-host/Makefile | 1 + drivers/virt/coco/tdx-host/tdx-host.c | 43 +++++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 drivers/virt/coco/tdx-host/Kconfig create mode 100644 drivers/virt/coco/tdx-host/Makefile create mode 100644 drivers/virt/coco/tdx-host/tdx-host.c diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index a0f8cf5e10d7..837e9b36e1ea 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1520,7 +1520,7 @@ const struct tdx_sys_info *tdx_get_sysinfo(void) =20 return (const struct tdx_sys_info *)&tdx_sysinfo; } -EXPORT_SYMBOL_FOR_KVM(tdx_get_sysinfo); +EXPORT_SYMBOL_FOR_MODULES(tdx_get_sysinfo, "kvm-intel,tdx-host"); =20 u32 tdx_get_nr_guest_keyids(void) { diff --git a/drivers/virt/coco/Kconfig b/drivers/virt/coco/Kconfig index df1cfaf26c65..f7691f64fbe3 100644 --- a/drivers/virt/coco/Kconfig +++ b/drivers/virt/coco/Kconfig @@ -17,5 +17,7 @@ source "drivers/virt/coco/arm-cca-guest/Kconfig" source "drivers/virt/coco/guest/Kconfig" endif =20 +source "drivers/virt/coco/tdx-host/Kconfig" + config TSM bool diff --git a/drivers/virt/coco/Makefile b/drivers/virt/coco/Makefile index cb52021912b3..b323b0ae4f82 100644 --- a/drivers/virt/coco/Makefile +++ b/drivers/virt/coco/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_EFI_SECRET) +=3D efi_secret/ obj-$(CONFIG_ARM_PKVM_GUEST) +=3D pkvm-guest/ obj-$(CONFIG_SEV_GUEST) +=3D sev-guest/ obj-$(CONFIG_INTEL_TDX_GUEST) +=3D tdx-guest/ +obj-$(CONFIG_INTEL_TDX_HOST) +=3D tdx-host/ obj-$(CONFIG_ARM_CCA_GUEST) +=3D arm-cca-guest/ obj-$(CONFIG_TSM) +=3D tsm-core.o obj-$(CONFIG_TSM_GUEST) +=3D guest/ diff --git a/drivers/virt/coco/tdx-host/Kconfig b/drivers/virt/coco/tdx-hos= t/Kconfig new file mode 100644 index 000000000000..d35d85ef91c0 --- /dev/null +++ b/drivers/virt/coco/tdx-host/Kconfig @@ -0,0 +1,10 @@ +config TDX_HOST_SERVICES + tristate "TDX Host Services Driver" + depends on INTEL_TDX_HOST + default m + help + Enable access to TDX host services like module update and + extensions (e.g. TDX Connect). + + Say y or m if enabling support for confidential virtual machine + support (CONFIG_INTEL_TDX_HOST). The module is called tdx_host.ko. diff --git a/drivers/virt/coco/tdx-host/Makefile b/drivers/virt/coco/tdx-ho= st/Makefile new file mode 100644 index 000000000000..e61e749a8dff --- /dev/null +++ b/drivers/virt/coco/tdx-host/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_TDX_HOST_SERVICES) +=3D tdx-host.o diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-= host/tdx-host.c new file mode 100644 index 000000000000..c77885392b09 --- /dev/null +++ b/drivers/virt/coco/tdx-host/tdx-host.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * TDX host user interface driver + * + * Copyright (C) 2025 Intel Corporation + */ + +#include +#include +#include + +#include +#include + +static const struct x86_cpu_id tdx_host_ids[] =3D { + X86_MATCH_FEATURE(X86_FEATURE_TDX_HOST_PLATFORM, NULL), + {} +}; +MODULE_DEVICE_TABLE(x86cpu, tdx_host_ids); + +static struct faux_device *fdev; + +static int __init tdx_host_init(void) +{ + if (!x86_match_cpu(tdx_host_ids) || !tdx_get_sysinfo()) + return -ENODEV; + + fdev =3D faux_device_create(KBUILD_MODNAME, NULL, NULL); + if (!fdev) + return -ENODEV; + + return 0; +} +module_init(tdx_host_init); + +static void __exit tdx_host_exit(void) +{ + faux_device_destroy(fdev); +} +module_exit(tdx_host_exit); + +MODULE_DESCRIPTION("TDX Host Services"); +MODULE_LICENSE("GPL"); --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 A4D5348AE32; Wed, 13 May 2026 15:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685104; cv=none; b=uF5pIHVqtjqtvuny1zc2XRCeehPJoH+K0FFGQk2XtV752d9YmBhhNDsm+Ix8T708uHWmPAoCl5ZI8AmzzOV4rSAmRvW1b2l5Lk+pZjuGyuT27sAUnlOUMS6qFkAuN4MIwgEBzACCVBrBoDHLyk9OmiY7fXXiKzwT8JPeJBFIEoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685104; c=relaxed/simple; bh=cg8SSqDBv4OUaZrITmhuTemfdL/3RKhSlXE7vmCYkus=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jfw7qcFjjwDDCHZaEmZNxRqOUh5h0rBgC0n36C54DL3E94vWExDHIGqqCORg4am7F1Uwj47IrW2pDg1EfssjTvK3hkL7Mjq8n6DMl/jEQ2lWXNoiIkfWHiBgMfLSfPTMa1bEdz21ikDhuVEA5AyeIETUPhIj29P4EO2GziSC/Fw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gtDLvBEl; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gtDLvBEl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685102; x=1810221102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cg8SSqDBv4OUaZrITmhuTemfdL/3RKhSlXE7vmCYkus=; b=gtDLvBElsq6w9H9Epe4MsX43867qcAM8FcKdLDIzZe3U3FTLWGXM1+6d kfdxWNEdtm7I+ySs1MixaOiTzjO3fDwZnVW0zuiITQbhumNHx+ifX9iB4 rE9lTWRvC01QNQu6dvhWqgqcwWSViEV1MJZY4+YX85hSD9jkJnbCYB5b8 LMLiVwXW/+9ttaJVw1w4G7XHOIvVRL/os4OapHHXpUGOD7Iy1ZX8K83Ve HsXSHpJ2dIzBib6ArHNo0LKMjTLwUUNxyC7h0ngzEV2jnT11I+iNRILlg tO+B+dSZIgPGskw/5p5S2T2S+eUZE07CulVL7tm3rTMvMGWipubvJtkUp A==; X-CSE-ConnectionGUID: 78OHivT9RPWFz2V3ADCuJA== X-CSE-MsgGUID: FBLesWjvSZW2TO0lLBJKEg== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921629" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921629" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:42 -0700 X-CSE-ConnectionGUID: p/TXb/9IR+q9ZITHZb7Yqw== X-CSE-MsgGUID: L2pAa+C8SxqTOVzhidq4wQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716781" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:41 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 05/23] coco/tdx-host: Expose TDX module version Date: Wed, 13 May 2026 08:09:48 -0700 Message-ID: <20260513151045.1420990-6-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" For TDX module updates, userspace needs to select compatible update versions based on the current module version. This design delegates module selection complexity to userspace because TDX module update policies are complex and version series are platform-specific. For example, the 1.5.x series is for certain platform generations, while the 2.0.x series is intended for others. And TDX module 1.5.x may be updated to 1.5.y but not to 1.5.y+1. Expose the TDX module version to userspace via sysfs to aid module selection. Since the TDX faux device will drive module updates, expose the version as its attribute. One bonus of exposing TDX module version via sysfs is: TDX module version information remains available even after dmesg logs are cleared. Define TDX_VERSION_FMT macro for the TDX version format since it will be used multiple times. Also convert an existing print statement to use it. =3D=3D Background =3D=3D The "faux device + device attribute" approach compares to other update mechanisms as follows: 1. AMD SEV leverages an existing PCI device for the PSP to expose metadata. TDX uses a faux device as it doesn't have PCI device in its architecture. 2. Microcode uses per-CPU virtual devices to report microcode revisions because CPUs can have different revisions. But, there is only a single TDX module, so exposing the TDX module version through a global TDX faux device is appropriate 3. ARM's CCA implementation isn't in-tree yet, but will likely follow a similar faux device approach, though it's unclear whether they need to expose firmware version information Signed-off-by: Chao Gao Reviewed-by: Binbin Wu Reviewed-by: Tony Lindgren Reviewed-by: Xu Yilun Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Xiaoyao Li Link: https://lore.kernel.org/all/2025073035-bulginess-rematch-b92e@gregkh/= # [1] Reviewed-by: Dave Hansen --- .../ABI/testing/sysfs-devices-faux-tdx-host | 6 +++++ arch/x86/include/asm/tdx.h | 6 +++++ arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 2 +- drivers/virt/coco/tdx-host/tdx-host.c | 26 ++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-faux-tdx-host diff --git a/Documentation/ABI/testing/sysfs-devices-faux-tdx-host b/Docume= ntation/ABI/testing/sysfs-devices-faux-tdx-host new file mode 100644 index 000000000000..2cf682b65acf --- /dev/null +++ b/Documentation/ABI/testing/sysfs-devices-faux-tdx-host @@ -0,0 +1,6 @@ +What: /sys/devices/faux/tdx_host/version +Contact: linux-coco@lists.linux.dev +Description: (RO) Report the version of the loaded TDX module. The TDX mod= ule + version is formatted as x.y.z, where "x" is the major version, + "y" is the minor version and "z" is the update version. Versions + are used for bug reporting, TDX module updates etc. diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 8b739ac01479..b7f4396b5cc5 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -41,6 +41,12 @@ #include #include =20 +/* + * TDX module and P-SEAMLDR version convention: "major.minor.update" + * (e.g., "1.5.08") with zero-padded two-digit update field. + */ +#define TDX_VERSION_FMT "%u.%u.%02u" + /* * Used by the #VE exception handler to gather the #VE exception * info from the TDX module. This is a software only structure diff --git a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c b/arch/x86/virt/vm= x/tdx/tdx_global_metadata.c index c7db393a9cfb..d54d4227990c 100644 --- a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c +++ b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c @@ -106,7 +106,7 @@ static __init int get_tdx_sys_info(struct tdx_sys_info = *sysinfo) =20 ret =3D ret ?: get_tdx_sys_info_version(&sysinfo->version); =20 - pr_info("Module version: %u.%u.%02u\n", + pr_info("Module version: " TDX_VERSION_FMT "\n", sysinfo->version.major_version, sysinfo->version.minor_version, sysinfo->version.update_version); diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-= host/tdx-host.c index c77885392b09..ef117a836b3a 100644 --- a/drivers/virt/coco/tdx-host/tdx-host.c +++ b/drivers/virt/coco/tdx-host/tdx-host.c @@ -8,6 +8,7 @@ #include #include #include +#include =20 #include #include @@ -18,6 +19,29 @@ static const struct x86_cpu_id tdx_host_ids[] =3D { }; MODULE_DEVICE_TABLE(x86cpu, tdx_host_ids); =20 +static ssize_t version_show(struct device *dev, struct device_attribute *a= ttr, + char *buf) +{ + const struct tdx_sys_info *tdx_sysinfo =3D tdx_get_sysinfo(); + const struct tdx_sys_info_version *ver; + + if (!tdx_sysinfo) + return -ENXIO; + + ver =3D &tdx_sysinfo->version; + + return sysfs_emit(buf, TDX_VERSION_FMT "\n", ver->major_version, + ver->minor_version, + ver->update_version); +} +static DEVICE_ATTR_RO(version); + +static struct attribute *tdx_host_attrs[] =3D { + &dev_attr_version.attr, + NULL, +}; +ATTRIBUTE_GROUPS(tdx_host); + static struct faux_device *fdev; =20 static int __init tdx_host_init(void) @@ -25,7 +49,7 @@ static int __init tdx_host_init(void) if (!x86_match_cpu(tdx_host_ids) || !tdx_get_sysinfo()) return -ENODEV; =20 - fdev =3D faux_device_create(KBUILD_MODNAME, NULL, NULL); + fdev =3D faux_device_create_with_groups(KBUILD_MODNAME, NULL, NULL, tdx_h= ost_groups); if (!fdev) return -ENODEV; =20 --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 9517847ECCC; Wed, 13 May 2026 15:11:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685105; cv=none; b=El1Gi12467OLF7fQ2xeV4aVoIPOCA+UFnzpkozQq3qwZfoddOPHCwkSDVNh+f6O1X+7ano4wcLeJDz+lF7CkZv9Tc5DQgnO/e+3z0Mu+zYhiNEY6v0Gn15tAsgK+2J01EcwiGudFpFZGtCJ7jxkXPRe1Vq1Num5eIfxEBGQWyj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685105; c=relaxed/simple; bh=7Whkh85mgm7G+NVn7IKbBq2HfUjBXzTeUUdbwVvkMGc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZdiwLlBvfLGFCcoeNcZnjgNWZhdrno5+ujvIoH0+uqYI8QU9NJA2gHjEADynf4QXgKhykS1zMH2ofNk2HnVkGe8dM834WuLrqAKJbvaMMh2Aa7iE4rrMShUR/7gfgNyAj+x2xY+9WF1LWPEgeomxnj0F1w4OV/76UIlc1tW9OP8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WGZ7LWJo; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WGZ7LWJo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685103; x=1810221103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7Whkh85mgm7G+NVn7IKbBq2HfUjBXzTeUUdbwVvkMGc=; b=WGZ7LWJoUhPysIfJagqHNPJwexGINFKe34DFPVlh5Ei2S/9ZfmoHFgxC LaNE85oq1uNCZK1Ncxo7tHNQBwDAynh0aDfG51jmZ1jtJqaA5kI/zm+bs VFwp2gQ89vi2iqrKXvNjsuJVtLVstg4vvMUh+EYozwYq8Ddl6477b0MmX U0jp4fBb+kM0X5qrDLnLyYnzq+KotLoRRcHqE1fHxodkb1410Whc+VBa7 ZSf2N8KYJrjrVIf5RQvutiozZm/9Dq5PQbDnI//afseAsTNk7u1+6Lpei 5Z41XN8ymyTWaVMGsxSFfrhAPAPZwMvyRKR6+Hh7HAReV2nkAXWaLsQNY w==; X-CSE-ConnectionGUID: 8mtT0hapSEW0NG++nMiZcQ== X-CSE-MsgGUID: fTBiSbxnT+mtimmePse1UA== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921640" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921640" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:43 -0700 X-CSE-ConnectionGUID: NAtZAUrcQMaLefEkJZvRkw== X-CSE-MsgGUID: r9fafdh6QDatDdGP7weP8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716788" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:43 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt Subject: [PATCH v9 06/23] x86/virt/seamldr: Introduce a wrapper for P-SEAMLDR SEAMCALLs Date: Wed, 13 May 2026 08:09:49 -0700 Message-ID: <20260513151045.1420990-7-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" The TDX architecture uses the "SEAMCALL" instruction to communicate with SEAM mode software. Right now, the only SEAM mode software that the kernel communicates with is the TDX module. But, there is actually another component that runs in SEAM mode but it is separate from the TDX module: the persistent SEAM loader or "P-SEAMLDR". Right now, the only component that communicates with it is the BIOS which loads the TDX module itself at boot. But, to support updating the TDX module, the kernel now needs to be able to talk to it. P-SEAMLDR SEAMCALLs differ from TDX module SEAMCALLs in areas such as concurrency requirements. Add a P-SEAMLDR wrapper to handle these differences and prepare for implementing concrete functions. Use seamcall_prerr() (not '_ret') because current P-SEAMLDR calls do not use any output registers other than RAX. Note that unlike P-SEAMLDR, there is also a non-persistent SEAM loader ("NP-SEAMLDR"). This is an authenticated code module (ACM) that is not callable at runtime. Only BIOS launches it to load P-SEAMLDR at boot; the kernel does not need to interact with it for runtime update. Signed-off-by: Chao Gao Reviewed-by: Binbin Wu Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Xiaoyao Li Reviewed-by: Rick Edgecombe Link: https://cdrdv2.intel.com/v1/dl/getContent/733582 # [1] Reviewed-by: Dave Hansen --- arch/x86/virt/vmx/tdx/Makefile | 2 +- arch/x86/virt/vmx/tdx/seamldr.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 arch/x86/virt/vmx/tdx/seamldr.c diff --git a/arch/x86/virt/vmx/tdx/Makefile b/arch/x86/virt/vmx/tdx/Makefile index 90da47eb85ee..d1dbc5cc5697 100644 --- a/arch/x86/virt/vmx/tdx/Makefile +++ b/arch/x86/virt/vmx/tdx/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y +=3D seamcall.o tdx.o +obj-y +=3D seamcall.o seamldr.o tdx.o diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c new file mode 100644 index 000000000000..65616dd2f4d2 --- /dev/null +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * P-SEAMLDR support for TDX module management features like runtime updat= es + * + * Copyright (C) 2025 Intel Corporation + */ +#define pr_fmt(fmt) "seamldr: " fmt + +#include + +#include "seamcall_internal.h" + +/* + * Serialize P-SEAMLDR calls since the hardware only allows a single CPU to + * interact with P-SEAMLDR simultaneously. Use raw version as the calls can + * be made with interrupts disabled, where plain spinlocks are prohibited = in + * PREEMPT_RT kernels as they become sleeping locks. + */ +static DEFINE_RAW_SPINLOCK(seamldr_lock); + +static __maybe_unused int seamldr_call(u64 fn, struct tdx_module_args *arg= s) +{ + guard(raw_spinlock)(&seamldr_lock); + return seamcall_prerr(fn, args); +} --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 93B8948C8BD; Wed, 13 May 2026 15:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685106; cv=none; b=sVUL1EbrYTX9I2XwOJjiH7vncE+MbAiGBhgtJTHM1wJFFR89ol30EAB9JWn2ZaHlMeMqg87j4iUNSbrdNqGJMy9ShWHkFWArqawssZE9OTMvKuVhKQ9q+5s0lijk8P6ceOVfDLUnLFmCs3IXdXNiLiMP35yCNdn/weEvaD0wDZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685106; c=relaxed/simple; bh=GIUn92kANNcSgC0Px04MFU2BPxJtKnESUqye1cQy4xo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=J8XRBvTo8x+S0mvhwYPUux9Vg5YjfGWidwqr9gjrhElzcx+YdRWn8ysqD8IcuE9aJXtjwkIdg0vrRtZ0a+qHW7eeiOSE9I9zmlTxtrgsvH81EXpwdcLFiz0LEiexJGwsBQNZKFFa5TUO/OvmiOPEGoSzNLUc/pTobX7wLFt5y9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=mQPv1ava; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mQPv1ava" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685104; x=1810221104; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GIUn92kANNcSgC0Px04MFU2BPxJtKnESUqye1cQy4xo=; b=mQPv1avapgItLo6Vw5aIUoCLwEaI/LSTmNC7G1USJ56z0xvFGH55cLTh OOk0uqapJNMKXPutU6fzc4wv73tQ2+/xrg2l7wXPII0vpePbeFVK0V1kv IvpzPe+urT7yIb5pOgebwP4cD5E6DZkAz1vV+YhHikD56dBNN8ejYfXBz /8suYYaY9OJ/Zvscp4Tvc9DFthH2/iKsAyD7WAUCkLyeEDS6zdWgBe3+R 9ffbgN+J/pWcQ6fbGem5bCYvHH21j+6z01IbTh+RDoFJjK1siUvDUEJBP 3xNW8yHbgY+4E+mEgLCou7WIReZ/QPI+mDvEVb+/5jGzHNaMiu8XUq+LX A==; X-CSE-ConnectionGUID: Fz4+3F64TCO8kGFih1DtDg== X-CSE-MsgGUID: gZWXDl9aQqWqMnHhrFfLqA== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921652" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921652" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:44 -0700 X-CSE-ConnectionGUID: N+yZTu3SQUapJUi1AycqXQ== X-CSE-MsgGUID: qpfJFbDeRmW71z0NcqwlAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716794" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:44 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 07/23] x86/virt/seamldr: Add a helper to retrieve P-SEAMLDR information Date: Wed, 13 May 2026 08:09:50 -0700 Message-ID: <20260513151045.1420990-8-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable P-SEAMLDR reports its state via SEAMLDR.INFO, including its version and the number of remaining runtime updates. This information is useful for userspace. For example, the admin can use the P-SEAMLDR version to determine whether a candidate TDX module is compatible with the running loader, and can use the remaining update count to determine whether another runtime update is still possible. Add a helper to retrieve P-SEAMLDR information in preparation for exposing P-SEAMLDR version and other necessary information to userspace. Export the new kAPI for use by tdx-host.ko. Note that there are two distinct P-SEAMLDR APIs with similar names: SEAMLDR.INFO: Returns a SEAMLDR_INFO structure containing SEAMLDR information such as version and remaining updates. SEAMLDR.SEAMINFO: Returns a SEAMLDR_SEAMINFO structure containing SEAM and system information such as Convertible Memory Regions (CMRs) and number of CPUs and sockets. The former is used here. For details, see "Intel=C2=AE Trust Domain Extensions - SEAM Loader (SEAMLD= R) Interface Specification". Signed-off-by: Chao Gao Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Xiaoyao Li Reviewed-by: Rick Edgecombe Reviewed-by: Dave Hansen --- arch/x86/include/asm/seamldr.h | 36 +++++++++++++++++++++++++++++++++ arch/x86/virt/vmx/tdx/seamldr.c | 20 +++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 arch/x86/include/asm/seamldr.h diff --git a/arch/x86/include/asm/seamldr.h b/arch/x86/include/asm/seamldr.h new file mode 100644 index 000000000000..c67e5bc910a9 --- /dev/null +++ b/arch/x86/include/asm/seamldr.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_SEAMLDR_H +#define _ASM_X86_SEAMLDR_H + +#include + +/* + * This is called the "SEAMLDR_INFO" data structure and is defined + * in "SEAM Loader (SEAMLDR) Interface Specification". + * + * The SEAMLDR.INFO documentation requires this to be aligned to a + * 256-byte boundary. + */ +struct seamldr_info { + u32 version; + u32 attributes; + u32 vendor_id; + u32 build_date; + u16 build_num; + u16 minor_version; + u16 major_version; + u16 update_version; + u32 acm_x2apicid; + u32 num_remaining_updates; + u8 seam_info[128]; + u8 seam_ready; + u8 seam_debug; + u8 p_seam_ready; + u8 reserved[93]; +} __packed __aligned(256); + +static_assert(sizeof(struct seamldr_info) =3D=3D 256); + +int seamldr_get_info(struct seamldr_info *seamldr_info); + +#endif /* _ASM_X86_SEAMLDR_H */ diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c index 65616dd2f4d2..7269a239bc22 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -8,8 +8,13 @@ =20 #include =20 +#include + #include "seamcall_internal.h" =20 +/* P-SEAMLDR SEAMCALL leaf function */ +#define P_SEAMLDR_INFO 0x8000000000000000 + /* * Serialize P-SEAMLDR calls since the hardware only allows a single CPU to * interact with P-SEAMLDR simultaneously. Use raw version as the calls can @@ -18,8 +23,21 @@ */ static DEFINE_RAW_SPINLOCK(seamldr_lock); =20 -static __maybe_unused int seamldr_call(u64 fn, struct tdx_module_args *arg= s) +static int seamldr_call(u64 fn, struct tdx_module_args *args) { guard(raw_spinlock)(&seamldr_lock); return seamcall_prerr(fn, args); } + +int seamldr_get_info(struct seamldr_info *seamldr_info) +{ + struct tdx_module_args args =3D {}; + + /* + * Use slow_virt_to_phys() since @seamldr_info may be allocated on + * the stack. + */ + args.rcx =3D slow_virt_to_phys(seamldr_info); + return seamldr_call(P_SEAMLDR_INFO, &args); +} +EXPORT_SYMBOL_FOR_MODULES(seamldr_get_info, "tdx-host"); --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 EF236494A1A; Wed, 13 May 2026 15:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685108; cv=none; b=lZwsedQ9DqBIYCtvFi+03X17IZ7fgLNIYNp+EHc8sQqEAD2M/PQP3Bp6FaU2rH0goCqB3cA30pBAnTLslQFSbd38Gxd1DkB//KMz+vd4xnwh25woKIPoLFr1kjGrTb+OsZBZNsvTjau0eX2crS+NDlBKomflyEuYvnarAxQXt6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685108; c=relaxed/simple; bh=bo2F6tUg/6+cBa8oHxrRVyUqwJOhMRQVhjgPVmhm7JE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qPunrG2EknHbkXhajaPHONVA/CPtKRO9J2wgOgi9nagCc5/6OeBeTZOG3LfhOqcDzvVeM0xnED35vsvoNlxkPCh1eAjYAgEuYf+/tjkZ0HV39w0bq1BVP1ZGZEA0iiGm8WRg+4zo1X1AGybah/zUGI91IB3gdbpmlZmDPBZLf44= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BQeLbWnE; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BQeLbWnE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685106; x=1810221106; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bo2F6tUg/6+cBa8oHxrRVyUqwJOhMRQVhjgPVmhm7JE=; b=BQeLbWnEQz/G7K1dblphPC482C7KNOZFmeKi2pRX5669Qqx2D1PNtBje Sr4qbW1pgs1iz5gdhIZJWpfWYrFj9EY7GHMgiPiC/lbPSWoUQlBtsrcBC HAEiXlFlFIXpGsEGD39LxcdKiDzJFrfI8XEdeDCOk9il8t+HbeffBlBVD Tbw82Pa/CaMO1jNYqGcM98IjhbigPkdOxE7L67wB0113ScfLvNz1zP8Sz fUnEVAtK9zFVkL6A2Nl7Z1DOduwljnSVas7hs0qc88yY0hUa3W6LNbelW MqLh7tNj73H2Ci/JlviHKg/NCBZ30pIHuVkm+Ix0tsiCopYCXs/0BZZkR Q==; X-CSE-ConnectionGUID: DhLx8e/gTz+KDgIBP5R0HA== X-CSE-MsgGUID: 1UivO5w4RZKeQ9UhTlfYqg== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921665" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921665" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:45 -0700 X-CSE-ConnectionGUID: 70AqlN2nRWa0NZCt8AzjyQ== X-CSE-MsgGUID: x0HH+vMhQpOmYj+F8e1TKg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716803" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:45 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 08/23] coco/tdx-host: Expose P-SEAMLDR information via sysfs Date: Wed, 13 May 2026 08:09:51 -0700 Message-ID: <20260513151045.1420990-9-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable TDX module updates require userspace to select the appropriate module to load. Expose necessary information to facilitate this decision. Two values are needed: - P-SEAMLDR version: for compatibility checks between TDX module and P-SEAMLDR - num_remaining_updates: indicates how many updates can be performed Expose them as tdx-host device attributes. Make seamldr attributes visible only when the update feature is supported, as that's their sole purpose. Note that the underlying P-SEAMLDR attributes are available regardless of update support; this only restricts their visibility in Linux. Signed-off-by: Chao Gao Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Dave Hansen --- v8: - explain when the two attributes are available and how they relate to TDX module update support [Rick] - drop erratum stuff [Rick, Dave] - drop the separate directory for p-seamldr attributes [Dave] - s/SEAM loader/P-SEAMLDR - don't use DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE() as it doesn't work on an unnamed group. --- .../ABI/testing/sysfs-devices-faux-tdx-host | 22 +++++++ arch/x86/include/asm/tdx.h | 6 ++ drivers/virt/coco/tdx-host/tdx-host.c | 65 ++++++++++++++++++- 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-devices-faux-tdx-host b/Docume= ntation/ABI/testing/sysfs-devices-faux-tdx-host index 2cf682b65acf..65897fe6abc0 100644 --- a/Documentation/ABI/testing/sysfs-devices-faux-tdx-host +++ b/Documentation/ABI/testing/sysfs-devices-faux-tdx-host @@ -4,3 +4,25 @@ Description: (RO) Report the version of the loaded TDX mod= ule. The TDX module version is formatted as x.y.z, where "x" is the major version, "y" is the minor version and "z" is the update version. Versions are used for bug reporting, TDX module updates etc. + +What: /sys/devices/faux/tdx_host/seamldr_version +Contact: linux-coco@lists.linux.dev +Description: (RO) Report the version of the loaded P-SEAMLDR. The P-SEAMLDR + version is formatted as x.y.z, where "x" is the major version, + "y" is the minor version and "z" is the update version. Versions + are used for bug reporting and compatibility checks. + +What: /sys/devices/faux/tdx_host/num_remaining_updates +Contact: linux-coco@lists.linux.dev +Description: (RO) Report the number of remaining updates. TDX maintains a + log about each TDX module that has been loaded. This log has + a finite size, which limits the number of TDX module updates + that can be performed. + + After each successful update, the number reduces by one. Once it + reaches zero, further updates will fail until next reboot. The + number is always zero if the P-SEAMLDR doesn't support updates. + + See Intel=C2=AE Trust Domain Extensions - SEAM Loader (SEAMLDR) + Interface Specification, Chapter "SEAMLDR_INFO" and Chapter + "SEAMLDR.INSTALL" for more information. diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index b7f4396b5cc5..27376db7ddac 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -110,6 +110,12 @@ void tdx_init(void); const char *tdx_dump_mce_info(struct mce *m); const struct tdx_sys_info *tdx_get_sysinfo(void); =20 +static inline bool tdx_supports_runtime_update(const struct tdx_sys_info *= sysinfo) +{ + /* To be enabled when kernel is ready. */ + return false; +} + int tdx_guest_keyid_alloc(void); u32 tdx_get_nr_guest_keyids(void); void tdx_guest_keyid_free(unsigned int keyid); diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-= host/tdx-host.c index ef117a836b3a..079913dcc888 100644 --- a/drivers/virt/coco/tdx-host/tdx-host.c +++ b/drivers/virt/coco/tdx-host/tdx-host.c @@ -11,6 +11,7 @@ #include =20 #include +#include #include =20 static const struct x86_cpu_id tdx_host_ids[] =3D { @@ -40,7 +41,69 @@ static struct attribute *tdx_host_attrs[] =3D { &dev_attr_version.attr, NULL, }; -ATTRIBUTE_GROUPS(tdx_host); + +static const struct attribute_group tdx_host_group =3D { + .attrs =3D tdx_host_attrs, +}; + +static ssize_t seamldr_version_show(struct device *dev, struct device_attr= ibute *attr, + char *buf) +{ + struct seamldr_info info; + int ret; + + ret =3D seamldr_get_info(&info); + if (ret) + return ret; + + return sysfs_emit(buf, TDX_VERSION_FMT "\n", info.major_version, + info.minor_version, + info.update_version); +} + +static ssize_t num_remaining_updates_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct seamldr_info info; + int ret; + + ret =3D seamldr_get_info(&info); + if (ret) + return ret; + + return sysfs_emit(buf, "%u\n", info.num_remaining_updates); +} + +static DEVICE_ATTR_ADMIN_RO(seamldr_version); +static DEVICE_ATTR_ADMIN_RO(num_remaining_updates); + +static struct attribute *seamldr_attrs[] =3D { + &dev_attr_seamldr_version.attr, + &dev_attr_num_remaining_updates.attr, + NULL, +}; + +static umode_t seamldr_group_visible(struct kobject *kobj, struct attribut= e *attr, int idx) +{ + const struct tdx_sys_info *sysinfo =3D tdx_get_sysinfo(); + + if (!sysinfo) + return 0; + + return tdx_supports_runtime_update(sysinfo) ? attr->mode : 0; +} + +static const struct attribute_group seamldr_group =3D { + .attrs =3D seamldr_attrs, + .is_visible =3D seamldr_group_visible, +}; + +static const struct attribute_group *tdx_host_groups[] =3D { + &tdx_host_group, + &seamldr_group, + NULL, +}; =20 static struct faux_device *fdev; =20 --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 256814963D8; Wed, 13 May 2026 15:11:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685109; cv=none; b=flDTSHXc1bqIDKZCVa8rt84G67T7BXFollHM/D+SKh/tPfPgUCDXf5bFq0Npw45NARNgVt9bMdL2M4UhUcEoTBPSJsmKsUCngugz2xU6DcoZfksWyRdrMaFZLJyDdbGoJkaKjDJQT8MuOlUrxXLd7cWtvzPZJyv8ZYBMaOyPciE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685109; c=relaxed/simple; bh=7Vlp2XDtMoqkUwxL5/QuIk6s5vFKWwuAnnEzUQ72jSs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Jj5iavddH4r8+mgvjV/HuiG8RtsoIAQiikMG0hsQawW/lUkYGk6xigSF3583Lc9yb9i9M1Rcm7pbuc1tEXqRGhk/2plK13rkqPsU1XTKltBmEkcSe0oSaN7Lvt3Pql2LzbhGr032ECxbl109xfvRpKHrbJMbjRC9TqaMKPWzJxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iyhFMl9v; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iyhFMl9v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685107; x=1810221107; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7Vlp2XDtMoqkUwxL5/QuIk6s5vFKWwuAnnEzUQ72jSs=; b=iyhFMl9v8mddUuHqJie9JwFlxlMaUJKxd2+jj44sdCDtnc2WteL+V87Y jSdx3JTAmCavxA5U2HDCdO8d/ys1D3H9Pc8jmdYF7Lvj3enILdrurbtFt rpRvQ3dMH3VP8LvK9wvJFiVLU8isaArrYX72K4FsTG4r5+bim5Llsjh9P /xnclNdLbyT996Nfb551c8HFq5ufInJBuKJjaAYpHskQFTc+5xnosIxlW uLkpKBS51mT/PSxIiAgHqUhirY/cDq/6GA9/2pOgqmvXjasPes2lMX9Hs MyNxO3dNYqHudMLF6FpdO+HGSynnQzUNzM+k4fBTfyeTuEqED9+y/t4Ct g==; X-CSE-ConnectionGUID: oCpMOI+TRCG6UDE62A7iVQ== X-CSE-MsgGUID: FSltLez4Ty+GdMYZJmGnQA== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921675" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921675" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:46 -0700 X-CSE-ConnectionGUID: H/rXTBBVSv+PCPqLMTprBQ== X-CSE-MsgGUID: mzLpvv8oRvqZOvJKiwbgZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716811" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:46 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 09/23] coco/tdx-host: Don't expose P-SEAMLDR information on CPUs with erratum Date: Wed, 13 May 2026 08:09:52 -0700 Message-ID: <20260513151045.1420990-10-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Some TDX-capable CPUs have an erratum, as documented in Intel=C2=AE Trust Domain CPU Architectural Extensions (May 2021 edition) Chapter 2.3: SEAMRET from the P-SEAMLDR clears the current VMCS structure pointed to by the current-VMCS pointer. A VMM that invokes the P-SEAMLDR using SEAMCALL must reload the current-VMCS, if required, using the VMPTRLD instruction. Clearing the current VMCS behind KVM's back will break KVM. This erratum is not present when IA32_VMX_BASIC[60] is set. Add a CPU bug bit for this erratum and refuse to expose P-SEAMLDR information on affected CPUs, because even reading the P-SEAMLDR sysfs knobs would enter and exit P-SEAMLDR. Use a CPU bug bit to stay consistent with X86_BUG_TDX_PW_MCE. As a bonus, the bug bit is visible to userspace, which allows userspace to determine why these sysfs files are not exposed, and it can also be checked by other kernel components in the future if needed. =3D=3D Alternatives =3D=3D Two workarounds were considered but both were rejected: 1. Save/restore the current VMCS around P-SEAMLDR calls. This produces ugly assembly code [1] and doesn't play well with #MCE or #NMI if they need to use the current VMCS. 2. Move KVM's VMCS tracking logic to the TDX core code, which would break the boundary between KVM and the TDX core code [2]. Signed-off-by: Chao Gao Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Rick Edgecombe Link: https://lore.kernel.org/kvm/fedb3192-e68c-423c-93b2-a4dc2f964148@inte= l.com/ # [1] Link: https://lore.kernel.org/kvm/aYIXFmT-676oN6j0@google.com/ # [2] Reviewed-by: Dave Hansen --- This is split into a separate patch rather than folded into the previous on= e, because the erratum handling warrants a longer changelog and discussion of the alternatives. --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/vmx.h | 1 + arch/x86/virt/vmx/tdx/tdx.c | 11 +++++++++++ drivers/virt/coco/tdx-host/tdx-host.c | 8 ++++++++ 4 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 1d506e5d6f46..7b572bc24265 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -573,4 +573,5 @@ #define X86_BUG_ITS_NATIVE_ONLY X86_BUG( 1*32+ 8) /* "its_native_only" CP= U is affected by ITS, VMX is not affected */ #define X86_BUG_TSA X86_BUG( 1*32+ 9) /* "tsa" CPU is affected by Transi= ent Scheduler Attacks */ #define X86_BUG_VMSCAPE X86_BUG( 1*32+10) /* "vmscape" CPU is affected b= y VMSCAPE attacks from guests */ +#define X86_BUG_SEAMRET_INVD_VMCS X86_BUG( 1*32+11) /* "seamret_invd_vmcs"= SEAMRET from P-SEAMLDR clears the current VMCS */ #endif /* _ASM_X86_CPUFEATURES_H */ diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 37080382df54..49d8551d285d 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -147,6 +147,7 @@ struct vmcs { #define VMX_BASIC_INOUT BIT_ULL(54) #define VMX_BASIC_TRUE_CTLS BIT_ULL(55) #define VMX_BASIC_NO_HW_ERROR_CODE_CC BIT_ULL(56) +#define VMX_BASIC_NO_SEAMRET_INVD_VMCS BIT_ULL(60) =20 static inline u32 vmx_basic_vmcs_revision_id(u64 vmx_basic) { diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 837e9b36e1ea..1621695d7561 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -42,6 +42,7 @@ #include #include #include +#include =20 #include "seamcall_internal.h" #include "tdx.h" @@ -1443,6 +1444,8 @@ static struct notifier_block tdx_memory_nb =3D { =20 static void __init check_tdx_erratum(void) { + u64 basic_msr; + /* * These CPUs have an erratum. A partial write from non-TD * software (e.g. via MOVNTI variants or UC/WC mapping) to TDX @@ -1454,6 +1457,14 @@ static void __init check_tdx_erratum(void) case INTEL_EMERALDRAPIDS_X: setup_force_cpu_bug(X86_BUG_TDX_PW_MCE); } + + /* + * Some TDX-capable CPUs have an erratum where the current VMCS is + * cleared after calling into P-SEAMLDR. + */ + rdmsrq(MSR_IA32_VMX_BASIC, basic_msr); + if (!(basic_msr & VMX_BASIC_NO_SEAMRET_INVD_VMCS)) + setup_force_cpu_bug(X86_BUG_SEAMRET_INVD_VMCS); } =20 void __init tdx_init(void) diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-= host/tdx-host.c index 079913dcc888..a540d658757b 100644 --- a/drivers/virt/coco/tdx-host/tdx-host.c +++ b/drivers/virt/coco/tdx-host/tdx-host.c @@ -91,6 +91,14 @@ static umode_t seamldr_group_visible(struct kobject *kob= j, struct attribute *att if (!sysinfo) return 0; =20 + /* + * Calling P-SEAMLDR on CPUs with the seamret_invd_vmcs bug clears + * the current VMCS, which breaks KVM. Verify the erratum is not + * present before exposing P-SEAMLDR features. + */ + if (boot_cpu_has_bug(X86_BUG_SEAMRET_INVD_VMCS)) + return 0; + return tdx_supports_runtime_update(sysinfo) ? attr->mode : 0; } =20 --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 6165147D95C; Wed, 13 May 2026 15:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685111; cv=none; b=t7o44iBQF8USC+hbvWfwOeEtjefT95vErqA/tPs9VZQyLXQoZ1cqWagVD6ESKEv9CDOSxIZLddhzXJAXs278h3FAe/bjaLzFzzmOLW6AQAGdGX2RMGw0+U/So2IcJgtDgfP2SfQ2N72OKVlbhVLOAAbWzsH9Oc6ZwMIKNa7w7L4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685111; c=relaxed/simple; bh=beV9EOdjFCy/ljpfkkUCekXBiTBe08yzb9VkAqkB1v4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZK257wz/LwDGEV4AnBlusjG4eRGb44M5lCVOmAG4RjhRI8kHrSBzsSs/rnem179XJQxeU38FlEeBxtxR9oqjfWtKLcdF9EZCm+yhbSlbZPH6M9V60jPjQRFjYN1kwSv927GwVH1dAPrAe0SMeomh3TmGS1ETA1Ji1n1psGslNFM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=A5wMqOZV; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="A5wMqOZV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685108; x=1810221108; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=beV9EOdjFCy/ljpfkkUCekXBiTBe08yzb9VkAqkB1v4=; b=A5wMqOZVSd9ZSZbCczwQBs2v44dDARPM9FfpMxiSJBwn0agJg7ZPyzjF PpWhRbrTYBxT8ai5aiUzWe1w6RaTD7lbHNiitDlcG7hJBJZ+3eo8pYHqX YlD8Awb1AHjxrhcuFGcj/j0hLN/NxWRRb0iqnsugF7lTJuQu5fOrXKGU/ 4S5e3nga/XkKxtt4CkUr3TiZ/Hv4N/Vy1QzHK1IpQpbsY4j3Gmv2zBuj8 wzH4sfzd7HYETrP6akrrEkb1klrOhBEATlsaGmmdvN1R9BdZDzxDmhU8C ihbKilntlFAMJTtpqZIVHz7j+fAv/M+1B95vQpVZdYJf5X03gLn2quQ+F Q==; X-CSE-ConnectionGUID: zmxyV9iERMOf7c3N53D4xA== X-CSE-MsgGUID: LqLoxKNXTa6Pa/4eD2VZ5A== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921687" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921687" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:48 -0700 X-CSE-ConnectionGUID: AwjR5SDaRm28LCE+vHlnLA== X-CSE-MsgGUID: jHch+/iqTRyq9OpUqdtXwQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716818" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:47 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 10/23] coco/tdx-host: Implement firmware upload sysfs ABI for TDX module updates Date: Wed, 13 May 2026 08:09:53 -0700 Message-ID: <20260513151045.1420990-11-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" tl;dr: Select fw_upload for doing TDX module updates. The process of selecting among available update images is complicated and nuanced. Punt the selection policy out to userspace. Long Version: Linux kernel supports two primary firmware update mechanisms: - request_firmware() - firmware upload (or fw_upload) The former is used by microcode updates, SEV firmware updates, etc. The latter is used by CXL and FPGA firmware updates. One key difference between them is: request_firmware() loads a named file from the filesystem where the filename is kernel-controlled, while fw_upload accepts firmware data directly from userspace. Use fw_upload for TDX module updates as loading a named file isn't suitable for TDX (see below for more reasons). Specifically, register TDX faux device with fw_upload framework to expose sysfs interfaces and implement operations to process data blobs supplied by userspace. Why fw_upload instead of request_firmware()? =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The explicit file selection capabilities of fw_upload is preferred over the implicit file selection of request_firmware() for the following reasons: a. Intel distributes all versions of the TDX module, allowing admins to load any version rather than always defaulting to the latest. This flexibility is necessary because future extensions may require reverting to a previous version to clear fatal errors. b. Some module version series are platform-specific. For example, the 1.5.x series is for certain platform generations, while the 2.0.x series is intended for others. c. The update policy for TDX module updates is non-linear at times. The latest TDX module may not be compatible. For example, TDX module 1.5.x may be updated to 1.5.y but not to 1.5.y+1. This policy is documented separately in a file released along with each TDX module release. So, the default policy of "request_firmware()" of "always load latest", is not suitable for TDX. Userspace needs to deploy a more sophisticated policy check (e.g., latest may not be compatible), and there is potential operator choice to consider. Just have userspace pick rather than add kernel mechanism to change the default policy of request_firmware(). Signed-off-by: Chao Gao Reviewed-by: Tony Lindgren Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Link: https://lore.kernel.org/kvm/01fc8946-eb84-46fa-9458-f345dd3f6033@inte= l.com/ --- Dave also suggested making .poll_complete() optional in fw_upload_ops. That will be handled in a separate series. v9: - add a TL;DR to state the implementation choice up front [Dave] - s/can_expose_seamldr()/supports_runtime_update()/ [Dave] --- arch/x86/include/asm/seamldr.h | 1 + arch/x86/virt/vmx/tdx/seamldr.c | 15 +++++ drivers/virt/coco/tdx-host/Kconfig | 2 + drivers/virt/coco/tdx-host/tdx-host.c | 87 ++++++++++++++++++++++++++- 4 files changed, 102 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/seamldr.h b/arch/x86/include/asm/seamldr.h index c67e5bc910a9..ac6f80f7208b 100644 --- a/arch/x86/include/asm/seamldr.h +++ b/arch/x86/include/asm/seamldr.h @@ -32,5 +32,6 @@ struct seamldr_info { static_assert(sizeof(struct seamldr_info) =3D=3D 256); =20 int seamldr_get_info(struct seamldr_info *seamldr_info); +int seamldr_install_module(const u8 *data, u32 size); =20 #endif /* _ASM_X86_SEAMLDR_H */ diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c index 7269a239bc22..7b345000d7c3 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -6,6 +6,7 @@ */ #define pr_fmt(fmt) "seamldr: " fmt =20 +#include #include =20 #include @@ -41,3 +42,17 @@ int seamldr_get_info(struct seamldr_info *seamldr_info) return seamldr_call(P_SEAMLDR_INFO, &args); } EXPORT_SYMBOL_FOR_MODULES(seamldr_get_info, "tdx-host"); + +/** + * seamldr_install_module - Install a new TDX module. + * @data: Pointer to the TDX module image. + * @size: Size of the TDX module image. + * + * Returns 0 on success, negative error code on failure. + */ +int seamldr_install_module(const u8 *data, u32 size) +{ + /* TODO: Update TDX module here */ + return 0; +} +EXPORT_SYMBOL_FOR_MODULES(seamldr_install_module, "tdx-host"); diff --git a/drivers/virt/coco/tdx-host/Kconfig b/drivers/virt/coco/tdx-hos= t/Kconfig index d35d85ef91c0..ca600a39d97b 100644 --- a/drivers/virt/coco/tdx-host/Kconfig +++ b/drivers/virt/coco/tdx-host/Kconfig @@ -1,6 +1,8 @@ config TDX_HOST_SERVICES tristate "TDX Host Services Driver" depends on INTEL_TDX_HOST + select FW_LOADER + select FW_UPLOAD default m help Enable access to TDX host services like module update and diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-= host/tdx-host.c index a540d658757b..c4c099cf3de1 100644 --- a/drivers/virt/coco/tdx-host/tdx-host.c +++ b/drivers/virt/coco/tdx-host/tdx-host.c @@ -6,6 +6,7 @@ */ =20 #include +#include #include #include #include @@ -84,7 +85,7 @@ static struct attribute *seamldr_attrs[] =3D { NULL, }; =20 -static umode_t seamldr_group_visible(struct kobject *kobj, struct attribut= e *attr, int idx) +static bool supports_runtime_update(void) { const struct tdx_sys_info *sysinfo =3D tdx_get_sysinfo(); =20 @@ -99,7 +100,12 @@ static umode_t seamldr_group_visible(struct kobject *ko= bj, struct attribute *att if (boot_cpu_has_bug(X86_BUG_SEAMRET_INVD_VMCS)) return 0; =20 - return tdx_supports_runtime_update(sysinfo) ? attr->mode : 0; + return tdx_supports_runtime_update(sysinfo); +} + +static umode_t seamldr_group_visible(struct kobject *kobj, struct attribut= e *attr, int idx) +{ + return supports_runtime_update() ? attr->mode : 0; } =20 static const struct attribute_group seamldr_group =3D { @@ -113,6 +119,81 @@ static const struct attribute_group *tdx_host_groups[]= =3D { NULL, }; =20 +static enum fw_upload_err tdx_fw_prepare(struct fw_upload *fwl, + const u8 *data, u32 size) +{ + return FW_UPLOAD_ERR_NONE; +} + +static enum fw_upload_err tdx_fw_write(struct fw_upload *fwl, const u8 *da= ta, + u32 offset, u32 size, u32 *written) +{ + int ret; + + ret =3D seamldr_install_module(data, size); + switch (ret) { + case 0: + *written =3D size; + return FW_UPLOAD_ERR_NONE; + default: + return FW_UPLOAD_ERR_FW_INVALID; + } +} + +static enum fw_upload_err tdx_fw_poll_complete(struct fw_upload *fwl) +{ + /* + * The upload completed during tdx_fw_write(). + * Never poll for completion. + */ + return FW_UPLOAD_ERR_NONE; +} + + +static void tdx_fw_cancel(struct fw_upload *fwl) +{ + /* + * TDX module updates are not cancellable. + * Provide a no-op callback to satisfy fw_upload_ops. + */ +} + +static const struct fw_upload_ops tdx_fw_ops =3D { + .prepare =3D tdx_fw_prepare, + .write =3D tdx_fw_write, + .poll_complete =3D tdx_fw_poll_complete, + .cancel =3D tdx_fw_cancel, +}; + +static void seamldr_deinit(void *tdx_fwl) +{ + firmware_upload_unregister(tdx_fwl); +} + +static int seamldr_init(struct device *dev) +{ + struct fw_upload *tdx_fwl; + + if (!supports_runtime_update()) + return 0; + + tdx_fwl =3D firmware_upload_register(THIS_MODULE, dev, "tdx_module", + &tdx_fw_ops, NULL); + if (IS_ERR(tdx_fwl)) + return PTR_ERR(tdx_fwl); + + return devm_add_action_or_reset(dev, seamldr_deinit, tdx_fwl); +} + +static int tdx_host_probe(struct faux_device *fdev) +{ + return seamldr_init(&fdev->dev); +} + +static const struct faux_device_ops tdx_host_ops =3D { + .probe =3D tdx_host_probe, +}; + static struct faux_device *fdev; =20 static int __init tdx_host_init(void) @@ -120,7 +201,7 @@ static int __init tdx_host_init(void) if (!x86_match_cpu(tdx_host_ids) || !tdx_get_sysinfo()) return -ENODEV; =20 - fdev =3D faux_device_create_with_groups(KBUILD_MODNAME, NULL, NULL, tdx_h= ost_groups); + fdev =3D faux_device_create_with_groups(KBUILD_MODNAME, NULL, &tdx_host_o= ps, tdx_host_groups); if (!fdev) return -ENODEV; =20 --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 794E44B8DFE; Wed, 13 May 2026 15:11:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685111; cv=none; b=KtuUuUN092fraMWw9rklImYpjNtRj5s/7Pm2+L6jd3lpOEf+wlw1MGHFMY5via2fLcD94XbTTUnjZdNPWT5NLkTW7QsdIrxZy3hyYtfOblTaFEQM64AxSp3S5Arr6qVt84Xa2zR+Ybab774mmOf2BA3nbUhjMtVg1ls0P/tdhlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685111; c=relaxed/simple; bh=LURwXxL3ZES66KefMxpDI/LyPCZOYuRnZoQInq//gkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pwX5mTWcTRCmCcF23uV2ik6ZbJw4ihX6z75nPWPmLVAcy/gfKUorQExvCqUjXLmsxEbcPgBih/XyOUJm8ohAoutvqeuCAU4eQ5c6ANmfuzjd8qv/6viGpsgYAVnCma1iuGPCWAIBR7K5XfjVs2uwnTfemK7/Nq1C/qs38hHBquA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dV6egZ3Q; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dV6egZ3Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685109; x=1810221109; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LURwXxL3ZES66KefMxpDI/LyPCZOYuRnZoQInq//gkk=; b=dV6egZ3QXZbYGLr/tKum2Os69Vf7tBXjuJ6inHSSuJmOe3M7R97dGOb4 GT7xfKAz4Mn7q7TQ7WfkN8vpqGf9I85ZnIMwCgTYFsdScUgmHrBfR4lFU qk9HJq4MuUZS+Upd47vH9bW8rCR/y5uL+jH5ikdFi5dXANzUQDTv5nl3h m0wnw4m3MwnbOR3GbKZZo+f3cY2WEEZakDTmw9mpf2tNNTkgyw016uvBK PlTjnFUGflQYpg7sYCm3MszPSd9O/uwuQER5wU9Q/cL47Tpz0XxMoUQGY vAQKvs5HGPS0o25+IP/Ff3W2OiSWT7JQ/UTEftqHnhea0P/qI7kwDFMZ6 Q==; X-CSE-ConnectionGUID: oGEPKBQ+S26YnliykcO25Q== X-CSE-MsgGUID: oQM+2mM/SSqMvlyT8rCTug== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921698" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921698" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:49 -0700 X-CSE-ConnectionGUID: YXnmXjqRSMiD80Dv8jQ8Rw== X-CSE-MsgGUID: oyJ1H6rFQYmsHbJDr8dLbA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716827" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:48 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 11/23] x86/virt/seamldr: Allocate and populate a module update request Date: Wed, 13 May 2026 08:09:54 -0700 Message-ID: <20260513151045.1420990-12-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" There are two important ABIs here: 'struct tdx_image' - The on-disk and in-memory format for a TDX module update image. 'struct seamldr_params' - The in-memory ABI passed to the TDX module loader. Points to a single 'struct tdx_image' Userspace supplies the update image in struct tdx_image format. The image consists of a header followed by a sigstruct and the module binary. P-SEAMLDR, however, consumes struct seamldr_params rather than the image directly. Parse the struct tdx_image provided by userspace and populate a matching struct seamldr_params. Validate the struct tdx_image header before using it, because the header is consumed solely by the kernel to locate the sigstruct and module within the image. Do not validate the payload itself. The sigstruct and module pages are passed through to P-SEAMLDR, which validates them as part of the update flow. Signed-off-by: Chao Gao --- sigstruct_pages_pa_list currently has only one entry, but it will grow to four pages in the future. Keep it as an array for symmetry with module_pages_pa_list and for extensibility. v9: - define a new format, basically don't use offset_of_module but use sigstruct/module_nr_pages if the offset should be paged-aligned. this saves alignment checks and bound checks. - add a tdx_image_header struct to avoid using sizeof() for a struct with variable array. - rewrite the changelog to call out that this patch is to convert an ABI f= rom what userspace provides to an ABI the P-SEAMLDR consums. - minimize casts and shifts and weird math --- arch/x86/virt/vmx/tdx/seamldr.c | 126 +++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c index 7b345000d7c3..929203ec96f2 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -7,6 +7,7 @@ #define pr_fmt(fmt) "seamldr: " fmt =20 #include +#include #include =20 #include @@ -16,6 +17,33 @@ /* P-SEAMLDR SEAMCALL leaf function */ #define P_SEAMLDR_INFO 0x8000000000000000 =20 +#define SEAMLDR_MAX_NR_MODULE_PAGES 496 +#define SEAMLDR_MAX_NR_SIG_PAGES 1 + +/* + * The seamldr_params "scenario" field specifies the operation mode: + * 0: Install TDX module from scratch (not used by kernel) + * 1: Update existing TDX module to a compatible version + */ +#define SEAMLDR_SCENARIO_UPDATE 1 + +/* + * This is called the "SEAMLDR_PARAMS" data structure and is defined + * in "SEAM Loader (SEAMLDR) Interface Specification". + * + * It describes the TDX module that will be installed. + */ +struct seamldr_params { + u32 version; + u32 scenario; + u64 sigstruct_pages_pa_list[SEAMLDR_MAX_NR_SIG_PAGES]; + u8 reserved[104]; + u64 module_nr_pages; + u64 module_pages_pa_list[SEAMLDR_MAX_NR_MODULE_PAGES]; +} __packed; + +static_assert(sizeof(struct seamldr_params) =3D=3D 4096); + /* * Serialize P-SEAMLDR calls since the hardware only allows a single CPU to * interact with P-SEAMLDR simultaneously. Use raw version as the calls can @@ -43,6 +71,89 @@ int seamldr_get_info(struct seamldr_info *seamldr_info) } EXPORT_SYMBOL_FOR_MODULES(seamldr_get_info, "tdx-host"); =20 +#define TDX_IMAGE_VERSION_2 0x200 + +struct tdx_image_header { + u16 version; // This ABI is always 0x200 + u16 checksum; + u8 signature[8]; + u32 sigstruct_nr_pages; + u32 module_nr_pages; + u8 reserved[4076]; +} __packed; + +#define HEADER_SIZE sizeof(struct tdx_image_header) +static_assert(HEADER_SIZE =3D=3D 4096); + +/* Intel TDX module update ABI structure. aka. "TDX module blob". */ +struct tdx_image { + struct tdx_image_header header; + u8 payload[]; // Contains sigstruct pages followed by module pages +}; + +static void populate_pa_list(u64 *pa_list, u32 max_entries, const u8 *star= t, u32 nr_pages) +{ + int i; + + nr_pages =3D MIN(nr_pages, max_entries); + for (i =3D 0; i < nr_pages; i++) { + pa_list[i] =3D vmalloc_to_pfn(start) << PAGE_SHIFT; + start +=3D PAGE_SIZE; + } +} + +static void populate_seamldr_params(struct seamldr_params *params, + const u8 *sig, u32 sig_nr_pages, + const u8 *mod, u32 mod_nr_pages) +{ + params->version =3D 0; + params->scenario =3D SEAMLDR_SCENARIO_UPDATE; + params->module_nr_pages =3D mod_nr_pages; + + populate_pa_list(params->sigstruct_pages_pa_list, SEAMLDR_MAX_NR_SIG_PAGE= S, + sig, sig_nr_pages); + populate_pa_list(params->module_pages_pa_list, SEAMLDR_MAX_NR_MODULE_PAGE= S, + mod, mod_nr_pages); +} + +static int init_seamldr_params(struct seamldr_params *params, const u8 *da= ta, u32 size) +{ + const struct tdx_image *image =3D (const void *)data; + const struct tdx_image_header *header =3D &image->header; + + u32 sigstruct_len =3D header->sigstruct_nr_pages * PAGE_SIZE; + u32 module_len =3D header->module_nr_pages * PAGE_SIZE; + + u8 *header_start =3D (u8 *)header; + u8 *header_end =3D header_start + HEADER_SIZE; + + u8 *sigstruct_start =3D header_end; + u8 *sigstruct_end =3D sigstruct_start + sigstruct_len; + + u8 *module_start =3D sigstruct_end; + + /* Check the calculated payload size against the data size. */ + if (HEADER_SIZE + sigstruct_len + module_len !=3D size) + return -EINVAL; + + /* + * Don't care about user passing the wrong file, but protect + * kernel ABI by preventing accepting garbage. + */ + if (header->version !=3D TDX_IMAGE_VERSION_2) + return -EINVAL; + + if (memcmp(header->signature, "TDX-BLOB", sizeof(header->signature))) + return -EINVAL; + + if (memchr_inv(header->reserved, 0, sizeof(header->reserved))) + return -EINVAL; + + populate_seamldr_params(params, sigstruct_start, header->sigstruct_nr_pag= es, + module_start, header->module_nr_pages); + return 0; +} + /** * seamldr_install_module - Install a new TDX module. * @data: Pointer to the TDX module image. @@ -52,7 +163,20 @@ EXPORT_SYMBOL_FOR_MODULES(seamldr_get_info, "tdx-host"); */ int seamldr_install_module(const u8 *data, u32 size) { + struct seamldr_params *params; + int ret; + + params =3D kzalloc_obj(*params); + if (!params) + return -ENOMEM; + + ret =3D init_seamldr_params(params, data, size); + if (ret) + goto out; + /* TODO: Update TDX module here */ - return 0; +out: + kfree(params); + return ret; } EXPORT_SYMBOL_FOR_MODULES(seamldr_install_module, "tdx-host"); --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 398E34BC016; Wed, 13 May 2026 15:11:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685111; cv=none; b=hQKpkaqTnkdcTqlUaZ3pNXHB97zuh0M5TbbMUWFViPJWHFUNqZUy9O0kjQ/sIqJP1oDbaS/612TJkw8Qn1nSytC1F1lqNb1RD3ctYnuDFN2Ppa0JTs43MOhraeqOGaKB8wWSaZYLASk1f7o0ojRBc2Oa7T+1vk+3o8h6Dx0yg5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685111; c=relaxed/simple; bh=BwCRyzJCVNr5aEzvQLZc6k5Qz5gHLeOaIsH1XuiGS9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dwz6IhcKq3aiw0OOrydj/qMzfMCkEh17A6Q+hW0JflOFNSBiBqAGK6Rc3kBXbKUD1bXAZjTJWETg0Y1tJ/wQbM6qkYNv2bpgsBZr6prOHyeA9lT78KUgzYoG+EpI6o89AdC6UBeR0LujYabwJM8zMivDK2kOhMeV8V2vcAY0LPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ViJqStGt; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ViJqStGt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685110; x=1810221110; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BwCRyzJCVNr5aEzvQLZc6k5Qz5gHLeOaIsH1XuiGS9k=; b=ViJqStGtjnykorv98q6DDovQ3L9s4dTOrTXtYVq7RwqVtNquULxR8/jN +XBQt2cGMR0X1N7KM6S+NUtZJ58wzpfPNiKNFlV4Z2NhLRuBzhBT/cIA9 vAp44wKUZ/y/q+6UZV1sfSE0HItbxnVaOSD8+/xZ26vlIghW1tIn40447 B+hU1tuavUvThESb2m6Fkr7oI84O7rO1pRZ5jwX5bLP1/DfT52qfNrOAE 7ufWwZXu45IEAB8gHlTgUpeclh6utIc8uqoWX6k4g1snU1euEKB7Bn6w2 2iELNMzjKZ9apNrbvWbyx1fQzXEVKR4NRmm+8j09GYejQjAyNf8FzUmoh g==; X-CSE-ConnectionGUID: IB2E3PwtSHaC0sxzMi5OmQ== X-CSE-MsgGUID: LUgoaUICSri9VMWLTe8KPg== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921710" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921710" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:49 -0700 X-CSE-ConnectionGUID: GVVPtxrHS/e+2vG3S0rFAQ== X-CSE-MsgGUID: ApfAVFcQRcaUmsJa4+i8NQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716836" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:49 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 12/23] x86/virt/seamldr: Introduce skeleton for TDX module updates Date: Wed, 13 May 2026 08:09:55 -0700 Message-ID: <20260513151045.1420990-13-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable TDX module updates require careful synchronization with other TDX operations. The requirements are (#1/#2 reflect current behavior that must be preserved): 1. SEAMCALLs need to be callable from both process and IRQ contexts. 2. SEAMCALLs need to be able to run concurrently across CPUs 3. During updates, only update-related SEAMCALLs are permitted; all other SEAMCALLs shouldn't be called. 4. During updates, all online CPUs must participate in the update work. No single lock primitive satisfies all requirements. For instance, rwlock_t handles #1/#2 but fails #4: CPUs spinning with IRQs disabled cannot be directed to perform update work. Use stop_machine() as it is the only well-understood mechanism that can meet all requirements. And TDX module updates consist of several steps (See Intel=C2=AE Trust Doma= in Extensions (Intel=C2=AE TDX) Module Base Architecture Specification, Chapter "TD-Preserving TDX module Update"). Ordering requirements between steps mandate lockstep synchronization across all CPUs. multi_cpu_stop() provides a good example of executing a multi-step task in lockstep across CPUs, but it does not synchronize the individual steps inside the callback itself. Implement a similar state machine as the skeleton for TDX module updates. Each state represents one step in the update flow, and the state advances only after all CPUs acknowledge completion of the current step. This acknowledgment mechanism provides the required lockstep execution. The update flow is intentionally simpler than multi_cpu_stop() in two ways: a) use a spinlock to protect the control data instead of atomic_t and explicit memory barriers. b) omit touch_nmi_watchdog() and rcu_momentary_eqs(), which exist there for debugging and are not strictly needed for this update flow Potential alternative to stop_machine() =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D An alternative approach is to lock all KVM entry points and kick all vCPUs. Here, KVM entry points refer to KVM VM/vCPU ioctl entry points, implemented in KVM common code (virt/kvm). Adding a locking mechanism there would affect all architectures KVM supports. And to lock only TDX vCPUs, new logic would be needed to identify TDX vCPUs, which the KVM common code currently lacks. This would add significant complexity and maintenance overhead to KVM for this TDX-specific use case, so don't take this approach. Signed-off-by: Chao Gao Reviewed-by: Xu Yilun Reviewed-by: Tony Lindgren Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Rick Edgecombe --- v9: - Extract control-data initialization into a separate helper. [Dave] - Drop touch_nmi_watchdog() and rcu_momentary_eqs(), as they are not needed here. - Rename thread_ack to num_ack to make it clear that it counts the number of acknowledgments. - Rename set_target_state() to __set_target_state() to mark it as an internal helper. Add a comment noting that __set_target_state() does not take the lock, unlike ack_state(). - Update the changelog to explain why a spinlock is used instead of atomic_t plus memory barriers to protect the control data. --- arch/x86/virt/vmx/tdx/seamldr.c | 87 ++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c index 929203ec96f2..7befe4a08f33 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -7,8 +7,10 @@ #define pr_fmt(fmt) "seamldr: " fmt =20 #include +#include #include #include +#include =20 #include =20 @@ -154,6 +156,84 @@ static int init_seamldr_params(struct seamldr_params *= params, const u8 *data, u3 return 0; } =20 +/* + * During a TDX module update, all CPUs start from MODULE_UPDATE_START and + * progress to MODULE_UPDATE_DONE. Each state is associated with certain + * work. For some states, just one CPU needs to perform the work, while + * other CPUs just wait during those states. + */ +enum module_update_state { + MODULE_UPDATE_START, + MODULE_UPDATE_DONE, +}; + +static struct update_ctrl { + enum module_update_state state; + int num_ack; + /* + * Protect update_ctrl. Raw spinlock as it will be acquired from + * interrupt-disabled contexts. + */ + raw_spinlock_t lock; +} update_ctrl; + +/* Called with ctrl->lock held or during initialization. */ +static void __set_target_state(struct update_ctrl *ctrl, + enum module_update_state newstate) +{ + /* Reset ack counter. */ + ctrl->num_ack =3D 0; + ctrl->state =3D newstate; +} + +/* Last one to ack a state moves to the next state. */ +static void ack_state(struct update_ctrl *ctrl) +{ + raw_spin_lock(&ctrl->lock); + + ctrl->num_ack++; + if (ctrl->num_ack =3D=3D num_online_cpus()) + __set_target_state(ctrl, ctrl->state + 1); + + raw_spin_unlock(&ctrl->lock); +} + +static void init_state(struct update_ctrl *ctrl) +{ + raw_spin_lock_init(&ctrl->lock); + __set_target_state(ctrl, MODULE_UPDATE_START + 1); +} + +/* + * See multi_cpu_stop() from where this multi-cpu state-machine was + * adopted. + */ +static int do_seamldr_install_module(void *seamldr_params) +{ + enum module_update_state newstate, curstate =3D MODULE_UPDATE_START; + int ret =3D 0; + + do { + newstate =3D READ_ONCE(update_ctrl.state); + + if (curstate =3D=3D newstate) { + cpu_relax(); + continue; + } + + curstate =3D newstate; + switch (curstate) { + /* TODO: add the update steps. */ + default: + break; + } + + ack_state(&update_ctrl); + } while (curstate !=3D MODULE_UPDATE_DONE); + + return ret; +} + /** * seamldr_install_module - Install a new TDX module. * @data: Pointer to the TDX module image. @@ -174,7 +254,12 @@ int seamldr_install_module(const u8 *data, u32 size) if (ret) goto out; =20 - /* TODO: Update TDX module here */ + /* Ensure a stable set of online CPUs for the update process. */ + cpus_read_lock(); + init_state(&update_ctrl); + ret =3D stop_machine_cpuslocked(do_seamldr_install_module, params, cpu_on= line_mask); + cpus_read_unlock(); + out: kfree(params); return ret; --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 BD03347F2DD; Wed, 13 May 2026 15:11:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685116; cv=none; b=dVpO6cPU6CgI1QbFEFwR9yYrunYyadk/7QVI1E4tkf1gyOxmvmVhSGqiRhUnqwDpaUXFcyW2BmRhD88zaao0SH3LkiiO6zaMWwrYF6WKwKTgO0hr3pDI4rVP9bwzxcX28jXutaraKlNL77B4uHOTMQf1HNPoScEJYbIbbXYXxr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685116; c=relaxed/simple; bh=8PbicTqEbhDrnSTKwgpCFEyUH9Bk/LHwnp78ypWxyUQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QRj+cwTtO/Qf9nTaq2f5+T6RAJAN2DEYa3rZlIgv0eIhM8JaBeL3ThrBR4fGnGwkBodMYN4mRX0khLLYeOxOY3bLwRlNOMyp8ggfk8TXHwiU0zvcG7eMLWHODrbyEuF6hRtKacQDKJcGnw0XSL1ZrpWg+YHwr3Ym3//aRTHYQeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BLYr5h9J; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BLYr5h9J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685114; x=1810221114; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8PbicTqEbhDrnSTKwgpCFEyUH9Bk/LHwnp78ypWxyUQ=; b=BLYr5h9JHSn741ohgyqhDBBwiSEWW9EoMJOayS4qs0cv/OS7pXC5aORD R9kwyHqDImP4tvc/mIqxFTxesMgozA56AaBpmcTHtvsVfgovTBn/LInIL iCOYDaNeR5SJeMx6OP2w028nJhS4tpwU3Vua8ENxthvZykGMxRvyyJMEe a65v6kmjbFsDw8dS5GPiVvbzUuWdTl7/SoDqqyoffwL2Y3BogDR+ZPZlv D2aM2l3IWElL2f/KyM3a/nXUEal/x8geP8n2QwGBeT4kSj5/o45zHxDMX ar42wgxUPNeBZ+1fC4SOUfj3BGMxZIiWNpNneTtjvcl6mDuoOS58vC0Wn w==; X-CSE-ConnectionGUID: 3ooqeFVpRxOStzItMWPB6A== X-CSE-MsgGUID: qOmGcZ6fT6+a8a+emux79Q== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921726" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921726" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:54 -0700 X-CSE-ConnectionGUID: p8rbDWQsSbWpWtU5aEuTAQ== X-CSE-MsgGUID: 9/ap5W54QNaxG9k4rUE31w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716848" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:50 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 13/23] x86/virt/seamldr: Abort updates after a failed step Date: Wed, 13 May 2026 08:09:56 -0700 Message-ID: <20260513151045.1420990-14-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" A TDX module update is a multi-step process, and any step can fail. The current update flow continues to later steps after an error. Continuing after a failure can leave the TDX module in an unrecoverable state. One failure case must remain recoverable: update contention with an ongoing TD build. The agreed kernel behavior for this case [1] is to fail the update with -EBUSY so userspace can retry later. Abort the update on any failure. This also makes the TD-build contention case recoverable, because that failure occurs before any TDX module state is changed. Apply the same rule to all errors instead of special-casing -EBUSY. Track per-step failures, stop the update loop once a failure is observed, and do not advance the state machine to the next step. Signed-off-by: Chao Gao Reviewed-by: Xu Yilun Reviewed-by: Tony Lindgren Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Link: https://lore.kernel.org/linux-coco/aQFmOZCdw64z14cJ@google.com/ # [1] --- v9: - Avoid nested if/else by deferring failure accounting to ack_state(). - Reduce indentation of the main flow. - Convert the failed flag into a counter. This avoids a conditional update of the flag; the counter can simply accumulate failures. --- arch/x86/virt/vmx/tdx/seamldr.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c index 7befe4a08f33..48fe71319fea 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -170,6 +170,7 @@ enum module_update_state { static struct update_ctrl { enum module_update_state state; int num_ack; + int num_failed; /* * Protect update_ctrl. Raw spinlock as it will be acquired from * interrupt-disabled contexts. @@ -187,12 +188,13 @@ static void __set_target_state(struct update_ctrl *ct= rl, } =20 /* Last one to ack a state moves to the next state. */ -static void ack_state(struct update_ctrl *ctrl) +static void ack_state(struct update_ctrl *ctrl, int result) { raw_spin_lock(&ctrl->lock); =20 + ctrl->num_failed +=3D !!result; ctrl->num_ack++; - if (ctrl->num_ack =3D=3D num_online_cpus()) + if (ctrl->num_ack =3D=3D num_online_cpus() && !ctrl->num_failed) __set_target_state(ctrl, ctrl->state + 1); =20 raw_spin_unlock(&ctrl->lock); @@ -202,6 +204,7 @@ static void init_state(struct update_ctrl *ctrl) { raw_spin_lock_init(&ctrl->lock); __set_target_state(ctrl, MODULE_UPDATE_START + 1); + ctrl->num_failed =3D 0; } =20 /* @@ -228,8 +231,8 @@ static int do_seamldr_install_module(void *seamldr_para= ms) break; } =20 - ack_state(&update_ctrl); - } while (curstate !=3D MODULE_UPDATE_DONE); + ack_state(&update_ctrl, ret); + } while (curstate !=3D MODULE_UPDATE_DONE && !READ_ONCE(update_ctrl.num_f= ailed)); =20 return ret; } --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 26A544CA268; Wed, 13 May 2026 15:11:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685117; cv=none; b=iWJVekEhtaBwSQbbfgbyMXkbfFof8DJWYlfuTUUA9ZfZL6B1Mrsi/jAFTV2KNi8BeY/3+mJJwtnJzxhdrusVN3ylbQvdZovRE18CctynflBkuqRU+g1KdDUHcwU7hpOY01JtCL81H5KSf2pqQr7hmVz6JudNq0+RXiDWF3psDtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685117; c=relaxed/simple; bh=lLatdVSnREhH3iHDFvWWOAW3ho54b9s9bAK+m2qph2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O55yrYbSylTVJ+uVmk+gR2ZFHkyjtU+hD9bG9FtOM0gsDxOExWTvvG1NILfjK99aZMv7pxgf/ff8IDbjGmHcKKzkehqVa+GePedGD66cHz5psBOCo/Y3xcxIPiN+wholDJn5V6UDrRWs8EaOT8UY67DZr8Xu7oYqVqcU8hII3gU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=S3HynLzY; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="S3HynLzY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685115; x=1810221115; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lLatdVSnREhH3iHDFvWWOAW3ho54b9s9bAK+m2qph2w=; b=S3HynLzY/wcSYMgHSgln5KuJZdfDlpMhFs6xd074YfhyawzMIywbKd1T YB/hKHk1e2L4FK5q/hrHV9b8m9DW85ciVcCgdYz0tZzH2ZgYZ44uwlpY/ S411UZWttlHeK3B48mH9SKtN1Kbg8CGacIKuQKfU5Hvu/I5i0lbDNoFal VYKs5NvxJRiLJP+WjkdbzENPX6wm9wzW+tNIcCKrk7YpvRdlilKxA7QWY UPI9Up4Pvm8u72k2vhgsNdqHHWUkJaJtmTnQTJoy2MO6aG/xgbh1DXp6O xF+C4ano8NWkk2qz4YOnpkoJPgiXvilEIuY7FR33sFg1gW5hottrSoCSL g==; X-CSE-ConnectionGUID: 2i+6gDYjQh6vk4jUs2cqRA== X-CSE-MsgGUID: SGT3vrx+TP6tuWejChIwJw== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921736" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921736" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:54 -0700 X-CSE-ConnectionGUID: +83ngug3TeCPTu6YeXwMvw== X-CSE-MsgGUID: Pvpo8iUhRe+cSreAneayrg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716881" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:53 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 14/23] x86/virt/seamldr: Shut down the current TDX module Date: Wed, 13 May 2026 08:09:57 -0700 Message-ID: <20260513151045.1420990-15-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The first step of TDX module updates is shutting down the current TDX module. This step also packs state information that needs to be preserved across updates as handoff data, which will be consumed by the updated module. The handoff data is stored internally in the SEAM range and is hidden from the kernel. To ensure a successful update, the new module must be able to consume the handoff data generated by the old module. Since handoff data layout may change between modules, the handoff data is versioned. Each module has a native handoff version and provides backward support for several older versions. The complete handoff versioning protocol is complex as it supports both module upgrades and downgrades. See details in Intel=C2=AE Trust Domain Extensions (Intel=C2=AE TDX) Module Base Architecture Specification, Chapter "Handoff Versioning". Ideally, the kernel needs to retrieve the handoff versions supported by the current module and the new module and select a version supported by both. But, since this implementation chooses to only support module upgrades, simply request the current module to generate handoff data using its highest supported version, expecting that the new module will likely support it. Retrieve the module's handoff version from TDX global metadata and add an update step to shut down the module. Module shutdown has global effect, so it only needs to run on one CPU. Note that the handoff information isn't cached in tdx_sysinfo. It is used only for module shutdown, and is present only when the TDX module supports updates. Caching it in get_tdx_sys_info() would require extra update-support guards and refreshing the cached value across module updates. Signed-off-by: Chao Gao Reviewed-by: Tony Lindgren Reviewed-by: Xu Yilun Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) --- v9: - Use CPU0 as the primary CPU --- arch/x86/include/asm/tdx_global_metadata.h | 4 ++++ arch/x86/virt/vmx/tdx/seamldr.c | 15 ++++++++++++++- arch/x86/virt/vmx/tdx/tdx.c | 19 ++++++++++++++++++- arch/x86/virt/vmx/tdx/tdx.h | 3 +++ arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 13 +++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/tdx_global_metadata.h b/arch/x86/include/= asm/tdx_global_metadata.h index 40689c8dc67e..41150d546589 100644 --- a/arch/x86/include/asm/tdx_global_metadata.h +++ b/arch/x86/include/asm/tdx_global_metadata.h @@ -40,6 +40,10 @@ struct tdx_sys_info_td_conf { u64 cpuid_config_values[128][2]; }; =20 +struct tdx_sys_info_handoff { + u16 module_hv; +}; + struct tdx_sys_info { struct tdx_sys_info_version version; struct tdx_sys_info_features features; diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c index 48fe71319fea..6114cab46196 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -15,6 +15,7 @@ #include =20 #include "seamcall_internal.h" +#include "tdx.h" =20 /* P-SEAMLDR SEAMCALL leaf function */ #define P_SEAMLDR_INFO 0x8000000000000000 @@ -164,6 +165,7 @@ static int init_seamldr_params(struct seamldr_params *p= arams, const u8 *data, u3 */ enum module_update_state { MODULE_UPDATE_START, + MODULE_UPDATE_SHUTDOWN, MODULE_UPDATE_DONE, }; =20 @@ -214,8 +216,16 @@ static void init_state(struct update_ctrl *ctrl) static int do_seamldr_install_module(void *seamldr_params) { enum module_update_state newstate, curstate =3D MODULE_UPDATE_START; + int cpu =3D smp_processor_id(); + bool primary; int ret =3D 0; =20 + /* + * Use CPU 0 to execute update steps that must run exactly once. + * Note CPU 0 is always online. + */ + primary =3D cpu =3D=3D 0; + do { newstate =3D READ_ONCE(update_ctrl.state); =20 @@ -226,7 +236,10 @@ static int do_seamldr_install_module(void *seamldr_par= ams) =20 curstate =3D newstate; switch (curstate) { - /* TODO: add the update steps. */ + case MODULE_UPDATE_SHUTDOWN: + if (primary) + ret =3D tdx_module_shutdown(); + break; default: break; } diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 1621695d7561..da3c1e857b26 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -321,7 +321,7 @@ static __init int build_tdx_memlist(struct list_head *t= mb_list) return ret; } =20 -static __init int read_sys_metadata_field(u64 field_id, u64 *data) +static int read_sys_metadata_field(u64 field_id, u64 *data) { struct tdx_module_args args =3D {}; int ret; @@ -1267,6 +1267,23 @@ static __init int tdx_enable(void) } subsys_initcall(tdx_enable); =20 +int tdx_module_shutdown(void) +{ + struct tdx_sys_info_handoff handoff =3D {}; + struct tdx_module_args args =3D {}; + int ret; + + ret =3D get_tdx_sys_info_handoff(&handoff); + WARN_ON_ONCE(ret); + + /* + * Use the module's handoff version as it is the highest the + * module can produce and most likely supported by newer modules. + */ + args.rcx =3D handoff.module_hv; + return seamcall_prerr(TDH_SYS_SHUTDOWN, &args); +} + static bool is_pamt_page(unsigned long phys) { struct tdmr_info_list *tdmr_list =3D &tdx_tdmr_list; diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index 76c5fb1e1ffe..f0c20dea0388 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -46,6 +46,7 @@ #define TDH_PHYMEM_PAGE_WBINVD 41 #define TDH_VP_WR 43 #define TDH_SYS_CONFIG 45 +#define TDH_SYS_SHUTDOWN 52 #define TDH_SYS_DISABLE 69 =20 /* @@ -108,4 +109,6 @@ struct tdmr_info_list { int max_tdmrs; /* How many 'tdmr_info's are allocated */ }; =20 +int tdx_module_shutdown(void); + #endif diff --git a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c b/arch/x86/virt/vm= x/tdx/tdx_global_metadata.c index d54d4227990c..e793dec688ab 100644 --- a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c +++ b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c @@ -100,6 +100,19 @@ static __init int get_tdx_sys_info_td_conf(struct tdx_= sys_info_td_conf *sysinfo_ return ret; } =20 +static int get_tdx_sys_info_handoff(struct tdx_sys_info_handoff *sysinfo_h= andoff) +{ + int ret; + u64 val; + + ret =3D read_sys_metadata_field(0x8900000100000000, &val); + if (ret) + return ret; + + sysinfo_handoff->module_hv =3D val; + return 0; +} + static __init int get_tdx_sys_info(struct tdx_sys_info *sysinfo) { int ret =3D 0; --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 C5CD84CA274; Wed, 13 May 2026 15:11:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685118; cv=none; b=SqF3cF9BbAorD7ybyFit3zsjbskGyu5RnijuQzD9MSTcMkboazi6yrQjwIokXULqZAVeQHI+iq7Vuor1WNFjwu+eXsZShcPRgCqfdd8mjiH/MFF6QZFu4Pa03WuHWUTt48EGjm85SHEFqdh8V5hGZgHTX0X2gO/sfqXlb4GxNW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685118; c=relaxed/simple; bh=Eaje9rcq+hNWK5XIn6HNCyCfWVyJ7d+TYb5MybZ0Uu4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hfYq9GzzYvSA5KGKck6Zz6fACty/768wKjOAq1WCAWHcGSNcCn0IpGTyjqMgfTJKQhcx//iapuNSOtkyoj7mHnSi2zGzj3gZdlzxOcbbYrukgdehup6cb8qoLdXAySigsW4ZNcvQDN/f5lHkzY2gp4LS76bW0KyuzgMttSyB5p4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jOnKvi6R; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jOnKvi6R" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685116; x=1810221116; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Eaje9rcq+hNWK5XIn6HNCyCfWVyJ7d+TYb5MybZ0Uu4=; b=jOnKvi6Rn6MruN0xNNT7s9SBSI+SH93xUiCeFCTfPPl1ua5dLB8NMEhh o9E6cOQs5mYaRALXQuGK7d8bsIojI6zd5HFaqc1rd2fRRAeJGcokWtams x7dB/a8dVcUg/88jhwBwU/B5AtJoOdx7jdXYWJqKxFHw7hm1uoJrWKsA2 YczVW9SEyvlBmi+Si6Sm/yEjMMFATgYxwxLMCZ6kfBTnwbnj3J3Ivg0Si xcESrww6i4nv0kv02R2h4vW0p5hleMY0s5Adk3929XUB9xMuXPxPMW9RS G5L2DRbonKvaK0VKLN9dTc/ZnOl4ECNfwuOmEXOpqz5RKl4c59Tjv4m0A A==; X-CSE-ConnectionGUID: os09Oo15S6+iF4qa7WPO4w== X-CSE-MsgGUID: aeyczR8TRyyW2iuXh9Nt4A== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921747" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921747" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:54 -0700 X-CSE-ConnectionGUID: zEljFDf8SDeyb7dsaZjTmQ== X-CSE-MsgGUID: D0ta9n1cQY2UpGcBWjVwyw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716883" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:53 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 15/23] x86/virt/tdx: Reset software states during TDX module shutdown Date: Wed, 13 May 2026 08:09:58 -0700 Message-ID: <20260513151045.1420990-16-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" The TDX module requires a one-time global initialization (TDH.SYS.INIT) and per-CPU initialization (TDH.SYS.LP.INIT) before use. These initializations are guarded by software flags to prevent repetition. After TDX module updates, the new TDX module requires the same global and per-CPU initializations, but the existing software flags prevent re-initialization. Reset all software flags guarding the initialization flows to allow the global and per-CPU initializations to be triggered again after updates. Signed-off-by: Chao Gao Reviewed-by: Tony Lindgren Reviewed-by: Kai Huang Reviewed-by: Rick Edgecombe --- v9: - use a global structure for TDX global state and use memset to zero the whole structure [Dave] --- arch/x86/virt/vmx/tdx/tdx.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index da3c1e857b26..20b3b33e4677 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1271,7 +1271,7 @@ int tdx_module_shutdown(void) { struct tdx_sys_info_handoff handoff =3D {}; struct tdx_module_args args =3D {}; - int ret; + int ret, cpu; =20 ret =3D get_tdx_sys_info_handoff(&handoff); WARN_ON_ONCE(ret); @@ -1281,7 +1281,21 @@ int tdx_module_shutdown(void) * module can produce and most likely supported by newer modules. */ args.rcx =3D handoff.module_hv; - return seamcall_prerr(TDH_SYS_SHUTDOWN, &args); + ret =3D seamcall_prerr(TDH_SYS_SHUTDOWN, &args); + if (ret) + return ret; + + /* + * Clear global and per-CPU initialization flags so the new module + * can be fully re-initialized after a successful update. + * + * No locks needed as no concurrent accesses can occur here. + */ + memset(&tdx_module_state, 0, sizeof(tdx_module_state)); + for_each_possible_cpu(cpu) + per_cpu(tdx_lp_initialized, cpu) =3D false; + + return 0; } =20 static bool is_pamt_page(unsigned long phys) --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 21E5D4CA282; Wed, 13 May 2026 15:11:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685118; cv=none; b=MCnvEivE0LZUMCC2VvIDtKmPJT0ZuSdh3WOouznrbTq4um03rzcu8r8Cy4w/ObH8iHGItji02Hvn2wCQSy159KDIt3eJNPg8vW0DKRkfywSGXJgAVAQ7SMFTujV2v4UJGINwZVjEesVtHbaeEellIQyMPupMDzu1Pyq330CAKoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685118; c=relaxed/simple; bh=mA+Ls5mGcVtIkKcE5YQQTXwY+Wu62lieuDPPD5IDV2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MX0NMbqyQppFQ9TRMQX2oose6VCPlENCnVN26vyn7ZWauyyfPjSNQyHBSPlV8T6zkBD1wgXsNda1wSBM8R1Hqhyq/mb/Kt5Wy/X2MQ+/muDGV3YRa8SPvEORtcBTUX7+xs6RL/oZxnk3u90V0anCenWQUhrm6jB0qYSvdRw5pps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Cd+7S6zx; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Cd+7S6zx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685117; x=1810221117; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mA+Ls5mGcVtIkKcE5YQQTXwY+Wu62lieuDPPD5IDV2w=; b=Cd+7S6zxj1/+JdEXE6s9OcAz0C8UCcMzNT3P5ej2/mysm45alClXQ4iZ /V6Nb7AxnYpgkGSbgJ6EUH0bJ00XPLkGaMueINOHSlV/Rjgd+VvHs5jpi ODFuU98502OCZ8jr1CLtqkFGc8gVtEoxqMOLFA0sJbdJLF3HFtSjyHrZb UMG+rJSf/IzDwR+5YFNiHRsO50lYf/lQigeLLZfxPYqfovvo3ZzbsPHZ9 bB+svFIPw/wEMHcAfV8I9xRw6zHxN8ECf1I1iGqpgVeKWwy/D7UHlDkbR n+I6bWTaIFQZLoW671POVmmUbLCRtcRYxi44aHVeKlIDLgD9Rr5zyMlmD Q==; X-CSE-ConnectionGUID: N8d6vPNFRLWdYiBHdVKB2g== X-CSE-MsgGUID: lh/i0Fb9QSGMvpo+/x3wIg== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921763" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921763" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:55 -0700 X-CSE-ConnectionGUID: XlXgSa/VQhiRTCB7DMjWzQ== X-CSE-MsgGUID: i+xQEzbwSGeejNWG9hF06Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716893" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:54 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 16/23] x86/virt/seamldr: Install a new TDX module Date: Wed, 13 May 2026 08:09:59 -0700 Message-ID: <20260513151045.1420990-17-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" Following the shutdown of the existing TDX module, the update process continues with installing the new module. P-SEAMLDR provides the SEAMLDR.INSTALL SEAMCALL to perform this installation, which must be executed on all CPUs. Implement SEAMLDR.INSTALL and execute it on every CPU. Signed-off-by: Chao Gao Reviewed-by: Tony Lindgren Reviewed-by: Kai Huang Reviewed-by: Xu Yilun Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Rick Edgecombe --- v9: - Add a comment above seamldr_install() --- arch/x86/virt/vmx/tdx/seamldr.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c index 6114cab46196..9d0e7e8c6c20 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -19,6 +19,7 @@ =20 /* P-SEAMLDR SEAMCALL leaf function */ #define P_SEAMLDR_INFO 0x8000000000000000 +#define P_SEAMLDR_INSTALL 0x8000000000000001 =20 #define SEAMLDR_MAX_NR_MODULE_PAGES 496 #define SEAMLDR_MAX_NR_SIG_PAGES 1 @@ -74,6 +75,15 @@ int seamldr_get_info(struct seamldr_info *seamldr_info) } EXPORT_SYMBOL_FOR_MODULES(seamldr_get_info, "tdx-host"); =20 +/* Call into P-SEAMLDR to install a TDX module update */ +static int seamldr_install(const struct seamldr_params *params) +{ + struct tdx_module_args args =3D {}; + + args.rcx =3D __pa(params); + return seamldr_call(P_SEAMLDR_INSTALL, &args); +} + #define TDX_IMAGE_VERSION_2 0x200 =20 struct tdx_image_header { @@ -166,6 +176,7 @@ static int init_seamldr_params(struct seamldr_params *p= arams, const u8 *data, u3 enum module_update_state { MODULE_UPDATE_START, MODULE_UPDATE_SHUTDOWN, + MODULE_UPDATE_CPU_INSTALL, MODULE_UPDATE_DONE, }; =20 @@ -240,6 +251,9 @@ static int do_seamldr_install_module(void *seamldr_para= ms) if (primary) ret =3D tdx_module_shutdown(); break; + case MODULE_UPDATE_CPU_INSTALL: + ret =3D seamldr_install(seamldr_params); + break; default: break; } --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 51F634CA287; Wed, 13 May 2026 15:11:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685118; cv=none; b=iqJYK5BndHsccRWZqZ48974ZUPGyMNTG+rSCnPakVr/FG+XF/oBY8y1aW7TV8cW6HFuY5lBjHJjwdTjw8b4l1HsuBLit2oQV8SsqPmklsCxAZp8HS36OkJgNNThYHUtF/yobOJ/nQbzXPWhHEmpj2KMxHOT2dwA6lBV9YPx5LfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685118; c=relaxed/simple; bh=pVfScDnFT5LQzUKrbNHeZ9wxSjJOj5uItEQNF5d741E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yu0Uc/Tpl7ARb82ptFOPeanT7Gk20QKZzE08+JPLvP2Z5mw9vQiOv3Hc6mAkqbbdspCV7qV0wj0zeMMFFyNZuBAACQQEihTKQ5i4p+XBRQjhg6AcfBpBwvupqj6JzUkiyQIhUti2iBxbtOoF8ilpamWcIIXrQTeLr00OOPk1pOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iPO0rSUx; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iPO0rSUx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685117; x=1810221117; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pVfScDnFT5LQzUKrbNHeZ9wxSjJOj5uItEQNF5d741E=; b=iPO0rSUxAAXz84HXHLiivcpqpgslRZrQS3JggHWdny5i8x3DRWkcYQkk gYmfTo0IRoj+EQUgkgp6ikkX3+XdcGZbxohgYjJr4U+/FDJ9WTeWALd6I 1vndGiHrxPKgazFvHzxRMQqHCYN7pfMHPAen+RfFnZkf2ayzemvEp0b4H j6L8ShX16XJwUnU0SZBO1pNNMo+bW6YNfU8pK6f+Jb27Het/fJogwKdOf 8pVNb7XO/m3ubwTAXsfqkP5y6XyK+Hm6MgRD7WmxGUB4R1EjZSl1pQSk7 u9wGWaWDJwGVjhUiF2AZiSFQ7CfxiqrLf4ih7KtHR0j/DmOMMsnpN78PR g==; X-CSE-ConnectionGUID: ClcRMEukTBqtro5yHuoSsA== X-CSE-MsgGUID: ycRYzClnQ7GOYuorfX6wXQ== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921771" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921771" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:56 -0700 X-CSE-ConnectionGUID: +itVP+tMQSaPFRL/gJvtTQ== X-CSE-MsgGUID: sPdDWnQkQwOmHiOpgoCkjg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716898" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:56 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 17/23] x86/virt/seamldr: Do TDX per-CPU initialization after module installation Date: Wed, 13 May 2026 08:10:00 -0700 Message-ID: <20260513151045.1420990-18-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" After installing the new TDX module, each CPU needs to be initialized again to make the CPU ready to run any other SEAMCALLs. So, export and call tdx_cpu_enable() on all CPUs. Signed-off-by: Chao Gao Reviewed-by: Xu Yilun Reviewed-by: Tony Lindgren Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Rick Edgecombe --- arch/x86/include/asm/tdx.h | 1 + arch/x86/virt/vmx/tdx/seamldr.c | 4 ++++ arch/x86/virt/vmx/tdx/tdx.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 27376db7ddac..5d750fe53669 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -107,6 +107,7 @@ static inline long tdx_kvm_hypercall(unsigned int nr, u= nsigned long p1, =20 #ifdef CONFIG_INTEL_TDX_HOST void tdx_init(void); +int tdx_cpu_enable(void); const char *tdx_dump_mce_info(struct mce *m); const struct tdx_sys_info *tdx_get_sysinfo(void); =20 diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c index 9d0e7e8c6c20..e4a3271051f6 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -177,6 +177,7 @@ enum module_update_state { MODULE_UPDATE_START, MODULE_UPDATE_SHUTDOWN, MODULE_UPDATE_CPU_INSTALL, + MODULE_UPDATE_CPU_INIT, MODULE_UPDATE_DONE, }; =20 @@ -254,6 +255,9 @@ static int do_seamldr_install_module(void *seamldr_para= ms) case MODULE_UPDATE_CPU_INSTALL: ret =3D seamldr_install(seamldr_params); break; + case MODULE_UPDATE_CPU_INIT: + ret =3D tdx_cpu_enable(); + break; default: break; } diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 20b3b33e4677..5e54da302f2d 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -106,7 +106,7 @@ static int try_init_module_global(void) * (and TDX module global initialization SEAMCALL if not done) on local cp= u to * make this cpu be ready to run any other SEAMCALLs. */ -static int tdx_cpu_enable(void) +int tdx_cpu_enable(void) { struct tdx_module_args args =3D {}; int ret; --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 66F654CA274; Wed, 13 May 2026 15:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685122; cv=none; b=ctHsIFYxrZocKNALpo+mvE6kcSh4xStVlFDKDJLxjAgtxCMFUr65T7KM1oko+wWAQ3rF74+LFs2x+sOctFgLkdbeWnOGvQWJfTKnFyJRXcvIE0g0d6uPR4okLQAlIUMlMGn/Yj41Jc0ZKPnCnsVReFij/oMPix+2bDju6dT9C74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685122; c=relaxed/simple; bh=LgJAWydLHvR8ezJs7eq/SLlr4i/XqNnAZA8qUlJbBtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cKivIjIkFAnMEbFTPi3y8H28EgQG3NIS43YVPUnF5wJsArYWQC84jO1BkQ54CHIdXW69dQZFb/KUy3k8EDRGSMNT7wKCltPZ+Ad5ezgBNRqzZKIq7RBtEBujekw1XheHhvQRkmBz/tmhyCwWRuY04+PDemlbttCC+MlpXXthcpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=F60GaVZi; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="F60GaVZi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685121; x=1810221121; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LgJAWydLHvR8ezJs7eq/SLlr4i/XqNnAZA8qUlJbBtw=; b=F60GaVZiu+PTTDfZGQHMOBm1idYF9j8hqJJFZTBtZcmCQt0aHVGyTqfv 5KUtN/BIS9FJbPOaZqdcHUkWsFE1ahb1JoAc9z6E0s+VOCEwH18CQIxef 7Ah4cb2idb4pdn449J7gnCt3vMexpYg27w8dqkBN54697iRHIK/M45Opv QZGYC3MqHlx4i3yYAxnJj+oFjNv29uPqmkcgX421+0ecBUWY1bzdhYNJQ fPEI8lnSA3zZlKcHzXiETxmJG27NktMQv/KyMXCUGoHDm49DeZkUa+M1n 9lFozWlgvPpBw9kupvTXRC+PqU80CMXAmLZe+fOXOdp4ebOipgVxPMbhc g==; X-CSE-ConnectionGUID: 3BdbuMWZTx2t710wxh2EFg== X-CSE-MsgGUID: t2kOQPDWRnW7tICT4tJH+w== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921779" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921779" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:57 -0700 X-CSE-ConnectionGUID: +70KIATCQYm4NRINAyKfZQ== X-CSE-MsgGUID: 20f9AGtaSqSy4yuzSz/M0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716904" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:57 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 18/23] x86/virt/tdx: Restore TDX module state Date: Wed, 13 May 2026 08:10:01 -0700 Message-ID: <20260513151045.1420990-19-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable TDX module state was packed as handoff data during module shutdown. After per-CPU initialization, the new module can restore TDX module state from handoff data to preserve running TDs. Once the restoration is done, the TDX module update is complete, which means the new module is ready to handle requests from the host and guests. Implement the new TDH.SYS.UPDATE SEAMCALL to restore TDX module state and invoke it on one CPU since it only needs to be called once. For error handling, Intel=C2=AE Trust Domain Extensions (Intel=C2=AE TDX) Module Base Architecture Specification, Chapter "Restore TDX Module State after a TD-Preserving Update" states If TDH.SYS.UPDATE returns an error, then the host VMM can continue with the non-update sequence (TDH.SYS.CONFIG, TDH.SYS.KEY.CONFIG etc.). In this case all existing TDs are lost. Alternatively, the host VMM can request the P-SEAMLDR to update to another TDX module. If that update is successful, existing TDs are preserved. Given the complexity and uncertain value of above recovery paths, simply propagate errors. Also note that the location and the format of handoff data is defined by the TDX module. The new module knows where to get handoff data and how to parse it. The kernel doesn't need to provide its location, format etc. Signed-off-by: Chao Gao Reviewed-by: Tony Lindgren Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Rick Edgecombe --- arch/x86/virt/vmx/tdx/seamldr.c | 5 +++++ arch/x86/virt/vmx/tdx/tdx.c | 13 +++++++++++++ arch/x86/virt/vmx/tdx/tdx.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamld= r.c index e4a3271051f6..6a39c9e3ef7d 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -178,6 +178,7 @@ enum module_update_state { MODULE_UPDATE_SHUTDOWN, MODULE_UPDATE_CPU_INSTALL, MODULE_UPDATE_CPU_INIT, + MODULE_UPDATE_RUN_UPDATE, MODULE_UPDATE_DONE, }; =20 @@ -258,6 +259,10 @@ static int do_seamldr_install_module(void *seamldr_par= ams) case MODULE_UPDATE_CPU_INIT: ret =3D tdx_cpu_enable(); break; + case MODULE_UPDATE_RUN_UPDATE: + if (primary) + ret =3D tdx_module_run_update(); + break; default: break; } diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 5e54da302f2d..7eb1b67af656 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1298,6 +1298,19 @@ int tdx_module_shutdown(void) return 0; } =20 +int tdx_module_run_update(void) +{ + struct tdx_module_args args =3D {}; + int ret; + + ret =3D seamcall_prerr(TDH_SYS_UPDATE, &args); + if (ret) + return ret; + + tdx_module_state.initialized =3D true; + return 0; +} + static bool is_pamt_page(unsigned long phys) { struct tdmr_info_list *tdmr_list =3D &tdx_tdmr_list; diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index f0c20dea0388..bdfd0e1e337a 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -47,6 +47,7 @@ #define TDH_VP_WR 43 #define TDH_SYS_CONFIG 45 #define TDH_SYS_SHUTDOWN 52 +#define TDH_SYS_UPDATE 53 #define TDH_SYS_DISABLE 69 =20 /* @@ -110,5 +111,6 @@ struct tdmr_info_list { }; =20 int tdx_module_shutdown(void); +int tdx_module_run_update(void); =20 #endif --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 7B2314DA559; Wed, 13 May 2026 15:12:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685123; cv=none; b=MLjqh3LDJLi/ArxOVEuAS3lIZeKuViP9EDrV5cav0IKmNCIOQQk04o6/i7gXQ1seNFeLjbdnjKnsdo8CFYpky5lrnZFVn3uQwpE7oJAmaeaaE1xz6+XMOA4Ovr0RI2+dCY5KAvWffNTXCzCHmsCDsv6QZvxv906i230VMyxPIYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685123; c=relaxed/simple; bh=OJs+uzAVPvyai7EjlSuZGq+u2Jdj5elwWlSDt98B6hc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=La348d77suRG8F0QxniYeT5i1XuVXwbUzYsh+iK9UKD1bHAF1jAVrNnM8k92MPPCccBDJFHG0c7IMlzhq0gPtXGamak0LdiCkpHBqZ/1rL6Sy06LKqTEzXwyxPniCncoJfWmuaxVBx5A6+ucLhU5URXMVxclkoyGPAsvrhWYafg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=V/1iG2hd; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="V/1iG2hd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685120; x=1810221120; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OJs+uzAVPvyai7EjlSuZGq+u2Jdj5elwWlSDt98B6hc=; b=V/1iG2hdy+/flzUpmgIx+V72MgcF+NXniVmWKUG/vgMvJeS5D57o+2NZ UDpo/2tBt+PtFjOs4s08QzHAQFmBMvTGXuUZyrn31KlHtJX/e42hsTiyS L+FMR/DXftBWmmO5MnM+FOrYAqhk0thCVl079hAdCNJARtT1flIICRpbh nnQHYboEjnhom/XzLDRFfPUDQiiejhOIkQe6/lwGzDilfdgPJ9A24V/jy 1QjbIZPENIeDm06OqsIge/XJPbtUhPMQXguP+ggoKJF8KsZxPmQCu9p5k MjiDhpiwitvU61w7c3Iel9Y02nEmKIR0vVzkaEKyE0VkTRSEeq/jaHv3M g==; X-CSE-ConnectionGUID: BJ8Cg8ARTvK70HhosE8kdA== X-CSE-MsgGUID: GmeuPqAMRI6H6FGIkSmgBA== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921790" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921790" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:58 -0700 X-CSE-ConnectionGUID: RsyfL3IoTOSbDecfprjXRg== X-CSE-MsgGUID: MUniygxbSOygWicp/KzpgQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716909" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:58 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 19/23] x86/virt/tdx: Refresh TDX module version after update Date: Wed, 13 May 2026 08:10:02 -0700 Message-ID: <20260513151045.1420990-20-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" The kernel exposes the TDX module version through sysfs so userspace can check update compatibility. That information needs to remain accurate across runtime updates. A runtime update may change the module's update_version, so refresh the cached version right after a successful update. Drop __ro_after_init from tdx_sysinfo because it is now updated at runtime. Do not refresh the rest of tdx_sysinfo, even if some values change across updates. TDX module updates are backward compatible, so existing tdx_sysinfo consumers, e.g. KVM, can continue to operate without seeing the new values. Refreshing the full structure would be risky. A tdx_sysinfo consumer may initialize its TDX support based on the features originally reported in tdx_sysinfo. If a runtime update adds new features and the full structure is refreshed, that consumer could observe and use the newly reported features without having performed the setup required to use them safely. Signed-off-by: Chao Gao Reviewed-by: Rick Edgecombe --- v9: - don't print old and new version [Dave] - explain why it's OK to hide changes from the tdx_sysinfo users [Dave] - update versions in stop_machine context - don't mention major/minor versions are idential across updates. That fact= is not relevant here. --- arch/x86/virt/vmx/tdx/tdx.c | 6 +++++- arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 7eb1b67af656..a04b69f77c6e 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -67,7 +67,7 @@ static struct tdmr_info_list tdx_tdmr_list; /* All TDX-usable memory regions. Protected by mem_hotplug_lock. */ static LIST_HEAD(tdx_memlist); =20 -static struct tdx_sys_info tdx_sysinfo __ro_after_init; +static struct tdx_sys_info tdx_sysinfo; =20 /* * Do the module global initialization once and return its result. @@ -1307,6 +1307,10 @@ int tdx_module_run_update(void) if (ret) return ret; =20 + /* Shouldn't fail as the update has succeeded. */ + ret =3D get_tdx_sys_info_version(&tdx_sysinfo.version); + WARN_ON_ONCE(ret); + tdx_module_state.initialized =3D true; return 0; } diff --git a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c b/arch/x86/virt/vm= x/tdx/tdx_global_metadata.c index e793dec688ab..e49c300f23d4 100644 --- a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c +++ b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c @@ -7,7 +7,7 @@ * Include this file to other C file instead. */ =20 -static __init int get_tdx_sys_info_version(struct tdx_sys_info_version *sy= sinfo_version) +static int get_tdx_sys_info_version(struct tdx_sys_info_version *sysinfo_v= ersion) { int ret =3D 0; u64 val; --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 624BF4D9918; Wed, 13 May 2026 15:12:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685123; cv=none; b=S8ayyTsbuXN7s7vyuS3UyI0WIVXT9Rh7eIpgZibW8C1PAYXKyX4gWQNWb3arN0KF3aVgR9d55rrYCxWRwnssvCPjXo1Dqvs0Jg6xMTXb8ZU14Hmv50rNhQxqA7n689Q3luxmdwMU0lu7uh1vAjbJnIXotz1U3jMP5AoboVURT+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685123; c=relaxed/simple; bh=i9WOcanhTAn5ETWDOWE5GSQybjpHUnROCBLLlQF1bBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rAnJbNZA1Lp5m3ALmqazXRo99KI9FrUrhlFddErU9IJ3dMGX5Ro/X2sEfCEjhgOkEu1VoN6wfIWTdnglXi3qTvnlFvS84aLgqE7ajKkUKISqME/yx5caiZVFumHr3oAWGl8YlAsKKZ1EsHvt9Dq0RrPMLSeAGDtmfGlUmtgvrEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=E7+9gq0F; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="E7+9gq0F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685122; x=1810221122; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i9WOcanhTAn5ETWDOWE5GSQybjpHUnROCBLLlQF1bBw=; b=E7+9gq0FbxoIU1qcRZd5Vh+IxAF3SAZjDNqGkeg9v864JRooFfW8d/Ny yx0dRA6hp5UheUeSxf4STdFWQTrt0fTjvbGn3HhXjZju6UE8T7TFlRzbp fLeiM1UamkQJa4xSEj2kb8BpvNDjI+ijbiwHwcPHnAtms4HcmhRpHKU+h THh1CtrT00oyb3MoDBhJNjUk65cpLV3PptFV3KurhyNmRFGxP9VoJdWKq 1X2MZP4bu2a2ilYdPj7XnXAOPL0NXAnDPomp0DFtDsLez8zP67Bnq/RFz TKTp0aX4MqGul0gr+kqNdOm+8fSpIlRGI5nqC79uthvVXtYHPdzDMboJy Q==; X-CSE-ConnectionGUID: vE9iQ5/WT4aMkDDir38rSw== X-CSE-MsgGUID: s1LDKerHSmWFg0n2YxtUCg== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921801" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921801" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:59 -0700 X-CSE-ConnectionGUID: 3aVINOlxRoS6JhmVBX9Ezg== X-CSE-MsgGUID: ZKG9/6SFRG+5AKK3w90/aw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716916" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:11:59 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 20/23] x86/virt/tdx: Reject updates during compatibility-sensitive operations Date: Wed, 13 May 2026 08:10:03 -0700 Message-ID: <20260513151045.1420990-21-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" A TDX module erratum can corrupt TD state if a module update races with a compatibility-sensitive operation. For example, if an update races with TD build, the TD measurement hash may be corrupted, which can later cause attestation failure. Handle this by requesting the TDX module to detect such races during TDH.SYS.SHUTDOWN and reject the update when one is found. Report the failure to userspace as -EBUSY so the update can be retried. The downside is that module updates can be blocked indefinitely if compatibility-sensitive operations do not quiesce. In that case, userspace must resolve the conflict and retry the update. Do not pre-check whether the TDX module supports this race-detection capability. If it does not, rely on the TDX module to reject module shutdown. =3D=3D Alternatives =3D=3D Two alternatives were considered and rejected [1]: a. Fail TD build when the race occurs. This would complicate KVM error handling and risk KVM uABI instability. b. Allow the issue to leak through. This would make the problem harder to detect and recover from. Signed-off-by: Chao Gao Link: https://lore.kernel.org/linux-coco/aQIbM5m09G0FYTzE@google.com/ # [1] --- v9: - Rewrite the changelog: focus on what the patch does and downsides then the alternatives [Dave] - Extract the movement of TDX_FEATURE0 bit definitions into a cleanup patc= h [Dave] --- arch/x86/include/asm/tdx.h | 6 ++++-- arch/x86/virt/vmx/tdx/tdx.c | 30 ++++++++++++++++++++++++--- drivers/virt/coco/tdx-host/tdx-host.c | 2 ++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 5d750fe53669..1e1bdc4ec9c8 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -29,11 +29,13 @@ /* * TDX module SEAMCALL leaf function error codes */ -#define TDX_SUCCESS 0ULL -#define TDX_RND_NO_ENTROPY 0x8000020300000000ULL +#define TDX_SUCCESS 0ULL +#define TDX_RND_NO_ENTROPY 0x8000020300000000ULL +#define TDX_UPDATE_COMPAT_SENSITIVE 0x8000051200000000ULL =20 /* Bit definitions of TDX_FEATURES0 metadata field */ #define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18) +#define TDX_FEATURES0_UPDATE_COMPAT BIT_ULL(47) =20 #ifndef __ASSEMBLER__ =20 diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index a04b69f77c6e..2ab6f6efe6d1 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1267,11 +1267,14 @@ static __init int tdx_enable(void) } subsys_initcall(tdx_enable); =20 +#define TDX_SYS_SHUTDOWN_AVOID_COMPAT_SENSITIVE BIT(16) + int tdx_module_shutdown(void) { struct tdx_sys_info_handoff handoff =3D {}; struct tdx_module_args args =3D {}; int ret, cpu; + u64 err; =20 ret =3D get_tdx_sys_info_handoff(&handoff); WARN_ON_ONCE(ret); @@ -1281,9 +1284,30 @@ int tdx_module_shutdown(void) * module can produce and most likely supported by newer modules. */ args.rcx =3D handoff.module_hv; - ret =3D seamcall_prerr(TDH_SYS_SHUTDOWN, &args); - if (ret) - return ret; + + /* + * This flag tells the TDX module to reject shutdown if it races + * with a "sensitive" ongoing operation. That eliminates exposure + * to a TDX erratum which can corrupt TDX guest states. + * + * This flag is not supported by all TDX modules and may cause + * the shutdown (and subsequent update procedure) to fail. + */ + args.rcx |=3D TDX_SYS_SHUTDOWN_AVOID_COMPAT_SENSITIVE; + + err =3D seamcall(TDH_SYS_SHUTDOWN, &args); + + /* + * The shutdown ran into a "sensitive" ongoing operation. Signal + * to userspace that it can retry. + */ + if ((err & TDX_SEAMCALL_STATUS_MASK) =3D=3D TDX_UPDATE_COMPAT_SENSITIVE) + return -EBUSY; + + if (err) { + seamcall_err(TDH_SYS_SHUTDOWN, err, &args); + return -EIO; + } =20 /* * Clear global and per-CPU initialization flags so the new module diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-= host/tdx-host.c index c4c099cf3de1..ad116e56aa1a 100644 --- a/drivers/virt/coco/tdx-host/tdx-host.c +++ b/drivers/virt/coco/tdx-host/tdx-host.c @@ -135,6 +135,8 @@ static enum fw_upload_err tdx_fw_write(struct fw_upload= *fwl, const u8 *data, case 0: *written =3D size; return FW_UPLOAD_ERR_NONE; + case -EBUSY: + return FW_UPLOAD_ERR_BUSY; default: return FW_UPLOAD_ERR_FW_INVALID; } --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 F2CF64DA55C; Wed, 13 May 2026 15:12:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685124; cv=none; b=AiD8aG9D2rr5X/grnj4wg7KXohHRHFizvkX3OLPyru6BhYdzeyEt1ykD9opOclHboxMJ8rWNpOTwws4C1MoWCLFUlX52x9Esf98nVVA9X9GhVhUifEaXmDZSZC5jMYcX8yC9aunRdLCi/6P7CMPjs1JmOQbd0IP91BHNeJv/tYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685124; c=relaxed/simple; bh=NQ4lEceBbiRV2FzlBRrERpkQeA5r2KNYHsPAFpy9GUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OOm0XjEdF0DE5awEQD5V+7sOCg3aqHCNcI7vGikKxsHB60m9dDbNUiDjjppTK4tv1vLMr048vKc7tFYHzMIouvmfGT81fcVFJXnQGO6k+7hRzy5lmwqvXYRm9vGmZWQ+ZRU7OXLKEtVqjDViswbbSurMKvmX3uq0c+/zeM+09+U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=LgL/DuzL; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LgL/DuzL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685123; x=1810221123; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NQ4lEceBbiRV2FzlBRrERpkQeA5r2KNYHsPAFpy9GUE=; b=LgL/DuzLwxuijQZpADpJMaXEEZxe/lcGDlzkxVIb1jNN3B5eKcNfBjsF 6IFKTdL2ZaLtnZb0Nxw2iNpaupESpDutDQpwa7uQQ9x18ugp4qBw5WjVr 4rYZj7ZkQ4FItQHb9am348CUAivpyx5srMexTRbv2Vt18YxqeTKsZ3g5K a/jtMchxiHUypMm/0ASrm7UM39F/fUGA6joMt24P1T+6NAVUNExTo9ufH zGBchOvOTZniFhV156ntivtrTNC6rSiEihGhrr8NDVM0WOfRX2Kvf/7W1 7xAsaY5F+mab3X2dURbEHQfcwudPJ9ka78E7u8ilyEuJ92bcTD8wBC0ZH Q==; X-CSE-ConnectionGUID: akBEJne1SxO1ATqXneWBlQ== X-CSE-MsgGUID: kh4sqhZuQMOeOD1VkqGn7Q== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921811" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921811" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:12:00 -0700 X-CSE-ConnectionGUID: h9+/am/jT/Sxq/mdceleFQ== X-CSE-MsgGUID: poH7E0tORwSMvvqKCXvL7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716922" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:12:00 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v9 21/23] x86/virt/tdx: Enable TDX module runtime updates Date: Wed, 13 May 2026 08:10:04 -0700 Message-ID: <20260513151045.1420990-22-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" All pieces of TDX module runtime updates are in place. Enable it if it is supported. Signed-off-by: Chao Gao Reviewed-by: Xu Yilun Reviewed-by: Tony Lindgren Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Rick Edgecombe --- arch/x86/include/asm/tdx.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 1e1bdc4ec9c8..ac042b369843 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -34,6 +34,7 @@ #define TDX_UPDATE_COMPAT_SENSITIVE 0x8000051200000000ULL =20 /* Bit definitions of TDX_FEATURES0 metadata field */ +#define TDX_FEATURES0_TD_PRESERVING BIT_ULL(1) #define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18) #define TDX_FEATURES0_UPDATE_COMPAT BIT_ULL(47) =20 @@ -115,8 +116,7 @@ const struct tdx_sys_info *tdx_get_sysinfo(void); =20 static inline bool tdx_supports_runtime_update(const struct tdx_sys_info *= sysinfo) { - /* To be enabled when kernel is ready. */ - return false; + return sysinfo->features.tdx_features0 & TDX_FEATURES0_TD_PRESERVING; } =20 int tdx_guest_keyid_alloc(void); --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 25F664DB56A; Wed, 13 May 2026 15:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685124; cv=none; b=BwnWh1jk3CsRpj1uLMuR0yp9RPp8mwwEmYxm07goaoXvSSbYGXyBiHSphmdRuPOjdpHWWQFr+6oLdGlO7zaRNjg1Yz928X7DY/gQLGtYAvJ4dFDdmhfZ6bLBfqnHk5l/eqNrO61Yg+3qLNN4vRTrWSlp/0W3rgqr6r7ptgJC6QU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685124; c=relaxed/simple; bh=gWj4SKVTRQCwExj/mUY7jfmfe/QOQ3xzc83+8c8gWAc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DnBoDqcZrzSjurKFVvg274S/jAJPesQZb8tKAnay1NSUDRQYK6oz/hg+/9oV031ykuTYosS3+WKFMsWWjJC6eZKMhfmhOARVaKzxSj8zBvqU6stn4jBzbr17LFHqhD/malm1v+xYrMOdCttr1/0rcsnpmti1XpUz9VYpcTnMAok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=k0gUO2eW; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="k0gUO2eW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685123; x=1810221123; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gWj4SKVTRQCwExj/mUY7jfmfe/QOQ3xzc83+8c8gWAc=; b=k0gUO2eWnPUOZFRpl2yeLDQmxvixUefBGNVsLCWghCm6MV9ZPQQOXntX Q7QXOoZ+UPjZcPonYs/D8duHCwmdVDrlewf2W4Hz1p+Vq7k2UgPT51IZC JUCmC+JW35329ymFriv2h3U09BTBkSFVegJHimz/ktZRx4NSIM4COhnb+ H7AWLF0IMi9gEkJNiJXJJ7TamXs7s0TB+jWm/JPzKS1EGvN8ml9+GiM+I I3AaWNZs+eRqk4ufa+kGPzJ6h7HxJ6gs0NlDFM1LkbaHZU/pFIbzyYnoS 0Bgua6O8lv8ALxhRY84miEbaKomKxhLgtzrvaADN1MNZ4ZHqqii71z8v9 A==; X-CSE-ConnectionGUID: GgOYgOqJTrqG9YjYtU8GrQ== X-CSE-MsgGUID: DsdR/CVGSGWwJ/lKNzntcw== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921821" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921821" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:12:01 -0700 X-CSE-ConnectionGUID: 9HZRAnETT5uGIAx+21Wvbw== X-CSE-MsgGUID: f0eUhzklR9iyLwPnM3EozQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716930" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:12:00 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, x86@kernel.org, linux-kernel@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Dan Williams Subject: [PATCH v9 22/23] coco/tdx-host: Document TDX module update compatibility criteria Date: Wed, 13 May 2026 08:10:05 -0700 Message-ID: <20260513151045.1420990-23-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The TDX module update protocol facilitates compatible runtime updates. Document the compatibility criteria and indicators of update failures. Note that runtime TDX module updates are an "update at your own risk" operation; userspace is responsible for ensuring that the update meets the compatibility criteria. Signed-off-by: Chao Gao Reviewed-by: Dan Williams Reviewed-by: Kiryl Shutsemau (Meta) --- v9: - Reword the update error descriptions. --- .../ABI/testing/sysfs-devices-faux-tdx-host | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-devices-faux-tdx-host b/Docume= ntation/ABI/testing/sysfs-devices-faux-tdx-host index 65897fe6abc0..9e08db231da1 100644 --- a/Documentation/ABI/testing/sysfs-devices-faux-tdx-host +++ b/Documentation/ABI/testing/sysfs-devices-faux-tdx-host @@ -26,3 +26,43 @@ Description: (RO) Report the number of remaining updates= . TDX maintains a See Intel=C2=AE Trust Domain Extensions - SEAM Loader (SEAMLDR) Interface Specification, Chapter "SEAMLDR_INFO" and Chapter "SEAMLDR.INSTALL" for more information. + +What: /sys/devices/faux/tdx_host/firmware/tdx_module +Contact: linux-coco@lists.linux.dev +Description: (Directory) The tdx_module directory implements the fw_upload + sysfs ABI, see Documentation/ABI/testing/sysfs-class-firmware + for the general description of the attributes @data, @cancel, + @error, @loading, @remaining_size, and @status. This ABI + facilitates "Compatible TDX module Updates". A compatible update + is one that meets the following criteria: + + Does not interrupt or interfere with any current TDX + operation or TD VM. + + Does not invalidate any previously consumed module metadata + values outside of the TEE_TCB_SVN_2 field (updated Security + Version Number) in TD Quotes. + + Does not require validation of new module metadata fields. By + implication, new module features and capabilities are only + available by installing the module at reboot (BIOS or EFI + helper loaded). + + See tdx_host/firmware/tdx_module/error for information on + update failure indicators. + +What: /sys/devices/faux/tdx_host/firmware/tdx_module/error +Contact: linux-coco@lists.linux.dev +Description: (RO) See Documentation/ABI/testing/sysfs-class-firmware for + baseline expectations for this file. The part in the + : format can be: + + "device-busy": The update conflicted with an ongoing + compatibility-sensitive operation. + + "firmware-invalid": The update failed for any other reason. + + "firmware-invalid" may be fatal, causing all TDs and the TDX + module to be lost and preventing further TDX operations. This + occurs when reading /sys/devices/faux/tdx_host/version returns + -ENXIO. --=20 2.52.0 From nobody Fri Jun 12 17:17:03 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 D69274CA287; Wed, 13 May 2026 15:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685125; cv=none; b=i2DU/MKwEGZA532t1uG4m05Qo+Q4p+KIjHrLFKr3VbuiS+yGd2GxkkJEvqZZUeTzJR/HzEkHpK75s2lRcQI8O5Mb9XHy6rjDAog9KCwJ9MSxzM3UvUH8ut2stMze77eLnAW6sxs50sqrn++Jyn8CxopLa5MKW9kkoRktXZtorrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778685125; c=relaxed/simple; bh=g7DBKzISsVeAPEr5fRf6vFci06L9JPnHLfj1n6CF7wg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HJgoJ8QkqoMlAZ1PyjCEa/d+u5Tj0UuwRyRLQ/93sTbFsgDf9qFCo7lL6VBLmiYvO9VM6e+xIxvBdo08us7vXAPQD2tPhZPJYI4/00UiKfQmH3xDvUZEq7bDmt/jW7/2xyZsClKrIfcW3e1Mp/xQqO+eAghOq8rUV+FiQLVSWyc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ePpBJbLT; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ePpBJbLT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778685124; x=1810221124; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g7DBKzISsVeAPEr5fRf6vFci06L9JPnHLfj1n6CF7wg=; b=ePpBJbLTJ+t/0cGMMe9aNv4M4mwkO9NiunZj2re+4bru6G/P+rF51is9 2huSSPLOIuZip9k+tO2b5WGyxYxt4BVYo6g2L/X02uQBSlvlLj6+RAGDM CA6Uj/ZJihZbNeY69TecuYxGSTP7e4SFGCpi2ryEWTN7NC4C/VTz5I/Id ZwPPIMcsBJUUVnFCjKGjNIwgN6DUjKgKbD+9/vWL+Qg2yEPuADqdIbKy2 s4NJ3Kuep2c7x5FJ4sEEP7Tlblufmil7A7n33/YUwO5zcESEaMW5u5kCi T5Y+g3DC9GSNDCfwPScK3xM7j+CaxNRZJdTDb8DnhTRa2oXa/VPl7SnmL w==; X-CSE-ConnectionGUID: YNMzsG2pQ1CsfjChsnRDmQ== X-CSE-MsgGUID: JU8csZH3Ru2yWe88fWqMgQ== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="89921830" X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="89921830" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:12:02 -0700 X-CSE-ConnectionGUID: gA4HYUfQQd62goYNWsZYTg== X-CSE-MsgGUID: 1fW5cWnpS/eV6H0ihhBZvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,232,1770624000"; d="scan'208";a="231716934" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 08:12:01 -0700 From: Chao Gao To: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: binbin.wu@linux.intel.com, dave.hansen@linux.intel.com, djbw@kernel.org, ira.weiny@intel.com, kai.huang@intel.com, kas@kernel.org, nik.borisov@suse.com, paulmck@kernel.org, pbonzini@redhat.com, reinette.chatre@intel.com, rick.p.edgecombe@intel.com, sagis@google.com, seanjc@google.com, tony.lindgren@linux.intel.com, vannapurve@google.com, vishal.l.verma@intel.com, yilun.xu@linux.intel.com, xiaoyao.li@intel.com, yan.y.zhao@intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Jonathan Corbet , Shuah Khan Subject: [PATCH v9 23/23] x86/virt/tdx: Document TDX module update Date: Wed, 13 May 2026 08:10:06 -0700 Message-ID: <20260513151045.1420990-24-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260513151045.1420990-1-chao.gao@intel.com> References: <20260513151045.1420990-1-chao.gao@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: quoted-printable Content-Type: text/plain; charset="utf-8" Document TDX module update as a subsection of "TDX Host Kernel Support" to provide background information and cover key points that developers and users may need to know, for example: - update is done in stop_machine() context - update instructions and results - update policy and tooling Signed-off-by: Chao Gao Reviewed-by: Kai Huang Reviewed-by: Kiryl Shutsemau (Meta) Reviewed-by: Rick Edgecombe --- Documentation/arch/x86/tdx.rst | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Documentation/arch/x86/tdx.rst b/Documentation/arch/x86/tdx.rst index 1a3b5bac1021..9d2b7db166b5 100644 --- a/Documentation/arch/x86/tdx.rst +++ b/Documentation/arch/x86/tdx.rst @@ -73,6 +73,40 @@ initialize:: =20 [..] virt/tdx: TDX-Module initialization failed ... =20 +TDX module Runtime Update +------------------------- + +The TDX architecture includes a persistent SEAM loader (P-SEAMLDR) that +runs in SEAM mode separately from the TDX module. The kernel can +communicate with P-SEAMLDR to perform runtime updates of the TDX module. + +During updates, the TDX module becomes unresponsive to other TDX +operations. To prevent components using TDX (such as KVM) from +experiencing unexpected errors during updates, updates are performed in +stop_machine() context. + +TDX module updates have complex compatibility requirements; the new module +must be compatible with the current CPU, P-SEAMLDR, and running TDX module. +Rather than implementing complex module selection and policy enforcement +logic in the kernel, userspace is responsible for auditing and selecting +appropriate updates. + +Updates use the standard firmware upload interface. See +Documentation/driver-api/firmware/fw_upload.rst for detailed instructions. + +If updates failed, running TDs may be killed and further TDX operations may +not be possible until reboot. For detailed error information, see +Documentation/ABI/testing/sysfs-devices-faux-tdx-host. + +Given the risk of losing existing TDs, userspace should verify that the +update is compatible with the current system and properly validated before +applying it. + +A reference userspace tool that implements necessary checks is available +at: + + https://github.com/intel/tdx-module-binaries + TDX Interaction to Other Kernel Components ------------------------------------------ =20 --=20 2.52.0