From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Cc: daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org,
memxor@gmail.com, john.fastabend@gmail.com, kernel-team@fb.com
Subject: Re: [PATCH v6 bpf-next 1/4] bpf: Introduce may_goto instruction
Date: Wed, 06 Mar 2024 15:12:05 +0200 [thread overview]
Message-ID: <d7b7dd3eab10ff5b57799e16b95ef1a45c90285a.camel@gmail.com> (raw)
In-Reply-To: <20240306031929.42666-2-alexei.starovoitov@gmail.com>
On Tue, 2024-03-05 at 19:19 -0800, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
[...]
> JCOND stands for conditional pseudo jump.
> Since goto_or_nop insn was proposed, it may use the same opcode.
> may_goto vs goto_or_nop can be distinguished by src_reg:
> code = BPF_JMP | BPF_JCOND
> src_reg = 0 - may_goto
> src_reg = 1 - goto_or_nop
>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
[...]
> @@ -14871,11 +14882,36 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
> int err;
>
> /* Only conditional jumps are expected to reach here. */
> - if (opcode == BPF_JA || opcode > BPF_JSLE) {
> + if (opcode == BPF_JA || opcode > BPF_JCOND) {
> verbose(env, "invalid BPF_JMP/JMP32 opcode %x\n", opcode);
> return -EINVAL;
> }
>
> + if (opcode == BPF_JCOND) {
> + struct bpf_verifier_state *cur_st = env->cur_state, *queued_st, *prev_st;
> + int idx = *insn_idx;
> +
> + if (insn->code != (BPF_JMP | BPF_JCOND) ||
> + insn->src_reg != BPF_MAY_GOTO ||
> + insn->dst_reg || insn->imm || insn->off == 0) {
> + verbose(env, "invalid may_goto off %d imm %d\n",
> + insn->off, insn->imm);
> + return -EINVAL;
> + }
> + prev_st = find_prev_entry(env, cur_st->parent, idx);
> +
> + /* branch out 'fallthrough' insn as a new state to explore */
> + queued_st = push_stack(env, idx + 1, idx, false);
> + if (!queued_st)
> + return -ENOMEM;
> +
> + queued_st->may_goto_depth++;
> + if (prev_st)
> + widen_imprecise_scalars(env, prev_st, queued_st);
> + *insn_idx += insn->off;
> + return 0;
> + }
Nit: for other conditional jumps the fallthrough branch is explored first,
I tried the following and the tests keep passing:
@@ -14901,14 +14901,13 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
prev_st = find_prev_entry(env, cur_st->parent, idx);
/* branch out 'fallthrough' insn as a new state to explore */
- queued_st = push_stack(env, idx + 1, idx, false);
+ queued_st = push_stack(env, idx + insn->off + 1, idx, false);
if (!queued_st)
return -ENOMEM;
- queued_st->may_goto_depth++;
+ cur_st->may_goto_depth++;
if (prev_st)
- widen_imprecise_scalars(env, prev_st, queued_st);
- *insn_idx += insn->off;
+ widen_imprecise_scalars(env, prev_st, cur_st);
return 0;
}
Maybe this is a property worth preserving, wdyt?
[...]
next prev parent reply other threads:[~2024-03-06 13:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-06 3:19 [PATCH v6 bpf-next 0/4] bpf: Introduce may_goto and cond_break Alexei Starovoitov
2024-03-06 3:19 ` [PATCH v6 bpf-next 1/4] bpf: Introduce may_goto instruction Alexei Starovoitov
2024-03-06 13:12 ` Eduard Zingerman [this message]
2024-03-06 16:40 ` Alexei Starovoitov
2024-03-06 18:33 ` Andrii Nakryiko
2024-03-06 18:38 ` Alexei Starovoitov
2024-03-06 3:19 ` [PATCH v6 bpf-next 2/4] bpf: Recognize that two registers are safe when their ranges match Alexei Starovoitov
2024-03-06 13:07 ` Eduard Zingerman
2024-03-06 3:19 ` [PATCH v6 bpf-next 3/4] bpf: Add cond_break macro Alexei Starovoitov
2024-03-06 13:26 ` Eduard Zingerman
2024-03-06 16:51 ` Alexei Starovoitov
2024-03-06 3:19 ` [PATCH v6 bpf-next 4/4] selftests/bpf: Test may_goto Alexei Starovoitov
2024-03-06 18:50 ` [PATCH v6 bpf-next 0/4] bpf: Introduce may_goto and cond_break patchwork-bot+netdevbpf
2024-03-06 19:15 ` John Fastabend
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=d7b7dd3eab10ff5b57799e16b95ef1a45c90285a.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=memxor@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox