]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bpf, x64: Add predicate for bpf2bpf with tailcalls support in JIT
authorTony Ambardar <tony.ambardar@gmail.com>
Fri, 17 Jun 2022 10:57:34 +0000 (12:57 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:41:04 +0000 (14:41 +0200)
[ Upstream commit 95acd8817e66d031d2e6ee7def3f1e1874819317 ]

The BPF core/verifier is hard-coded to permit mixing bpf2bpf and tail
calls for only x86-64. Change the logic to instead rely on a new weak
function 'bool bpf_jit_supports_subprog_tailcalls(void)', which a capable
JIT backend can override.

Update the x86-64 eBPF JIT to reflect this.

Signed-off-by: Tony Ambardar <Tony.Ambardar@gmail.com>
[jakub: drop MIPS bits and tweak patch subject]
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220617105735.733938-2-jakub@cloudflare.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/net/bpf_jit_comp.c
include/linux/filter.h
kernel/bpf/core.c
kernel/bpf/verifier.c

index 9ec96d5a823970f5834a483a8a194f12b7393150..124456bb23b92f522cb1b5d20cd2d9f271e529e9 100644 (file)
@@ -2477,3 +2477,9 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len)
                return ERR_PTR(-EINVAL);
        return dst;
 }
+
+/* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */
+bool bpf_jit_supports_subprog_tailcalls(void)
+{
+       return true;
+}
index ed0c0ff42ad5b5bc0b0cb5ec2f41712a4b9400c6..d9a0db845b508ce2bb1c91a90b56f97923e6c5b7 100644 (file)
@@ -948,6 +948,7 @@ u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
 struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog);
 void bpf_jit_compile(struct bpf_prog *prog);
 bool bpf_jit_needs_zext(void);
+bool bpf_jit_supports_subprog_tailcalls(void);
 bool bpf_jit_supports_kfunc_call(void);
 bool bpf_helper_changes_pkt_data(void *func);
 
index 3adff3831c047c32f5671df4f99b926a0c4b2860..7a1ce697689b97f559afd7228aa276089f2507af 100644 (file)
@@ -2712,6 +2712,12 @@ bool __weak bpf_jit_needs_zext(void)
        return false;
 }
 
+/* Return TRUE if the JIT backend supports mixing bpf2bpf and tailcalls. */
+bool __weak bpf_jit_supports_subprog_tailcalls(void)
+{
+       return false;
+}
+
 bool __weak bpf_jit_supports_kfunc_call(void)
 {
        return false;
index d04147a5efa552e491d220e9dfd260db7ad50a78..a6d3a89723555185c5321542fbe19ca22edba373 100644 (file)
@@ -5696,7 +5696,8 @@ static bool may_update_sockmap(struct bpf_verifier_env *env, int func_id)
 
 static bool allow_tail_call_in_subprogs(struct bpf_verifier_env *env)
 {
-       return env->prog->jit_requested && IS_ENABLED(CONFIG_X86_64);
+       return env->prog->jit_requested &&
+              bpf_jit_supports_subprog_tailcalls();
 }
 
 static int check_map_func_compatibility(struct bpf_verifier_env *env,