From nobody Sun May 24 19:34:54 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 61144371D1E; Fri, 22 May 2026 17:26:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779470796; cv=none; b=SjK+FSHzvQRl/ksHVIwt30xBisQtvnfeB1k3K6WwDn4GK16KMNC2IgpL5NDHWyRU7AlgI/EuDFolMfUbuN1b4BziqqAa0nSp0rX6StulyMfGukZIlGsK1jT87Xs6hhfSC9/nA8wYIdv7yl1F4umOr6Q/1hLbfxACQUuu/syU8/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779470796; c=relaxed/simple; bh=jolGiiPetTm0L0Rbi9yI/JrHQpHtGCfQOQi2nWUVYY4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=dIQzwXsRHv8MvXlA26LABSXbPdkDs/kuOz/n+ByATDiYTte1AQKzYgT/KRQRrMNZxB20q+aDcfAmU3TCbWAHXHZgOMRsmd/kA9LTh17p0SU61XrV7b001k890jaVCG+YMAumHhT/F57Rbf2M7XB1T+5jUpFXo+FavrtAiBDYTVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tSYv88cQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FXUolHDQ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tSYv88cQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FXUolHDQ" Date: Fri, 22 May 2026 17:26:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779470794; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=STQ8hfoGWCFv0Cc5V0cp19uUSL3mOqEi9O5OgtCngG4=; b=tSYv88cQhRQ0K8KeuHMYzsROyANOkNFSONsoWzrpBAu53R7dmuT0v+Z04fDMz1zkC6qMZm MOd9kMywGVC3AlGYI7rzG6brkWlgSPnbL8Rz8w2bXU+wdBE0FjcZBMBobh2TO8Hh4lCztP XOrbRJfGjNElmYX9IKzOU4TLUNmGCxCVFz589lEpYj/4RLRW/BfZNFc/uf6yrhcSaV/t+e G1Mojz+UjRtC6DpmhnFx0D5jMULwhP679hBU50UF6/rtqbEvfdzY7eOc0XdYncWsl63lZI 5NzKLDOxVLAnua2O+ihWkUiGkwI3KgNcBM+1SAIpAJyxcjuO1DdzRdWWPQiYIQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779470794; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=STQ8hfoGWCFv0Cc5V0cp19uUSL3mOqEi9O5OgtCngG4=; b=FXUolHDQRGntFQo5DP/XiTJkIHoFZW4JY0AlrzaNTa2MvpwpL9qgucYteyhQxfVnDTFEvA pmcObkXtmsm5hZAg== From: "tip-bot2 for Chao Gao" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/virt/tdx: Consolidate TDX global initialization states Cc: Chao Gao , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260520222848.C8D4AD6D@davehans-spike.ostc.intel.com> References: <20260520222848.C8D4AD6D@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177947079264.711.16217326148626195506.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 332d5758bbad876d6e1c0ff4f4a2a65b3ceac1b2 Gitweb: https://git.kernel.org/tip/332d5758bbad876d6e1c0ff4f4a2a65b3= ceac1b2 Author: Chao Gao AuthorDate: Wed, 20 May 2026 15:28:48 -07:00 Committer: Dave Hansen CommitterDate: Wed, 20 May 2026 15:37:08 -07:00 x86/virt/tdx: Consolidate TDX global initialization states 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 Signed-off-by: Dave Hansen Link: https://patch.msgid.link/20260520133909.409394-4-chao.gao@intel.com Link: https://patch.msgid.link/20260520222848.C8D4AD6D@davehans-spike.ostc.= intel.com --- arch/x86/virt/vmx/tdx/tdx.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 40444a3..71d39a7 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 @@ -106,8 +112,6 @@ static __always_inline int sc_retry_prerr(sc_func_t fun= c, sc_retry_prerr(__seamcall_ret, seamcall_err_ret, (__fn), (__args)) =20 static DEFINE_RAW_SPINLOCK(sysinit_lock); -static bool sysinit_done; -static int sysinit_ret; =20 /* * Do the module global initialization once and return its result. @@ -121,8 +125,8 @@ static int try_init_module_global(void) raw_spin_lock(&sysinit_lock); =20 /* Return the "cached" return code. */ - if (sysinit_done) { - ret =3D sysinit_ret; + if (tdx_module_state.sysinit_done) { + ret =3D tdx_module_state.sysinit_ret; goto out; } =20 @@ -139,8 +143,8 @@ static int try_init_module_global(void) pr_err("module not loaded\n"); =20 /* Save the return code for later callers. */ - sysinit_done =3D true; - sysinit_ret =3D ret; + tdx_module_state.sysinit_done =3D true; + tdx_module_state.sysinit_ret =3D ret; out: raw_spin_unlock(&sysinit_lock); return ret; @@ -1306,7 +1310,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; } @@ -1561,7 +1565,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;