Re: [PATCH bpf-next v2 4/8] arm32, bpf: add support for unconditional bswap instruction

Russell King (Oracle)
2023-09-07T16:24:34Z

On Thu, Sep 07, 2023 at 09:08:46AM +0000, Puranjay Mohan wrote:
> On Thu, Sep 07 2023, Russell King (Oracle) wrote:
>
> > On Wed, Sep 06, 2023 at 06:33:16PM +0000, Puranjay Mohan wrote:
> >> @@ -1633,8 +1633,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
> >> /* dst = htobe(dst) */
> >> case BPF_ALU | BPF_END | BPF_FROM_LE:
> >> case BPF_ALU | BPF_END | BPF_FROM_BE:
> >> + /* dst = bswap(dst) */
> >> + case BPF_ALU64 | BPF_END | BPF_TO_LE:
> >> rd = arm_bpf_get_reg64(dst, tmp, ctx);
> >> - if (BPF_SRC(code) == BPF_FROM_LE)
> >> + if (BPF_SRC(code) == BPF_FROM_LE && BPF_CLASS(code) != BPF_ALU64)
> >
> > With the addition of the BPF_ALU64 case, I'm wondering why this if() is
> > affected. If you were adding:
> >
> > case BPF_ALU64 | BPF_END | BPF_FROM_LE:
> >
> > then maybe there would be a reason, but the BPF_ALU64 | BPF_END |
> > BPF_TO_LE case will never match even the original if() statement.
>
> The reason is that these mean the same thing.
> from: include/uapi/linux/bpf.h
>
> #define BPF_TO_LE 0x00 /* convert to little-endian */
> #define BPF_TO_BE 0x08 /* convert to big-endian */
> #define BPF_FROM_LE BPF_TO_LE
> #define BPF_FROM_BE BPF_TO_BE
>
> So, to not cause confusion and follow the earlier cases I can add:
>
> case BPF_ALU64 | BPF_END | BPF_FROM_LE:
>
> in the next version.

It might be worth adding a comment after each stating one of:

/* also BPF_TO_LE */
/* also BPF_TO_BE */

as appropriate to make this more readable.

Thanks.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!