From nobody Mon Jun 8 06:38:01 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 76544481AA1; Fri, 5 Jun 2026 21:25:39 +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=1780694740; cv=none; b=QUVtqHn3Jtyd/hw1c5vh4RC8nx4nVHDjniPL6BP7DPWAgau6Dzdj+JHy1HbczfhyJ/Xi+/23R4n6o8nRvbpKtOlq7glb0ca7stPW69jziGVN9xzk2FuRosad5O26L1SvI6QV+/f4q8EO0onNhk5PhJ04Ps6VSnQ/gN15PLZIj/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780694740; c=relaxed/simple; bh=X3JaVr2vqRmdtQvBeWrNm7CkKeygIE5VttdPf8rDMjk=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=CAgeLbdyZIRnSoSVH00Bi7yel0+0KrGkXiDJF1I8H6xmhSC8V1x4QfSbMhf+d/naxYbgWUHn/PYpuFaRe0MdYTedmGBH/BatwwG1FF8XHNSUVPC04kA0uzvBHYIaW6va9+/950aMgYSN93sRh4hF60QINL1GNAeRIwnkx2hqeLc= 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=EMaI0+iZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0b0mll/z; 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="EMaI0+iZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0b0mll/z" Date: Fri, 05 Jun 2026 21:25:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780694738; 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=c+kwfYF2RBWXnEZymvM7MuQxeYuhg/ktS1qDaKDfQYE=; b=EMaI0+iZZSNIk1Kd5rbvr2BWoOK/QXTdAxVyd6WxBE+6wn8Y842jGLBWUmL4QcnqOCwTZa bTkKwWfNOaNXBD0E83bfX3A/wgPszV0ysxXFi9jANs8thpitQR19QwxMbBI1yeBfkG21mc szUBeaCv17y59OOg8dsB7Xly3t0lnL/Nx9nfWgEP7JxagpjshK2O2dNezoRLPdDXkXz1Uu W0KZs3vX2kRrHI/69PM/KiNdJYlRb8zbukwoyeXAQcKSuO9nDGYF/UKZ7L1h6VM1O0P0PB XyInQ/Q/B5l1C+yCu2QJGuMpp8EU9+TVbIpwBOLtHPYHOEioMvG8I4nX0tSrhQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780694738; 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=c+kwfYF2RBWXnEZymvM7MuQxeYuhg/ktS1qDaKDfQYE=; b=0b0mll/zEJKuMe/zCPBPI9+giVrWUvbl78kLtyhv5gvRmhHpzZ1uIEZFw7MZ+t5h4pP2Nx ghX+eTMcrRq2tfAA== 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: Clarify try_init_module_global() result caching Cc: Chao Gao , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260520133909.409394-2-chao.gao@intel.com> References: <20260520133909.409394-2-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178069473666.710.6378657832704351220.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: 1ffa6a10253c417b281aff3cbd02bdf43b2b159d Gitweb: https://git.kernel.org/tip/1ffa6a10253c417b281aff3cbd02bdf43= b2b159d Author: Chao Gao AuthorDate: Wed, 20 May 2026 15:28:46 -07:00 Committer: Dave Hansen CommitterDate: Wed, 03 Jun 2026 08:14:39 -07:00 x86/virt/tdx: Clarify try_init_module_global() result caching TDX module global initialization is executed only once. The first call caches both the return code and the "done" state in static function variables. Later callers read the variables. A lock protects the saved state and serializes callers. These variables will soon be moved to a global structure. Prepare for that by treating the variables as a unit. Assign them together and limit accesses to while the lock is held. [ dhansen: mostly rewrite changelog ] Signed-off-by: Chao Gao Signed-off-by: Dave Hansen Link: https://patch.msgid.link/20260520133909.409394-2-chao.gao@intel.com --- arch/x86/virt/vmx/tdx/tdx.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index c0c6281..ad56f14 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -115,28 +115,34 @@ static int try_init_module_global(void) static DEFINE_RAW_SPINLOCK(sysinit_lock); static bool sysinit_done; static int sysinit_ret; + int ret; =20 raw_spin_lock(&sysinit_lock); =20 - if (sysinit_done) + /* Return the "cached" return code. */ + if (sysinit_done) { + ret =3D sysinit_ret; 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); + 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 (ret =3D=3D -ENODEV) pr_err("module not loaded\n"); =20 + /* Save the return code for later callers. */ sysinit_done =3D true; + sysinit_ret =3D ret; out: raw_spin_unlock(&sysinit_lock); - return sysinit_ret; + return ret; } =20 /**