bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: Add LINK_DETACH for iter and perf links
@ 2025-08-01 12:10 Florian Lehner
  2025-08-05 21:07 ` Yonghong Song
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Lehner @ 2025-08-01 12:10 UTC (permalink / raw)
  To: bpf
  Cc: yonghong.song, ast, daniel, andrii, martin.lau, eddyz87, song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, davem, kuba, hawk,
	netdev, Florian Lehner

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@der-flo.net>
---
 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,
 	.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,
 	.dealloc = bpf_perf_link_dealloc,
 	.fill_link_info = bpf_perf_link_fill_link_info,
 	.show_fdinfo = bpf_perf_link_show_fdinfo,
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-08-06 20:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-01 12:10 [PATCH bpf-next] bpf: Add LINK_DETACH for iter and perf links Florian Lehner
2025-08-05 21:07 ` Yonghong Song
2025-08-06 18:38   ` Florian Lehner
2025-08-06 18:44     ` Yonghong Song
2025-08-06 20:35     ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).