aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-09-30 11:09:14 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-09-30 11:09:14 -0400
commit29f79155b9b331167497efb0407de082d8750862 (patch)
treedde524fa03471f3a6c951e21879f36b7b952a9f8 /tools
parent2e32188a66142b5b4c2dbdd6ac8dc6f54361f044 (diff)
parent17b57b1883c1285f3d0dc2266e8f79286a7bef38 (diff)
Merge 4.19-rc6 into usb-next
We want the USB fixes in here as well. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/include/tools/libc_compat.h2
-rw-r--r--tools/lib/bpf/Build2
-rw-r--r--tools/lib/bpf/libbpf.c20
-rw-r--r--tools/lib/bpf/str_error.c18
-rw-r--r--tools/lib/bpf/str_error.h6
-rw-r--r--tools/perf/Documentation/Makefile2
-rw-r--r--tools/testing/selftests/android/Makefile2
-rw-r--r--tools/testing/selftests/android/config (renamed from tools/testing/selftests/android/ion/config)0
-rw-r--r--tools/testing/selftests/android/ion/Makefile2
-rw-r--r--tools/testing/selftests/bpf/test_maps.c10
-rw-r--r--tools/testing/selftests/cgroup/.gitignore1
-rw-r--r--tools/testing/selftests/cgroup/cgroup_util.c38
-rw-r--r--tools/testing/selftests/cgroup/cgroup_util.h1
-rw-r--r--tools/testing/selftests/cgroup/test_memcontrol.c205
-rw-r--r--tools/testing/selftests/efivarfs/config1
-rw-r--r--tools/testing/selftests/futex/functional/Makefile1
-rw-r--r--tools/testing/selftests/gpio/Makefile7
-rw-r--r--tools/testing/selftests/kselftest.h1
-rw-r--r--tools/testing/selftests/kvm/.gitignore1
-rw-r--r--tools/testing/selftests/kvm/Makefile12
-rw-r--r--tools/testing/selftests/kvm/include/kvm_util.h4
-rw-r--r--tools/testing/selftests/kvm/lib/kvm_util.c89
-rw-r--r--tools/testing/selftests/kvm/platform_info_test.c110
-rw-r--r--tools/testing/selftests/lib.mk12
-rw-r--r--tools/testing/selftests/memory-hotplug/config1
-rw-r--r--tools/testing/selftests/net/Makefile1
-rwxr-xr-xtools/testing/selftests/net/pmtu.sh4
-rw-r--r--tools/testing/selftests/net/tls.c49
-rw-r--r--tools/testing/selftests/networking/timestamping/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/alignment/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/benchmarks/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/cache_shape/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/copyloops/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/dscr/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/math/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/mm/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/pmu/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/pmu/ebb/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/primitives/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/ptrace/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/signal/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/stringloops/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/switch_endian/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/syscalls/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/tm/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/vphn/Makefile1
-rw-r--r--tools/testing/selftests/vm/Makefile4
47 files changed, 585 insertions, 39 deletions
diff --git a/tools/include/tools/libc_compat.h b/tools/include/tools/libc_compat.h
index 664ced8cb1b0..e907ba6f15e5 100644
--- a/tools/include/tools/libc_compat.h
+++ b/tools/include/tools/libc_compat.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+ 1// SPDX-License-Identifier: (LGPL-2.0+ OR BSD-2-Clause)
2/* Copyright (C) 2018 Netronome Systems, Inc. */ 2/* Copyright (C) 2018 Netronome Systems, Inc. */
3 3
4#ifndef __TOOLS_LIBC_COMPAT_H 4#ifndef __TOOLS_LIBC_COMPAT_H
diff --git a/tools/lib/bpf/Build b/tools/lib/bpf/Build
index 13a861135127..6eb9bacd1948 100644
--- a/tools/lib/bpf/Build
+++ b/tools/lib/bpf/Build
@@ -1 +1 @@
libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_errno.o libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_errno.o str_error.o
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 2abd0f112627..bdb94939fd60 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -50,6 +50,7 @@
50#include "libbpf.h" 50#include "libbpf.h"
51#include "bpf.h" 51#include "bpf.h"
52#include "btf.h" 52#include "btf.h"
53#include "str_error.h"
53 54
54#ifndef EM_BPF 55#ifndef EM_BPF
55#define EM_BPF 247 56#define EM_BPF 247
@@ -469,7 +470,7 @@ static int bpf_object__elf_init(struct bpf_object *obj)
469 obj->efile.fd = open(obj->path, O_RDONLY); 470 obj->efile.fd = open(obj->path, O_RDONLY);
470 if (obj->efile.fd < 0) { 471 if (obj->efile.fd < 0) {
471 char errmsg[STRERR_BUFSIZE]; 472 char errmsg[STRERR_BUFSIZE];
472 char *cp = strerror_r(errno, errmsg, sizeof(errmsg)); 473 char *cp = str_error(errno, errmsg, sizeof(errmsg));
473 474
474 pr_warning("failed to open %s: %s\n", obj->path, cp); 475 pr_warning("failed to open %s: %s\n", obj->path, cp);
475 return -errno; 476 return -errno;
@@ -810,8 +811,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
810 data->d_size, name, idx); 811 data->d_size, name, idx);
811 if (err) { 812 if (err) {
812 char errmsg[STRERR_BUFSIZE]; 813 char errmsg[STRERR_BUFSIZE];
813 char *cp = strerror_r(-err, errmsg, 814 char *cp = str_error(-err, errmsg, sizeof(errmsg));
814 sizeof(errmsg));
815 815
816 pr_warning("failed to alloc program %s (%s): %s", 816 pr_warning("failed to alloc program %s (%s): %s",
817 name, obj->path, cp); 817 name, obj->path, cp);
@@ -1140,7 +1140,7 @@ bpf_object__create_maps(struct bpf_object *obj)
1140 1140
1141 *pfd = bpf_create_map_xattr(&create_attr); 1141 *pfd = bpf_create_map_xattr(&create_attr);
1142 if (*pfd < 0 && create_attr.btf_key_type_id) { 1142 if (*pfd < 0 && create_attr.btf_key_type_id) {
1143 cp = strerror_r(errno, errmsg, sizeof(errmsg)); 1143 cp = str_error(errno, errmsg, sizeof(errmsg));
1144 pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n", 1144 pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n",
1145 map->name, cp, errno); 1145 map->name, cp, errno);
1146 create_attr.btf_fd = 0; 1146 create_attr.btf_fd = 0;
@@ -1155,7 +1155,7 @@ bpf_object__create_maps(struct bpf_object *obj)
1155 size_t j; 1155 size_t j;
1156 1156
1157 err = *pfd; 1157 err = *pfd;
1158 cp = strerror_r(errno, errmsg, sizeof(errmsg)); 1158 cp = str_error(errno, errmsg, sizeof(errmsg));
1159 pr_warning("failed to create map (name: '%s'): %s\n", 1159 pr_warning("failed to create map (name: '%s'): %s\n",
1160 map->name, cp); 1160 map->name, cp);
1161 for (j = 0; j < i; j++) 1161 for (j = 0; j < i; j++)
@@ -1339,7 +1339,7 @@ load_program(enum bpf_prog_type type, enum bpf_attach_type expected_attach_type,
1339 } 1339 }
1340 1340
1341 ret = -LIBBPF_ERRNO__LOAD; 1341 ret = -LIBBPF_ERRNO__LOAD;
1342 cp = strerror_r(errno, errmsg, sizeof(errmsg)); 1342 cp = str_error(errno, errmsg, sizeof(errmsg));
1343 pr_warning("load bpf program failed: %s\n", cp); 1343 pr_warning("load bpf program failed: %s\n", cp);
1344 1344
1345 if (log_buf && log_buf[0] != '\0') { 1345 if (log_buf && log_buf[0] != '\0') {
@@ -1654,7 +1654,7 @@ static int check_path(const char *path)
1654 1654
1655 dir = dirname(dname); 1655 dir = dirname(dname);
1656 if (statfs(dir, &st_fs)) { 1656 if (statfs(dir, &st_fs)) {
1657 cp = strerror_r(errno, errmsg, sizeof(errmsg)); 1657 cp = str_error(errno, errmsg, sizeof(errmsg));
1658 pr_warning("failed to statfs %s: %s\n", dir, cp); 1658 pr_warning("failed to statfs %s: %s\n", dir, cp);
1659 err = -errno; 1659 err = -errno;
1660 } 1660 }
@@ -1690,7 +1690,7 @@ int bpf_program__pin_instance(struct bpf_program *prog, const char *path,
1690 } 1690 }
1691 1691
1692 if (bpf_obj_pin(prog->instances.fds[instance], path)) { 1692 if (bpf_obj_pin(prog->instances.fds[instance], path)) {
1693 cp = strerror_r(errno, errmsg, sizeof(errmsg)); 1693 cp = str_error(errno, errmsg, sizeof(errmsg));
1694 pr_warning("failed to pin program: %s\n", cp); 1694 pr_warning("failed to pin program: %s\n", cp);
1695 return -errno; 1695 return -errno;
1696 } 1696 }
@@ -1708,7 +1708,7 @@ static int make_dir(const char *path)
1708 err = -errno; 1708 err = -errno;
1709 1709
1710 if (err) { 1710 if (err) {
1711 cp = strerror_r(-err, errmsg, sizeof(errmsg)); 1711 cp = str_error(-err, errmsg, sizeof(errmsg));
1712 pr_warning("failed to mkdir %s: %s\n", path, cp); 1712 pr_warning("failed to mkdir %s: %s\n", path, cp);
1713 } 1713 }
1714 return err; 1714 return err;
@@ -1770,7 +1770,7 @@ int bpf_map__pin(struct bpf_map *map, const char *path)
1770 } 1770 }
1771 1771
1772 if (bpf_obj_pin(map->fd, path)) { 1772 if (bpf_obj_pin(map->fd, path)) {
1773 cp = strerror_r(errno, errmsg, sizeof(errmsg)); 1773 cp = str_error(errno, errmsg, sizeof(errmsg));
1774 pr_warning("failed to pin map: %s\n", cp); 1774 pr_warning("failed to pin map: %s\n", cp);
1775 return -errno; 1775 return -errno;
1776 } 1776 }
diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c
new file mode 100644
index 000000000000..b8798114a357
--- /dev/null
+++ b/tools/lib/bpf/str_error.c
@@ -0,0 +1,18 @@
1// SPDX-License-Identifier: LGPL-2.1
2#undef _GNU_SOURCE
3#include <string.h>
4#include <stdio.h>
5#include "str_error.h"
6
7/*
8 * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl
9 * libc, while checking strerror_r() return to avoid having to check this in
10 * all places calling it.
11 */
12char *str_error(int err, char *dst, int len)
13{
14 int ret = strerror_r(err, dst, len);
15 if (ret)
16 snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret);
17 return dst;
18}
diff --git a/tools/lib/bpf/str_error.h b/tools/lib/bpf/str_error.h
new file mode 100644
index 000000000000..355b1db571d1
--- /dev/null
+++ b/tools/lib/bpf/str_error.h
@@ -0,0 +1,6 @@
1// SPDX-License-Identifier: LGPL-2.1
2#ifndef BPF_STR_ERROR
3#define BPF_STR_ERROR
4
5char *str_error(int err, char *dst, int len);
6#endif // BPF_STR_ERROR
diff --git a/tools/perf/Documentation/Makefile b/tools/perf/Documentation/Makefile
index 42261a9b280e..ac841bc5c35b 100644
--- a/tools/perf/Documentation/Makefile
+++ b/tools/perf/Documentation/Makefile
@@ -280,7 +280,7 @@ $(MAN_HTML): $(OUTPUT)%.html : %.txt
280 mv $@+ $@ 280 mv $@+ $@
281 281
282ifdef USE_ASCIIDOCTOR 282ifdef USE_ASCIIDOCTOR
283$(OUTPUT)%.1 $(OUTPUT)%.5 $(OUTPUT)%.7 : $(OUTPUT)%.txt 283$(OUTPUT)%.1 $(OUTPUT)%.5 $(OUTPUT)%.7 : %.txt
284 $(QUIET_ASCIIDOC)$(RM) $@+ $@ && \ 284 $(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
285 $(ASCIIDOC) -b manpage -d manpage \ 285 $(ASCIIDOC) -b manpage -d manpage \
286 $(ASCIIDOC_EXTRA) -aperf_version=$(PERF_VERSION) -o $@+ $< && \ 286 $(ASCIIDOC_EXTRA) -aperf_version=$(PERF_VERSION) -o $@+ $< && \
diff --git a/tools/testing/selftests/android/Makefile b/tools/testing/selftests/android/Makefile
index 72c25a3cb658..d9a725478375 100644
--- a/tools/testing/selftests/android/Makefile
+++ b/tools/testing/selftests/android/Makefile
@@ -6,7 +6,7 @@ TEST_PROGS := run.sh
6 6
7include ../lib.mk 7include ../lib.mk
8 8
9all: 9all: khdr
10 @for DIR in $(SUBDIRS); do \ 10 @for DIR in $(SUBDIRS); do \
11 BUILD_TARGET=$(OUTPUT)/$$DIR; \ 11 BUILD_TARGET=$(OUTPUT)/$$DIR; \
12 mkdir $$BUILD_TARGET -p; \ 12 mkdir $$BUILD_TARGET -p; \
diff --git a/tools/testing/selftests/android/ion/config b/tools/testing/selftests/android/config
index b4ad748a9dd9..b4ad748a9dd9 100644
--- a/tools/testing/selftests/android/ion/config
+++ b/tools/testing/selftests/android/config
diff --git a/tools/testing/selftests/android/ion/Makefile b/tools/testing/selftests/android/ion/Makefile
index e03695287f76..88cfe88e466f 100644
--- a/tools/testing/selftests/android/ion/Makefile
+++ b/tools/testing/selftests/android/ion/Makefile
@@ -10,6 +10,8 @@ $(TEST_GEN_FILES): ipcsocket.c ionutils.c
10 10
11TEST_PROGS := ion_test.sh 11TEST_PROGS := ion_test.sh
12 12
13KSFT_KHDR_INSTALL := 1
14top_srcdir = ../../../../..
13include ../../lib.mk 15include ../../lib.mk
14 16
15$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c 17$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index 6f54f84144a0..9b552c0fc47d 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -580,7 +580,11 @@ static void test_sockmap(int tasks, void *data)
580 /* Test update without programs */ 580 /* Test update without programs */
581 for (i = 0; i < 6; i++) { 581 for (i = 0; i < 6; i++) {
582 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); 582 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY);
583 if (err) { 583 if (i < 2 && !err) {
584 printf("Allowed update sockmap '%i:%i' not in ESTABLISHED\n",
585 i, sfd[i]);
586 goto out_sockmap;
587 } else if (i >= 2 && err) {
584 printf("Failed noprog update sockmap '%i:%i'\n", 588 printf("Failed noprog update sockmap '%i:%i'\n",
585 i, sfd[i]); 589 i, sfd[i]);
586 goto out_sockmap; 590 goto out_sockmap;
@@ -741,7 +745,7 @@ static void test_sockmap(int tasks, void *data)
741 } 745 }
742 746
743 /* Test map update elem afterwards fd lives in fd and map_fd */ 747 /* Test map update elem afterwards fd lives in fd and map_fd */
744 for (i = 0; i < 6; i++) { 748 for (i = 2; i < 6; i++) {
745 err = bpf_map_update_elem(map_fd_rx, &i, &sfd[i], BPF_ANY); 749 err = bpf_map_update_elem(map_fd_rx, &i, &sfd[i], BPF_ANY);
746 if (err) { 750 if (err) {
747 printf("Failed map_fd_rx update sockmap %i '%i:%i'\n", 751 printf("Failed map_fd_rx update sockmap %i '%i:%i'\n",
@@ -845,7 +849,7 @@ static void test_sockmap(int tasks, void *data)
845 } 849 }
846 850
847 /* Delete the elems without programs */ 851 /* Delete the elems without programs */
848 for (i = 0; i < 6; i++) { 852 for (i = 2; i < 6; i++) {
849 err = bpf_map_delete_elem(fd, &i); 853 err = bpf_map_delete_elem(fd, &i);
850 if (err) { 854 if (err) {
851 printf("Failed delete sockmap %i '%i:%i'\n", 855 printf("Failed delete sockmap %i '%i:%i'\n",
diff --git a/tools/testing/selftests/cgroup/.gitignore b/tools/testing/selftests/cgroup/.gitignore
index 95eb3a53c381..adacda50a4b2 100644
--- a/tools/testing/selftests/cgroup/.gitignore
+++ b/tools/testing/selftests/cgroup/.gitignore
@@ -1 +1,2 @@
1test_memcontrol 1test_memcontrol
2test_core
diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c
index 1c5d2b2a583b..14c9fe284806 100644
--- a/tools/testing/selftests/cgroup/cgroup_util.c
+++ b/tools/testing/selftests/cgroup/cgroup_util.c
@@ -89,17 +89,28 @@ int cg_read(const char *cgroup, const char *control, char *buf, size_t len)
89int cg_read_strcmp(const char *cgroup, const char *control, 89int cg_read_strcmp(const char *cgroup, const char *control,
90 const char *expected) 90 const char *expected)
91{ 91{
92 size_t size = strlen(expected) + 1; 92 size_t size;
93 char *buf; 93 char *buf;
94 int ret;
95
96 /* Handle the case of comparing against empty string */
97 if (!expected)
98 size = 32;
99 else
100 size = strlen(expected) + 1;
94 101
95 buf = malloc(size); 102 buf = malloc(size);
96 if (!buf) 103 if (!buf)
97 return -1; 104 return -1;
98 105
99 if (cg_read(cgroup, control, buf, size)) 106 if (cg_read(cgroup, control, buf, size)) {
107 free(buf);
100 return -1; 108 return -1;
109 }
101 110
102 return strcmp(expected, buf); 111 ret = strcmp(expected, buf);
112 free(buf);
113 return ret;
103} 114}
104 115
105int cg_read_strstr(const char *cgroup, const char *control, const char *needle) 116int cg_read_strstr(const char *cgroup, const char *control, const char *needle)
@@ -337,3 +348,24 @@ int is_swap_enabled(void)
337 348
338 return cnt > 1; 349 return cnt > 1;
339} 350}
351
352int set_oom_adj_score(int pid, int score)
353{
354 char path[PATH_MAX];
355 int fd, len;
356
357 sprintf(path, "/proc/%d/oom_score_adj", pid);
358
359 fd = open(path, O_WRONLY | O_APPEND);
360 if (fd < 0)
361 return fd;
362
363 len = dprintf(fd, "%d", score);
364 if (len < 0) {
365 close(fd);
366 return len;
367 }
368
369 close(fd);
370 return 0;
371}
diff --git a/tools/testing/selftests/cgroup/cgroup_util.h b/tools/testing/selftests/cgroup/cgroup_util.h
index 1ff6f9f1abdc..9ac8b7958f83 100644
--- a/tools/testing/selftests/cgroup/cgroup_util.h
+++ b/tools/testing/selftests/cgroup/cgroup_util.h
@@ -40,3 +40,4 @@ extern int get_temp_fd(void);
40extern int alloc_pagecache(int fd, size_t size); 40extern int alloc_pagecache(int fd, size_t size);
41extern int alloc_anon(const char *cgroup, void *arg); 41extern int alloc_anon(const char *cgroup, void *arg);
42extern int is_swap_enabled(void); 42extern int is_swap_enabled(void);
43extern int set_oom_adj_score(int pid, int score);
diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
index cf0bddc9d271..28d321ba311b 100644
--- a/tools/testing/selftests/cgroup/test_memcontrol.c
+++ b/tools/testing/selftests/cgroup/test_memcontrol.c
@@ -2,6 +2,7 @@
2#define _GNU_SOURCE 2#define _GNU_SOURCE
3 3
4#include <linux/limits.h> 4#include <linux/limits.h>
5#include <linux/oom.h>
5#include <fcntl.h> 6#include <fcntl.h>
6#include <stdio.h> 7#include <stdio.h>
7#include <stdlib.h> 8#include <stdlib.h>
@@ -202,6 +203,36 @@ static int alloc_pagecache_50M_noexit(const char *cgroup, void *arg)
202 return 0; 203 return 0;
203} 204}
204 205
206static int alloc_anon_noexit(const char *cgroup, void *arg)
207{
208 int ppid = getppid();
209
210 if (alloc_anon(cgroup, arg))
211 return -1;
212
213 while (getppid() == ppid)
214 sleep(1);
215
216 return 0;
217}
218
219/*
220 * Wait until processes are killed asynchronously by the OOM killer
221 * If we exceed a timeout, fail.
222 */
223static int cg_test_proc_killed(const char *cgroup)
224{
225 int limit;
226
227 for (limit = 10; limit > 0; limit--) {
228 if (cg_read_strcmp(cgroup, "cgroup.procs", "") == 0)
229 return 0;
230
231 usleep(100000);
232 }
233 return -1;
234}
235
205/* 236/*
206 * First, this test creates the following hierarchy: 237 * First, this test creates the following hierarchy:
207 * A memory.min = 50M, memory.max = 200M 238 * A memory.min = 50M, memory.max = 200M
@@ -964,6 +995,177 @@ cleanup:
964 return ret; 995 return ret;
965} 996}
966 997
998/*
999 * This test disables swapping and tries to allocate anonymous memory
1000 * up to OOM with memory.group.oom set. Then it checks that all
1001 * processes in the leaf (but not the parent) were killed.
1002 */
1003static int test_memcg_oom_group_leaf_events(const char *root)
1004{
1005 int ret = KSFT_FAIL;
1006 char *parent, *child;
1007
1008 parent = cg_name(root, "memcg_test_0");
1009 child = cg_name(root, "memcg_test_0/memcg_test_1");
1010
1011 if (!parent || !child)
1012 goto cleanup;
1013
1014 if (cg_create(parent))
1015 goto cleanup;
1016
1017 if (cg_create(child))
1018 goto cleanup;
1019
1020 if (cg_write(parent, "cgroup.subtree_control", "+memory"))
1021 goto cleanup;
1022
1023 if (cg_write(child, "memory.max", "50M"))
1024 goto cleanup;
1025
1026 if (cg_write(child, "memory.swap.max", "0"))
1027 goto cleanup;
1028
1029 if (cg_write(child, "memory.oom.group", "1"))
1030 goto cleanup;
1031
1032 cg_run_nowait(parent, alloc_anon_noexit, (void *) MB(60));
1033 cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1));
1034 cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1));
1035 if (!cg_run(child, alloc_anon, (void *)MB(100)))
1036 goto cleanup;
1037
1038 if (cg_test_proc_killed(child))
1039 goto cleanup;
1040
1041 if (cg_read_key_long(child, "memory.events", "oom_kill ") <= 0)
1042 goto cleanup;
1043
1044 if (cg_read_key_long(parent, "memory.events", "oom_kill ") != 0)
1045 goto cleanup;
1046
1047 ret = KSFT_PASS;
1048
1049cleanup:
1050 if (child)
1051 cg_destroy(child);
1052 if (parent)
1053 cg_destroy(parent);
1054 free(child);
1055 free(parent);
1056
1057 return ret;
1058}
1059
1060/*
1061 * This test disables swapping and tries to allocate anonymous memory
1062 * up to OOM with memory.group.oom set. Then it checks that all
1063 * processes in the parent and leaf were killed.
1064 */
1065static int test_memcg_oom_group_parent_events(const char *root)
1066{
1067 int ret = KSFT_FAIL;
1068 char *parent, *child;
1069
1070 parent = cg_name(root, "memcg_test_0");
1071 child = cg_name(root, "memcg_test_0/memcg_test_1");
1072
1073 if (!parent || !child)
1074 goto cleanup;
1075
1076 if (cg_create(parent))
1077 goto cleanup;
1078
1079 if (cg_create(child))
1080 goto cleanup;
1081
1082 if (cg_write(parent, "memory.max", "80M"))
1083 goto cleanup;
1084
1085 if (cg_write(parent, "memory.swap.max", "0"))
1086 goto cleanup;
1087
1088 if (cg_write(parent, "memory.oom.group", "1"))
1089 goto cleanup;
1090
1091 cg_run_nowait(parent, alloc_anon_noexit, (void *) MB(60));
1092 cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1));
1093 cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1));
1094
1095 if (!cg_run(child, alloc_anon, (void *)MB(100)))
1096 goto cleanup;
1097
1098 if (cg_test_proc_killed(child))
1099 goto cleanup;
1100 if (cg_test_proc_killed(parent))
1101 goto cleanup;
1102
1103 ret = KSFT_PASS;
1104
1105cleanup:
1106 if (child)
1107 cg_destroy(child);
1108 if (parent)
1109 cg_destroy(parent);
1110 free(child);
1111 free(parent);
1112
1113 return ret;
1114}
1115
1116/*
1117 * This test disables swapping and tries to allocate anonymous memory
1118 * up to OOM with memory.group.oom set. Then it checks that all
1119 * processes were killed except those set with OOM_SCORE_ADJ_MIN
1120 */
1121static int test_memcg_oom_group_score_events(const char *root)
1122{
1123 int ret = KSFT_FAIL;
1124 char *memcg;
1125 int safe_pid;
1126
1127 memcg = cg_name(root, "memcg_test_0");
1128
1129 if (!memcg)
1130 goto cleanup;
1131
1132 if (cg_create(memcg))
1133 goto cleanup;
1134
1135 if (cg_write(memcg, "memory.max", "50M"))
1136 goto cleanup;
1137
1138 if (cg_write(memcg, "memory.swap.max", "0"))
1139 goto cleanup;
1140
1141 if (cg_write(memcg, "memory.oom.group", "1"))
1142 goto cleanup;
1143
1144 safe_pid = cg_run_nowait(memcg, alloc_anon_noexit, (void *) MB(1));
1145 if (set_oom_adj_score(safe_pid, OOM_SCORE_ADJ_MIN))
1146 goto cleanup;
1147
1148 cg_run_nowait(memcg, alloc_anon_noexit, (void *) MB(1));
1149 if (!cg_run(memcg, alloc_anon, (void *)MB(100)))
1150 goto cleanup;
1151
1152 if (cg_read_key_long(memcg, "memory.events", "oom_kill ") != 3)
1153 goto cleanup;
1154
1155 if (kill(safe_pid, SIGKILL))
1156 goto cleanup;
1157
1158 ret = KSFT_PASS;
1159
1160cleanup:
1161 if (memcg)
1162 cg_destroy(memcg);
1163 free(memcg);
1164
1165 return ret;
1166}
1167
1168
967#define T(x) { x, #x } 1169#define T(x) { x, #x }
968struct memcg_test { 1170struct memcg_test {
969 int (*fn)(const char *root); 1171 int (*fn)(const char *root);
@@ -978,6 +1180,9 @@ struct memcg_test {
978 T(test_memcg_oom_events), 1180 T(test_memcg_oom_events),
979 T(test_memcg_swap_max), 1181 T(test_memcg_swap_max),
980 T(test_memcg_sock), 1182 T(test_memcg_sock),
1183 T(test_memcg_oom_group_leaf_events),
1184 T(test_memcg_oom_group_parent_events),
1185 T(test_memcg_oom_group_score_events),
981}; 1186};
982#undef T 1187#undef T
983 1188
diff --git a/tools/testing/selftests/efivarfs/config b/tools/testing/selftests/efivarfs/config
new file mode 100644
index 000000000000..4e151f1005b2
--- /dev/null
+++ b/tools/testing/selftests/efivarfs/config
@@ -0,0 +1 @@
CONFIG_EFIVAR_FS=y
diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/testing/selftests/futex/functional/Makefile
index ff8feca49746..ad1eeb14fda7 100644
--- a/tools/testing/selftests/futex/functional/Makefile
+++ b/tools/testing/selftests/futex/functional/Makefile
@@ -18,6 +18,7 @@ TEST_GEN_FILES := \
18 18
19TEST_PROGS := run.sh 19TEST_PROGS := run.sh
20 20
21top_srcdir = ../../../../..
21include ../../lib.mk 22include ../../lib.mk
22 23
23$(TEST_GEN_FILES): $(HEADERS) 24$(TEST_GEN_FILES): $(HEADERS)
diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile
index 1bbb47565c55..4665cdbf1a8d 100644
--- a/tools/testing/selftests/gpio/Makefile
+++ b/tools/testing/selftests/gpio/Makefile
@@ -21,11 +21,8 @@ endef
21CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/ 21CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/
22LDLIBS += -lmount -I/usr/include/libmount 22LDLIBS += -lmount -I/usr/include/libmount
23 23
24$(BINARIES): ../../../gpio/gpio-utils.o ../../../../usr/include/linux/gpio.h 24$(BINARIES):| khdr
25$(BINARIES): ../../../gpio/gpio-utils.o
25 26
26../../../gpio/gpio-utils.o: 27../../../gpio/gpio-utils.o:
27 make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C ../../../gpio 28 make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C ../../../gpio
28
29../../../../usr/include/linux/gpio.h:
30 make -C ../../../.. headers_install INSTALL_HDR_PATH=$(shell pwd)/../../../../usr/
31
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 15e6b75fc3a5..a3edb2c8e43d 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -19,7 +19,6 @@
19#define KSFT_FAIL 1 19#define KSFT_FAIL 1
20#define KSFT_XFAIL 2 20#define KSFT_XFAIL 2
21#define KSFT_XPASS 3 21#define KSFT_XPASS 3
22/* Treat skip as pass */
23#define KSFT_SKIP 4 22#define KSFT_SKIP 4
24 23
25/* counters */ 24/* counters */
diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore
index 4202139d81d9..5c34752e1cff 100644
--- a/tools/testing/selftests/kvm/.gitignore
+++ b/tools/testing/selftests/kvm/.gitignore
@@ -1,4 +1,5 @@
1cr4_cpuid_sync_test 1cr4_cpuid_sync_test
2platform_info_test
2set_sregs_test 3set_sregs_test
3sync_regs_test 4sync_regs_test
4vmx_tsc_adjust_test 5vmx_tsc_adjust_test
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 03b0f551bedf..ec32dad3c3f0 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -6,7 +6,8 @@ UNAME_M := $(shell uname -m)
6LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c 6LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c
7LIBKVM_x86_64 = lib/x86.c lib/vmx.c 7LIBKVM_x86_64 = lib/x86.c lib/vmx.c
8 8
9TEST_GEN_PROGS_x86_64 = set_sregs_test 9TEST_GEN_PROGS_x86_64 = platform_info_test
10TEST_GEN_PROGS_x86_64 += set_sregs_test
10TEST_GEN_PROGS_x86_64 += sync_regs_test 11TEST_GEN_PROGS_x86_64 += sync_regs_test
11TEST_GEN_PROGS_x86_64 += vmx_tsc_adjust_test 12TEST_GEN_PROGS_x86_64 += vmx_tsc_adjust_test
12TEST_GEN_PROGS_x86_64 += cr4_cpuid_sync_test 13TEST_GEN_PROGS_x86_64 += cr4_cpuid_sync_test
@@ -20,7 +21,7 @@ INSTALL_HDR_PATH = $(top_srcdir)/usr
20LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/ 21LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
21LINUX_TOOL_INCLUDE = $(top_srcdir)tools/include 22LINUX_TOOL_INCLUDE = $(top_srcdir)tools/include
22CFLAGS += -O2 -g -std=gnu99 -I$(LINUX_TOOL_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude -I$(<D) -I.. 23CFLAGS += -O2 -g -std=gnu99 -I$(LINUX_TOOL_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude -I$(<D) -I..
23LDFLAGS += -lpthread 24LDFLAGS += -pthread
24 25
25# After inclusion, $(OUTPUT) is defined and 26# After inclusion, $(OUTPUT) is defined and
26# $(TEST_GEN_PROGS) starts with $(OUTPUT)/ 27# $(TEST_GEN_PROGS) starts with $(OUTPUT)/
@@ -37,9 +38,6 @@ $(LIBKVM_OBJ): $(OUTPUT)/%.o: %.c
37$(OUTPUT)/libkvm.a: $(LIBKVM_OBJ) 38$(OUTPUT)/libkvm.a: $(LIBKVM_OBJ)
38 $(AR) crs $@ $^ 39 $(AR) crs $@ $^
39 40
40$(LINUX_HDR_PATH): 41all: $(STATIC_LIBS)
41 make -C $(top_srcdir) headers_install
42
43all: $(STATIC_LIBS) $(LINUX_HDR_PATH)
44$(TEST_GEN_PROGS): $(STATIC_LIBS) 42$(TEST_GEN_PROGS): $(STATIC_LIBS)
45$(TEST_GEN_PROGS) $(LIBKVM_OBJ): | $(LINUX_HDR_PATH) 43$(STATIC_LIBS):| khdr
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index bb5a25fb82c6..3acf9a91704c 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -50,6 +50,7 @@ enum vm_mem_backing_src_type {
50}; 50};
51 51
52int kvm_check_cap(long cap); 52int kvm_check_cap(long cap);
53int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap);
53 54
54struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm); 55struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm);
55void kvm_vm_free(struct kvm_vm *vmp); 56void kvm_vm_free(struct kvm_vm *vmp);
@@ -108,6 +109,9 @@ void vcpu_events_get(struct kvm_vm *vm, uint32_t vcpuid,
108 struct kvm_vcpu_events *events); 109 struct kvm_vcpu_events *events);
109void vcpu_events_set(struct kvm_vm *vm, uint32_t vcpuid, 110void vcpu_events_set(struct kvm_vm *vm, uint32_t vcpuid,
110 struct kvm_vcpu_events *events); 111 struct kvm_vcpu_events *events);
112uint64_t vcpu_get_msr(struct kvm_vm *vm, uint32_t vcpuid, uint64_t msr_index);
113void vcpu_set_msr(struct kvm_vm *vm, uint32_t vcpuid, uint64_t msr_index,
114 uint64_t msr_value);
111 115
112const char *exit_reason_str(unsigned int exit_reason); 116const char *exit_reason_str(unsigned int exit_reason);
113 117
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index e9ba389c48db..6fd8c089cafc 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -63,6 +63,29 @@ int kvm_check_cap(long cap)
63 return ret; 63 return ret;
64} 64}
65 65
66/* VM Enable Capability
67 *
68 * Input Args:
69 * vm - Virtual Machine
70 * cap - Capability
71 *
72 * Output Args: None
73 *
74 * Return: On success, 0. On failure a TEST_ASSERT failure is produced.
75 *
76 * Enables a capability (KVM_CAP_*) on the VM.
77 */
78int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap)
79{
80 int ret;
81
82 ret = ioctl(vm->fd, KVM_ENABLE_CAP, cap);
83 TEST_ASSERT(ret == 0, "KVM_ENABLE_CAP IOCTL failed,\n"
84 " rc: %i errno: %i", ret, errno);
85
86 return ret;
87}
88
66static void vm_open(struct kvm_vm *vm, int perm) 89static void vm_open(struct kvm_vm *vm, int perm)
67{ 90{
68 vm->kvm_fd = open(KVM_DEV_PATH, perm); 91 vm->kvm_fd = open(KVM_DEV_PATH, perm);
@@ -1220,6 +1243,72 @@ void vcpu_events_set(struct kvm_vm *vm, uint32_t vcpuid,
1220 ret, errno); 1243 ret, errno);
1221} 1244}
1222 1245
1246/* VCPU Get MSR
1247 *
1248 * Input Args:
1249 * vm - Virtual Machine
1250 * vcpuid - VCPU ID
1251 * msr_index - Index of MSR
1252 *
1253 * Output Args: None
1254 *
1255 * Return: On success, value of the MSR. On failure a TEST_ASSERT is produced.
1256 *
1257 * Get value of MSR for VCPU.
1258 */
1259uint64_t vcpu_get_msr(struct kvm_vm *vm, uint32_t vcpuid, uint64_t msr_index)
1260{
1261 struct vcpu *vcpu = vcpu_find(vm, vcpuid);
1262 struct {
1263 struct kvm_msrs header;
1264 struct kvm_msr_entry entry;
1265 } buffer = {};
1266 int r;
1267
1268 TEST_ASSERT(vcpu != NULL, "vcpu not found, vcpuid: %u", vcpuid);
1269 buffer.header.nmsrs = 1;
1270 buffer.entry.index = msr_index;
1271 r = ioctl(vcpu->fd, KVM_GET_MSRS, &buffer.header);
1272 TEST_ASSERT(r == 1, "KVM_GET_MSRS IOCTL failed,\n"
1273 " rc: %i errno: %i", r, errno);
1274
1275 return buffer.entry.data;
1276}
1277
1278/* VCPU Set MSR
1279 *
1280 * Input Args:
1281 * vm - Virtual Machine
1282 * vcpuid - VCPU ID
1283 * msr_index - Index of MSR
1284 * msr_value - New value of MSR
1285 *
1286 * Output Args: None
1287 *
1288 * Return: On success, nothing. On failure a TEST_ASSERT is produced.
1289 *
1290 * Set value of MSR for VCPU.
1291 */
1292void vcpu_set_msr(struct kvm_vm *vm, uint32_t vcpuid, uint64_t msr_index,
1293 uint64_t msr_value)
1294{
1295 struct vcpu *vcpu = vcpu_find(vm, vcpuid);
1296 struct {
1297 struct kvm_msrs header;
1298 struct kvm_msr_entry entry;
1299 } buffer = {};
1300 int r;
1301
1302 TEST_ASSERT(vcpu != NULL, "vcpu not found, vcpuid: %u", vcpuid);
1303 memset(&buffer, 0, sizeof(buffer));
1304 buffer.header.nmsrs = 1;
1305 buffer.entry.index = msr_index;
1306 buffer.entry.data = msr_value;
1307 r = ioctl(vcpu->fd, KVM_SET_MSRS, &buffer.header);
1308 TEST_ASSERT(r == 1, "KVM_SET_MSRS IOCTL failed,\n"
1309 " rc: %i errno: %i", r, errno);
1310}
1311
1223/* VM VCPU Args Set 1312/* VM VCPU Args Set
1224 * 1313 *
1225 * Input Args: 1314 * Input Args:
diff --git a/tools/testing/selftests/kvm/platform_info_test.c b/tools/testing/selftests/kvm/platform_info_test.c
new file mode 100644
index 000000000000..3764e7121265
--- /dev/null
+++ b/tools/testing/selftests/kvm/platform_info_test.c
@@ -0,0 +1,110 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Test for x86 KVM_CAP_MSR_PLATFORM_INFO
4 *
5 * Copyright (C) 2018, Google LLC.
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2.
8 *
9 * Verifies expected behavior of controlling guest access to
10 * MSR_PLATFORM_INFO.
11 */
12
13#define _GNU_SOURCE /* for program_invocation_short_name */
14#include <fcntl.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18#include <sys/ioctl.h>
19
20#include "test_util.h"
21#include "kvm_util.h"
22#include "x86.h"
23
24#define VCPU_ID 0
25#define MSR_PLATFORM_INFO_MAX_TURBO_RATIO 0xff00
26
27static void guest_code(void)
28{
29 uint64_t msr_platform_info;
30
31 for (;;) {
32 msr_platform_info = rdmsr(MSR_PLATFORM_INFO);
33 GUEST_SYNC(msr_platform_info);
34 asm volatile ("inc %r11");
35 }
36}
37
38static void set_msr_platform_info_enabled(struct kvm_vm *vm, bool enable)
39{
40 struct kvm_enable_cap cap = {};
41
42 cap.cap = KVM_CAP_MSR_PLATFORM_INFO;
43 cap.flags = 0;
44 cap.args[0] = (int)enable;
45 vm_enable_cap(vm, &cap);
46}
47
48static void test_msr_platform_info_enabled(struct kvm_vm *vm)
49{
50 struct kvm_run *run = vcpu_state(vm, VCPU_ID);
51 struct guest_args args;
52
53 set_msr_platform_info_enabled(vm, true);
54 vcpu_run(vm, VCPU_ID);
55 TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
56 "Exit_reason other than KVM_EXIT_IO: %u (%s),\n",
57 run->exit_reason,
58 exit_reason_str(run->exit_reason));
59 guest_args_read(vm, VCPU_ID, &args);
60 TEST_ASSERT(args.port == GUEST_PORT_SYNC,
61 "Received IO from port other than PORT_HOST_SYNC: %u\n",
62 run->io.port);
63 TEST_ASSERT((args.arg1 & MSR_PLATFORM_INFO_MAX_TURBO_RATIO) ==
64 MSR_PLATFORM_INFO_MAX_TURBO_RATIO,
65 "Expected MSR_PLATFORM_INFO to have max turbo ratio mask: %i.",
66 MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
67}
68
69static void test_msr_platform_info_disabled(struct kvm_vm *vm)
70{
71 struct kvm_run *run = vcpu_state(vm, VCPU_ID);
72
73 set_msr_platform_info_enabled(vm, false);
74 vcpu_run(vm, VCPU_ID);
75 TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN,
76 "Exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n",
77 run->exit_reason,
78 exit_reason_str(run->exit_reason));
79}
80
81int main(int argc, char *argv[])
82{
83 struct kvm_vm *vm;
84 struct kvm_run *state;
85 int rv;
86 uint64_t msr_platform_info;
87
88 /* Tell stdout not to buffer its content */
89 setbuf(stdout, NULL);
90
91 rv = kvm_check_cap(KVM_CAP_MSR_PLATFORM_INFO);
92 if (!rv) {
93 fprintf(stderr,
94 "KVM_CAP_MSR_PLATFORM_INFO not supported, skip test\n");
95 exit(KSFT_SKIP);
96 }
97
98 vm = vm_create_default(VCPU_ID, 0, guest_code);
99
100 msr_platform_info = vcpu_get_msr(vm, VCPU_ID, MSR_PLATFORM_INFO);
101 vcpu_set_msr(vm, VCPU_ID, MSR_PLATFORM_INFO,
102 msr_platform_info | MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
103 test_msr_platform_info_disabled(vm);
104 test_msr_platform_info_enabled(vm);
105 vcpu_set_msr(vm, VCPU_ID, MSR_PLATFORM_INFO, msr_platform_info);
106
107 kvm_vm_free(vm);
108
109 return 0;
110}
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 17ab36605a8e..0a8e75886224 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -16,8 +16,20 @@ TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
16TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) 16TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
17TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) 17TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
18 18
19top_srcdir ?= ../../../..
20include $(top_srcdir)/scripts/subarch.include
21ARCH ?= $(SUBARCH)
22
19all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 23all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
20 24
25.PHONY: khdr
26khdr:
27 make ARCH=$(ARCH) -C $(top_srcdir) headers_install
28
29ifdef KSFT_KHDR_INSTALL
30$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES):| khdr
31endif
32
21.ONESHELL: 33.ONESHELL:
22define RUN_TEST_PRINT_RESULT 34define RUN_TEST_PRINT_RESULT
23 TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST"; \ 35 TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST"; \
diff --git a/tools/testing/selftests/memory-hotplug/config b/tools/testing/selftests/memory-hotplug/config
index 2fde30191a47..a7e8cd5bb265 100644
--- a/tools/testing/selftests/memory-hotplug/config
+++ b/tools/testing/selftests/memory-hotplug/config
@@ -2,3 +2,4 @@ CONFIG_MEMORY_HOTPLUG=y
2CONFIG_MEMORY_HOTPLUG_SPARSE=y 2CONFIG_MEMORY_HOTPLUG_SPARSE=y
3CONFIG_NOTIFIER_ERROR_INJECTION=y 3CONFIG_NOTIFIER_ERROR_INJECTION=y
4CONFIG_MEMORY_NOTIFIER_ERROR_INJECT=m 4CONFIG_MEMORY_NOTIFIER_ERROR_INJECT=m
5CONFIG_MEMORY_HOTREMOVE=y
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 9cca68e440a0..919aa2ac00af 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -15,6 +15,7 @@ TEST_GEN_FILES += udpgso udpgso_bench_tx udpgso_bench_rx
15TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa 15TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
16TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls 16TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls
17 17
18KSFT_KHDR_INSTALL := 1
18include ../lib.mk 19include ../lib.mk
19 20
20$(OUTPUT)/reuseport_bpf_numa: LDFLAGS += -lnuma 21$(OUTPUT)/reuseport_bpf_numa: LDFLAGS += -lnuma
diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh
index 32a194e3e07a..0ab9423d009f 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -178,8 +178,8 @@ setup() {
178 178
179cleanup() { 179cleanup() {
180 [ ${cleanup_done} -eq 1 ] && return 180 [ ${cleanup_done} -eq 1 ] && return
181 ip netns del ${NS_A} 2 > /dev/null 181 ip netns del ${NS_A} 2> /dev/null
182 ip netns del ${NS_B} 2 > /dev/null 182 ip netns del ${NS_B} 2> /dev/null
183 cleanup_done=1 183 cleanup_done=1
184} 184}
185 185
diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c
index b3ebf2646e52..8fdfeafaf8c0 100644
--- a/tools/testing/selftests/net/tls.c
+++ b/tools/testing/selftests/net/tls.c
@@ -502,6 +502,55 @@ TEST_F(tls, recv_peek_multiple)
502 EXPECT_EQ(memcmp(test_str, buf, send_len), 0); 502 EXPECT_EQ(memcmp(test_str, buf, send_len), 0);
503} 503}
504 504
505TEST_F(tls, recv_peek_multiple_records)
506{
507 char const *test_str = "test_read_peek_mult_recs";
508 char const *test_str_first = "test_read_peek";
509 char const *test_str_second = "_mult_recs";
510 int len;
511 char buf[64];
512
513 len = strlen(test_str_first);
514 EXPECT_EQ(send(self->fd, test_str_first, len, 0), len);
515
516 len = strlen(test_str_second) + 1;
517 EXPECT_EQ(send(self->fd, test_str_second, len, 0), len);
518
519 len = sizeof(buf);
520 memset(buf, 0, len);
521 EXPECT_NE(recv(self->cfd, buf, len, MSG_PEEK), -1);
522
523 /* MSG_PEEK can only peek into the current record. */
524 len = strlen(test_str_first) + 1;
525 EXPECT_EQ(memcmp(test_str_first, buf, len), 0);
526
527 len = sizeof(buf);
528 memset(buf, 0, len);
529 EXPECT_NE(recv(self->cfd, buf, len, 0), -1);
530
531 /* Non-MSG_PEEK will advance strparser (and therefore record)
532 * however.
533 */
534 len = strlen(test_str) + 1;
535 EXPECT_EQ(memcmp(test_str, buf, len), 0);
536
537 /* MSG_MORE will hold current record open, so later MSG_PEEK
538 * will see everything.
539 */
540 len = strlen(test_str_first);
541 EXPECT_EQ(send(self->fd, test_str_first, len, MSG_MORE), len);
542
543 len = strlen(test_str_second) + 1;
544 EXPECT_EQ(send(self->fd, test_str_second, len, 0), len);
545
546 len = sizeof(buf);
547 memset(buf, 0, len);
548 EXPECT_NE(recv(self->cfd, buf, len, MSG_PEEK), -1);
549
550 len = strlen(test_str) + 1;
551 EXPECT_EQ(memcmp(test_str, buf, len), 0);
552}
553
505TEST_F(tls, pollin) 554TEST_F(tls, pollin)
506{ 555{
507 char const *test_str = "test_poll"; 556 char const *test_str = "test_poll";
diff --git a/tools/testing/selftests/networking/timestamping/Makefile b/tools/testing/selftests/networking/timestamping/Makefile
index a728040edbe1..14cfcf006936 100644
--- a/tools/testing/selftests/networking/timestamping/Makefile
+++ b/tools/testing/selftests/networking/timestamping/Makefile
@@ -5,6 +5,7 @@ TEST_PROGS := hwtstamp_config rxtimestamp timestamping txtimestamp
5 5
6all: $(TEST_PROGS) 6all: $(TEST_PROGS)
7 7
8top_srcdir = ../../../../..
8include ../../lib.mk 9include ../../lib.mk
9 10
10clean: 11clean:
diff --git a/tools/testing/selftests/powerpc/alignment/Makefile b/tools/testing/selftests/powerpc/alignment/Makefile
index 93baacab7693..d056486f49de 100644
--- a/tools/testing/selftests/powerpc/alignment/Makefile
+++ b/tools/testing/selftests/powerpc/alignment/Makefile
@@ -1,5 +1,6 @@
1TEST_GEN_PROGS := copy_first_unaligned alignment_handler 1TEST_GEN_PROGS := copy_first_unaligned alignment_handler
2 2
3top_srcdir = ../../../../..
3include ../../lib.mk 4include ../../lib.mk
4 5
5$(TEST_GEN_PROGS): ../harness.c ../utils.c 6$(TEST_GEN_PROGS): ../harness.c ../utils.c
diff --git a/tools/testing/selftests/powerpc/benchmarks/Makefile b/tools/testing/selftests/powerpc/benchmarks/Makefile
index b4d7432a0ecd..d40300a65b42 100644
--- a/tools/testing/selftests/powerpc/benchmarks/Makefile
+++ b/tools/testing/selftests/powerpc/benchmarks/Makefile
@@ -4,6 +4,7 @@ TEST_GEN_FILES := exec_target
4 4
5CFLAGS += -O2 5CFLAGS += -O2
6 6
7top_srcdir = ../../../../..
7include ../../lib.mk 8include ../../lib.mk
8 9
9$(TEST_GEN_PROGS): ../harness.c 10$(TEST_GEN_PROGS): ../harness.c
diff --git a/tools/testing/selftests/powerpc/cache_shape/Makefile b/tools/testing/selftests/powerpc/cache_shape/Makefile
index 1be547434a49..ede4d3dae750 100644
--- a/tools/testing/selftests/powerpc/cache_shape/Makefile
+++ b/tools/testing/selftests/powerpc/cache_shape/Makefile
@@ -5,6 +5,7 @@ all: $(TEST_PROGS)
5 5
6$(TEST_PROGS): ../harness.c ../utils.c 6$(TEST_PROGS): ../harness.c ../utils.c
7 7
8top_srcdir = ../../../../..
8include ../../lib.mk 9include ../../lib.mk
9 10
10clean: 11clean:
diff --git a/tools/testing/selftests/powerpc/copyloops/Makefile b/tools/testing/selftests/powerpc/copyloops/Makefile
index 1cf89a34d97c..44574f3818b3 100644
--- a/tools/testing/selftests/powerpc/copyloops/Makefile
+++ b/tools/testing/selftests/powerpc/copyloops/Makefile
@@ -17,6 +17,7 @@ TEST_GEN_PROGS := copyuser_64_t0 copyuser_64_t1 copyuser_64_t2 \
17 17
18EXTRA_SOURCES := validate.c ../harness.c stubs.S 18EXTRA_SOURCES := validate.c ../harness.c stubs.S
19 19
20top_srcdir = ../../../../..
20include ../../lib.mk 21include ../../lib.mk
21 22
22$(OUTPUT)/copyuser_64_t%: copyuser_64.S $(EXTRA_SOURCES) 23$(OUTPUT)/copyuser_64_t%: copyuser_64.S $(EXTRA_SOURCES)
diff --git a/tools/testing/selftests/powerpc/dscr/Makefile b/tools/testing/selftests/powerpc/dscr/Makefile
index 55d7db7a616b..5df476364b4d 100644
--- a/tools/testing/selftests/powerpc/dscr/Makefile
+++ b/tools/testing/selftests/powerpc/dscr/Makefile
@@ -3,6 +3,7 @@ TEST_GEN_PROGS := dscr_default_test dscr_explicit_test dscr_user_test \
3 dscr_inherit_test dscr_inherit_exec_test dscr_sysfs_test \ 3 dscr_inherit_test dscr_inherit_exec_test dscr_sysfs_test \
4 dscr_sysfs_thread_test 4 dscr_sysfs_thread_test
5 5
6top_srcdir = ../../../../..
6include ../../lib.mk 7include ../../lib.mk
7 8
8$(OUTPUT)/dscr_default_test: LDLIBS += -lpthread 9$(OUTPUT)/dscr_default_test: LDLIBS += -lpthread
diff --git a/tools/testing/selftests/powerpc/math/Makefile b/tools/testing/selftests/powerpc/math/Makefile
index 0dd3a01fdab9..11a10d7a2bbd 100644
--- a/tools/testing/selftests/powerpc/math/Makefile
+++ b/tools/testing/selftests/powerpc/math/Makefile
@@ -1,6 +1,7 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2TEST_GEN_PROGS := fpu_syscall fpu_preempt fpu_signal vmx_syscall vmx_preempt vmx_signal vsx_preempt 2TEST_GEN_PROGS := fpu_syscall fpu_preempt fpu_signal vmx_syscall vmx_preempt vmx_signal vsx_preempt
3 3
4top_srcdir = ../../../../..
4include ../../lib.mk 5include ../../lib.mk
5 6
6$(TEST_GEN_PROGS): ../harness.c 7$(TEST_GEN_PROGS): ../harness.c
diff --git a/tools/testing/selftests/powerpc/mm/Makefile b/tools/testing/selftests/powerpc/mm/Makefile
index 8ebbe96d80a8..33ced6e0ad25 100644
--- a/tools/testing/selftests/powerpc/mm/Makefile
+++ b/tools/testing/selftests/powerpc/mm/Makefile
@@ -5,6 +5,7 @@ noarg:
5TEST_GEN_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao segv_errors 5TEST_GEN_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao segv_errors
6TEST_GEN_FILES := tempfile 6TEST_GEN_FILES := tempfile
7 7
8top_srcdir = ../../../../..
8include ../../lib.mk 9include ../../lib.mk
9 10
10$(TEST_GEN_PROGS): ../harness.c 11$(TEST_GEN_PROGS): ../harness.c
diff --git a/tools/testing/selftests/powerpc/pmu/Makefile b/tools/testing/selftests/powerpc/pmu/Makefile
index 6e1629bf5b09..19046db995fe 100644
--- a/tools/testing/selftests/powerpc/pmu/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/Makefile
@@ -5,6 +5,7 @@ noarg:
5TEST_GEN_PROGS := count_instructions l3_bank_test per_event_excludes 5TEST_GEN_PROGS := count_instructions l3_bank_test per_event_excludes
6EXTRA_SOURCES := ../harness.c event.c lib.c ../utils.c 6EXTRA_SOURCES := ../harness.c event.c lib.c ../utils.c
7 7
8top_srcdir = ../../../../..
8include ../../lib.mk 9include ../../lib.mk
9 10
10all: $(TEST_GEN_PROGS) ebb 11all: $(TEST_GEN_PROGS) ebb
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/Makefile b/tools/testing/selftests/powerpc/pmu/ebb/Makefile
index c4e64bc2e265..bd5dfa509272 100644
--- a/tools/testing/selftests/powerpc/pmu/ebb/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/ebb/Makefile
@@ -17,6 +17,7 @@ TEST_GEN_PROGS := reg_access_test event_attributes_test cycles_test \
17 lost_exception_test no_handler_test \ 17 lost_exception_test no_handler_test \
18 cycles_with_mmcr2_test 18 cycles_with_mmcr2_test
19 19
20top_srcdir = ../../../../../..
20include ../../../lib.mk 21include ../../../lib.mk
21 22
22$(TEST_GEN_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c \ 23$(TEST_GEN_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c \
diff --git a/tools/testing/selftests/powerpc/primitives/Makefile b/tools/testing/selftests/powerpc/primitives/Makefile
index 175366db7be8..ea2b7bd09e36 100644
--- a/tools/testing/selftests/powerpc/primitives/Makefile
+++ b/tools/testing/selftests/powerpc/primitives/Makefile
@@ -2,6 +2,7 @@ CFLAGS += -I$(CURDIR)
2 2
3TEST_GEN_PROGS := load_unaligned_zeropad 3TEST_GEN_PROGS := load_unaligned_zeropad
4 4
5top_srcdir = ../../../../..
5include ../../lib.mk 6include ../../lib.mk
6 7
7$(TEST_GEN_PROGS): ../harness.c 8$(TEST_GEN_PROGS): ../harness.c
diff --git a/tools/testing/selftests/powerpc/ptrace/Makefile b/tools/testing/selftests/powerpc/ptrace/Makefile
index 28f5b781a553..923d531265f8 100644
--- a/tools/testing/selftests/powerpc/ptrace/Makefile
+++ b/tools/testing/selftests/powerpc/ptrace/Makefile
@@ -4,6 +4,7 @@ TEST_PROGS := ptrace-gpr ptrace-tm-gpr ptrace-tm-spd-gpr \
4 ptrace-tm-spd-vsx ptrace-tm-spr ptrace-hwbreak ptrace-pkey core-pkey \ 4 ptrace-tm-spd-vsx ptrace-tm-spr ptrace-hwbreak ptrace-pkey core-pkey \
5 perf-hwbreak 5 perf-hwbreak
6 6
7top_srcdir = ../../../../..
7include ../../lib.mk 8include ../../lib.mk
8 9
9all: $(TEST_PROGS) 10all: $(TEST_PROGS)
diff --git a/tools/testing/selftests/powerpc/signal/Makefile b/tools/testing/selftests/powerpc/signal/Makefile
index a7cbd5082e27..1fca25c6ace0 100644
--- a/tools/testing/selftests/powerpc/signal/Makefile
+++ b/tools/testing/selftests/powerpc/signal/Makefile
@@ -8,6 +8,7 @@ $(TEST_PROGS): ../harness.c ../utils.c signal.S
8CFLAGS += -maltivec 8CFLAGS += -maltivec
9signal_tm: CFLAGS += -mhtm 9signal_tm: CFLAGS += -mhtm
10 10
11top_srcdir = ../../../../..
11include ../../lib.mk 12include ../../lib.mk
12 13
13clean: 14clean:
diff --git a/tools/testing/selftests/powerpc/stringloops/Makefile b/tools/testing/selftests/powerpc/stringloops/Makefile
index 10b35c87a4f4..7fc0623d85c3 100644
--- a/tools/testing/selftests/powerpc/stringloops/Makefile
+++ b/tools/testing/selftests/powerpc/stringloops/Makefile
@@ -29,6 +29,7 @@ endif
29 29
30ASFLAGS = $(CFLAGS) 30ASFLAGS = $(CFLAGS)
31 31
32top_srcdir = ../../../../..
32include ../../lib.mk 33include ../../lib.mk
33 34
34$(TEST_GEN_PROGS): $(EXTRA_SOURCES) 35$(TEST_GEN_PROGS): $(EXTRA_SOURCES)
diff --git a/tools/testing/selftests/powerpc/switch_endian/Makefile b/tools/testing/selftests/powerpc/switch_endian/Makefile
index 30b8ff8fb82e..fcd2dcb8972b 100644
--- a/tools/testing/selftests/powerpc/switch_endian/Makefile
+++ b/tools/testing/selftests/powerpc/switch_endian/Makefile
@@ -5,6 +5,7 @@ ASFLAGS += -O2 -Wall -g -nostdlib -m64
5 5
6EXTRA_CLEAN = $(OUTPUT)/*.o $(OUTPUT)/check-reversed.S 6EXTRA_CLEAN = $(OUTPUT)/*.o $(OUTPUT)/check-reversed.S
7 7
8top_srcdir = ../../../../..
8include ../../lib.mk 9include ../../lib.mk
9 10
10$(OUTPUT)/switch_endian_test: $(OUTPUT)/check-reversed.S 11$(OUTPUT)/switch_endian_test: $(OUTPUT)/check-reversed.S
diff --git a/tools/testing/selftests/powerpc/syscalls/Makefile b/tools/testing/selftests/powerpc/syscalls/Makefile
index da22ca7c38c1..161b8846336f 100644
--- a/tools/testing/selftests/powerpc/syscalls/Makefile
+++ b/tools/testing/selftests/powerpc/syscalls/Makefile
@@ -2,6 +2,7 @@ TEST_GEN_PROGS := ipc_unmuxed
2 2
3CFLAGS += -I../../../../../usr/include 3CFLAGS += -I../../../../../usr/include
4 4
5top_srcdir = ../../../../..
5include ../../lib.mk 6include ../../lib.mk
6 7
7$(TEST_GEN_PROGS): ../harness.c 8$(TEST_GEN_PROGS): ../harness.c
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index c0e45d2dde25..9fc2cf6fbc92 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -6,6 +6,7 @@ TEST_GEN_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack
6 tm-vmxcopy tm-fork tm-tar tm-tmspr tm-vmx-unavail tm-unavailable tm-trap \ 6 tm-vmxcopy tm-fork tm-tar tm-tmspr tm-vmx-unavail tm-unavailable tm-trap \
7 $(SIGNAL_CONTEXT_CHK_TESTS) tm-sigreturn 7 $(SIGNAL_CONTEXT_CHK_TESTS) tm-sigreturn
8 8
9top_srcdir = ../../../../..
9include ../../lib.mk 10include ../../lib.mk
10 11
11$(TEST_GEN_PROGS): ../harness.c ../utils.c 12$(TEST_GEN_PROGS): ../harness.c ../utils.c
diff --git a/tools/testing/selftests/powerpc/vphn/Makefile b/tools/testing/selftests/powerpc/vphn/Makefile
index f8ced26748f8..fb82068c9fda 100644
--- a/tools/testing/selftests/powerpc/vphn/Makefile
+++ b/tools/testing/selftests/powerpc/vphn/Makefile
@@ -2,6 +2,7 @@ TEST_GEN_PROGS := test-vphn
2 2
3CFLAGS += -m64 3CFLAGS += -m64
4 4
5top_srcdir = ../../../../..
5include ../../lib.mk 6include ../../lib.mk
6 7
7$(TEST_GEN_PROGS): ../harness.c 8$(TEST_GEN_PROGS): ../harness.c
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
index 9881876d2aa0..e94b7b14bcb2 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -26,10 +26,6 @@ TEST_PROGS := run_vmtests
26 26
27include ../lib.mk 27include ../lib.mk
28 28
29$(OUTPUT)/userfaultfd: ../../../../usr/include/linux/kernel.h
30$(OUTPUT)/userfaultfd: LDLIBS += -lpthread 29$(OUTPUT)/userfaultfd: LDLIBS += -lpthread
31 30
32$(OUTPUT)/mlock-random-test: LDLIBS += -lcap 31$(OUTPUT)/mlock-random-test: LDLIBS += -lcap
33
34../../../../usr/include/linux/kernel.h:
35 make -C ../../../.. headers_install