From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH v5 bpf-next 2/3] bpf: Relax precision marking in open coded iters and may_goto loop.
Date: Thu, 06 Jun 2024 15:19:16 -0700 [thread overview]
Message-ID: <098d570be9bb15fc804355851b4b99837f18c664.camel@gmail.com> (raw)
In-Reply-To: <CAADnVQ+KFoNW-yJCa5fFmNzXjoEN4ECvPeQ1YoCeSZpyR9uO5Q@mail.gmail.com>
On Thu, 2024-06-06 at 13:02 -0700, Alexei Starovoitov wrote:
[...]
> > > + reg1->var_off = tnum_unknown;
> > > + reg2->var_off = tnum_unknown;
> > > + break;
> >
> > Just a random thought: suppose that one of the registers in question
> > is used as an index int the array of ints, and compiler increments it
> > using += 4. Would it be interesting to preserve alignment info in the
> > var_off in such case? (in other words, preserve known trailing zeros).
>
> Well, the verifier cannot figure out which register is
> an induction variable. Compiler can generate a code where
> would be multiple such registers too.
> But even if it was one rX += 4
> it's nor clear how to figure out the size of the increment.
>
> Also the above code is called at the time of comparison like "if 2 < 100".
> I figured I will try a heuristic at that time.
> See attached diff.
> It computes alignment of LHS and RHS and
> then heuristically adjusts the range.
> After spending all morning on it and various heuristics
> I'm convinced that this is a dead end.
> It cannot be made to work with i += 2 loops.
Summary of off-list discussion below.
For the following C code:
long arr1[1024];
SEC("socket")
__success
int test1(const void *ctx)
{
long i;
for (i = 0; i < 1024 && can_loop; i++)
arr1[i] = i;
return 0;
}
clang generates the following BPF code:
0000000000000340 <test1>:
104: r1 = 0x0
105: r2 = 0x0 ll
0000000000000358 <LBB28_1>:
107: may_goto +0x4 <LBB28_3>
108: *(u64 *)(r2 + 0x0) = r1
109: r2 += 0x8
110: r1 += 0x1
111: if r1 != 0x400 goto -0x5 <LBB28_1>
0000000000000380 <LBB28_3>:
112: w0 = 0x0
113: exit
Here r2 is used as an index and r1 as a counter.
Since r2 is never compared it is never widened.
Hence my point about preserving trailing zeros
for widened values is moot, as it won't really
help for real-life programs.
next prev parent reply other threads:[~2024-06-06 22:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 0:54 [PATCH v5 bpf-next 1/3] bpf: Relax tuple len requirement for sk helpers Alexei Starovoitov
2024-06-06 0:54 ` [PATCH v5 bpf-next 2/3] bpf: Relax precision marking in open coded iters and may_goto loop Alexei Starovoitov
2024-06-06 11:08 ` Eduard Zingerman
2024-06-06 20:02 ` Alexei Starovoitov
2024-06-06 22:19 ` Eduard Zingerman [this message]
2024-06-06 23:39 ` Eduard Zingerman
2024-06-07 0:28 ` Alexei Starovoitov
2024-06-06 0:54 ` [PATCH v5 bpf-next 3/3] selftests/bpf: Remove i = zero workaround and add new tests Alexei Starovoitov
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=098d570be9bb15fc804355851b4b99837f18c664.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=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