All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: Yonghong Song <yhs@fb.com>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Jesper Dangaard Brouer <brouer@redhat.com>
Subject: Re: [PATCH bpf-next 1/2] bpf: fix a verifier failure with xor
Date: Wed, 2 Sep 2020 14:40:02 -0700	[thread overview]
Message-ID: <20200902214002.ciczljw7wrbznper@ast-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <871rjki5nw.fsf@toke.dk>

On Wed, Sep 02, 2020 at 05:01:39PM +0200, Toke Høiland-Jørgensen wrote:
> Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:
> 
> > On Wed, Sep 02, 2020 at 11:33:09AM +0200, Toke Høiland-Jørgensen wrote:
> >> Yonghong Song <yhs@fb.com> writes:
> >> 
> >> > On 9/1/20 1:07 PM, Andrii Nakryiko wrote:
> >> >> On Mon, Aug 24, 2020 at 11:47 PM Yonghong Song <yhs@fb.com> wrote:
> >> >>>
> >> >>> bpf selftest test_progs/test_sk_assign failed with llvm 11 and llvm 12.
> >> >>> Compared to llvm 10, llvm 11 and 12 generates xor instruction which
> >> >> 
> >> >> Does this mean that some perfectly working BPF programs will now fail
> >> >> to verify on older kernels, if compiled with llvm 11 or llvm 12? If
> >> >
> >> > Right.
> >> >
> >> >> yes, is there something that one can do to prevent Clang from using
> >> >> xor in such situations?
> >> >
> >> > The xor is generated by the combination of llvm simplifyCFG and 
> >> > instrCombine phase.
> >> >
> >> > The following is a hack to prevent compiler from generating xor's.
> >> 
> >> Wait, so this means that we can no longer tell people to just use the
> >> newest LLVM version - now we have to keep track of a minimum *and*
> >> maximum LLVM version for each kernel version?
> >
> > No. The only way is forward. Everyone has to upgrade their llvm periodically.
> 
> Right, great! But surely that implies that a regression such as that
> described here, where a new LLVM version turns a previously-valid
> program into one that no longer verifies is a bug, no?

It's not a regression. Previous valid _compiled_ programs will load.
Nothing guarantees that recompiled program will keep loading.
Even if you keep compiler and source code constant the environment could change.
That risk always existed in libbcc and in anything that compiles on the fly.
A new version of bpftrace may suddenly start failing existing bpftrace scripts.
No one wants this, of course, but we cannot guarantee 100%.

> 
> >> Could we maybe try to not *keep* making it harder for people to use BPF? :/
> >
> > Whom do you mean by "we" ?
> 
> I mean "we as a community who would like BPF to be as useful as possible
> to as many people as possible". Usability is a big part of this.

Of course. I completely agree, but your previous statement said
that somebody "is making it harder for people to use BPF"...
and I asked whom did you point finger at.
Sounds like you're saying that you are not a compiler person,
so it's not your fault and some compiler person must be responsible?
Well, we are all in the same boat and all are responsible for the outcome.

> 
> >> As for the patch, sure, make the verifier smarter, but I also feel like
> >> LLVM should be fixed to not suddenly emit such xor instructions...
> >
> > I don't think there is anything to be "fixed". It's not a bug form
> > llvm developers point of view. At least I suspect that's the response
> > you will get if you post the same sentence on llvm-dev mailing list.
> > If you care to help, please bisect which llvm commit introduced this
> > change. May be author (whoever that was) will have ideas how to
> > pessimize it specifically for bpf backend. But I suspect they will
> > refuse to do so. The discussion about partial disable of optimizations
> > was brought up several times. tldr optimizations cannot be disabled
> > effectively. Pretty much all of them may cause trouble for the
> > verifier and all of them are often necessary for the verifier as well.
> > Please read this thread:
> > http://clang-developers.42468.n3.nabble.com/Disable-certain-llvm-optimizations-at-clang-frontend-tp4068601.html
> 
> I am not enough of a compiler person to get the nuances of that
> discussion, but it seems that the last message[0] by Y Song seems to
> imply that you guys do want to fix such issues in LLVM, just not by
> disabling the optimisation, but at a later stage in the processing
> pipeline?

Not really. The "fix such issues in LLVM" statement is missing the point.
There is no _issue_ in LLVM and there is no _issue_ in the verifier.
The word "fix" assigns the blame and implies a bug.
The verifier is getting smarter. LLVM is getting smarter, but they
follow different religions, so to speak. Reconciling the differences
is what should happen.
Inserting inline asm barriers at different stages of the compilation
is a fragile hack. Both the verifier and the LLVM need to work
towards each other. BPF programs are a pain to write. People keep
fighting the verifier and fighting LLVM. Large progs are full of
inline asm hacks (mostly written by humans) to please the verifier
and force LLVM to do something that is against LLVM objectives.
Yonghong is trying to come up with a set of heuristics to do this
asm insertion automatically. It will help, for sure, but won't
close every corner case. The verifier needs to get smarter too.
Recognizing XORs in the verifier is the right thing to do.
Missing XORs in older kernels is not a bug, but we might consider it
a bug and backport this verifier feature to older kernels.
LLVM vs verifier contest is outside of typical kernel bug vs feature
classification of patches. I think we need to be creative here.

  reply	other threads:[~2020-09-02 21:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-25  6:46 [PATCH bpf-next 0/2] fix a verifier failure with xor Yonghong Song
2020-08-25  6:46 ` [PATCH bpf-next 1/2] bpf: " Yonghong Song
2020-08-26  1:58   ` Alexei Starovoitov
2020-08-26  3:36     ` Yonghong Song
2020-08-26 22:06       ` John Fastabend
2020-08-27  5:12         ` Alexei Starovoitov
2020-08-27 18:43           ` John Fastabend
2020-09-01 20:07   ` Andrii Nakryiko
2020-09-02  2:17     ` Yonghong Song
2020-09-02  5:27       ` John Fastabend
2020-09-02  5:43         ` Yonghong Song
2020-09-04  5:29           ` John Fastabend
2020-09-02  9:33       ` Toke Høiland-Jørgensen
2020-09-02 14:21         ` Alexei Starovoitov
2020-09-02 15:01           ` Toke Høiland-Jørgensen
2020-09-02 21:40             ` Alexei Starovoitov [this message]
2020-08-25  6:46 ` [PATCH bpf-next 2/2] selftests/bpf: add verifier tests for xor operation Yonghong Song

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=20200902214002.ciczljw7wrbznper@ast-mbp.dhcp.thefacebook.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=toke@redhat.com \
    --cc=yhs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.