From nobody Thu Apr 9 02:36:46 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 6306C3D88F1; Wed, 11 Mar 2026 09:31: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=1773221496; cv=none; b=SqQ2NSKjredEoMOd4IeCErdXCdgGoVvnJzqe/5tLT+hoADk9MisPWmAl4x9w0iHUx9B1z8zRloTDE6iDdieUeUwVxqU3nyTtMJLkTkJboV0kZh7IZRkEbvgwFun6sRrSFvyCZR7olj3QoNgNNqvz/YOdBeBuOT+egN0KXzyuNgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773221496; c=relaxed/simple; bh=N7BoiOTMIVGnxnu/TTCbiPxYa2NCl2+mWkntF/b/t5g=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=SPcLqBLhox44cAVEZchWlugvtpxSJVqK0Ouc45dgKPoQFhF9pKUvGBdJ9m4jCbIslTUC6JvczP13ssdfoBxBvbB03MLBMaxxEA6aRo+wbebGzavXnNFxOQGnljZpVUx95WK+F6Re/oAVhb2AMgfTbrhGFPL5jTajCsDO+4niEMc= 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=yCHwRTG4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cKvHPMDi; 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="yCHwRTG4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cKvHPMDi" Date: Wed, 11 Mar 2026 09:31:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1773221493; 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=+QjVaEAYt/9qlQfuKXauIB6emycZQPp0HOS4Af5e9qc=; b=yCHwRTG4M9wlERyju4T/eUNt46mcQ95n6p8gwsGKkdc/fyHK40dUsBuTLcH8hnfTOLMvku OKEcxkltKWbKFDnjG292yeybxT6M3bXniugtKY6TVaJtAyJofJTJXJ+4qtkR7eBAWV5MCg mnmTNn/Gv11luI9edqsBIr8eDfd2uvxnWg+/bQOkyx6K0bCX72tZhSwnosmm8OQIearCvq +UPcJzQ399fS0fN7b6gjI1zNDQ4W8rqibKMV/r2iCO2RtXR9n69jo/BoQOAIQMnLqfNJ21 PbBZEKKWTQEYnrIEsqVa2t6ILFfZv5gZ7riwXarO/3xyG4slWh5uqeY5kC/PAQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1773221493; 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=+QjVaEAYt/9qlQfuKXauIB6emycZQPp0HOS4Af5e9qc=; b=cKvHPMDi4wyfR5OCqoOMzIHdWcHq2PemO89KnWgRFQCqEz04XwCv+2JNLYRP7sXYkpQRCL eDKRrhDfPLr1LaCA== From: tip-bot2 for Thomas =?utf-8?q?Wei=C3=9Fschuh?= Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/vdso] vdso/gettimeofday: Add a helper to read the sequence lock of a time namespace aware clock Cc: thomas.weissschuh@linutronix.de, Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260227-vdso-cleanups-v1-2-c848b4bc4850@linutronix.de> References: <20260227-vdso-cleanups-v1-2-c848b4bc4850@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177322149203.1647592.897862694314603946.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 timers/vdso branch of tip: Commit-ID: ed78b7b2c5ae679960469c0f679539c427e051ab Gitweb: https://git.kernel.org/tip/ed78b7b2c5ae679960469c0f679539c42= 7e051ab Author: Thomas Wei=C3=9Fschuh AuthorDate: Fri, 27 Feb 2026 07:43:21 +01:00 Committer: Thomas Gleixner CommitterDate: Wed, 11 Mar 2026 10:27:35 +01:00 vdso/gettimeofday: Add a helper to read the sequence lock of a time namespa= ce aware clock Currently there are three different open-coded variants of a time namespace aware variant of vdso_read_begin(). They make the code hard to read and introduce an inconsistency, as only the first copy uses unlikely(). Split the code into a shared helper function. Move that next to the definition of the regular vdso_read_begin(), so that any future changes can be kept in sync easily. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/20260227-vdso-cleanups-v1-2-c848b4bc4850@lin= utronix.de --- include/vdso/helpers.h | 22 +++++++++++++++++- lib/vdso/gettimeofday.c | 51 +++++++--------------------------------- 2 files changed, 31 insertions(+), 42 deletions(-) diff --git a/include/vdso/helpers.h b/include/vdso/helpers.h index 1a5ee9d..9ccf6b5 100644 --- a/include/vdso/helpers.h +++ b/include/vdso/helpers.h @@ -18,6 +18,28 @@ static __always_inline u32 vdso_read_begin(const struct = vdso_clock *vc) return seq; } =20 +/* + * Variant of vdso_read_begin() to handle VDSO_CLOCKMODE_TIMENS. + * + * Time namespace enabled tasks have a special VVAR page installed which h= as + * vc->seq set to 1 and vc->clock_mode set to VDSO_CLOCKMODE_TIMENS. For n= on + * time namespace affected tasks this does not affect performance because = if + * vc->seq is odd, i.e. a concurrent update is in progress the extra check= for + * vc->clock_mode is just a few extra instructions while spin waiting for + * vc->seq to become even again. + */ +static __always_inline bool vdso_read_begin_timens(const struct vdso_clock= *vc, u32 *seq) +{ + while (unlikely((*seq =3D READ_ONCE(vc->seq)) & 1)) { + if (IS_ENABLED(CONFIG_TIME_NS) && vc->clock_mode =3D=3D VDSO_CLOCKMODE_T= IMENS) + return true; + cpu_relax(); + } + smp_rmb(); + + return false; +} + static __always_inline u32 vdso_read_retry(const struct vdso_clock *vc, u32 start) { diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index 4939ee8..e493696 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -158,24 +158,8 @@ bool do_hres(const struct vdso_time_data *vd, const st= ruct vdso_clock *vc, return false; =20 do { - /* - * Open coded function vdso_read_begin() to handle - * VDSO_CLOCKMODE_TIMENS. Time namespace enabled tasks have a - * special VVAR page installed which has vc->seq set to 1 and - * vc->clock_mode set to VDSO_CLOCKMODE_TIMENS. For non time - * namespace affected tasks this does not affect performance - * because if vc->seq is odd, i.e. a concurrent update is in - * progress the extra check for vc->clock_mode is just a few - * extra instructions while spin waiting for vc->seq to become - * even again. - */ - while (unlikely((seq =3D READ_ONCE(vc->seq)) & 1)) { - if (IS_ENABLED(CONFIG_TIME_NS) && - vc->clock_mode =3D=3D VDSO_CLOCKMODE_TIMENS) - return do_hres_timens(vd, vc, clk, ts); - cpu_relax(); - } - smp_rmb(); + if (vdso_read_begin_timens(vc, &seq)) + return do_hres_timens(vd, vc, clk, ts); =20 if (!vdso_get_timestamp(vd, vc, clk, &sec, &ns)) return false; @@ -223,17 +207,8 @@ bool do_coarse(const struct vdso_time_data *vd, const = struct vdso_clock *vc, u32 seq; =20 do { - /* - * Open coded function vdso_read_begin() to handle - * VDSO_CLOCK_TIMENS. See comment in do_hres(). - */ - while ((seq =3D READ_ONCE(vc->seq)) & 1) { - if (IS_ENABLED(CONFIG_TIME_NS) && - vc->clock_mode =3D=3D VDSO_CLOCKMODE_TIMENS) - return do_coarse_timens(vd, vc, clk, ts); - cpu_relax(); - } - smp_rmb(); + if (vdso_read_begin_timens(vc, &seq)) + return do_coarse_timens(vd, vc, clk, ts); =20 ts->tv_sec =3D vdso_ts->sec; ts->tv_nsec =3D vdso_ts->nsec; @@ -256,20 +231,12 @@ bool do_aux(const struct vdso_time_data *vd, clockid_= t clock, struct __kernel_ti vc =3D &vd->aux_clock_data[idx]; =20 do { - /* - * Open coded function vdso_read_begin() to handle - * VDSO_CLOCK_TIMENS. See comment in do_hres(). - */ - while ((seq =3D READ_ONCE(vc->seq)) & 1) { - if (IS_ENABLED(CONFIG_TIME_NS) && vc->clock_mode =3D=3D VDSO_CLOCKMODE_= TIMENS) { - vd =3D __arch_get_vdso_u_timens_data(vd); - vc =3D &vd->aux_clock_data[idx]; - /* Re-read from the real time data page */ - continue; - } - cpu_relax(); + if (vdso_read_begin_timens(vc, &seq)) { + vd =3D __arch_get_vdso_u_timens_data(vd); + vc =3D &vd->aux_clock_data[idx]; + /* Re-read from the real time data page */ + continue; } - smp_rmb(); =20 /* Auxclock disabled? */ if (vc->clock_mode =3D=3D VDSO_CLOCKMODE_NONE)