Re: [PATCH v5 1/4] vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem()

From: Thomas Weißschuh

Date: Fri Sep 25 2026 - 03:49:57 EST


On Wed, Sep 16, 2026 at 10:32:49AM +0800, Zhan Xusheng wrote:
> __iter_div_u64_rem() divides by repeated subtraction, because its callers
> only ever produce a small quotient. A barrier inside the subtraction loop
> keeps the compiler from replacing the loop with a division:
>
> asm("" : "+rm"(dividend));
>
> The "rm" constraint permits a memory operand. clang picks it and spills
> the dividend inside the loop, at 32-bit and 64-bit alike. The helper sits
> on the clock_gettime() fast path through vdso_set_timespec(), so the spill
> is not free: with clang 18 the x86 vDSO is 64 bytes larger in vdso64 text
> and 112 bytes larger in vdso32 text than with a register-only barrier.
>
> Use OPTIMIZER_HIDE_VAR(), which is the register-only form of the same
> barrier and the form the rest of the kernel uses. gcc 13 generates
> identical code either way, and neither compiler turns the loop into a
> division at either width.
>
> Put the function signature on one line while touching it, and reformat the
> comment, which described the asm() that is now gone.
>
> Signed-off-by: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>

Reviewed-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>

> ---
> include/vdso/math64.h | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)

(...)