[PATCH v2] RDMA/irdma: do not acquire zero-reference listeners
From: Jaeyeong Lee
Date: Wed Dec 02 2026 - 22:16:14 EST
irdma_dec_refcnt_listen() can drop a listener reference count to zero
before taking listen_list_lock to remove it from the lookup list. During
this window, irdma_find_listener() can find the listener and call
refcount_inc() on the zero count. It then returns a listener that the
teardown path is about to free.
Use refcount_inc_not_zero() while holding listen_list_lock. If the
listener has reached zero, skip it and let the teardown path remove it
from the list.
Fixes: 146b9756f14c ("RDMA/irdma: Add connection manager")
Signed-off-by: Jaeyeong Lee <lee@xxxxxxxxxxx>
---
Changes since v1:
- Avoid acquiring a zero reference in the lookup path instead of moving
the final decrement under listen_list_lock.
drivers/infiniband/hw/irdma/cm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/irdma/cm.c b/drivers/infiniband/hw/irdma/cm.c
index bc30e465c..8a84b6aef 100644
--- a/drivers/infiniband/hw/irdma/cm.c
+++ b/drivers/infiniband/hw/irdma/cm.c
@@ -1487,7 +1487,8 @@ irdma_find_listener(struct irdma_cm_core *cm_core, u32 *dst_addr, bool ipv4,
if (!memcmp(listen_addr, ip_zero, sizeof(listen_addr)) ||
(!memcmp(listen_addr, dst_addr, sizeof(listen_addr)) &&
vlan_id == listen_node->vlan_id)) {
- refcount_inc(&listen_node->refcnt);
+ if (!refcount_inc_not_zero(&listen_node->refcnt))
+ continue;
spin_unlock_irqrestore(&cm_core->listen_list_lock,
flags);
trace_irdma_find_listener(listen_node);
--
2.43.0