Skip to content

Commit

Permalink
BPF: Change callx insn encoding (#81546)
Browse files Browse the repository at this point in the history
Currently, the kernel verifier unsupported callx insn used the 32-bit
imm field to store the target register. On the other hand, gcc used the
dst_reg field to store the target register. The gcc encoding is better.
This patch adjusted the coding to be the same as gcc.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
  • Loading branch information
yonghong-song authored Feb 13, 2024
1 parent 4af24d4 commit c43ad6c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ struct BPFOperand : public MCParsedAsmOperand {
return StringSwitch<bool>(Name.lower())
.Case("if", true)
.Case("call", true)
.Case("callx", true)
.Case("goto", true)
.Case("gotol", true)
.Case("*", true)
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/BPF/BPFInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,9 @@ class CALLX<string OpcodeStr>
(ins GPR:$BrDst),
!strconcat(OpcodeStr, " $BrDst"),
[]> {
bits<32> BrDst;
bits<4> BrDst;

let Inst{31-0} = BrDst;
let Inst{51-48} = BrDst;
let BPFClass = BPF_JMP;
}

Expand Down
3 changes: 3 additions & 0 deletions llvm/test/MC/BPF/insn-unit.s
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
// CHECK-32: c3 92 10 00 00 00 00 00 lock *(u32 *)(r2 + 16) += w9
// CHECK: db a3 e2 ff 00 00 00 00 lock *(u64 *)(r3 - 30) += r10

callx r2
// CHECK: 8d 02 00 00 00 00 00 00 callx r2

// ======== BPF_JMP Class ========
if r1 & r2 goto Llabel0 // BPF_JSET | BPF_X
if r1 & 0xffff goto Llabel0 // BPF_JSET | BPF_K
Expand Down

0 comments on commit c43ad6c

Please sign in to comment.