[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <207ecd4c-b1b4-3dcd-62a6-30824c19dbf7@solarflare.com>
Date: Thu, 21 Sep 2017 17:58:14 +0100
From: Edward Cree <ecree@...arflare.com>
To: Y Song <ys114321@...il.com>
CC: Alexei Starovoitov <alexei.starovoitov@...il.com>,
David Miller <davem@...emloft.net>,
netdev <netdev@...r.kernel.org>,
Daniel Borkmann <daniel@...earbox.net>
Subject: Re: [PATCH net-next] bpf/verifier: improve disassembly of BPF_END
instructions
On 21/09/17 17:40, Y Song wrote:
> On Thu, Sep 21, 2017 at 9:24 AM, Edward Cree <ecree@...arflare.com> wrote:
>> On 21/09/17 16:52, Alexei Starovoitov wrote:
>>> 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.
> Could you explain what is "from_be" here? Do not quite understand.
Taking the example of a little-endian processor:
cpu_to_be16() is a byte-swap, converting a u16 (cpu-endian) to a __be16.
be16_to_cpu(), to convert a __be16 to a u16, is *also* a byte-swap.
Meanwhile, cpu_to_le16() and le16_to_cpu() are both no-ops.
More generally, the conversions between cpu-endian and fixed-endian for
any given size are self-inverses. eBPF takes advantage of this by only
having a single opcode for both the "to" and "from" direction. So to
specify an endianness conversion, you need only the size and the fixed
endianness (le or be), not the to/from direction. Conversely, when
disassembling one of these instructions, you don't know whether it's a
cpu_to_be16() or a be16_to_cpu(), because they both look the same at an
instruction level (they only differ in what types the programmer thought
of the register as holding before and after).
Powered by blists - more mailing lists