Skip to content

BPF link force-detach support

Andrii Nakryiko bpf netdev 2 versions – Applied

Status from this message: Applied. Thanks

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 6 repliesApplied
  2. v15 patches 13 repliesSuperseded

Changes in v2 from the cover letter

- improve error reporting in bpftool link detach (Song).

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/5bpf: add support for forced LINK_DETACH commandinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/cgroup.c +3 more+64 -21 reply
2/5libbpf: add bpf_link detach APIstools/include/uapi/linux/bpf.h tools/lib/bpf/bpf.c tools/lib/bpf/bpf.h +3 more+25 -01 reply
3/5selftests/bpf: add link detach tests for cgroup, netns, and xdp bpf_linkstools/testing/selftests/bpf/prog_tests/cgroup_link.c tools/testing/selftests/bpf/prog_tests/sk_lookup.c tools/testing/selftests/bpf/prog_tests/xdp_link.c +2 more+73 -291 reply
4/5tools/bpftool: add `link detach` subcommandtools/bpf/bpftool/link.c+36 -11 reply
5/5tools/bpftool: add documentation and bash-completion for `link detach`tools/bpf/bpftool/Documentation/bpftool-link.rst tools/bpf/bpftool/bash-completion/bpftool+10 -21 reply

Reviews trailers per patch

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

PatchSong LiuJohn Fastabend
1/5A-b A-b
2/5A-b A-b
3/5A-b A-b
4/5A-b A-b
5/5A-b A-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 v2 bpf-next 0/5] BPF link force-detach support

This patch set adds new BPF link operation, LINK_DETACH, allowing processes with BPF link FD to force-detach it from respective BPF hook, similarly how BPF link is auto-detached when such BPF hook (e.g., cgroup, net_device, netns, etc) is removed. This facility allows admin to forcefully undo BPF link attachment, while process that created BPF link in the first place is left intact.

Once force-detached, BPF link stays valid in the kernel as long as there is at least one FD open against it. It goes into defunct state, just like auto-detached BPF link.

bpftool also got link detach command to allow triggering this in non-programmatic fashion.

v1->v2:
- improve error reporting in bpftool link detach (Song).

Andrii Nakryiko (5):
bpf: add support for forced LINK_DETACH command
libbpf: add bpf_link detach APIs
selftests/bpf: add link detach tests for cgroup, netns, and xdp
bpf_links
tools/bpftool: add link detach subcommand
tools/bpftool: add documentation and bash-completion for link detach

 include/linux/bpf.h                           |  1 +
 include/uapi/linux/bpf.h                      |  5 ++
 kernel/bpf/cgroup.c                           | 15 +++++-
 kernel/bpf/net_namespace.c                    |  8 +++
 kernel/bpf/syscall.c                          | 26 ++++++++++
 net/core/dev.c                                | 11 +++-
 .../bpftool/Documentation/bpftool-link.rst    |  8 +++
 tools/bpf/bpftool/bash-completion/bpftool     |  4 +-
 tools/bpf/bpftool/link.c                      | 37 +++++++++++++-
 tools/include/uapi/linux/bpf.h                |  5 ++
 tools/lib/bpf/bpf.c                           | 10 ++++
 tools/lib/bpf/bpf.h                           |  2 +
 tools/lib/bpf/libbpf.c                        |  5 ++
 tools/lib/bpf/libbpf.h                        |  1 +
 tools/lib/bpf/libbpf.map                      |  2 +
 .../selftests/bpf/prog_tests/cgroup_link.c    | 20 +++++++-
 .../selftests/bpf/prog_tests/sk_lookup.c      | 51 +++++++++----------
 .../selftests/bpf/prog_tests/xdp_link.c       | 14 +++++
 tools/testing/selftests/bpf/testing_helpers.c | 14 +++++
 tools/testing/selftests/bpf/testing_helpers.h |  3 ++
 20 files changed, 208 insertions(+), 34 deletions(-)
Signature · 1 line
2.24.1