From nobody Tue Feb 10 21:39:11 2026 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3D1F1D5CEA for ; Fri, 2 Jan 2026 15:02:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767366138; cv=none; b=F5ZYPoIPzcvi98uENwYn4a+2xfDwsQb+OrWKRdW+RDsHKMdnyHQI3bEDatfT+r29vAjBcINuoyYH5HBlTSq8fVEYkYnzxWvudV3re+X4N34YStmkWvGUZ9dvK7SDPQ2inx7rXYcsPNWC8wddt/2V1Ll9iFIr4HllHQOqE/o2Y3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767366138; c=relaxed/simple; bh=oBa469maWudsSL5hciWDODbQnyvM7WMptEAnoC2Jg2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t9LcbmdYX0Qa9Hy/MF2fAAFYJud8wcf29ifvvBPqM9s7UaOEEm4WGAWb8k+h6j3RxZg2+MmbsJ/ivt4zpQ5pNlzckPcKJorf48YCI7Y1bq0ZDqTFqn5nUe+82kIvIqkQYMemb9hZwY3AvbSnMbccPqfoRqiUu2CNG62Q1W5UcYo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=dTd7xJ82; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dTd7xJ82" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767366134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SWoEF/+O4yZ7+ZS1SC3d02+me9C0QQC50vg1G2pDlFk=; b=dTd7xJ82NQ50raWJ1auBfjVAEwvFe1zNPFyY3dHzp/bG923whF4XKdS/DUgHQEvXkI3H+D 2cu4C7PnzuE4zP0oxCJ+qzCDPlfxsgn1+i8mteiHNpH+MSZjsfbzjqr+Fwb8306pMkT6qV 7dilcsPQzEAPjUodluMNHjnbf0UKuoQ= From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Puranjay Mohan , Xu Kuohai , Catalin Marinas , Will Deacon , "David S . Miller" , David Ahern , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel-patches-bot@fb.com, Leon Hwang Subject: [PATCH bpf-next 4/4] bpf, lib/test_bpf: Fix broken tailcall tests Date: Fri, 2 Jan 2026 23:00:32 +0800 Message-ID: <20260102150032.53106-5-leon.hwang@linux.dev> In-Reply-To: <20260102150032.53106-1-leon.hwang@linux.dev> References: <20260102150032.53106-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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 --- 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; =20 - for (i =3D 0; i < ARRAY_SIZE(tail_call_tests); i++) - if (progs->ptrs[i]) - bpf_prog_free(progs->ptrs[i]); + for (i =3D 0; i < ARRAY_SIZE(tail_call_tests); i++) { + struct bpf_prog *fp =3D 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 =3D NULL; + fp->aux->used_map_cnt =3D 0; + bpf_prog_free(fp); + } kfree(progs); } =20 static __init int prepare_tail_call_tests(struct bpf_array **pprogs) { + int prologue_offset =3D bpf_arch_tail_call_prologue_offset(); int ntests =3D ARRAY_SIZE(tail_call_tests); + u32 max_entries =3D ntests + 1; struct bpf_array *progs; int which, err; =20 /* Allocate the table of programs to be used for tail calls */ - progs =3D kzalloc(struct_size(progs, ptrs, ntests + 1), GFP_KERNEL); + progs =3D kzalloc(struct_size(progs, ptrs, max_entries * 2), GFP_KERNEL); if (!progs) goto out_nomem; =20 + /* Set max_entries before JIT, as it's used in JIT */ + progs->map.max_entries =3D max_entries; + /* Create all eBPF programs and populate the table */ for (which =3D 0; which < ntests; which++) { struct tail_call_test *test =3D &tail_call_tests[which]; + struct bpf_map *map =3D &progs->map; struct bpf_prog *fp; int len, i; =20 @@ -15487,10 +15506,16 @@ static __init int prepare_tail_call_tests(struct = bpf_array **pprogs) if (!fp) goto out_nomem; =20 + fp->aux->used_maps =3D kmalloc_array(1, sizeof(map), GFP_KERNEL); + if (!fp->aux->used_maps) + goto out_nomem; + fp->len =3D len; fp->type =3D BPF_PROG_TYPE_SOCKET_FILTER; fp->aux->stack_depth =3D test->stack_depth; fp->aux->tail_call_reachable =3D test->has_tail_call; + fp->aux->used_maps[0] =3D map; + fp->aux->used_map_cnt =3D 1; memcpy(fp->insnsi, test->insns, len * sizeof(struct bpf_insn)); =20 /* Relocate runtime tail call offsets and addresses */ @@ -15548,6 +15573,10 @@ static __init int prepare_tail_call_tests(struct b= pf_array **pprogs) if ((long)__bpf_call_base + insn->imm !=3D addr) *insn =3D BPF_JMP_A(0); /* Skip: NOP */ break; + + case BPF_JMP | BPF_TAIL_CALL: + insn->imm =3D 0; + break; } } =20 @@ -15555,11 +15584,11 @@ static __init int prepare_tail_call_tests(struct = bpf_array **pprogs) if (err) goto out_err; =20 + progs->ptrs[max_entries + which] =3D (void *) fp->bpf_func + prologue_of= fset; progs->ptrs[which] =3D fp; } =20 /* The last entry contains a NULL program pointer */ - progs->map.max_entries =3D ntests + 1; *pprogs =3D progs; return 0; =20 --=20 2.52.0