Skip to content

Commit 25bc6e8

Browse files
amlutogregkh
authored andcommitted
x86/vdso: Fix vDSO syscall fallback asm constraint regression
commit 02e4256 upstream. When I added the missing memory outputs, I failed to update the index of the first argument (ebx) on 32-bit builds, which broke the fallbacks. Somehow I must have screwed up my testing or gotten lucky. Add another test to cover gettimeofday() as well. Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: stable@vger.kernel.org Fixes: 715bd9d ("x86/vdso: Fix asm constraints on vDSO syscall fallbacks") Link: http://lkml.kernel.org/r/21bd45ab04b6d838278fa5bebfa9163eceffa13c.1538608971.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1194e83 commit 25bc6e8

2 files changed

Lines changed: 77 additions & 4 deletions

File tree

arch/x86/entry/vdso/vclock_gettime.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
6868

6969
asm (
7070
"mov %%ebx, %%edx \n"
71-
"mov %2, %%ebx \n"
71+
"mov %[clock], %%ebx \n"
7272
"call __kernel_vsyscall \n"
7373
"mov %%edx, %%ebx \n"
7474
: "=a" (ret), "=m" (*ts)
75-
: "0" (__NR_clock_gettime), "g" (clock), "c" (ts)
75+
: "0" (__NR_clock_gettime), [clock] "g" (clock), "c" (ts)
7676
: "memory", "edx");
7777
return ret;
7878
}
@@ -83,11 +83,11 @@ notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz)
8383

8484
asm (
8585
"mov %%ebx, %%edx \n"
86-
"mov %2, %%ebx \n"
86+
"mov %[tv], %%ebx \n"
8787
"call __kernel_vsyscall \n"
8888
"mov %%edx, %%ebx \n"
8989
: "=a" (ret), "=m" (*tv), "=m" (*tz)
90-
: "0" (__NR_gettimeofday), "g" (tv), "c" (tz)
90+
: "0" (__NR_gettimeofday), [tv] "g" (tv), "c" (tz)
9191
: "memory", "edx");
9292
return ret;
9393
}

tools/testing/selftests/x86/test_vdso.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ typedef int (*vgettime_t)(clockid_t, struct timespec *);
3636

3737
vgettime_t vdso_clock_gettime;
3838

39+
typedef long (*vgtod_t)(struct timeval *tv, struct timezone *tz);
40+
41+
vgtod_t vdso_gettimeofday;
42+
3943
typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
4044

4145
getcpu_t vgetcpu;
@@ -104,6 +108,11 @@ static void fill_function_pointers()
104108
vdso_clock_gettime = (vgettime_t)dlsym(vdso, "__vdso_clock_gettime");
105109
if (!vdso_clock_gettime)
106110
printf("Warning: failed to find clock_gettime in vDSO\n");
111+
112+
vdso_gettimeofday = (vgtod_t)dlsym(vdso, "__vdso_gettimeofday");
113+
if (!vdso_gettimeofday)
114+
printf("Warning: failed to find gettimeofday in vDSO\n");
115+
107116
}
108117

109118
static long sys_getcpu(unsigned * cpu, unsigned * node,
@@ -117,6 +126,11 @@ static inline int sys_clock_gettime(clockid_t id, struct timespec *ts)
117126
return syscall(__NR_clock_gettime, id, ts);
118127
}
119128

129+
static inline int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
130+
{
131+
return syscall(__NR_gettimeofday, tv, tz);
132+
}
133+
120134
static void test_getcpu(void)
121135
{
122136
printf("[RUN]\tTesting getcpu...\n");
@@ -177,6 +191,14 @@ static bool ts_leq(const struct timespec *a, const struct timespec *b)
177191
return a->tv_nsec <= b->tv_nsec;
178192
}
179193

194+
static bool tv_leq(const struct timeval *a, const struct timeval *b)
195+
{
196+
if (a->tv_sec != b->tv_sec)
197+
return a->tv_sec < b->tv_sec;
198+
else
199+
return a->tv_usec <= b->tv_usec;
200+
}
201+
180202
static char const * const clocknames[] = {
181203
[0] = "CLOCK_REALTIME",
182204
[1] = "CLOCK_MONOTONIC",
@@ -248,11 +270,62 @@ static void test_clock_gettime(void)
248270
test_one_clock_gettime(INT_MAX, "invalid");
249271
}
250272

273+
static void test_gettimeofday(void)
274+
{
275+
struct timeval start, vdso, end;
276+
struct timezone sys_tz, vdso_tz;
277+
int vdso_ret, end_ret;
278+
279+
if (!vdso_gettimeofday)
280+
return;
281+
282+
printf("[RUN]\tTesting gettimeofday...\n");
283+
284+
if (sys_gettimeofday(&start, &sys_tz) < 0) {
285+
printf("[FAIL]\tsys_gettimeofday failed (%d)\n", errno);
286+
nerrs++;
287+
return;
288+
}
289+
290+
vdso_ret = vdso_gettimeofday(&vdso, &vdso_tz);
291+
end_ret = sys_gettimeofday(&end, NULL);
292+
293+
if (vdso_ret != 0 || end_ret != 0) {
294+
printf("[FAIL]\tvDSO returned %d, syscall errno=%d\n",
295+
vdso_ret, errno);
296+
nerrs++;
297+
return;
298+
}
299+
300+
printf("\t%llu.%06ld %llu.%06ld %llu.%06ld\n",
301+
(unsigned long long)start.tv_sec, start.tv_usec,
302+
(unsigned long long)vdso.tv_sec, vdso.tv_usec,
303+
(unsigned long long)end.tv_sec, end.tv_usec);
304+
305+
if (!tv_leq(&start, &vdso) || !tv_leq(&vdso, &end)) {
306+
printf("[FAIL]\tTimes are out of sequence\n");
307+
nerrs++;
308+
}
309+
310+
if (sys_tz.tz_minuteswest == vdso_tz.tz_minuteswest &&
311+
sys_tz.tz_dsttime == vdso_tz.tz_dsttime) {
312+
printf("[OK]\ttimezones match: minuteswest=%d, dsttime=%d\n",
313+
sys_tz.tz_minuteswest, sys_tz.tz_dsttime);
314+
} else {
315+
printf("[FAIL]\ttimezones do not match\n");
316+
nerrs++;
317+
}
318+
319+
/* And make sure that passing NULL for tz doesn't crash. */
320+
vdso_gettimeofday(&vdso, NULL);
321+
}
322+
251323
int main(int argc, char **argv)
252324
{
253325
fill_function_pointers();
254326

255327
test_clock_gettime();
328+
test_gettimeofday();
256329

257330
/*
258331
* Test getcpu() last so that, if something goes wrong setting affinity,

0 commit comments

Comments
 (0)