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

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf

Daniel Borkmann says:

====================
pull-request: bpf 2017-12-02

The following pull-request contains BPF updates for your *net* tree.

The main changes are:

1) Fix a compilation warning in xdp redirect tracepoint due to
missing bpf.h include that pulls in struct bpf_map, from Xie.

2) Limit the maximum number of attachable BPF progs for a given
perf event as long as uabi is not frozen yet. The hard upper
limit is now 64 and therefore the same as with BPF multi-prog
for cgroups. Also add related error checking for the sample
BPF loader when enabling and attaching to the perf event, from
Yonghong.

3) Specifically set the RLIMIT_MEMLOCK for the test_verifier_log
case, so that the test case can always pass and not fail in
some environments due to too low default limit, also from
Yonghong.

4) Fix up a missing license header comment for kernel/bpf/offload.c,
from Jakub.

5) Several fixes for bpftool, among others a crash on incorrect
arguments when json output is used, error message handling
fixes on unknown options and proper destruction of json writer
for some exit cases, all from Quentin.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+77 -21
+1
include/trace/events/xdp.h
··· 8 8 #include <linux/netdevice.h> 9 9 #include <linux/filter.h> 10 10 #include <linux/tracepoint.h> 11 + #include <linux/bpf.h> 11 12 12 13 #define __XDP_ACT_MAP(FN) \ 13 14 FN(ABORTED) \
+2 -1
kernel/bpf/core.c
··· 1447 1447 rcu_read_lock(); 1448 1448 prog = rcu_dereference(progs)->progs; 1449 1449 for (; *prog; prog++) 1450 - cnt++; 1450 + if (*prog != &dummy_bpf_prog.prog) 1451 + cnt++; 1451 1452 rcu_read_unlock(); 1452 1453 return cnt; 1453 1454 }
+15
kernel/bpf/offload.c
··· 1 + /* 2 + * Copyright (C) 2017 Netronome Systems, Inc. 3 + * 4 + * This software is licensed under the GNU General License Version 2, 5 + * June 1991 as shown in the file COPYING in the top-level directory of this 6 + * source tree. 7 + * 8 + * THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" 9 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, 10 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 11 + * FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE 12 + * OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME 13 + * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 14 + */ 15 + 1 16 #include <linux/bpf.h> 2 17 #include <linux/bpf_verifier.h> 3 18 #include <linux/bug.h>
+8
kernel/trace/bpf_trace.c
··· 759 759 760 760 static DEFINE_MUTEX(bpf_event_mutex); 761 761 762 + #define BPF_TRACE_MAX_PROGS 64 763 + 762 764 int perf_event_attach_bpf_prog(struct perf_event *event, 763 765 struct bpf_prog *prog) 764 766 { ··· 774 772 goto unlock; 775 773 776 774 old_array = event->tp_event->prog_array; 775 + if (old_array && 776 + bpf_prog_array_length(old_array) >= BPF_TRACE_MAX_PROGS) { 777 + ret = -E2BIG; 778 + goto unlock; 779 + } 780 + 777 781 ret = bpf_prog_array_copy(old_array, NULL, prog, &new_array); 778 782 if (ret < 0) 779 783 goto unlock;
+12 -2
samples/bpf/bpf_load.c
··· 193 193 return -1; 194 194 } 195 195 event_fd[prog_cnt - 1] = efd; 196 - ioctl(efd, PERF_EVENT_IOC_ENABLE, 0); 197 - ioctl(efd, PERF_EVENT_IOC_SET_BPF, fd); 196 + err = ioctl(efd, PERF_EVENT_IOC_ENABLE, 0); 197 + if (err < 0) { 198 + printf("ioctl PERF_EVENT_IOC_ENABLE failed err %s\n", 199 + strerror(errno)); 200 + return -1; 201 + } 202 + err = ioctl(efd, PERF_EVENT_IOC_SET_BPF, fd); 203 + if (err < 0) { 204 + printf("ioctl PERF_EVENT_IOC_SET_BPF failed err %s\n", 205 + strerror(errno)); 206 + return -1; 207 + } 198 208 199 209 return 0; 200 210 }
+1 -1
tools/bpf/bpftool/Documentation/Makefile
··· 6 6 7 7 # Make the path relative to DESTDIR, not prefix 8 8 ifndef DESTDIR 9 - prefix?=$(HOME) 9 + prefix ?= /usr/local 10 10 endif 11 11 mandir ?= $(prefix)/share/man 12 12 man8dir = $(mandir)/man8
+4 -3
tools/bpf/bpftool/Makefile
··· 45 45 $(call QUIET_CLEAN, libbpf) 46 46 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null 47 47 48 - prefix = /usr 49 - bash_compdir ?= $(prefix)/share/bash-completion/completions 48 + prefix = /usr/local 49 + bash_compdir ?= /usr/share/bash-completion/completions 50 50 51 51 CC = gcc 52 52 ··· 76 76 $(Q)rm -rf $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d 77 77 78 78 install: 79 + install -m 0755 -d $(prefix)/sbin 79 80 install $(OUTPUT)bpftool $(prefix)/sbin/bpftool 80 81 install -m 0755 -d $(bash_compdir) 81 82 install -m 0644 bash-completion/bpftool $(bash_compdir) ··· 89 88 90 89 FORCE: 91 90 92 - .PHONY: all clean FORCE 91 + .PHONY: all clean FORCE install doc doc-install 93 92 .DEFAULT_GOAL := all
+24 -12
tools/bpf/bpftool/main.c
··· 58 58 struct pinned_obj_table prog_table; 59 59 struct pinned_obj_table map_table; 60 60 61 + static void __noreturn clean_and_exit(int i) 62 + { 63 + if (json_output) 64 + jsonw_destroy(&json_wtr); 65 + 66 + exit(i); 67 + } 68 + 61 69 void usage(void) 62 70 { 63 71 last_do_help(last_argc - 1, last_argv + 1); 64 72 65 - exit(-1); 73 + clean_and_exit(-1); 66 74 } 67 75 68 76 static int do_help(int argc, char **argv) ··· 288 280 hash_init(prog_table.table); 289 281 hash_init(map_table.table); 290 282 283 + opterr = 0; 291 284 while ((opt = getopt_long(argc, argv, "Vhpjf", 292 285 options, NULL)) >= 0) { 293 286 switch (opt) { ··· 300 291 pretty_output = true; 301 292 /* fall through */ 302 293 case 'j': 303 - json_output = true; 294 + if (!json_output) { 295 + json_wtr = jsonw_new(stdout); 296 + if (!json_wtr) { 297 + p_err("failed to create JSON writer"); 298 + return -1; 299 + } 300 + json_output = true; 301 + } 302 + jsonw_pretty(json_wtr, pretty_output); 304 303 break; 305 304 case 'f': 306 305 show_pinned = true; 307 306 break; 308 307 default: 309 - usage(); 308 + p_err("unrecognized option '%s'", argv[optind - 1]); 309 + if (json_output) 310 + clean_and_exit(-1); 311 + else 312 + usage(); 310 313 } 311 314 } 312 315 ··· 326 305 argv += optind; 327 306 if (argc < 0) 328 307 usage(); 329 - 330 - if (json_output) { 331 - json_wtr = jsonw_new(stdout); 332 - if (!json_wtr) { 333 - p_err("failed to create JSON writer"); 334 - return -1; 335 - } 336 - jsonw_pretty(json_wtr, pretty_output); 337 - } 338 308 339 309 bfd_init(); 340 310
+3 -2
tools/bpf/bpftool/main.h
··· 41 41 #include <stdbool.h> 42 42 #include <stdio.h> 43 43 #include <linux/bpf.h> 44 + #include <linux/compiler.h> 44 45 #include <linux/kernel.h> 45 46 #include <linux/hashtable.h> 46 47 ··· 51 50 52 51 #define NEXT_ARG() ({ argc--; argv++; if (argc < 0) usage(); }) 53 52 #define NEXT_ARGP() ({ (*argc)--; (*argv)++; if (*argc < 0) usage(); }) 54 - #define BAD_ARG() ({ p_err("what is '%s'?\n", *argv); -1; }) 53 + #define BAD_ARG() ({ p_err("what is '%s'?", *argv); -1; }) 55 54 56 55 #define ERR_MAX_LEN 1024 57 56 ··· 81 80 82 81 bool is_prefix(const char *pfx, const char *str); 83 82 void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep); 84 - void usage(void) __attribute__((noreturn)); 83 + void usage(void) __noreturn; 85 84 86 85 struct pinned_obj_table { 87 86 DECLARE_HASHTABLE(table, 16);
+7
tools/testing/selftests/bpf/test_verifier_log.c
··· 3 3 #include <stdio.h> 4 4 #include <string.h> 5 5 #include <unistd.h> 6 + #include <sys/time.h> 7 + #include <sys/resource.h> 6 8 7 9 #include <linux/bpf.h> 8 10 #include <linux/filter.h> ··· 133 131 134 132 int main(int argc, char **argv) 135 133 { 134 + struct rlimit limit = { RLIM_INFINITY, RLIM_INFINITY }; 136 135 char full_log[LOG_SIZE]; 137 136 char log[LOG_SIZE]; 138 137 size_t want_len; 139 138 int i; 139 + 140 + /* allow unlimited locked memory to have more consistent error code */ 141 + if (setrlimit(RLIMIT_MEMLOCK, &limit) < 0) 142 + perror("Unable to lift memlock rlimit"); 140 143 141 144 memset(log, 1, LOG_SIZE); 142 145