Since interpreter is unable to handle the 'insn_is_cast_user()' insn,
require JIT in __bpf_prog_select_runtime() when the prog has the insn.
Fixes: 142fd4d2dcf5 ("bpf: Add x86-64 JIT support for bpf_addr_space_cast
instruction.")
Signed-off-by: Leon Hwang <[email protected]>
---
include/linux/bpf.h | 1 +
kernel/bpf/core.c | 1 +
kernel/bpf/fixups.c | 2 ++
3 files changed, 4 insertions(+)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 56f5da2b437f..5f48a6ab8a1a 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1780,6 +1780,7 @@ struct bpf_prog_aux {
bool changes_pkt_data;
bool might_sleep;
bool kprobe_write_ctx;
+ bool has_addr_space_cast_insn;
struct {
s32 keyring_serial;
u8 keyring_type;
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 649cce41e13f..49398b5bd172 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2620,6 +2620,7 @@ struct bpf_prog *__bpf_prog_select_runtime(struct
bpf_verifier_env *env, struct
goto finalize;
if (IS_ENABLED(CONFIG_BPF_JIT_ALWAYS_ON) ||
+ fp->aux->has_addr_space_cast_insn ||
bpf_prog_has_kfunc_call(fp))
jit_needed = true;
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 3cf2cc6e3ab6..2d5958774b61 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -1523,6 +1523,8 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
insn->off = 0;
insn->imm = 0;
} /* cast from as(0) to as(1) should be handled by JIT
*/
+ if (insn_is_cast_user(insn))
+ prog->aux->has_addr_space_cast_insn = true;
goto next_insn;
}
--
2.54.0