[tip: timers/vdso] vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem()
From: tip-bot2 for Zhan Xusheng
Date: Tue Sep 29 2026 - 15:28:38 EST
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 37db375ad90467d7e3ce4e450b3d1c4f297d4ed3
Gitweb: https://git.kernel.org/tip/37db375ad90467d7e3ce4e450b3d1c4f297d4ed3
Author: Zhan Xusheng <zhanxusheng1024@xxxxxxxxx>
AuthorDate: Wed, 16 Sep 2026 10:32:49 +08:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Tue, 29 Sep 2026 21:23:30 +02:00
vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem()
__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>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Reviewed-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
Link: https://patch.msgid.link/20260916023252.418473-2-zhanxusheng@xxxxxxxxxx
---
include/vdso/math64.h | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/vdso/math64.h b/include/vdso/math64.h
index 22ae212..c628d6c 100644
--- a/include/vdso/math64.h
+++ b/include/vdso/math64.h
@@ -2,15 +2,16 @@
#ifndef __VDSO_MATH64_H
#define __VDSO_MATH64_H
-static __always_inline u32
-__iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
+static __always_inline u32 __iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
{
u32 ret = 0;
while (dividend >= divisor) {
- /* The following asm() prevents the compiler from
- optimising this loop into a modulo operation. */
- asm("" : "+rm"(dividend));
+ /*
+ * Prevent the compiler from optimising this loop into a
+ * modulo operation.
+ */
+ OPTIMIZER_HIDE_VAR(dividend);
dividend -= divisor;
ret++;