Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795026925; b=pmvHZoTuzZOTH1PFEmllsXQhXDNP7TtFYJQeilS2JMuicI5fzZfb1QVFSEl1RP2wSQDt 1pcbt426mqjULRXjD290DDGIz6tVyvpgrhYH2NbaylgCHP8kflqRDFwyyVY288l9BuoIk 1Z/46BmQXwEoy30SYMwi1CzP7v5J2TffFXLg72b6ZvYOF7NeTglb1OZzPAnfT+M8Gf/ZY syQI9h9lhIlNSryV6Tnh7DQn9mSd1OWwEhz6KQzBpl+EKvlFfL8qA3nJCFmy66ULMFyET EolpGBQzGuuxQOxIitdTAfTToTyzXR9wRmLFWdrgshAzSq1QU4GQxm0IelgKMIaKvFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795026925; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=2Pdt2dnEyyIK+cYv8YKii9LA6TkxN+37+8YhlnDtBvs=; b=YR/+LO5gtm2XMpP5Qf9scW4GhXwGmnYoDYK11r+OfSXVm8tr6UcCUQ081EWqFTlDHcK/ o77y1IN6S3EdUoqck0/2yg5YDMPSaRE6+HlH8S2+sghR9v36IlvY39meKuSghEoLlTARL 9Nt+H5ZZXiR2AMq4RObngs8xiYFLPNq4ZnimRjK7SZhpZBl9Tjpg8UqoWZHVo1usrASvu AE+6fSU3y51Hu3K8UkPgp2uvxOjhS7374XA8o5DJbslwvWQk73zYsCcqn6z6LFesUT6oG ZPrua1pxVmkXJ7YDvKc6wN5CHAeLKx3ZZ+ll8GpjlzKGh6dYC6P9U0V2WtMQCzuSnCg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uOhA7NjM; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F138D606A331; Wed, 18 Nov 2026 18:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uOhA7NjM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C6161F000C4; Wed, 18 Nov 2026 18:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795026924; bh=2Pdt2dnEyyIK+cYv8YKii9LA6TkxN+37+8YhlnDtBvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uOhA7NjMk2ycgGVXvM9j7VsyYpCdB/CEGFlT3pMHfkY9fxkl161J+oPB5AUk36bdw TkiULX9uB5iHo6RETNTxcPutLlWUnoMsy6r9Ju0ALcDT/2m8+fNHSr64jvqGe1AuGG iMpMz9N7W73Xe7LoFeoTyxgBDRPBjpySnFNjr7LU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhan Xusheng , Thomas Gleixner , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Sasha Levin Subject: [PATCH 6.18 1609/2151] vdso/vsyscall: Keep the CLOCK_AUX base scaled Date: Wed, 18 Nov 2026 15:55:44 +0100 Message-ID: <20261118150220.484490829@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhan Xusheng [ Upstream commit 8d17190fae2caab89cd5df19257ed9dac0739e3b ] The vDSO basetime of a clock is stored in the scaled nanoseconds of tkr_mono, so that the reader can floor the base and the cycle delta together in vdso_calc_ns(). vdso_time_update_aux() instead shifts the base down to nanoseconds, adds the offset, and shifts it back up, which zeroes the fractional nanoseconds of xtime_nsec. The reader then floors the base and the delta separately: ktime_get_aux(): base + ((delta * mult + xtime_nsec) >> shift) vdso: base + (xtime_nsec >> shift) + ((delta * mult) >> shift) Since floor(a) + floor(b) <= floor(a + b), the vDSO reports 0 or 1 ns below the syscall for the same clock. It is not a monotonicity problem: across an update the step is floor(a + d) - floor(a) - floor(d), which is 0 or 1, never negative. Add the offset in scaled nanoseconds as the other high resolution clocks do, and normalise with __iter_div64_u64_rem() so that the stored base stays below one second and the userspace fast-path does not iterate more in __iter_div_u64_rem(). Only the sub-second field changes. (a + (b << shift)) >> shift is exactly (a >> shift) + b, so the seconds carried out of the normalisation are the same as before; what the old form dropped was the low shift bits of the remainder. monotonic_to_aux.tv_nsec is a normalised timespec64 fraction, so it stays below NSEC_PER_SEC even for a negative offset, and the sum stays below 2 * (NSEC_PER_SEC << shift). The largest shift clocks_calc_mult_shift() can pick is 32, which makes that 8.6e18 against a u64 limit of 1.8e19. Fixes: 380b84e168e5 ("vdso/vsyscall: Update auxiliary clock data in the datapage") Signed-off-by: Zhan Xusheng Signed-off-by: Thomas Gleixner Reviewed-by: Thomas Weißschuh Link: https://patch.msgid.link/20261002153104.1347978-4-zhanxusheng@xiaomi.com Signed-off-by: Sasha Levin --- kernel/time/vsyscall.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/time/vsyscall.c b/kernel/time/vsyscall.c index f43dd3f4744b5..0e4b499328c08 100644 --- a/kernel/time/vsyscall.c +++ b/kernel/time/vsyscall.c @@ -155,11 +155,11 @@ void vdso_time_update_aux(struct timekeeper *tk) vdso_ts->sec = tk->xtime_sec + tk->monotonic_to_aux.tv_sec; - nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift; - nsec += tk->monotonic_to_aux.tv_nsec; - vdso_ts->sec += __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec); - nsec = nsec << tk->tkr_mono.shift; - vdso_ts->nsec = nsec; + nsec = tk->tkr_mono.xtime_nsec; + nsec += (u64)tk->monotonic_to_aux.tv_nsec << tk->tkr_mono.shift; + vdso_ts->sec += __iter_div64_u64_rem(nsec, + (u64)NSEC_PER_SEC << tk->tkr_mono.shift, + &vdso_ts->nsec); } __arch_update_vdso_clock(vc); -- 2.53.0