aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2017-08-10 10:49:46 -0400
committerIngo Molnar <mingo@kernel.org>2017-08-10 10:49:46 -0400
commit636bf35880e5a79c2ecb10640137bbd9a4681cb7 (patch)
tree919ea9ac007b72acb92a99fb7e28c8238a69573f /tools
parent276c87054751bb6adfa160a6e68e47b97592a897 (diff)
parent8d31f80eb38819e4f2905ad21c0e8998382a08f7 (diff)
Merge branch 'linus' into x86/platform, to pick up fixes
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/build/feature/test-bpf.c2
-rwxr-xr-xtools/kvm/kvm_stat/kvm_stat22
-rw-r--r--tools/lib/bpf/bpf.c3
-rw-r--r--tools/testing/selftests/bpf/test_pkt_md_access.c11
-rw-r--r--tools/testing/selftests/bpf/test_progs.c8
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c47
6 files changed, 76 insertions, 17 deletions
diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c
index 7598361ef1f1..da2172ff9662 100644
--- a/tools/build/feature/test-bpf.c
+++ b/tools/build/feature/test-bpf.c
@@ -11,6 +11,8 @@
11# define __NR_bpf 280 11# define __NR_bpf 280
12# elif defined(__sparc__) 12# elif defined(__sparc__)
13# define __NR_bpf 349 13# define __NR_bpf 349
14# elif defined(__s390__)
15# define __NR_bpf 351
14# else 16# else
15# error __NR_bpf not defined. libbpf does not support your arch. 17# error __NR_bpf not defined. libbpf does not support your arch.
16# endif 18# endif
diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index dd8f00cfb8b4..32283d88701a 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -474,7 +474,7 @@ class Provider(object):
474 @staticmethod 474 @staticmethod
475 def is_field_wanted(fields_filter, field): 475 def is_field_wanted(fields_filter, field):
476 """Indicate whether field is valid according to fields_filter.""" 476 """Indicate whether field is valid according to fields_filter."""
477 if not fields_filter: 477 if not fields_filter or fields_filter == "help":
478 return True 478 return True
479 return re.match(fields_filter, field) is not None 479 return re.match(fields_filter, field) is not None
480 480
@@ -1413,8 +1413,8 @@ performance.
1413 1413
1414Requirements: 1414Requirements:
1415- Access to: 1415- Access to:
1416 /sys/kernel/debug/kvm 1416 %s
1417 /sys/kernel/debug/trace/events/* 1417 %s/events/*
1418 /proc/pid/task 1418 /proc/pid/task
1419- /proc/sys/kernel/perf_event_paranoid < 1 if user has no 1419- /proc/sys/kernel/perf_event_paranoid < 1 if user has no
1420 CAP_SYS_ADMIN and perf events are used. 1420 CAP_SYS_ADMIN and perf events are used.
@@ -1434,7 +1434,7 @@ Interactive Commands:
1434 s set update interval 1434 s set update interval
1435 x toggle reporting of stats for individual child trace events 1435 x toggle reporting of stats for individual child trace events
1436Press any other key to refresh statistics immediately. 1436Press any other key to refresh statistics immediately.
1437""" 1437""" % (PATH_DEBUGFS_KVM, PATH_DEBUGFS_TRACING)
1438 1438
1439 class PlainHelpFormatter(optparse.IndentedHelpFormatter): 1439 class PlainHelpFormatter(optparse.IndentedHelpFormatter):
1440 def format_description(self, description): 1440 def format_description(self, description):
@@ -1496,7 +1496,8 @@ Press any other key to refresh statistics immediately.
1496 action='store', 1496 action='store',
1497 default=DEFAULT_REGEX, 1497 default=DEFAULT_REGEX,
1498 dest='fields', 1498 dest='fields',
1499 help='fields to display (regex)', 1499 help='''fields to display (regex)
1500 "-f help" for a list of available events''',
1500 ) 1501 )
1501 optparser.add_option('-p', '--pid', 1502 optparser.add_option('-p', '--pid',
1502 action='store', 1503 action='store',
@@ -1559,6 +1560,17 @@ def main():
1559 1560
1560 stats = Stats(options) 1561 stats = Stats(options)
1561 1562
1563 if options.fields == "help":
1564 event_list = "\n"
1565 s = stats.get()
1566 for key in s.keys():
1567 if key.find('(') != -1:
1568 key = key[0:key.find('(')]
1569 if event_list.find('\n' + key + '\n') == -1:
1570 event_list += key + '\n'
1571 sys.stdout.write(event_list)
1572 return ""
1573
1562 if options.log: 1574 if options.log:
1563 log(stats) 1575 log(stats)
1564 elif not options.once: 1576 elif not options.once:
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 412a7c82995a..e5bbb090bf88 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -39,6 +39,8 @@
39# define __NR_bpf 280 39# define __NR_bpf 280
40# elif defined(__sparc__) 40# elif defined(__sparc__)
41# define __NR_bpf 349 41# define __NR_bpf 349
42# elif defined(__s390__)
43# define __NR_bpf 351
42# else 44# else
43# error __NR_bpf not defined. libbpf does not support your arch. 45# error __NR_bpf not defined. libbpf does not support your arch.
44# endif 46# endif
@@ -314,7 +316,6 @@ int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len)
314 int err; 316 int err;
315 317
316 bzero(&attr, sizeof(attr)); 318 bzero(&attr, sizeof(attr));
317 bzero(info, *info_len);
318 attr.info.bpf_fd = prog_fd; 319 attr.info.bpf_fd = prog_fd;
319 attr.info.info_len = *info_len; 320 attr.info.info_len = *info_len;
320 attr.info.info = ptr_to_u64(info); 321 attr.info.info = ptr_to_u64(info);
diff --git a/tools/testing/selftests/bpf/test_pkt_md_access.c b/tools/testing/selftests/bpf/test_pkt_md_access.c
index 71729d47eb85..7956302ecdf2 100644
--- a/tools/testing/selftests/bpf/test_pkt_md_access.c
+++ b/tools/testing/selftests/bpf/test_pkt_md_access.c
@@ -12,12 +12,23 @@
12 12
13int _version SEC("version") = 1; 13int _version SEC("version") = 1;
14 14
15#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
15#define TEST_FIELD(TYPE, FIELD, MASK) \ 16#define TEST_FIELD(TYPE, FIELD, MASK) \
16 { \ 17 { \
17 TYPE tmp = *(volatile TYPE *)&skb->FIELD; \ 18 TYPE tmp = *(volatile TYPE *)&skb->FIELD; \
18 if (tmp != ((*(volatile __u32 *)&skb->FIELD) & MASK)) \ 19 if (tmp != ((*(volatile __u32 *)&skb->FIELD) & MASK)) \
19 return TC_ACT_SHOT; \ 20 return TC_ACT_SHOT; \
20 } 21 }
22#else
23#define TEST_FIELD_OFFSET(a, b) ((sizeof(a) - sizeof(b)) / sizeof(b))
24#define TEST_FIELD(TYPE, FIELD, MASK) \
25 { \
26 TYPE tmp = *((volatile TYPE *)&skb->FIELD + \
27 TEST_FIELD_OFFSET(skb->FIELD, TYPE)); \
28 if (tmp != ((*(volatile __u32 *)&skb->FIELD) & MASK)) \
29 return TC_ACT_SHOT; \
30 }
31#endif
21 32
22SEC("test1") 33SEC("test1")
23int process(struct __sk_buff *skb) 34int process(struct __sk_buff *skb)
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 5855cd3d3d45..1f7dd35551b9 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -340,6 +340,7 @@ static void test_bpf_obj_id(void)
340 340
341 /* Check getting prog info */ 341 /* Check getting prog info */
342 info_len = sizeof(struct bpf_prog_info) * 2; 342 info_len = sizeof(struct bpf_prog_info) * 2;
343 bzero(&prog_infos[i], info_len);
343 prog_infos[i].jited_prog_insns = ptr_to_u64(jited_insns); 344 prog_infos[i].jited_prog_insns = ptr_to_u64(jited_insns);
344 prog_infos[i].jited_prog_len = sizeof(jited_insns); 345 prog_infos[i].jited_prog_len = sizeof(jited_insns);
345 prog_infos[i].xlated_prog_insns = ptr_to_u64(xlated_insns); 346 prog_infos[i].xlated_prog_insns = ptr_to_u64(xlated_insns);
@@ -369,6 +370,7 @@ static void test_bpf_obj_id(void)
369 370
370 /* Check getting map info */ 371 /* Check getting map info */
371 info_len = sizeof(struct bpf_map_info) * 2; 372 info_len = sizeof(struct bpf_map_info) * 2;
373 bzero(&map_infos[i], info_len);
372 err = bpf_obj_get_info_by_fd(map_fds[i], &map_infos[i], 374 err = bpf_obj_get_info_by_fd(map_fds[i], &map_infos[i],
373 &info_len); 375 &info_len);
374 if (CHECK(err || 376 if (CHECK(err ||
@@ -394,7 +396,7 @@ static void test_bpf_obj_id(void)
394 nr_id_found = 0; 396 nr_id_found = 0;
395 next_id = 0; 397 next_id = 0;
396 while (!bpf_prog_get_next_id(next_id, &next_id)) { 398 while (!bpf_prog_get_next_id(next_id, &next_id)) {
397 struct bpf_prog_info prog_info; 399 struct bpf_prog_info prog_info = {};
398 int prog_fd; 400 int prog_fd;
399 401
400 info_len = sizeof(prog_info); 402 info_len = sizeof(prog_info);
@@ -418,6 +420,8 @@ static void test_bpf_obj_id(void)
418 nr_id_found++; 420 nr_id_found++;
419 421
420 err = bpf_obj_get_info_by_fd(prog_fd, &prog_info, &info_len); 422 err = bpf_obj_get_info_by_fd(prog_fd, &prog_info, &info_len);
423 prog_infos[i].jited_prog_insns = 0;
424 prog_infos[i].xlated_prog_insns = 0;
421 CHECK(err || info_len != sizeof(struct bpf_prog_info) || 425 CHECK(err || info_len != sizeof(struct bpf_prog_info) ||
422 memcmp(&prog_info, &prog_infos[i], info_len), 426 memcmp(&prog_info, &prog_infos[i], info_len),
423 "get-prog-info(next_id->fd)", 427 "get-prog-info(next_id->fd)",
@@ -436,7 +440,7 @@ static void test_bpf_obj_id(void)
436 nr_id_found = 0; 440 nr_id_found = 0;
437 next_id = 0; 441 next_id = 0;
438 while (!bpf_map_get_next_id(next_id, &next_id)) { 442 while (!bpf_map_get_next_id(next_id, &next_id)) {
439 struct bpf_map_info map_info; 443 struct bpf_map_info map_info = {};
440 int map_fd; 444 int map_fd;
441 445
442 info_len = sizeof(map_info); 446 info_len = sizeof(map_info);
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index af7d173910f4..d3ed7324105e 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -8,6 +8,7 @@
8 * License as published by the Free Software Foundation. 8 * License as published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <endian.h>
11#include <asm/types.h> 12#include <asm/types.h>
12#include <linux/types.h> 13#include <linux/types.h>
13#include <stdint.h> 14#include <stdint.h>
@@ -1098,7 +1099,7 @@ static struct bpf_test tests[] = {
1098 "check skb->hash byte load permitted", 1099 "check skb->hash byte load permitted",
1099 .insns = { 1100 .insns = {
1100 BPF_MOV64_IMM(BPF_REG_0, 0), 1101 BPF_MOV64_IMM(BPF_REG_0, 0),
1101#ifdef __LITTLE_ENDIAN 1102#if __BYTE_ORDER == __LITTLE_ENDIAN
1102 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 1103 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
1103 offsetof(struct __sk_buff, hash)), 1104 offsetof(struct __sk_buff, hash)),
1104#else 1105#else
@@ -1135,7 +1136,7 @@ static struct bpf_test tests[] = {
1135 "check skb->hash byte load not permitted 3", 1136 "check skb->hash byte load not permitted 3",
1136 .insns = { 1137 .insns = {
1137 BPF_MOV64_IMM(BPF_REG_0, 0), 1138 BPF_MOV64_IMM(BPF_REG_0, 0),
1138#ifdef __LITTLE_ENDIAN 1139#if __BYTE_ORDER == __LITTLE_ENDIAN
1139 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 1140 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
1140 offsetof(struct __sk_buff, hash) + 3), 1141 offsetof(struct __sk_buff, hash) + 3),
1141#else 1142#else
@@ -1244,7 +1245,7 @@ static struct bpf_test tests[] = {
1244 "check skb->hash half load permitted", 1245 "check skb->hash half load permitted",
1245 .insns = { 1246 .insns = {
1246 BPF_MOV64_IMM(BPF_REG_0, 0), 1247 BPF_MOV64_IMM(BPF_REG_0, 0),
1247#ifdef __LITTLE_ENDIAN 1248#if __BYTE_ORDER == __LITTLE_ENDIAN
1248 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, 1249 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
1249 offsetof(struct __sk_buff, hash)), 1250 offsetof(struct __sk_buff, hash)),
1250#else 1251#else
@@ -1259,7 +1260,7 @@ static struct bpf_test tests[] = {
1259 "check skb->hash half load not permitted", 1260 "check skb->hash half load not permitted",
1260 .insns = { 1261 .insns = {
1261 BPF_MOV64_IMM(BPF_REG_0, 0), 1262 BPF_MOV64_IMM(BPF_REG_0, 0),
1262#ifdef __LITTLE_ENDIAN 1263#if __BYTE_ORDER == __LITTLE_ENDIAN
1263 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, 1264 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
1264 offsetof(struct __sk_buff, hash) + 2), 1265 offsetof(struct __sk_buff, hash) + 2),
1265#else 1266#else
@@ -5422,7 +5423,7 @@ static struct bpf_test tests[] = {
5422 "check bpf_perf_event_data->sample_period byte load permitted", 5423 "check bpf_perf_event_data->sample_period byte load permitted",
5423 .insns = { 5424 .insns = {
5424 BPF_MOV64_IMM(BPF_REG_0, 0), 5425 BPF_MOV64_IMM(BPF_REG_0, 0),
5425#ifdef __LITTLE_ENDIAN 5426#if __BYTE_ORDER == __LITTLE_ENDIAN
5426 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 5427 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
5427 offsetof(struct bpf_perf_event_data, sample_period)), 5428 offsetof(struct bpf_perf_event_data, sample_period)),
5428#else 5429#else
@@ -5438,7 +5439,7 @@ static struct bpf_test tests[] = {
5438 "check bpf_perf_event_data->sample_period half load permitted", 5439 "check bpf_perf_event_data->sample_period half load permitted",
5439 .insns = { 5440 .insns = {
5440 BPF_MOV64_IMM(BPF_REG_0, 0), 5441 BPF_MOV64_IMM(BPF_REG_0, 0),
5441#ifdef __LITTLE_ENDIAN 5442#if __BYTE_ORDER == __LITTLE_ENDIAN
5442 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, 5443 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
5443 offsetof(struct bpf_perf_event_data, sample_period)), 5444 offsetof(struct bpf_perf_event_data, sample_period)),
5444#else 5445#else
@@ -5454,7 +5455,7 @@ static struct bpf_test tests[] = {
5454 "check bpf_perf_event_data->sample_period word load permitted", 5455 "check bpf_perf_event_data->sample_period word load permitted",
5455 .insns = { 5456 .insns = {
5456 BPF_MOV64_IMM(BPF_REG_0, 0), 5457 BPF_MOV64_IMM(BPF_REG_0, 0),
5457#ifdef __LITTLE_ENDIAN 5458#if __BYTE_ORDER == __LITTLE_ENDIAN
5458 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 5459 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
5459 offsetof(struct bpf_perf_event_data, sample_period)), 5460 offsetof(struct bpf_perf_event_data, sample_period)),
5460#else 5461#else
@@ -5481,7 +5482,7 @@ static struct bpf_test tests[] = {
5481 "check skb->data half load not permitted", 5482 "check skb->data half load not permitted",
5482 .insns = { 5483 .insns = {
5483 BPF_MOV64_IMM(BPF_REG_0, 0), 5484 BPF_MOV64_IMM(BPF_REG_0, 0),
5484#ifdef __LITTLE_ENDIAN 5485#if __BYTE_ORDER == __LITTLE_ENDIAN
5485 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, 5486 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
5486 offsetof(struct __sk_buff, data)), 5487 offsetof(struct __sk_buff, data)),
5487#else 5488#else
@@ -5497,7 +5498,7 @@ static struct bpf_test tests[] = {
5497 "check skb->tc_classid half load not permitted for lwt prog", 5498 "check skb->tc_classid half load not permitted for lwt prog",
5498 .insns = { 5499 .insns = {
5499 BPF_MOV64_IMM(BPF_REG_0, 0), 5500 BPF_MOV64_IMM(BPF_REG_0, 0),
5500#ifdef __LITTLE_ENDIAN 5501#if __BYTE_ORDER == __LITTLE_ENDIAN
5501 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, 5502 BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
5502 offsetof(struct __sk_buff, tc_classid)), 5503 offsetof(struct __sk_buff, tc_classid)),
5503#else 5504#else
@@ -5980,6 +5981,34 @@ static struct bpf_test tests[] = {
5980 .result = REJECT, 5981 .result = REJECT,
5981 .result_unpriv = REJECT, 5982 .result_unpriv = REJECT,
5982 }, 5983 },
5984 {
5985 "subtraction bounds (map value)",
5986 .insns = {
5987 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
5988 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
5989 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
5990 BPF_LD_MAP_FD(BPF_REG_1, 0),
5991 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
5992 BPF_FUNC_map_lookup_elem),
5993 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 9),
5994 BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0),
5995 BPF_JMP_IMM(BPF_JGT, BPF_REG_1, 0xff, 7),
5996 BPF_LDX_MEM(BPF_B, BPF_REG_3, BPF_REG_0, 1),
5997 BPF_JMP_IMM(BPF_JGT, BPF_REG_3, 0xff, 5),
5998 BPF_ALU64_REG(BPF_SUB, BPF_REG_1, BPF_REG_3),
5999 BPF_ALU64_IMM(BPF_RSH, BPF_REG_1, 56),
6000 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
6001 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_0, 0),
6002 BPF_EXIT_INSN(),
6003 BPF_MOV64_IMM(BPF_REG_0, 0),
6004 BPF_EXIT_INSN(),
6005 },
6006 .fixup_map1 = { 3 },
6007 .errstr_unpriv = "R0 pointer arithmetic prohibited",
6008 .errstr = "R0 min value is negative, either use unsigned index or do a if (index >=0) check.",
6009 .result = REJECT,
6010 .result_unpriv = REJECT,
6011 },
5983}; 6012};
5984 6013
5985static int probe_filter_length(const struct bpf_insn *fp) 6014static int probe_filter_length(const struct bpf_insn *fp)