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

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

Pull kselftest updates from Shuah Khan:
"This 12 patch update for 4.4-rc1 consists of a new pstore test and
fixes to existing tests"

* tag 'linux-kselftest-4.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
selftests: breakpoint: Actually build it
selftests: vm: Try harder to allocate huge pages
selftests: Make scripts executable
selftests: kprobe: Choose an always-defined function to probe
selftests: memfd: Stop unnecessary rebuilds
selftests: Add missing #include directives
selftests/seccomp: Be more precise with syscall arguments.
selftests/seccomp: build and pass on arm64
selftests: memfd_test: Revised STACK_SIZE to make it 16-byte aligned
selftests/pstore: add pstore test scripts going with reboot
selftests/pstore: add pstore test script for pre-reboot
selftests: add .gitignore for efivarfs

+362 -53
+4
tools/testing/selftests/Makefile
··· 14 14 TARGETS += mqueue 15 15 TARGETS += net 16 16 TARGETS += powerpc 17 + TARGETS += pstore 17 18 TARGETS += ptrace 18 19 TARGETS += seccomp 19 20 TARGETS += size ··· 66 65 for TARGET in $(TARGETS_HOTPLUG); do \ 67 66 make -C $$TARGET clean; \ 68 67 done; 68 + 69 + run_pstore_crash: 70 + make -C pstore run_crash 69 71 70 72 INSTALL_PATH ?= install 71 73 INSTALL_PATH := $(abspath $(INSTALL_PATH))
+1 -1
tools/testing/selftests/breakpoints/Makefile
··· 6 6 TEST_PROGS := breakpoint_test 7 7 endif 8 8 9 - all: 9 + all: $(TEST_PROGS) 10 10 11 11 include ../lib.mk 12 12
+2
tools/testing/selftests/efivarfs/.gitignore
··· 1 + create-read 2 + open-unlink
+1 -1
tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc
··· 5 5 6 6 echo 0 > events/enable 7 7 echo > kprobe_events 8 - echo p:myevent do_fork > kprobe_events 8 + echo p:myevent _do_fork > kprobe_events 9 9 grep myevent kprobe_events 10 10 test -d events/kprobes/myevent 11 11 echo > kprobe_events
+1 -1
tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc
··· 5 5 6 6 echo 0 > events/enable 7 7 echo > kprobe_events 8 - echo p:myevent do_fork > kprobe_events 8 + echo p:myevent _do_fork > kprobe_events 9 9 test -d events/kprobes/myevent 10 10 echo 1 > events/kprobes/myevent/enable 11 11 echo > kprobe_events && exit 1 # this must fail
+1 -1
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc
··· 5 5 6 6 echo 0 > events/enable 7 7 echo > kprobe_events 8 - echo 'p:testprobe do_fork $stack $stack0 +0($stack)' > kprobe_events 8 + echo 'p:testprobe _do_fork $stack $stack0 +0($stack)' > kprobe_events 9 9 grep testprobe kprobe_events 10 10 test -d events/kprobes/testprobe 11 11 echo 1 > events/kprobes/testprobe/enable
+7 -7
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_ftrace.tc
··· 6 6 7 7 # prepare 8 8 echo nop > current_tracer 9 - echo do_fork > set_ftrace_filter 9 + echo _do_fork > set_ftrace_filter 10 10 echo 0 > events/enable 11 11 echo > kprobe_events 12 - echo 'p:testprobe do_fork' > kprobe_events 12 + echo 'p:testprobe _do_fork' > kprobe_events 13 13 14 14 # kprobe on / ftrace off 15 15 echo 1 > events/kprobes/testprobe/enable 16 16 echo > trace 17 17 ( echo "forked") 18 18 grep testprobe trace 19 - ! grep 'do_fork <-' trace 19 + ! grep '_do_fork <-' trace 20 20 21 21 # kprobe on / ftrace on 22 22 echo function > current_tracer 23 23 echo > trace 24 24 ( echo "forked") 25 25 grep testprobe trace 26 - grep 'do_fork <-' trace 26 + grep '_do_fork <-' trace 27 27 28 28 # kprobe off / ftrace on 29 29 echo 0 > events/kprobes/testprobe/enable 30 30 echo > trace 31 31 ( echo "forked") 32 32 ! grep testprobe trace 33 - grep 'do_fork <-' trace 33 + grep '_do_fork <-' trace 34 34 35 35 # kprobe on / ftrace on 36 36 echo 1 > events/kprobes/testprobe/enable ··· 38 38 echo > trace 39 39 ( echo "forked") 40 40 grep testprobe trace 41 - grep 'do_fork <-' trace 41 + grep '_do_fork <-' trace 42 42 43 43 # kprobe on / ftrace off 44 44 echo nop > current_tracer 45 45 echo > trace 46 46 ( echo "forked") 47 47 grep testprobe trace 48 - ! grep 'do_fork <-' trace 48 + ! grep '_do_fork <-' trace 49 49 50 50 # cleanup 51 51 echo nop > current_tracer
+1 -1
tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc
··· 5 5 6 6 echo 0 > events/enable 7 7 echo > kprobe_events 8 - echo 'r:testprobe2 do_fork $retval' > kprobe_events 8 + echo 'r:testprobe2 _do_fork $retval' > kprobe_events 9 9 grep testprobe2 kprobe_events 10 10 test -d events/kprobes/testprobe2 11 11 echo 1 > events/kprobes/testprobe2/enable
+6 -6
tools/testing/selftests/memfd/Makefile
··· 4 4 CFLAGS += -I../../../../include/ 5 5 CFLAGS += -I../../../../usr/include/ 6 6 7 - all: 8 - $(CC) $(CFLAGS) memfd_test.c -o memfd_test 9 - 10 7 TEST_PROGS := memfd_test 8 + 9 + all: $(TEST_PROGS) 11 10 12 11 include ../lib.mk 13 12 14 - build_fuse: 15 - $(CC) $(CFLAGS) fuse_mnt.c `pkg-config fuse --cflags --libs` -o fuse_mnt 16 - $(CC) $(CFLAGS) fuse_test.c -o fuse_test 13 + build_fuse: fuse_mnt fuse_test 14 + 15 + fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags) 16 + fuse_mnt: LDFLAGS += $(shell pkg-config fuse --libs) 17 17 18 18 run_fuse: build_fuse 19 19 @./run_fuse_test.sh || echo "fuse_test: [FAIL]"
+2 -1
tools/testing/selftests/memfd/memfd_test.c
··· 15 15 #include <sys/mman.h> 16 16 #include <sys/stat.h> 17 17 #include <sys/syscall.h> 18 + #include <sys/wait.h> 18 19 #include <unistd.h> 19 20 20 21 #define MFD_DEF_SIZE 8192 21 - #define STACK_SIZE 65535 22 + #define STACK_SIZE 65536 22 23 23 24 static int sys_memfd_create(const char *name, 24 25 unsigned int flags)
tools/testing/selftests/memfd/run_fuse_test.sh
+1
tools/testing/selftests/mqueue/mq_open_tests.c
··· 31 31 #include <sys/resource.h> 32 32 #include <sys/stat.h> 33 33 #include <mqueue.h> 34 + #include <error.h> 34 35 35 36 static char *usage = 36 37 "Usage:\n"
+1
tools/testing/selftests/mqueue/mq_perf_tests.c
··· 37 37 #include <sys/stat.h> 38 38 #include <mqueue.h> 39 39 #include <popt.h> 40 + #include <error.h> 40 41 41 42 static char *usage = 42 43 "Usage:\n"
+15
tools/testing/selftests/pstore/Makefile
··· 1 + # Makefile for pstore selftests. 2 + # Expects pstore backend is registered. 3 + 4 + all: 5 + 6 + TEST_PROGS := pstore_tests pstore_post_reboot_tests 7 + TEST_FILES := common_tests pstore_crash_test 8 + 9 + include ../lib.mk 10 + 11 + run_crash: 12 + @sh pstore_crash_test || { echo "pstore_crash_test: [FAIL]"; exit 1; } 13 + 14 + clean: 15 + rm -rf logs/* *uuid
+83
tools/testing/selftests/pstore/common_tests
··· 1 + #!/bin/sh 2 + 3 + # common_tests - Shell script commonly used by pstore test scripts 4 + # 5 + # Copyright (C) Hitachi Ltd., 2015 6 + # Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com> 7 + # 8 + # Released under the terms of the GPL v2. 9 + 10 + # Utilities 11 + errexit() { # message 12 + echo "Error: $1" 1>&2 13 + exit 1 14 + } 15 + 16 + absdir() { # file_path 17 + (cd `dirname $1`; pwd) 18 + } 19 + 20 + show_result() { # result_value 21 + if [ $1 -eq 0 ]; then 22 + prlog "ok" 23 + else 24 + prlog "FAIL" 25 + rc=1 26 + fi 27 + } 28 + 29 + check_files_exist() { # type of pstorefs file 30 + if [ -e ${1}-${backend}-0 ]; then 31 + prlog "ok" 32 + for f in `ls ${1}-${backend}-*`; do 33 + prlog -e "\t${f}" 34 + done 35 + else 36 + prlog "FAIL" 37 + rc=1 38 + fi 39 + } 40 + 41 + operate_files() { # tested value, files, operation 42 + if [ $1 -eq 0 ]; then 43 + prlog 44 + for f in $2; do 45 + prlog -ne "\t${f} ... " 46 + # execute operation 47 + $3 $f 48 + show_result $? 49 + done 50 + else 51 + prlog " ... FAIL" 52 + rc=1 53 + fi 54 + } 55 + 56 + # Parameters 57 + TEST_STRING_PATTERN="Testing pstore: uuid=" 58 + UUID=`cat /proc/sys/kernel/random/uuid` 59 + TOP_DIR=`absdir $0` 60 + LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`_${UUID}/ 61 + REBOOT_FLAG=$TOP_DIR/reboot_flag 62 + 63 + # Preparing logs 64 + LOG_FILE=$LOG_DIR/`basename $0`.log 65 + mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" 66 + date > $LOG_FILE 67 + prlog() { # messages 68 + /bin/echo "$@" | tee -a $LOG_FILE 69 + } 70 + 71 + # Starting tests 72 + rc=0 73 + prlog "=== Pstore unit tests (`basename $0`) ===" 74 + prlog "UUID="$UUID 75 + 76 + prlog -n "Checking pstore backend is registered ... " 77 + backend=`cat /sys/module/pstore/parameters/backend` 78 + show_result $? 79 + prlog -e "\tbackend=${backend}" 80 + prlog -e "\tcmdline=`cat /proc/cmdline`" 81 + if [ $rc -ne 0 ]; then 82 + exit 1 83 + fi
+30
tools/testing/selftests/pstore/pstore_crash_test
··· 1 + #!/bin/sh 2 + 3 + # pstore_crash_test - Pstore test shell script which causes crash and reboot 4 + # 5 + # Copyright (C) Hitachi Ltd., 2015 6 + # Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com> 7 + # 8 + # Released under the terms of the GPL v2. 9 + 10 + # exit if pstore backend is not registered 11 + . ./common_tests 12 + 13 + prlog "Causing kernel crash ..." 14 + 15 + # enable all functions triggered by sysrq 16 + echo 1 > /proc/sys/kernel/sysrq 17 + # setting to reboot in 3 seconds after panic 18 + echo 3 > /proc/sys/kernel/panic 19 + 20 + # save uuid file by different name because next test execution will replace it. 21 + mv $TOP_DIR/uuid $TOP_DIR/prev_uuid 22 + 23 + # create a file as reboot flag 24 + touch $REBOOT_FLAG 25 + sync 26 + 27 + # cause crash 28 + # Note: If you use kdump and want to see kmesg-* files after reboot, you should 29 + # specify 'crash_kexec_post_notifiers' in 1st kernel's cmdline. 30 + echo c > /proc/sysrq-trigger
+77
tools/testing/selftests/pstore/pstore_post_reboot_tests
··· 1 + #!/bin/sh 2 + 3 + # pstore_post_reboot_tests - Check pstore's behavior after crash/reboot 4 + # 5 + # Copyright (C) Hitachi Ltd., 2015 6 + # Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com> 7 + # 8 + # Released under the terms of the GPL v2. 9 + 10 + . ./common_tests 11 + 12 + if [ -e $REBOOT_FLAG ]; then 13 + rm $REBOOT_FLAG 14 + else 15 + prlog "pstore_crash_test has not been executed yet. we skip further tests." 16 + exit 0 17 + fi 18 + 19 + prlog -n "Mounting pstore filesystem ... " 20 + mount_info=`grep pstore /proc/mounts` 21 + if [ $? -eq 0 ]; then 22 + mount_point=`echo ${mount_info} | cut -d' ' -f2 | head -n1` 23 + prlog "ok" 24 + else 25 + mount none /sys/fs/pstore -t pstore 26 + if [ $? -eq 0 ]; then 27 + mount_point=`grep pstore /proc/mounts | cut -d' ' -f2 | head -n1` 28 + prlog "ok" 29 + else 30 + prlog "FAIL" 31 + exit 1 32 + fi 33 + fi 34 + 35 + cd ${mount_point} 36 + 37 + prlog -n "Checking dmesg files exist in pstore filesystem ... " 38 + check_files_exist dmesg 39 + 40 + prlog -n "Checking console files exist in pstore filesystem ... " 41 + check_files_exist console 42 + 43 + prlog -n "Checking pmsg files exist in pstore filesystem ... " 44 + check_files_exist pmsg 45 + 46 + prlog -n "Checking dmesg files contain oops end marker" 47 + grep_end_trace() { 48 + grep -q "\---\[ end trace" $1 49 + } 50 + files=`ls dmesg-${backend}-*` 51 + operate_files $? "$files" grep_end_trace 52 + 53 + prlog -n "Checking console file contains oops end marker ... " 54 + grep -q "\---\[ end trace" console-${backend}-0 55 + show_result $? 56 + 57 + prlog -n "Checking pmsg file properly keeps the content written before crash ... " 58 + prev_uuid=`cat $TOP_DIR/prev_uuid` 59 + if [ $? -eq 0 ]; then 60 + nr_matched=`grep -c "$TEST_STRING_PATTERN" pmsg-${backend}-0` 61 + if [ $nr_matched -eq 1 ]; then 62 + grep -q "$TEST_STRING_PATTERN"$prev_uuid pmsg-${backend}-0 63 + show_result $? 64 + else 65 + prlog "FAIL" 66 + rc=1 67 + fi 68 + else 69 + prlog "FAIL" 70 + rc=1 71 + fi 72 + 73 + prlog -n "Removing all files in pstore filesystem " 74 + files=`ls *-${backend}-*` 75 + operate_files $? "$files" rm 76 + 77 + exit $rc
+30
tools/testing/selftests/pstore/pstore_tests
··· 1 + #!/bin/sh 2 + 3 + # pstore_tests - Check pstore's behavior before crash/reboot 4 + # 5 + # Copyright (C) Hitachi Ltd., 2015 6 + # Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com> 7 + # 8 + # Released under the terms of the GPL v2. 9 + 10 + . ./common_tests 11 + 12 + prlog -n "Checking pstore console is registered ... " 13 + dmesg | grep -q "console \[pstore" 14 + show_result $? 15 + 16 + prlog -n "Checking /dev/pmsg0 exists ... " 17 + test -e /dev/pmsg0 18 + show_result $? 19 + 20 + prlog -n "Writing unique string to /dev/pmsg0 ... " 21 + if [ -e "/dev/pmsg0" ]; then 22 + echo "${TEST_STRING_PATTERN}""$UUID" > /dev/pmsg0 23 + show_result $? 24 + echo "$UUID" > $TOP_DIR/uuid 25 + else 26 + prlog "FAIL" 27 + rc=1 28 + fi 29 + 30 + exit $rc
+84 -33
tools/testing/selftests/seccomp/seccomp_bpf.c
··· 19 19 #include <linux/prctl.h> 20 20 #include <linux/ptrace.h> 21 21 #include <linux/seccomp.h> 22 - #include <poll.h> 23 22 #include <pthread.h> 24 23 #include <semaphore.h> 25 24 #include <signal.h> 26 25 #include <stddef.h> 27 26 #include <stdbool.h> 28 27 #include <string.h> 28 + #include <time.h> 29 29 #include <linux/elf.h> 30 30 #include <sys/uio.h> 31 + #include <sys/utsname.h> 32 + #include <sys/fcntl.h> 33 + #include <sys/mman.h> 34 + #include <sys/times.h> 31 35 32 36 #define _GNU_SOURCE 33 37 #include <unistd.h> ··· 432 428 433 429 TEST_SIGNAL(KILL_one_arg_one, SIGSYS) 434 430 { 431 + void *fatal_address; 435 432 struct sock_filter filter[] = { 436 433 BPF_STMT(BPF_LD|BPF_W|BPF_ABS, 437 434 offsetof(struct seccomp_data, nr)), 438 - BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_getpid, 1, 0), 435 + BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_times, 1, 0), 439 436 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), 440 437 /* Only both with lower 32-bit for now. */ 441 438 BPF_STMT(BPF_LD|BPF_W|BPF_ABS, syscall_arg(0)), 442 - BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, 0x0C0FFEE, 0, 1), 439 + BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, 440 + (unsigned long)&fatal_address, 0, 1), 443 441 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL), 444 442 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), 445 443 }; ··· 451 445 }; 452 446 long ret; 453 447 pid_t parent = getppid(); 454 - pid_t pid = getpid(); 448 + struct tms timebuf; 449 + clock_t clock = times(&timebuf); 455 450 456 451 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); 457 452 ASSERT_EQ(0, ret); ··· 461 454 ASSERT_EQ(0, ret); 462 455 463 456 EXPECT_EQ(parent, syscall(__NR_getppid)); 464 - EXPECT_EQ(pid, syscall(__NR_getpid)); 465 - /* getpid() should never return. */ 466 - EXPECT_EQ(0, syscall(__NR_getpid, 0x0C0FFEE)); 457 + EXPECT_LE(clock, syscall(__NR_times, &timebuf)); 458 + /* times() should never return. */ 459 + EXPECT_EQ(0, syscall(__NR_times, &fatal_address)); 467 460 } 468 461 469 462 TEST_SIGNAL(KILL_one_arg_six, SIGSYS) 470 463 { 464 + #ifndef __NR_mmap2 465 + int sysno = __NR_mmap; 466 + #else 467 + int sysno = __NR_mmap2; 468 + #endif 471 469 struct sock_filter filter[] = { 472 470 BPF_STMT(BPF_LD|BPF_W|BPF_ABS, 473 471 offsetof(struct seccomp_data, nr)), 474 - BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_getpid, 1, 0), 472 + BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, sysno, 1, 0), 475 473 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), 476 474 /* Only both with lower 32-bit for now. */ 477 475 BPF_STMT(BPF_LD|BPF_W|BPF_ABS, syscall_arg(5)), ··· 490 478 }; 491 479 long ret; 492 480 pid_t parent = getppid(); 493 - pid_t pid = getpid(); 481 + int fd; 482 + void *map1, *map2; 494 483 495 484 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); 496 485 ASSERT_EQ(0, ret); ··· 499 486 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog); 500 487 ASSERT_EQ(0, ret); 501 488 489 + fd = open("/dev/zero", O_RDONLY); 490 + ASSERT_NE(-1, fd); 491 + 502 492 EXPECT_EQ(parent, syscall(__NR_getppid)); 503 - EXPECT_EQ(pid, syscall(__NR_getpid)); 504 - /* getpid() should never return. */ 505 - EXPECT_EQ(0, syscall(__NR_getpid, 1, 2, 3, 4, 5, 0x0C0FFEE)); 493 + map1 = (void *)syscall(sysno, 494 + NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, fd, PAGE_SIZE); 495 + EXPECT_NE(MAP_FAILED, map1); 496 + /* mmap2() should never return. */ 497 + map2 = (void *)syscall(sysno, 498 + NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, fd, 0x0C0FFEE); 499 + EXPECT_EQ(MAP_FAILED, map2); 500 + 501 + /* The test failed, so clean up the resources. */ 502 + munmap(map1, PAGE_SIZE); 503 + munmap(map2, PAGE_SIZE); 504 + close(fd); 506 505 } 507 506 508 507 /* TODO(wad) add 64-bit versus 32-bit arg tests. */ ··· 1272 1247 ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov); 1273 1248 EXPECT_EQ(0, ret); 1274 1249 1275 - #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \ 1276 - defined(__powerpc__) || defined(__s390__) 1250 + #if defined(__x86_64__) || defined(__i386__) || defined(__powerpc__) || \ 1251 + defined(__s390__) 1277 1252 { 1278 1253 regs.SYSCALL_NUM = syscall; 1279 1254 } ··· 1287 1262 EXPECT_EQ(0, ret); 1288 1263 } 1289 1264 1265 + #elif defined(__aarch64__) 1266 + # ifndef NT_ARM_SYSTEM_CALL 1267 + # define NT_ARM_SYSTEM_CALL 0x404 1268 + # endif 1269 + { 1270 + iov.iov_base = &syscall; 1271 + iov.iov_len = sizeof(syscall); 1272 + ret = ptrace(PTRACE_SETREGSET, tracee, NT_ARM_SYSTEM_CALL, 1273 + &iov); 1274 + EXPECT_EQ(0, ret); 1275 + } 1276 + 1290 1277 #else 1291 1278 ASSERT_EQ(1, 0) { 1292 1279 TH_LOG("How is the syscall changed on this architecture?"); ··· 1309 1272 if (syscall == -1) 1310 1273 regs.SYSCALL_RET = 1; 1311 1274 1275 + iov.iov_base = &regs; 1276 + iov.iov_len = sizeof(regs); 1312 1277 ret = ptrace(PTRACE_SETREGSET, tracee, NT_PRSTATUS, &iov); 1313 1278 EXPECT_EQ(0, ret); 1314 1279 } ··· 2044 2005 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_read, 5, 0), 2045 2006 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_exit, 4, 0), 2046 2007 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_rt_sigreturn, 3, 0), 2047 - BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_poll, 4, 0), 2008 + BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_nanosleep, 4, 0), 2048 2009 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_restart_syscall, 4, 0), 2049 2010 2050 2011 /* Allow __NR_write for easy logging. */ 2051 2012 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_write, 0, 1), 2052 2013 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), 2053 2014 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL), 2054 - BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE|0x100), /* poll */ 2055 - BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE|0x200), /* restart */ 2015 + /* The nanosleep jump target. */ 2016 + BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE|0x100), 2017 + /* The restart_syscall jump target. */ 2018 + BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE|0x200), 2056 2019 }; 2057 2020 struct sock_fprog prog = { 2058 2021 .len = (unsigned short)ARRAY_SIZE(filter), 2059 2022 .filter = filter, 2060 2023 }; 2024 + #if defined(__arm__) 2025 + struct utsname utsbuf; 2026 + #endif 2061 2027 2062 2028 ASSERT_EQ(0, pipe(pipefd)); 2063 2029 ··· 2071 2027 if (child_pid == 0) { 2072 2028 /* Child uses EXPECT not ASSERT to deliver status correctly. */ 2073 2029 char buf = ' '; 2074 - struct pollfd fds = { 2075 - .fd = pipefd[0], 2076 - .events = POLLIN, 2077 - }; 2030 + struct timespec timeout = { }; 2078 2031 2079 2032 /* Attach parent as tracer and stop. */ 2080 2033 EXPECT_EQ(0, ptrace(PTRACE_TRACEME)); ··· 2095 2054 TH_LOG("Failed to get sync data from read()"); 2096 2055 } 2097 2056 2098 - /* Start poll to be interrupted. */ 2057 + /* Start nanosleep to be interrupted. */ 2058 + timeout.tv_sec = 1; 2099 2059 errno = 0; 2100 - EXPECT_EQ(1, poll(&fds, 1, -1)) { 2101 - TH_LOG("Call to poll() failed (errno %d)", errno); 2060 + EXPECT_EQ(0, nanosleep(&timeout, NULL)) { 2061 + TH_LOG("Call to nanosleep() failed (errno %d)", errno); 2102 2062 } 2103 2063 2104 2064 /* Read final sync from parent. */ ··· 2124 2082 ASSERT_EQ(0, ptrace(PTRACE_CONT, child_pid, NULL, 0)); 2125 2083 ASSERT_EQ(1, write(pipefd[1], ".", 1)); 2126 2084 2127 - /* Wait for poll() to start. */ 2085 + /* Wait for nanosleep() to start. */ 2128 2086 ASSERT_EQ(child_pid, waitpid(child_pid, &status, 0)); 2129 2087 ASSERT_EQ(true, WIFSTOPPED(status)); 2130 2088 ASSERT_EQ(SIGTRAP, WSTOPSIG(status)); 2131 2089 ASSERT_EQ(PTRACE_EVENT_SECCOMP, (status >> 16)); 2132 2090 ASSERT_EQ(0, ptrace(PTRACE_GETEVENTMSG, child_pid, NULL, &msg)); 2133 2091 ASSERT_EQ(0x100, msg); 2134 - EXPECT_EQ(__NR_poll, get_syscall(_metadata, child_pid)); 2092 + EXPECT_EQ(__NR_nanosleep, get_syscall(_metadata, child_pid)); 2135 2093 2136 2094 /* Might as well check siginfo for sanity while we're here. */ 2137 2095 ASSERT_EQ(0, ptrace(PTRACE_GETSIGINFO, child_pid, NULL, &info)); ··· 2142 2100 /* Verify signal delivery came from child (seccomp-triggered). */ 2143 2101 EXPECT_EQ(child_pid, info.si_pid); 2144 2102 2145 - /* Interrupt poll with SIGSTOP (which we'll need to handle). */ 2103 + /* Interrupt nanosleep with SIGSTOP (which we'll need to handle). */ 2146 2104 ASSERT_EQ(0, kill(child_pid, SIGSTOP)); 2147 2105 ASSERT_EQ(0, ptrace(PTRACE_CONT, child_pid, NULL, 0)); 2148 2106 ASSERT_EQ(child_pid, waitpid(child_pid, &status, 0)); ··· 2152 2110 ASSERT_EQ(0, ptrace(PTRACE_GETSIGINFO, child_pid, NULL, &info)); 2153 2111 EXPECT_EQ(getpid(), info.si_pid); 2154 2112 2155 - /* Restart poll with SIGCONT, which triggers restart_syscall. */ 2113 + /* Restart nanosleep with SIGCONT, which triggers restart_syscall. */ 2156 2114 ASSERT_EQ(0, kill(child_pid, SIGCONT)); 2157 2115 ASSERT_EQ(0, ptrace(PTRACE_CONT, child_pid, NULL, 0)); 2158 2116 ASSERT_EQ(child_pid, waitpid(child_pid, &status, 0)); ··· 2166 2124 ASSERT_EQ(SIGTRAP, WSTOPSIG(status)); 2167 2125 ASSERT_EQ(PTRACE_EVENT_SECCOMP, (status >> 16)); 2168 2126 ASSERT_EQ(0, ptrace(PTRACE_GETEVENTMSG, child_pid, NULL, &msg)); 2127 + 2169 2128 ASSERT_EQ(0x200, msg); 2170 2129 ret = get_syscall(_metadata, child_pid); 2171 2130 #if defined(__arm__) 2172 - /* FIXME: ARM does not expose true syscall in registers. */ 2173 - EXPECT_EQ(__NR_poll, ret); 2174 - #else 2175 - EXPECT_EQ(__NR_restart_syscall, ret); 2131 + /* 2132 + * FIXME: 2133 + * - native ARM registers do NOT expose true syscall. 2134 + * - compat ARM registers on ARM64 DO expose true syscall. 2135 + */ 2136 + ASSERT_EQ(0, uname(&utsbuf)); 2137 + if (strncmp(utsbuf.machine, "arm", 3) == 0) { 2138 + EXPECT_EQ(__NR_nanosleep, ret); 2139 + } else 2176 2140 #endif 2141 + { 2142 + EXPECT_EQ(__NR_restart_syscall, ret); 2143 + } 2177 2144 2178 - /* Write again to end poll. */ 2145 + /* Write again to end test. */ 2179 2146 ASSERT_EQ(0, ptrace(PTRACE_CONT, child_pid, NULL, 0)); 2180 2147 ASSERT_EQ(1, write(pipefd[1], "!", 1)); 2181 2148 EXPECT_EQ(0, close(pipefd[1]));
tools/testing/selftests/static_keys/test_static_keys.sh
+1
tools/testing/selftests/timers/nanosleep.c
··· 19 19 * GNU General Public License for more details. 20 20 */ 21 21 22 + #include <errno.h> 22 23 #include <stdio.h> 23 24 #include <stdlib.h> 24 25 #include <time.h>
+14 -1
tools/testing/selftests/vm/run_vmtests
··· 20 20 if [ -n "$freepgs" ] && [ -n "$pgsize" ]; then 21 21 nr_hugepgs=`cat /proc/sys/vm/nr_hugepages` 22 22 needpgs=`expr $needmem / $pgsize` 23 - if [ $freepgs -lt $needpgs ]; then 23 + tries=2 24 + while [ $tries -gt 0 ] && [ $freepgs -lt $needpgs ]; do 24 25 lackpgs=$(( $needpgs - $freepgs )) 26 + echo 3 > /proc/sys/vm/drop_caches 25 27 echo $(( $lackpgs + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages 26 28 if [ $? -ne 0 ]; then 27 29 echo "Please run this test as root" 28 30 exit 1 29 31 fi 32 + while read name size unit; do 33 + if [ "$name" = "HugePages_Free:" ]; then 34 + freepgs=$size 35 + fi 36 + done < /proc/meminfo 37 + tries=$((tries - 1)) 38 + done 39 + if [ $freepgs -lt $needpgs ]; then 40 + printf "Not enough huge pages available (%d < %d)\n" \ 41 + $freepgs $needpgs 42 + exit 1 30 43 fi 31 44 else 32 45 echo "no hugetlbfs support in kernel?"