From: <thinker.li@gmail.com>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <martin.lau@linux.dev>,
<kernel-team@meta.com>, <andrii@kernel.org>,
<sinquersw@gmail.com>, <kuifeng@meta.com>, <thinker.li@gmail.com>
Subject: [PATCH bpf-next v7 4/8] bpf: export bpf_link_inc_not_zero.
Date: Wed, 29 May 2024 23:59:42 -0700 [thread overview]
Message-ID: <20240530065946.979330-5-thinker.li@gmail.com> (raw)
In-Reply-To: <20240530065946.979330-1-thinker.li@gmail.com>
From: Kui-Feng Lee <thinker.li@gmail.com>
bpf_link_inc_not_zero() will be used by kernel modules. We will use it in
bpf_testmod.c later.
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
---
include/linux/bpf.h | 6 ++++++
kernel/bpf/syscall.c | 3 ++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 5eb61120e4f5..a834f4b761bc 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2334,6 +2334,7 @@ int bpf_link_prime(struct bpf_link *link, struct bpf_link_primer *primer);
int bpf_link_settle(struct bpf_link_primer *primer);
void bpf_link_cleanup(struct bpf_link_primer *primer);
void bpf_link_inc(struct bpf_link *link);
+struct bpf_link *bpf_link_inc_not_zero(struct bpf_link *link);
void bpf_link_put(struct bpf_link *link);
int bpf_link_new_fd(struct bpf_link *link);
struct bpf_link *bpf_link_get_from_fd(u32 ufd);
@@ -2705,6 +2706,11 @@ static inline void bpf_link_inc(struct bpf_link *link)
{
}
+static inline struct bpf_link *bpf_link_inc_not_zero(struct bpf_link *link)
+{
+ return NULL;
+}
+
static inline void bpf_link_put(struct bpf_link *link)
{
}
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 81efa1944942..5070fa20d05c 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -5437,10 +5437,11 @@ static int link_detach(union bpf_attr *attr)
return ret;
}
-static struct bpf_link *bpf_link_inc_not_zero(struct bpf_link *link)
+struct bpf_link *bpf_link_inc_not_zero(struct bpf_link *link)
{
return atomic64_fetch_add_unless(&link->refcnt, 1, 0) ? link : ERR_PTR(-ENOENT);
}
+EXPORT_SYMBOL(bpf_link_inc_not_zero);
struct bpf_link *bpf_link_by_id(u32 id)
{
--
2.43.0
next prev parent reply other threads:[~2024-05-30 7:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-30 6:59 [PATCH bpf-next v7 0/8] Notify user space when a struct_ops object is detached/unregistered thinker.li
2024-05-30 6:59 ` [PATCH bpf-next v7 1/8] bpf: pass bpf_struct_ops_link to callbacks in bpf_struct_ops thinker.li
2024-05-30 6:59 ` [PATCH bpf-next v7 2/8] bpf: enable detaching links of struct_ops objects thinker.li
2024-05-30 6:59 ` [PATCH bpf-next v7 3/8] bpf: support epoll from bpf struct_ops links thinker.li
2024-05-30 6:59 ` thinker.li [this message]
2024-05-30 6:59 ` [PATCH bpf-next v7 5/8] selftests/bpf: test struct_ops with epoll thinker.li
2024-05-30 6:59 ` [PATCH bpf-next v7 6/8] selftests/bpf: detach a struct_ops link from the subsystem managing it thinker.li
2024-05-30 23:02 ` Martin KaFai Lau
2024-05-30 6:59 ` [PATCH bpf-next v7 7/8] selftests/bpf: make sure bpf_testmod handling racing link destroying well thinker.li
2024-05-30 6:59 ` [PATCH bpf-next v7 8/8] bpftool: Change pid_iter.bpf.c to comply with the change of bpf_link_fops thinker.li
2024-05-30 22:40 ` [PATCH bpf-next v7 0/8] Notify user space when a struct_ops object is detached/unregistered patchwork-bot+netdevbpf
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=20240530065946.979330-5-thinker.li@gmail.com \
--to=thinker.li@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=martin.lau@linux.dev \
--cc=sinquersw@gmail.com \
/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.