BPF List
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Brendan Jackman <jackmanb@google.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <kafai@fb.com>, bpf <bpf@vger.kernel.org>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH v2 bpf] bpf: Account for BPF_FETCH in insn_has_def32()
Date: Mon, 01 Mar 2021 14:26:13 +0100	[thread overview]
Message-ID: <aabc55351862d0c1ea2ade0bedb3412ff0c6633e.camel@linux.ibm.com> (raw)
In-Reply-To: <CA+i-1C1DxO+dvmCRWTLhD-XUiCFji=r7LwSgb7yHC5iLneLk9w@mail.gmail.com>

On Mon, 2021-03-01 at 12:02 +0100, Brendan Jackman wrote:
> On Fri, 26 Feb 2021 at 22:31, Ilya Leoshkevich <iii@linux.ibm.com>
> wrote:

[...]

> > @@ -11006,9 +11026,10 @@ static int
> > opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env,
> >         for (i = 0; i < len; i++) {
> >                 int adj_idx = i + delta;
> >                 struct bpf_insn insn;
> > -               u8 load_reg;
> > +               int load_reg;
> > 
> >                 insn = insns[adj_idx];
> > +               load_reg = insn_def_regno(&insn);
> 
> Nit: Might as well save a line by squashing this into the
> declaration.

Will do.

[...]

> > @@ -11049,22 +11070,9 @@ static int
> > opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env,
> >                 if (!bpf_jit_needs_zext())
> >                         continue;
> > 
> > -               /* zext_dst means that we want to zero-extend
> > whatever register
> > -                * the insn defines, which is dst_reg most of the
> > time, with
> > -                * the notable exception of BPF_STX + BPF_ATOMIC +
> > BPF_FETCH.
> > -                */
> > -               if (BPF_CLASS(insn.code) == BPF_STX &&
> > -                   BPF_MODE(insn.code) == BPF_ATOMIC) {
> > -                       /* BPF_STX + BPF_ATOMIC insns without
> > BPF_FETCH do not
> > -                        * define any registers, therefore zext_dst
> > cannot be
> > -                        * set.
> > -                        */
> > -                       if (WARN_ON(!(insn.imm & BPF_FETCH)))
> > -                               return -EINVAL;
> > -                       load_reg = insn.imm == BPF_CMPXCHG ?
> > BPF_REG_0
> > -                                                          :
> > insn.src_reg;
> > -               } else {
> > -                       load_reg = insn.dst_reg;
> > +               if (WARN_ON_ONCE(load_reg == -1)) {
> > +                       verbose(env, "zext_dst is set, but no reg
> > is defined\n");
> 
> Let's add the string "verifier bug." to the beginning of this message
> (this is done elsewhere too). Hopefully the only person that ever
> sees
> this message would be someone who's hacking on the verifier, but even
> for them it could be a significant time-saver.

OK.

[...]

> Overall LGTM, thanks. It seems like without this patch, the cmpxchg
> test I added in [1] should fail on the s390 JIT, and this patch
> should
> fix it. Is that correct? If so could you add the test to this patch?
> (I guess you ought to paste in my Signed-off-by)
> 
> [1]  
> https://lore.kernel.org/bpf/44d680a0c40fc9dddf1b2bf4e78bd75b76dc4061.camel@linux.ibm.com/T/#mf6546406db03c6ca473a29cdf3bde7ddeeedf1a1

For this to work, my implementation of atomics needs to be merged
(and I haven't posted it yet). I propose to keep your tests in your
patch, merge this commit first, then your zext patch with tests, then
my atomics patch.


      reply	other threads:[~2021-03-01 13:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-26 21:31 [PATCH v2 bpf] bpf: Account for BPF_FETCH in insn_has_def32() Ilya Leoshkevich
2021-03-01  5:38 ` Martin KaFai Lau
2021-03-01 11:02 ` Brendan Jackman
2021-03-01 13:26   ` Ilya Leoshkevich [this message]

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=aabc55351862d0c1ea2ade0bedb3412ff0c6633e.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=jackmanb@google.com \
    --cc=kafai@fb.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