* [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
* Re: [PATCH bpf-next] bpf: Add LINK_DETACH for iter and perf links
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
0 siblings, 1 reply; 5+ messages in thread
From: Yonghong Song @ 2025-08-05 21:07 UTC (permalink / raw)
To: Florian Lehner, bpf
Cc: ast, daniel, andrii, martin.lau, eddyz87, song, john.fastabend,
kpsingh, sdf, haoluo, jolsa, davem, kuba, hawk, netdev
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@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,
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,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: Add LINK_DETACH for iter and perf links
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
0 siblings, 2 replies; 5+ messages in thread
From: Florian Lehner @ 2025-08-06 18:38 UTC (permalink / raw)
To: Yonghong Song
Cc: bpf, ast, daniel, andrii, martin.lau, eddyz87, song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, davem, kuba, hawk,
netdev
On Tue, Aug 05, 2025 at 02:07:20PM -0700, Yonghong Song wrote:
>
>
> 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.
[..]
> > 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?
>
A key reason for adding this was to enable the temporary disabling and re-enabling of
an attached BPF program while keeping the same bpf_iter flavor. If you don't think
this is a strong enough use case, I'm open to removing this from the patch.
> > 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.
>
The primary use case for this feature is to allow for the temporary disabling of
uprobes that are attached using bpf_perf_links.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: Add LINK_DETACH for iter and perf links
2025-08-06 18:38 ` Florian Lehner
@ 2025-08-06 18:44 ` Yonghong Song
2025-08-06 20:35 ` Alexei Starovoitov
1 sibling, 0 replies; 5+ messages in thread
From: Yonghong Song @ 2025-08-06 18:44 UTC (permalink / raw)
To: Florian Lehner
Cc: bpf, ast, daniel, andrii, martin.lau, eddyz87, song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, davem, kuba, hawk,
netdev
On 8/6/25 11:38 AM, Florian Lehner wrote:
> On Tue, Aug 05, 2025 at 02:07:20PM -0700, Yonghong Song wrote:
>>
>> 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.
> [..]
>>> 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?
>>
> A key reason for adding this was to enable the temporary disabling and re-enabling of
> an attached BPF program while keeping the same bpf_iter flavor. If you don't think
> this is a strong enough use case, I'm open to removing this from the patch.
>
>>> 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.
>>
> The primary use case for this feature is to allow for the temporary disabling of
> uprobes that are attached using bpf_perf_links.
Okay, you patch looks good to me.
Acked-by: Yonghong Song <yonghong.song@linux.dev>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: Add LINK_DETACH for iter and perf links
2025-08-06 18:38 ` Florian Lehner
2025-08-06 18:44 ` Yonghong Song
@ 2025-08-06 20:35 ` Alexei Starovoitov
1 sibling, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2025-08-06 20:35 UTC (permalink / raw)
To: Florian Lehner
Cc: Yonghong Song, bpf, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard, Song Liu,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer,
Network Development
On Wed, Aug 6, 2025 at 11:39 AM Florian Lehner <dev@der-flo.net> wrote:
>
> On Tue, Aug 05, 2025 at 02:07:20PM -0700, Yonghong Song wrote:
> >
> >
> > 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.
> [..]
> > > 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?
> >
>
> A key reason for adding this was to enable the temporary disabling and re-enabling of
> an attached BPF program while keeping the same bpf_iter flavor. If you don't think
> this is a strong enough use case, I'm open to removing this from the patch.
>
> > > 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.
> >
>
> The primary use case for this feature is to allow for the temporary disabling of
> uprobes that are attached using bpf_perf_links.
I guess the use case makes sense, but pls provide
corresponding libbpf and selftest that demonstrates such usage.
--
pw-bot: cr
^ permalink raw reply [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).