* [PATCH bpf-next 1/2] selftests/bpf: use host CPU features in JIT disassembler
2026-06-02 20:58 [PATCH bpf-next 0/2] RISC-V JIT support for bpf_get_current_task/_btf Varun R Mallya
@ 2026-06-02 20:58 ` Varun R Mallya
2026-06-03 7:21 ` Björn Töpel
2026-06-02 20:58 ` [PATCH bpf-next 2/2] bpf, riscv: inline bpf_get_current_task() and bpf_get_current_task_btf() Varun R Mallya
2026-06-05 22:30 ` [PATCH bpf-next 0/2] RISC-V JIT support for bpf_get_current_task/_btf patchwork-bot+netdevbpf
2 siblings, 1 reply; 6+ messages in thread
From: Varun R Mallya @ 2026-06-02 20:58 UTC (permalink / raw)
To: bpf, linux-riscv, ast, daniel, andrii, eddyz87, memxor, bjorn,
pjw, palmer, aou, puranjay, menglong8.dong
Cc: martin.lau, song, yonghong.song, jolsa, pulehui, alex,
linux-kernel, linux-kselftest, varunrmallya
Pass the host CPU name and feature string to
LLVMCreateDisasmCPUFeatures() instead of using LLVMCreateDisasm(), so
the disassembler correctly decodes CPU-specific instructions and
extensions such as RISC-V compressed and vector instructions.
Signed-off-by: Varun R Mallya <varunrmallya@gmail.com>
---
tools/testing/selftests/bpf/jit_disasm_helpers.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/jit_disasm_helpers.c b/tools/testing/selftests/bpf/jit_disasm_helpers.c
index 364c557c5115..3558fe10e28c 100644
--- a/tools/testing/selftests/bpf/jit_disasm_helpers.c
+++ b/tools/testing/selftests/bpf/jit_disasm_helpers.c
@@ -96,10 +96,19 @@ static int disasm_one_func(FILE *text_out, uint8_t *image, __u32 len)
__u32 *label_pc, pc;
int i, cnt, err = 0;
char buf[64];
+ char *cpu, *features;
triple = LLVMGetDefaultTargetTriple();
- ctx = LLVMCreateDisasm(triple, &labels, 0, NULL, lookup_symbol);
- if (!ASSERT_OK_PTR(ctx, "LLVMCreateDisasm")) {
+
+ cpu = LLVMGetHostCPUName();
+ features = LLVMGetHostCPUFeatures();
+
+ ctx = LLVMCreateDisasmCPUFeatures(triple, cpu, features, &labels, 0, NULL, lookup_symbol);
+
+ LLVMDisposeMessage(cpu);
+ LLVMDisposeMessage(features);
+
+ if (!ASSERT_OK_PTR(ctx, "LLVMCreateDisasmCPUFeatures")) {
err = -EINVAL;
goto out;
}
--
2.54.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH bpf-next 1/2] selftests/bpf: use host CPU features in JIT disassembler
2026-06-02 20:58 ` [PATCH bpf-next 1/2] selftests/bpf: use host CPU features in JIT disassembler Varun R Mallya
@ 2026-06-03 7:21 ` Björn Töpel
0 siblings, 0 replies; 6+ messages in thread
From: Björn Töpel @ 2026-06-03 7:21 UTC (permalink / raw)
To: Varun R Mallya
Cc: bpf, linux-riscv, ast, daniel, andrii, eddyz87, memxor, pjw,
palmer, aou, puranjay, menglong8.dong, martin.lau, song,
yonghong.song, jolsa, pulehui, alex, linux-kernel,
linux-kselftest
On Tue, 2 Jun 2026 at 22:59, Varun R Mallya <varunrmallya@gmail.com> wrote:
>
> Pass the host CPU name and feature string to
> LLVMCreateDisasmCPUFeatures() instead of using LLVMCreateDisasm(), so
> the disassembler correctly decodes CPU-specific instructions and
> extensions such as RISC-V compressed and vector instructions.
>
> Signed-off-by: Varun R Mallya <varunrmallya@gmail.com>
Reviewed-by: Björn Töpel <bjorn@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH bpf-next 2/2] bpf, riscv: inline bpf_get_current_task() and bpf_get_current_task_btf()
2026-06-02 20:58 [PATCH bpf-next 0/2] RISC-V JIT support for bpf_get_current_task/_btf Varun R Mallya
2026-06-02 20:58 ` [PATCH bpf-next 1/2] selftests/bpf: use host CPU features in JIT disassembler Varun R Mallya
@ 2026-06-02 20:58 ` Varun R Mallya
2026-06-03 7:16 ` Björn Töpel
2026-06-05 22:30 ` [PATCH bpf-next 0/2] RISC-V JIT support for bpf_get_current_task/_btf patchwork-bot+netdevbpf
2 siblings, 1 reply; 6+ messages in thread
From: Varun R Mallya @ 2026-06-02 20:58 UTC (permalink / raw)
To: bpf, linux-riscv, ast, daniel, andrii, eddyz87, memxor, bjorn,
pjw, palmer, aou, puranjay, menglong8.dong
Cc: martin.lau, song, yonghong.song, jolsa, pulehui, alex,
linux-kernel, linux-kselftest, varunrmallya
On RISC-V, the current task pointer is stored in the thread pointer
register (tp). Emit a single `mv a5, tp` instead of a full helper
call for BPF_FUNC_get_current_task and BPF_FUNC_get_current_task_btf.
Register bpf_jit_inlines_helper_call() entries for both helpers so the
verifier treats them as inlined, and add the expected `mv a5, tp`
annotation to the riscv64 selftests.
The following show changes before and after this patch.
Before patch:
auipc t1,0x817a # load upper PC-relative address
jalr -2004(t1) # call bpf_get_current_task helper
mv a5,a0 # move return value to BPF_REG_0
After patch:
mv a5,tp # directly: a5 = current (tp = thread pointer)
Benchmark (bpf_prog_test_run wrapping bpf_get_current_task in loop,
batch=100, 10s, QEMU RISC-V):
| runs/sec | helper-calls/sec | ns/call
-------------+-----------+------------------+---------
Before patch | 173,490 | 17,349,090 | 57
After patch | 320,497 | 32,049,780 | 31
-------------+-----------+------------------+---------
Improvement | +84.7% | +84.7% | -45.6%
Signed-off-by: Varun R Mallya <varunrmallya@gmail.com>
---
arch/riscv/net/bpf_jit_comp64.c | 9 +++++++++
tools/testing/selftests/bpf/progs/verifier_jit_inline.c | 2 ++
2 files changed, 11 insertions(+)
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 2f1109dbf105..e2c70c70cca8 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -1808,6 +1808,13 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
break;
}
+ /* Implement helper call to bpf_get_current_task/_btf() inline */
+ if (insn->src_reg == 0 && (insn->imm == BPF_FUNC_get_current_task ||
+ insn->imm == BPF_FUNC_get_current_task_btf)) {
+ emit_mv(bpf_to_rv_reg(BPF_REG_0, ctx), RV_REG_TP, ctx);
+ break;
+ }
+
mark_call(ctx);
ret = bpf_jit_get_func_addr(ctx->prog, insn, extra_pass,
&addr, &fixed_addr);
@@ -2138,6 +2145,8 @@ bool bpf_jit_inlines_helper_call(s32 imm)
{
switch (imm) {
case BPF_FUNC_get_smp_processor_id:
+ case BPF_FUNC_get_current_task:
+ case BPF_FUNC_get_current_task_btf:
return true;
default:
return false;
diff --git a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
index 885ff69a3a62..76d80605ec7f 100644
--- a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
+++ b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
@@ -10,6 +10,8 @@ __arch_x86_64
__jited(" addq %gs:{{.*}}, %rax")
__arch_arm64
__jited(" mrs x8, SP_EL0")
+__arch_riscv64
+__jited(" mv a5, tp")
int inline_bpf_get_current_task(void)
{
bpf_get_current_task();
--
2.54.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH bpf-next 2/2] bpf, riscv: inline bpf_get_current_task() and bpf_get_current_task_btf()
2026-06-02 20:58 ` [PATCH bpf-next 2/2] bpf, riscv: inline bpf_get_current_task() and bpf_get_current_task_btf() Varun R Mallya
@ 2026-06-03 7:16 ` Björn Töpel
0 siblings, 0 replies; 6+ messages in thread
From: Björn Töpel @ 2026-06-03 7:16 UTC (permalink / raw)
To: Varun R Mallya
Cc: bpf, linux-riscv, ast, daniel, andrii, eddyz87, memxor, pjw,
palmer, aou, puranjay, menglong8.dong, martin.lau, song,
yonghong.song, jolsa, pulehui, alex, linux-kernel,
linux-kselftest
On Tue, 2 Jun 2026 at 22:59, Varun R Mallya <varunrmallya@gmail.com> wrote:
>
> On RISC-V, the current task pointer is stored in the thread pointer
> register (tp). Emit a single `mv a5, tp` instead of a full helper
> call for BPF_FUNC_get_current_task and BPF_FUNC_get_current_task_btf.
>
> Register bpf_jit_inlines_helper_call() entries for both helpers so the
> verifier treats them as inlined, and add the expected `mv a5, tp`
> annotation to the riscv64 selftests.
>
> The following show changes before and after this patch.
>
> Before patch:
>
> auipc t1,0x817a # load upper PC-relative address
> jalr -2004(t1) # call bpf_get_current_task helper
> mv a5,a0 # move return value to BPF_REG_0
>
> After patch:
>
> mv a5,tp # directly: a5 = current (tp = thread pointer)
>
> Benchmark (bpf_prog_test_run wrapping bpf_get_current_task in loop,
> batch=100, 10s, QEMU RISC-V):
>
> | runs/sec | helper-calls/sec | ns/call
> -------------+-----------+------------------+---------
> Before patch | 173,490 | 17,349,090 | 57
> After patch | 320,497 | 32,049,780 | 31
> -------------+-----------+------------------+---------
> Improvement | +84.7% | +84.7% | -45.6%
>
> Signed-off-by: Varun R Mallya <varunrmallya@gmail.com>
Acked-by: Björn Töpel <bjorn@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH bpf-next 0/2] RISC-V JIT support for bpf_get_current_task/_btf
2026-06-02 20:58 [PATCH bpf-next 0/2] RISC-V JIT support for bpf_get_current_task/_btf Varun R Mallya
2026-06-02 20:58 ` [PATCH bpf-next 1/2] selftests/bpf: use host CPU features in JIT disassembler Varun R Mallya
2026-06-02 20:58 ` [PATCH bpf-next 2/2] bpf, riscv: inline bpf_get_current_task() and bpf_get_current_task_btf() Varun R Mallya
@ 2026-06-05 22:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-06-05 22:30 UTC (permalink / raw)
To: Varun R Mallya
Cc: bpf, linux-riscv, ast, daniel, andrii, eddyz87, memxor, bjorn,
pjw, palmer, aou, puranjay, menglong8.dong, martin.lau, song,
yonghong.song, jolsa, pulehui, alex, linux-kernel,
linux-kselftest
Hello:
This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Wed, 3 Jun 2026 02:28:45 +0530 you wrote:
> These two patches add support for the bpf_get_current_task and
> bpf_get_current_task_btf kfuncs in RISC-V JIT and add a selftest.
>
> The first patch adds support for cpu and feature detection on
> the JIT disassembly helper function as RISC-V JITed code was not
> being disassembled using `LLVMCreateDisasm` as it was missing the
> "+c" CPU feature and JITed code contained RISC-V Compressed (C)
> Extension. This patch generalizes that to detect CPU features and
> enables testing on more RISC-V JIT work ahead.
>
> [...]
Here is the summary with links:
- [bpf-next,1/2] selftests/bpf: use host CPU features in JIT disassembler
https://git.kernel.org/bpf/bpf-next/c/557d0cc3f252
- [bpf-next,2/2] bpf, riscv: inline bpf_get_current_task() and bpf_get_current_task_btf()
https://git.kernel.org/bpf/bpf-next/c/6d13ddb1d465
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread