Skip to content

Commit c43ad6c

Browse files
BPF: Change callx insn encoding (#81546)
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 <[email protected]>
1 parent 4af24d4 commit c43ad6c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ struct BPFOperand : public MCParsedAsmOperand {
229229
return StringSwitch<bool>(Name.lower())
230230
.Case("if", true)
231231
.Case("call", true)
232+
.Case("callx", true)
232233
.Case("goto", true)
233234
.Case("gotol", true)
234235
.Case("*", true)

llvm/lib/Target/BPF/BPFInstrInfo.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,9 @@ class CALLX<string OpcodeStr>
622622
(ins GPR:$BrDst),
623623
!strconcat(OpcodeStr, " $BrDst"),
624624
[]> {
625-
bits<32> BrDst;
625+
bits<4> BrDst;
626626

627-
let Inst{31-0} = BrDst;
627+
let Inst{51-48} = BrDst;
628628
let BPFClass = BPF_JMP;
629629
}
630630

llvm/test/MC/BPF/insn-unit.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
// CHECK-32: c3 92 10 00 00 00 00 00 lock *(u32 *)(r2 + 16) += w9
6262
// CHECK: db a3 e2 ff 00 00 00 00 lock *(u64 *)(r3 - 30) += r10
6363

64+
callx r2
65+
// CHECK: 8d 02 00 00 00 00 00 00 callx r2
66+
6467
// ======== BPF_JMP Class ========
6568
if r1 & r2 goto Llabel0 // BPF_JSET | BPF_X
6669
if r1 & 0xffff goto Llabel0 // BPF_JSET | BPF_K

0 commit comments

Comments
 (0)