Skip to content

Commit

Permalink
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Browse files Browse the repository at this point in the history
Daniel Borkmann says:

====================
pull-request: bpf-next 2018-03-03

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

The main changes are:

1) Extend bpftool to build up CFG information of eBPF programs and add an
   option to dump this in DOT format such that this can later be used with
   DOT graphic tools (xdot, graphviz, etc) to visualize it. Part of the
   analysis performed is sub-program detection and basic-block partitioning,
   from Jiong.

2) Multiple enhancements for bpftool's batch mode, more specifically the
   parser now understands comments (#), continuation lines (\), and arguments
   enclosed between quotes. Also, allow to read from stdin via '-' as input
   file, all from Quentin.

3) Improve BPF kselftests by i) unifying the rlimit handling into a helper
   that is then used by all tests, and ii) add support for testing tail calls
   to test_verifier plus add tests covering all corner cases. The latter is
   especially useful for testing JITs, from Daniel.

4) Remove x64 JIT's bpf_flush_icache() since flush_icache_range() is a noop
   on x64, from Daniel.

5) Fix one more occasion in BPF samples where we do not detach the BPF program
   from the cgroup after completion, from Prashant.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Mar 3, 2018
2 parents b72c8a7 + c51a637 commit e4e31cf
Show file tree
Hide file tree
Showing 22 changed files with 1,259 additions and 374 deletions.
15 changes: 2 additions & 13 deletions arch/x86/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include <linux/netdevice.h>
#include <linux/filter.h>
#include <linux/if_vlan.h>
#include <asm/cacheflush.h>
#include <linux/bpf.h>

#include <asm/set_memory.h>
#include <asm/nospec-branch.h>
#include <linux/bpf.h>

/*
* assembly code in arch/x86/net/bpf_jit.S
Expand Down Expand Up @@ -103,16 +103,6 @@ static int bpf_size_to_x86_bytes(int bpf_size)
#define X86_JLE 0x7E
#define X86_JG 0x7F

static void bpf_flush_icache(void *start, void *end)
{
mm_segment_t old_fs = get_fs();

set_fs(KERNEL_DS);
smp_wmb();
flush_icache_range((unsigned long)start, (unsigned long)end);
set_fs(old_fs);
}

#define CHOOSE_LOAD_FUNC(K, func) \
((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)

Expand Down Expand Up @@ -1266,7 +1256,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
bpf_jit_dump(prog->len, proglen, pass + 1, image);

if (image) {
bpf_flush_icache(header, image + proglen);
if (!prog->is_func || extra_pass) {
bpf_jit_binary_lock_ro(header);
} else {
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/test_cgrp2_sock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ cleanup_and_exit()

[ -n "$msg" ] && echo "ERROR: $msg"

test_cgrp2_sock -d ${CGRP_MNT}/sockopts
ip li del cgrp2_sock
umount ${CGRP_MNT}

Expand Down
3 changes: 3 additions & 0 deletions samples/bpf/test_cgrp2_sock2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function attach_bpf {
}

function cleanup {
if [ -d /tmp/cgroupv2/foo ]; then
test_cgrp2_sock -d /tmp/cgroupv2/foo
fi
ip link del veth0b
ip netns delete at_ns0
umount /tmp/cgroupv2
Expand Down
18 changes: 12 additions & 6 deletions tools/bpf/bpftool/Documentation/bpftool-prog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MAP COMMANDS
=============

| **bpftool** **prog { show | list }** [*PROG*]
| **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes**}]
| **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes** | **visual**}]
| **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes**}]
| **bpftool** **prog pin** *PROG* *FILE*
| **bpftool** **prog load** *OBJ* *FILE*
Expand All @@ -39,12 +39,18 @@ DESCRIPTION
Output will start with program ID followed by program type and
zero or more named attributes (depending on kernel version).

**bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** }]
Dump eBPF instructions of the program from the kernel.
If *FILE* is specified image will be written to a file,
otherwise it will be disassembled and printed to stdout.
**bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** }]
Dump eBPF instructions of the program from the kernel. By
default, eBPF will be disassembled and printed to standard
output in human-readable format. In this case, **opcodes**
controls if raw opcodes should be printed as well.

**opcodes** controls if raw opcodes will be printed.
If **file** is specified, the binary image will instead be
written to *FILE*.

If **visual** is specified, control flow graph (CFG) will be
built instead, and eBPF instructions will be presented with
CFG in DOT format, on standard output.

**bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** }]
Dump jited image (host machine code) of the program.
Expand Down
13 changes: 9 additions & 4 deletions tools/bpf/bpftool/bash-completion/bpftool
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ _bpftool()

# Deal with simplest keywords
case $prev in
help|key|opcodes)
help|key|opcodes|visual)
return 0
;;
tag)
Expand Down Expand Up @@ -223,11 +223,16 @@ _bpftool()
return 0
;;
*)
_bpftool_once_attr 'file'
_bpftool_once_attr 'file'
if _bpftool_search_list 'xlated'; then
COMPREPLY+=( $( compgen -W 'opcodes visual' -- \
"$cur" ) )
else
COMPREPLY+=( $( compgen -W 'opcodes' -- \
"$cur" ) )
return 0
;;
fi
return 0
;;
esac
;;
pin)
Expand Down
Loading

0 comments on commit e4e31cf

Please sign in to comment.