1 From 02e425668f5c9deb42787d10001a3b605993ad15 Mon Sep 17 00:00:00 2001
2 From: Andy Lutomirski <luto@kernel.org>
3 Date: Wed, 3 Oct 2018 16:23:49 -0700
4 Subject: x86/vdso: Fix vDSO syscall fallback asm constraint regression
6 From: Andy Lutomirski <luto@kernel.org>
8 commit 02e425668f5c9deb42787d10001a3b605993ad15 upstream.
10 When I added the missing memory outputs, I failed to update the
11 index of the first argument (ebx) on 32-bit builds, which broke the
12 fallbacks. Somehow I must have screwed up my testing or gotten
15 Add another test to cover gettimeofday() as well.
17 Signed-off-by: Andy Lutomirski <luto@kernel.org>
18 Cc: Linus Torvalds <torvalds@linux-foundation.org>
19 Cc: Peter Zijlstra <peterz@infradead.org>
20 Cc: Thomas Gleixner <tglx@linutronix.de>
21 Cc: stable@vger.kernel.org
22 Fixes: 715bd9d12f84 ("x86/vdso: Fix asm constraints on vDSO syscall fallbacks")
23 Link: http://lkml.kernel.org/r/21bd45ab04b6d838278fa5bebfa9163eceffa13c.1538608971.git.luto@kernel.org
24 Signed-off-by: Ingo Molnar <mingo@kernel.org>
25 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 arch/x86/entry/vdso/vclock_gettime.c | 8 +--
29 tools/testing/selftests/x86/test_vdso.c | 73 ++++++++++++++++++++++++++++++++
30 2 files changed, 77 insertions(+), 4 deletions(-)
32 --- a/arch/x86/entry/vdso/vclock_gettime.c
33 +++ b/arch/x86/entry/vdso/vclock_gettime.c
34 @@ -68,11 +68,11 @@ notrace static long vdso_fallback_gettim
39 + "mov %[clock], %%ebx \n"
40 "call __kernel_vsyscall \n"
42 : "=a" (ret), "=m" (*ts)
43 - : "0" (__NR_clock_gettime), "g" (clock), "c" (ts)
44 + : "0" (__NR_clock_gettime), [clock] "g" (clock), "c" (ts)
48 @@ -83,11 +83,11 @@ notrace static long vdso_fallback_gtod(s
53 + "mov %[tv], %%ebx \n"
54 "call __kernel_vsyscall \n"
56 : "=a" (ret), "=m" (*tv), "=m" (*tz)
57 - : "0" (__NR_gettimeofday), "g" (tv), "c" (tz)
58 + : "0" (__NR_gettimeofday), [tv] "g" (tv), "c" (tz)
62 --- a/tools/testing/selftests/x86/test_vdso.c
63 +++ b/tools/testing/selftests/x86/test_vdso.c
64 @@ -36,6 +36,10 @@ typedef int (*vgettime_t)(clockid_t, str
66 vgettime_t vdso_clock_gettime;
68 +typedef long (*vgtod_t)(struct timeval *tv, struct timezone *tz);
70 +vgtod_t vdso_gettimeofday;
72 typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
75 @@ -104,6 +108,11 @@ static void fill_function_pointers()
76 vdso_clock_gettime = (vgettime_t)dlsym(vdso, "__vdso_clock_gettime");
77 if (!vdso_clock_gettime)
78 printf("Warning: failed to find clock_gettime in vDSO\n");
80 + vdso_gettimeofday = (vgtod_t)dlsym(vdso, "__vdso_gettimeofday");
81 + if (!vdso_gettimeofday)
82 + printf("Warning: failed to find gettimeofday in vDSO\n");
86 static long sys_getcpu(unsigned * cpu, unsigned * node,
87 @@ -117,6 +126,11 @@ static inline int sys_clock_gettime(cloc
88 return syscall(__NR_clock_gettime, id, ts);
91 +static inline int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
93 + return syscall(__NR_gettimeofday, tv, tz);
96 static void test_getcpu(void)
98 printf("[RUN]\tTesting getcpu...\n");
99 @@ -177,6 +191,14 @@ static bool ts_leq(const struct timespec
100 return a->tv_nsec <= b->tv_nsec;
103 +static bool tv_leq(const struct timeval *a, const struct timeval *b)
105 + if (a->tv_sec != b->tv_sec)
106 + return a->tv_sec < b->tv_sec;
108 + return a->tv_usec <= b->tv_usec;
111 static char const * const clocknames[] = {
112 [0] = "CLOCK_REALTIME",
113 [1] = "CLOCK_MONOTONIC",
114 @@ -248,11 +270,62 @@ static void test_clock_gettime(void)
115 test_one_clock_gettime(INT_MAX, "invalid");
118 +static void test_gettimeofday(void)
120 + struct timeval start, vdso, end;
121 + struct timezone sys_tz, vdso_tz;
122 + int vdso_ret, end_ret;
124 + if (!vdso_gettimeofday)
127 + printf("[RUN]\tTesting gettimeofday...\n");
129 + if (sys_gettimeofday(&start, &sys_tz) < 0) {
130 + printf("[FAIL]\tsys_gettimeofday failed (%d)\n", errno);
135 + vdso_ret = vdso_gettimeofday(&vdso, &vdso_tz);
136 + end_ret = sys_gettimeofday(&end, NULL);
138 + if (vdso_ret != 0 || end_ret != 0) {
139 + printf("[FAIL]\tvDSO returned %d, syscall errno=%d\n",
145 + printf("\t%llu.%06ld %llu.%06ld %llu.%06ld\n",
146 + (unsigned long long)start.tv_sec, start.tv_usec,
147 + (unsigned long long)vdso.tv_sec, vdso.tv_usec,
148 + (unsigned long long)end.tv_sec, end.tv_usec);
150 + if (!tv_leq(&start, &vdso) || !tv_leq(&vdso, &end)) {
151 + printf("[FAIL]\tTimes are out of sequence\n");
155 + if (sys_tz.tz_minuteswest == vdso_tz.tz_minuteswest &&
156 + sys_tz.tz_dsttime == vdso_tz.tz_dsttime) {
157 + printf("[OK]\ttimezones match: minuteswest=%d, dsttime=%d\n",
158 + sys_tz.tz_minuteswest, sys_tz.tz_dsttime);
160 + printf("[FAIL]\ttimezones do not match\n");
164 + /* And make sure that passing NULL for tz doesn't crash. */
165 + vdso_gettimeofday(&vdso, NULL);
168 int main(int argc, char **argv)
170 fill_function_pointers();
172 test_clock_gettime();
173 + test_gettimeofday();
176 * Test getcpu() last so that, if something goes wrong setting affinity,