BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	martin.lau@kernel.org, kernel-team@meta.com
Subject: Re: [PATCH v3 bpf-next 00/10] Complete BPF verifier precision tracking support for register spills
Date: Mon, 4 Dec 2023 15:02:25 -0800	[thread overview]
Message-ID: <7de7f58a-5d98-4a72-892b-368559fdc581@linux.dev> (raw)
In-Reply-To: <CAEf4BzaqWDNUyWzwSM6ZyZXcVuE10HZ6ryaZQ05wPY-0spb+aw@mail.gmail.com>


On 12/4/23 5:32 PM, Andrii Nakryiko wrote:
> On Mon, Dec 4, 2023 at 11:26 AM Andrii Nakryiko <andrii@kernel.org> wrote:
>> Add support to BPF verifier to track and support register spill/fill to/from
>> stack regardless if it was done through read-only R10 register (which is the
>> only form supported today), or through a general register after copying R10
>> into it, while also potentially modifying offset.
>>
>> Once we add register this generic spill/fill support to precision
>> backtracking, we can take advantage of it to stop doing eager STACK_ZERO
>> conversion on register spill. Instead we can rely on (im)precision of spilled
>> const zero register to improve verifier state pruning efficiency. This
>> situation of using const zero register to initialize stack slots is very
>> common with __builtin_memset() usage or just zero-initializing variables on
>> the stack, and it causes unnecessary state duplication, as that STACK_ZERO
>> knowledge is often not necessary for correctness, as those zero values are
>> never used in precise context. Thus, relying on register imprecision helps
>> tremendously, especially in real-world BPF programs.
>>
>> To make spilled const zero register behave completely equivalently to
>> STACK_ZERO, we need to improve few other small pieces, which is done in the
>> second part of the patch set. See individual patches for details. There are
>> also two small bug fixes spotted during STACK_ZERO debugging.
>>
>> The patch set consists of logically three changes:
>>    - patch #1 (and corresponding tests in patch #2) is fixing/impoving precision
>>      propagation for stack spills/fills. This can be landed as a stand-alone
>>      improvement;
>>    - patches #3 through #9 is improving verification scalability by utilizing
>>      register (im)precision instead of eager STACK_ZERO. These changes depend
>>      on patch #1.
>>    - patch #10 is a memory efficiency improvement to how instruction/jump
>>      history is tracked and maintained. It depends on patch #1, but is not
>>      strictly speaking required, even though I believe it's a good long-term
>>      solution to have a path-dependent per-instruction information. Kind
>>      of like a path-dependent counterpart to path-agnostic insn_aux array.
>>
>> v2->v3:
>>    - BPF_ST instruction workaround (Eduard);
> ok, so I fixed this in the main partial_stack_load_preserves_zeros
> test, but there is at least spill_subregs_preserve_stack_zero that
> needs fixing as well. I'll audit all the tests thoroughly and will fix
> all BPF_ST uses.
>
> Eduard or Yonghong, what's the Clang version that does support BPF_ST
> instructions in inline asm? When would we be able to just assume those
> instructions are supported?

For inline asm, llvm18.
For C->asm codegen, llvm18 + cpu=v4.

[...]


  reply	other threads:[~2023-12-04 23:02 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04 19:25 [PATCH v3 bpf-next 00/10] Complete BPF verifier precision tracking support for register spills Andrii Nakryiko
2023-12-04 19:25 ` [PATCH v3 bpf-next 01/10] bpf: support non-r10 register spill/fill to/from stack in precision tracking Andrii Nakryiko
2023-12-04 19:25 ` [PATCH v3 bpf-next 02/10] selftests/bpf: add stack access precision test Andrii Nakryiko
2023-12-04 19:25 ` [PATCH v3 bpf-next 03/10] bpf: fix check for attempt to corrupt spilled pointer Andrii Nakryiko
2023-12-04 22:12   ` Eduard Zingerman
2023-12-04 22:15     ` Eduard Zingerman
2023-12-05  0:23     ` Andrii Nakryiko
2023-12-05  0:54       ` Eduard Zingerman
2023-12-05  3:56         ` Andrii Nakryiko
2023-12-05 13:34           ` Eduard Zingerman
2023-12-05 18:30             ` Andrii Nakryiko
2023-12-05 18:49               ` Eduard Zingerman
2023-12-05 18:55                 ` Andrii Nakryiko
2023-12-05  1:45       ` Alexei Starovoitov
2023-12-05  3:50         ` Andrii Nakryiko
2023-12-04 19:25 ` [PATCH v3 bpf-next 04/10] bpf: preserve STACK_ZERO slots on partial reg spills Andrii Nakryiko
2023-12-04 19:25 ` [PATCH v3 bpf-next 05/10] selftests/bpf: validate STACK_ZERO is preserved on subreg spill Andrii Nakryiko
2023-12-04 19:25 ` [PATCH v3 bpf-next 06/10] bpf: preserve constant zero when doing partial register restore Andrii Nakryiko
2023-12-04 19:25 ` [PATCH v3 bpf-next 07/10] selftests/bpf: validate zero preservation for sub-slot loads Andrii Nakryiko
2023-12-04 19:25 ` [PATCH v3 bpf-next 08/10] bpf: track aligned STACK_ZERO cases as imprecise spilled registers Andrii Nakryiko
2023-12-04 19:26 ` [PATCH v3 bpf-next 09/10] selftests/bpf: validate precision logic in partial_stack_load_preserves_zeros Andrii Nakryiko
2023-12-04 19:26 ` [PATCH v3 bpf-next 10/10] bpf: use common instruction history across all states Andrii Nakryiko
2023-12-04 22:32 ` [PATCH v3 bpf-next 00/10] Complete BPF verifier precision tracking support for register spills Andrii Nakryiko
2023-12-04 23:02   ` Yonghong Song [this message]
2023-12-04 23:52     ` Andrii Nakryiko

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=7de7f58a-5d98-4a72-892b-368559fdc581@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii.nakryiko@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