Message ID | 20230905210621.1711859-5-puranjay12@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | arm32, bpf: add support for cpuv4 insns | expand |
On Tue, Sep 05 2023, Russell King (Oracle) wrote: > On Tue, Sep 05, 2023 at 09:06:17PM +0000, Puranjay Mohan wrote: >> The cpuv4 added a new unconditional bswap instruction with following >> behaviour: >> >> BPF_ALU64 | BPF_TO_LE | BPF_END with imm = 16/32/64 means: >> dst = bswap16(dst) >> dst = bswap32(dst) >> dst = bswap64(dst) >> >> As we already support converting to big-endian from little-endian we can >> use the same for unconditional bswap. >> Since ARM32 is always little-endian, just treat the unconditional scenario > > This is not true. Arm32 BPF is disabled for BE32 but not for BE8. It's > entirely possible to build a kernel using BE8 for ARMv7 and have the > BPF JIT enabled: > > select HAVE_EBPF_JIT if !CPU_ENDIAN_BE32 > > So it's not true to say "Since ARM32 is always little-endian". Sure, I will change the commit message in next version. Thanks, Puranjay
diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c index 0a30188de660..09496203f13e 100644 --- a/arch/arm/net/bpf_jit_32.c +++ b/arch/arm/net/bpf_jit_32.c @@ -1632,8 +1632,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) goto emit_bswap_uxt; switch (imm) { case 16:
The cpuv4 added a new unconditional bswap instruction with following behaviour: BPF_ALU64 | BPF_TO_LE | BPF_END with imm = 16/32/64 means: dst = bswap16(dst) dst = bswap32(dst) dst = bswap64(dst) As we already support converting to big-endian from little-endian we can use the same for unconditional bswap. Since ARM32 is always little-endian, just treat the unconditional scenario the same as big-endian conversion. Signed-off-by: Puranjay Mohan <puranjay12@gmail.com> --- arch/arm/net/bpf_jit_32.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)