From: Justin Suess <utilityemal77@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com
Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, bpf@vger.kernel.org, mic@digikod.net,
Justin Suess <utilityemal77@gmail.com>
Subject: [PATCH bpf-next v3 1/2] bpf: Implement dtor for struct file BTF ID
Date: Fri, 24 Apr 2026 15:22:51 -0400 [thread overview]
Message-ID: <20260424192252.695240-2-utilityemal77@gmail.com> (raw)
In-Reply-To: <20260424192252.695240-1-utilityemal77@gmail.com>
Implement a destructor for struct file allowing it to be stored in a map
as a referenced kptr.
This dtor is analogous to bpf_put_file, and calls fput to release the
reference.
Acked-by: Song Liu <song@kernel.org>
Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Justin Suess <utilityemal77@gmail.com>
---
Changes in v3:
- None
Changes in v2:
- None
kernel/bpf/helpers.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index baa12b24bb64..4739e2bf0f31 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -20,6 +20,7 @@
#include <linux/proc_ns.h>
#include <linux/sched/task.h>
#include <linux/security.h>
+#include <linux/fs.h>
#include <linux/btf_ids.h>
#include <linux/bpf_mem_alloc.h>
#include <linux/kasan.h>
@@ -2752,6 +2753,13 @@ __bpf_kfunc void bpf_task_release_dtor(void *p)
}
CFI_NOSEAL(bpf_task_release_dtor);
+__bpf_kfunc void bpf_file_release_dtor(void *file)
+{
+ fput((struct file *)file);
+}
+
+CFI_NOSEAL(bpf_file_release_dtor);
+
#ifdef CONFIG_CGROUPS
/**
* bpf_cgroup_acquire - Acquire a reference to a cgroup. A cgroup acquired by
@@ -4763,6 +4771,8 @@ static const struct btf_kfunc_id_set generic_kfunc_set = {
BTF_ID_LIST(generic_dtor_ids)
BTF_ID(struct, task_struct)
BTF_ID(func, bpf_task_release_dtor)
+BTF_ID(struct, file)
+BTF_ID(func, bpf_file_release_dtor)
#ifdef CONFIG_CGROUPS
BTF_ID(struct, cgroup)
BTF_ID(func, bpf_cgroup_release_dtor)
@@ -4874,11 +4884,15 @@ static int __init kfunc_init(void)
.btf_id = generic_dtor_ids[0],
.kfunc_btf_id = generic_dtor_ids[1]
},
-#ifdef CONFIG_CGROUPS
{
.btf_id = generic_dtor_ids[2],
.kfunc_btf_id = generic_dtor_ids[3]
},
+#ifdef CONFIG_CGROUPS
+ {
+ .btf_id = generic_dtor_ids[4],
+ .kfunc_btf_id = generic_dtor_ids[5]
+ },
#endif
};
--
2.53.0
next prev parent reply other threads:[~2026-04-24 19:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 19:22 [PATCH bpf-next v3 0/2] Allow storing referenced struct file kptrs in BPF maps Justin Suess
2026-04-24 19:22 ` Justin Suess [this message]
2026-04-24 19:52 ` [PATCH bpf-next v3 1/2] bpf: Implement dtor for struct file BTF ID bot+bpf-ci
2026-04-24 19:59 ` sashiko-bot
2026-04-24 20:12 ` Justin Suess
2026-04-24 22:05 ` Alexei Starovoitov
2026-04-24 23:20 ` Justin Suess
2026-04-25 1:25 ` Alexei Starovoitov
2026-04-25 2:17 ` Justin Suess
2026-04-24 19:22 ` [PATCH bpf-next v3 2/2] selftests/bpf: Add test for map-stored struct file kptrs Justin Suess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260424192252.695240-2-utilityemal77@gmail.com \
--to=utilityemal77@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jolsa@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mic@digikod.net \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.