Skip to content

Commit 7975fde

Browse files
florianltheihor
authored andcommitted
bpf: Add LINK_DETACH for iter and perf links
73b11c2 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 <[email protected]>
1 parent ed19bc9 commit 7975fde

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

kernel/bpf/bpf_iter.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ static void bpf_iter_link_release(struct bpf_link *link)
397397
iter_link->tinfo->reg_info->detach_target(&iter_link->aux);
398398
}
399399

400+
static int bpf_iter_link_detach(struct bpf_link *link)
401+
{
402+
bpf_iter_link_release(link);
403+
return 0;
404+
}
405+
400406
static void bpf_iter_link_dealloc(struct bpf_link *link)
401407
{
402408
struct bpf_iter_link *iter_link =
@@ -490,6 +496,7 @@ static int bpf_iter_link_fill_link_info(const struct bpf_link *link,
490496

491497
static const struct bpf_link_ops bpf_iter_link_lops = {
492498
.release = bpf_iter_link_release,
499+
.detach = bpf_iter_link_detach,
493500
.dealloc = bpf_iter_link_dealloc,
494501
.update_prog = bpf_iter_link_replace,
495502
.show_fdinfo = bpf_iter_link_show_fdinfo,

kernel/bpf/syscall.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,6 +3740,12 @@ static void bpf_perf_link_release(struct bpf_link *link)
37403740
fput(perf_link->perf_file);
37413741
}
37423742

3743+
static int bpf_perf_link_detach(struct bpf_link *link)
3744+
{
3745+
bpf_perf_link_release(link);
3746+
return 0;
3747+
}
3748+
37433749
static void bpf_perf_link_dealloc(struct bpf_link *link)
37443750
{
37453751
struct bpf_perf_link *perf_link = container_of(link, struct bpf_perf_link, link);
@@ -4034,6 +4040,7 @@ static void bpf_perf_link_show_fdinfo(const struct bpf_link *link,
40344040

40354041
static const struct bpf_link_ops bpf_perf_link_lops = {
40364042
.release = bpf_perf_link_release,
4043+
.detach = bpf_perf_link_detach,
40374044
.dealloc = bpf_perf_link_dealloc,
40384045
.fill_link_info = bpf_perf_link_fill_link_info,
40394046
.show_fdinfo = bpf_perf_link_show_fdinfo,

0 commit comments

Comments
 (0)