diff options
| author | Rob Herring <robh@kernel.org> | 2018-03-08 10:21:07 -0500 |
|---|---|---|
| committer | Rob Herring <robh@kernel.org> | 2018-03-08 10:21:07 -0500 |
| commit | c679fa6e3aaa5c58fc514b5b88cfa82774b8d390 (patch) | |
| tree | 0c10b339368bd1795152a66a4e245e6f654fb3ec /tools/testing/selftests | |
| parent | bdb7013df910681f84eff27b07791d4c160cb76f (diff) | |
| parent | 4fd98e374fd377ae0458a9dc44aa779cf9631ddd (diff) | |
Merge branch 'dtc-update' into dt/next
Diffstat (limited to 'tools/testing/selftests')
| -rw-r--r-- | tools/testing/selftests/bpf/.gitignore | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/bpf/test_maps.c | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/bpf/test_tcpbpf_kern.c | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/bpf/test_verifier.c | 26 | ||||
| -rw-r--r-- | tools/testing/selftests/memfd/Makefile | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/alignment/alignment_handler.c | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/seccomp/seccomp_bpf.c | 61 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/Makefile | 24 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/mpx-mini-test.c | 32 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/protection_keys.c | 28 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/single_step_syscall.c | 5 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/test_mremap_vdso.c | 4 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/test_vdso.c | 55 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/test_vsyscall.c | 11 |
14 files changed, 202 insertions, 51 deletions
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore index cc15af2e54fe..9cf83f895d98 100644 --- a/tools/testing/selftests/bpf/.gitignore +++ b/tools/testing/selftests/bpf/.gitignore | |||
| @@ -11,3 +11,4 @@ test_progs | |||
| 11 | test_tcpbpf_user | 11 | test_tcpbpf_user |
| 12 | test_verifier_log | 12 | test_verifier_log |
| 13 | feature | 13 | feature |
| 14 | test_libbpf_open | ||
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index 436c4c72414f..9e03a4c356a4 100644 --- a/tools/testing/selftests/bpf/test_maps.c +++ b/tools/testing/selftests/bpf/test_maps.c | |||
| @@ -126,6 +126,8 @@ static void test_hashmap_sizes(int task, void *data) | |||
| 126 | fd = bpf_create_map(BPF_MAP_TYPE_HASH, i, j, | 126 | fd = bpf_create_map(BPF_MAP_TYPE_HASH, i, j, |
| 127 | 2, map_flags); | 127 | 2, map_flags); |
| 128 | if (fd < 0) { | 128 | if (fd < 0) { |
| 129 | if (errno == ENOMEM) | ||
| 130 | return; | ||
| 129 | printf("Failed to create hashmap key=%d value=%d '%s'\n", | 131 | printf("Failed to create hashmap key=%d value=%d '%s'\n", |
| 130 | i, j, strerror(errno)); | 132 | i, j, strerror(errno)); |
| 131 | exit(1); | 133 | exit(1); |
diff --git a/tools/testing/selftests/bpf/test_tcpbpf_kern.c b/tools/testing/selftests/bpf/test_tcpbpf_kern.c index 57119ad57a3f..3e645ee41ed5 100644 --- a/tools/testing/selftests/bpf/test_tcpbpf_kern.c +++ b/tools/testing/selftests/bpf/test_tcpbpf_kern.c | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #include <linux/if_ether.h> | 5 | #include <linux/if_ether.h> |
| 6 | #include <linux/if_packet.h> | 6 | #include <linux/if_packet.h> |
| 7 | #include <linux/ip.h> | 7 | #include <linux/ip.h> |
| 8 | #include <linux/in6.h> | ||
| 9 | #include <linux/types.h> | 8 | #include <linux/types.h> |
| 10 | #include <linux/socket.h> | 9 | #include <linux/socket.h> |
| 11 | #include <linux/tcp.h> | 10 | #include <linux/tcp.h> |
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index c0f16e93f9bd..c73592fa3d41 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c | |||
| @@ -2587,6 +2587,32 @@ static struct bpf_test tests[] = { | |||
| 2587 | .result = ACCEPT, | 2587 | .result = ACCEPT, |
| 2588 | }, | 2588 | }, |
| 2589 | { | 2589 | { |
| 2590 | "runtime/jit: pass negative index to tail_call", | ||
| 2591 | .insns = { | ||
| 2592 | BPF_MOV64_IMM(BPF_REG_3, -1), | ||
| 2593 | BPF_LD_MAP_FD(BPF_REG_2, 0), | ||
| 2594 | BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, | ||
| 2595 | BPF_FUNC_tail_call), | ||
| 2596 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
| 2597 | BPF_EXIT_INSN(), | ||
| 2598 | }, | ||
| 2599 | .fixup_prog = { 1 }, | ||
| 2600 | .result = ACCEPT, | ||
| 2601 | }, | ||
| 2602 | { | ||
| 2603 | "runtime/jit: pass > 32bit index to tail_call", | ||
| 2604 | .insns = { | ||
| 2605 | BPF_LD_IMM64(BPF_REG_3, 0x100000000ULL), | ||
| 2606 | BPF_LD_MAP_FD(BPF_REG_2, 0), | ||
| 2607 | BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, | ||
| 2608 | BPF_FUNC_tail_call), | ||
| 2609 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
| 2610 | BPF_EXIT_INSN(), | ||
| 2611 | }, | ||
| 2612 | .fixup_prog = { 2 }, | ||
| 2613 | .result = ACCEPT, | ||
| 2614 | }, | ||
| 2615 | { | ||
| 2590 | "stack pointer arithmetic", | 2616 | "stack pointer arithmetic", |
| 2591 | .insns = { | 2617 | .insns = { |
| 2592 | BPF_MOV64_IMM(BPF_REG_1, 4), | 2618 | BPF_MOV64_IMM(BPF_REG_1, 4), |
diff --git a/tools/testing/selftests/memfd/Makefile b/tools/testing/selftests/memfd/Makefile index a5276a91dfbf..0862e6f47a38 100644 --- a/tools/testing/selftests/memfd/Makefile +++ b/tools/testing/selftests/memfd/Makefile | |||
| @@ -5,6 +5,7 @@ CFLAGS += -I../../../../include/ | |||
| 5 | CFLAGS += -I../../../../usr/include/ | 5 | CFLAGS += -I../../../../usr/include/ |
| 6 | 6 | ||
| 7 | TEST_PROGS := run_tests.sh | 7 | TEST_PROGS := run_tests.sh |
| 8 | TEST_FILES := run_fuse_test.sh | ||
| 8 | TEST_GEN_FILES := memfd_test fuse_mnt fuse_test | 9 | TEST_GEN_FILES := memfd_test fuse_mnt fuse_test |
| 9 | 10 | ||
| 10 | fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags) | 11 | fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags) |
diff --git a/tools/testing/selftests/powerpc/alignment/alignment_handler.c b/tools/testing/selftests/powerpc/alignment/alignment_handler.c index 39fd362415cf..0f2698f9fd6d 100644 --- a/tools/testing/selftests/powerpc/alignment/alignment_handler.c +++ b/tools/testing/selftests/powerpc/alignment/alignment_handler.c | |||
| @@ -57,7 +57,7 @@ volatile int gotsig; | |||
| 57 | 57 | ||
| 58 | void sighandler(int sig, siginfo_t *info, void *ctx) | 58 | void sighandler(int sig, siginfo_t *info, void *ctx) |
| 59 | { | 59 | { |
| 60 | struct ucontext *ucp = ctx; | 60 | ucontext_t *ucp = ctx; |
| 61 | 61 | ||
| 62 | if (!testing) { | 62 | if (!testing) { |
| 63 | signal(sig, SIG_DFL); | 63 | signal(sig, SIG_DFL); |
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index 0b457e8e0f0c..5df609950a66 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c | |||
| @@ -141,6 +141,15 @@ struct seccomp_data { | |||
| 141 | #define SECCOMP_FILTER_FLAG_LOG 2 | 141 | #define SECCOMP_FILTER_FLAG_LOG 2 |
| 142 | #endif | 142 | #endif |
| 143 | 143 | ||
| 144 | #ifndef PTRACE_SECCOMP_GET_METADATA | ||
| 145 | #define PTRACE_SECCOMP_GET_METADATA 0x420d | ||
| 146 | |||
| 147 | struct seccomp_metadata { | ||
| 148 | __u64 filter_off; /* Input: which filter */ | ||
| 149 | __u64 flags; /* Output: filter's flags */ | ||
| 150 | }; | ||
| 151 | #endif | ||
| 152 | |||
| 144 | #ifndef seccomp | 153 | #ifndef seccomp |
| 145 | int seccomp(unsigned int op, unsigned int flags, void *args) | 154 | int seccomp(unsigned int op, unsigned int flags, void *args) |
| 146 | { | 155 | { |
| @@ -2845,6 +2854,58 @@ TEST(get_action_avail) | |||
| 2845 | EXPECT_EQ(errno, EOPNOTSUPP); | 2854 | EXPECT_EQ(errno, EOPNOTSUPP); |
| 2846 | } | 2855 | } |
| 2847 | 2856 | ||
| 2857 | TEST(get_metadata) | ||
| 2858 | { | ||
| 2859 | pid_t pid; | ||
| 2860 | int pipefd[2]; | ||
| 2861 | char buf; | ||
| 2862 | struct seccomp_metadata md; | ||
| 2863 | |||
| 2864 | ASSERT_EQ(0, pipe(pipefd)); | ||
| 2865 | |||
| 2866 | pid = fork(); | ||
| 2867 | ASSERT_GE(pid, 0); | ||
| 2868 | if (pid == 0) { | ||
| 2869 | struct sock_filter filter[] = { | ||
| 2870 | BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), | ||
| 2871 | }; | ||
| 2872 | struct sock_fprog prog = { | ||
| 2873 | .len = (unsigned short)ARRAY_SIZE(filter), | ||
| 2874 | .filter = filter, | ||
| 2875 | }; | ||
| 2876 | |||
| 2877 | /* one with log, one without */ | ||
| 2878 | ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, | ||
| 2879 | SECCOMP_FILTER_FLAG_LOG, &prog)); | ||
| 2880 | ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog)); | ||
| 2881 | |||
| 2882 | ASSERT_EQ(0, close(pipefd[0])); | ||
| 2883 | ASSERT_EQ(1, write(pipefd[1], "1", 1)); | ||
| 2884 | ASSERT_EQ(0, close(pipefd[1])); | ||
| 2885 | |||
| 2886 | while (1) | ||
| 2887 | sleep(100); | ||
| 2888 | } | ||
| 2889 | |||
| 2890 | ASSERT_EQ(0, close(pipefd[1])); | ||
| 2891 | ASSERT_EQ(1, read(pipefd[0], &buf, 1)); | ||
| 2892 | |||
| 2893 | ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid)); | ||
| 2894 | ASSERT_EQ(pid, waitpid(pid, NULL, 0)); | ||
| 2895 | |||
| 2896 | md.filter_off = 0; | ||
| 2897 | ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md)); | ||
| 2898 | EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG); | ||
| 2899 | EXPECT_EQ(md.filter_off, 0); | ||
| 2900 | |||
| 2901 | md.filter_off = 1; | ||
| 2902 | ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md)); | ||
| 2903 | EXPECT_EQ(md.flags, 0); | ||
| 2904 | EXPECT_EQ(md.filter_off, 1); | ||
| 2905 | |||
| 2906 | ASSERT_EQ(0, kill(pid, SIGKILL)); | ||
| 2907 | } | ||
| 2908 | |||
| 2848 | /* | 2909 | /* |
| 2849 | * TODO: | 2910 | * TODO: |
| 2850 | * - add microbenchmarks | 2911 | * - add microbenchmarks |
diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests/x86/Makefile index 10ca46df1449..d744991c0f4f 100644 --- a/tools/testing/selftests/x86/Makefile +++ b/tools/testing/selftests/x86/Makefile | |||
| @@ -5,16 +5,26 @@ include ../lib.mk | |||
| 5 | 5 | ||
| 6 | .PHONY: all all_32 all_64 warn_32bit_failure clean | 6 | .PHONY: all all_32 all_64 warn_32bit_failure clean |
| 7 | 7 | ||
| 8 | TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_syscall test_mremap_vdso \ | 8 | UNAME_M := $(shell uname -m) |
| 9 | check_initial_reg_state sigreturn ldt_gdt iopl mpx-mini-test ioperm \ | 9 | CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32) |
| 10 | CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c) | ||
| 11 | |||
| 12 | TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \ | ||
| 13 | check_initial_reg_state sigreturn iopl mpx-mini-test ioperm \ | ||
| 10 | protection_keys test_vdso test_vsyscall | 14 | protection_keys test_vdso test_vsyscall |
| 11 | TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \ | 15 | TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \ |
| 12 | test_FCMOV test_FCOMI test_FISTTP \ | 16 | test_FCMOV test_FCOMI test_FISTTP \ |
| 13 | vdso_restorer | 17 | vdso_restorer |
| 14 | TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip 5lvl | 18 | TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip |
| 19 | # Some selftests require 32bit support enabled also on 64bit systems | ||
| 20 | TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall | ||
| 15 | 21 | ||
| 16 | TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) | 22 | TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED) |
| 17 | TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY) | 23 | TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY) |
| 24 | ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11) | ||
| 25 | TARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED) | ||
| 26 | endif | ||
| 27 | |||
| 18 | BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32) | 28 | BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32) |
| 19 | BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64) | 29 | BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64) |
| 20 | 30 | ||
| @@ -23,10 +33,6 @@ BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) | |||
| 23 | 33 | ||
| 24 | CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie | 34 | CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie |
| 25 | 35 | ||
| 26 | UNAME_M := $(shell uname -m) | ||
| 27 | CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32) | ||
| 28 | CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c) | ||
| 29 | |||
| 30 | define gen-target-rule-32 | 36 | define gen-target-rule-32 |
| 31 | $(1) $(1)_32: $(OUTPUT)/$(1)_32 | 37 | $(1) $(1)_32: $(OUTPUT)/$(1)_32 |
| 32 | .PHONY: $(1) $(1)_32 | 38 | .PHONY: $(1) $(1)_32 |
| @@ -40,12 +46,14 @@ endef | |||
| 40 | ifeq ($(CAN_BUILD_I386),1) | 46 | ifeq ($(CAN_BUILD_I386),1) |
| 41 | all: all_32 | 47 | all: all_32 |
| 42 | TEST_PROGS += $(BINARIES_32) | 48 | TEST_PROGS += $(BINARIES_32) |
| 49 | EXTRA_CFLAGS += -DCAN_BUILD_32 | ||
| 43 | $(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t)))) | 50 | $(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t)))) |
| 44 | endif | 51 | endif |
| 45 | 52 | ||
| 46 | ifeq ($(CAN_BUILD_X86_64),1) | 53 | ifeq ($(CAN_BUILD_X86_64),1) |
| 47 | all: all_64 | 54 | all: all_64 |
| 48 | TEST_PROGS += $(BINARIES_64) | 55 | TEST_PROGS += $(BINARIES_64) |
| 56 | EXTRA_CFLAGS += -DCAN_BUILD_64 | ||
| 49 | $(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t)))) | 57 | $(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t)))) |
| 50 | endif | 58 | endif |
| 51 | 59 | ||
diff --git a/tools/testing/selftests/x86/mpx-mini-test.c b/tools/testing/selftests/x86/mpx-mini-test.c index ec0f6b45ce8b..9c0325e1ea68 100644 --- a/tools/testing/selftests/x86/mpx-mini-test.c +++ b/tools/testing/selftests/x86/mpx-mini-test.c | |||
| @@ -315,11 +315,39 @@ static inline void *__si_bounds_upper(siginfo_t *si) | |||
| 315 | return si->si_upper; | 315 | return si->si_upper; |
| 316 | } | 316 | } |
| 317 | #else | 317 | #else |
| 318 | |||
| 319 | /* | ||
| 320 | * This deals with old version of _sigfault in some distros: | ||
| 321 | * | ||
| 322 | |||
| 323 | old _sigfault: | ||
| 324 | struct { | ||
| 325 | void *si_addr; | ||
| 326 | } _sigfault; | ||
| 327 | |||
| 328 | new _sigfault: | ||
| 329 | struct { | ||
| 330 | void __user *_addr; | ||
| 331 | int _trapno; | ||
| 332 | short _addr_lsb; | ||
| 333 | union { | ||
| 334 | struct { | ||
| 335 | void __user *_lower; | ||
| 336 | void __user *_upper; | ||
| 337 | } _addr_bnd; | ||
| 338 | __u32 _pkey; | ||
| 339 | }; | ||
| 340 | } _sigfault; | ||
| 341 | * | ||
| 342 | */ | ||
| 343 | |||
| 318 | static inline void **__si_bounds_hack(siginfo_t *si) | 344 | static inline void **__si_bounds_hack(siginfo_t *si) |
| 319 | { | 345 | { |
| 320 | void *sigfault = &si->_sifields._sigfault; | 346 | void *sigfault = &si->_sifields._sigfault; |
| 321 | void *end_sigfault = sigfault + sizeof(si->_sifields._sigfault); | 347 | void *end_sigfault = sigfault + sizeof(si->_sifields._sigfault); |
| 322 | void **__si_lower = end_sigfault; | 348 | int *trapno = (int*)end_sigfault; |
| 349 | /* skip _trapno and _addr_lsb */ | ||
| 350 | void **__si_lower = (void**)(trapno + 2); | ||
| 323 | 351 | ||
| 324 | return __si_lower; | 352 | return __si_lower; |
| 325 | } | 353 | } |
| @@ -331,7 +359,7 @@ static inline void *__si_bounds_lower(siginfo_t *si) | |||
| 331 | 359 | ||
| 332 | static inline void *__si_bounds_upper(siginfo_t *si) | 360 | static inline void *__si_bounds_upper(siginfo_t *si) |
| 333 | { | 361 | { |
| 334 | return (*__si_bounds_hack(si)) + sizeof(void *); | 362 | return *(__si_bounds_hack(si) + 1); |
| 335 | } | 363 | } |
| 336 | #endif | 364 | #endif |
| 337 | 365 | ||
diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c index bc1b0735bb50..f15aa5a76fe3 100644 --- a/tools/testing/selftests/x86/protection_keys.c +++ b/tools/testing/selftests/x86/protection_keys.c | |||
| @@ -393,34 +393,6 @@ pid_t fork_lazy_child(void) | |||
| 393 | return forkret; | 393 | return forkret; |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | void davecmp(void *_a, void *_b, int len) | ||
| 397 | { | ||
| 398 | int i; | ||
| 399 | unsigned long *a = _a; | ||
| 400 | unsigned long *b = _b; | ||
| 401 | |||
| 402 | for (i = 0; i < len / sizeof(*a); i++) { | ||
| 403 | if (a[i] == b[i]) | ||
| 404 | continue; | ||
| 405 | |||
| 406 | dprintf3("[%3d]: a: %016lx b: %016lx\n", i, a[i], b[i]); | ||
| 407 | } | ||
| 408 | } | ||
| 409 | |||
| 410 | void dumpit(char *f) | ||
| 411 | { | ||
| 412 | int fd = open(f, O_RDONLY); | ||
| 413 | char buf[100]; | ||
| 414 | int nr_read; | ||
| 415 | |||
| 416 | dprintf2("maps fd: %d\n", fd); | ||
| 417 | do { | ||
| 418 | nr_read = read(fd, &buf[0], sizeof(buf)); | ||
| 419 | write(1, buf, nr_read); | ||
| 420 | } while (nr_read > 0); | ||
| 421 | close(fd); | ||
| 422 | } | ||
| 423 | |||
| 424 | #define PKEY_DISABLE_ACCESS 0x1 | 396 | #define PKEY_DISABLE_ACCESS 0x1 |
| 425 | #define PKEY_DISABLE_WRITE 0x2 | 397 | #define PKEY_DISABLE_WRITE 0x2 |
| 426 | 398 | ||
diff --git a/tools/testing/selftests/x86/single_step_syscall.c b/tools/testing/selftests/x86/single_step_syscall.c index a48da95c18fd..ddfdd635de16 100644 --- a/tools/testing/selftests/x86/single_step_syscall.c +++ b/tools/testing/selftests/x86/single_step_syscall.c | |||
| @@ -119,7 +119,9 @@ static void check_result(void) | |||
| 119 | 119 | ||
| 120 | int main() | 120 | int main() |
| 121 | { | 121 | { |
| 122 | #ifdef CAN_BUILD_32 | ||
| 122 | int tmp; | 123 | int tmp; |
| 124 | #endif | ||
| 123 | 125 | ||
| 124 | sethandler(SIGTRAP, sigtrap, 0); | 126 | sethandler(SIGTRAP, sigtrap, 0); |
| 125 | 127 | ||
| @@ -139,12 +141,13 @@ int main() | |||
| 139 | : : "c" (post_nop) : "r11"); | 141 | : : "c" (post_nop) : "r11"); |
| 140 | check_result(); | 142 | check_result(); |
| 141 | #endif | 143 | #endif |
| 142 | 144 | #ifdef CAN_BUILD_32 | |
| 143 | printf("[RUN]\tSet TF and check int80\n"); | 145 | printf("[RUN]\tSet TF and check int80\n"); |
| 144 | set_eflags(get_eflags() | X86_EFLAGS_TF); | 146 | set_eflags(get_eflags() | X86_EFLAGS_TF); |
| 145 | asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid) | 147 | asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid) |
| 146 | : INT80_CLOBBERS); | 148 | : INT80_CLOBBERS); |
| 147 | check_result(); | 149 | check_result(); |
| 150 | #endif | ||
| 148 | 151 | ||
| 149 | /* | 152 | /* |
| 150 | * This test is particularly interesting if fast syscalls use | 153 | * This test is particularly interesting if fast syscalls use |
diff --git a/tools/testing/selftests/x86/test_mremap_vdso.c b/tools/testing/selftests/x86/test_mremap_vdso.c index bf0d687c7db7..64f11c8d9b76 100644 --- a/tools/testing/selftests/x86/test_mremap_vdso.c +++ b/tools/testing/selftests/x86/test_mremap_vdso.c | |||
| @@ -90,8 +90,12 @@ int main(int argc, char **argv, char **envp) | |||
| 90 | vdso_size += PAGE_SIZE; | 90 | vdso_size += PAGE_SIZE; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | #ifdef __i386__ | ||
| 93 | /* Glibc is likely to explode now - exit with raw syscall */ | 94 | /* Glibc is likely to explode now - exit with raw syscall */ |
| 94 | asm volatile ("int $0x80" : : "a" (__NR_exit), "b" (!!ret)); | 95 | asm volatile ("int $0x80" : : "a" (__NR_exit), "b" (!!ret)); |
| 96 | #else /* __x86_64__ */ | ||
| 97 | syscall(SYS_exit, ret); | ||
| 98 | #endif | ||
| 95 | } else { | 99 | } else { |
| 96 | int status; | 100 | int status; |
| 97 | 101 | ||
diff --git a/tools/testing/selftests/x86/test_vdso.c b/tools/testing/selftests/x86/test_vdso.c index 29973cde06d3..235259011704 100644 --- a/tools/testing/selftests/x86/test_vdso.c +++ b/tools/testing/selftests/x86/test_vdso.c | |||
| @@ -26,20 +26,59 @@ | |||
| 26 | # endif | 26 | # endif |
| 27 | #endif | 27 | #endif |
| 28 | 28 | ||
| 29 | /* max length of lines in /proc/self/maps - anything longer is skipped here */ | ||
| 30 | #define MAPS_LINE_LEN 128 | ||
| 31 | |||
| 29 | int nerrs = 0; | 32 | int nerrs = 0; |
| 30 | 33 | ||
| 34 | typedef long (*getcpu_t)(unsigned *, unsigned *, void *); | ||
| 35 | |||
| 36 | getcpu_t vgetcpu; | ||
| 37 | getcpu_t vdso_getcpu; | ||
| 38 | |||
| 39 | static void *vsyscall_getcpu(void) | ||
| 40 | { | ||
| 31 | #ifdef __x86_64__ | 41 | #ifdef __x86_64__ |
| 32 | # define VSYS(x) (x) | 42 | FILE *maps; |
| 43 | char line[MAPS_LINE_LEN]; | ||
| 44 | bool found = false; | ||
| 45 | |||
| 46 | maps = fopen("/proc/self/maps", "r"); | ||
| 47 | if (!maps) /* might still be present, but ignore it here, as we test vDSO not vsyscall */ | ||
| 48 | return NULL; | ||
| 49 | |||
| 50 | while (fgets(line, MAPS_LINE_LEN, maps)) { | ||
| 51 | char r, x; | ||
| 52 | void *start, *end; | ||
| 53 | char name[MAPS_LINE_LEN]; | ||
| 54 | |||
| 55 | /* sscanf() is safe here as strlen(name) >= strlen(line) */ | ||
| 56 | if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s", | ||
| 57 | &start, &end, &r, &x, name) != 5) | ||
| 58 | continue; | ||
| 59 | |||
| 60 | if (strcmp(name, "[vsyscall]")) | ||
| 61 | continue; | ||
| 62 | |||
| 63 | /* assume entries are OK, as we test vDSO here not vsyscall */ | ||
| 64 | found = true; | ||
| 65 | break; | ||
| 66 | } | ||
| 67 | |||
| 68 | fclose(maps); | ||
| 69 | |||
| 70 | if (!found) { | ||
| 71 | printf("Warning: failed to find vsyscall getcpu\n"); | ||
| 72 | return NULL; | ||
| 73 | } | ||
| 74 | return (void *) (0xffffffffff600800); | ||
| 33 | #else | 75 | #else |
| 34 | # define VSYS(x) 0 | 76 | return NULL; |
| 35 | #endif | 77 | #endif |
| 78 | } | ||
| 36 | 79 | ||
| 37 | typedef long (*getcpu_t)(unsigned *, unsigned *, void *); | ||
| 38 | |||
| 39 | const getcpu_t vgetcpu = (getcpu_t)VSYS(0xffffffffff600800); | ||
| 40 | getcpu_t vdso_getcpu; | ||
| 41 | 80 | ||
| 42 | void fill_function_pointers() | 81 | static void fill_function_pointers() |
| 43 | { | 82 | { |
| 44 | void *vdso = dlopen("linux-vdso.so.1", | 83 | void *vdso = dlopen("linux-vdso.so.1", |
| 45 | RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD); | 84 | RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD); |
| @@ -54,6 +93,8 @@ void fill_function_pointers() | |||
| 54 | vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu"); | 93 | vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu"); |
| 55 | if (!vdso_getcpu) | 94 | if (!vdso_getcpu) |
| 56 | printf("Warning: failed to find getcpu in vDSO\n"); | 95 | printf("Warning: failed to find getcpu in vDSO\n"); |
| 96 | |||
| 97 | vgetcpu = (getcpu_t) vsyscall_getcpu(); | ||
| 57 | } | 98 | } |
| 58 | 99 | ||
| 59 | static long sys_getcpu(unsigned * cpu, unsigned * node, | 100 | static long sys_getcpu(unsigned * cpu, unsigned * node, |
diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/selftests/x86/test_vsyscall.c index 7a744fa7b786..be81621446f0 100644 --- a/tools/testing/selftests/x86/test_vsyscall.c +++ b/tools/testing/selftests/x86/test_vsyscall.c | |||
| @@ -33,6 +33,9 @@ | |||
| 33 | # endif | 33 | # endif |
| 34 | #endif | 34 | #endif |
| 35 | 35 | ||
| 36 | /* max length of lines in /proc/self/maps - anything longer is skipped here */ | ||
| 37 | #define MAPS_LINE_LEN 128 | ||
| 38 | |||
| 36 | static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *), | 39 | static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *), |
| 37 | int flags) | 40 | int flags) |
| 38 | { | 41 | { |
| @@ -98,7 +101,7 @@ static int init_vsys(void) | |||
| 98 | #ifdef __x86_64__ | 101 | #ifdef __x86_64__ |
| 99 | int nerrs = 0; | 102 | int nerrs = 0; |
| 100 | FILE *maps; | 103 | FILE *maps; |
| 101 | char line[128]; | 104 | char line[MAPS_LINE_LEN]; |
| 102 | bool found = false; | 105 | bool found = false; |
| 103 | 106 | ||
| 104 | maps = fopen("/proc/self/maps", "r"); | 107 | maps = fopen("/proc/self/maps", "r"); |
| @@ -108,10 +111,12 @@ static int init_vsys(void) | |||
| 108 | return 0; | 111 | return 0; |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | while (fgets(line, sizeof(line), maps)) { | 114 | while (fgets(line, MAPS_LINE_LEN, maps)) { |
| 112 | char r, x; | 115 | char r, x; |
| 113 | void *start, *end; | 116 | void *start, *end; |
| 114 | char name[128]; | 117 | char name[MAPS_LINE_LEN]; |
| 118 | |||
| 119 | /* sscanf() is safe here as strlen(name) >= strlen(line) */ | ||
| 115 | if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s", | 120 | if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s", |
| 116 | &start, &end, &r, &x, name) != 5) | 121 | &start, &end, &r, &x, name) != 5) |
| 117 | continue; | 122 | continue; |
