Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 034565da authored by Daniel Borkmann's avatar Daniel Borkmann
Browse files

Merge branch 'bpf-bpftool-cleanups'



Quentin Monnet says:

====================
This series contains several minor fixes for bpftool source and
documentation.

The first patches focus on documentation: addition of an option in the page
for "bpftool prog", clean up and update of the same page, and addition of
an example of prog array map manipulation in "bpftool map" page.

The last two fix warnings susceptible to appear when libbfd is not present
(patch 4), or with additional warning flags passed to the compiler (last
patch).
====================

Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parents bab89add c101189b
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
@@ -170,6 +170,61 @@ The following three commands are equivalent:
| **# bpftool map pin id 10 /sys/fs/bpf/map**
| **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00**

Note that map update can also be used in order to change the program references
hold by a program array map. This can be used, for example, to change the
programs used for tail-call jumps at runtime, without having to reload the
entry-point program. Below is an example for this use case: we load a program
defining a prog array map, and with a main function that contains a tail call
to other programs that can be used either to "process" packets or to "debug"
processing. Note that the prog array map MUST be pinned into the BPF virtual
file system for the map update to work successfully, as kernel flushes prog
array maps when they have no more references from user space (and the update
would be lost as soon as bpftool exits).

|
| **# bpftool prog loadall tail_calls.o /sys/fs/bpf/foo type xdp**
| **# bpftool prog --bpffs**

::

  545: xdp  name main_func  tag 674b4b5597193dc3  gpl
          loaded_at 2018-12-12T15:02:58+0000  uid 0
          xlated 240B  jited 257B  memlock 4096B  map_ids 294
          pinned /sys/fs/bpf/foo/xdp
  546: xdp  name bpf_func_process  tag e369a529024751fc  gpl
          loaded_at 2018-12-12T15:02:58+0000  uid 0
          xlated 200B  jited 164B  memlock 4096B
          pinned /sys/fs/bpf/foo/process
  547: xdp  name bpf_func_debug  tag 0b597868bc7f0976  gpl
          loaded_at 2018-12-12T15:02:58+0000  uid 0
          xlated 200B  jited 164B  memlock 4096B
          pinned /sys/fs/bpf/foo/debug

**# bpftool map**

::

  294: prog_array  name jmp_table  flags 0x0
          key 4B  value 4B  max_entries 1  memlock 4096B
          owner_prog_type xdp  owner jited

|
| **# bpftool map pin id 294 /sys/fs/bpf/bar**
| **# bpftool map dump pinned /sys/fs/bpf/bar**

::

  Found 0 elements

|
| **# bpftool map update pinned /sys/fs/bpf/bar key 0 0 0 0 value pinned /sys/fs/bpf/foo/debug**
| **# bpftool map dump pinned /sys/fs/bpf/bar**

::

  key: 00 00 00 00  value: 22 02 00 00
  Found 1 element

SEE ALSO
========
	**bpf**\ (2),
+56 −45
Original line number Diff line number Diff line
@@ -158,26 +158,29 @@ OPTIONS
		  When showing BPF programs, show file names of pinned
		  programs.

	-m, --mapcompat
		  Allow loading maps with unknown map definitions.

EXAMPLES
========
**# bpftool prog show**

::

    10: xdp  name some_prog  tag 005a3d2123620c8b  gpl
	loaded_at Sep 29/20:11  uid 0
            loaded_at 2017-09-29T20:11:00+0000  uid 0
            xlated 528B  jited 370B  memlock 4096B  map_ids 10

**# bpftool --json --pretty prog show**

::

    {
        "programs": [{
    [{
            "id": 10,
            "type": "xdp",
            "tag": "005a3d2123620c8b",
            "gpl_compatible": true,
                "loaded_at": "Sep 29/20:11",
            "loaded_at": 1506715860,
            "uid": 0,
            "bytes_xlated": 528,
            "jited": true,
@@ -187,54 +190,62 @@ EXAMPLES
            ]
        }
    ]
    }

|
| **# bpftool prog dump xlated id 10 file /tmp/t**
| **# ls -l /tmp/t**
|   -rw------- 1 root root 560 Jul 22 01:42 /tmp/t

**# bpftool prog dum jited tag 005a3d2123620c8b**
::

    -rw------- 1 root root 560 Jul 22 01:42 /tmp/t

**# bpftool prog dump jited tag 005a3d2123620c8b**

::

    push   %rbp
    mov    %rsp,%rbp
    sub    $0x228,%rsp
    sub    $0x28,%rbp
    mov    %rbx,0x0(%rbp)
    0:   push   %rbp
    1:   mov    %rsp,%rbp
    2:   sub    $0x228,%rsp
    3:   sub    $0x28,%rbp
    4:   mov    %rbx,0x0(%rbp)

|
| **# mount -t bpf none /sys/fs/bpf/**
| **# bpftool prog pin id 10 /sys/fs/bpf/prog**
| **# bpftool prog load ./my_prog.o /sys/fs/bpf/prog2**
| **# ls -l /sys/fs/bpf/**
|   -rw------- 1 root root 0 Jul 22 01:43 prog
|   -rw------- 1 root root 0 Jul 22 01:44 prog2

**# bpftool prog dum jited pinned /sys/fs/bpf/prog opcodes**
::

    -rw------- 1 root root 0 Jul 22 01:43 prog
    -rw------- 1 root root 0 Jul 22 01:44 prog2

**# bpftool prog dump jited pinned /sys/fs/bpf/prog opcodes**

::

    push   %rbp
   0:   push   %rbp
        55
    mov    %rsp,%rbp
   1:   mov    %rsp,%rbp
        48 89 e5
    sub    $0x228,%rsp
   4:   sub    $0x228,%rsp
        48 81 ec 28 02 00 00
    sub    $0x28,%rbp
   b:   sub    $0x28,%rbp
        48 83 ed 28
    mov    %rbx,0x0(%rbp)
   f:   mov    %rbx,0x0(%rbp)
        48 89 5d 00

|
| **# bpftool prog load xdp1_kern.o /sys/fs/bpf/xdp1 type xdp map name rxcnt id 7**
| **# bpftool prog show pinned /sys/fs/bpf/xdp1**
|   9: xdp  name xdp_prog1  tag 539ec6ce11b52f98  gpl
|	loaded_at 2018-06-25T16:17:31-0700  uid 0
|	xlated 488B  jited 336B  memlock 4096B  map_ids 7
| **# rm /sys/fs/bpf/xdp1**
|

::

    9: xdp  name xdp_prog1  tag 539ec6ce11b52f98  gpl
            loaded_at 2018-06-25T16:17:31-0700  uid 0
            xlated 488B  jited 336B  memlock 4096B  map_ids 7

**# rm /sys/fs/bpf/xdp1**

SEE ALSO
========
+2 −2
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@
#define BPF_FS_MAGIC		0xcafe4a11
#endif

void p_err(const char *fmt, ...)
void __printf(1, 2) p_err(const char *fmt, ...)
{
	va_list ap;

@@ -46,7 +46,7 @@ void p_err(const char *fmt, ...)
	va_end(ap);
}

void p_info(const char *fmt, ...)
void __printf(1, 2) p_info(const char *fmt, ...)
{
	va_list ap;

+4 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <malloc.h>
#include <inttypes.h>
#include <stdint.h>
#include <linux/compiler.h>

#include "json_writer.h"

@@ -157,7 +158,8 @@ void jsonw_name(json_writer_t *self, const char *name)
		putc(' ', self->out);
}

void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
void __printf(2, 0)
jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
{
	jsonw_eor(self);
	putc('"', self->out);
@@ -165,7 +167,7 @@ void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
	putc('"', self->out);
}

void jsonw_printf(json_writer_t *self, const char *fmt, ...)
void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...)
{
	va_list ap;

+1 −1
Original line number Diff line number Diff line
@@ -147,8 +147,8 @@ int prog_parse_fd(int *argc, char ***argv);
int map_parse_fd(int *argc, char ***argv);
int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len);

#ifdef HAVE_LIBBFD_SUPPORT
struct bpf_prog_linfo;
#ifdef HAVE_LIBBFD_SUPPORT
void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes,
		       const char *arch, const char *disassembler_options,
		       const struct btf *btf,
Loading