Skip to content

Commit c2eb6d0

Browse files
committed
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 <[email protected]>
2 parents e4485c7 + 0ec9552 commit c2eb6d0

File tree

10 files changed

+77
-21
lines changed

10 files changed

+77
-21
lines changed

include/trace/events/xdp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/netdevice.h>
99
#include <linux/filter.h>
1010
#include <linux/tracepoint.h>
11+
#include <linux/bpf.h>
1112

1213
#define __XDP_ACT_MAP(FN) \
1314
FN(ABORTED) \

kernel/bpf/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,8 @@ int bpf_prog_array_length(struct bpf_prog_array __rcu *progs)
14471447
rcu_read_lock();
14481448
prog = rcu_dereference(progs)->progs;
14491449
for (; *prog; prog++)
1450-
cnt++;
1450+
if (*prog != &dummy_bpf_prog.prog)
1451+
cnt++;
14511452
rcu_read_unlock();
14521453
return cnt;
14531454
}

kernel/bpf/offload.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
116
#include <linux/bpf.h>
217
#include <linux/bpf_verifier.h>
318
#include <linux/bug.h>

kernel/trace/bpf_trace.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ const struct bpf_prog_ops perf_event_prog_ops = {
759759

760760
static DEFINE_MUTEX(bpf_event_mutex);
761761

762+
#define BPF_TRACE_MAX_PROGS 64
763+
762764
int perf_event_attach_bpf_prog(struct perf_event *event,
763765
struct bpf_prog *prog)
764766
{
@@ -772,6 +774,12 @@ int perf_event_attach_bpf_prog(struct perf_event *event,
772774
goto unlock;
773775

774776
old_array = event->tp_event->prog_array;
777+
if (old_array &&
778+
bpf_prog_array_length(old_array) >= BPF_TRACE_MAX_PROGS) {
779+
ret = -E2BIG;
780+
goto unlock;
781+
}
782+
775783
ret = bpf_prog_array_copy(old_array, NULL, prog, &new_array);
776784
if (ret < 0)
777785
goto unlock;

samples/bpf/bpf_load.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,18 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
193193
return -1;
194194
}
195195
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+
}
198208

199209
return 0;
200210
}

tools/bpf/bpftool/Documentation/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RM ?= rm -f
66

77
# Make the path relative to DESTDIR, not prefix
88
ifndef DESTDIR
9-
prefix?=$(HOME)
9+
prefix ?= /usr/local
1010
endif
1111
mandir ?= $(prefix)/share/man
1212
man8dir = $(mandir)/man8

tools/bpf/bpftool/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ $(LIBBPF)-clean:
4545
$(call QUIET_CLEAN, libbpf)
4646
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
4747

48-
prefix = /usr
49-
bash_compdir ?= $(prefix)/share/bash-completion/completions
48+
prefix = /usr/local
49+
bash_compdir ?= /usr/share/bash-completion/completions
5050

5151
CC = gcc
5252

@@ -76,6 +76,7 @@ clean: $(LIBBPF)-clean
7676
$(Q)rm -rf $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
7777

7878
install:
79+
install -m 0755 -d $(prefix)/sbin
7980
install $(OUTPUT)bpftool $(prefix)/sbin/bpftool
8081
install -m 0755 -d $(bash_compdir)
8182
install -m 0644 bash-completion/bpftool $(bash_compdir)
@@ -88,5 +89,5 @@ doc-install:
8889

8990
FORCE:
9091

91-
.PHONY: all clean FORCE
92+
.PHONY: all clean FORCE install doc doc-install
9293
.DEFAULT_GOAL := all

tools/bpf/bpftool/main.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,19 @@ bool show_pinned;
5858
struct pinned_obj_table prog_table;
5959
struct pinned_obj_table map_table;
6060

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+
6169
void usage(void)
6270
{
6371
last_do_help(last_argc - 1, last_argv + 1);
6472

65-
exit(-1);
73+
clean_and_exit(-1);
6674
}
6775

6876
static int do_help(int argc, char **argv)
@@ -280,6 +288,7 @@ int main(int argc, char **argv)
280288
hash_init(prog_table.table);
281289
hash_init(map_table.table);
282290

291+
opterr = 0;
283292
while ((opt = getopt_long(argc, argv, "Vhpjf",
284293
options, NULL)) >= 0) {
285294
switch (opt) {
@@ -291,13 +300,25 @@ int main(int argc, char **argv)
291300
pretty_output = true;
292301
/* fall through */
293302
case 'j':
294-
json_output = true;
303+
if (!json_output) {
304+
json_wtr = jsonw_new(stdout);
305+
if (!json_wtr) {
306+
p_err("failed to create JSON writer");
307+
return -1;
308+
}
309+
json_output = true;
310+
}
311+
jsonw_pretty(json_wtr, pretty_output);
295312
break;
296313
case 'f':
297314
show_pinned = true;
298315
break;
299316
default:
300-
usage();
317+
p_err("unrecognized option '%s'", argv[optind - 1]);
318+
if (json_output)
319+
clean_and_exit(-1);
320+
else
321+
usage();
301322
}
302323
}
303324

@@ -306,15 +327,6 @@ int main(int argc, char **argv)
306327
if (argc < 0)
307328
usage();
308329

309-
if (json_output) {
310-
json_wtr = jsonw_new(stdout);
311-
if (!json_wtr) {
312-
p_err("failed to create JSON writer");
313-
return -1;
314-
}
315-
jsonw_pretty(json_wtr, pretty_output);
316-
}
317-
318330
bfd_init();
319331

320332
ret = cmd_select(cmds, argc, argv, do_help);

tools/bpf/bpftool/main.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <stdbool.h>
4242
#include <stdio.h>
4343
#include <linux/bpf.h>
44+
#include <linux/compiler.h>
4445
#include <linux/kernel.h>
4546
#include <linux/hashtable.h>
4647

@@ -50,7 +51,7 @@
5051

5152
#define NEXT_ARG() ({ argc--; argv++; if (argc < 0) usage(); })
5253
#define NEXT_ARGP() ({ (*argc)--; (*argv)++; if (*argc < 0) usage(); })
53-
#define BAD_ARG() ({ p_err("what is '%s'?\n", *argv); -1; })
54+
#define BAD_ARG() ({ p_err("what is '%s'?", *argv); -1; })
5455

5556
#define ERR_MAX_LEN 1024
5657

@@ -80,7 +81,7 @@ void p_info(const char *fmt, ...);
8081

8182
bool is_prefix(const char *pfx, const char *str);
8283
void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
83-
void usage(void) __attribute__((noreturn));
84+
void usage(void) __noreturn;
8485

8586
struct pinned_obj_table {
8687
DECLARE_HASHTABLE(table, 16);

tools/testing/selftests/bpf/test_verifier_log.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <stdio.h>
44
#include <string.h>
55
#include <unistd.h>
6+
#include <sys/time.h>
7+
#include <sys/resource.h>
68

79
#include <linux/bpf.h>
810
#include <linux/filter.h>
@@ -131,11 +133,16 @@ static void test_log_bad(char *log, size_t log_len, int log_level)
131133

132134
int main(int argc, char **argv)
133135
{
136+
struct rlimit limit = { RLIM_INFINITY, RLIM_INFINITY };
134137
char full_log[LOG_SIZE];
135138
char log[LOG_SIZE];
136139
size_t want_len;
137140
int i;
138141

142+
/* allow unlimited locked memory to have more consistent error code */
143+
if (setrlimit(RLIMIT_MEMLOCK, &limit) < 0)
144+
perror("Unable to lift memlock rlimit");
145+
139146
memset(log, 1, LOG_SIZE);
140147

141148
/* Test incorrect attr */

0 commit comments

Comments
 (0)