[PATCH v0 3/3] selftests/bpf: Extend tests with more coverage for sign extension

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This commit adds a few more tests related to tnum_scast that explicitly
check cases with known / unknown sign bit, as well as values that cross
zero (going from negative to positive).

Signed-off-by: Dimitar Kanaliev <dimitar.kanaliev@xxxxxxxxxxxxxx>
---
 .../selftests/bpf/progs/verifier_movsx.c      | 73 +++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c
index 994bbc346d25..20abeec09dee 100644
--- a/tools/testing/selftests/bpf/progs/verifier_movsx.c
+++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c
@@ -327,6 +327,79 @@ label_%=: 	                                        \
 	: __clobber_all);
 }
 
+SEC("socket")
+__description("MOV64SX, S8, unknown value")
+__success __success_unpriv __retval(1)
+__naked void mov64sx_s8_unknown(void)
+{
+	asm volatile ("                                      \
+	call %[bpf_get_prandom_u32];                         \
+	r1 = r0;                                             \
+	r1 &= 0xFF;      			             \
+	r1 = (s8)r1;  					     \
+	if r1 s>= -128 goto l0_%=;                           \
+	r0 = 0;                                              \
+	exit;                                                \
+l0_%=:                                                       \
+	if r1 s<= 127 goto l1_%=;                            \
+	r0 = 0;                                              \
+	exit;                                                \
+l1_%=:                                                       \
+	r0 = 1;                                              \
+	exit;                                                \
+"	:
+	: __imm(bpf_get_prandom_u32)
+	: __clobber_all);
+}
+
+SEC("socket")
+	__description("MOV64SX, S8, sign bit unknown")
+	__success __success_unpriv __retval(1)
+__naked void mov64sx_s8_sign_unknown(void)
+{
+	asm volatile ("                                      \
+	call %[bpf_get_prandom_u32];                         \
+	r1 = r0;                                             \
+	r1 &= 0x7F;                 			     \
+	r1 |= 0x80;        				     \
+	r1 = (s8)r1;       				     \
+	if r1 s>= -128 goto l0_%=;                           \
+	r0 = 0;                                              \
+	exit;                                                \
+l0_%=:                                                       \
+	if r1 s<= 127 goto l1_%=;                            \
+	r0 = 0;                                              \
+	exit;                                                \
+l1_%=:                                                       \
+	r0 = 1;                                              \
+	exit;                                                \
+	"   :
+	: __imm(bpf_get_prandom_u32)
+	: __clobber_all);
+}
+
+SEC("socket")
+	__description("MOV64SX, S8, value crossing zero")
+	__success __success_unpriv __retval(1)
+__naked void mov64sx_s8_cross_zero(void)
+{
+	asm volatile ("                                      \
+	call %[bpf_get_prandom_u32];                         \
+	r1 = r0;                                             \
+	r1 &= 0xFF;      			             \
+	r1 = (s8)r1;             			     \
+	if r1 s> -10 goto l0_%=;                             \
+	if r1 s< 10 goto l0_%=;                              \
+	r0 = 0;                                              \
+	exit;                                                \
+l0_%=:                                               	     \
+	r0 = 1;                                              \
+	exit;                                                \
+	"   :
+	: __imm(bpf_get_prandom_u32)
+	: __clobber_all);
+}
+
 #else
 
 SEC("socket")
-- 
2.43.0





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux