From nobody Thu Sep 24 12:52:59 2026 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (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 5355C52BE58; Wed, 23 Sep 2026 13:09:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790168977; cv=none; b=SbNDMxafFoUqmHTkauE7hjhEXl1nUgQLL6TTx9xobgnNsSlvNlQCpV7wO5iAhJTXMoA9xng87CQ3VP5wqo9Qat0nJdVG1WVPmENP8jFWXrJk6sJauNFPEf/t19RQm3rJ7Ix48ZiHCM0tRgH7EYfY+NbLac8eVDKsvLQnx75Xz44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790168977; c=relaxed/simple; bh=bg9bhbGrO8szyUuIieyhFOaqXkMVTj0HA51QVzs36Xs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lm5mUTHivQkiNstg6gqSOZ+JgZtppk2o26PVZu1L6zl/sS9/zOL8iDR69PxLOZfZe146mhDc2ATRuzkzTes6Ma7d8x8B5FHByY8NaYOt/scAUmvnNdQ0z8td4abNQXkXqwA8c7b0FOL1xBJ+mC65qmDannDQVvZ9vREm2YlrHis= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=sKhOeygB; arc=none smtp.client-ip=115.124.30.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="sKhOeygB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1790168968; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=o6SVUnKde/TR5k8kPB3Bgbc2uo8e/oZYlAsOUPZzYhI=; b=sKhOeygBsXf+Zln0mzQe72MUeS4kW5KijfS93dKnGdTxxJIh4cNUuIeezsvLqnmE0aaaOzmBJDdTFP12eBJQewvJKu8q/2HiR5Yuq3wxA2X3Ad0n1QEVR4Q1HTp9QdGUIJzU5IwACvrpgFH5L6t63ouUtV6NQvOr2AQMpU8CBQU= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=cp0613@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0XBX4ZPB_1790168967; Received: from DESKTOP-S9E58SO.localdomain(mailfrom:cp0613@linux.alibaba.com fp:SMTPD_---0XBX4ZPB_1790168967 cluster:ay36) by smtp.aliyun-inc.com; Wed, 23 Sep 2026 21:09:27 +0800 From: Chen Pei To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, memxor@gmail.com, bjorn@kernel.org, puranjay@kernel.org Cc: ihor.solodrai@linux.dev, eddyz87@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, pulehui@huawei.com, pjw@kernel.org, palmer@dabbelt.com, shuah@kernel.org, guoren@kernel.org, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 1/2] bpf, riscv: Add support for indirect jumps Date: Wed, 23 Sep 2026 21:08:55 +0800 Message-ID: <20260923130856.1157-2-cp0613@linux.alibaba.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260923130856.1157-1-cp0613@linux.alibaba.com> References: <20260923130856.1157-1-cp0613@linux.alibaba.com> 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 Content-Type: text/plain; charset="utf-8" Implement JIT support for the indirect jump instruction (BPF_JMP | BPF_JA | BPF_X), a.k.a. gotox, which lets a BPF program jump through a BPF_MAP_TYPE_INSN_ARRAY jump table. Emit "jalr zero, rd, 0" and hand the xlated to jitted offsets to bpf_prog_update_insn_ptrs(), which is what fills in the jump table entries; without that call the load fails with -EFAULT in bpf_insn_array_ready(). ctx->offset[] holds the offset of the insn *following* insn i, as bpf_prog_fill_jited_linfo() expects, so it is shifted by one and offset[0] comes from the prologue length. build_body() now records both halves of a multi-insn record, so no slot keeps a fabricated offset. Only the RV64 JIT is covered; RV32 keeps failing to load as before. Signed-off-by: Chen Pei --- arch/riscv/net/bpf_jit_comp64.c | 5 +++++ arch/riscv/net/bpf_jit_core.c | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp6= 4.c index ed0a6f871dea..9de3749fb268 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -1691,6 +1691,11 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, s= truct rv_jit_context *ctx, emit_zextw(rd, rd, ctx); break; =20 + /* JUMP reg */ + case BPF_JMP | BPF_JA | BPF_X: + emit_jalr(RV_REG_ZERO, rd, 0, ctx); + break; + /* JUMP off */ case BPF_JMP | BPF_JA: case BPF_JMP32 | BPF_JA: diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c index 2fb0b4e198b9..15acf249fed4 100644 --- a/arch/riscv/net/bpf_jit_core.c +++ b/arch/riscv/net/bpf_jit_core.c @@ -26,10 +26,13 @@ static int build_body(struct rv_jit_context *ctx, bool = extra_pass, int *offset) int ret; =20 ret =3D bpf_jit_emit_insn(insn, ctx, extra_pass); - if (ret > 0) - i++; /* skip the next instruction */ if (offset) offset[i] =3D ctx->ninsns; + if (ret > 0) { + i++; /* skip the next instruction */ + if (offset) + offset[i] =3D ctx->ninsns; + } if (ret < 0) return ret; } @@ -176,6 +179,15 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifi= er_env *env, struct bpf_pr for (i =3D 0; i < prog->len; i++) ctx->offset[i] =3D ninsns_rvoff(ctx->offset[i]); bpf_prog_fill_jited_linfo(prog, ctx->offset); + + /* + * bpf_prog_update_insn_ptrs() wants the start of each insn, so + * shift the linfo array by one and get insn 0 from the prologue. + */ + for (i =3D prog->len - 1; i > 0; i--) + ctx->offset[i] =3D ctx->offset[i - 1]; + ctx->offset[0] =3D ninsns_rvoff(ctx->prologue_len); + bpf_prog_update_insn_ptrs(prog, ctx->offset, jit_data->ro_image); out_offset: kvfree(ctx->offset); kfree(jit_data); --=20 2.50.1 From nobody Thu Sep 24 12:52:59 2026 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (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 BDD7F52CCDF; Wed, 23 Sep 2026 13:09:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790168979; cv=none; b=jHvrZ6Vg2NsmEAcv8OM2FC/U4RKe5PEu9AjrgIfmkxrl9AKsCsFZZII/crboM1afNVRYQWJV5smGAPYvTh5BrEi0DGyIGYhy23/Q3gFif95zzuPP+ypj+4Soz0U1QaBWRDxqUL0N8TotROtov4/+nXHWaHqYgHeQgOoblH/rNFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790168979; c=relaxed/simple; bh=57PuwQ6vh0dHqm64Qch1yvln/aQ34OaRWLzMWMvIp78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZFmGErRxC3ZjIMPtXK10d1h/cZ5r8XyZvCTSYkuS7MxgNoLXvvGQoXUqwzJKnAOvlukk8VldGLcc7GBzUZVLEGdN8uifkBICjgntklKFOts8avNQIl2boErkaqE9V4iRyFrn1l/cP6vmfhzMubVrjsNzo+3Ydb2zKONgSLc93ZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=iuOYGxb0; arc=none smtp.client-ip=115.124.30.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="iuOYGxb0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1790168969; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=qDsY6laUwuanA+jJYyeUYogdaMe7dOVPNrzeOBRqPVI=; b=iuOYGxb0N9BlMMbWwRyqJlw+hbDw+czUPZk2A3P9GkLAjDQSo5lWOwrS76gEEZCA3XOpXzGwRVwi54b9WZpMvN6vlfYp5FS5qqwC/AX4Tfv3vXHqpmxRSgUNzKsIZBfHDxcB2wV2cxNEYnKcuPhFqk1si+WE5ByBIf/LnnOxGRU= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=cp0613@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0XBX4ZPj_1790168968; Received: from DESKTOP-S9E58SO.localdomain(mailfrom:cp0613@linux.alibaba.com fp:SMTPD_---0XBX4ZPj_1790168968 cluster:ay36) by smtp.aliyun-inc.com; Wed, 23 Sep 2026 21:09:28 +0800 From: Chen Pei To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, memxor@gmail.com, bjorn@kernel.org, puranjay@kernel.org Cc: ihor.solodrai@linux.dev, eddyz87@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, pulehui@huawei.com, pjw@kernel.org, palmer@dabbelt.com, shuah@kernel.org, guoren@kernel.org, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/2] selftests/bpf: Enable gotox tests for riscv64 Date: Wed, 23 Sep 2026 21:08:56 +0800 Message-ID: <20260923130856.1157-3-cp0613@linux.alibaba.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260923130856.1157-1-cp0613@linux.alibaba.com> References: <20260923130856.1157-1-cp0613@linux.alibaba.com> 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 Content-Type: text/plain; charset="utf-8" The riscv64 JIT now supports the gotox instruction and jump tables, so run the tests in verifier_gotox.c on riscv64 too, mirroring what was done for arm64 and powerpc. The guard is 64-bit only because the RV32 JIT does not implement gotox. Signed-off-by: Chen Pei --- tools/testing/selftests/bpf/progs/verifier_gotox.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/verifier_gotox.c b/tools/tes= ting/selftests/bpf/progs/verifier_gotox.c index 5b18c9a27717..4a38f7da720a 100644 --- a/tools/testing/selftests/bpf/progs/verifier_gotox.c +++ b/tools/testing/selftests/bpf/progs/verifier_gotox.c @@ -6,7 +6,9 @@ #include "bpf_misc.h" #include "../../../include/linux/filter.h" =20 -#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || defined(= __TARGET_ARCH_powerpc) +#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || \ + defined(__TARGET_ARCH_powerpc) || \ + (defined(__TARGET_ARCH_riscv) && __riscv_xlen =3D=3D 64) =20 #define DEFINE_SIMPLE_JUMP_TABLE_PROG(NAME, SRC_REG, OFF, IMM, OUTCOME) \ \ @@ -409,6 +411,8 @@ __naked void spill_fill_ptr_to_insn(void) : __clobber_all); } =20 -#endif /* __TARGET_ARCH_x86 || __TARGET_ARCH_arm64 || __TARGET_ARCH_powerp= c*/ +#endif /* __TARGET_ARCH_x86 || __TARGET_ARCH_arm64 || + * __TARGET_ARCH_powerpc || __TARGET_ARCH_riscv + */ =20 char _license[] SEC("license") =3D "GPL"; --=20 2.50.1