]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
s390/bpf: Do not write tail call counter into helper and kfunc frames
authorIlya Leoshkevich <iii@linux.ibm.com>
Wed, 13 Aug 2025 12:06:28 +0000 (14:06 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 18 Aug 2025 13:08:29 +0000 (15:08 +0200)
Only BPF functions make use of the tail call counter; helpers and
kfuncs ignore and most likely also clobber it. Writing it into these
functions' frames is pointless and misleading, so do not do it.

Fixes: dd691e847d28 ("s390/bpf: Implement bpf_jit_supports_subprog_tailcalls()")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20250813121016.163375-2-iii@linux.ibm.com
arch/s390/net/bpf_jit_comp.c

index bb17efe29d6570e71fe4e5ff1ea1c8c0b42c0073..bfac1ddf3447b971a3a84cdb05e4f40bb1f113ee 100644 (file)
@@ -1790,6 +1790,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
 
                REG_SET_SEEN(BPF_REG_5);
                jit->seen |= SEEN_FUNC;
+
                /*
                 * Copy the tail call counter to where the callee expects it.
                 *
@@ -1800,10 +1801,17 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
                 * Note 2: We assume that the verifier does not let us call the
                 * main program, which clears the tail call counter on entry.
                 */
-               /* mvc tail_call_cnt(4,%r15),frame_off+tail_call_cnt(%r15) */
-               _EMIT6(0xd203f000 | offsetof(struct prog_frame, tail_call_cnt),
-                      0xf000 | (jit->frame_off +
-                                offsetof(struct prog_frame, tail_call_cnt)));
+
+               if (insn->src_reg == BPF_PSEUDO_CALL)
+                       /*
+                        * mvc tail_call_cnt(4,%r15),
+                        *     frame_off+tail_call_cnt(%r15)
+                        */
+                       _EMIT6(0xd203f000 | offsetof(struct prog_frame,
+                                                    tail_call_cnt),
+                              0xf000 | (jit->frame_off +
+                                        offsetof(struct prog_frame,
+                                                 tail_call_cnt)));
 
                /* Sign-extend the kfunc arguments. */
                if (insn->src_reg == BPF_PSEUDO_KFUNC_CALL) {