1. 24 Aug, 2023 13 commits
    • Alexei Starovoitov's avatar
      Merge branch 'samples-bpf-remove-unmaintained-xdp-sample-utilities' · 1b580c9b
      Alexei Starovoitov authored
      Toke Høiland-Jørgensen says:
      
      ====================
      samples/bpf: Remove unmaintained XDP sample utilities
      
      The samples/bpf directory in the kernel tree started out as a way of showcasing
      different aspects of BPF functionality by writing small utility programs for
      each feature. However, as the BPF subsystem has matured, the preferred way of
      including userspace code with a feature has become the BPF selftests, which also
      have the benefit of being consistently run as part of the BPF CI system.
      
      As a result of this shift, the utilities in samples/bpf have seen little love,
      and have slowly bitrotted. There have been sporadic cleanup patches over the
      years, but it's clear that the utilities are far from maintained.
      
      For XDP in particular, some of the utilities have been used as benchmarking aids
      when implementing new kernel features, which seems to be the main reason they
      have stuck around; any updates the utilities have seen have been targeted at
      this use case. However, as the BPF subsystem as a whole has moved on, it has
      become increasingly difficult to incorporate new features into these utilities
      because they predate most of the modern BPF features (such as kfuncs and BTF).
      
      Rather than try to update these utilities and keep maintaining them in the
      kernel tree, we have ported the useful features of the utilities to the
      xdp-tools package. In the porting process we also updated the utilities to take
      advantage of modern BPF features, integrated them with libxdp, and polished the
      user interface.
      
      As these utilities are standalone tools, maintaining them out of tree is
      simpler, and we plan to keep maintaining them in the xdp-tools repo. To direct
      users of these utilities to the right place, this series removes the utilities
      from samples/bpf, leaving in place only a couple of utilities whose
      functionality have not yet been ported to xdp-tools.
      
      The xdp-tools repository is located on Github at the following URL:
      
      https://github.com/xdp-project/xdp-tools
      
      The commits in the series removes one utility each, explaining how the
      equivalent functionality can be obtained with xdp-tools.
      
      v2:
      - Add equivalent xdp-tools commands for each removed utility
      v3:
      - Add link to xdp-tools in the README
      
      Toke Høiland-Jørgensen (7):
        samples/bpf: Remove the xdp_monitor utility
        samples/bpf: Remove the xdp_redirect* utilities
        samples/bpf: Remove the xdp_rxq_info utility
        samples/bpf: Remove the xdp1 and xdp2 utilities
        samples/bpf: Remove the xdp_sample_pkts utility
        samples/bpf: Cleanup .gitignore
        samples/bpf: Add note to README about the XDP utilities moved to
          xdp-tools
      
       samples/bpf/.gitignore                    |  12 -
       samples/bpf/Makefile                      |  48 +-
       samples/bpf/README.rst                    |   6 +
       samples/bpf/xdp1_kern.c                   | 100 ----
       samples/bpf/xdp1_user.c                   | 166 ------
       samples/bpf/xdp2_kern.c                   | 125 -----
       samples/bpf/xdp_monitor.bpf.c             |   8 -
       samples/bpf/xdp_monitor_user.c            | 118 -----
       samples/bpf/xdp_redirect.bpf.c            |  49 --
       samples/bpf/xdp_redirect_cpu.bpf.c        | 539 -------------------
       samples/bpf/xdp_redirect_cpu_user.c       | 559 --------------------
       samples/bpf/xdp_redirect_map.bpf.c        |  97 ----
       samples/bpf/xdp_redirect_map_multi.bpf.c  |  77 ---
       samples/bpf/xdp_redirect_map_multi_user.c | 232 --------
       samples/bpf/xdp_redirect_map_user.c       | 228 --------
       samples/bpf/xdp_redirect_user.c           | 172 ------
       samples/bpf/xdp_rxq_info_kern.c           | 140 -----
       samples/bpf/xdp_rxq_info_user.c           | 614 ----------------------
       samples/bpf/xdp_sample_pkts_kern.c        |  57 --
       samples/bpf/xdp_sample_pkts_user.c        | 196 -------
       20 files changed, 7 insertions(+), 3536 deletions(-)
       delete mode 100644 samples/bpf/xdp1_kern.c
       delete mode 100644 samples/bpf/xdp1_user.c
       delete mode 100644 samples/bpf/xdp2_kern.c
       delete mode 100644 samples/bpf/xdp_monitor.bpf.c
       delete mode 100644 samples/bpf/xdp_monitor_user.c
       delete mode 100644 samples/bpf/xdp_redirect.bpf.c
       delete mode 100644 samples/bpf/xdp_redirect_cpu.bpf.c
       delete mode 100644 samples/bpf/xdp_redirect_cpu_user.c
       delete mode 100644 samples/bpf/xdp_redirect_map.bpf.c
       delete mode 100644 samples/bpf/xdp_redirect_map_multi.bpf.c
       delete mode 100644 samples/bpf/xdp_redirect_map_multi_user.c
       delete mode 100644 samples/bpf/xdp_redirect_map_user.c
       delete mode 100644 samples/bpf/xdp_redirect_user.c
       delete mode 100644 samples/bpf/xdp_rxq_info_kern.c
       delete mode 100644 samples/bpf/xdp_rxq_info_user.c
       delete mode 100644 samples/bpf/xdp_sample_pkts_kern.c
       delete mode 100644 samples/bpf/xdp_sample_pkts_user.c
      ====================
      
      Link: https://lore.kernel.org/r/20230824102255.1561885-1-toke@redhat.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      1b580c9b
    • Toke Høiland-Jørgensen's avatar
      samples/bpf: Add note to README about the XDP utilities moved to xdp-tools · 5a9fd0f7
      Toke Høiland-Jørgensen authored
      To help users find the XDP utilities, add a note to the README about the
      new location and the conversion documentation in the commit messages.
      Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/r/20230824102255.1561885-8-toke@redhat.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      5a9fd0f7
    • Toke Høiland-Jørgensen's avatar
      samples/bpf: Cleanup .gitignore · 91b96513
      Toke Høiland-Jørgensen authored
      Remove no longer present XDP utilities from .gitignore. Apart from the
      recently removed XDP utilities this also includes the previously removed
      xdpsock and xsk utilities.
      Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/r/20230824102255.1561885-7-toke@redhat.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      91b96513
    • Toke Høiland-Jørgensen's avatar
      samples/bpf: Remove the xdp_sample_pkts utility · cced0699
      Toke Høiland-Jørgensen authored
      The functionality of this utility is covered by the xdpdump utility in
      xdp-tools.
      
      There's a slight difference in usage as the xdpdump utility's main focus is
      to dump packets before or after they are processed by an existing XDP
      program. However, xdpdump also has the --load-xdp-program switch, which
      will make it attach its own program if no existing program is loaded. With
      this, xdp_sample_pkts usage can be converted as:
      
      xdp_sample_pkts eth0
        --> xdpdump --load-xdp-program eth0
      
      To get roughly equivalent behaviour.
      Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/r/20230824102255.1561885-6-toke@redhat.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      cced0699
    • Toke Høiland-Jørgensen's avatar
      samples/bpf: Remove the xdp1 and xdp2 utilities · eaca21d6
      Toke Høiland-Jørgensen authored
      The functionality of these utilities have been incorporated into the
      xdp-bench utility in xdp-tools.
      
      Equivalent functionality is:
      
      xdp1 eth0
        --> xdp-bench drop -p parse-ip -l load-bytes eth0
      
      xdp2 eth0
        --> xdp-bench drop -p swap-macs eth0
      
      Note that there's a slight difference in behaviour of those examples: the
      swap-macs operation of xdp-bench doesn't use the bpf_xdp_load_bytes()
      helper to load the packet data, whereas the xdp2 utility did so
      unconditionally. For the parse-ip action the use of bpf_xdp_load_bytes()
      can be selected by the '-l load-bytes' switch, with the difference that the
      xdp-bench utility will perform two separate calls to the helper, one to
      load the ethernet header and another to load the IP header; where the xdp1
      utility only performed one call always loading 60 bytes of data.
      Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/r/20230824102255.1561885-5-toke@redhat.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      eaca21d6
    • Toke Høiland-Jørgensen's avatar
      samples/bpf: Remove the xdp_rxq_info utility · 0e445e11
      Toke Høiland-Jørgensen authored
      The functionality of this utility has been incorporated into the xdp-bench
      utility in xdp-tools, by way of the --rxq-stats argument to the 'drop',
      'pass' and 'tx' commands of xdp-bench.
      
      Some examples of how to convert xdp_rxq_info invocations into equivalent
      xdp-bench commands:
      
      xdp_rxq_info -d eth0
        --> xdp-bench pass --rxq-stats eth0
      
      xdp_rxq_info -d eth0 -a XDP_DROP -m
        --> xdp-bench drop --rxq-stats -p swap-macs eth0
      Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/r/20230824102255.1561885-4-toke@redhat.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      0e445e11
    • Toke Høiland-Jørgensen's avatar
      samples/bpf: Remove the xdp_redirect* utilities · 91dda69b
      Toke Høiland-Jørgensen authored
      These utilities have all been ported to xdp-tools as functions of the
      xdp-bench utility. The four different utilities in samples are incorporated
      as separate subcommands to xdp-bench, with most of the command line
      parameters left intact, except that mandatory arguments are always
      positional in xdp-bench. For full usage details see the --help output of
      each command, or the xdp-bench man page.
      
      Some examples of how to convert usage to xdp-bench are:
      
      xdp_redirect eth0 eth1
        --> xdp-bench redirect eth0 eth1
      
      xdp_redirect_map eth0 eth1
        --> xdp-bench redirect-map eth0 eth1
      
      xdp_redirect_map_multi eth0 eth1 eth2 eth3
        --> xdp-bench redirect-multi eth0 eth1 eth2 eth3
      
      xdp_redirect_cpu -d eth0 -c 0 -c 1
        --> xdp-bench redirect-cpu -c 0 -c 1 eth0
      
      xdp_redirect_cpu -d eth0 -c 0 -c 1 -r eth1
        --> xdp-bench redirect-cpu -c 0 -c 1 eth0 -r redirect -D eth1
      Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/r/20230824102255.1561885-3-toke@redhat.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      91dda69b
    • Toke Høiland-Jørgensen's avatar
      samples/bpf: Remove the xdp_monitor utility · e7c9e73d
      Toke Høiland-Jørgensen authored
      This utility has been ported as-is to xdp-tools as 'xdp-monitor'. The only
      difference in usage between the samples and xdp-tools versions is that the
      '-v' command line parameter has been changed to '-e' in the xdp-tools
      version for consistency with the other utilities.
      Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/r/20230824102255.1561885-2-toke@redhat.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      e7c9e73d
    • Yonghong Song's avatar
      selftests/bpf: Add a local kptr test with no special fields · 001fedac
      Yonghong Song authored
      Add a local kptr test with no special fields in the struct. Without the
      previous patch, the following warning will hit:
      
        [   44.683877] WARNING: CPU: 3 PID: 485 at kernel/bpf/syscall.c:660 bpf_obj_free_fields+0x220/0x240
        [   44.684640] Modules linked in: bpf_testmod(OE)
        [   44.685044] CPU: 3 PID: 485 Comm: kworker/u8:5 Tainted: G           OE      6.5.0-rc5-01703-g260d855e9b90 #248
        [   44.685827] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
        [   44.686693] Workqueue: events_unbound bpf_map_free_deferred
        [   44.687297] RIP: 0010:bpf_obj_free_fields+0x220/0x240
        [   44.687775] Code: e8 55 17 1f 00 49 8b 74 24 08 4c 89 ef e8 e8 14 05 00 e8 a3 da e2 ff e9 55 fe ff ff 0f 0b e9 4e fe ff
                             ff 0f 0b e9 47 fe ff ff <0f> 0b e8 d9 d9 e2 ff 31 f6 eb d5 48 83 c4 10 5b 41 5c e
        [   44.689353] RSP: 0018:ffff888106467cb8 EFLAGS: 00010246
        [   44.689806] RAX: 0000000000000000 RBX: ffff888112b3a200 RCX: 0000000000000001
        [   44.690433] RDX: 0000000000000000 RSI: dffffc0000000000 RDI: ffff8881128ad988
        [   44.691094] RBP: 0000000000000002 R08: ffffffff81370bd0 R09: 1ffff110216231a5
        [   44.691643] R10: dffffc0000000000 R11: ffffed10216231a6 R12: ffff88810d68a488
        [   44.692245] R13: ffff88810767c288 R14: ffff88810d68a400 R15: ffff88810d68a418
        [   44.692829] FS:  0000000000000000(0000) GS:ffff8881f7580000(0000) knlGS:0000000000000000
        [   44.693484] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        [   44.693964] CR2: 000055c7f2afce28 CR3: 000000010fee4002 CR4: 0000000000370ee0
        [   44.694513] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
        [   44.695102] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
        [   44.695747] Call Trace:
        [   44.696001]  <TASK>
        [   44.696183]  ? __warn+0xfe/0x270
        [   44.696447]  ? bpf_obj_free_fields+0x220/0x240
        [   44.696817]  ? report_bug+0x220/0x2d0
        [   44.697180]  ? handle_bug+0x3d/0x70
        [   44.697507]  ? exc_invalid_op+0x1a/0x50
        [   44.697887]  ? asm_exc_invalid_op+0x1a/0x20
        [   44.698282]  ? btf_find_struct_meta+0xd0/0xd0
        [   44.698634]  ? bpf_obj_free_fields+0x220/0x240
        [   44.699027]  ? bpf_obj_free_fields+0x1e2/0x240
        [   44.699414]  array_map_free+0x1a3/0x260
        [   44.699763]  bpf_map_free_deferred+0x7b/0xe0
        [   44.700154]  process_one_work+0x46d/0x750
        [   44.700523]  worker_thread+0x49e/0x900
        [   44.700892]  ? pr_cont_work+0x270/0x270
        [   44.701224]  kthread+0x1ae/0x1d0
        [   44.701516]  ? kthread_blkcg+0x50/0x50
        [   44.701860]  ret_from_fork+0x34/0x50
        [   44.702178]  ? kthread_blkcg+0x50/0x50
        [   44.702508]  ret_from_fork_asm+0x11/0x20
        [   44.702880]  </TASK>
      
      With the previous patch, there is no warnings.
      Signed-off-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Link: https://lore.kernel.org/r/20230824063422.203097-1-yonghong.song@linux.devSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      001fedac
    • Yonghong Song's avatar
      bpf: Remove a WARN_ON_ONCE warning related to local kptr · 393dc4bd
      Yonghong Song authored
      Currently, in function bpf_obj_free_fields(), for local kptr,
      a warning will be issued if the struct does not contain any
      special fields. But actually the kernel seems totally okay
      with a local kptr without any special fields. Permitting
      no special fields also aligns with future percpu kptr which
      also allows no special fields.
      Acked-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
      Signed-off-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Link: https://lore.kernel.org/r/20230824063417.201925-1-yonghong.song@linux.devSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      393dc4bd
    • Andrii Nakryiko's avatar
      libbpf: fix signedness determination in CO-RE relo handling logic · f3bdb54f
      Andrii Nakryiko authored
      Extracting btf_int_encoding() is only meaningful for BTF_KIND_INT, so we
      need to check that first before inferring signedness.
      
      Closes: https://github.com/libbpf/libbpf/issues/704Reported-by: default avatarLorenz Bauer <lmb@isovalent.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Link: https://lore.kernel.org/r/20230824000016.2658017-2-andrii@kernel.orgSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
      f3bdb54f
    • Andrii Nakryiko's avatar
      selftests/bpf: add uprobe_multi test binary to .gitignore · a182e641
      Andrii Nakryiko authored
      It seems like it was forgotten to add uprobe_multi binary to .gitignore.
      Fix this trivial omission.
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Link: https://lore.kernel.org/r/20230824000016.2658017-1-andrii@kernel.orgSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
      a182e641
    • Daniel Xu's avatar
      libbpf: Add bpf_object__unpin() · 068ca522
      Daniel Xu authored
      For bpf_object__pin_programs() there is bpf_object__unpin_programs().
      Likewise bpf_object__unpin_maps() for bpf_object__pin_maps().
      
      But no bpf_object__unpin() for bpf_object__pin(). Adding the former adds
      symmetry to the API.
      
      It's also convenient for cleanup in application code. It's an API I
      would've used if it was available for a repro I was writing earlier.
      Signed-off-by: default avatarDaniel Xu <dxu@dxuuu.xyz>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Reviewed-by: default avatarSong Liu <song@kernel.org>
      Link: https://lore.kernel.org/bpf/b2f9d41da4a350281a0b53a804d11b68327e14e5.1692832478.git.dxu@dxuuu.xyz
      068ca522
  2. 23 Aug, 2023 3 commits
  3. 22 Aug, 2023 6 commits
  4. 21 Aug, 2023 18 commits