Thread (10 messages) 10 messages, 3 authors, 24d ago

Re: [PATCH rdma-next 4/4] RDMA/hns: Use unsigned comparison in the CQ cleanup loop

flat view

From: sashiko-bot@kernel.org
Date: 2026-09-15 15:44:37

From: Yishai Hadas <yishaih@nvidia.com>

__hns_roce_v2_cq_clean() sweeps the CQ backwards from the producer
index down to the consumer index:

  while ((int) --prod_index - (int) hr_cq->cons_index >= 0)

Both indexes are free running u32 counters, so the comparison has to
be done modulo 2^32.  Casting each operand to int and subtracting
does not do that: the subtraction overflows whenever the two indexes
straddle 2^31, which is undefined behaviour, and a compiler that
assumes signed overflow cannot occur is free to discard the
subtraction and fold the expression into a plain signed comparison.
That comparison is not wraparound safe.

[ ... ]
of whether either counter has wrapped, because the loop no longer
compares magnitudes at all.

Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Signed-off-by: Edward Srouji <redacted>
Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260915-fix-cq-cleanup-v1-0-e991944cf898@nvidia.com?part=4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help