* [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning
@ 2025-02-18 8:02 Song Liu
2025-02-20 12:34 ` Xu Kuohai
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Song Liu @ 2025-02-18 8:02 UTC (permalink / raw)
To: bpf; +Cc: daniel, ast, puranjay, xukuohai, kernel-team, song, Breno Leitao
With UBSAN, test_bpf.ko triggers warnings like:
UBSAN: negation-overflow in arch/arm64/net/bpf_jit_comp.c:1333:28
negation of -2147483648 cannot be represented in type 's32' (aka 'int'):
Silent these warnings by casting imm to u32 first.
Fixes: fd868f148189 ("bpf, arm64: Optimize ADD,SUB,JMP BPF_K using arm64 add/sub immediates")
Reported-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Song Liu <song@kernel.org>
---
arch/arm64/net/bpf_jit_comp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 8446848edddb..7409c8acbde3 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -272,7 +272,7 @@ static inline void emit_a64_add_i(const bool is64, const int dst, const int src,
{
if (is_addsub_imm(imm)) {
emit(A64_ADD_I(is64, dst, src, imm), ctx);
- } else if (is_addsub_imm(-imm)) {
+ } else if (is_addsub_imm(-(u32)imm)) {
emit(A64_SUB_I(is64, dst, src, -imm), ctx);
} else {
emit_a64_mov_i(is64, tmp, imm, ctx);
@@ -1159,7 +1159,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
case BPF_ALU64 | BPF_SUB | BPF_K:
if (is_addsub_imm(imm)) {
emit(A64_SUB_I(is64, dst, dst, imm), ctx);
- } else if (is_addsub_imm(-imm)) {
+ } else if (is_addsub_imm(-(u32)imm)) {
emit(A64_ADD_I(is64, dst, dst, -imm), ctx);
} else {
emit_a64_mov_i(is64, tmp, imm, ctx);
@@ -1330,7 +1330,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
case BPF_JMP32 | BPF_JSLE | BPF_K:
if (is_addsub_imm(imm)) {
emit(A64_CMP_I(is64, dst, imm), ctx);
- } else if (is_addsub_imm(-imm)) {
+ } else if (is_addsub_imm(-(u32)imm)) {
emit(A64_CMN_I(is64, dst, -imm), ctx);
} else {
emit_a64_mov_i(is64, tmp, imm, ctx);
--
2.43.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning
2025-02-18 8:02 [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning Song Liu
@ 2025-02-20 12:34 ` Xu Kuohai
2025-02-20 16:05 ` Song Liu
2025-02-21 9:39 ` Breno Leitao
2025-02-23 21:10 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Xu Kuohai @ 2025-02-20 12:34 UTC (permalink / raw)
To: Song Liu, bpf; +Cc: daniel, ast, puranjay, kernel-team, Breno Leitao
On 2/18/2025 4:02 PM, Song Liu wrote:
> With UBSAN, test_bpf.ko triggers warnings like:
>
> UBSAN: negation-overflow in arch/arm64/net/bpf_jit_comp.c:1333:28
> negation of -2147483648 cannot be represented in type 's32' (aka 'int'):
>
> Silent these warnings by casting imm to u32 first.
>
> Fixes: fd868f148189 ("bpf, arm64: Optimize ADD,SUB,JMP BPF_K using arm64 add/sub immediates")
I doubt this is a bug fix since I checked the build result and found nothing changed.
> Reported-by: Breno Leitao <leitao@debian.org>
> Signed-off-by: Song Liu <song@kernel.org>
> ---
> arch/arm64/net/bpf_jit_comp.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 8446848edddb..7409c8acbde3 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
> @@ -272,7 +272,7 @@ static inline void emit_a64_add_i(const bool is64, const int dst, const int src,
> {
> if (is_addsub_imm(imm)) {
> emit(A64_ADD_I(is64, dst, src, imm), ctx);
> - } else if (is_addsub_imm(-imm)) {
> + } else if (is_addsub_imm(-(u32)imm)) {
> emit(A64_SUB_I(is64, dst, src, -imm), ctx);
> } else {
> emit_a64_mov_i(is64, tmp, imm, ctx);
> @@ -1159,7 +1159,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
> case BPF_ALU64 | BPF_SUB | BPF_K:
> if (is_addsub_imm(imm)) {
> emit(A64_SUB_I(is64, dst, dst, imm), ctx);
> - } else if (is_addsub_imm(-imm)) {
> + } else if (is_addsub_imm(-(u32)imm)) {
> emit(A64_ADD_I(is64, dst, dst, -imm), ctx);
> } else {
> emit_a64_mov_i(is64, tmp, imm, ctx);
> @@ -1330,7 +1330,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
> case BPF_JMP32 | BPF_JSLE | BPF_K:
> if (is_addsub_imm(imm)) {
> emit(A64_CMP_I(is64, dst, imm), ctx);
> - } else if (is_addsub_imm(-imm)) {
> + } else if (is_addsub_imm(-(u32)imm)) {
> emit(A64_CMN_I(is64, dst, -imm), ctx);
> } else {
> emit_a64_mov_i(is64, tmp, imm, ctx);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning
2025-02-20 12:34 ` Xu Kuohai
@ 2025-02-20 16:05 ` Song Liu
0 siblings, 0 replies; 5+ messages in thread
From: Song Liu @ 2025-02-20 16:05 UTC (permalink / raw)
To: Xu Kuohai; +Cc: bpf, daniel, ast, puranjay, kernel-team, Breno Leitao
On Thu, Feb 20, 2025 at 4:35 AM Xu Kuohai <xukuohai@huaweicloud.com> wrote:
>
> On 2/18/2025 4:02 PM, Song Liu wrote:
> > With UBSAN, test_bpf.ko triggers warnings like:
> >
> > UBSAN: negation-overflow in arch/arm64/net/bpf_jit_comp.c:1333:28
> > negation of -2147483648 cannot be represented in type 's32' (aka 'int'):
> >
> > Silent these warnings by casting imm to u32 first.
> >
> > Fixes: fd868f148189 ("bpf, arm64: Optimize ADD,SUB,JMP BPF_K using arm64 add/sub immediates")
>
> I doubt this is a bug fix since I checked the build result and found nothing changed.
This is just to silence the UBSAN. We can remove the Fixes tag.
Thanks,
Song
> > Reported-by: Breno Leitao <leitao@debian.org>
> > Signed-off-by: Song Liu <song@kernel.org>
> > ---
> > arch/arm64/net/bpf_jit_comp.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> > index 8446848edddb..7409c8acbde3 100644
> > --- a/arch/arm64/net/bpf_jit_comp.c
> > +++ b/arch/arm64/net/bpf_jit_comp.c
> > @@ -272,7 +272,7 @@ static inline void emit_a64_add_i(const bool is64, const int dst, const int src,
> > {
> > if (is_addsub_imm(imm)) {
> > emit(A64_ADD_I(is64, dst, src, imm), ctx);
> > - } else if (is_addsub_imm(-imm)) {
> > + } else if (is_addsub_imm(-(u32)imm)) {
> > emit(A64_SUB_I(is64, dst, src, -imm), ctx);
> > } else {
> > emit_a64_mov_i(is64, tmp, imm, ctx);
> > @@ -1159,7 +1159,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
> > case BPF_ALU64 | BPF_SUB | BPF_K:
> > if (is_addsub_imm(imm)) {
> > emit(A64_SUB_I(is64, dst, dst, imm), ctx);
> > - } else if (is_addsub_imm(-imm)) {
> > + } else if (is_addsub_imm(-(u32)imm)) {
> > emit(A64_ADD_I(is64, dst, dst, -imm), ctx);
> > } else {
> > emit_a64_mov_i(is64, tmp, imm, ctx);
> > @@ -1330,7 +1330,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
> > case BPF_JMP32 | BPF_JSLE | BPF_K:
> > if (is_addsub_imm(imm)) {
> > emit(A64_CMP_I(is64, dst, imm), ctx);
> > - } else if (is_addsub_imm(-imm)) {
> > + } else if (is_addsub_imm(-(u32)imm)) {
> > emit(A64_CMN_I(is64, dst, -imm), ctx);
> > } else {
> > emit_a64_mov_i(is64, tmp, imm, ctx);
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning
2025-02-18 8:02 [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning Song Liu
2025-02-20 12:34 ` Xu Kuohai
@ 2025-02-21 9:39 ` Breno Leitao
2025-02-23 21:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Breno Leitao @ 2025-02-21 9:39 UTC (permalink / raw)
To: Song Liu; +Cc: bpf, daniel, ast, puranjay, xukuohai, kernel-team
On Tue, Feb 18, 2025 at 12:02:40AM -0800, Song Liu wrote:
> With UBSAN, test_bpf.ko triggers warnings like:
>
> UBSAN: negation-overflow in arch/arm64/net/bpf_jit_comp.c:1333:28
> negation of -2147483648 cannot be represented in type 's32' (aka 'int'):
>
> Silent these warnings by casting imm to u32 first.
>
> Fixes: fd868f148189 ("bpf, arm64: Optimize ADD,SUB,JMP BPF_K using arm64 add/sub immediates")
> Reported-by: Breno Leitao <leitao@debian.org>
> Signed-off-by: Song Liu <song@kernel.org>
Tested-by: Breno Leitao <leitao@debian.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning
2025-02-18 8:02 [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning Song Liu
2025-02-20 12:34 ` Xu Kuohai
2025-02-21 9:39 ` Breno Leitao
@ 2025-02-23 21:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-02-23 21:10 UTC (permalink / raw)
To: Song Liu; +Cc: bpf, daniel, ast, puranjay, xukuohai, kernel-team, leitao
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Tue, 18 Feb 2025 00:02:40 -0800 you wrote:
> With UBSAN, test_bpf.ko triggers warnings like:
>
> UBSAN: negation-overflow in arch/arm64/net/bpf_jit_comp.c:1333:28
> negation of -2147483648 cannot be represented in type 's32' (aka 'int'):
>
> Silent these warnings by casting imm to u32 first.
>
> [...]
Here is the summary with links:
- [bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning
https://git.kernel.org/bpf/bpf-next/c/239860828f86
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] 5+ messages in thread
end of thread, other threads:[~2025-02-23 21:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-18 8:02 [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning Song Liu
2025-02-20 12:34 ` Xu Kuohai
2025-02-20 16:05 ` Song Liu
2025-02-21 9:39 ` Breno Leitao
2025-02-23 21:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox