BPF List
 help / color / mirror / Atom feed
* [PATCH] bpf: remove trunctaiton warning in BPF_LD_IMM64_RAW
@ 2024-03-14 10:31 Ben Dooks
  2024-03-14 19:58 ` Stanislav Fomichev
  2024-03-14 22:08 ` Alexei Starovoitov
  0 siblings, 2 replies; 3+ messages in thread
From: Ben Dooks @ 2024-03-14 10:31 UTC (permalink / raw)
  To: ast, daniel; +Cc: bpf, Ben Dooks

When building W=1, the following warningds get generated by lib/test_bpf.c
due to the BPF_LD_IMM64_RAW() truncating a 64bit to 32bit value without
a specific mask to do so.

lib/test_bpf.c:6441:25: warning: cast truncates bits from constant value (ffffffff0000 becomes ffff0000)
lib/test_bpf.c:6442:25: warning: cast truncates bits from constant value (ffffffff0000 becomes ffff0000)
lib/test_bpf.c:6473:25: warning: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
lib/test_bpf.c:6489:25: warning: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
lib/test_bpf.c:6490:25: warning: cast truncates bits from constant value (123456780a0c0e0 becomes 80a0c0e0)
lib/test_bpf.c:6599:25: warning: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
lib/test_bpf.c:6637:25: warning: cast truncates bits from constant value (ffffffff0000 becomes ffff0000)

(more warnings truncated)

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
 include/linux/filter.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/filter.h b/include/linux/filter.h
index c99bc3df2d28..c1ff6511f365 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -238,7 +238,7 @@ static inline bool insn_is_zext(const struct bpf_insn *insn)
 		.dst_reg = DST,					\
 		.src_reg = SRC,					\
 		.off   = 0,					\
-		.imm   = (__u32) (IMM) }),			\
+		.imm   = (__u32) ((IMM) & (__u64)0xffffffff) }), \
 	((struct bpf_insn) {					\
 		.code  = 0, /* zero is reserved opcode */	\
 		.dst_reg = 0,					\
-- 
2.37.2.352.g3c44437643


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-14 22:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-14 10:31 [PATCH] bpf: remove trunctaiton warning in BPF_LD_IMM64_RAW Ben Dooks
2024-03-14 19:58 ` Stanislav Fomichev
2024-03-14 22:08 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox