aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSean Paul <seanpaul@chromium.org>2018-09-27 02:54:54 -0400
committerSean Paul <seanpaul@chromium.org>2018-09-27 02:54:54 -0400
commit7b76d0588477d4b6097a9048b42835a45caf5c48 (patch)
treefa4e0bcd49f8d17f26795224290c8f8460aa4116 /tools
parenta74c0aa524050e5fd6c275a153b1f37283f6e37c (diff)
parentbf78296ab1cb215d0609ac6cff4e43e941e51265 (diff)
Merge drm/drm-next into drm-misc-next
Backmerging 4.19-rc5 to pick up sun4i fix Signed-off-by: Sean Paul <seanpaul@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/arch/arm/include/uapi/asm/kvm.h13
-rw-r--r--tools/arch/arm64/include/uapi/asm/kvm.h13
-rw-r--r--tools/arch/s390/include/uapi/asm/kvm.h5
-rw-r--r--tools/arch/x86/include/uapi/asm/kvm.h37
-rw-r--r--tools/bpf/bpftool/map.c1
-rw-r--r--tools/bpf/bpftool/map_perf_ring.c5
-rw-r--r--tools/hv/hv_kvp_daemon.c2
-rw-r--r--tools/include/linux/lockdep.h3
-rw-r--r--tools/include/linux/nmi.h0
-rw-r--r--tools/include/uapi/asm-generic/unistd.h4
-rw-r--r--tools/include/uapi/drm/drm.h9
-rw-r--r--tools/include/uapi/linux/if_link.h17
-rw-r--r--tools/include/uapi/linux/kvm.h6
-rw-r--r--tools/include/uapi/linux/perf_event.h2
-rw-r--r--tools/include/uapi/linux/vhost.h18
-rwxr-xr-xtools/kvm/kvm_stat/kvm_stat59
-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/perf/Makefile.perf14
-rw-r--r--tools/perf/arch/arm64/Makefile5
-rwxr-xr-xtools/perf/arch/arm64/entry/syscalls/mksyscalltbl6
-rw-r--r--tools/perf/arch/powerpc/util/sym-handling.c4
-rw-r--r--tools/perf/arch/x86/include/arch-tests.h1
-rw-r--r--tools/perf/arch/x86/tests/Build1
-rw-r--r--tools/perf/arch/x86/tests/arch-tests.c6
-rw-r--r--tools/perf/arch/x86/tests/bp-modify.c213
-rw-r--r--tools/perf/util/annotate.c32
-rw-r--r--tools/perf/util/annotate.h1
-rw-r--r--tools/perf/util/evsel.c5
-rw-r--r--tools/perf/util/map.c11
-rw-r--r--tools/perf/util/trace-event-info.c2
-rw-r--r--tools/perf/util/trace-event-parse.c7
-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/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.sh7
-rw-r--r--tools/testing/selftests/net/tls.c49
-rw-r--r--tools/testing/selftests/networking/timestamping/Makefile1
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/police.json48
-rw-r--r--tools/testing/selftests/vm/Makefile4
-rw-r--r--tools/vm/page-types.c6
-rw-r--r--tools/vm/slabinfo.c4
61 files changed, 1076 insertions, 82 deletions
diff --git a/tools/arch/arm/include/uapi/asm/kvm.h b/tools/arch/arm/include/uapi/asm/kvm.h
index 16e006f708ca..4602464ebdfb 100644
--- a/tools/arch/arm/include/uapi/asm/kvm.h
+++ b/tools/arch/arm/include/uapi/asm/kvm.h
@@ -27,6 +27,7 @@
27#define __KVM_HAVE_GUEST_DEBUG 27#define __KVM_HAVE_GUEST_DEBUG
28#define __KVM_HAVE_IRQ_LINE 28#define __KVM_HAVE_IRQ_LINE
29#define __KVM_HAVE_READONLY_MEM 29#define __KVM_HAVE_READONLY_MEM
30#define __KVM_HAVE_VCPU_EVENTS
30 31
31#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 32#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
32 33
@@ -125,6 +126,18 @@ struct kvm_sync_regs {
125struct kvm_arch_memory_slot { 126struct kvm_arch_memory_slot {
126}; 127};
127 128
129/* for KVM_GET/SET_VCPU_EVENTS */
130struct kvm_vcpu_events {
131 struct {
132 __u8 serror_pending;
133 __u8 serror_has_esr;
134 /* Align it to 8 bytes */
135 __u8 pad[6];
136 __u64 serror_esr;
137 } exception;
138 __u32 reserved[12];
139};
140
128/* If you need to interpret the index values, here is the key: */ 141/* If you need to interpret the index values, here is the key: */
129#define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000 142#define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000
130#define KVM_REG_ARM_COPROC_SHIFT 16 143#define KVM_REG_ARM_COPROC_SHIFT 16
diff --git a/tools/arch/arm64/include/uapi/asm/kvm.h b/tools/arch/arm64/include/uapi/asm/kvm.h
index 4e76630dd655..97c3478ee6e7 100644
--- a/tools/arch/arm64/include/uapi/asm/kvm.h
+++ b/tools/arch/arm64/include/uapi/asm/kvm.h
@@ -39,6 +39,7 @@
39#define __KVM_HAVE_GUEST_DEBUG 39#define __KVM_HAVE_GUEST_DEBUG
40#define __KVM_HAVE_IRQ_LINE 40#define __KVM_HAVE_IRQ_LINE
41#define __KVM_HAVE_READONLY_MEM 41#define __KVM_HAVE_READONLY_MEM
42#define __KVM_HAVE_VCPU_EVENTS
42 43
43#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 44#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
44 45
@@ -154,6 +155,18 @@ struct kvm_sync_regs {
154struct kvm_arch_memory_slot { 155struct kvm_arch_memory_slot {
155}; 156};
156 157
158/* for KVM_GET/SET_VCPU_EVENTS */
159struct kvm_vcpu_events {
160 struct {
161 __u8 serror_pending;
162 __u8 serror_has_esr;
163 /* Align it to 8 bytes */
164 __u8 pad[6];
165 __u64 serror_esr;
166 } exception;
167 __u32 reserved[12];
168};
169
157/* If you need to interpret the index values, here is the key: */ 170/* If you need to interpret the index values, here is the key: */
158#define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000 171#define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000
159#define KVM_REG_ARM_COPROC_SHIFT 16 172#define KVM_REG_ARM_COPROC_SHIFT 16
diff --git a/tools/arch/s390/include/uapi/asm/kvm.h b/tools/arch/s390/include/uapi/asm/kvm.h
index 4cdaa55fabfe..9a50f02b9894 100644
--- a/tools/arch/s390/include/uapi/asm/kvm.h
+++ b/tools/arch/s390/include/uapi/asm/kvm.h
@@ -4,7 +4,7 @@
4/* 4/*
5 * KVM s390 specific structures and definitions 5 * KVM s390 specific structures and definitions
6 * 6 *
7 * Copyright IBM Corp. 2008 7 * Copyright IBM Corp. 2008, 2018
8 * 8 *
9 * Author(s): Carsten Otte <cotte@de.ibm.com> 9 * Author(s): Carsten Otte <cotte@de.ibm.com>
10 * Christian Borntraeger <borntraeger@de.ibm.com> 10 * Christian Borntraeger <borntraeger@de.ibm.com>
@@ -225,6 +225,7 @@ struct kvm_guest_debug_arch {
225#define KVM_SYNC_FPRS (1UL << 8) 225#define KVM_SYNC_FPRS (1UL << 8)
226#define KVM_SYNC_GSCB (1UL << 9) 226#define KVM_SYNC_GSCB (1UL << 9)
227#define KVM_SYNC_BPBC (1UL << 10) 227#define KVM_SYNC_BPBC (1UL << 10)
228#define KVM_SYNC_ETOKEN (1UL << 11)
228/* length and alignment of the sdnx as a power of two */ 229/* length and alignment of the sdnx as a power of two */
229#define SDNXC 8 230#define SDNXC 8
230#define SDNXL (1UL << SDNXC) 231#define SDNXL (1UL << SDNXC)
@@ -258,6 +259,8 @@ struct kvm_sync_regs {
258 struct { 259 struct {
259 __u64 reserved1[2]; 260 __u64 reserved1[2];
260 __u64 gscb[4]; 261 __u64 gscb[4];
262 __u64 etoken;
263 __u64 etoken_extension;
261 }; 264 };
262 }; 265 };
263}; 266};
diff --git a/tools/arch/x86/include/uapi/asm/kvm.h b/tools/arch/x86/include/uapi/asm/kvm.h
index c535c2fdea13..86299efa804a 100644
--- a/tools/arch/x86/include/uapi/asm/kvm.h
+++ b/tools/arch/x86/include/uapi/asm/kvm.h
@@ -378,4 +378,41 @@ struct kvm_sync_regs {
378#define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0) 378#define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0)
379#define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1) 379#define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1)
380 380
381#define KVM_STATE_NESTED_GUEST_MODE 0x00000001
382#define KVM_STATE_NESTED_RUN_PENDING 0x00000002
383
384#define KVM_STATE_NESTED_SMM_GUEST_MODE 0x00000001
385#define KVM_STATE_NESTED_SMM_VMXON 0x00000002
386
387struct kvm_vmx_nested_state {
388 __u64 vmxon_pa;
389 __u64 vmcs_pa;
390
391 struct {
392 __u16 flags;
393 } smm;
394};
395
396/* for KVM_CAP_NESTED_STATE */
397struct kvm_nested_state {
398 /* KVM_STATE_* flags */
399 __u16 flags;
400
401 /* 0 for VMX, 1 for SVM. */
402 __u16 format;
403
404 /* 128 for SVM, 128 + VMCS size for VMX. */
405 __u32 size;
406
407 union {
408 /* VMXON, VMCS */
409 struct kvm_vmx_nested_state vmx;
410
411 /* Pad the header to 128 bytes. */
412 __u8 pad[120];
413 };
414
415 __u8 data[0];
416};
417
381#endif /* _ASM_X86_KVM_H */ 418#endif /* _ASM_X86_KVM_H */
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index b2ec20e562bd..b455930a3eaf 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -68,6 +68,7 @@ static const char * const map_type_name[] = {
68 [BPF_MAP_TYPE_DEVMAP] = "devmap", 68 [BPF_MAP_TYPE_DEVMAP] = "devmap",
69 [BPF_MAP_TYPE_SOCKMAP] = "sockmap", 69 [BPF_MAP_TYPE_SOCKMAP] = "sockmap",
70 [BPF_MAP_TYPE_CPUMAP] = "cpumap", 70 [BPF_MAP_TYPE_CPUMAP] = "cpumap",
71 [BPF_MAP_TYPE_XSKMAP] = "xskmap",
71 [BPF_MAP_TYPE_SOCKHASH] = "sockhash", 72 [BPF_MAP_TYPE_SOCKHASH] = "sockhash",
72 [BPF_MAP_TYPE_CGROUP_STORAGE] = "cgroup_storage", 73 [BPF_MAP_TYPE_CGROUP_STORAGE] = "cgroup_storage",
73}; 74};
diff --git a/tools/bpf/bpftool/map_perf_ring.c b/tools/bpf/bpftool/map_perf_ring.c
index 1832100d1b27..6d41323be291 100644
--- a/tools/bpf/bpftool/map_perf_ring.c
+++ b/tools/bpf/bpftool/map_perf_ring.c
@@ -194,8 +194,10 @@ int do_event_pipe(int argc, char **argv)
194 } 194 }
195 195
196 while (argc) { 196 while (argc) {
197 if (argc < 2) 197 if (argc < 2) {
198 BAD_ARG(); 198 BAD_ARG();
199 goto err_close_map;
200 }
199 201
200 if (is_prefix(*argv, "cpu")) { 202 if (is_prefix(*argv, "cpu")) {
201 char *endptr; 203 char *endptr;
@@ -221,6 +223,7 @@ int do_event_pipe(int argc, char **argv)
221 NEXT_ARG(); 223 NEXT_ARG();
222 } else { 224 } else {
223 BAD_ARG(); 225 BAD_ARG();
226 goto err_close_map;
224 } 227 }
225 228
226 do_all = false; 229 do_all = false;
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index dbf6e8bd98ba..bbb2a8ef367c 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -286,7 +286,7 @@ static int kvp_key_delete(int pool, const __u8 *key, int key_size)
286 * Found a match; just move the remaining 286 * Found a match; just move the remaining
287 * entries up. 287 * entries up.
288 */ 288 */
289 if (i == num_records) { 289 if (i == (num_records - 1)) {
290 kvp_file_info[pool].num_records--; 290 kvp_file_info[pool].num_records--;
291 kvp_update_file(pool); 291 kvp_update_file(pool);
292 return 0; 292 return 0;
diff --git a/tools/include/linux/lockdep.h b/tools/include/linux/lockdep.h
index 6b0c36a58fcb..e56997288f2b 100644
--- a/tools/include/linux/lockdep.h
+++ b/tools/include/linux/lockdep.h
@@ -30,9 +30,12 @@ struct task_struct {
30 struct held_lock held_locks[MAX_LOCK_DEPTH]; 30 struct held_lock held_locks[MAX_LOCK_DEPTH];
31 gfp_t lockdep_reclaim_gfp; 31 gfp_t lockdep_reclaim_gfp;
32 int pid; 32 int pid;
33 int state;
33 char comm[17]; 34 char comm[17];
34}; 35};
35 36
37#define TASK_RUNNING 0
38
36extern struct task_struct *__curr(void); 39extern struct task_struct *__curr(void);
37 40
38#define current (__curr()) 41#define current (__curr())
diff --git a/tools/include/linux/nmi.h b/tools/include/linux/nmi.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/tools/include/linux/nmi.h
diff --git a/tools/include/uapi/asm-generic/unistd.h b/tools/include/uapi/asm-generic/unistd.h
index 42990676a55e..df4bedb9b01c 100644
--- a/tools/include/uapi/asm-generic/unistd.h
+++ b/tools/include/uapi/asm-generic/unistd.h
@@ -734,9 +734,11 @@ __SYSCALL(__NR_pkey_free, sys_pkey_free)
734__SYSCALL(__NR_statx, sys_statx) 734__SYSCALL(__NR_statx, sys_statx)
735#define __NR_io_pgetevents 292 735#define __NR_io_pgetevents 292
736__SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) 736__SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents)
737#define __NR_rseq 293
738__SYSCALL(__NR_rseq, sys_rseq)
737 739
738#undef __NR_syscalls 740#undef __NR_syscalls
739#define __NR_syscalls 293 741#define __NR_syscalls 294
740 742
741/* 743/*
742 * 32 bit systems traditionally used different 744 * 32 bit systems traditionally used different
diff --git a/tools/include/uapi/drm/drm.h b/tools/include/uapi/drm/drm.h
index 9c660e1688ab..300f336633f2 100644
--- a/tools/include/uapi/drm/drm.h
+++ b/tools/include/uapi/drm/drm.h
@@ -687,6 +687,15 @@ struct drm_get_cap {
687 */ 687 */
688#define DRM_CLIENT_CAP_ASPECT_RATIO 4 688#define DRM_CLIENT_CAP_ASPECT_RATIO 4
689 689
690/**
691 * DRM_CLIENT_CAP_WRITEBACK_CONNECTORS
692 *
693 * If set to 1, the DRM core will expose special connectors to be used for
694 * writing back to memory the scene setup in the commit. Depends on client
695 * also supporting DRM_CLIENT_CAP_ATOMIC
696 */
697#define DRM_CLIENT_CAP_WRITEBACK_CONNECTORS 5
698
690/** DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */ 699/** DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */
691struct drm_set_client_cap { 700struct drm_set_client_cap {
692 __u64 capability; 701 __u64 capability;
diff --git a/tools/include/uapi/linux/if_link.h b/tools/include/uapi/linux/if_link.h
index cf01b6824244..43391e2d1153 100644
--- a/tools/include/uapi/linux/if_link.h
+++ b/tools/include/uapi/linux/if_link.h
@@ -164,6 +164,8 @@ enum {
164 IFLA_CARRIER_UP_COUNT, 164 IFLA_CARRIER_UP_COUNT,
165 IFLA_CARRIER_DOWN_COUNT, 165 IFLA_CARRIER_DOWN_COUNT,
166 IFLA_NEW_IFINDEX, 166 IFLA_NEW_IFINDEX,
167 IFLA_MIN_MTU,
168 IFLA_MAX_MTU,
167 __IFLA_MAX 169 __IFLA_MAX
168}; 170};
169 171
@@ -334,6 +336,7 @@ enum {
334 IFLA_BRPORT_GROUP_FWD_MASK, 336 IFLA_BRPORT_GROUP_FWD_MASK,
335 IFLA_BRPORT_NEIGH_SUPPRESS, 337 IFLA_BRPORT_NEIGH_SUPPRESS,
336 IFLA_BRPORT_ISOLATED, 338 IFLA_BRPORT_ISOLATED,
339 IFLA_BRPORT_BACKUP_PORT,
337 __IFLA_BRPORT_MAX 340 __IFLA_BRPORT_MAX
338}; 341};
339#define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1) 342#define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
@@ -459,6 +462,16 @@ enum {
459 462
460#define IFLA_MACSEC_MAX (__IFLA_MACSEC_MAX - 1) 463#define IFLA_MACSEC_MAX (__IFLA_MACSEC_MAX - 1)
461 464
465/* XFRM section */
466enum {
467 IFLA_XFRM_UNSPEC,
468 IFLA_XFRM_LINK,
469 IFLA_XFRM_IF_ID,
470 __IFLA_XFRM_MAX
471};
472
473#define IFLA_XFRM_MAX (__IFLA_XFRM_MAX - 1)
474
462enum macsec_validation_type { 475enum macsec_validation_type {
463 MACSEC_VALIDATE_DISABLED = 0, 476 MACSEC_VALIDATE_DISABLED = 0,
464 MACSEC_VALIDATE_CHECK = 1, 477 MACSEC_VALIDATE_CHECK = 1,
@@ -920,6 +933,7 @@ enum {
920 XDP_ATTACHED_DRV, 933 XDP_ATTACHED_DRV,
921 XDP_ATTACHED_SKB, 934 XDP_ATTACHED_SKB,
922 XDP_ATTACHED_HW, 935 XDP_ATTACHED_HW,
936 XDP_ATTACHED_MULTI,
923}; 937};
924 938
925enum { 939enum {
@@ -928,6 +942,9 @@ enum {
928 IFLA_XDP_ATTACHED, 942 IFLA_XDP_ATTACHED,
929 IFLA_XDP_FLAGS, 943 IFLA_XDP_FLAGS,
930 IFLA_XDP_PROG_ID, 944 IFLA_XDP_PROG_ID,
945 IFLA_XDP_DRV_PROG_ID,
946 IFLA_XDP_SKB_PROG_ID,
947 IFLA_XDP_HW_PROG_ID,
931 __IFLA_XDP_MAX, 948 __IFLA_XDP_MAX,
932}; 949};
933 950
diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h
index b6270a3b38e9..07548de5c988 100644
--- a/tools/include/uapi/linux/kvm.h
+++ b/tools/include/uapi/linux/kvm.h
@@ -949,6 +949,9 @@ struct kvm_ppc_resize_hpt {
949#define KVM_CAP_GET_MSR_FEATURES 153 949#define KVM_CAP_GET_MSR_FEATURES 153
950#define KVM_CAP_HYPERV_EVENTFD 154 950#define KVM_CAP_HYPERV_EVENTFD 154
951#define KVM_CAP_HYPERV_TLBFLUSH 155 951#define KVM_CAP_HYPERV_TLBFLUSH 155
952#define KVM_CAP_S390_HPAGE_1M 156
953#define KVM_CAP_NESTED_STATE 157
954#define KVM_CAP_ARM_INJECT_SERROR_ESR 158
952 955
953#ifdef KVM_CAP_IRQ_ROUTING 956#ifdef KVM_CAP_IRQ_ROUTING
954 957
@@ -1391,6 +1394,9 @@ struct kvm_enc_region {
1391/* Available with KVM_CAP_HYPERV_EVENTFD */ 1394/* Available with KVM_CAP_HYPERV_EVENTFD */
1392#define KVM_HYPERV_EVENTFD _IOW(KVMIO, 0xbd, struct kvm_hyperv_eventfd) 1395#define KVM_HYPERV_EVENTFD _IOW(KVMIO, 0xbd, struct kvm_hyperv_eventfd)
1393 1396
1397/* Available with KVM_CAP_NESTED_STATE */
1398#define KVM_GET_NESTED_STATE _IOWR(KVMIO, 0xbe, struct kvm_nested_state)
1399#define KVM_SET_NESTED_STATE _IOW(KVMIO, 0xbf, struct kvm_nested_state)
1394 1400
1395/* Secure Encrypted Virtualization command */ 1401/* Secure Encrypted Virtualization command */
1396enum sev_cmd_id { 1402enum sev_cmd_id {
diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index eeb787b1c53c..f35eb72739c0 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -144,7 +144,7 @@ enum perf_event_sample_format {
144 144
145 PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */ 145 PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */
146 146
147 __PERF_SAMPLE_CALLCHAIN_EARLY = 1ULL << 63, 147 __PERF_SAMPLE_CALLCHAIN_EARLY = 1ULL << 63, /* non-ABI; internal use */
148}; 148};
149 149
150/* 150/*
diff --git a/tools/include/uapi/linux/vhost.h b/tools/include/uapi/linux/vhost.h
index c51f8e5cc608..84c3de89696a 100644
--- a/tools/include/uapi/linux/vhost.h
+++ b/tools/include/uapi/linux/vhost.h
@@ -65,6 +65,7 @@ struct vhost_iotlb_msg {
65}; 65};
66 66
67#define VHOST_IOTLB_MSG 0x1 67#define VHOST_IOTLB_MSG 0x1
68#define VHOST_IOTLB_MSG_V2 0x2
68 69
69struct vhost_msg { 70struct vhost_msg {
70 int type; 71 int type;
@@ -74,6 +75,15 @@ struct vhost_msg {
74 }; 75 };
75}; 76};
76 77
78struct vhost_msg_v2 {
79 __u32 type;
80 __u32 reserved;
81 union {
82 struct vhost_iotlb_msg iotlb;
83 __u8 padding[64];
84 };
85};
86
77struct vhost_memory_region { 87struct vhost_memory_region {
78 __u64 guest_phys_addr; 88 __u64 guest_phys_addr;
79 __u64 memory_size; /* bytes */ 89 __u64 memory_size; /* bytes */
@@ -160,6 +170,14 @@ struct vhost_memory {
160#define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \ 170#define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \
161 struct vhost_vring_state) 171 struct vhost_vring_state)
162 172
173/* Set or get vhost backend capability */
174
175/* Use message type V2 */
176#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
177
178#define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
179#define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
180
163/* VHOST_NET specific defines */ 181/* VHOST_NET specific defines */
164 182
165/* Attach virtio net ring to a raw socket, or tap device. 183/* Attach virtio net ring to a raw socket, or tap device.
diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index 56c4b3f8a01b..439b8a27488d 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -759,12 +759,18 @@ class DebugfsProvider(Provider):
759 if len(vms) == 0: 759 if len(vms) == 0:
760 self.do_read = False 760 self.do_read = False
761 761
762 self.paths = filter(lambda x: "{}-".format(pid) in x, vms) 762 self.paths = list(filter(lambda x: "{}-".format(pid) in x, vms))
763 763
764 else: 764 else:
765 self.paths = [] 765 self.paths = []
766 self.do_read = True 766 self.do_read = True
767 self.reset() 767
768 def _verify_paths(self):
769 """Remove invalid paths"""
770 for path in self.paths:
771 if not os.path.exists(os.path.join(PATH_DEBUGFS_KVM, path)):
772 self.paths.remove(path)
773 continue
768 774
769 def read(self, reset=0, by_guest=0): 775 def read(self, reset=0, by_guest=0):
770 """Returns a dict with format:'file name / field -> current value'. 776 """Returns a dict with format:'file name / field -> current value'.
@@ -780,6 +786,7 @@ class DebugfsProvider(Provider):
780 # If no debugfs filtering support is available, then don't read. 786 # If no debugfs filtering support is available, then don't read.
781 if not self.do_read: 787 if not self.do_read:
782 return results 788 return results
789 self._verify_paths()
783 790
784 paths = self.paths 791 paths = self.paths
785 if self._pid == 0: 792 if self._pid == 0:
@@ -1096,15 +1103,16 @@ class Tui(object):
1096 pid = self.stats.pid_filter 1103 pid = self.stats.pid_filter
1097 self.screen.erase() 1104 self.screen.erase()
1098 gname = self.get_gname_from_pid(pid) 1105 gname = self.get_gname_from_pid(pid)
1106 self._gname = gname
1099 if gname: 1107 if gname:
1100 gname = ('({})'.format(gname[:MAX_GUEST_NAME_LEN] + '...' 1108 gname = ('({})'.format(gname[:MAX_GUEST_NAME_LEN] + '...'
1101 if len(gname) > MAX_GUEST_NAME_LEN 1109 if len(gname) > MAX_GUEST_NAME_LEN
1102 else gname)) 1110 else gname))
1103 if pid > 0: 1111 if pid > 0:
1104 self.screen.addstr(0, 0, 'kvm statistics - pid {0} {1}' 1112 self._headline = 'kvm statistics - pid {0} {1}'.format(pid, gname)
1105 .format(pid, gname), curses.A_BOLD)
1106 else: 1113 else:
1107 self.screen.addstr(0, 0, 'kvm statistics - summary', curses.A_BOLD) 1114 self._headline = 'kvm statistics - summary'
1115 self.screen.addstr(0, 0, self._headline, curses.A_BOLD)
1108 if self.stats.fields_filter: 1116 if self.stats.fields_filter:
1109 regex = self.stats.fields_filter 1117 regex = self.stats.fields_filter
1110 if len(regex) > MAX_REGEX_LEN: 1118 if len(regex) > MAX_REGEX_LEN:
@@ -1162,6 +1170,19 @@ class Tui(object):
1162 1170
1163 return sorted_items 1171 return sorted_items
1164 1172
1173 if not self._is_running_guest(self.stats.pid_filter):
1174 if self._gname:
1175 try: # ...to identify the guest by name in case it's back
1176 pids = self.get_pid_from_gname(self._gname)
1177 if len(pids) == 1:
1178 self._refresh_header(pids[0])
1179 self._update_pid(pids[0])
1180 return
1181 except:
1182 pass
1183 self._display_guest_dead()
1184 # leave final data on screen
1185 return
1165 row = 3 1186 row = 3
1166 self.screen.move(row, 0) 1187 self.screen.move(row, 0)
1167 self.screen.clrtobot() 1188 self.screen.clrtobot()
@@ -1184,6 +1205,7 @@ class Tui(object):
1184 # print events 1205 # print events
1185 tavg = 0 1206 tavg = 0
1186 tcur = 0 1207 tcur = 0
1208 guest_removed = False
1187 for key, values in get_sorted_events(self, stats): 1209 for key, values in get_sorted_events(self, stats):
1188 if row >= self.screen.getmaxyx()[0] - 1 or values == (0, 0): 1210 if row >= self.screen.getmaxyx()[0] - 1 or values == (0, 0):
1189 break 1211 break
@@ -1191,7 +1213,10 @@ class Tui(object):
1191 key = self.get_gname_from_pid(key) 1213 key = self.get_gname_from_pid(key)
1192 if not key: 1214 if not key:
1193 continue 1215 continue
1194 cur = int(round(values.delta / sleeptime)) if values.delta else '' 1216 cur = int(round(values.delta / sleeptime)) if values.delta else 0
1217 if cur < 0:
1218 guest_removed = True
1219 continue
1195 if key[0] != ' ': 1220 if key[0] != ' ':
1196 if values.delta: 1221 if values.delta:
1197 tcur += values.delta 1222 tcur += values.delta
@@ -1204,13 +1229,21 @@ class Tui(object):
1204 values.value * 100 / float(ltotal), cur)) 1229 values.value * 100 / float(ltotal), cur))
1205 row += 1 1230 row += 1
1206 if row == 3: 1231 if row == 3:
1207 self.screen.addstr(4, 1, 'No matching events reported yet') 1232 if guest_removed:
1233 self.screen.addstr(4, 1, 'Guest removed, updating...')
1234 else:
1235 self.screen.addstr(4, 1, 'No matching events reported yet')
1208 if row > 4: 1236 if row > 4:
1209 tavg = int(round(tcur / sleeptime)) if tcur > 0 else '' 1237 tavg = int(round(tcur / sleeptime)) if tcur > 0 else ''
1210 self.screen.addstr(row, 1, '%-40s %10d %8s' % 1238 self.screen.addstr(row, 1, '%-40s %10d %8s' %
1211 ('Total', total, tavg), curses.A_BOLD) 1239 ('Total', total, tavg), curses.A_BOLD)
1212 self.screen.refresh() 1240 self.screen.refresh()
1213 1241
1242 def _display_guest_dead(self):
1243 marker = ' Guest is DEAD '
1244 y = min(len(self._headline), 80 - len(marker))
1245 self.screen.addstr(0, y, marker, curses.A_BLINK | curses.A_STANDOUT)
1246
1214 def _show_msg(self, text): 1247 def _show_msg(self, text):
1215 """Display message centered text and exit on key press""" 1248 """Display message centered text and exit on key press"""
1216 hint = 'Press any key to continue' 1249 hint = 'Press any key to continue'
@@ -1219,10 +1252,10 @@ class Tui(object):
1219 (x, term_width) = self.screen.getmaxyx() 1252 (x, term_width) = self.screen.getmaxyx()
1220 row = 2 1253 row = 2
1221 for line in text: 1254 for line in text:
1222 start = (term_width - len(line)) / 2 1255 start = (term_width - len(line)) // 2
1223 self.screen.addstr(row, start, line) 1256 self.screen.addstr(row, start, line)
1224 row += 1 1257 row += 1
1225 self.screen.addstr(row + 1, (term_width - len(hint)) / 2, hint, 1258 self.screen.addstr(row + 1, (term_width - len(hint)) // 2, hint,
1226 curses.A_STANDOUT) 1259 curses.A_STANDOUT)
1227 self.screen.getkey() 1260 self.screen.getkey()
1228 1261
@@ -1319,6 +1352,12 @@ class Tui(object):
1319 msg = '"' + str(val) + '": Invalid value' 1352 msg = '"' + str(val) + '": Invalid value'
1320 self._refresh_header() 1353 self._refresh_header()
1321 1354
1355 def _is_running_guest(self, pid):
1356 """Check if pid is still a running process."""
1357 if not pid:
1358 return True
1359 return os.path.isdir(os.path.join('/proc/', str(pid)))
1360
1322 def _show_vm_selection_by_guest(self): 1361 def _show_vm_selection_by_guest(self):
1323 """Draws guest selection mask. 1362 """Draws guest selection mask.
1324 1363
@@ -1346,7 +1385,7 @@ class Tui(object):
1346 if not guest or guest == '0': 1385 if not guest or guest == '0':
1347 break 1386 break
1348 if guest.isdigit(): 1387 if guest.isdigit():
1349 if not os.path.isdir(os.path.join('/proc/', guest)): 1388 if not self._is_running_guest(guest):
1350 msg = '"' + guest + '": Not a running process' 1389 msg = '"' + guest + '": Not a running process'
1351 continue 1390 continue
1352 pid = int(guest) 1391 pid = int(guest)
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/perf/Makefile.perf b/tools/perf/Makefile.perf
index b3d1b12a5081..5224ade3d5af 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -777,14 +777,12 @@ endif
777 $(call QUIET_INSTALL, libexec) \ 777 $(call QUIET_INSTALL, libexec) \
778 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' 778 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
779ifndef NO_LIBBPF 779ifndef NO_LIBBPF
780 $(call QUIET_INSTALL, lib) \ 780 $(call QUIET_INSTALL, bpf-headers) \
781 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf' 781 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'; \
782 $(call QUIET_INSTALL, include/bpf) \ 782 $(INSTALL) include/bpf/*.h -t '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
783 $(INSTALL) include/bpf/*.h '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf' 783 $(call QUIET_INSTALL, bpf-examples) \
784 $(call QUIET_INSTALL, lib) \ 784 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'; \
785 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf' 785 $(INSTALL) examples/bpf/*.c -t '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
786 $(call QUIET_INSTALL, examples/bpf) \
787 $(INSTALL) examples/bpf/*.c '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
788endif 786endif
789 $(call QUIET_INSTALL, perf-archive) \ 787 $(call QUIET_INSTALL, perf-archive) \
790 $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' 788 $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
diff --git a/tools/perf/arch/arm64/Makefile b/tools/perf/arch/arm64/Makefile
index f013b115dc86..dbef716a1913 100644
--- a/tools/perf/arch/arm64/Makefile
+++ b/tools/perf/arch/arm64/Makefile
@@ -11,7 +11,8 @@ PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
11 11
12out := $(OUTPUT)arch/arm64/include/generated/asm 12out := $(OUTPUT)arch/arm64/include/generated/asm
13header := $(out)/syscalls.c 13header := $(out)/syscalls.c
14sysdef := $(srctree)/tools/include/uapi/asm-generic/unistd.h 14incpath := $(srctree)/tools
15sysdef := $(srctree)/tools/arch/arm64/include/uapi/asm/unistd.h
15sysprf := $(srctree)/tools/perf/arch/arm64/entry/syscalls/ 16sysprf := $(srctree)/tools/perf/arch/arm64/entry/syscalls/
16systbl := $(sysprf)/mksyscalltbl 17systbl := $(sysprf)/mksyscalltbl
17 18
@@ -19,7 +20,7 @@ systbl := $(sysprf)/mksyscalltbl
19_dummy := $(shell [ -d '$(out)' ] || mkdir -p '$(out)') 20_dummy := $(shell [ -d '$(out)' ] || mkdir -p '$(out)')
20 21
21$(header): $(sysdef) $(systbl) 22$(header): $(sysdef) $(systbl)
22 $(Q)$(SHELL) '$(systbl)' '$(CC)' '$(HOSTCC)' $(sysdef) > $@ 23 $(Q)$(SHELL) '$(systbl)' '$(CC)' '$(HOSTCC)' $(incpath) $(sysdef) > $@
23 24
24clean:: 25clean::
25 $(call QUIET_CLEAN, arm64) $(RM) $(header) 26 $(call QUIET_CLEAN, arm64) $(RM) $(header)
diff --git a/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl b/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl
index 52e197317d3e..2dbb8cade048 100755
--- a/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl
+++ b/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl
@@ -11,7 +11,8 @@
11 11
12gcc=$1 12gcc=$1
13hostcc=$2 13hostcc=$2
14input=$3 14incpath=$3
15input=$4
15 16
16if ! test -r $input; then 17if ! test -r $input; then
17 echo "Could not read input file" >&2 18 echo "Could not read input file" >&2
@@ -28,7 +29,6 @@ create_table_from_c()
28 29
29 cat <<-_EoHEADER 30 cat <<-_EoHEADER
30 #include <stdio.h> 31 #include <stdio.h>
31 #define __ARCH_WANT_RENAMEAT
32 #include "$input" 32 #include "$input"
33 int main(int argc, char *argv[]) 33 int main(int argc, char *argv[])
34 { 34 {
@@ -42,7 +42,7 @@ create_table_from_c()
42 printf "%s\n" " printf(\"#define SYSCALLTBL_ARM64_MAX_ID %d\\n\", __NR_$last_sc);" 42 printf "%s\n" " printf(\"#define SYSCALLTBL_ARM64_MAX_ID %d\\n\", __NR_$last_sc);"
43 printf "}\n" 43 printf "}\n"
44 44
45 } | $hostcc -o $create_table_exe -x c - 45 } | $hostcc -I $incpath/include/uapi -o $create_table_exe -x c -
46 46
47 $create_table_exe 47 $create_table_exe
48 48
diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c
index 20e7d74d86cd..10a44e946f77 100644
--- a/tools/perf/arch/powerpc/util/sym-handling.c
+++ b/tools/perf/arch/powerpc/util/sym-handling.c
@@ -22,15 +22,16 @@ bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
22 22
23#endif 23#endif
24 24
25#if !defined(_CALL_ELF) || _CALL_ELF != 2
26int arch__choose_best_symbol(struct symbol *syma, 25int arch__choose_best_symbol(struct symbol *syma,
27 struct symbol *symb __maybe_unused) 26 struct symbol *symb __maybe_unused)
28{ 27{
29 char *sym = syma->name; 28 char *sym = syma->name;
30 29
30#if !defined(_CALL_ELF) || _CALL_ELF != 2
31 /* Skip over any initial dot */ 31 /* Skip over any initial dot */
32 if (*sym == '.') 32 if (*sym == '.')
33 sym++; 33 sym++;
34#endif
34 35
35 /* Avoid "SyS" kernel syscall aliases */ 36 /* Avoid "SyS" kernel syscall aliases */
36 if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3)) 37 if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
@@ -41,6 +42,7 @@ int arch__choose_best_symbol(struct symbol *syma,
41 return SYMBOL_A; 42 return SYMBOL_A;
42} 43}
43 44
45#if !defined(_CALL_ELF) || _CALL_ELF != 2
44/* Allow matching against dot variants */ 46/* Allow matching against dot variants */
45int arch__compare_symbol_names(const char *namea, const char *nameb) 47int arch__compare_symbol_names(const char *namea, const char *nameb)
46{ 48{
diff --git a/tools/perf/arch/x86/include/arch-tests.h b/tools/perf/arch/x86/include/arch-tests.h
index c1bd979b957b..613709cfbbd0 100644
--- a/tools/perf/arch/x86/include/arch-tests.h
+++ b/tools/perf/arch/x86/include/arch-tests.h
@@ -9,6 +9,7 @@ struct test;
9int test__rdpmc(struct test *test __maybe_unused, int subtest); 9int test__rdpmc(struct test *test __maybe_unused, int subtest);
10int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest); 10int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest);
11int test__insn_x86(struct test *test __maybe_unused, int subtest); 11int test__insn_x86(struct test *test __maybe_unused, int subtest);
12int test__bp_modify(struct test *test, int subtest);
12 13
13#ifdef HAVE_DWARF_UNWIND_SUPPORT 14#ifdef HAVE_DWARF_UNWIND_SUPPORT
14struct thread; 15struct thread;
diff --git a/tools/perf/arch/x86/tests/Build b/tools/perf/arch/x86/tests/Build
index 8e2c5a38c3b9..586849ff83a0 100644
--- a/tools/perf/arch/x86/tests/Build
+++ b/tools/perf/arch/x86/tests/Build
@@ -5,3 +5,4 @@ libperf-y += arch-tests.o
5libperf-y += rdpmc.o 5libperf-y += rdpmc.o
6libperf-y += perf-time-to-tsc.o 6libperf-y += perf-time-to-tsc.o
7libperf-$(CONFIG_AUXTRACE) += insn-x86.o 7libperf-$(CONFIG_AUXTRACE) += insn-x86.o
8libperf-$(CONFIG_X86_64) += bp-modify.o
diff --git a/tools/perf/arch/x86/tests/arch-tests.c b/tools/perf/arch/x86/tests/arch-tests.c
index cc1802ff5410..d47d3f8e3c8e 100644
--- a/tools/perf/arch/x86/tests/arch-tests.c
+++ b/tools/perf/arch/x86/tests/arch-tests.c
@@ -24,6 +24,12 @@ struct test arch_tests[] = {
24 .func = test__insn_x86, 24 .func = test__insn_x86,
25 }, 25 },
26#endif 26#endif
27#if defined(__x86_64__)
28 {
29 .desc = "x86 bp modify",
30 .func = test__bp_modify,
31 },
32#endif
27 { 33 {
28 .func = NULL, 34 .func = NULL,
29 }, 35 },
diff --git a/tools/perf/arch/x86/tests/bp-modify.c b/tools/perf/arch/x86/tests/bp-modify.c
new file mode 100644
index 000000000000..f53e4406709f
--- /dev/null
+++ b/tools/perf/arch/x86/tests/bp-modify.c
@@ -0,0 +1,213 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/compiler.h>
3#include <sys/types.h>
4#include <sys/wait.h>
5#include <sys/user.h>
6#include <syscall.h>
7#include <unistd.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <sys/ptrace.h>
11#include <asm/ptrace.h>
12#include <errno.h>
13#include "debug.h"
14#include "tests/tests.h"
15#include "arch-tests.h"
16
17static noinline int bp_1(void)
18{
19 pr_debug("in %s\n", __func__);
20 return 0;
21}
22
23static noinline int bp_2(void)
24{
25 pr_debug("in %s\n", __func__);
26 return 0;
27}
28
29static int spawn_child(void)
30{
31 int child = fork();
32
33 if (child == 0) {
34 /*
35 * The child sets itself for as tracee and
36 * waits in signal for parent to trace it,
37 * then it calls bp_1 and quits.
38 */
39 int err = ptrace(PTRACE_TRACEME, 0, NULL, NULL);
40
41 if (err) {
42 pr_debug("failed to PTRACE_TRACEME\n");
43 exit(1);
44 }
45
46 raise(SIGCONT);
47 bp_1();
48 exit(0);
49 }
50
51 return child;
52}
53
54/*
55 * This tests creates HW breakpoint, tries to
56 * change it and checks it was properly changed.
57 */
58static int bp_modify1(void)
59{
60 pid_t child;
61 int status;
62 unsigned long rip = 0, dr7 = 1;
63
64 child = spawn_child();
65
66 waitpid(child, &status, 0);
67 if (WIFEXITED(status)) {
68 pr_debug("tracee exited prematurely 1\n");
69 return TEST_FAIL;
70 }
71
72 /*
73 * The parent does following steps:
74 * - creates a new breakpoint (id 0) for bp_2 function
75 * - changes that breakponit to bp_1 function
76 * - waits for the breakpoint to hit and checks
77 * it has proper rip of bp_1 function
78 * - detaches the child
79 */
80 if (ptrace(PTRACE_POKEUSER, child,
81 offsetof(struct user, u_debugreg[0]), bp_2)) {
82 pr_debug("failed to set breakpoint, 1st time: %s\n",
83 strerror(errno));
84 goto out;
85 }
86
87 if (ptrace(PTRACE_POKEUSER, child,
88 offsetof(struct user, u_debugreg[0]), bp_1)) {
89 pr_debug("failed to set breakpoint, 2nd time: %s\n",
90 strerror(errno));
91 goto out;
92 }
93
94 if (ptrace(PTRACE_POKEUSER, child,
95 offsetof(struct user, u_debugreg[7]), dr7)) {
96 pr_debug("failed to set dr7: %s\n", strerror(errno));
97 goto out;
98 }
99
100 if (ptrace(PTRACE_CONT, child, NULL, NULL)) {
101 pr_debug("failed to PTRACE_CONT: %s\n", strerror(errno));
102 goto out;
103 }
104
105 waitpid(child, &status, 0);
106 if (WIFEXITED(status)) {
107 pr_debug("tracee exited prematurely 2\n");
108 return TEST_FAIL;
109 }
110
111 rip = ptrace(PTRACE_PEEKUSER, child,
112 offsetof(struct user_regs_struct, rip), NULL);
113 if (rip == (unsigned long) -1) {
114 pr_debug("failed to PTRACE_PEEKUSER: %s\n",
115 strerror(errno));
116 goto out;
117 }
118
119 pr_debug("rip %lx, bp_1 %p\n", rip, bp_1);
120
121out:
122 if (ptrace(PTRACE_DETACH, child, NULL, NULL)) {
123 pr_debug("failed to PTRACE_DETACH: %s", strerror(errno));
124 return TEST_FAIL;
125 }
126
127 return rip == (unsigned long) bp_1 ? TEST_OK : TEST_FAIL;
128}
129
130/*
131 * This tests creates HW breakpoint, tries to
132 * change it to bogus value and checks the original
133 * breakpoint is hit.
134 */
135static int bp_modify2(void)
136{
137 pid_t child;
138 int status;
139 unsigned long rip = 0, dr7 = 1;
140
141 child = spawn_child();
142
143 waitpid(child, &status, 0);
144 if (WIFEXITED(status)) {
145 pr_debug("tracee exited prematurely 1\n");
146 return TEST_FAIL;
147 }
148
149 /*
150 * The parent does following steps:
151 * - creates a new breakpoint (id 0) for bp_1 function
152 * - tries to change that breakpoint to (-1) address
153 * - waits for the breakpoint to hit and checks
154 * it has proper rip of bp_1 function
155 * - detaches the child
156 */
157 if (ptrace(PTRACE_POKEUSER, child,
158 offsetof(struct user, u_debugreg[0]), bp_1)) {
159 pr_debug("failed to set breakpoint: %s\n",
160 strerror(errno));
161 goto out;
162 }
163
164 if (ptrace(PTRACE_POKEUSER, child,
165 offsetof(struct user, u_debugreg[7]), dr7)) {
166 pr_debug("failed to set dr7: %s\n", strerror(errno));
167 goto out;
168 }
169
170 if (!ptrace(PTRACE_POKEUSER, child,
171 offsetof(struct user, u_debugreg[0]), (unsigned long) (-1))) {
172 pr_debug("failed, breakpoint set to bogus address\n");
173 goto out;
174 }
175
176 if (ptrace(PTRACE_CONT, child, NULL, NULL)) {
177 pr_debug("failed to PTRACE_CONT: %s\n", strerror(errno));
178 goto out;
179 }
180
181 waitpid(child, &status, 0);
182 if (WIFEXITED(status)) {
183 pr_debug("tracee exited prematurely 2\n");
184 return TEST_FAIL;
185 }
186
187 rip = ptrace(PTRACE_PEEKUSER, child,
188 offsetof(struct user_regs_struct, rip), NULL);
189 if (rip == (unsigned long) -1) {
190 pr_debug("failed to PTRACE_PEEKUSER: %s\n",
191 strerror(errno));
192 goto out;
193 }
194
195 pr_debug("rip %lx, bp_1 %p\n", rip, bp_1);
196
197out:
198 if (ptrace(PTRACE_DETACH, child, NULL, NULL)) {
199 pr_debug("failed to PTRACE_DETACH: %s", strerror(errno));
200 return TEST_FAIL;
201 }
202
203 return rip == (unsigned long) bp_1 ? TEST_OK : TEST_FAIL;
204}
205
206int test__bp_modify(struct test *test __maybe_unused,
207 int subtest __maybe_unused)
208{
209 TEST_ASSERT_VAL("modify test 1 failed\n", !bp_modify1());
210 TEST_ASSERT_VAL("modify test 2 failed\n", !bp_modify2());
211
212 return 0;
213}
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 20061cf42288..28cd6a17491b 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -246,8 +246,14 @@ find_target:
246 246
247indirect_call: 247indirect_call:
248 tok = strchr(endptr, '*'); 248 tok = strchr(endptr, '*');
249 if (tok != NULL) 249 if (tok != NULL) {
250 ops->target.addr = strtoull(tok + 1, NULL, 16); 250 endptr++;
251
252 /* Indirect call can use a non-rip register and offset: callq *0x8(%rbx).
253 * Do not parse such instruction. */
254 if (strstr(endptr, "(%r") == NULL)
255 ops->target.addr = strtoull(endptr, NULL, 16);
256 }
251 goto find_target; 257 goto find_target;
252} 258}
253 259
@@ -276,7 +282,19 @@ bool ins__is_call(const struct ins *ins)
276 return ins->ops == &call_ops || ins->ops == &s390_call_ops; 282 return ins->ops == &call_ops || ins->ops == &s390_call_ops;
277} 283}
278 284
279static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms) 285/*
286 * Prevents from matching commas in the comment section, e.g.:
287 * ffff200008446e70: b.cs ffff2000084470f4 <generic_exec_single+0x314> // b.hs, b.nlast
288 */
289static inline const char *validate_comma(const char *c, struct ins_operands *ops)
290{
291 if (ops->raw_comment && c > ops->raw_comment)
292 return NULL;
293
294 return c;
295}
296
297static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms)
280{ 298{
281 struct map *map = ms->map; 299 struct map *map = ms->map;
282 struct symbol *sym = ms->sym; 300 struct symbol *sym = ms->sym;
@@ -285,6 +303,10 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op
285 }; 303 };
286 const char *c = strchr(ops->raw, ','); 304 const char *c = strchr(ops->raw, ',');
287 u64 start, end; 305 u64 start, end;
306
307 ops->raw_comment = strchr(ops->raw, arch->objdump.comment_char);
308 c = validate_comma(c, ops);
309
288 /* 310 /*
289 * Examples of lines to parse for the _cpp_lex_token@@Base 311 * Examples of lines to parse for the _cpp_lex_token@@Base
290 * function: 312 * function:
@@ -304,6 +326,7 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op
304 ops->target.addr = strtoull(c, NULL, 16); 326 ops->target.addr = strtoull(c, NULL, 16);
305 if (!ops->target.addr) { 327 if (!ops->target.addr) {
306 c = strchr(c, ','); 328 c = strchr(c, ',');
329 c = validate_comma(c, ops);
307 if (c++ != NULL) 330 if (c++ != NULL)
308 ops->target.addr = strtoull(c, NULL, 16); 331 ops->target.addr = strtoull(c, NULL, 16);
309 } 332 }
@@ -361,9 +384,12 @@ static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
361 return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name); 384 return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name);
362 385
363 c = strchr(ops->raw, ','); 386 c = strchr(ops->raw, ',');
387 c = validate_comma(c, ops);
388
364 if (c != NULL) { 389 if (c != NULL) {
365 const char *c2 = strchr(c + 1, ','); 390 const char *c2 = strchr(c + 1, ',');
366 391
392 c2 = validate_comma(c2, ops);
367 /* check for 3-op insn */ 393 /* check for 3-op insn */
368 if (c2 != NULL) 394 if (c2 != NULL)
369 c = c2; 395 c = c2;
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 005a5fe8a8c6..5399ba2321bb 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -22,6 +22,7 @@ struct ins {
22 22
23struct ins_operands { 23struct ins_operands {
24 char *raw; 24 char *raw;
25 char *raw_comment;
25 struct { 26 struct {
26 char *raw; 27 char *raw;
27 char *name; 28 char *name;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index c980bbff6353..1a61628a1c12 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -251,8 +251,9 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
251{ 251{
252 struct perf_evsel *evsel = zalloc(perf_evsel__object.size); 252 struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
253 253
254 if (evsel != NULL) 254 if (!evsel)
255 perf_evsel__init(evsel, attr, idx); 255 return NULL;
256 perf_evsel__init(evsel, attr, idx);
256 257
257 if (perf_evsel__is_bpf_output(evsel)) { 258 if (perf_evsel__is_bpf_output(evsel)) {
258 evsel->attr.sample_type |= (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | 259 evsel->attr.sample_type |= (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 36d0763311ef..6a6929f208b4 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -576,6 +576,13 @@ struct symbol *map_groups__find_symbol(struct map_groups *mg,
576 return NULL; 576 return NULL;
577} 577}
578 578
579static bool map__contains_symbol(struct map *map, struct symbol *sym)
580{
581 u64 ip = map->unmap_ip(map, sym->start);
582
583 return ip >= map->start && ip < map->end;
584}
585
579struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, 586struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
580 struct map **mapp) 587 struct map **mapp)
581{ 588{
@@ -591,6 +598,10 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
591 598
592 if (sym == NULL) 599 if (sym == NULL)
593 continue; 600 continue;
601 if (!map__contains_symbol(pos, sym)) {
602 sym = NULL;
603 continue;
604 }
594 if (mapp != NULL) 605 if (mapp != NULL)
595 *mapp = pos; 606 *mapp = pos;
596 goto out; 607 goto out;
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index c85d0d1a65ed..7b0ca7cbb7de 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -377,7 +377,7 @@ out:
377 377
378static int record_saved_cmdline(void) 378static int record_saved_cmdline(void)
379{ 379{
380 unsigned int size; 380 unsigned long long size;
381 char *path; 381 char *path;
382 struct stat st; 382 struct stat st;
383 int ret, err = 0; 383 int ret, err = 0;
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 920b1d58a068..e76214f8d596 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -164,16 +164,15 @@ void parse_ftrace_printk(struct tep_handle *pevent,
164void parse_saved_cmdline(struct tep_handle *pevent, 164void parse_saved_cmdline(struct tep_handle *pevent,
165 char *file, unsigned int size __maybe_unused) 165 char *file, unsigned int size __maybe_unused)
166{ 166{
167 char *comm; 167 char comm[17]; /* Max comm length in the kernel is 16. */
168 char *line; 168 char *line;
169 char *next = NULL; 169 char *next = NULL;
170 int pid; 170 int pid;
171 171
172 line = strtok_r(file, "\n", &next); 172 line = strtok_r(file, "\n", &next);
173 while (line) { 173 while (line) {
174 sscanf(line, "%d %ms", &pid, &comm); 174 if (sscanf(line, "%d %16s", &pid, comm) == 2)
175 tep_register_comm(pevent, comm, pid); 175 tep_register_comm(pevent, comm, pid);
176 free(comm);
177 line = strtok_r(NULL, "\n", &next); 176 line = strtok_r(NULL, "\n", &next);
178 } 177 }
179} 178}
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/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 f8cc38afffa2..32a194e3e07a 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -46,6 +46,9 @@
46# Kselftest framework requirement - SKIP code is 4. 46# Kselftest framework requirement - SKIP code is 4.
47ksft_skip=4 47ksft_skip=4
48 48
49# Some systems don't have a ping6 binary anymore
50which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
51
49tests=" 52tests="
50 pmtu_vti6_exception vti6: PMTU exceptions 53 pmtu_vti6_exception vti6: PMTU exceptions
51 pmtu_vti4_exception vti4: PMTU exceptions 54 pmtu_vti4_exception vti4: PMTU exceptions
@@ -274,7 +277,7 @@ test_pmtu_vti6_exception() {
274 mtu "${ns_b}" veth_b 4000 277 mtu "${ns_b}" veth_b 4000
275 mtu "${ns_a}" vti6_a 5000 278 mtu "${ns_a}" vti6_a 5000
276 mtu "${ns_b}" vti6_b 5000 279 mtu "${ns_b}" vti6_b 5000
277 ${ns_a} ping6 -q -i 0.1 -w 2 -s 60000 ${vti6_b_addr} > /dev/null 280 ${ns_a} ${ping6} -q -i 0.1 -w 2 -s 60000 ${vti6_b_addr} > /dev/null
278 281
279 # Check that exception was created 282 # Check that exception was created
280 if [ "$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" = "" ]; then 283 if [ "$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" = "" ]; then
@@ -334,7 +337,7 @@ test_pmtu_vti4_link_add_mtu() {
334 fail=0 337 fail=0
335 338
336 min=68 339 min=68
337 max=$((65528 - 20)) 340 max=$((65535 - 20))
338 # Check invalid values first 341 # Check invalid values first
339 for v in $((min - 1)) $((max + 1)); do 342 for v in $((min - 1)) $((max + 1)); do
340 ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 2>/dev/null 343 ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 2>/dev/null
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/tc-testing/tc-tests/actions/police.json b/tools/testing/selftests/tc-testing/tc-tests/actions/police.json
index f03763d81617..30f9b54bd666 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/police.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/police.json
@@ -313,6 +313,54 @@
313 ] 313 ]
314 }, 314 },
315 { 315 {
316 "id": "6aaf",
317 "name": "Add police actions with conform-exceed control pass/pipe [with numeric values]",
318 "category": [
319 "actions",
320 "police"
321 ],
322 "setup": [
323 [
324 "$TC actions flush action police",
325 0,
326 1,
327 255
328 ]
329 ],
330 "cmdUnderTest": "$TC actions add action police rate 3mbit burst 250k conform-exceed 0/3 index 1",
331 "expExitCode": "0",
332 "verifyCmd": "$TC actions get action police index 1",
333 "matchPattern": "action order [0-9]*: police 0x1 rate 3Mbit burst 250Kb mtu 2Kb action pass/pipe",
334 "matchCount": "1",
335 "teardown": [
336 "$TC actions flush action police"
337 ]
338 },
339 {
340 "id": "29b1",
341 "name": "Add police actions with conform-exceed control <invalid>/drop",
342 "category": [
343 "actions",
344 "police"
345 ],
346 "setup": [
347 [
348 "$TC actions flush action police",
349 0,
350 1,
351 255
352 ]
353 ],
354 "cmdUnderTest": "$TC actions add action police rate 3mbit burst 250k conform-exceed 10/drop index 1",
355 "expExitCode": "255",
356 "verifyCmd": "$TC actions ls action police",
357 "matchPattern": "action order [0-9]*: police 0x1 rate 3Mbit burst 250Kb mtu 2Kb action ",
358 "matchCount": "0",
359 "teardown": [
360 "$TC actions flush action police"
361 ]
362 },
363 {
316 "id": "c26f", 364 "id": "c26f",
317 "name": "Add police action with invalid peakrate value", 365 "name": "Add police action with invalid peakrate value",
318 "category": [ 366 "category": [
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
diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c
index 30cb0a0713ff..37908a83ddc2 100644
--- a/tools/vm/page-types.c
+++ b/tools/vm/page-types.c
@@ -159,12 +159,6 @@ static const char * const page_flag_names[] = {
159}; 159};
160 160
161 161
162static const char * const debugfs_known_mountpoints[] = {
163 "/sys/kernel/debug",
164 "/debug",
165 0,
166};
167
168/* 162/*
169 * data structures 163 * data structures
170 */ 164 */
diff --git a/tools/vm/slabinfo.c b/tools/vm/slabinfo.c
index f82c2eaa859d..334b16db0ebb 100644
--- a/tools/vm/slabinfo.c
+++ b/tools/vm/slabinfo.c
@@ -30,8 +30,8 @@ struct slabinfo {
30 int alias; 30 int alias;
31 int refs; 31 int refs;
32 int aliases, align, cache_dma, cpu_slabs, destroy_by_rcu; 32 int aliases, align, cache_dma, cpu_slabs, destroy_by_rcu;
33 int hwcache_align, object_size, objs_per_slab; 33 unsigned int hwcache_align, object_size, objs_per_slab;
34 int sanity_checks, slab_size, store_user, trace; 34 unsigned int sanity_checks, slab_size, store_user, trace;
35 int order, poison, reclaim_account, red_zone; 35 int order, poison, reclaim_account, red_zone;
36 unsigned long partial, objects, slabs, objects_partial, objects_total; 36 unsigned long partial, objects, slabs, objects_partial, objects_total;
37 unsigned long alloc_fastpath, alloc_slowpath; 37 unsigned long alloc_fastpath, alloc_slowpath;