From: Eduard Zingerman <eddyz87@gmail.com>
To: Emil Tsalapatis <emil@etsalapatis.com>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org
Subject: Re: [PATCH 1/2] bpf: Allow bpf_for/bpf_repeat calls while holding a spinlock
Date: Thu, 02 Jan 2025 10:02:49 -0800 [thread overview]
Message-ID: <ac3eda5992a9fbee296abcbc917d5521da0be83c.camel@gmail.com> (raw)
In-Reply-To: <20250101203731.1651981-2-emil@etsalapatis.com>
On Wed, 2025-01-01 at 15:37 -0500, Emil Tsalapatis wrote:
> Add the bpf_iter_num_* kfuncs called by bpf_for in special_kfunc_list,
> and allow the calls even while holding a spin lock.
>
> Signed-off-by: Emil Tsalapatis (Meta) <emil@etsalapatis.com>
> ---
Reviewed-by: Eduard Zingerman <eddyz87@gmail.com>
[...]
> @@ -19048,7 +19066,7 @@ static int do_check(struct bpf_verifier_env *env)
> if (env->cur_state->active_locks) {
> if ((insn->src_reg == BPF_REG_0 && insn->imm != BPF_FUNC_spin_unlock) ||
> (insn->src_reg == BPF_PSEUDO_KFUNC_CALL &&
> - (insn->off != 0 || !is_bpf_graph_api_kfunc(insn->imm)))) {
> + (insn->off != 0 || !kfunc_spin_allowed(insn->imm)))) {
> verbose(env, "function calls are not allowed while holding a lock\n");
> return -EINVAL;
> }
Nit: technically, 'bpf_loop' is a helper function independent of iter_num API.
I suggest to change the name to is_bpf_iter_num_api_kfunc.
Also, if we decide that loops are ok with spin locks,
the condition above should be adjusted to allow calls to bpf_loop,
e.g. to make the following test work:
--- 8< -------------------------------------
static int loop_cb(__u64 index, void *ctx)
{
return 0;
}
SEC("tc")
__success __failure_unpriv __msg_unpriv("")
__retval(0)
int bpf_loop_inside_locked_region2(void)
{
const int zero = 0;
struct val *val;
val = bpf_map_lookup_elem(&map_spin_lock, &zero);
if (!val)
return -1;
bpf_spin_lock(&val->l);
bpf_loop(10, loop_cb, NULL, 0);
bpf_spin_unlock(&val->l);
return 0;
}
------------------------------------- >8 ---
next prev parent reply other threads:[~2025-01-02 18:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-01 20:37 [PATCH 0/2] bpf: Allow bpf_for/bpf_repeat while holding spin Emil Tsalapatis
2025-01-01 20:37 ` [PATCH 1/2] bpf: Allow bpf_for/bpf_repeat calls while holding a spinlock Emil Tsalapatis
2025-01-02 18:02 ` Eduard Zingerman [this message]
2025-01-04 19:25 ` Emil Tsalapatis
2025-01-05 0:11 ` Eduard Zingerman
2025-01-06 14:56 ` Emil Tsalapatis
2025-01-06 18:59 ` Alexei Starovoitov
2025-01-01 20:37 ` [PATCH 2/2] selftests/bpf: test bpf_for within spin lock section Emil Tsalapatis
2025-01-02 18:05 ` Eduard Zingerman
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=ac3eda5992a9fbee296abcbc917d5521da0be83c.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=emil@etsalapatis.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