[PATCH bpf-next] selftests/bpf: Enable signed division and modulo overflow tests for LoongArch
From: Tiezhu Yang
Date: Tue Oct 27 2026 - 00:16:49 EST
The LoongArch hardware divider handles signed overflow boundaries (such
as INT_MIN/-1 or LLONG_MIN/-1) natively and perfectly well on physical
silicon: (1)for division operations, it naturally returns the dividend
itself; (2)for modulo operations, it returns 0. Thus enable the signed
division and modulo overflow tests for LoongArch in verifier_sdiv.c.
Before:
$ sudo ./test_progs -t verifier_sdiv | grep "MIN/-1"
#731/121 verifier_sdiv/SDIV64, overflow r/r, LLONG_MIN/-1:SKIP
#731/123 verifier_sdiv/SDIV64, overflow r/i, LLONG_MIN/-1:SKIP
#731/125 verifier_sdiv/SDIV32, overflow r/r, INT_MIN/-1:SKIP
#731/127 verifier_sdiv/SDIV32, overflow r/i, INT_MIN/-1:SKIP
#731/129 verifier_sdiv/SMOD64, overflow r/r, LLONG_MIN/-1:SKIP
#731/131 verifier_sdiv/SMOD64, overflow r/i, LLONG_MIN/-1:SKIP
#731/133 verifier_sdiv/SMOD32, overflow r/r, INT_MIN/-1:SKIP
#731/135 verifier_sdiv/SMOD32, overflow r/i, INT_MIN/-1:SKIP
After:
$ sudo ./test_progs -t verifier_sdiv | grep "MIN/-1"
#731/121 verifier_sdiv/SDIV64, overflow r/r, LLONG_MIN/-1:OK
#731/123 verifier_sdiv/SDIV64, overflow r/i, LLONG_MIN/-1:OK
#731/125 verifier_sdiv/SDIV32, overflow r/r, INT_MIN/-1:OK
#731/127 verifier_sdiv/SDIV32, overflow r/i, INT_MIN/-1:OK
#731/129 verifier_sdiv/SMOD64, overflow r/r, LLONG_MIN/-1:OK
#731/131 verifier_sdiv/SMOD64, overflow r/i, LLONG_MIN/-1:OK
#731/133 verifier_sdiv/SMOD32, overflow r/r, INT_MIN/-1:OK
#731/135 verifier_sdiv/SMOD32, overflow r/i, INT_MIN/-1:OK
Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
---
tools/testing/selftests/bpf/progs/verifier_sdiv.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_sdiv.c b/tools/testing/selftests/bpf/progs/verifier_sdiv.c
index d6cbe1e27fd6..5e8bf781e073 100644
--- a/tools/testing/selftests/bpf/progs/verifier_sdiv.c
+++ b/tools/testing/selftests/bpf/progs/verifier_sdiv.c
@@ -775,6 +775,7 @@ SEC("socket")
__description("SDIV64, overflow r/r, LLONG_MIN/-1")
__success __retval(1)
__arch_x86_64
+__arch_loongarch
__xlated("0: r2 = 0x8000000000000000")
__xlated("2: r3 = -1")
__xlated("3: r4 = r2")
@@ -839,6 +840,7 @@ SEC("socket")
__description("SDIV64, overflow r/i, LLONG_MIN/-1")
__success __retval(1)
__arch_x86_64
+__arch_loongarch
__xlated("0: r2 = 0x8000000000000000")
__xlated("2: r4 = r2")
__xlated("3: r2 = -r2")
@@ -887,6 +889,7 @@ SEC("socket")
__description("SDIV32, overflow r/r, INT_MIN/-1")
__success __retval(1)
__arch_x86_64
+__arch_loongarch
__xlated("0: w2 = -2147483648")
__xlated("1: w3 = -1")
__xlated("2: w4 = w2")
@@ -953,6 +956,7 @@ SEC("socket")
__description("SDIV32, overflow r/i, INT_MIN/-1")
__success __retval(1)
__arch_x86_64
+__arch_loongarch
__xlated("0: w2 = -2147483648")
__xlated("1: w4 = w2")
__xlated("2: w2 = -w2")
@@ -1001,6 +1005,7 @@ SEC("socket")
__description("SMOD64, overflow r/r, LLONG_MIN/-1")
__success __retval(0)
__arch_x86_64
+__arch_loongarch
__xlated("0: r2 = 0x8000000000000000")
__xlated("2: r3 = -1")
__xlated("3: r4 = r2")
@@ -1061,6 +1066,7 @@ SEC("socket")
__description("SMOD64, overflow r/i, LLONG_MIN/-1")
__success __retval(0)
__arch_x86_64
+__arch_loongarch
__xlated("0: r2 = 0x8000000000000000")
__xlated("2: r4 = r2")
__xlated("3: w2 = 0")
@@ -1105,6 +1111,7 @@ SEC("socket")
__description("SMOD32, overflow r/r, INT_MIN/-1")
__success __retval(0)
__arch_x86_64
+__arch_loongarch
__xlated("0: w2 = -2147483648")
__xlated("1: w3 = -1")
__xlated("2: w4 = w2")
@@ -1169,6 +1176,7 @@ SEC("socket")
__description("SMOD32, overflow r/i, INT_MIN/-1")
__success __retval(0)
__arch_x86_64
+__arch_loongarch
__xlated("0: w2 = -2147483648")
__xlated("1: w4 = w2")
__xlated("2: w2 = 0")
--
2.42.0