From: Yonghong Song <yhs@meta.com>
To: Alexei Starovoitov <ast@meta.com>, Yonghong Song <yhs@fb.com>,
bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v2 4/8] bpf: Add kfunc bpf_rcu_read_lock/unlock()
Date: Tue, 8 Nov 2022 11:09:15 -0800 [thread overview]
Message-ID: <c8cfde72-eb93-955f-0672-bb617364d6b9@meta.com> (raw)
In-Reply-To: <d5a886ba-4768-9c97-9b56-0e0d58020617@meta.com>
On 11/8/22 8:56 AM, Alexei Starovoitov wrote:
> On 11/7/22 11:41 PM, Yonghong Song wrote:
>> Add two kfunc's bpf_rcu_read_lock() and bpf_rcu_read_unlock(). These
>> two kfunc's
>> can be used for all program types. A new kfunc hook type
>> BTF_KFUNC_HOOK_GENERIC
>> is added which corresponds to prog type BPF_PROG_TYPE_UNSPEC,
>> indicating the
>> kfunc intends to be used for all prog types.
>>
>> The kfunc bpf_rcu_read_lock() is tagged with new flag KF_RCU_LOCK and
>> bpf_rcu_read_unlock() with new flag KF_RCU_UNLOCK. These two new flags
>> are used by the verifier to identify these two helpers.
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>> include/linux/bpf.h | 3 +++
>> include/linux/btf.h | 2 ++
>> kernel/bpf/btf.c | 8 ++++++++
>> kernel/bpf/helpers.c | 25 ++++++++++++++++++++++++-
>> 4 files changed, 37 insertions(+), 1 deletion(-)
>>
>> For new kfuncs, I added KF_RCU_LOCK and KF_RCU_UNLOCK flags to
>> indicate a helper could be bpf_rcu_read_lock/unlock(). This could
>> be a waste for kfunc flag space as the flag is used to identify
>> one helper. Alternatively, we might identify kfunc based on
>> btf_id. Any suggestions are welcome.
>>
>> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
>> index 5011cb50abf1..b4bbcafd1c9b 100644
>> --- a/include/linux/bpf.h
>> +++ b/include/linux/bpf.h
>> @@ -2118,6 +2118,9 @@ bool bpf_prog_has_kfunc_call(const struct
>> bpf_prog *prog);
>> const struct btf_func_model *
>> bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
>> const struct bpf_insn *insn);
>> +void bpf_rcu_read_lock(void);
>> +void bpf_rcu_read_unlock(void);
>> +
>> struct bpf_core_ctx {
>> struct bpf_verifier_log *log;
>> const struct btf *btf;
>> diff --git a/include/linux/btf.h b/include/linux/btf.h
>> index d80345fa566b..8783ca7e6079 100644
>> --- a/include/linux/btf.h
>> +++ b/include/linux/btf.h
>> @@ -51,6 +51,8 @@
>> #define KF_TRUSTED_ARGS (1 << 4) /* kfunc only takes trusted pointer
>> arguments */
>> #define KF_SLEEPABLE (1 << 5) /* kfunc may sleep */
>> #define KF_DESTRUCTIVE (1 << 6) /* kfunc performs destructive
>> actions */
>> +#define KF_RCU_LOCK (1 << 7) /* kfunc does rcu_read_lock() */
>> +#define KF_RCU_UNLOCK (1 << 8) /* kfunc does rcu_read_unlock() */
>
> Please don't use KF flags for these. It's not going to scale.
> Compare btf_id instead.
Will do. Kumar has a suggestion like:
https://lore.kernel.org/bpf/20221107230950.7117-17-memxor@gmail.com
which I will explore.
next prev parent reply other threads:[~2022-11-08 19:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 7:40 [PATCH bpf-next v2 0/8] bpf: Add bpf_rcu_read_lock() support Yonghong Song
2022-11-08 7:40 ` [PATCH bpf-next v2 1/8] compiler_types: Define __rcu as __attribute__((btf_type_tag("rcu"))) Yonghong Song
2022-11-08 7:40 ` [PATCH bpf-next v2 2/8] bpf: Refactor btf_struct_access callback interface Yonghong Song
2022-11-08 7:41 ` [PATCH bpf-next v2 3/8] bpf: Abstract out functions to check sleepable helpers Yonghong Song
2022-11-08 10:43 ` kernel test robot
2022-11-08 14:15 ` kernel test robot
2022-11-08 7:41 ` [PATCH bpf-next v2 4/8] bpf: Add kfunc bpf_rcu_read_lock/unlock() Yonghong Song
2022-11-08 16:56 ` Alexei Starovoitov
2022-11-08 19:09 ` Yonghong Song [this message]
2022-11-08 17:09 ` Kumar Kartikeya Dwivedi
2022-11-08 19:08 ` Yonghong Song
2022-11-08 7:41 ` [PATCH bpf-next v2 5/8] bpf: Add bpf_rcu_read_lock() verifier support Yonghong Song
2022-11-08 17:04 ` Kumar Kartikeya Dwivedi
2022-11-08 20:03 ` Yonghong Song
2022-11-08 20:19 ` Kumar Kartikeya Dwivedi
2022-11-08 20:40 ` Yonghong Song
2022-11-08 7:41 ` [PATCH bpf-next v2 6/8] bpf: Enable sleeptable support for cgrp local storage Yonghong Song
2022-11-08 7:41 ` [PATCH bpf-next v2 7/8] selftests/bpf: Add tests for bpf_rcu_read_lock() Yonghong Song
2022-11-08 7:41 ` [PATCH bpf-next v2 8/8] selftests/bpf: Add rcu_read_lock test to s390x deny list Yonghong Song
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=c8cfde72-eb93-955f-0672-bb617364d6b9@meta.com \
--to=yhs@meta.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=ast@meta.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox