From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
martin.lau@kernel.org
Cc: kernel-team@meta.com
Subject: Re: [PATCH bpf-next 1/7] bpf: use common jump (instruction) history across all states
Date: Thu, 09 Nov 2023 17:20:10 +0200 [thread overview]
Message-ID: <43f0d9f7219b74bfaff14b6496902f1056847de7.camel@gmail.com> (raw)
In-Reply-To: <20231031050324.1107444-2-andrii@kernel.org>
On Mon, 2023-10-30 at 22:03 -0700, Andrii Nakryiko wrote:
> Instead of allocating and copying jump history each time we enqueue
> child verifier state, switch to a model where we use one common
> dynamically sized array of instruction jumps across all states.
>
> The key observation for proving this is correct is that jmp_history is
> only relevant while state is active, which means it either is a current
> state (and thus we are actively modifying jump history and no other
> state can interfere with us) or we are checkpointed state with some
> children still active (either enqueued or being current).
>
> In the latter case our portion of jump history is finalized and won't
> change or grow, so as long as we keep it immutable until the state is
> finalized, we are good.
>
> Now, when state is finalized and is put into state hash for potentially
> future pruning lookups, jump history is not used anymore. This is
> because jump history is only used by precision marking logic, and we
> never modify precision markings for finalized states.
>
> So, instead of each state having its own small jump history, we keep
> a global dynamically-sized jump history, where each state in current DFS
> path from root to active state remembers its portion of jump history.
> Current state can append to this history, but cannot modify any of its
> parent histories.
>
> Because the jmp_history array can be grown through realloc, states don't
> keep pointers, they instead maintain two indexes [start, end) into
> global jump history array. End is exclusive index, so start == end means
> there is no relevant jump history.
>
> This should eliminate a lot of allocations and minimize overall memory
> usage (but I haven't benchmarked on real hardware, and QEMU benchmarking
> is too noisy).
>
> Also, in the next patch we'll extend jump history to maintain additional
> markings for some instructions even if there was no jump, so in
> preparation for that call this thing a more generic "instruction history".
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Nitpick: could you please add a comment somewhere in the code
(is_state_visited? pop_stack?) saying something like this:
states in the env->head happen to be sorted by insn_hist_end in
descending order, so popping next state for verification poses no
risk of overwriting history relevant for states remaining in
env->head.
Side note: this change would make it harder to change states traversal
order to something other than DFS, should we chose to do so.
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
[...]
next prev parent reply other threads:[~2023-11-09 15:20 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-31 5:03 [PATCH bpf-next 0/7] Complete BPF verifier precision tracking support for register spills Andrii Nakryiko
2023-10-31 5:03 ` [PATCH bpf-next 1/7] bpf: use common jump (instruction) history across all states Andrii Nakryiko
2023-11-09 15:20 ` Eduard Zingerman [this message]
2023-11-09 16:13 ` Alexei Starovoitov
2023-11-09 17:28 ` Andrii Nakryiko
2023-11-09 19:29 ` Alexei Starovoitov
2023-11-09 19:49 ` Andrii Nakryiko
2023-11-09 20:39 ` Andrii Nakryiko
2023-11-09 22:05 ` Alexei Starovoitov
2023-11-09 22:57 ` Andrii Nakryiko
2023-11-11 4:29 ` Andrii Nakryiko
2023-10-31 5:03 ` [PATCH bpf-next 2/7] bpf: support non-r10 register spill/fill to/from stack in precision tracking Andrii Nakryiko
2023-11-09 15:20 ` Eduard Zingerman
2023-11-09 17:20 ` Andrii Nakryiko
2023-11-09 18:20 ` Eduard Zingerman
2023-11-10 5:48 ` Andrii Nakryiko
2023-11-12 1:57 ` Andrii Nakryiko
2023-11-12 14:05 ` Eduard Zingerman
2023-10-31 5:03 ` [PATCH bpf-next 3/7] bpf: enforce precision for r0 on callback return Andrii Nakryiko
2023-11-09 15:20 ` Eduard Zingerman
2023-11-09 17:32 ` Andrii Nakryiko
2023-11-09 17:38 ` Eduard Zingerman
2023-11-09 17:50 ` Andrii Nakryiko
2023-11-09 17:58 ` Alexei Starovoitov
2023-11-09 18:01 ` Andrii Nakryiko
2023-11-09 18:03 ` Eduard Zingerman
2023-11-09 18:00 ` Eduard Zingerman
2023-10-31 5:03 ` [PATCH bpf-next 4/7] bpf: fix check for attempt to corrupt spilled pointer Andrii Nakryiko
2023-11-09 15:20 ` Eduard Zingerman
2023-10-31 5:03 ` [PATCH bpf-next 5/7] bpf: preserve STACK_ZERO slots on partial reg spills Andrii Nakryiko
2023-11-09 15:20 ` Eduard Zingerman
2023-11-09 17:37 ` Andrii Nakryiko
2023-11-09 17:54 ` Eduard Zingerman
2023-10-31 5:03 ` [PATCH bpf-next 6/7] bpf: preserve constant zero when doing partial register restore Andrii Nakryiko
2023-11-09 15:20 ` Eduard Zingerman
2023-11-09 17:41 ` Andrii Nakryiko
2023-11-09 19:34 ` Eduard Zingerman
2023-10-31 5:03 ` [PATCH bpf-next 7/7] bpf: track aligned STACK_ZERO cases as imprecise spilled registers Andrii Nakryiko
2023-10-31 5:22 ` Andrii Nakryiko
2023-11-01 7:56 ` Jiri Olsa
2023-11-01 16:27 ` Andrii Nakryiko
2023-11-02 9:54 ` Jiri Olsa
2023-11-09 15:21 ` Eduard Zingerman
2023-11-09 17:43 ` Andrii Nakryiko
2023-11-09 17:44 ` 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=43f0d9f7219b74bfaff14b6496902f1056847de7.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=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
/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