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>
This commit is contained in:
commit
c2eb6d07a6
@ -8,6 +8,7 @@
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/filter.h>
|
||||
#include <linux/tracepoint.h>
|
||||
#include <linux/bpf.h>
|
||||
|
||||
#define __XDP_ACT_MAP(FN) \
|
||||
FN(ABORTED) \
|
||||
|
@ -1447,7 +1447,8 @@ int bpf_prog_array_length(struct bpf_prog_array __rcu *progs)
|
||||
rcu_read_lock();
|
||||
prog = rcu_dereference(progs)->progs;
|
||||
for (; *prog; prog++)
|
||||
cnt++;
|
||||
if (*prog != &dummy_bpf_prog.prog)
|
||||
cnt++;
|
||||
rcu_read_unlock();
|
||||
return cnt;
|
||||
}
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Netronome Systems, Inc.
|
||||
*
|
||||
* This software is licensed under the GNU General License Version 2,
|
||||
* June 1991 as shown in the file COPYING in the top-level directory of this
|
||||
* source tree.
|
||||
*
|
||||
* THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS"
|
||||
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
|
||||
* OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
|
||||
* THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
*/
|
||||
|
||||
#include <linux/bpf.h>
|
||||
#include <linux/bpf_verifier.h>
|
||||
#include <linux/bug.h>
|
||||
|
@ -759,6 +759,8 @@ const struct bpf_prog_ops perf_event_prog_ops = {
|
||||
|
||||
static DEFINE_MUTEX(bpf_event_mutex);
|
||||
|
||||
#define BPF_TRACE_MAX_PROGS 64
|
||||
|
||||
int perf_event_attach_bpf_prog(struct perf_event *event,
|
||||
struct bpf_prog *prog)
|
||||
{
|
||||
@ -772,6 +774,12 @@ int perf_event_attach_bpf_prog(struct perf_event *event,
|
||||
goto unlock;
|
||||
|
||||
old_array = event->tp_event->prog_array;
|
||||
if (old_array &&
|
||||
bpf_prog_array_length(old_array) >= BPF_TRACE_MAX_PROGS) {
|
||||
ret = -E2BIG;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
ret = bpf_prog_array_copy(old_array, NULL, prog, &new_array);
|
||||
if (ret < 0)
|
||||
goto unlock;
|
||||
|
@ -193,8 +193,18 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
|
||||
return -1;
|
||||
}
|
||||
event_fd[prog_cnt - 1] = efd;
|
||||
ioctl(efd, PERF_EVENT_IOC_ENABLE, 0);
|
||||
ioctl(efd, PERF_EVENT_IOC_SET_BPF, fd);
|
||||
err = ioctl(efd, PERF_EVENT_IOC_ENABLE, 0);
|
||||
if (err < 0) {
|
||||
printf("ioctl PERF_EVENT_IOC_ENABLE failed err %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
err = ioctl(efd, PERF_EVENT_IOC_SET_BPF, fd);
|
||||
if (err < 0) {
|
||||
printf("ioctl PERF_EVENT_IOC_SET_BPF failed err %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ RM ?= rm -f
|
||||
|
||||
# Make the path relative to DESTDIR, not prefix
|
||||
ifndef DESTDIR
|
||||
prefix?=$(HOME)
|
||||
prefix ?= /usr/local
|
||||
endif
|
||||
mandir ?= $(prefix)/share/man
|
||||
man8dir = $(mandir)/man8
|
||||
|
@ -45,8 +45,8 @@ $(LIBBPF)-clean:
|
||||
$(call QUIET_CLEAN, libbpf)
|
||||
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
|
||||
|
||||
prefix = /usr
|
||||
bash_compdir ?= $(prefix)/share/bash-completion/completions
|
||||
prefix = /usr/local
|
||||
bash_compdir ?= /usr/share/bash-completion/completions
|
||||
|
||||
CC = gcc
|
||||
|
||||
@ -76,6 +76,7 @@ clean: $(LIBBPF)-clean
|
||||
$(Q)rm -rf $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
|
||||
|
||||
install:
|
||||
install -m 0755 -d $(prefix)/sbin
|
||||
install $(OUTPUT)bpftool $(prefix)/sbin/bpftool
|
||||
install -m 0755 -d $(bash_compdir)
|
||||
install -m 0644 bash-completion/bpftool $(bash_compdir)
|
||||
@ -88,5 +89,5 @@ doc-install:
|
||||
|
||||
FORCE:
|
||||
|
||||
.PHONY: all clean FORCE
|
||||
.PHONY: all clean FORCE install doc doc-install
|
||||
.DEFAULT_GOAL := all
|
||||
|
@ -58,11 +58,19 @@ bool show_pinned;
|
||||
struct pinned_obj_table prog_table;
|
||||
struct pinned_obj_table map_table;
|
||||
|
||||
static void __noreturn clean_and_exit(int i)
|
||||
{
|
||||
if (json_output)
|
||||
jsonw_destroy(&json_wtr);
|
||||
|
||||
exit(i);
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
last_do_help(last_argc - 1, last_argv + 1);
|
||||
|
||||
exit(-1);
|
||||
clean_and_exit(-1);
|
||||
}
|
||||
|
||||
static int do_help(int argc, char **argv)
|
||||
@ -280,6 +288,7 @@ int main(int argc, char **argv)
|
||||
hash_init(prog_table.table);
|
||||
hash_init(map_table.table);
|
||||
|
||||
opterr = 0;
|
||||
while ((opt = getopt_long(argc, argv, "Vhpjf",
|
||||
options, NULL)) >= 0) {
|
||||
switch (opt) {
|
||||
@ -291,13 +300,25 @@ int main(int argc, char **argv)
|
||||
pretty_output = true;
|
||||
/* fall through */
|
||||
case 'j':
|
||||
json_output = true;
|
||||
if (!json_output) {
|
||||
json_wtr = jsonw_new(stdout);
|
||||
if (!json_wtr) {
|
||||
p_err("failed to create JSON writer");
|
||||
return -1;
|
||||
}
|
||||
json_output = true;
|
||||
}
|
||||
jsonw_pretty(json_wtr, pretty_output);
|
||||
break;
|
||||
case 'f':
|
||||
show_pinned = true;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
p_err("unrecognized option '%s'", argv[optind - 1]);
|
||||
if (json_output)
|
||||
clean_and_exit(-1);
|
||||
else
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
@ -306,15 +327,6 @@ int main(int argc, char **argv)
|
||||
if (argc < 0)
|
||||
usage();
|
||||
|
||||
if (json_output) {
|
||||
json_wtr = jsonw_new(stdout);
|
||||
if (!json_wtr) {
|
||||
p_err("failed to create JSON writer");
|
||||
return -1;
|
||||
}
|
||||
jsonw_pretty(json_wtr, pretty_output);
|
||||
}
|
||||
|
||||
bfd_init();
|
||||
|
||||
ret = cmd_select(cmds, argc, argv, do_help);
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/bpf.h>
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/hashtable.h>
|
||||
|
||||
@ -50,7 +51,7 @@
|
||||
|
||||
#define NEXT_ARG() ({ argc--; argv++; if (argc < 0) usage(); })
|
||||
#define NEXT_ARGP() ({ (*argc)--; (*argv)++; if (*argc < 0) usage(); })
|
||||
#define BAD_ARG() ({ p_err("what is '%s'?\n", *argv); -1; })
|
||||
#define BAD_ARG() ({ p_err("what is '%s'?", *argv); -1; })
|
||||
|
||||
#define ERR_MAX_LEN 1024
|
||||
|
||||
@ -80,7 +81,7 @@ void p_info(const char *fmt, ...);
|
||||
|
||||
bool is_prefix(const char *pfx, const char *str);
|
||||
void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
|
||||
void usage(void) __attribute__((noreturn));
|
||||
void usage(void) __noreturn;
|
||||
|
||||
struct pinned_obj_table {
|
||||
DECLARE_HASHTABLE(table, 16);
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <linux/bpf.h>
|
||||
#include <linux/filter.h>
|
||||
@ -131,11 +133,16 @@ static void test_log_bad(char *log, size_t log_len, int log_level)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct rlimit limit = { RLIM_INFINITY, RLIM_INFINITY };
|
||||
char full_log[LOG_SIZE];
|
||||
char log[LOG_SIZE];
|
||||
size_t want_len;
|
||||
int i;
|
||||
|
||||
/* allow unlimited locked memory to have more consistent error code */
|
||||
if (setrlimit(RLIMIT_MEMLOCK, &limit) < 0)
|
||||
perror("Unable to lift memlock rlimit");
|
||||
|
||||
memset(log, 1, LOG_SIZE);
|
||||
|
||||
/* Test incorrect attr */
|
||||
|
Loading…
Reference in New Issue
Block a user