Skip to content

Commit 27dd0d2

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: BPF: Fix unconditional bswap instructions
We can see that "bswap32: Takes an unsigned 32-bit number in either big- or little-endian format and returns the equivalent number with the same bit width but opposite endianness" in BPF Instruction Set Specification, so it should clear the upper 32 bits in "case 32:" for both BPF_ALU and BPF_ALU64. [root@linux fedora]# echo 1 > /proc/sys/net/core/bpf_jit_enable [root@linux fedora]# modprobe test_bpf Before: test_bpf: torvalds#313 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89 jited:1 ret 1460850314 != -271733879 (0x5712ce8a != 0xefcdab89)FAIL (1 times) test_bpf: torvalds#317 BSWAP 32: 0xfedcba9876543210 -> 0x10325476 jited:1 ret -1460850316 != 271733878 (0xa8ed3174 != 0x10325476)FAIL (1 times) After: test_bpf: torvalds#313 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89 jited:1 4 PASS test_bpf: torvalds#317 BSWAP 32: 0xfedcba9876543210 -> 0x10325476 jited:1 4 PASS Fixes: 4ebf921 ("LoongArch: BPF: Support unconditional bswap instructions") Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent c533641 commit 27dd0d2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/loongarch/net/bpf_jit.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,8 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
774774
break;
775775
case 32:
776776
emit_insn(ctx, revb2w, dst, dst);
777-
/* zero-extend 32 bits into 64 bits */
778-
emit_zext_32(ctx, dst, is32);
777+
/* clear the upper 32 bits */
778+
emit_zext_32(ctx, dst, true);
779779
break;
780780
case 64:
781781
emit_insn(ctx, revbd, dst, dst);

0 commit comments

Comments
 (0)