Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'linux-kselftest-next-5.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull Kselftest updates from Shuah Khan:

- Much needed gpio test Makefile cleanup to various problems with test
dependencies and build errors from Michael Ellerman

- Enabling vDSO test on non x86 platforms from Vincenzo Frascino

- Fix intel_pstate to replace deprecated ftime() usages with
clock_gettime() from Tommi Rantala

- cgroup test build fix on older releases from Sachin Sant

- A couple of spelling mistake fixes

* tag 'linux-kselftest-next-5.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
selftests/cgroup: Fix build on older distros
selftests/run_kselftest.sh: fix dry-run typo
tool: selftests: fix spelling typo of 'writting'
selftests/memfd: Fix implicit declaration warnings
selftests: intel_pstate: ftime() is deprecated
selftests/gpio: Add to CLEAN rule rather than overriding
selftests/gpio: Fix build when source tree is read only
selftests/gpio: Move include of lib.mk up
selftests/gpio: Use TEST_GEN_PROGS_EXTENDED
kselftest: Extend vdso correctness test to clock_gettime64
kselftest: Move test_vdso to the vDSO test suite
kselftest: Extend vDSO selftest to clock_getres
kselftest: Extend vDSO selftest
kselftest: Enable vDSO test on non x86 platforms

+622 -35
+1
tools/testing/selftests/Makefile
··· 66 66 TARGETS += tmpfs 67 67 TARGETS += tpm2 68 68 TARGETS += user 69 + TARGETS += vDSO 69 70 TARGETS += vm 70 71 TARGETS += x86 71 72 TARGETS += zram
+2 -2
tools/testing/selftests/cgroup/cgroup_util.c
··· 337 337 #ifdef CLONE_ARGS_SIZE_VER2 338 338 pid_t pid; 339 339 340 - struct clone_args args = { 340 + struct __clone_args args = { 341 341 .flags = CLONE_INTO_CGROUP, 342 342 .exit_signal = SIGCHLD, 343 343 .cgroup = cgroup_fd, 344 344 }; 345 345 346 - pid = sys_clone3(&args, sizeof(struct clone_args)); 346 + pid = sys_clone3(&args, sizeof(struct __clone_args)); 347 347 /* 348 348 * Verify that this is a genuine test failure: 349 349 * ENOSYS -> clone3() not available
+13 -14
tools/testing/selftests/gpio/Makefile
··· 11 11 12 12 TEST_PROGS := gpio-mockup.sh 13 13 TEST_FILES := gpio-mockup-sysfs.sh 14 - TEST_PROGS_EXTENDED := gpio-mockup-chardev 15 - 16 - GPIODIR := $(realpath ../../../gpio) 17 - GPIOOBJ := gpio-utils.o 18 - 19 - all: $(TEST_PROGS_EXTENDED) 20 - 21 - override define CLEAN 22 - $(RM) $(TEST_PROGS_EXTENDED) 23 - $(MAKE) -C $(GPIODIR) OUTPUT=$(GPIODIR)/ clean 24 - endef 14 + TEST_GEN_PROGS_EXTENDED := gpio-mockup-chardev 25 15 26 16 KSFT_KHDR_INSTALL := 1 27 17 include ../lib.mk 28 18 29 - $(TEST_PROGS_EXTENDED): $(GPIODIR)/$(GPIOOBJ) 19 + GPIODIR := $(realpath ../../../gpio) 20 + GPIOOUT := $(OUTPUT)/tools-gpio/ 21 + GPIOOBJ := $(GPIOOUT)/gpio-utils.o 30 22 31 - $(GPIODIR)/$(GPIOOBJ): 32 - $(MAKE) OUTPUT=$(GPIODIR)/ -C $(GPIODIR) 23 + CLEAN += ; $(RM) -rf $(GPIOOUT) 24 + 25 + $(TEST_GEN_PROGS_EXTENDED): $(GPIOOBJ) 26 + 27 + $(GPIOOUT): 28 + mkdir -p $@ 29 + 30 + $(GPIOOBJ): $(GPIOOUT) 31 + $(MAKE) OUTPUT=$(GPIOOUT) -C $(GPIODIR)
+16 -6
tools/testing/selftests/intel_pstate/aperf.c
··· 10 10 #include <sched.h> 11 11 #include <errno.h> 12 12 #include <string.h> 13 + #include <time.h> 13 14 #include "../kselftest.h" 15 + 16 + #define MSEC_PER_SEC 1000L 17 + #define NSEC_PER_MSEC 1000000L 14 18 15 19 void usage(char *name) { 16 20 printf ("Usage: %s cpunum\n", name); ··· 26 22 long long tsc, old_tsc, new_tsc; 27 23 long long aperf, old_aperf, new_aperf; 28 24 long long mperf, old_mperf, new_mperf; 29 - struct timeb before, after; 25 + struct timespec before, after; 30 26 long long int start, finish, total; 31 27 cpu_set_t cpuset; 32 28 ··· 59 55 return 1; 60 56 } 61 57 62 - ftime(&before); 58 + if (clock_gettime(CLOCK_MONOTONIC, &before) < 0) { 59 + perror("clock_gettime"); 60 + return 1; 61 + } 63 62 pread(fd, &old_tsc, sizeof(old_tsc), 0x10); 64 63 pread(fd, &old_aperf, sizeof(old_mperf), 0xe7); 65 64 pread(fd, &old_mperf, sizeof(old_aperf), 0xe8); ··· 71 64 sqrt(i); 72 65 } 73 66 74 - ftime(&after); 67 + if (clock_gettime(CLOCK_MONOTONIC, &after) < 0) { 68 + perror("clock_gettime"); 69 + return 1; 70 + } 75 71 pread(fd, &new_tsc, sizeof(new_tsc), 0x10); 76 72 pread(fd, &new_aperf, sizeof(new_mperf), 0xe7); 77 73 pread(fd, &new_mperf, sizeof(new_aperf), 0xe8); ··· 83 73 aperf = new_aperf-old_aperf; 84 74 mperf = new_mperf-old_mperf; 85 75 86 - start = before.time*1000 + before.millitm; 87 - finish = after.time*1000 + after.millitm; 76 + start = before.tv_sec*MSEC_PER_SEC + before.tv_nsec/NSEC_PER_MSEC; 77 + finish = after.tv_sec*MSEC_PER_SEC + after.tv_nsec/NSEC_PER_MSEC; 88 78 total = finish - start; 89 79 90 - printf("runTime: %4.2f\n", 1.0*total/1000); 80 + printf("runTime: %4.2f\n", 1.0*total/MSEC_PER_SEC); 91 81 printf("freq: %7.0f\n", tsc / (1.0*aperf / (1.0 * mperf)) / total); 92 82 return 0; 93 83 }
+1 -1
tools/testing/selftests/memfd/fuse_test.c
··· 20 20 #include <inttypes.h> 21 21 #include <limits.h> 22 22 #include <linux/falloc.h> 23 - #include <linux/fcntl.h> 23 + #include <fcntl.h> 24 24 #include <linux/memfd.h> 25 25 #include <sched.h> 26 26 #include <stdio.h>
+1 -1
tools/testing/selftests/memfd/memfd_test.c
··· 6 6 #include <inttypes.h> 7 7 #include <limits.h> 8 8 #include <linux/falloc.h> 9 - #include <linux/fcntl.h> 9 + #include <fcntl.h> 10 10 #include <linux/memfd.h> 11 11 #include <sched.h> 12 12 #include <stdio.h>
+1 -1
tools/testing/selftests/run_kselftest.sh
··· 48 48 -l | --list) 49 49 echo "$available" 50 50 exit 0 ;; 51 - -n | --dry-run) 51 + -d | --dry-run) 52 52 dryrun="echo" 53 53 shift ;; 54 54 -h | --help)
+12 -4
tools/testing/selftests/vDSO/Makefile
··· 5 5 ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) 6 6 7 7 TEST_GEN_PROGS := $(OUTPUT)/vdso_test_gettimeofday $(OUTPUT)/vdso_test_getcpu 8 - ifeq ($(ARCH),x86) 8 + TEST_GEN_PROGS += $(OUTPUT)/vdso_test_abi 9 + TEST_GEN_PROGS += $(OUTPUT)/vdso_test_clock_getres 10 + ifeq ($(ARCH),$(filter $(ARCH),x86 x86_64)) 9 11 TEST_GEN_PROGS += $(OUTPUT)/vdso_standalone_test_x86 10 12 endif 13 + TEST_GEN_PROGS += $(OUTPUT)/vdso_test_correctness 11 14 12 - ifndef CROSS_COMPILE 13 15 CFLAGS := -std=gnu99 14 16 CFLAGS_vdso_standalone_test_x86 := -nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector 17 + LDFLAGS_vdso_test_correctness := -ldl 15 18 ifeq ($(CONFIG_X86_32),y) 16 19 LDLIBS += -lgcc_s 17 20 endif ··· 22 19 all: $(TEST_GEN_PROGS) 23 20 $(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c 24 21 $(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c 22 + $(OUTPUT)/vdso_test_abi: parse_vdso.c vdso_test_abi.c 23 + $(OUTPUT)/vdso_test_clock_getres: vdso_test_clock_getres.c 25 24 $(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c 26 25 $(CC) $(CFLAGS) $(CFLAGS_vdso_standalone_test_x86) \ 27 26 vdso_standalone_test_x86.c parse_vdso.c \ 28 27 -o $@ 29 - 30 - endif 28 + $(OUTPUT)/vdso_test_correctness: vdso_test_correctness.c 29 + $(CC) $(CFLAGS) \ 30 + vdso_test_correctness.c \ 31 + -o $@ \ 32 + $(LDFLAGS_vdso_test_correctness)
+92
tools/testing/selftests/vDSO/vdso_config.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * vdso_config.h: Configuration options for vDSO tests. 4 + * Copyright (c) 2019 Arm Ltd. 5 + */ 6 + #ifndef __VDSO_CONFIG_H__ 7 + #define __VDSO_CONFIG_H__ 8 + 9 + /* 10 + * Each architecture exports its vDSO implementation with different names 11 + * and a different version from the others, so we need to handle it as a 12 + * special case. 13 + */ 14 + #if defined(__arm__) 15 + #define VDSO_VERSION 0 16 + #define VDSO_NAMES 1 17 + #define VDSO_32BIT 1 18 + #elif defined(__aarch64__) 19 + #define VDSO_VERSION 3 20 + #define VDSO_NAMES 0 21 + #elif defined(__powerpc__) 22 + #define VDSO_VERSION 1 23 + #define VDSO_NAMES 0 24 + #define VDSO_32BIT 1 25 + #elif defined(__powerpc64__) 26 + #define VDSO_VERSION 1 27 + #define VDSO_NAMES 0 28 + #elif defined (__s390__) 29 + #define VDSO_VERSION 2 30 + #define VDSO_NAMES 0 31 + #define VDSO_32BIT 1 32 + #elif defined (__s390X__) 33 + #define VDSO_VERSION 2 34 + #define VDSO_NAMES 0 35 + #elif defined(__mips__) 36 + #define VDSO_VERSION 0 37 + #define VDSO_NAMES 1 38 + #define VDSO_32BIT 1 39 + #elif defined(__sparc__) 40 + #define VDSO_VERSION 0 41 + #define VDSO_NAMES 1 42 + #define VDSO_32BIT 1 43 + #elif defined(__i386__) 44 + #define VDSO_VERSION 0 45 + #define VDSO_NAMES 1 46 + #define VDSO_32BIT 1 47 + #elif defined(__x86_64__) 48 + #define VDSO_VERSION 0 49 + #define VDSO_NAMES 1 50 + #elif defined(__riscv__) 51 + #define VDSO_VERSION 5 52 + #define VDSO_NAMES 1 53 + #define VDSO_32BIT 1 54 + #else /* nds32 */ 55 + #define VDSO_VERSION 4 56 + #define VDSO_NAMES 1 57 + #define VDSO_32BIT 1 58 + #endif 59 + 60 + static const char *versions[6] = { 61 + "LINUX_2.6", 62 + "LINUX_2.6.15", 63 + "LINUX_2.6.29", 64 + "LINUX_2.6.39", 65 + "LINUX_4", 66 + "LINUX_4.15", 67 + }; 68 + 69 + static const char *names[2][6] = { 70 + { 71 + "__kernel_gettimeofday", 72 + "__kernel_clock_gettime", 73 + "__kernel_time", 74 + "__kernel_clock_getres", 75 + "__kernel_getcpu", 76 + #if defined(VDSO_32BIT) 77 + "__kernel_clock_gettime64", 78 + #endif 79 + }, 80 + { 81 + "__vdso_gettimeofday", 82 + "__vdso_clock_gettime", 83 + "__vdso_time", 84 + "__vdso_clock_getres", 85 + "__vdso_getcpu", 86 + #if defined(VDSO_32BIT) 87 + "__vdso_clock_gettime64", 88 + #endif 89 + }, 90 + }; 91 + 92 + #endif /* __VDSO_CONFIG_H__ */
+244
tools/testing/selftests/vDSO/vdso_test_abi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * vdso_full_test.c: Sample code to test all the timers. 4 + * Copyright (c) 2019 Arm Ltd. 5 + * 6 + * Compile with: 7 + * gcc -std=gnu99 vdso_full_test.c parse_vdso.c 8 + * 9 + */ 10 + 11 + #include <stdint.h> 12 + #include <elf.h> 13 + #include <stdio.h> 14 + #include <time.h> 15 + #include <sys/auxv.h> 16 + #include <sys/time.h> 17 + #define _GNU_SOURCE 18 + #include <unistd.h> 19 + #include <sys/syscall.h> 20 + 21 + #include "../kselftest.h" 22 + #include "vdso_config.h" 23 + 24 + extern void *vdso_sym(const char *version, const char *name); 25 + extern void vdso_init_from_sysinfo_ehdr(uintptr_t base); 26 + extern void vdso_init_from_auxv(void *auxv); 27 + 28 + static const char *version; 29 + static const char **name; 30 + 31 + typedef long (*vdso_gettimeofday_t)(struct timeval *tv, struct timezone *tz); 32 + typedef long (*vdso_clock_gettime_t)(clockid_t clk_id, struct timespec *ts); 33 + typedef long (*vdso_clock_getres_t)(clockid_t clk_id, struct timespec *ts); 34 + typedef time_t (*vdso_time_t)(time_t *t); 35 + 36 + static int vdso_test_gettimeofday(void) 37 + { 38 + /* Find gettimeofday. */ 39 + vdso_gettimeofday_t vdso_gettimeofday = 40 + (vdso_gettimeofday_t)vdso_sym(version, name[0]); 41 + 42 + if (!vdso_gettimeofday) { 43 + printf("Could not find %s\n", name[0]); 44 + return KSFT_SKIP; 45 + } 46 + 47 + struct timeval tv; 48 + long ret = vdso_gettimeofday(&tv, 0); 49 + 50 + if (ret == 0) { 51 + printf("The time is %lld.%06lld\n", 52 + (long long)tv.tv_sec, (long long)tv.tv_usec); 53 + } else { 54 + printf("%s failed\n", name[0]); 55 + return KSFT_FAIL; 56 + } 57 + 58 + return KSFT_PASS; 59 + } 60 + 61 + static int vdso_test_clock_gettime(clockid_t clk_id) 62 + { 63 + /* Find clock_gettime. */ 64 + vdso_clock_gettime_t vdso_clock_gettime = 65 + (vdso_clock_gettime_t)vdso_sym(version, name[1]); 66 + 67 + if (!vdso_clock_gettime) { 68 + printf("Could not find %s\n", name[1]); 69 + return KSFT_SKIP; 70 + } 71 + 72 + struct timespec ts; 73 + long ret = vdso_clock_gettime(clk_id, &ts); 74 + 75 + if (ret == 0) { 76 + printf("The time is %lld.%06lld\n", 77 + (long long)ts.tv_sec, (long long)ts.tv_nsec); 78 + } else { 79 + printf("%s failed\n", name[1]); 80 + return KSFT_FAIL; 81 + } 82 + 83 + return KSFT_PASS; 84 + } 85 + 86 + static int vdso_test_time(void) 87 + { 88 + /* Find time. */ 89 + vdso_time_t vdso_time = 90 + (vdso_time_t)vdso_sym(version, name[2]); 91 + 92 + if (!vdso_time) { 93 + printf("Could not find %s\n", name[2]); 94 + return KSFT_SKIP; 95 + } 96 + 97 + long ret = vdso_time(NULL); 98 + 99 + if (ret > 0) { 100 + printf("The time in hours since January 1, 1970 is %lld\n", 101 + (long long)(ret / 3600)); 102 + } else { 103 + printf("%s failed\n", name[2]); 104 + return KSFT_FAIL; 105 + } 106 + 107 + return KSFT_PASS; 108 + } 109 + 110 + static int vdso_test_clock_getres(clockid_t clk_id) 111 + { 112 + /* Find clock_getres. */ 113 + vdso_clock_getres_t vdso_clock_getres = 114 + (vdso_clock_getres_t)vdso_sym(version, name[3]); 115 + 116 + if (!vdso_clock_getres) { 117 + printf("Could not find %s\n", name[3]); 118 + return KSFT_SKIP; 119 + } 120 + 121 + struct timespec ts, sys_ts; 122 + long ret = vdso_clock_getres(clk_id, &ts); 123 + 124 + if (ret == 0) { 125 + printf("The resolution is %lld %lld\n", 126 + (long long)ts.tv_sec, (long long)ts.tv_nsec); 127 + } else { 128 + printf("%s failed\n", name[3]); 129 + return KSFT_FAIL; 130 + } 131 + 132 + ret = syscall(SYS_clock_getres, clk_id, &sys_ts); 133 + 134 + if ((sys_ts.tv_sec != ts.tv_sec) || (sys_ts.tv_nsec != ts.tv_nsec)) { 135 + printf("%s failed\n", name[3]); 136 + return KSFT_FAIL; 137 + } 138 + 139 + return KSFT_PASS; 140 + } 141 + 142 + const char *vdso_clock_name[12] = { 143 + "CLOCK_REALTIME", 144 + "CLOCK_MONOTONIC", 145 + "CLOCK_PROCESS_CPUTIME_ID", 146 + "CLOCK_THREAD_CPUTIME_ID", 147 + "CLOCK_MONOTONIC_RAW", 148 + "CLOCK_REALTIME_COARSE", 149 + "CLOCK_MONOTONIC_COARSE", 150 + "CLOCK_BOOTTIME", 151 + "CLOCK_REALTIME_ALARM", 152 + "CLOCK_BOOTTIME_ALARM", 153 + "CLOCK_SGI_CYCLE", 154 + "CLOCK_TAI", 155 + }; 156 + 157 + /* 158 + * This function calls vdso_test_clock_gettime and vdso_test_clock_getres 159 + * with different values for clock_id. 160 + */ 161 + static inline int vdso_test_clock(clockid_t clock_id) 162 + { 163 + int ret0, ret1; 164 + 165 + ret0 = vdso_test_clock_gettime(clock_id); 166 + /* A skipped test is considered passed */ 167 + if (ret0 == KSFT_SKIP) 168 + ret0 = KSFT_PASS; 169 + 170 + ret1 = vdso_test_clock_getres(clock_id); 171 + /* A skipped test is considered passed */ 172 + if (ret1 == KSFT_SKIP) 173 + ret1 = KSFT_PASS; 174 + 175 + ret0 += ret1; 176 + 177 + printf("clock_id: %s", vdso_clock_name[clock_id]); 178 + 179 + if (ret0 > 0) 180 + printf(" [FAIL]\n"); 181 + else 182 + printf(" [PASS]\n"); 183 + 184 + return ret0; 185 + } 186 + 187 + int main(int argc, char **argv) 188 + { 189 + unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR); 190 + int ret; 191 + 192 + if (!sysinfo_ehdr) { 193 + printf("AT_SYSINFO_EHDR is not present!\n"); 194 + return KSFT_SKIP; 195 + } 196 + 197 + version = versions[VDSO_VERSION]; 198 + name = (const char **)&names[VDSO_NAMES]; 199 + 200 + printf("[vDSO kselftest] VDSO_VERSION: %s\n", version); 201 + 202 + vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR)); 203 + 204 + ret = vdso_test_gettimeofday(); 205 + 206 + #if _POSIX_TIMERS > 0 207 + 208 + #ifdef CLOCK_REALTIME 209 + ret += vdso_test_clock(CLOCK_REALTIME); 210 + #endif 211 + 212 + #ifdef CLOCK_BOOTTIME 213 + ret += vdso_test_clock(CLOCK_BOOTTIME); 214 + #endif 215 + 216 + #ifdef CLOCK_TAI 217 + ret += vdso_test_clock(CLOCK_TAI); 218 + #endif 219 + 220 + #ifdef CLOCK_REALTIME_COARSE 221 + ret += vdso_test_clock(CLOCK_REALTIME_COARSE); 222 + #endif 223 + 224 + #ifdef CLOCK_MONOTONIC 225 + ret += vdso_test_clock(CLOCK_MONOTONIC); 226 + #endif 227 + 228 + #ifdef CLOCK_MONOTONIC_RAW 229 + ret += vdso_test_clock(CLOCK_MONOTONIC_RAW); 230 + #endif 231 + 232 + #ifdef CLOCK_MONOTONIC_COARSE 233 + ret += vdso_test_clock(CLOCK_MONOTONIC_COARSE); 234 + #endif 235 + 236 + #endif 237 + 238 + ret += vdso_test_time(); 239 + 240 + if (ret > 0) 241 + return KSFT_FAIL; 242 + 243 + return KSFT_PASS; 244 + }
+124
tools/testing/selftests/vDSO/vdso_test_clock_getres.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2 + /* 3 + * vdso_clock_getres.c: Sample code to test clock_getres. 4 + * Copyright (c) 2019 Arm Ltd. 5 + * 6 + * Compile with: 7 + * gcc -std=gnu99 vdso_clock_getres.c 8 + * 9 + * Tested on ARM, ARM64, MIPS32, x86 (32-bit and 64-bit), 10 + * Power (32-bit and 64-bit), S390x (32-bit and 64-bit). 11 + * Might work on other architectures. 12 + */ 13 + 14 + #define _GNU_SOURCE 15 + #include <elf.h> 16 + #include <err.h> 17 + #include <fcntl.h> 18 + #include <stdint.h> 19 + #include <stdio.h> 20 + #include <stdlib.h> 21 + #include <time.h> 22 + #include <sys/auxv.h> 23 + #include <sys/mman.h> 24 + #include <sys/time.h> 25 + #include <unistd.h> 26 + #include <sys/syscall.h> 27 + 28 + #include "../kselftest.h" 29 + 30 + static long syscall_clock_getres(clockid_t _clkid, struct timespec *_ts) 31 + { 32 + long ret; 33 + 34 + ret = syscall(SYS_clock_getres, _clkid, _ts); 35 + 36 + return ret; 37 + } 38 + 39 + const char *vdso_clock_name[12] = { 40 + "CLOCK_REALTIME", 41 + "CLOCK_MONOTONIC", 42 + "CLOCK_PROCESS_CPUTIME_ID", 43 + "CLOCK_THREAD_CPUTIME_ID", 44 + "CLOCK_MONOTONIC_RAW", 45 + "CLOCK_REALTIME_COARSE", 46 + "CLOCK_MONOTONIC_COARSE", 47 + "CLOCK_BOOTTIME", 48 + "CLOCK_REALTIME_ALARM", 49 + "CLOCK_BOOTTIME_ALARM", 50 + "CLOCK_SGI_CYCLE", 51 + "CLOCK_TAI", 52 + }; 53 + 54 + /* 55 + * This function calls clock_getres in vdso and by system call 56 + * with different values for clock_id. 57 + * 58 + * Example of output: 59 + * 60 + * clock_id: CLOCK_REALTIME [PASS] 61 + * clock_id: CLOCK_BOOTTIME [PASS] 62 + * clock_id: CLOCK_TAI [PASS] 63 + * clock_id: CLOCK_REALTIME_COARSE [PASS] 64 + * clock_id: CLOCK_MONOTONIC [PASS] 65 + * clock_id: CLOCK_MONOTONIC_RAW [PASS] 66 + * clock_id: CLOCK_MONOTONIC_COARSE [PASS] 67 + */ 68 + static inline int vdso_test_clock(unsigned int clock_id) 69 + { 70 + struct timespec x, y; 71 + 72 + printf("clock_id: %s", vdso_clock_name[clock_id]); 73 + clock_getres(clock_id, &x); 74 + syscall_clock_getres(clock_id, &y); 75 + 76 + if ((x.tv_sec != y.tv_sec) || (x.tv_nsec != y.tv_nsec)) { 77 + printf(" [FAIL]\n"); 78 + return KSFT_FAIL; 79 + } 80 + 81 + printf(" [PASS]\n"); 82 + return KSFT_PASS; 83 + } 84 + 85 + int main(int argc, char **argv) 86 + { 87 + int ret; 88 + 89 + #if _POSIX_TIMERS > 0 90 + 91 + #ifdef CLOCK_REALTIME 92 + ret = vdso_test_clock(CLOCK_REALTIME); 93 + #endif 94 + 95 + #ifdef CLOCK_BOOTTIME 96 + ret += vdso_test_clock(CLOCK_BOOTTIME); 97 + #endif 98 + 99 + #ifdef CLOCK_TAI 100 + ret += vdso_test_clock(CLOCK_TAI); 101 + #endif 102 + 103 + #ifdef CLOCK_REALTIME_COARSE 104 + ret += vdso_test_clock(CLOCK_REALTIME_COARSE); 105 + #endif 106 + 107 + #ifdef CLOCK_MONOTONIC 108 + ret += vdso_test_clock(CLOCK_MONOTONIC); 109 + #endif 110 + 111 + #ifdef CLOCK_MONOTONIC_RAW 112 + ret += vdso_test_clock(CLOCK_MONOTONIC_RAW); 113 + #endif 114 + 115 + #ifdef CLOCK_MONOTONIC_COARSE 116 + ret += vdso_test_clock(CLOCK_MONOTONIC_COARSE); 117 + #endif 118 + 119 + #endif 120 + if (ret > 0) 121 + return KSFT_FAIL; 122 + 123 + return KSFT_PASS; 124 + }
+2 -2
tools/testing/selftests/vm/userfaultfd.c
··· 906 906 count_verify[nr]); 907 907 } 908 908 /* 909 - * Trigger write protection if there is by writting 909 + * Trigger write protection if there is by writing 910 910 * the same value back. 911 911 */ 912 912 *area_count(area_dst, nr) = count; ··· 934 934 count_verify[nr]); exit(1); 935 935 } 936 936 /* 937 - * Trigger write protection if there is by writting 937 + * Trigger write protection if there is by writing 938 938 * the same value back. 939 939 */ 940 940 *area_count(area_dst, nr) = count;
+1 -1
tools/testing/selftests/x86/Makefile
··· 12 12 13 13 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \ 14 14 check_initial_reg_state sigreturn iopl ioperm \ 15 - test_vdso test_vsyscall mov_ss_trap \ 15 + test_vsyscall mov_ss_trap \ 16 16 syscall_arg_fault fsgsbase_restore 17 17 TARGETS_C_32BIT_ONLY := entry_from_vm86 test_syscall_vdso unwind_vdso \ 18 18 test_FCMOV test_FCOMI test_FISTTP \
+112 -3
tools/testing/selftests/x86/test_vdso.c tools/testing/selftests/vDSO/vdso_test_correctness.c
··· 19 19 #include <stdbool.h> 20 20 #include <limits.h> 21 21 22 + #include "vdso_config.h" 23 + 24 + static const char **name; 25 + 22 26 #ifndef SYS_getcpu 23 27 # ifdef __x86_64__ 24 28 # define SYS_getcpu 309 25 29 # else 26 30 # define SYS_getcpu 318 27 31 # endif 32 + #endif 33 + 34 + #ifndef __NR_clock_gettime64 35 + #define __NR_clock_gettime64 403 36 + #endif 37 + 38 + #ifndef __kernel_timespec 39 + struct __kernel_timespec { 40 + long long tv_sec; 41 + long long tv_nsec; 42 + }; 28 43 #endif 29 44 30 45 /* max length of lines in /proc/self/maps - anything longer is skipped here */ ··· 50 35 typedef int (*vgettime_t)(clockid_t, struct timespec *); 51 36 52 37 vgettime_t vdso_clock_gettime; 38 + 39 + typedef int (*vgettime64_t)(clockid_t, struct __kernel_timespec *); 40 + 41 + vgettime64_t vdso_clock_gettime64; 53 42 54 43 typedef long (*vgtod_t)(struct timeval *tv, struct timezone *tz); 55 44 ··· 118 99 return; 119 100 } 120 101 121 - vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu"); 102 + vdso_getcpu = (getcpu_t)dlsym(vdso, name[4]); 122 103 if (!vdso_getcpu) 123 104 printf("Warning: failed to find getcpu in vDSO\n"); 124 105 125 106 vgetcpu = (getcpu_t) vsyscall_getcpu(); 126 107 127 - vdso_clock_gettime = (vgettime_t)dlsym(vdso, "__vdso_clock_gettime"); 108 + vdso_clock_gettime = (vgettime_t)dlsym(vdso, name[1]); 128 109 if (!vdso_clock_gettime) 129 110 printf("Warning: failed to find clock_gettime in vDSO\n"); 130 111 131 - vdso_gettimeofday = (vgtod_t)dlsym(vdso, "__vdso_gettimeofday"); 112 + #if defined(VDSO_32BIT) 113 + vdso_clock_gettime64 = (vgettime64_t)dlsym(vdso, name[5]); 114 + if (!vdso_clock_gettime64) 115 + printf("Warning: failed to find clock_gettime64 in vDSO\n"); 116 + #endif 117 + 118 + vdso_gettimeofday = (vgtod_t)dlsym(vdso, name[0]); 132 119 if (!vdso_gettimeofday) 133 120 printf("Warning: failed to find gettimeofday in vDSO\n"); 134 121 ··· 149 124 static inline int sys_clock_gettime(clockid_t id, struct timespec *ts) 150 125 { 151 126 return syscall(__NR_clock_gettime, id, ts); 127 + } 128 + 129 + static inline int sys_clock_gettime64(clockid_t id, struct __kernel_timespec *ts) 130 + { 131 + return syscall(__NR_clock_gettime64, id, ts); 152 132 } 153 133 154 134 static inline int sys_gettimeofday(struct timeval *tv, struct timezone *tz) ··· 214 184 } 215 185 216 186 static bool ts_leq(const struct timespec *a, const struct timespec *b) 187 + { 188 + if (a->tv_sec != b->tv_sec) 189 + return a->tv_sec < b->tv_sec; 190 + else 191 + return a->tv_nsec <= b->tv_nsec; 192 + } 193 + 194 + static bool ts64_leq(const struct __kernel_timespec *a, 195 + const struct __kernel_timespec *b) 217 196 { 218 197 if (a->tv_sec != b->tv_sec) 219 198 return a->tv_sec < b->tv_sec; ··· 293 254 if (!ts_leq(&start, &vdso) || !ts_leq(&vdso, &end)) { 294 255 printf("[FAIL]\tTimes are out of sequence\n"); 295 256 nerrs++; 257 + return; 296 258 } 259 + 260 + printf("[OK]\tTest Passed.\n"); 297 261 } 298 262 299 263 static void test_clock_gettime(void) ··· 315 273 test_one_clock_gettime(-1, "invalid"); 316 274 test_one_clock_gettime(INT_MIN, "invalid"); 317 275 test_one_clock_gettime(INT_MAX, "invalid"); 276 + } 277 + 278 + static void test_one_clock_gettime64(int clock, const char *name) 279 + { 280 + struct __kernel_timespec start, vdso, end; 281 + int vdso_ret, end_ret; 282 + 283 + printf("[RUN]\tTesting clock_gettime64 for clock %s (%d)...\n", name, clock); 284 + 285 + if (sys_clock_gettime64(clock, &start) < 0) { 286 + if (errno == EINVAL) { 287 + vdso_ret = vdso_clock_gettime64(clock, &vdso); 288 + if (vdso_ret == -EINVAL) { 289 + printf("[OK]\tNo such clock.\n"); 290 + } else { 291 + printf("[FAIL]\tNo such clock, but __vdso_clock_gettime64 returned %d\n", vdso_ret); 292 + nerrs++; 293 + } 294 + } else { 295 + printf("[WARN]\t clock_gettime64(%d) syscall returned error %d\n", clock, errno); 296 + } 297 + return; 298 + } 299 + 300 + vdso_ret = vdso_clock_gettime64(clock, &vdso); 301 + end_ret = sys_clock_gettime64(clock, &end); 302 + 303 + if (vdso_ret != 0 || end_ret != 0) { 304 + printf("[FAIL]\tvDSO returned %d, syscall errno=%d\n", 305 + vdso_ret, errno); 306 + nerrs++; 307 + return; 308 + } 309 + 310 + printf("\t%llu.%09ld %llu.%09ld %llu.%09ld\n", 311 + (unsigned long long)start.tv_sec, start.tv_nsec, 312 + (unsigned long long)vdso.tv_sec, vdso.tv_nsec, 313 + (unsigned long long)end.tv_sec, end.tv_nsec); 314 + 315 + if (!ts64_leq(&start, &vdso) || !ts64_leq(&vdso, &end)) { 316 + printf("[FAIL]\tTimes are out of sequence\n"); 317 + nerrs++; 318 + return; 319 + } 320 + 321 + printf("[OK]\tTest Passed.\n"); 322 + } 323 + 324 + static void test_clock_gettime64(void) 325 + { 326 + if (!vdso_clock_gettime64) { 327 + printf("[SKIP]\tNo vDSO, so skipping clock_gettime64() tests\n"); 328 + return; 329 + } 330 + 331 + for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]); 332 + clock++) { 333 + test_one_clock_gettime64(clock, clocknames[clock]); 334 + } 335 + 336 + /* Also test some invalid clock ids */ 337 + test_one_clock_gettime64(-1, "invalid"); 338 + test_one_clock_gettime64(INT_MIN, "invalid"); 339 + test_one_clock_gettime64(INT_MAX, "invalid"); 318 340 } 319 341 320 342 static void test_gettimeofday(void) ··· 433 327 434 328 int main(int argc, char **argv) 435 329 { 330 + name = (const char **)&names[VDSO_NAMES]; 331 + 436 332 fill_function_pointers(); 437 333 438 334 test_clock_gettime(); 335 + test_clock_gettime64(); 439 336 test_gettimeofday(); 440 337 441 338 /*