From nobody Sun May 24 19:34:22 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 CE1C4372070; Fri, 22 May 2026 17:26:37 +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=1779470799; cv=none; b=TTjhaQAZHcWoYV5wt10ksc78PCNeHBucXEzFbHFEmSIpf0BPrGeMPIVB9u+8JKjaPVppnVnfcWOCBcvfhAfq/J1L5PU6uCZcbY6mmeIkW03NrnT+nsni6zEmb/2qGOHRrNvHMa+MrnryurKHtjhW3yg60D2CRHdGokrR+LOPK3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779470799; c=relaxed/simple; bh=Qub6mZoyH6IFap0hf9bbdxxgfKj/ckbwpf5tDajXFg0=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=SVTekBiqD/N8MgN4RPSjX2OZWA6boQVeGfcABS7FsUcyIC56JmVSLiyMTJPVcNvmU4JMWw/rrenE/BeJoIkqsSAkwhtITpetQyBfgEE7AoIgK/KimMoH0opYWIsVKWgGebGZJTP4EahDBnU31fAunaUOpaFRo3AvpIuyrWzGGH4= 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=BzlSkxaQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=nwrhkx8O; 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="BzlSkxaQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nwrhkx8O" Date: Fri, 22 May 2026 17:26:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779470796; 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=8LXdT7sUKuECSnxAeT/qSvwLL5bzDGeD7cJxGLkxLJ0=; b=BzlSkxaQg1GbMh8yKCk5TyMBHDQvb2qiwTRQY/d7J5KLyiAfueEBMRkgcb2bfBUnJpMJ0t pmMC0S+XIYVIvJame6ksxru1bn0ZPJ11+bUbp8kvHEB2t4h0iMJB8lZtIEeSsZrOtRmeZw TY2cHrMjEOpY0l1fqNbpY8es6BtC6HkcQ5OL/dBPj2nFE5K/TlGs2L5J5zYVBS7zUZALHk 9i9GC4RUmFVClt4U+WOm1uz/kERtpvvxSZIzyR4Ic1q2EFqtHOsUuO9slaGGekuyY0GqU1 CI0sjavPN8OG56XRD2Lu88yDMsSPGBbFf16lVKcVbOlIVswr0tUSOHGyV0rU5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779470796; 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=8LXdT7sUKuECSnxAeT/qSvwLL5bzDGeD7cJxGLkxLJ0=; b=nwrhkx8O4+bDeaX1NABli3tU9QC+a9/o1IYRdTpu8FbGaeNk/XN1b0tpV18WpS42Ra8oYC 7Hl46kMSFAw508CA== 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: <20260520222846.2F2E0B02@davehans-spike.ostc.intel.com> References: <20260520222846.2F2E0B02@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: <177947079514.711.7445560628725890961.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: 394d7f52d8449099af57aed156ccc3cec446ce03 Gitweb: https://git.kernel.org/tip/394d7f52d8449099af57aed156ccc3cec= 446ce03 Author: Chao Gao AuthorDate: Wed, 20 May 2026 15:28:46 -07:00 Committer: Dave Hansen CommitterDate: Wed, 20 May 2026 15:37:08 -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 Link: https://patch.msgid.link/20260520222846.2F2E0B02@davehans-spike.ostc.= 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 /**