RDMA/srpt: Clamp the CQ size request to max_cqe
Subsystems (3)
PATCH v2 1/1 RDMA/srpt: Clamp the CQ size request to max_cqe
srpt_create_ch_ib() asks ib_cq_pool_get() for ch->rq_size + sq_size completion queue entries. rq_size is bounded by max_qp_wr, but sq_size comes from the per-port srp_sq_size configfs attribute, which is only validated against MAX_SRPT_SRQ_SIZE (65535) and never compared with dev->attrs.max_cqe. The largest configuration srpt accepts therefore asks for 128 + 65535 = 65663 entries, while rxe caps max_cqe at 32767 and cxgb4 and ionic are in the same range.
Such a request cannot be met, and ib_cq_pool_get() does not reject it. It clamps every CQ it creates to max_cqe, so no CQ it adds to the pool can ever fit the request, and it keeps allocating batches until the allocation fails. A single SRP login against such a target exhausts memory:
Out of memory and no killable processes...
Kernel panic - not syncing: System is deadlocked on memory Workqueue: ib_cm cm_work_handler Call Trace: __vmalloc_node_range_noprof vmalloc_user_noprof rxe_queue_init rxe_cq_from_init rxe_create_cq __ib_alloc_cq ib_cq_pool_get srpt_cm_req_recv.cold
Before commit c804af2c1d31 ("IB/srpt: use new shared CQ mechanism") the same request went to ib_alloc_cq_any(), which rejected it with -EINVAL.
The existing backoff, which halves sq_size when queue pair creation fails, only runs after ib_cq_pool_get() has returned, so shrink sq_size before asking for the CQ. rq_size never exceeds MAX_SRPT_RQ_SIZE (128), far below the max_cqe any device reports in practice, so the subtraction does not underflow. With the clamp the same login proceeds exactly like a correctly sized target.
---
Changes since v1:
- Move the fix from the RDMA core to ib_srpt, as requested by Leon Romanovsky.
- Clamp sq_size before the CQ request instead of rejecting oversized requests in ib_cq_pool_get().
v1: https://lore.kernel.org/linux-rdma/[email protected]/
drivers/infiniband/ulp/srpt/ib_srpt.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/infiniband/ulp/srpt/ib_srpt.c +7 -0
@@ -1867,6 +1867,13 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)if (!qp_init) goto out; +/* The send and receive queues share a single CQ. */ +if (ch->rq_size + sq_size > attrs->max_cqe) { + sq_size = attrs->max_cqe - ch->rq_size; +pr_debug ("reduced sq_size to %u because max_cqe is %u\n" , + sq_size, attrs->max_cqe); + } + retry: ch->cq =ib_cq_pool_get (sdev->device, ch->rq_size + sq_size,-1 ,IB_POLL_WORKQUEUE );
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
Signature · 1 line
2.53.0
Quoted 56 lines · Serhat Kumral
srpt_create_ch_ib()asksib_cq_pool_get()forch->rq_size+sq_sizecompletion queue entries.rq_sizeis bounded bymax_qp_wr, butsq_sizecomes from the per-portsrp_sq_sizeconfigfs attribute, which is only validated againstMAX_SRPT_SRQ_SIZE(65535) and never compared withdev->attrs.max_cqe. The largest configuration srpt accepts therefore asks for 128 + 65535 = 65663 entries, while rxe capsmax_cqeat 32767 and cxgb4 and ionic are in the same range.Such a request cannot be met, and
ib_cq_pool_get()does not reject it. It clamps every CQ it creates tomax_cqe, so no CQ it adds to the pool can ever fit the request, and it keeps allocating batches until the allocation fails. A single SRP login against such a target exhausts memory:Out of memory and no killable processes...
Kernel panic - not syncing: System is deadlocked on memory Workqueue: ib_cm cm_work_handler Call Trace: __vmalloc_node_range_noprof vmalloc_user_noprof rxe_queue_init rxe_cq_from_init rxe_create_cq __ib_alloc_cq ib_cq_pool_get srpt_cm_req_recv.coldBefore commit
c804af2c1d31("IB/srpt: use new shared CQ mechanism") the same request went toib_alloc_cq_any(), which rejected it with-EINVAL.The existing backoff, which halves
sq_sizewhen queue pair creation fails, only runs afterib_cq_pool_get()has returned, so shrinksq_sizebefore asking for the CQ.rq_sizenever exceedsMAX_SRPT_RQ_SIZE(128), far below themax_cqeany device reports in practice, so the subtraction does not underflow. With the clamp the same login proceeds exactly like a correctly sized target.Fixes c804af2c1d31 ("IB/srpt: use new shared CQ mechanism")Signed-off-by Serhat Kumral <[email protected]>---
Changes since v1:
- Move the fix from the RDMA core toib_srpt, as requested by Leon Romanovsky.
- Clampsq_sizebefore the CQ request instead of rejecting oversized requests inib_cq_pool_get().v1: https://lore.kernel.org/linux-rdma/[email protected]/
drivers/infiniband/ulp/srpt/ib_srpt.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/infiniband/ulp/srpt/ib_srpt.c +0
-0
drivers/infiniband/ulp/srpt/ib_srpt.c static int srpt_create_ch_ib(struct srpt_rdma_ch *ch) · line 1872
Quoted 6 lines
drivers/infiniband/ulp/srpt/ib_srpt.c +3
-0@@ -1867,6 +1867,13 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)if (!qp_init) goto out; +/* The send and receive queues share a single CQ. */ +if (ch->rq_size + sq_size > attrs->max_cqe) { + sq_size = attrs->max_cqe - ch->rq_size;
I don't think that Sashiko concern is real
https://sashiko.dev/#/patchset/[email protected]
but it is worth to write it in a way to avoid triggering this warning.
For example
/* Catch drivers that incorrectly set ch->rq_size */ WARN_ON_ONCE(attrs->max_cqe < ch->rq_size)
Thanks
Quoted 12 lines
drivers/infiniband/ulp/srpt/ib_srpt.c +4
-0+pr_debug ("reduced sq_size to %u because max_cqe is %u\n" , + sq_size, attrs->max_cqe); + } + retry: ch->cq =ib_cq_pool_get (sdev->device, ch->rq_size + sq_size,-1 ,IB_POLL_WORKQUEUE );base-commit:
cee9395acd8043be0644b25c34bfa86623f2b935Signature · 1 line
2.53.0