From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Edward Cree <ecree@solarflare.com>
Cc: David Miller <davem@davemloft.net>,
netdev <netdev@vger.kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH net-next] bpf/verifier: improve disassembly of BPF_END instructions
Date: Thu, 21 Sep 2017 09:40:20 -0700 [thread overview]
Message-ID: <20170921164018.xeos6z5cdghmtnti@ast-mbp> (raw)
In-Reply-To: <4cfac985-4f99-cf85-fc15-c3ad1f8ff123@solarflare.com>
On Thu, Sep 21, 2017 at 05:24:10PM +0100, Edward Cree wrote:
> On 21/09/17 16:52, Alexei Starovoitov wrote:
> > On Thu, Sep 21, 2017 at 04:09:34PM +0100, Edward Cree wrote:
> >> print_bpf_insn() was treating all BPF_ALU[64] the same, but BPF_END has a
> >> different structure: it has a size in insn->imm (even if it's BPF_X) and
> >> uses the BPF_SRC (X or K) to indicate which endianness to use. So it
> >> needs different code to print it.
> >>
> >> Signed-off-by: Edward Cree <ecree@solarflare.com>
> >> ---
> >> It's not the same format as the new LLVM asm uses, does that matter?
> >> AFAIK the LLVM format doesn't comprehend BPF_TO_LE, just assumes that all
> >> endian ops are necessarily swaps (rather than sometimes nops).
> > that is being fixed and we will fix asm format too.
> > Let's pick good format first.
> Agreed.
> >> kernel/bpf/verifier.c | 13 +++++++++++--
> >> 1 file changed, 11 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> >> index 799b245..e7657a4 100644
> >> --- a/kernel/bpf/verifier.c
> >> +++ b/kernel/bpf/verifier.c
> >> @@ -331,20 +331,29 @@ static void print_bpf_insn(const struct bpf_verifier_env *env,
> >> u8 class = BPF_CLASS(insn->code);
> >>
> >> if (class == BPF_ALU || class == BPF_ALU64) {
> >> - if (BPF_SRC(insn->code) == BPF_X)
> >> + if (BPF_OP(insn->code) == BPF_END) {
> >> + if (class == BPF_ALU64)
> >> + verbose("BUG_alu64_%02x\n", insn->code);
> >> + else
> >> + verbose("(%02x) (u%d) r%d %s %s\n",
> >> + insn->code, insn->imm, insn->dst_reg,
> >> + bpf_alu_string[BPF_END >> 4],
> >> + BPF_SRC(insn->code) == BPF_X ? "be" : "le");
> > yes the bit the same, but please use BPF_SRC(insn->code) == BPF_TO_BE.
> Good point.
> > imo
> > (u16) r4 endian be
> > isn't intuitive.
> > Can we come up with some better syntax?
> > Like
> > bswap16be r4
> > bswap32le r4
> Hmm, I don't like these, since bswapbe is a swap on *le* and a nop on be.
> > or
> >
> > to_be16 r4
> > to_le32 r4
> And the problem here is that it's not just to_be, it's also from_be.
> Otherwise we could write `(be16) r4 = endian (u16) r4` and be much more
> explicit about what's happening.
> Really the operation is something like `cpu_tofrom_be16 r4`, but that also
> seems a bit clumsy and longwinded. Also it's inconsistent with the other
> ops that all indicate sizes with these (u16) etc casts.
> `endian (be16) r4`, perhaps?
How about:
r4 = (be16) (u16) r4
r4 = (le64) (u64) r4
most C like and most explicit ?
it should be easy to grasp that (be16) cast on big-endian arch is a nop and
swap on little.
next prev parent reply other threads:[~2017-09-21 16:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-21 15:09 [PATCH net-next] bpf/verifier: improve disassembly of BPF_END instructions Edward Cree
2017-09-21 15:52 ` Alexei Starovoitov
2017-09-21 16:24 ` Edward Cree
2017-09-21 16:40 ` Alexei Starovoitov [this message]
2017-09-21 16:40 ` Y Song
2017-09-21 16:58 ` Edward Cree
2017-09-21 19:29 ` Daniel Borkmann
2017-09-21 19:44 ` Alexei Starovoitov
2017-09-21 19:58 ` Edward Cree
2017-09-21 23:11 ` Y Song
2017-09-22 13:46 ` Edward Cree
2017-09-22 14:11 ` Y Song
2017-09-22 14:27 ` Y Song
2017-09-22 15:16 ` Alexei Starovoitov
2017-09-22 16:23 ` Edward Cree
2017-09-23 4:49 ` Y Song
2017-09-24 5:50 ` Alexei Starovoitov
2017-09-25 21:44 ` Daniel Borkmann
2017-09-26 1:33 ` Alexei Starovoitov
2017-09-26 14:37 ` Edward Cree
2017-09-21 16:30 ` Y 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=20170921164018.xeos6z5cdghmtnti@ast-mbp \
--to=alexei.starovoitov@gmail.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=ecree@solarflare.com \
--cc=netdev@vger.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