* [PATCH bpf-next] riscv, bpf: Fix missing sign-ext for signed 1-byte and 2-byte kfunc args
@ 2026-08-14 6:47 Pu Lehui
2026-08-14 6:57 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Pu Lehui @ 2026-08-14 6:47 UTC (permalink / raw)
To: bpf, linux-riscv, linux-kernel
Cc: Björn Töpel, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
Emil Tsalapatis, Ihor Solodrai, Puranjay Mohan, Paul Walmsley,
Palmer Dabbelt, Alexandre Ghiti, Pu Lehui
From: Pu Lehui <pulehui@huawei.com>
On RV64, the ABI requires sign-extension for signed 1-byte and 2-byte
kfunc args. However, the RV64 JIT currently does not perform
sign-extension for such kfunc args.
Before commit 7ce090afbf72 ("bpf: Infer zext_dst based on static
register liveness analysis"), state pruning could potentially omit
zero-extension of 32-bit subregisters, which inadvertently masked the
above issue by making the args appear as if they had been properly
sign-extended. After that commit, the problem is exposed, causing the
kfunc_call/kfunc_call_test4 selftest to fail.
Fix this by extending the existing sign-extension logic to handle signed
1-byte and 2-byte kfunc args as well.
Fixes: 443574b03387 ("riscv, bpf: Fix kfunc parameters incompatibility between bpf and riscv abi")
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
arch/riscv/net/bpf_jit_comp64.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 2504df1fa111..74efe4b138d2 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -1823,9 +1823,10 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
for (idx = 0; idx < fm->nr_args; idx++) {
u8 reg = bpf_to_rv_reg(BPF_REG_1 + idx, ctx);
+ bool sign = fm->arg_flags[idx] & BTF_FMODEL_SIGNED_ARG;
- if (fm->arg_size[idx] == sizeof(int))
- emit_sextw(reg, reg, ctx);
+ if (sign_extend(reg, reg, fm->arg_size[idx], sign, ctx))
+ return -EINVAL;
}
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] riscv, bpf: Fix missing sign-ext for signed 1-byte and 2-byte kfunc args
2026-08-14 6:47 [PATCH bpf-next] riscv, bpf: Fix missing sign-ext for signed 1-byte and 2-byte kfunc args Pu Lehui
@ 2026-08-14 6:57 ` sashiko-bot
2026-08-14 7:05 ` Pu Lehui
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-08-14 6:57 UTC (permalink / raw)
To: Pu Lehui; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch introduces a call to a `sign_extend()` function that is undeclared and undefined, resulting in a compilation failure.
--
--- Patch [1]: [PATCH bpf-next] riscv, bpf: Fix missing sign-ext for signed 1-byte and 2-byte kfunc args ---
commit 47567ad8c96e02d677f1ae5123565efa9cf1b55f
Author: Pu Lehui <pulehui@huawei.com>
riscv, bpf: Fix missing sign-ext for signed 1-byte and 2-byte kfunc args
This commit updates the RISC-V BPF JIT to sign-extend 1-byte and 2-byte
kfunc arguments as required by the RV64 ABI. This addresses an issue exposed
by recent state pruning liveness analysis changes.
> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> index 10e01ff06312d..0c6de02eb33a8 100644
> --- a/arch/riscv/net/bpf_jit_comp64.c
> +++ b/arch/riscv/net/bpf_jit_comp64.c
> @@ -1784,9 +1784,10 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
>
> for (idx = 0; idx < fm->nr_args; idx++) {
> u8 reg = bpf_to_rv_reg(BPF_REG_1 + idx, ctx);
> + bool sign = fm->arg_flags[idx] & BTF_FMODEL_SIGNED_ARG;
>
> - if (fm->arg_size[idx] == sizeof(int))
> - emit_sextw(reg, reg, ctx);
> + if (sign_extend(reg, reg, fm->arg_size[idx], sign, ctx))
> + return -EINVAL;
[Severity: Low]
Is sign_extend() declared in this context?
It appears this function might be missing from this file or requires an
unapplied prerequisite patch. Looking through the source, there doesn't
appear to be a sign_extend() function defined in the RISC-V BPF JIT code
that matches this 5-argument signature. Will this cause a build failure due
to an undeclared function?
> }
> }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260814064726.3607615-1-pulehui@huaweicloud.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] riscv, bpf: Fix missing sign-ext for signed 1-byte and 2-byte kfunc args
2026-08-14 6:57 ` sashiko-bot
@ 2026-08-14 7:05 ` Pu Lehui
0 siblings, 0 replies; 3+ messages in thread
From: Pu Lehui @ 2026-08-14 7:05 UTC (permalink / raw)
To: sashiko-reviews, Pu Lehui; +Cc: bpf
On 2026/8/14 14:57, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] The patch introduces a call to a `sign_extend()` function that is undeclared and undefined, resulting in a compilation failure.
> --
>
> --- Patch [1]: [PATCH bpf-next] riscv, bpf: Fix missing sign-ext for signed 1-byte and 2-byte kfunc args ---
> commit 47567ad8c96e02d677f1ae5123565efa9cf1b55f
> Author: Pu Lehui <pulehui@huawei.com>
>
> riscv, bpf: Fix missing sign-ext for signed 1-byte and 2-byte kfunc args
>
> This commit updates the RISC-V BPF JIT to sign-extend 1-byte and 2-byte
> kfunc arguments as required by the RV64 ABI. This addresses an issue exposed
> by recent state pruning liveness analysis changes.
>
>> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
>> index 10e01ff06312d..0c6de02eb33a8 100644
>> --- a/arch/riscv/net/bpf_jit_comp64.c
>> +++ b/arch/riscv/net/bpf_jit_comp64.c
>> @@ -1784,9 +1784,10 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
>>
>> for (idx = 0; idx < fm->nr_args; idx++) {
>> u8 reg = bpf_to_rv_reg(BPF_REG_1 + idx, ctx);
>> + bool sign = fm->arg_flags[idx] & BTF_FMODEL_SIGNED_ARG;
>>
>> - if (fm->arg_size[idx] == sizeof(int))
>> - emit_sextw(reg, reg, ctx);
>> + if (sign_extend(reg, reg, fm->arg_size[idx], sign, ctx))
>> + return -EINVAL;
>
> [Severity: Low]
> Is sign_extend() declared in this context?
No, sign_extend() has been add by commit fd2e08128944a("riscv, bpf: Sign
extend struct ops return values properly"), and there is no building
failure.
>
> It appears this function might be missing from this file or requires an
> unapplied prerequisite patch. Looking through the source, there doesn't
> appear to be a sign_extend() function defined in the RISC-V BPF JIT code
> that matches this 5-argument signature. Will this cause a build failure due
> to an undeclared function?
>
>> }
>> }
>>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-14 7:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 6:47 [PATCH bpf-next] riscv, bpf: Fix missing sign-ext for signed 1-byte and 2-byte kfunc args Pu Lehui
2026-08-14 6:57 ` sashiko-bot
2026-08-14 7:05 ` Pu Lehui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox