In __rte_lpm_lookup_vec() (SVE), the main loop condition was
for (i = 0; i < n - vl; i += vl)
where n is uint32_t and vl is uint64_t. When n < vl the subtraction
is done in 64-bit unsigned arithmetic and wraps to a very large
value, so the loop does not terminate at the end of the input array.
It reads past the end of ips[] resulting in a segmentation fault.
Rewrite the condition as "i + vl < n" so no unsigned wrap occurs. The
existing tail handling with svwhilelt_b32() covers the remaining
elements, including n == 0.
Fixes: b29ccbea24 ("lpm: use SVE for bulk lookup")
Cc: [email protected]
Signed-off-by: Rupesh Chiluka <[email protected]>
---
lib/lpm/rte_lpm_sve.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/lpm/rte_lpm_sve.h b/lib/lpm/rte_lpm_sve.h
index 52b8bd4940..6113269120 100644
--- a/lib/lpm/rte_lpm_sve.h
+++ b/lib/lpm/rte_lpm_sve.h
@@ -26,7 +26,7 @@ __rte_lpm_lookup_vec(const struct rte_lpm *lpm, const
uint32_t *ips,
for (i = 0; i < n; i++)
next_hops[i] = 0;
- for (i = 0; i < n - vl; i += vl) {
+ for (i = 0; i + vl < n; i += vl) {
v_ip = svld1(pg, &ips[i]);
/* Get indices for tbl24[] */
v_idx = svlsr_x(pg, v_ip, 8);
--
2.43.0