Re: [PATCH bpf-next] bpf: Add LINK_DETACH for iter and perf links

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 8/1/25 5:10 AM, Florian Lehner wrote:
73b11c2a introduced LINK_DETACH and implemented it for some link types,
like xdp, netns and others.

This patch implements LINK_DETACH for perf and iter links, re-using
existing link release handling code.

Signed-off-by: Florian Lehner <dev@xxxxxxxxxxx>
---
  kernel/bpf/bpf_iter.c | 7 +++++++
  kernel/bpf/syscall.c  | 7 +++++++
  2 files changed, 14 insertions(+)

diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
index 0cbcae727079..823dad09735d 100644
--- a/kernel/bpf/bpf_iter.c
+++ b/kernel/bpf/bpf_iter.c
@@ -397,6 +397,12 @@ static void bpf_iter_link_release(struct bpf_link *link)
  		iter_link->tinfo->reg_info->detach_target(&iter_link->aux);
  }
+static int bpf_iter_link_detach(struct bpf_link *link)
+{
+	bpf_iter_link_release(link);
+	return 0;
+}
+
  static void bpf_iter_link_dealloc(struct bpf_link *link)
  {
  	struct bpf_iter_link *iter_link =
@@ -490,6 +496,7 @@ static int bpf_iter_link_fill_link_info(const struct bpf_link *link,
static const struct bpf_link_ops bpf_iter_link_lops = {
  	.release = bpf_iter_link_release,
+	.detach = bpf_iter_link_detach,

Not sure how useful for this one. For bpf_iter programs,
the loaded prog will expect certain bpt_iter (e.g., bpf_map_elem, bpf_map, ...).
So even if you have detach, you won't be able to attach to a different
bpf_iter flavor.

Do you have a use case for this one?

  	.dealloc = bpf_iter_link_dealloc,
  	.update_prog = bpf_iter_link_replace,
  	.show_fdinfo = bpf_iter_link_show_fdinfo,
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index e63039817af3..e89694f6874a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3733,6 +3733,12 @@ static void bpf_perf_link_release(struct bpf_link *link)
  	fput(perf_link->perf_file);
  }
+static int bpf_perf_link_detach(struct bpf_link *link)
+{
+	bpf_perf_link_release(link);
+	return 0;
+}
+
  static void bpf_perf_link_dealloc(struct bpf_link *link)
  {
  	struct bpf_perf_link *perf_link = container_of(link, struct bpf_perf_link, link);
@@ -4027,6 +4033,7 @@ static void bpf_perf_link_show_fdinfo(const struct bpf_link *link,
static const struct bpf_link_ops bpf_perf_link_lops = {
  	.release = bpf_perf_link_release,
+	.detach = bpf_perf_link_detach,

This one may be possible. You might be able to e.g., try a different bpf_cookie, or
different perf event.

  	.dealloc = bpf_perf_link_dealloc,
  	.fill_link_info = bpf_perf_link_fill_link_info,
  	.show_fdinfo = bpf_perf_link_show_fdinfo,





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux