From nobody Mon Jun 8 20:53:44 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 9BBFF366562; Tue, 26 May 2026 15:32:58 +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=1779809580; cv=none; b=UFJ1llW1WDqLD2kyLDzSzhweg9XHC4cIbWL6DB6QbirDlc5is4DcyM51ijg3WWvddLiN5hDglpd9LRbFimaGXaaQhUNgQCU4Z7z448070JkiaFCZ9mFSkf9/yUi2zLOQ5Krw9kTnP0IYAd+HEXBa9AO+lSX3sstfSP5R58uzH5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779809580; c=relaxed/simple; bh=tI/OI8utpo5sem8hOCp4m1dF1rNR76ru77GOdNrMu58=; h=Date:From:To:Subject:Cc:MIME-Version:Message-ID:Content-Type; b=SfZhWQhswCVtlHEE9Xpd16qs2h5SaawlYIchFF8Gm1K5vkWMfMHQLUrt9TnWbrNITi0lsC8+XRDt9UFVuBSC9OGYnc5WpFkHY+2mVRb/3nUszLcBwxTa8PZDGVCWKJGdGugq0J8ShUDSBVS51mhWnDfq21lvlnxxtFHfR0Jq+NA= 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=FYQHbEU6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZcovYVzE; 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="FYQHbEU6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZcovYVzE" Date: Tue, 26 May 2026 15:32:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779809577; 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; bh=UxFYNHRBsRoqvfchNYgSQ21QQB/c7pJinlI/U+mbpo4=; b=FYQHbEU65WvNBCg4e2/YJNrPZonm9C+TqZa+3TLGmrvv+r80ofGfm6zOdjwFc1+TrNRGMv 9LAENb9bgsID79Uo9hAjBsi/apnYLA1SOqp/5q3VFD6sNb3SoV53gvQrcgiapTSji/WEtI /YSI/H7DZ4dMDgDwGzuklIbngHg+sL+9J2CMubqznn9dO/YEHHTOF+kODsSIJA7GRU4o3x kIzpH3NCsrJvVQG8sH+GmmMYQ7VghemNUfR1qbc2Sq7k+4oMuoUn+CDl/3foBhrSIhlsyO 4lBwrJS7nuxPul9/sGFZxjHNrImImqb/6h1uy6bbt04a3TGg84KlmsJP/4raPA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779809577; 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; bh=UxFYNHRBsRoqvfchNYgSQ21QQB/c7pJinlI/U+mbpo4=; b=ZcovYVzE77LWELBoB+zYgKvsU5rHeVWxrmqNMBw/StqJCJ452mg6X8naE3uBh32SZjuAmJ hRY56VtNY85JoXCw== From: "tip-bot2 for Dave Hansen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] coco/tdx-host: Lock out module updates when reading version Cc: Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177980957567.1039918.3806538112493257716.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: 9d84a61321b76f393ad06919065ca5fd11d433aa Gitweb: https://git.kernel.org/tip/9d84a61321b76f393ad06919065ca5fd1= 1d433aa Author: Dave Hansen AuthorDate: Fri, 22 May 2026 08:56:29 -07:00 Committer: Dave Hansen CommitterDate: Tue, 26 May 2026 08:29:15 -07:00 coco/tdx-host: Lock out module updates when reading version The TDX module version is currently stashed in some global variables and dumped out to sysfs without locking. This works fine when the version is static and never changes. But with runtime module updates, the TDX module version can change. Some kind of locking is needed. Barring this, userspace could theoretically see a strange torn module version that is some Frankenstein version from from two different updates. Use the new module update lock/unlock to prevent updates while trying to read the version. Don't be fussy about it. There's no need to snapshot the version or do READ_ONCE(), or minimize lock holding times. sysfs_emit() does not sleep. Also note that the lock/unlock are backed by preempt_dis/enable() which are really cheap CPU-local operations. This is not a heavyweight lock. Signed-off-by: Dave Hansen --- drivers/virt/coco/tdx-host/tdx-host.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-= host/tdx-host.c index e5a672b..d489529 100644 --- a/drivers/virt/coco/tdx-host/tdx-host.c +++ b/drivers/virt/coco/tdx-host/tdx-host.c @@ -26,15 +26,24 @@ static ssize_t version_show(struct device *dev, struct = device_attribute *attr, { const struct tdx_sys_info *tdx_sysinfo =3D tdx_get_sysinfo(); const struct tdx_sys_info_version *ver; + int ret; =20 if (!tdx_sysinfo) return -ENXIO; =20 + /* + * The version number can change during an update. + * Lock out updates while printing the version. + */ + seamldr_lock_module_update(); + ver =3D &tdx_sysinfo->version; + ret =3D sysfs_emit(buf, TDX_VERSION_FMT "\n", ver->major_version, + ver->minor_version, + ver->update_version); + seamldr_unlock_module_update(); =20 - return sysfs_emit(buf, TDX_VERSION_FMT "\n", ver->major_version, - ver->minor_version, - ver->update_version); + return ret; } static DEVICE_ATTR_RO(version); =20