From: Leon Romanovsky <[email protected]> The CQ resize path must be protected from concurrent execution because it updates in-kernel objects. Some drivers did not provide any locking, leading to inconsistent behavior.
Rely on the core mutex for synchronization and drop the various ad‑hoc locking implementations in individual drivers. Signed-off-by: Leon Romanovsky <[email protected]> --- drivers/infiniband/core/uverbs_cmd.c | 1 + drivers/infiniband/core/uverbs_std_types_cq.c | 1 + drivers/infiniband/core/verbs.c | 2 ++ include/rdma/ib_verbs.h | 3 +++ 4 files changed, 7 insertions(+) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index b4b0c7c92fb1..1348ebd7a1c3 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -1067,6 +1067,7 @@ static int create_cq(struct uverbs_attr_bundle *attrs, cq->event_handler = ib_uverbs_cq_event_handler; cq->cq_context = ev_file ? &ev_file->ev_queue : NULL; atomic_set(&cq->usecnt, 0); + mutex_init(&cq->resize_mutex); rdma_restrack_new(&cq->res, RDMA_RESTRACK_CQ); rdma_restrack_set_name(&cq->res, NULL); diff --git a/drivers/infiniband/core/uverbs_std_types_cq.c b/drivers/infiniband/core/uverbs_std_types_cq.c index a12e3184dd5c..c572f528579d 100644 --- a/drivers/infiniband/core/uverbs_std_types_cq.c +++ b/drivers/infiniband/core/uverbs_std_types_cq.c @@ -195,6 +195,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)( */ cq->umem = umem; atomic_set(&cq->usecnt, 0); + mutex_init(&cq->resize_mutex); rdma_restrack_new(&cq->res, RDMA_RESTRACK_CQ); rdma_restrack_set_name(&cq->res, NULL); diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 5f59487fc9d4..b308100ba964 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -2257,6 +2257,8 @@ int ib_destroy_cq_user(struct ib_cq *cq, struct ib_udata *udata) if (ret) return ret; + if (udata) + mutex_destroy(&cq->resize_mutex); ib_umem_release(cq->umem); rdma_restrack_del(&cq->res); kfree(cq); diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 7d32d02c35e3..48340b39ab26 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -1638,8 +1638,11 @@ struct ib_cq { struct ib_wc *wc; struct list_head pool_entry; union { + /* Kernel CQs */ struct irq_poll iop; struct work_struct work; + /* Uverbs CQs */ + struct mutex resize_mutex; }; struct workqueue_struct *comp_wq; struct dim *dim; -- 2.52.0
