Skip to content

samples: bpf: Refactor XDP programs with libbpf

Daniel T. Lee bpf netdev xdp-newbies 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest posting 2/23 patches 3 repliesIn review
  2. v2 posting 1/23 patches 0 repliesSuperseded
  3. v13 patches 8 repliesSuperseded

Changes in v2 from the cover letter

- added cleanup logic for bpf_link and bpf_object in xdp_monitor
- program section match with bpf_program__is_<type> instead of strncmp
- revert BTF key/val type to default of BPF_MAP_TYPE_PERF_EVENT_ARRAY
- split increment into seperate satement
- refactor pointer array initialization
- error code cleanup

Patches in v2 posting 2/2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3samples: bpf: Refactor xdp_monitor with libbpfsamples/bpf/Makefile samples/bpf/xdp_monitor_user.c+121 -401 reply
2/3samples: bpf: Replace attach_tracepoint() to attach() in xdp_redirect_cpusamples/bpf/Makefile samples/bpf/xdp_redirect_cpu_user.c+73 -821 reply
3/3samples: bpf: refactor XDP kern program maps with BTF-defined mapsamples/bpf/xdp_monitor_kern.c samples/bpf/xdp_sample_pkts_kern.c samples/bpf/xdp_sample_pkts_user.c+36 -391 reply

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchAndrii Nakryiko
1/3A-b
2/3A-b
3/3A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH bpf-next v2 0/3] samples: bpf: Refactor XDP programs with libbpf

To avoid confusion caused by the increasing fragmentation of the BPF Loader program, this commit would like to convert the previous bpf_load loader with the libbpf loader.

Thanks to libbpf's bpf_link interface, managing the tracepoint BPF program is much easier. bpf_program__attach_tracepoint manages the enable of tracepoint event and attach of BPF programs to it with a single interface bpf_link, so there is no need to manage event_fd and prog_fd separately.

And due to addition of generic bpf_program__attach() to libbpf, it is now possible to attach BPF programs with __attach() instead of explicitly calling __attach_<type>().

This patchset refactors xdp_monitor with using this libbpf API, and the bpf_load is removed and migrated to libbpf. Also, attach_tracepoint() is replaced with the generic __attach() method in xdp_redirect_cpu. Moreover, maps in kern program have been converted to BTF-defined map.

---
Changes in v2:
- added cleanup logic for bpf_link and bpf_object in xdp_monitor
- program section match with bpf_program__is_<type> instead of strncmp
- revert BTF key/val type to default of BPF_MAP_TYPE_PERF_EVENT_ARRAY
- split increment into seperate satement
- refactor pointer array initialization
- error code cleanup

Daniel T. Lee (3):
samples: bpf: Refactor xdp_monitor with libbpf
samples: bpf: Replace attach_tracepoint() to attach() in
xdp_redirect_cpu
samples: bpf: refactor XDP kern program maps with BTF-defined map

 samples/bpf/Makefile                |   4 +-
 samples/bpf/xdp_monitor_kern.c      |  60 +++++------
 samples/bpf/xdp_monitor_user.c      | 159 +++++++++++++++++++++-------
 samples/bpf/xdp_redirect_cpu_user.c | 153 +++++++++++++-------------
 samples/bpf/xdp_sample_pkts_kern.c  |  14 ++-
 samples/bpf/xdp_sample_pkts_user.c  |   1 -
 6 files changed, 230 insertions(+), 161 deletions(-)
Signature · 1 line
2.25.1