From: Leon Hwang <leon.hwang@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Puranjay Mohan <puranjay@kernel.org>,
Xu Kuohai <xukuohai@huaweicloud.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
kernel-patches-bot@fb.com, Leon Hwang <leon.hwang@linux.dev>
Subject: [PATCH bpf-next 4/4] bpf, lib/test_bpf: Fix broken tailcall tests
Date: Fri, 2 Jan 2026 23:00:32 +0800 [thread overview]
Message-ID: <20260102150032.53106-5-leon.hwang@linux.dev> (raw)
In-Reply-To: <20260102150032.53106-1-leon.hwang@linux.dev>
Update the tail call tests in test_bpf to work with the new tail call
optimization that requires:
1. A valid used_maps array pointing to the prog array
2. Precomputed tail call targets in array->ptrs[max_entries + index]
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
lib/test_bpf.c | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index af0041df2b72..680d34d46f19 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -15448,26 +15448,45 @@ static void __init destroy_tail_call_tests(struct bpf_array *progs)
{
int i;
- for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++)
- if (progs->ptrs[i])
- bpf_prog_free(progs->ptrs[i]);
+ for (i = 0; i < ARRAY_SIZE(tail_call_tests); i++) {
+ struct bpf_prog *fp = progs->ptrs[i];
+
+ if (!fp)
+ continue;
+
+ /*
+ * The used_maps points to fake maps that don't have
+ * proper ops, so clear it before bpf_prog_free to avoid
+ * bpf_free_used_maps trying to process it.
+ */
+ kfree(fp->aux->used_maps);
+ fp->aux->used_maps = NULL;
+ fp->aux->used_map_cnt = 0;
+ bpf_prog_free(fp);
+ }
kfree(progs);
}
static __init int prepare_tail_call_tests(struct bpf_array **pprogs)
{
+ int prologue_offset = bpf_arch_tail_call_prologue_offset();
int ntests = ARRAY_SIZE(tail_call_tests);
+ u32 max_entries = ntests + 1;
struct bpf_array *progs;
int which, err;
/* Allocate the table of programs to be used for tail calls */
- progs = kzalloc(struct_size(progs, ptrs, ntests + 1), GFP_KERNEL);
+ progs = kzalloc(struct_size(progs, ptrs, max_entries * 2), GFP_KERNEL);
if (!progs)
goto out_nomem;
+ /* Set max_entries before JIT, as it's used in JIT */
+ progs->map.max_entries = max_entries;
+
/* Create all eBPF programs and populate the table */
for (which = 0; which < ntests; which++) {
struct tail_call_test *test = &tail_call_tests[which];
+ struct bpf_map *map = &progs->map;
struct bpf_prog *fp;
int len, i;
@@ -15487,10 +15506,16 @@ static __init int prepare_tail_call_tests(struct bpf_array **pprogs)
if (!fp)
goto out_nomem;
+ fp->aux->used_maps = kmalloc_array(1, sizeof(map), GFP_KERNEL);
+ if (!fp->aux->used_maps)
+ goto out_nomem;
+
fp->len = len;
fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
fp->aux->stack_depth = test->stack_depth;
fp->aux->tail_call_reachable = test->has_tail_call;
+ fp->aux->used_maps[0] = map;
+ fp->aux->used_map_cnt = 1;
memcpy(fp->insnsi, test->insns, len * sizeof(struct bpf_insn));
/* Relocate runtime tail call offsets and addresses */
@@ -15548,6 +15573,10 @@ static __init int prepare_tail_call_tests(struct bpf_array **pprogs)
if ((long)__bpf_call_base + insn->imm != addr)
*insn = BPF_JMP_A(0); /* Skip: NOP */
break;
+
+ case BPF_JMP | BPF_TAIL_CALL:
+ insn->imm = 0;
+ break;
}
}
@@ -15555,11 +15584,11 @@ static __init int prepare_tail_call_tests(struct bpf_array **pprogs)
if (err)
goto out_err;
+ progs->ptrs[max_entries + which] = (void *) fp->bpf_func + prologue_offset;
progs->ptrs[which] = fp;
}
/* The last entry contains a NULL program pointer */
- progs->map.max_entries = ntests + 1;
*pprogs = progs;
return 0;
--
2.52.0
next prev parent reply other threads:[~2026-01-02 15:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-02 15:00 [PATCH bpf-next 0/4] bpf: tailcall: Eliminate max_entries and bpf_func access at runtime Leon Hwang
2026-01-02 15:00 ` [PATCH bpf-next 1/4] bpf: tailcall: Introduce bpf_arch_tail_call_prologue_offset Leon Hwang
2026-01-02 15:21 ` bot+bpf-ci
2026-01-02 15:38 ` Leon Hwang
2026-01-02 15:00 ` [PATCH bpf-next 2/4] bpf, x64: tailcall: Eliminate max_entries and bpf_func access at runtime Leon Hwang
2026-01-02 15:00 ` [PATCH bpf-next 3/4] bpf, arm64: " Leon Hwang
2026-01-02 15:00 ` Leon Hwang [this message]
2026-01-03 0:10 ` [PATCH bpf-next 0/4] bpf: " Alexei Starovoitov
2026-01-14 11:28 ` Jiri Olsa
2026-01-14 16:04 ` Alexei Starovoitov
2026-01-14 21:00 ` Jiri Olsa
2026-01-14 21:56 ` Alexei Starovoitov
2026-01-15 18:00 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260102150032.53106-5-leon.hwang@linux.dev \
--to=leon.hwang@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=hpa@zytor.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-patches-bot@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=puranjay@kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=xukuohai@huaweicloud.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.