Skip to content

Commit 78d375a

Browse files
thule-vincenzogregkh
authored andcommitted
powerpc: Fix vDSO clock_getres()
[ Upstream commit 5522634 ] clock_getres in the vDSO library has to preserve the same behaviour of posix_get_hrtimer_res(). In particular, posix_get_hrtimer_res() does: sec = 0; ns = hrtimer_resolution; and hrtimer_resolution depends on the enablement of the high resolution timers that can happen either at compile or at run time. Fix the powerpc vdso implementation of clock_getres keeping a copy of hrtimer_resolution in vdso data and using that directly. Fixes: a7f290d ("[PATCH] powerpc: Merge vdso's and add vdso support to 32 bits kernel") Cc: stable@vger.kernel.org Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com> Reviewed-by: Christophe Leroy <christophe.leroy@c-s.fr> Acked-by: Shuah Khan <skhan@linuxfoundation.org> [chleroy: changed CLOCK_REALTIME_RES to CLOCK_HRTIMER_RES] Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/a55eca3a5e85233838c2349783bcb5164dae1d09.1575273217.git.christophe.leroy@c-s.fr Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 002d1ca commit 78d375a

5 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎arch/powerpc/include/asm/vdso_datapage.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct vdso_data {
8282
__s32 wtom_clock_nsec; /* Wall to monotonic clock nsec */
8383
__s64 wtom_clock_sec; /* Wall to monotonic clock sec */
8484
struct timespec stamp_xtime; /* xtime as at tb_orig_stamp */
85+
__u32 hrtimer_res; /* hrtimer resolution */
8586
__u32 syscall_map_64[SYSCALL_MAP_SIZE]; /* map of syscalls */
8687
__u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */
8788
};
@@ -103,6 +104,7 @@ struct vdso_data {
103104
__s32 wtom_clock_nsec;
104105
struct timespec stamp_xtime; /* xtime as at tb_orig_stamp */
105106
__u32 stamp_sec_fraction; /* fractional seconds of stamp_xtime */
107+
__u32 hrtimer_res; /* hrtimer resolution */
106108
__u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */
107109
__u32 dcache_block_size; /* L1 d-cache block size */
108110
__u32 icache_block_size; /* L1 i-cache block size */

‎arch/powerpc/kernel/asm-offsets.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ int main(void)
387387
OFFSET(WTOM_CLOCK_NSEC, vdso_data, wtom_clock_nsec);
388388
OFFSET(STAMP_XTIME, vdso_data, stamp_xtime);
389389
OFFSET(STAMP_SEC_FRAC, vdso_data, stamp_sec_fraction);
390+
OFFSET(CLOCK_HRTIMER_RES, vdso_data, hrtimer_res);
390391
OFFSET(CFG_ICACHE_BLOCKSZ, vdso_data, icache_block_size);
391392
OFFSET(CFG_DCACHE_BLOCKSZ, vdso_data, dcache_block_size);
392393
OFFSET(CFG_ICACHE_LOGBLOCKSZ, vdso_data, icache_log_block_size);
@@ -417,7 +418,6 @@ int main(void)
417418
DEFINE(CLOCK_REALTIME_COARSE, CLOCK_REALTIME_COARSE);
418419
DEFINE(CLOCK_MONOTONIC_COARSE, CLOCK_MONOTONIC_COARSE);
419420
DEFINE(NSEC_PER_SEC, NSEC_PER_SEC);
420-
DEFINE(CLOCK_REALTIME_RES, MONOTONIC_RES_NSEC);
421421

422422
#ifdef CONFIG_BUG
423423
DEFINE(BUG_ENTRY_SIZE, sizeof(struct bug_entry));

‎arch/powerpc/kernel/time.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ void update_vsyscall(struct timekeeper *tk)
959959
vdso_data->wtom_clock_nsec = tk->wall_to_monotonic.tv_nsec;
960960
vdso_data->stamp_xtime = xt;
961961
vdso_data->stamp_sec_fraction = frac_sec;
962+
vdso_data->hrtimer_res = hrtimer_resolution;
962963
smp_wmb();
963964
++(vdso_data->tb_update_count);
964965
}

‎arch/powerpc/kernel/vdso32/gettimeofday.S‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,15 @@ V_FUNCTION_BEGIN(__kernel_clock_getres)
156156
cror cr0*4+eq,cr0*4+eq,cr1*4+eq
157157
bne cr0,99f
158158

159+
mflr r12
160+
.cfi_register lr,r12
161+
bl __get_datapage@local /* get data page */
162+
lwz r5, CLOCK_HRTIMER_RES(r3)
163+
mtlr r12
159164
li r3,0
160165
cmpli cr0,r4,0
161166
crclr cr0*4+so
162167
beqlr
163-
lis r5,CLOCK_REALTIME_RES@h
164-
ori r5,r5,CLOCK_REALTIME_RES@l
165168
stw r3,TSPC32_TV_SEC(r4)
166169
stw r5,TSPC32_TV_NSEC(r4)
167170
blr

‎arch/powerpc/kernel/vdso64/gettimeofday.S‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,15 @@ V_FUNCTION_BEGIN(__kernel_clock_getres)
186186
cror cr0*4+eq,cr0*4+eq,cr1*4+eq
187187
bne cr0,99f
188188

189+
mflr r12
190+
.cfi_register lr,r12
191+
bl V_LOCAL_FUNC(__get_datapage)
192+
lwz r5, CLOCK_HRTIMER_RES(r3)
193+
mtlr r12
189194
li r3,0
190195
cmpldi cr0,r4,0
191196
crclr cr0*4+so
192197
beqlr
193-
lis r5,CLOCK_REALTIME_RES@h
194-
ori r5,r5,CLOCK_REALTIME_RES@l
195198
std r3,TSPC64_TV_SEC(r4)
196199
std r5,TSPC64_TV_NSEC(r4)
197200
blr

0 commit comments

Comments
 (0)