Skip to content

Commit 4c5a116

Browse files
committed
vdso/treewide: Add vdso_data pointer argument to __arch_get_hw_counter()
MIPS already uses and S390 will need the vdso data pointer in __arch_get_hw_counter(). This works nicely as long as the architecture does not support time namespaces in the VDSO. With time namespaces enabled the regular accessor to the vdso data pointer __arch_get_vdso_data() will return the namespace specific VDSO data page for tasks which are part of a non-root time namespace. This would cause the architectures which need the vdso data pointer in __arch_get_hw_counter() to access the wrong vdso data page. Add a vdso_data pointer argument to __arch_get_hw_counter() and hand it in from the call sites in the core code. For architectures which do not need the data pointer in their counter accessor function the compiler will just optimize it out. Fix up all existing architecture implementations and make MIPS utilize the pointer instead of invoking the accessor function. No functional change and no change in the resulting object code (except MIPS). Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 2324d50 commit 4c5a116

File tree

7 files changed

+15
-9
lines changed

7 files changed

+15
-9
lines changed

arch/arm/include/asm/vdso/gettimeofday.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ static inline bool arm_vdso_hres_capable(void)
113113
}
114114
#define __arch_vdso_hres_capable arm_vdso_hres_capable
115115

116-
static __always_inline u64 __arch_get_hw_counter(int clock_mode)
116+
static __always_inline u64 __arch_get_hw_counter(int clock_mode,
117+
const struct vdso_data *vd)
117118
{
118119
#ifdef CONFIG_ARM_ARCH_TIMER
119120
u64 cycle_now;

arch/arm64/include/asm/vdso/compat_gettimeofday.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ int clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
103103
return ret;
104104
}
105105

106-
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode)
106+
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
107+
const struct vdso_data *vd)
107108
{
108109
u64 res;
109110

arch/arm64/include/asm/vdso/gettimeofday.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
6464
return ret;
6565
}
6666

67-
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode)
67+
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
68+
const struct vdso_data *vd)
6869
{
6970
u64 res;
7071

arch/mips/include/asm/vdso/gettimeofday.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,16 @@ static __always_inline u64 read_gic_count(const struct vdso_data *data)
167167

168168
#endif
169169

170-
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode)
170+
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
171+
const struct vdso_data *vd)
171172
{
172173
#ifdef CONFIG_CSRC_R4K
173174
if (clock_mode == VDSO_CLOCKMODE_R4K)
174175
return read_r4k_count();
175176
#endif
176177
#ifdef CONFIG_CLKSRC_MIPS_GIC
177178
if (clock_mode == VDSO_CLOCKMODE_GIC)
178-
return read_gic_count(get_vdso_data());
179+
return read_gic_count(vd);
179180
#endif
180181
/*
181182
* Core checks mode already. So this raced against a concurrent

arch/riscv/include/asm/vdso/gettimeofday.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
6060
return ret;
6161
}
6262

63-
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode)
63+
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
64+
const struct vdso_data *vd)
6465
{
6566
/*
6667
* The purpose of csr_read(CSR_TIME) is to trap the system into

arch/x86/include/asm/vdso/gettimeofday.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ static u64 vread_hvclock(void)
241241
}
242242
#endif
243243

244-
static inline u64 __arch_get_hw_counter(s32 clock_mode)
244+
static inline u64 __arch_get_hw_counter(s32 clock_mode,
245+
const struct vdso_data *vd)
245246
{
246247
if (likely(clock_mode == VDSO_CLOCKMODE_TSC))
247248
return (u64)rdtsc_ordered();

lib/vdso/gettimeofday.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int do_hres_timens(const struct vdso_data *vdns, clockid_t clk,
6868
if (unlikely(!vdso_clocksource_ok(vd)))
6969
return -1;
7070

71-
cycles = __arch_get_hw_counter(vd->clock_mode);
71+
cycles = __arch_get_hw_counter(vd->clock_mode, vd);
7272
if (unlikely(!vdso_cycles_ok(cycles)))
7373
return -1;
7474
ns = vdso_ts->nsec;
@@ -138,7 +138,7 @@ static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk,
138138
if (unlikely(!vdso_clocksource_ok(vd)))
139139
return -1;
140140

141-
cycles = __arch_get_hw_counter(vd->clock_mode);
141+
cycles = __arch_get_hw_counter(vd->clock_mode, vd);
142142
if (unlikely(!vdso_cycles_ok(cycles)))
143143
return -1;
144144
ns = vdso_ts->nsec;

0 commit comments

Comments
 (0)