diff options
author | Puranjay Mohan <puranjay12@gmail.com> | 2024-03-24 21:32:26 +0300 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2024-03-25 19:10:51 +0300 |
commit | 770546ae9f4c1ae1ebcaf0874f0dd9631d77ec97 (patch) | |
tree | 3a7bbdf305e2c5ab7154fdd2c40216f17f3e4e69 /include/linux/filter.h | |
parent | a8497506cd2c0fc90a64f6f5d2744a0ddb2c81eb (diff) | |
download | linux-770546ae9f4c1ae1ebcaf0874f0dd9631d77ec97.tar.xz |
bpf: implement insn_is_cast_user() helper for JITs
Implement a helper function to check if an instruction is
addr_space_cast from as(0) to as(1). Use this helper in the x86 JIT.
Other JITs can use this helper when they add support for this instruction.
Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
Link: https://lore.kernel.org/r/20240324183226.29674-1-puranjay12@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include/linux/filter.h')
-rw-r--r-- | include/linux/filter.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/linux/filter.h b/include/linux/filter.h index c0d51bff8f96..44934b968b57 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -228,6 +228,16 @@ static inline bool insn_is_zext(const struct bpf_insn *insn) return insn->code == (BPF_ALU | BPF_MOV | BPF_X) && insn->imm == 1; } +/* addr_space_cast from as(0) to as(1) is for converting bpf arena pointers + * to pointers in user vma. + */ +static inline bool insn_is_cast_user(const struct bpf_insn *insn) +{ + return insn->code == (BPF_ALU64 | BPF_MOV | BPF_X) && + insn->off == BPF_ADDR_SPACE_CAST && + insn->imm == 1U << 16; +} + /* BPF_LD_IMM64 macro encodes single 'load 64-bit immediate' insn */ #define BPF_LD_IMM64(DST, IMM) \ BPF_LD_IMM64_RAW(DST, 0, IMM) |