From nobody Sat Jul 25 19:33:48 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 8C4843BF684; Tue, 14 Jul 2026 12:16:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784031403; cv=none; b=GIWWEA6FjgiVoTWxmCz95w0FYd/dO1zDCp+4tBSSUuss9fuzN3LE2nUcuZY6LqiQvog57U19jftdVY5xgPUd1DbOkDypHi/Q4vGmJGjafjBA0y6Y7O+96zqhtKPtx3FIP5k0s036iBqwSKddu+Y4MjPabL7ibFwDnJp71VXSTCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784031403; c=relaxed/simple; bh=Elt5MKAY55ZX4mcbRsImPgbrsAPseQfnz74J6UKmSks=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FeXtjGtMi7s/1AjHZ7r8mTSOSwUPiKyoSeturNhYg3apEtZk8z8MUXSwFJlnoL4CAxGLEk4Z2rcv/qqZJMNtfyh0HyQzJb7dhxmMO53G0eOMGBn7I5oVmk42fwj0sdD2hOhmSTCRVg+syla36q+DaCZ2VCi1QGykLzq9/LyJJHM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: d38b56787f7d11f1aa26b74ffac11d73-20260714 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:298d5829-ba20-455e-a0e3-656ecc3f1cf2,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:e7bac3a,CLOUDID:622c0acc96050cf769b2fdd8b8619630,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|136|850|865|898,TC:nil,Content :0|15|50,EDM:-3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: d38b56787f7d11f1aa26b74ffac11d73-20260714 X-User: jiangfeng@kylinos.cn Received: from [127.0.0.1] [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 827933751; Tue, 14 Jul 2026 20:16:22 +0800 From: Feng Jiang Date: Tue, 14 Jul 2026 20:16:15 +0800 Subject: [PATCH v2 1/2] bpf, riscv: add support for timed may_goto Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260714-riscv-bpf-timed-may-goto-v2-1-eeb6201aedcc@kylinos.cn> References: <20260714-riscv-bpf-timed-may-goto-v2-0-eeb6201aedcc@kylinos.cn> In-Reply-To: <20260714-riscv-bpf-timed-may-goto-v2-0-eeb6201aedcc@kylinos.cn> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , Pu Lehui , Puranjay Mohan , Luke Nelson , Xi Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Shuah Khan Cc: bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Feng Jiang X-Mailer: b4 0.14.3 Implement arch_bpf_timed_may_goto() for the RV64 JIT. The argument and return value are carried in BPF_REG_AX, and BPF R0-R5 are preserved across the call to the generic bpf_check_timed_may_goto(). Enable bpf_jit_supports_timed_may_goto() so the verifier uses the timed expansion path. Signed-off-by: Feng Jiang --- arch/riscv/net/Makefile | 2 +- arch/riscv/net/bpf_jit_comp64.c | 13 ++++++++++- arch/riscv/net/bpf_timed_may_goto.S | 44 +++++++++++++++++++++++++++++++++= ++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/arch/riscv/net/Makefile b/arch/riscv/net/Makefile index 9a1e5f0a94e5..6458d4d51990 100644 --- a/arch/riscv/net/Makefile +++ b/arch/riscv/net/Makefile @@ -3,7 +3,7 @@ obj-$(CONFIG_BPF_JIT) +=3D bpf_jit_core.o =20 ifeq ($(CONFIG_ARCH_RV64I),y) - obj-$(CONFIG_BPF_JIT) +=3D bpf_jit_comp64.o + obj-$(CONFIG_BPF_JIT) +=3D bpf_jit_comp64.o bpf_timed_may_goto.o else obj-$(CONFIG_BPF_JIT) +=3D bpf_jit_comp32.o endif diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp6= 4.c index c03c1de16b79..4f88a446278a 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -1841,7 +1841,13 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, s= truct rv_jit_context *ctx, if (ret) return ret; =20 - if (insn->src_reg !=3D BPF_PSEUDO_CALL) + /* + * arch_bpf_timed_may_goto() is emitted by the verifier and + * returns its result in BPF_REG_AX instead of BPF_REG_0, so + * skip the normal "move return register into R0". + */ + if (insn->src_reg !=3D BPF_PSEUDO_CALL && + addr !=3D (u64)arch_bpf_timed_may_goto) emit_mv(bpf_to_rv_reg(BPF_REG_0, ctx), RV_REG_A0, ctx); break; } @@ -2157,3 +2163,8 @@ bool bpf_jit_supports_fsession(void) { return true; } + +bool bpf_jit_supports_timed_may_goto(void) +{ + return true; +} diff --git a/arch/riscv/net/bpf_timed_may_goto.S b/arch/riscv/net/bpf_timed= _may_goto.S new file mode 100644 index 000000000000..f54f389d921e --- /dev/null +++ b/arch/riscv/net/bpf_timed_may_goto.S @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2026 Feng Jiang */ + +#include +#include + +/* + * Trampoline for the BPF timed may_goto loop bound. Custom calling conven= tion: + * - input: stack offset in BPF_REG_AX (t0) + * - output: updated count in BPF_REG_AX (t0) + * + * Calls bpf_check_timed_may_goto(ptr) with the standard RISC-V ABI, where + * ptr =3D BPF_REG_FP (s5) + BPF_REG_AX (t0). BPF R0-R5 (a5, a0-a4) are sa= ved + * across the call; BPF_REG_FP (s5) is callee-saved and needs no saving. + */ + +SYM_FUNC_START(arch_bpf_timed_may_goto) + addi sp, sp, -64 + sd ra, 56(sp) + + /* Save BPF registers R0-R5 (a5, a0-a4) */ + sd a5, 48(sp) + sd a0, 40(sp) + sd a1, 32(sp) + sd a2, 24(sp) + sd a3, 16(sp) + sd a4, 8(sp) + + add a0, t0, s5 + call bpf_check_timed_may_goto + mv t0, a0 + + /* Restore BPF registers R0-R5 */ + ld a4, 8(sp) + ld a3, 16(sp) + ld a2, 24(sp) + ld a1, 32(sp) + ld a0, 40(sp) + ld a5, 48(sp) + + ld ra, 56(sp) + addi sp, sp, 64 + ret +SYM_FUNC_END(arch_bpf_timed_may_goto) --=20 2.25.1 From nobody Sat Jul 25 19:33:48 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 F3CFD3C0605; Tue, 14 Jul 2026 12:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784031399; cv=none; b=WHz8CjR6nA9JyTjUndHZtld+AUlYEEJkhs25/t6s9LZW1PFmhL9tBpjLl8Jt06pJ+KMrzL5vg4F8TZv9Z8KQHyiXqz4HNQSf2H2ez5E8ZC/IhYe+MCZJxDQerLIOkeeVEMmHzp2GoErhNc8jE5gwEnJpLOlNcQaqlYMaXUZbW+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784031399; c=relaxed/simple; bh=3IUxIAMwAgJQi/w5DKjB1ynDyfv07I0GZbRiVejHe9M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PhU7NZ/47aVkhiEM3Uy3s+W8rJ5EA3cqCyBWIvjlR4q8xAYUMGKt7bhI+Bm8tktcxuQUETuLcrPPFjTMMZUC9PwWsPFD3hJNdXCCh1JpmkmDJm0UzA+oMscaUtswuaMFS2Sr5glFovvJm1CnEtS75YJ42W3h3guPSIjpomUGkEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: d40b551c7f7d11f1aa26b74ffac11d73-20260714 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:6ebc2989-9d4e-4cac-8341-8829a453cdbc,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:e7bac3a,CLOUDID:2b8b25a171b65b0ae0ef429c63571512,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|850|865|898,TC:nil,Content:0|1 5|50,EDM:-3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI :0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: d40b551c7f7d11f1aa26b74ffac11d73-20260714 X-User: jiangfeng@kylinos.cn Received: from [127.0.0.1] [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1685286094; Tue, 14 Jul 2026 20:16:23 +0800 From: Feng Jiang Date: Tue, 14 Jul 2026 20:16:16 +0800 Subject: [PATCH v2 2/2] selftests/bpf: enable timed may_goto tests for riscv64 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260714-riscv-bpf-timed-may-goto-v2-2-eeb6201aedcc@kylinos.cn> References: <20260714-riscv-bpf-timed-may-goto-v2-0-eeb6201aedcc@kylinos.cn> In-Reply-To: <20260714-riscv-bpf-timed-may-goto-v2-0-eeb6201aedcc@kylinos.cn> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , Pu Lehui , Puranjay Mohan , Luke Nelson , Xi Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Shuah Khan Cc: bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Feng Jiang X-Mailer: b4 0.14.3 Enable verifier_may_goto_1 (raw instruction tests), stream_cond_break (250ms timeout path), and the may_goto_interaction_arm64 fastcall test on riscv64 now that the JIT supports timed may_goto. Signed-off-by: Feng Jiang --- tools/testing/selftests/bpf/progs/stream.c | 1 + tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c | 1 + tools/testing/selftests/bpf/progs/verifier_may_goto_1.c | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/stream.c b/tools/testing/sel= ftests/bpf/progs/stream.c index 92ba1d72e0ec..8d8e53d37266 100644 --- a/tools/testing/selftests/bpf/progs/stream.c +++ b/tools/testing/selftests/bpf/progs/stream.c @@ -64,6 +64,7 @@ SEC("syscall") __arch_x86_64 __arch_arm64 __arch_s390x +__arch_riscv64 __success __retval(0) __stderr("ERROR: Timeout detected for may_goto instruction") __stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}") diff --git a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c b/to= ols/testing/selftests/bpf/progs/verifier_bpf_fastcall.c index 8d7ff38e4c06..e6671c54e53a 100644 --- a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c +++ b/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c @@ -660,6 +660,7 @@ __naked void may_goto_interaction_x86_64(void) =20 SEC("raw_tp") __arch_arm64 +__arch_riscv64 __log_level(4) __msg("stack depth 24") /* may_goto counter at -24 */ __xlated("0: *(u64 *)(r10 -24) =3D") diff --git a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c b/tool= s/testing/selftests/bpf/progs/verifier_may_goto_1.c index 4bdf4256a41e..f47b9d540a17 100644 --- a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c +++ b/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c @@ -11,6 +11,7 @@ __description("may_goto 0") __arch_x86_64 __arch_s390x __arch_arm64 +__arch_riscv64 __xlated("0: r0 =3D 1") __xlated("1: exit") __success @@ -31,6 +32,7 @@ __description("batch 2 of may_goto 0") __arch_x86_64 __arch_s390x __arch_arm64 +__arch_riscv64 __xlated("0: r0 =3D 1") __xlated("1: exit") __success @@ -53,6 +55,7 @@ __description("may_goto batch with offsets 2/1/0") __arch_x86_64 __arch_s390x __arch_arm64 +__arch_riscv64 __xlated("0: r0 =3D 1") __xlated("1: exit") __success @@ -79,6 +82,7 @@ __description("may_goto batch with offsets 2/0") __arch_x86_64 __arch_s390x __arch_arm64 +__arch_riscv64 __xlated("0: *(u64 *)(r10 -16) =3D 65535") __xlated("1: *(u64 *)(r10 -8) =3D 0") __xlated("2: r12 =3D *(u64 *)(r10 -16)") --=20 2.25.1