ebpf icon indicating copy to clipboard operation
ebpf copied to clipboard

asm: add support for the may_goto insn and JCOND opcode

Open mtardy opened this issue 3 months ago • 1 comments

The may_goto instruction is a bit special and relatively new, from March 2024, added by 011832b97b31 ("bpf: Introduce may_goto instruction")^1. It uses the BPF_JCOND opcode 0xe0 with the source register being BPF_MAY_GOTO = 0. Note that this instruction is not documented in the latest instruction set kernel documentation^2.

As I understand, the goal of this instruction is to be injected in loops (also potentially by LLVM) to offload the verifier responsability of loop verification to a runtime check. The runtime check being decrementing a counter so far.

I realized when writing this PR that I had never used the asm package of c/ebpf and that I didn't have the time right now specifically to dive into this. So I'll take that later, or if you want to guide me on what would be the best strategy for you for this "a bit weird" instruction.

mtardy avatar Nov 07 '25 10:11 mtardy

cc @dylandreimerink

mtardy avatar Nov 07 '25 11:11 mtardy