summaryrefslogtreecommitdiff
path: root/tools/testing
diff options
context:
space:
mode:
authorCupertino Miranda <cupertino.miranda@oracle.com>2026-03-04 22:50:18 +0300
committerAlexei Starovoitov <ast@kernel.org>2026-03-10 21:51:18 +0300
commit6a1c9a442f634e7b95c5ad0927870335b1ce299e (patch)
tree977d0899d15ac4412007b7c2df54b734e8d5763b /tools/testing
parent2f4cb53eed448c1aeb6f4b40cf9c810716d8218c (diff)
downloadlinux-6a1c9a442f634e7b95c5ad0927870335b1ce299e.tar.xz
selftests/bpf: tests to non_null ptr detection using register operand in JEQ/JNE
This patch adds two tests to check non_null ptr detection when using JEQ and JNE have a register in second operand, and its value is known to be 0. Signed-off-by: Cupertino Miranda <cupertino.miranda@oracle.com> Cc: David Faust <david.faust@oracle.com> Cc: Jose Marchesi <jose.marchesi@oracle.com> Cc: Elena Zannoni <elena.zannoni@oracle.com> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/r/20260304195018.181396-4-cupertino.miranda@oracle.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/bpf/progs/verifier_jeq_infer_not_null.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/verifier_jeq_infer_not_null.c b/tools/testing/selftests/bpf/progs/verifier_jeq_infer_not_null.c
index bf16b00502f2..3d1e8de4390c 100644
--- a/tools/testing/selftests/bpf/progs/verifier_jeq_infer_not_null.c
+++ b/tools/testing/selftests/bpf/progs/verifier_jeq_infer_not_null.c
@@ -210,4 +210,58 @@ l0_%=: /* return 0; */ \
: __clobber_all);
}
+/* Verified that we can detect the pointer as non_null when comparing with
+ * register with value 0. JEQ test case.
+ */
+SEC("xdp")
+__success __log_level(2)
+/* to make sure the branch is not falsely predicted*/
+__msg("r0 = *(u32 *)(r0 +0)")
+__msg("from 7 to 9")
+__naked void jeq_reg_reg_null_check(void)
+{
+ asm volatile (" \
+ *(u32*)(r10 - 8) = 0; \
+ r1 = %[map_xskmap] ll; \
+ r2 = r10; \
+ r2 += -8; \
+ call %[bpf_map_lookup_elem]; \
+ r1 = 0; \
+ if r0 == r1 goto 1f; \
+ r0 = *(u32*)(r0 +0); \
+1: r0 = 0; \
+ exit; \
+" :
+ : __imm(bpf_map_lookup_elem),
+ __imm_addr(map_xskmap)
+ : __clobber_all);
+}
+
+/* Same as above but for JNE.
+ */
+SEC("xdp")
+__success __log_level(2)
+/* to make sure the branch is not falsely predicted*/
+__msg("r0 = *(u32 *)(r0 +0)")
+__msg("from 7 to 9")
+__naked void jne_reg_reg_null_check(void)
+{
+ asm volatile (" \
+ *(u32*)(r10 - 8) = 0; \
+ r1 = %[map_xskmap] ll; \
+ r2 = r10; \
+ r2 += -8; \
+ call %[bpf_map_lookup_elem]; \
+ r1 = 0; \
+ if r0 != r1 goto 1f; \
+ goto 2f; \
+1: r0 = *(u32*)(r0 +0); \
+2: r0 = 0; \
+ exit; \
+" :
+ : __imm(bpf_map_lookup_elem),
+ __imm_addr(map_xskmap)
+ : __clobber_all);
+}
+
char _license[] SEC("license") = "GPL";