From: Thomas Gleixner <tglx@kernel.org>
To: "Zhan Xusheng" <zhanxusheng1024@gmail.com>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Cc: Yury Norov <yury.norov@gmail.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Andy Lutomirski <luto@kernel.org>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
David Laight <david.laight.linux@gmail.com>,
linux-kernel@vger.kernel.org,
Zhan Xusheng <zhanxusheng@xiaomi.com>,
kernel test robot <lkp@intel.com>
Subject: Re: [PATCH v7 5/5] vdso/gettimeofday: Assert that the clockid fits into the u32 bitmask
Date: Thu, 15 Oct 2026 15:54:24 +0200 [thread overview]
Message-ID: <87ik33dq7j.ffs@fw13> (raw)
In-Reply-To: <20261002153104.1347978-6-zhanxusheng@xiaomi.com>
On Fri, Oct 02 2026 at 23:31, Zhan Xusheng wrote:
> __cvdso_clock_gettime_common() and __cvdso_clock_getres_common() convert
> the clockid into a bitmask and match it against VDSO_HRES, VDSO_COARSE,
> VDSO_RAW and VDSO_AUX:
>
> msk = 1U << clock;
>
> vdso_clockid_valid() rejects anything above CLOCK_AUX_LAST beforehand,
> and CLOCK_AUX_LAST is 23, so the shift count is in range. Nothing
> records that dependency though. Raising MAX_AUX_CLOCKS beyond 16 moves
> CLOCK_AUX_LAST to 32 and makes the shift undefined.
>
> Add a BUILD_BUG_ON() at both conversion sites. The condition is on a
> function parameter rather than a constant, so it relies on the compiler
> deriving the range from the vdso_clockid_valid() bail-out above it. gcc
> 13 and clang 18 both do: the x86 vdso64 and vdso32 builds stay clean, and
> raising MAX_AUX_CLOCKS to 17 trips the assert.
But using 'clock' for the assert is fragile as it relies on the compiler
to defer the maximum 'clock' value from vdso_clockid_valid().
Checking for CLOCK_AUX_LAST >= BITS_PER_TYPE() should be sufficient, no?
> diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
> index f7a591aba59f..ef4dcc614489 100644
> --- a/lib/vdso/gettimeofday.c
> +++ b/lib/vdso/gettimeofday.c
> @@ -285,6 +285,7 @@ __cvdso_clock_gettime_common(const struct vdso_time_data *vd, clockid_t clock,
> * Convert the clockid to a bitmask and use it to check which
> * clocks are handled in the VDSO directly.
> */
> + BUILD_BUG_ON(clock >= BITS_PER_TYPE(msk));
> msk = 1U << clock;
> if (likely(msk & VDSO_HRES))
> vc = &vc[CS_HRES_COARSE];
> @@ -438,6 +439,7 @@ bool __cvdso_clock_getres_common(const struct vdso_time_data *vd, clockid_t cloc
> * Convert the clockid to a bitmask and use it to check which
> * clocks are handled in the VDSO directly.
> */
> + BUILD_BUG_ON(clock >= BITS_PER_TYPE(msk));
> msk = 1U << clock;
> if (msk & (VDSO_HRES | VDSO_RAW)) {
> /*
Aside of that why do we need the same BUILD_BUG_ON() in two functions?
Thanks,
tglx
prev parent reply other threads:[~2026-10-15 13:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 15:30 [PATCH v7 0/5] vdso: Keep the CLOCK_AUX base at full precision Zhan Xusheng
2026-10-02 15:30 ` [PATCH v7 1/5] vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem() Zhan Xusheng
2026-10-15 15:37 ` [tip: timers/vdso] " tip-bot2 for Zhan Xusheng
2026-10-02 15:31 ` [PATCH v7 2/5] vdso/math64: Add and use __iter_div64_u64_rem() Zhan Xusheng
2026-10-15 15:37 ` [tip: timers/vdso] " tip-bot2 for Zhan Xusheng
2026-10-02 15:31 ` [PATCH v7 3/5] vdso/vsyscall: Keep the CLOCK_AUX base scaled Zhan Xusheng
2026-10-15 15:37 ` [tip: timers/vdso] " tip-bot2 for Zhan Xusheng
2026-10-02 15:31 ` [PATCH v7 4/5] vdso: Move BITS_PER_BYTE and BITS_PER_TYPE() to vdso/bits.h Zhan Xusheng
2026-10-02 15:31 ` [PATCH v7 5/5] vdso/gettimeofday: Assert that the clockid fits into the u32 bitmask Zhan Xusheng
2026-10-15 13:54 ` Thomas Gleixner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ik33dq7j.ffs@fw13 \
--to=tglx@kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=lkp@intel.com \
--cc=luto@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--cc=yury.norov@gmail.com \
--cc=zhanxusheng1024@gmail.com \
--cc=zhanxusheng@xiaomi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®