18 Jun, 2019

1 commit


28 May, 2019

1 commit


21 May, 2019

1 commit


04 Dec, 2018

1 commit


24 Nov, 2018

1 commit

  • Currently, kprobe_events failure won't be handled properly.
    Due to calling system() indirectly to write to kprobe_events,
    it can't be identified whether an error is derived from kprobe or system.

    // buf = "echo '%c:%s %s' >> /s/k/d/t/kprobe_events"
    err = system(buf);
    if (err < 0) {
    printf("failed to create kprobe ..");
    return -1;
    }

    For example, running ./tracex7 sample in ext4 partition,
    "echo p:open_ctree open_ctree >> /s/k/d/t/kprobe_events"
    gets 256 error code system() failure.
    => The error comes from kprobe, but it's not handled correctly.

    According to man of system(3), it's return value
    just passes the termination status of the child shell
    rather than treating the error as -1. (don't care success)

    Which means, currently it's not working as desired.
    (According to the upper code snippet)

    ex) running ./tracex7 with ext4 env.
    # Current Output
    sh: echo: I/O error
    failed to open event open_ctree

    # Desired Output
    failed to create kprobe 'open_ctree' error 'No such file or directory'

    The problem is, error can't be verified whether from child ps
    or system. But using write() directly can verify the command
    failure, and it will treat all error as -1. So I suggest using
    write() directly to 'kprobe_events' rather than calling system().

    Signed-off-by: Daniel T. Lee
    Signed-off-by: Daniel Borkmann

    Daniel T. Lee
     

08 Nov, 2018

1 commit


18 Sep, 2018

1 commit


17 Jul, 2018

1 commit


15 May, 2018

1 commit


11 May, 2018

1 commit

  • Both tools/lib/bpf/libbpf.h and samples/bpf/bpf_load.h define their
    own version of struct bpf_map_def. The version in bpf_load.h has
    more fields. libbpf does not support inner maps and its definition
    of struct bpf_map_def lacks the related fields. Rename the definition
    in bpf_load.h (samples/bpf) to avoid conflicts.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     

30 Apr, 2018

1 commit

  • Commit d5a00528b58c ("syscalls/core, syscalls/x86: Rename
    struct pt_regs-based sys_*() to __x64_sys_*()") renamed a lot
    of syscall function sys_*() to __x64_sys_*().
    This caused several kprobe based samples/bpf tests failing.

    This patch fixed the problem in bpf_load.c.
    For x86_64 architecture, function name __x64_sys_*() will be
    first used for kprobe event creation. If the creation is successful,
    it will be used. Otherwise, function name sys_*() will be used
    for kprobe event creation.

    Fixes: d5a00528b58c ("syscalls/core, syscalls/x86: Rename struct pt_regs-based sys_*() to __x64_sys_*()")
    Signed-off-by: Yonghong Song
    Signed-off-by: Alexei Starovoitov

    Yonghong Song
     

29 Apr, 2018

1 commit

  • There is no functionality change in this patch. The common-purpose
    trace functions, including perf_event polling and ksym lookup,
    are moved from trace_output_user.c and bpf_load.c to
    selftests/bpf/trace_helpers.c so that these function can
    be reused later in selftests.

    Acked-by: Alexei Starovoitov
    Signed-off-by: Yonghong Song
    Signed-off-by: Alexei Starovoitov

    Yonghong Song
     

27 Apr, 2018

1 commit

  • 2 redundant ret assignments removed:

    * 'ret = 1' before the logic 'if (data_maps)', and if any errors jump to
    label 'done'. No 'ret = 1' needed before the error jump.

    * After the '/* load programs */' part, if everything goes well, then
    the BPF code will be loaded and 'ret' set to 0 by load_and_attach().
    If something goes wrong, 'ret' set to none-O, the redundant 'ret = 0'
    after the for clause will make the error skipped.

    For example, if some BPF code cannot provide supported program types
    in ELF SEC("unknown"), the for clause will not call load_and_attach()
    to load the BPF code. 1 should be returned to callees instead of 0.

    Signed-off-by: Wang Sheng-Hui
    Signed-off-by: Daniel Borkmann

    Wang Sheng-Hui
     

29 Mar, 2018

1 commit


20 Mar, 2018

1 commit


03 Feb, 2018

1 commit


01 Dec, 2017

1 commit

  • load_bpf_file() should fail if ioctl with command
    PERF_EVENT_IOC_ENABLE and PERF_EVENT_IOC_SET_BPF fails.
    When they do fail, proper error messages are printed.

    With this change, the below "syscall_tp" run shows that
    the maximum number of bpf progs attaching to the same
    perf tracepoint is indeed enforced.
    $ ./syscall_tp -i 64
    prog #0: map ids 4 5
    ...
    prog #63: map ids 382 383
    $ ./syscall_tp -i 65
    prog #0: map ids 4 5
    ...
    prog #64: map ids 388 389
    ioctl PERF_EVENT_IOC_SET_BPF failed err Argument list too long

    Signed-off-by: Yonghong Song
    Signed-off-by: Daniel Borkmann

    Yonghong Song
     

04 Nov, 2017

1 commit


02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

29 Sep, 2017

1 commit

  • This patch extends the libbpf to provide API support to
    allow specifying BPF object name.

    In tools/lib/bpf/libbpf, the C symbol of the function
    and the map is used. Regarding section name, all maps are
    under the same section named "maps". Hence, section name
    is not a good choice for map's name. To be consistent with
    map, bpf_prog also follows and uses its function symbol as
    the prog's name.

    This patch adds logic to collect function's symbols in libbpf.
    There is existing codes to collect the map's symbols and no change
    is needed.

    The bpf_load_program_name() and bpf_map_create_name() are
    added to take the name argument. For the other bpf_map_create_xxx()
    variants, a name argument is directly added to them.

    In samples/bpf, bpf_load.c in particular, the symbol is also
    used as the map's name and the map symbols has already been
    collected in the existing code. For bpf_prog, bpf_load.c does
    not collect the function symbol name. We can consider to collect
    them later if there is a need to continue supporting the bpf_load.c.

    Signed-off-by: Martin KaFai Lau
    Acked-by: Alexei Starovoitov
    Acked-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Martin KaFai Lau
     

20 Aug, 2017

1 commit


17 Aug, 2017

1 commit

  • This program binds a program to a cgroup and then matches hard
    coded IP addresses and adds these to a sockmap.

    This will receive messages from the backend and send them to
    the client.

    client:X frontend:10000 client:X backend:10001

    To keep things simple this is only designed for 1:1 connections
    using hard coded values. A more complete example would allow many
    backends and clients.

    To run,

    # sockmap

    Signed-off-by: John Fastabend
    Signed-off-by: David S. Miller

    John Fastabend
     

05 Jul, 2017

1 commit

  • The function load_bpf_file ignores the return value of
    load_and_attach(), so even if load_and_attach() returns an error,
    load_bpf_file() will return 0.

    Now, load_bpf_file() can call load_and_attach() multiple times and some
    can succeed and some could fail. I think the correct behavor is to
    return error on the first failed load_and_attach().

    v2: Added missing SOB

    Signed-off-by: Lawrence Brakmo
    Signed-off-by: David S. Miller

    Lawrence Brakmo
     

02 Jul, 2017

1 commit

  • Created a new BPF program type, BPF_PROG_TYPE_SOCK_OPS, and a corresponding
    struct that allows BPF programs of this type to access some of the
    socket's fields (such as IP addresses, ports, etc.). It uses the
    existing bpf cgroups infrastructure so the programs can be attached per
    cgroup with full inheritance support. The program will be called at
    appropriate times to set relevant connections parameters such as buffer
    sizes, SYN and SYN-ACK RTOs, etc., based on connection information such
    as IP addresses, port numbers, etc.

    Alghough there are already 3 mechanisms to set parameters (sysctls,
    route metrics and setsockopts), this new mechanism provides some
    distinct advantages. Unlike sysctls, it can set parameters per
    connection. In contrast to route metrics, it can also use port numbers
    and information provided by a user level program. In addition, it could
    set parameters probabilistically for evaluation purposes (i.e. do
    something different on 10% of the flows and compare results with the
    other 90% of the flows). Also, in cases where IPv6 addresses contain
    geographic information, the rules to make changes based on the distance
    (or RTT) between the hosts are much easier than route metric rules and
    can be global. Finally, unlike setsockopt, it oes not require
    application changes and it can be updated easily at any time.

    Although the bpf cgroup framework already contains a sock related
    program type (BPF_PROG_TYPE_CGROUP_SOCK), I created the new type
    (BPF_PROG_TYPE_SOCK_OPS) beccause the existing type expects to be called
    only once during the connections's lifetime. In contrast, the new
    program type will be called multiple times from different places in the
    network stack code. For example, before sending SYN and SYN-ACKs to set
    an appropriate timeout, when the connection is established to set
    congestion control, etc. As a result it has "op" field to specify the
    type of operation requested.

    The purpose of this new program type is to simplify setting connection
    parameters, such as buffer sizes, TCP's SYN RTO, etc. For example, it is
    easy to use facebook's internal IPv6 addresses to determine if both hosts
    of a connection are in the same datacenter. Therefore, it is easy to
    write a BPF program to choose a small SYN RTO value when both hosts are
    in the same datacenter.

    This patch only contains the framework to support the new BPF program
    type, following patches add the functionality to set various connection
    parameters.

    This patch defines a new BPF program type: BPF_PROG_TYPE_SOCKET_OPS
    and a new bpf syscall command to load a new program of this type:
    BPF_PROG_LOAD_SOCKET_OPS.

    Two new corresponding structs (one for the kernel one for the user/BPF
    program):

    /* kernel version */
    struct bpf_sock_ops_kern {
    struct sock *sk;
    __u32 op;
    union {
    __u32 reply;
    __u32 replylong[4];
    };
    };

    /* user version
    * Some fields are in network byte order reflecting the sock struct
    * Use the bpf_ntohl helper macro in samples/bpf/bpf_endian.h to
    * convert them to host byte order.
    */
    struct bpf_sock_ops {
    __u32 op;
    union {
    __u32 reply;
    __u32 replylong[4];
    };
    __u32 family;
    __u32 remote_ip4; /* In network byte order */
    __u32 local_ip4; /* In network byte order */
    __u32 remote_ip6[4]; /* In network byte order */
    __u32 local_ip6[4]; /* In network byte order */
    __u32 remote_port; /* In network byte order */
    __u32 local_port; /* In host byte horder */
    };

    Currently there are two types of ops. The first type expects the BPF
    program to return a value which is then used by the caller (or a
    negative value to indicate the operation is not supported). The second
    type expects state changes to be done by the BPF program, for example
    through a setsockopt BPF helper function, and they ignore the return
    value.

    The reply fields of the bpf_sockt_ops struct are there in case a bpf
    program needs to return a value larger than an integer.

    Signed-off-by: Lawrence Brakmo
    Acked-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Lawrence Brakmo
     

01 Jun, 2017

1 commit

  • An eBPF ELF file generated with LLVM can contain several program
    section, which can be used for bpf tail calls. The bpf prog file
    descriptors are accessible via array prog_fd[].

    At-least XDP samples assume ordering, and uses prog_fd[0] is the main
    XDP program to attach. The actual order of array prog_fd[] depend on
    whether or not a bpf program section is referencing any maps or not.
    Not using a map result in being loaded/processed after all other
    prog section. Thus, this can lead to some very strange and hard to
    debug situation, as the user can only see a FD and cannot correlated
    that with the ELF section name.

    The fix is rather simple, and even removes duplicate memcmp code.
    Simply load program sections as the last step, instead of
    load_and_attach while processing the relocation section.

    When working with tail calls, it become even more essential that the
    order of prog_fd[] is consistant, like the current dependency of the
    map_fd[] order.

    Signed-off-by: Jesper Dangaard Brouer
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Jesper Dangaard Brouer
     

03 May, 2017

2 commits

  • Do this change before others start to use this callback.
    Change map_perf_test_user.c which seems to be the only user.

    This patch extends capabilities of commit 9fd63d05f3e8 ("bpf:
    Allow bpf sample programs (*_user.c) to change bpf_map_def").

    Give fixup callback access to struct bpf_map_data, instead of
    only stuct bpf_map_def. This add flexibility to allow userspace
    to reassign the map file descriptor. This is very useful when
    wanting to share maps between several bpf programs.

    Signed-off-by: Jesper Dangaard Brouer
    Signed-off-by: David S. Miller

    Jesper Dangaard Brouer
     
  • This patch does proper parsing of the ELF "maps" section, in-order to
    be both backwards and forwards compatible with changes to the map
    definition struct bpf_map_def, which gets compiled into the ELF file.

    The assumption is that new features with value zero, means that they
    are not in-use. For backward compatibility where loading an ELF file
    with a smaller struct bpf_map_def, only copy objects ELF size, leaving
    rest of loaders struct zero. For forward compatibility where ELF file
    have a larger struct bpf_map_def, only copy loaders own struct size
    and verify that rest of the larger struct is zero, assuming this means
    the newer feature was not activated, thus it should be safe for this
    older loader to load this newer ELF file.

    Fixes: fb30d4b71214 ("bpf: Add tests for map-in-map")
    Fixes: 409526bea3c3 ("samples/bpf: bpf_load.c detect and abort if ELF maps section size is wrong")
    Signed-off-by: Jesper Dangaard Brouer
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Jesper Dangaard Brouer
     

01 May, 2017

2 commits

  • The kernel side of XDP_FLAGS_SKB_MODE is unsigned, and the rtnetlink
    IFLA_XDP_FLAGS is defined as NLA_U32. Thus, userspace programs under
    samples/bpf/ should use the correct type.

    Fixes: 3993f2cb983b ("samples/bpf: Add support for SKB_MODE to xdp1 and xdp_tx_iptunnel")
    Signed-off-by: Jesper Dangaard Brouer
    Acked-by: Daniel Borkmann
    Reviewed-by: Andy Gospodarek
    Signed-off-by: David S. Miller

    Jesper Dangaard Brouer
     
  • The struct bpf_map_def was extended in commit fb30d4b71214 ("bpf: Add tests
    for map-in-map") with member unsigned int inner_map_idx. This changed the size
    of the maps section in the generated ELF _kern.o files.

    Unfortunately the loader in bpf_load.c does not detect or handle this. Thus,
    older _kern.o files became incompatible, and caused hard-to-debug errors
    where the syscall validation rejected BPF_MAP_CREATE request.

    This patch only detect the situation and aborts load_bpf_file(). It also
    add code comments warning people that read this loader for inspiration
    for these pitfalls.

    Fixes: fb30d4b71214 ("bpf: Add tests for map-in-map")
    Signed-off-by: Jesper Dangaard Brouer
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Jesper Dangaard Brouer
     

28 Apr, 2017

1 commit

  • Add option to xdp1 and xdp_tx_iptunnel to insert xdp program in
    SKB_MODE:
    - update set_link_xdp_fd to take a flags argument that is added to the
    RTM_SETLINK message

    - Add -S option to xdp1 and xdp_tx_iptunnel user code. When passed in
    XDP_FLAGS_SKB_MODE is set in the flags arg passed to set_link_xdp_fd

    Signed-off-by: David Ahern
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    David Ahern
     

18 Apr, 2017

1 commit

  • The current bpf_map_def is statically defined during compile
    time. This patch allows the *_user.c program to change it during
    runtime. It is done by adding load_bpf_file_fixup_map() which
    takes a callback. The callback will be called before creating
    each map so that it has a chance to modify the bpf_map_def.

    The current usecase is to change max_entries in map_perf_test.
    It is interesting to test with a much bigger map size in
    some cases (e.g. the following patch on bpf_lru_map.c).
    However, it is hard to find one size to fit all testing
    environment. Hence, it is handy to take the max_entries
    as a cmdline arg and then configure the bpf_map_def during
    runtime.

    This patch adds two cmdline args. One is to configure
    the map's max_entries. Another is to configure the max_cnt
    which controls how many times a syscall is called.

    Signed-off-by: Martin KaFai Lau
    Acked-by: Alexei Starovoitov
    Acked-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Martin KaFai Lau
     

23 Mar, 2017

1 commit


14 Feb, 2017

2 commits

  • Before loading a new ELF, clean previous kernel version, license and
    processed sections.

    Signed-off-by: Mickaël Salaün
    Acked-by: Joe Stringer
    Acked-by: Wang Nan
    Cc: Alexei Starovoitov
    Cc: Daniel Borkmann
    Cc: David S. Miller
    Cc: netdev@vger.kernel.org
    Link: http://lkml.kernel.org/r/20170208202744.16274-3-mic@digikod.net
    Signed-off-by: Arnaldo Carvalho de Melo

    Mickaël Salaün
     
  • Add a missing check for the map fixup loop.

    Signed-off-by: Mickaël Salaün
    Acked-by: Joe Stringer
    Acked-by: Wang Nan
    Cc: Alexei Starovoitov
    Cc: Daniel Borkmann
    Cc: David S. Miller
    Cc: netdev@vger.kernel.org
    Link: http://lkml.kernel.org/r/20170208202744.16274-2-mic@digikod.net
    Signed-off-by: Arnaldo Carvalho de Melo

    Mickaël Salaün
     

20 Dec, 2016

2 commits

  • This declaration was made in samples/bpf/libbpf.c for convenience, but
    there's already one in tools/perf/perf-sys.h. Reuse that one.

    Committer notes:

    Testing it:

    $ make -j4 O=../build/v4.9.0-rc8+ samples/bpf/
    make[1]: Entering directory '/home/build/v4.9.0-rc8+'
    CHK include/config/kernel.release
    GEN ./Makefile
    CHK include/generated/uapi/linux/version.h
    Using /home/acme/git/linux as source for kernel
    CHK include/generated/utsrelease.h
    CHK include/generated/timeconst.h
    CHK include/generated/bounds.h
    CHK include/generated/asm-offsets.h
    CALL /home/acme/git/linux/scripts/checksyscalls.sh
    HOSTCC samples/bpf/test_verifier.o
    HOSTCC samples/bpf/libbpf.o
    HOSTCC samples/bpf/../../tools/lib/bpf/bpf.o
    HOSTCC samples/bpf/test_maps.o
    HOSTCC samples/bpf/sock_example.o
    HOSTCC samples/bpf/bpf_load.o

    HOSTLD samples/bpf/trace_event
    HOSTLD samples/bpf/sampleip
    HOSTLD samples/bpf/tc_l2_redirect
    make[1]: Leaving directory '/home/build/v4.9.0-rc8+'
    $

    Also tested the offwaketime resulting from the rebuild, seems to work as
    before.

    Signed-off-by: Joe Stringer
    Tested-by: Arnaldo Carvalho de Melo
    Cc: Alexei Starovoitov
    Cc: Daniel Borkmann
    Cc: Wang Nan
    Link: http://lkml.kernel.org/r/20161209024620.31660-7-joe@ovn.org
    [ Use -I$(srctree)/tools/lib/ to support out of source code tree builds ]
    Signed-off-by: Arnaldo Carvalho de Melo

    Joe Stringer
     
  • Now that libbpf under tools/lib/bpf/* is synced with the version from
    samples/bpf, we can get rid most of the libbpf library here.

    Committer notes:

    Built it in a docker fedora rawhide container and ran it in the f25 host, seems
    to work just like it did before this patch, i.e. the switch to tools/lib/bpf/
    doesn't seem to have introduced problems and Joe said he tested it with
    all the entries in samples/bpf/ and other code he found:

    [root@f5065a7d6272 linux]# make -j4 O=/tmp/build/linux headers_install

    [root@f5065a7d6272 linux]# rm -rf /tmp/build/linux/samples/bpf/
    [root@f5065a7d6272 linux]# make -j4 O=/tmp/build/linux samples/bpf/
    make[1]: Entering directory '/tmp/build/linux'
    CHK include/config/kernel.release
    HOSTCC scripts/basic/fixdep
    GEN ./Makefile
    CHK include/generated/uapi/linux/version.h
    Using /git/linux as source for kernel
    CHK include/generated/utsrelease.h
    HOSTCC scripts/basic/bin2c
    HOSTCC arch/x86/tools/relocs_32.o
    HOSTCC arch/x86/tools/relocs_64.o
    LD samples/bpf/built-in.o

    HOSTCC samples/bpf/fds_example.o
    HOSTCC samples/bpf/sockex1_user.o
    /git/linux/samples/bpf/fds_example.c: In function 'bpf_prog_create':
    /git/linux/samples/bpf/fds_example.c:63:6: warning: passing argument 2 of 'bpf_load_program' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
    insns, insns_cnt, "GPL", 0,
    ^~~~~
    In file included from /git/linux/samples/bpf/libbpf.h:5:0,
    from /git/linux/samples/bpf/bpf_load.h:4,
    from /git/linux/samples/bpf/fds_example.c:15:
    /git/linux/tools/lib/bpf/bpf.h:31:5: note: expected 'struct bpf_insn *' but argument is of type 'const struct bpf_insn *'
    int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
    ^~~~~~~~~~~~~~~~
    HOSTCC samples/bpf/sockex2_user.o

    HOSTCC samples/bpf/xdp_tx_iptunnel_user.o
    clang -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/6.2.1/include -I/git/linux/arch/x86/include -I./arch/x86/include/generated/uapi -I./arch/x86/include/generated -I/git/linux/include -I./include -I/git/linux/arch/x86/include/uapi -I/git/linux/include/uapi -I./include/generated/uapi -include /git/linux/include/linux/kconfig.h \
    -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
    -Wno-compare-distinct-pointer-types \
    -Wno-gnu-variable-sized-type-not-at-end \
    -Wno-address-of-packed-member -Wno-tautological-compare \
    -O2 -emit-llvm -c /git/linux/samples/bpf/sockex1_kern.c -o -| llc -march=bpf -filetype=obj -o samples/bpf/sockex1_kern.o
    HOSTLD samples/bpf/tc_l2_redirect

    HOSTLD samples/bpf/lwt_len_hist
    HOSTLD samples/bpf/xdp_tx_iptunnel
    make[1]: Leaving directory '/tmp/build/linux'
    [root@f5065a7d6272 linux]#

    And then, in the host:

    [root@jouet bpf]# mount | grep "docker.*devicemapper\/"
    /dev/mapper/docker-253:0-1705076-9bd8aa1e0af33adce89ff42090847868ca676932878942be53941a06ec5923f9 on /var/lib/docker/devicemapper/mnt/9bd8aa1e0af33adce89ff42090847868ca676932878942be53941a06ec5923f9 type xfs (rw,relatime,context="system_u:object_r:container_file_t:s0:c73,c276",nouuid,attr2,inode64,sunit=1024,swidth=1024,noquota)
    [root@jouet bpf]# cd /var/lib/docker/devicemapper/mnt/9bd8aa1e0af33adce89ff42090847868ca676932878942be53941a06ec5923f9/rootfs/tmp/build/linux/samples/bpf/
    [root@jouet bpf]# file offwaketime
    offwaketime: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f423d171e0487b2f802b6a792657f0f3c8f6d155, not stripped
    [root@jouet bpf]# readelf -SW offwaketime
    offwaketime offwaketime_kern.o offwaketime_user.o
    [root@jouet bpf]# readelf -SW offwaketime_kern.o
    There are 11 section headers, starting at offset 0x700:

    Section Headers:
    [Nr] Name Type Address Off Size ES Flg Lk Inf Al
    [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
    [ 1] .strtab STRTAB 0000000000000000 000658 0000a8 00 0 0 1
    [ 2] .text PROGBITS 0000000000000000 000040 000000 00 AX 0 0 4
    [ 3] kprobe/try_to_wake_up PROGBITS 0000000000000000 000040 0000d8 00 AX 0 0 8
    [ 4] .relkprobe/try_to_wake_up REL 0000000000000000 0005a8 000020 10 10 3 8
    [ 5] tracepoint/sched/sched_switch PROGBITS 0000000000000000 000118 000318 00 AX 0 0 8
    [ 6] .reltracepoint/sched/sched_switch REL 0000000000000000 0005c8 000090 10 10 5 8
    [ 7] maps PROGBITS 0000000000000000 000430 000050 00 WA 0 0 4
    [ 8] license PROGBITS 0000000000000000 000480 000004 00 WA 0 0 1
    [ 9] version PROGBITS 0000000000000000 000484 000004 00 WA 0 0 4
    [10] .symtab SYMTAB 0000000000000000 000488 000120 18 1 4 8
    Key to Flags:
    W (write), A (alloc), X (execute), M (merge), S (strings)
    I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
    O (extra OS processing required) o (OS specific), p (processor specific)
    [root@jouet bpf]# ./offwaketime | head -3
    qemu-system-x86;entry_SYSCALL_64_fastpath;sys_ppoll;do_sys_poll;poll_schedule_timeout;schedule_hrtimeout_range;schedule_hrtimeout_range_clock;schedule;__schedule;-;try_to_wake_up;hrtimer_wakeup;__hrtimer_run_queues;hrtimer_interrupt;local_apic_timer_interrupt;smp_apic_timer_interrupt;__irqentry_text_start;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernel;start_cpu;;swapper/0 4
    firefox;entry_SYSCALL_64_fastpath;sys_poll;do_sys_poll;poll_schedule_timeout;schedule_hrtimeout_range;schedule_hrtimeout_range_clock;schedule;__schedule;-;try_to_wake_up;pollwake;__wake_up_common;__wake_up_sync_key;pipe_write;__vfs_write;vfs_write;sys_write;entry_SYSCALL_64_fastpath;;Timer 1
    swapper/2;start_cpu;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule;__schedule;-;---;; 61
    [root@jouet bpf]#

    Signed-off-by: Joe Stringer
    Tested-by: Arnaldo Carvalho de Melo
    Cc: Alexei Starovoitov
    Cc: Daniel Borkmann
    Cc: Wang Nan
    Cc: netdev@vger.kernel.org
    Link: https://github.com/joestringer/linux/commit/5c40f54a52b1f437123c81e21873f4b4b1f9bd55.patch
    Link: http://lkml.kernel.org/n/tip-xr8twtx7sjh5821g8qw47yxk@git.kernel.org
    [ Use -I$(srctree)/tools/lib/ to support out of source code tree builds, as noticed by Wang Nan ]
    Signed-off-by: Arnaldo Carvalho de Melo

    Joe Stringer
     

16 Dec, 2016

1 commit

  • Switch all of the sample code to use the function names from
    tools/lib/bpf so that they're consistent with that, and to declare their
    own log buffers. This allow the next commit to be purely devoted to
    getting rid of the duplicate library in samples/bpf.

    Committer notes:

    Testing it:

    On a fedora rawhide container, with clang/llvm 3.9, sharing the host
    linux kernel git tree:

    # make O=/tmp/build/linux/ headers_install
    # make O=/tmp/build/linux -C samples/bpf/

    Since I forgot to make it privileged, just tested it outside the
    container, using what it generated:

    # uname -a
    Linux jouet 4.9.0-rc8+ #1 SMP Mon Dec 12 11:20:49 BRT 2016 x86_64 x86_64 x86_64 GNU/Linux
    # cd /var/lib/docker/devicemapper/mnt/c43e09a53ff56c86a07baf79847f00e2cc2a17a1e2220e1adbf8cbc62734feda/rootfs/tmp/build/linux/samples/bpf/
    # ls -la offwaketime
    -rwxr-xr-x. 1 root root 24200 Dec 15 12:19 offwaketime
    # file offwaketime
    offwaketime: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=c940d3f127d5e66cdd680e42d885cb0b64f8a0e4, not stripped
    # readelf -SW offwaketime_kern.o | grep PROGBITS
    [ 2] .text PROGBITS 0000000000000000 000040 000000 00 AX 0 0 4
    [ 3] kprobe/try_to_wake_up PROGBITS 0000000000000000 000040 0000d8 00 AX 0 0 8
    [ 5] tracepoint/sched/sched_switch PROGBITS 0000000000000000 000118 000318 00 AX 0 0 8
    [ 7] maps PROGBITS 0000000000000000 000430 000050 00 WA 0 0 4
    [ 8] license PROGBITS 0000000000000000 000480 000004 00 WA 0 0 1
    [ 9] version PROGBITS 0000000000000000 000484 000004 00 WA 0 0 4
    # ./offwaketime | head -5
    swapper/1;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule;__schedule;-;---;; 106
    CPU 0/KVM;entry_SYSCALL_64_fastpath;sys_ioctl;do_vfs_ioctl;kvm_vcpu_ioctl;kvm_arch_vcpu_ioctl_run;kvm_vcpu_block;schedule;__schedule;-;try_to_wake_up;swake_up_locked;swake_up;apic_timer_expired;apic_timer_fn;__hrtimer_run_queues;hrtimer_interrupt;local_apic_timer_interrupt;smp_apic_timer_interrupt;__irqentry_text_start;cpuidle_enter;call_cpuidle;cpu_startup_entry;start_secondary;;swapper/3 2
    Compositor;entry_SYSCALL_64_fastpath;sys_futex;do_futex;futex_wait;futex_wait_queue_me;schedule;__schedule;-;try_to_wake_up;futex_requeue;do_futex;sys_futex;entry_SYSCALL_64_fastpath;;SoftwareVsyncTh 5
    firefox;entry_SYSCALL_64_fastpath;sys_poll;do_sys_poll;poll_schedule_timeout;schedule_hrtimeout_range;schedule_hrtimeout_range_clock;schedule;__schedule;-;try_to_wake_up;pollwake;__wake_up_common;__wake_up_sync_key;pipe_write;__vfs_write;vfs_write;sys_write;entry_SYSCALL_64_fastpath;;Timer 13
    JS Helper;entry_SYSCALL_64_fastpath;sys_futex;do_futex;futex_wait;futex_wait_queue_me;schedule;__schedule;-;try_to_wake_up;do_futex;sys_futex;entry_SYSCALL_64_fastpath;;firefox 2
    #

    Signed-off-by: Joe Stringer
    Tested-by: Arnaldo Carvalho de Melo
    Cc: Alexei Starovoitov
    Cc: Daniel Borkmann
    Cc: Wang Nan
    Cc: netdev@vger.kernel.org
    Link: http://lkml.kernel.org/r/20161214224342.12858-2-joe@ovn.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Joe Stringer
     

09 Dec, 2016

1 commit

  • The XDP prog checks if the incoming packet matches any VIP:PORT
    combination in the BPF hashmap. If it is, it will encapsulate
    the packet with a IPv4/v6 header as instructed by the value of
    the BPF hashmap and then XDP_TX it out.

    The VIP:PORT -> IP-Encap-Info can be specified by the cmd args
    of the user prog.

    Acked-by: Alexei Starovoitov
    Signed-off-by: Martin KaFai Lau
    Signed-off-by: David S. Miller

    Martin KaFai Lau
     

03 Dec, 2016

1 commit


25 Nov, 2016

1 commit

  • llvm can emit relocations into sections other than program code
    (like debug info sections). Ignore them during parsing of elf file

    Signed-off-by: Alexei Starovoitov
    Acked-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Alexei Starovoitov