Skip to contentSkip to conversation

vmw_pvrdma cleanup and style fixes

PATCH In review Bryan Tan 3 participants 10 messages Dec 20, 2017 – Dec 28, 2017 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Bryan Tan

author
#0 lore raw

cover vmw_pvrdma cleanup and style fixes

Do some cleanup and fixes related to comments received when going through the review process for the change to enable SRQs on vmw_pvrdma.

Note, as there are dependencies on the 4.15 fixes, this patch series is based on top of the for-rc fixes for 4.15. The patch series is named "vmw_pvrdma fixes for 4.15" and the last commit of the series is "RDMA/vmw_pvrdma: Avoid use after free due to QP/CQ/SRQ destroy".

Bryan Tan (4):
RDMA/vmw_pvrdma: Clarify QP and CQ is_kernel logic RDMA/vmw_pvrdma: Use more specific sizeof in kcalloc RDMA/vmw_pvrdma: Use refcount_t instead of atomic_t RDMA/vmw_pvrdma: Remove usage of BIT() from UAPI header

 drivers/infiniband/hw/vmw_pvrdma/pvrdma.h      |  4 ++--
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c   | 13 ++++++-------
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c | 16 ++++++++--------
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c   | 11 +++++------
 include/uapi/rdma/vmw_pvrdma-abi.h             | 12 ++++++------
 5 files changed, 27 insertions(+), 29 deletions(-)
Signature · 6 lines
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20171220192305.GA28403-qXbCdz4EeRo1jLI2hToXVI42T8aCTgcwy4vvyvUx+exJXi8ZT2ovy+oDBWuYMCC/[email protected]

author
#2 lore raw

PATCH 1/4 RDMA/vmw_pvrdma: Clarify QP and CQ is_kernel logic

Be more consistent in setting and checking is_kernel flag for QPs and CQs.

---
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c | 9 ++++-----
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c | 7 +++----
 2 files changed, 7 insertions(+), 9 deletions(-)
drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c +4 -5
index e529622..cc46161 100644
@@ -132,8 +132,9 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
 	}
 
 	cq->ibcq.cqe = entries;
+	cq->is_kernel = !context;
 
-	if (context) {
+	if (!cq->is_kernel) {
 		if (ib_copy_from_udata(&ucmd, udata, sizeof(ucmd))) {
 			ret = -EFAULT;
 			goto err_cq;
@@ -148,8 +149,6 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
 
 		npages = ib_umem_page_count(cq->umem);
 	} else {
-		cq->is_kernel = true;
-
 		/* One extra page for shared ring state */
 		npages = 1 + (entries * sizeof(struct pvrdma_cqe) +
 			      PAGE_SIZE - 1) / PAGE_SIZE;
@@ -202,7 +201,7 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
 	dev->cq_tbl[cq->cq_handle % dev->dsr->caps.max_cq] = cq;
 	spin_unlock_irqrestore(&dev->cq_tbl_lock, flags);
 
-	if (context) {
+	if (!cq->is_kernel) {
 		cq->uar = &(to_vucontext(context)->uar);
 
 		/* Copy udata back. */
@@ -219,7 +218,7 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
 err_page_dir:
 	pvrdma_page_dir_cleanup(dev, &cq->pdir);
 err_umem:
-	if (context)
+	if (!cq->is_kernel)
 		ib_umem_release(cq->umem);
 err_cq:
 	atomic_dec(&dev->num_cqs);
drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c +3 -4
index 4059308..9dd556a 100644
@@ -249,8 +249,9 @@ struct ib_qp *pvrdma_create_qp(struct ib_pd *pd,
 		init_completion(&qp->free);
 
 		qp->state = IB_QPS_RESET;
+		qp->is_kernel = !(pd->uobject && udata);
 
-		if (pd->uobject && udata) {
+		if (!qp->is_kernel) {
 			dev_dbg(&dev->pdev->dev,
 				"create queuepair from user space\n");
 
@@ -291,8 +292,6 @@ struct ib_qp *pvrdma_create_qp(struct ib_pd *pd,
 				qp->npages_recv = 0;
 			qp->npages = qp->npages_send + qp->npages_recv;
 		} else {
-			qp->is_kernel = true;
-
 			ret = pvrdma_set_sq_size(to_vdev(pd->device),
 						 &init_attr->cap, qp);
 			if (ret)
@@ -394,7 +393,7 @@ struct ib_qp *pvrdma_create_qp(struct ib_pd *pd,
 err_pdir:
 	pvrdma_page_dir_cleanup(dev, &qp->pdir);
 err_umem:
-	if (pd->uobject && udata) {
+	if (!qp->is_kernel) {
 		if (qp->rumem)
 			ib_umem_release(qp->rumem);
 		if (qp->sumem)
Signature · 6 lines
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#3 lore raw

PATCH 2/4 RDMA/vmw_pvrdma: Use more specific sizeof in kcalloc

In reply to a message not in the archive

Convert the sizeof(void *) in two kcalloc calls to be more specific for the arrays that are being allocated.

---
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c +2 -2
index e926818..69835d1 100644
@@ -243,13 +243,13 @@ static int pvrdma_register_device(struct pvrdma_dev *dev)
 	mutex_init(&dev->port_mutex);
 	spin_lock_init(&dev->desc_lock);
 
-	dev->cq_tbl = kcalloc(dev->dsr->caps.max_cq, sizeof(void *),
+	dev->cq_tbl = kcalloc(dev->dsr->caps.max_cq, sizeof(struct pvrdma_cq *),
 			      GFP_KERNEL);
 	if (!dev->cq_tbl)
 		return ret;
 	spin_lock_init(&dev->cq_tbl_lock);
 
-	dev->qp_tbl = kcalloc(dev->dsr->caps.max_qp, sizeof(void *),
+	dev->qp_tbl = kcalloc(dev->dsr->caps.max_qp, sizeof(struct pvrdma_qp *),
 			      GFP_KERNEL);
 	if (!dev->qp_tbl)
 		goto err_cq_free;
Signature · 6 lines
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#4 lore raw

PATCH 3/4 RDMA/vmw_pvrdma: Use refcount_t instead of atomic_t

In reply to a message not in the archive

refcount_t is the preferred type for refcounts. Change the QP and CQ refcnt fields to use refcount_t.

---
 drivers/infiniband/hw/vmw_pvrdma/pvrdma.h      |  4 ++--
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c   |  4 ++--
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c | 12 ++++++------
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c   |  4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)
drivers/infiniband/hw/vmw_pvrdma/pvrdma.h +2 -2
index 4f7bd3b6..44cb1cf 100644
@@ -93,7 +93,7 @@ struct pvrdma_cq {
 	struct pvrdma_page_dir pdir;
 	u32 cq_handle;
 	bool is_kernel;
-	atomic_t refcnt;
+	refcount_t refcnt;
 	struct completion free;
 };
 
@@ -196,7 +196,7 @@ struct pvrdma_qp {
 	u8 state;
 	bool is_kernel;
 	struct mutex mutex; /* QP state mutex. */
-	atomic_t refcnt;
+	refcount_t refcnt;
 	struct completion free;
 };
 
drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c +2 -2
index cc46161..faa9478 100644
@@ -177,7 +177,7 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
 	else
 		pvrdma_page_dir_insert_umem(&cq->pdir, cq->umem, 0);
 
-	atomic_set(&cq->refcnt, 1);
+	refcount_set(&cq->refcnt, 1);
 	init_completion(&cq->free);
 	spin_lock_init(&cq->cq_lock);
 
@@ -229,7 +229,7 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
 
 static void pvrdma_free_cq(struct pvrdma_dev *dev, struct pvrdma_cq *cq)
 {
-	if (atomic_dec_and_test(&cq->refcnt))
+	if (refcount_dec_and_test(&cq->refcnt))
 		complete(&cq->free);
 	wait_for_completion(&cq->free);
 
drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c +6 -6
index 69835d1..939ac2f 100644
@@ -333,7 +333,7 @@ static void pvrdma_qp_event(struct pvrdma_dev *dev, u32 qpn, int type)
 	spin_lock_irqsave(&dev->qp_tbl_lock, flags);
 	qp = dev->qp_tbl[qpn % dev->dsr->caps.max_qp];
 	if (qp)
-		atomic_inc(&qp->refcnt);
+		refcount_inc(&qp->refcnt);
 	spin_unlock_irqrestore(&dev->qp_tbl_lock, flags);
 
 	if (qp && qp->ibqp.event_handler) {
@@ -346,7 +346,7 @@ static void pvrdma_qp_event(struct pvrdma_dev *dev, u32 qpn, int type)
 		ibqp->event_handler(&e, ibqp->qp_context);
 	}
 	if (qp) {
-		if (atomic_dec_and_test(&qp->refcnt))
+		if (refcount_dec_and_test(&qp->refcnt))
 			complete(&qp->free);
 	}
 }
@@ -359,7 +359,7 @@ static void pvrdma_cq_event(struct pvrdma_dev *dev, u32 cqn, int type)
 	spin_lock_irqsave(&dev->cq_tbl_lock, flags);
 	cq = dev->cq_tbl[cqn % dev->dsr->caps.max_cq];
 	if (cq)
-		atomic_inc(&cq->refcnt);
+		refcount_inc(&cq->refcnt);
 	spin_unlock_irqrestore(&dev->cq_tbl_lock, flags);
 
 	if (cq && cq->ibcq.event_handler) {
@@ -372,7 +372,7 @@ static void pvrdma_cq_event(struct pvrdma_dev *dev, u32 cqn, int type)
 		ibcq->event_handler(&e, ibcq->cq_context);
 	}
 	if (cq) {
-		if (atomic_dec_and_test(&cq->refcnt))
+		if (refcount_dec_and_test(&cq->refcnt))
 			complete(&cq->free);
 	}
 }
@@ -531,13 +531,13 @@ static irqreturn_t pvrdma_intrx_handler(int irq, void *dev_id)
 		spin_lock_irqsave(&dev->cq_tbl_lock, flags);
 		cq = dev->cq_tbl[cqne->info % dev->dsr->caps.max_cq];
 		if (cq)
-			atomic_inc(&cq->refcnt);
+			refcount_inc(&cq->refcnt);
 		spin_unlock_irqrestore(&dev->cq_tbl_lock, flags);
 
 		if (cq && cq->ibcq.comp_handler)
 			cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context);
 		if (cq) {
-			if (atomic_dec_and_test(&cq->refcnt))
+			if (refcount_dec_and_test(&cq->refcnt))
 				complete(&cq->free);
 		}
 		pvrdma_idx_ring_inc(&ring->cons_head, ring_slots);
drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c +2 -2
index 9dd556a..7bf518b 100644
@@ -245,7 +245,7 @@ struct ib_qp *pvrdma_create_qp(struct ib_pd *pd,
 		spin_lock_init(&qp->sq.lock);
 		spin_lock_init(&qp->rq.lock);
 		mutex_init(&qp->mutex);
-		atomic_set(&qp->refcnt, 1);
+		refcount_set(&qp->refcnt, 1);
 		init_completion(&qp->free);
 
 		qp->state = IB_QPS_RESET;
@@ -427,7 +427,7 @@ static void pvrdma_free_qp(struct pvrdma_qp *qp)
 
 	pvrdma_unlock_cqs(scq, rcq, &scq_flags, &rcq_flags);
 
-	if (atomic_dec_and_test(&qp->refcnt))
+	if (refcount_dec_and_test(&qp->refcnt))
 		complete(&qp->free);
 	wait_for_completion(&qp->free);
 
Signature · 6 lines
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#5 lore raw

PATCH 4/4 RDMA/vmw_pvrdma: Remove usage of BIT() from UAPI header

In reply to a message not in the archive

BIT() should not be used in the UAPI header. Remove it.

---
 include/uapi/rdma/vmw_pvrdma-abi.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/uapi/rdma/vmw_pvrdma-abi.h +6 -6
index 4007cac..02ca0d0 100644
@@ -52,14 +52,14 @@
 #define PVRDMA_UVERBS_ABI_VERSION	3		/* ABI Version. */
 #define PVRDMA_UAR_HANDLE_MASK		0x00FFFFFF	/* Bottom 24 bits. */
 #define PVRDMA_UAR_QP_OFFSET		0		/* QP doorbell. */
-#define PVRDMA_UAR_QP_SEND		BIT(30)		/* Send bit. */
-#define PVRDMA_UAR_QP_RECV		BIT(31)		/* Recv bit. */
+#define PVRDMA_UAR_QP_SEND		(1 << 30)	/* Send bit. */
+#define PVRDMA_UAR_QP_RECV		(1 << 31)	/* Recv bit. */
 #define PVRDMA_UAR_CQ_OFFSET		4		/* CQ doorbell. */
-#define PVRDMA_UAR_CQ_ARM_SOL		BIT(29)		/* Arm solicited bit. */
-#define PVRDMA_UAR_CQ_ARM		BIT(30)		/* Arm bit. */
-#define PVRDMA_UAR_CQ_POLL		BIT(31)		/* Poll bit. */
+#define PVRDMA_UAR_CQ_ARM_SOL		(1 << 29)	/* Arm solicited bit. */
+#define PVRDMA_UAR_CQ_ARM		(1 << 30)	/* Arm bit. */
+#define PVRDMA_UAR_CQ_POLL		(1 << 31)	/* Poll bit. */
 #define PVRDMA_UAR_SRQ_OFFSET		8		/* SRQ doorbell. */
-#define PVRDMA_UAR_SRQ_RECV		BIT(30)		/* Recv bit. */
+#define PVRDMA_UAR_SRQ_RECV		(1 << 30)	/* Recv bit. */
 
 enum pvrdma_wr_opcode {
 	PVRDMA_WR_RDMA_WRITE,
Signature · 6 lines
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20171220192721.GA32622-qXbCdz4EeRo1jLI2hToXVI42T8aCTgcwy4vvyvUx+exJXi8ZT2ovy+oDBWuYMCC/[email protected]

#7 lore raw

Re: [PATCH for-next 4/4] RDMA/vmw_pvrdma: Remove usage of BIT() from UAPI header

Quoted 6 lines · Bryan Tan

BIT() should not be used in the UAPI header. Remove it.

---
 include/uapi/rdma/vmw_pvrdma-abi.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

IMHO, it should go to -rc.
Doug, Jason?

Quoted 33 lines
include/uapi/rdma/vmw_pvrdma-abi.h +6 -7
index 4007cac..02ca0d0 100644
@@ -52,14 +52,14 @@
 #define PVRDMA_UVERBS_ABI_VERSION	3		/* ABI Version. */
 #define PVRDMA_UAR_HANDLE_MASK		0x00FFFFFF	/* Bottom 24 bits. */
 #define PVRDMA_UAR_QP_OFFSET		0		/* QP doorbell. */
-#define PVRDMA_UAR_QP_SEND		BIT(30)		/* Send bit. */
-#define PVRDMA_UAR_QP_RECV		BIT(31)		/* Recv bit. */
+#define PVRDMA_UAR_QP_SEND		(1 << 30)	/* Send bit. */
+#define PVRDMA_UAR_QP_RECV		(1 << 31)	/* Recv bit. */
 #define PVRDMA_UAR_CQ_OFFSET		4		/* CQ doorbell. */
-#define PVRDMA_UAR_CQ_ARM_SOL		BIT(29)		/* Arm solicited bit. */
-#define PVRDMA_UAR_CQ_ARM		BIT(30)		/* Arm bit. */
-#define PVRDMA_UAR_CQ_POLL		BIT(31)		/* Poll bit. */
+#define PVRDMA_UAR_CQ_ARM_SOL		(1 << 29)	/* Arm solicited bit. */
+#define PVRDMA_UAR_CQ_ARM		(1 << 30)	/* Arm bit. */
+#define PVRDMA_UAR_CQ_POLL		(1 << 31)	/* Poll bit. */
 #define PVRDMA_UAR_SRQ_OFFSET		8		/* SRQ doorbell. */
-#define PVRDMA_UAR_SRQ_RECV		BIT(30)		/* Recv bit. */
+#define PVRDMA_UAR_SRQ_RECV		(1 << 30)	/* Recv bit. */
 
 enum pvrdma_wr_opcode {
 	PVRDMA_WR_RDMA_WRITE,
--

1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20171221130034.GH2942-U/[email protected]

#9 lore raw

Re: [PATCH for-next 4/4] RDMA/vmw_pvrdma: Remove usage of BIT() from UAPI header

Quoted 9 lines · Leon Romanovsky
Quoted 5 lines · Bryan Tan

BIT() should not be used in the UAPI header. Remove it.

 include/uapi/rdma/vmw_pvrdma-abi.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

IMHO, it should go to -rc.
Doug, Jason?

I can't decide if any of the -abi.h changes should be for-rc material or not..

The BIT() issue is being worked around in userspace today, so this seems even less for-rc'y?

I'm leaning toward 'not' as we can and do cherry pick a for-next uapi header into rdma-core, so there isn't really an actual reason to put changes to those headers into for-rc?

Thoughts?

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20171221163433.GD20015-uk2M96/[email protected]

#11 lore raw

Re: [PATCH for-next 4/4] RDMA/vmw_pvrdma: Remove usage of BIT() from UAPI header

Quoted 14 lines · Jason Gunthorpe
Quoted 9 lines · Leon Romanovsky
Quoted 5 lines · Bryan Tan

BIT() should not be used in the UAPI header. Remove it.

 include/uapi/rdma/vmw_pvrdma-abi.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

IMHO, it should go to -rc.
Doug, Jason?

I can't decide if any of the -abi.h changes should be for-rc material or not..

Quoted 8 lines

The BIT() issue is being worked around in userspace today, so this seems even less for-rc'y?

I'm leaning toward 'not' as we can and do cherry pick a for-next uapi header into rdma-core, so there isn't really an actual reason to put changes to those headers into for-rc?

Thoughts?

I think that UAPI should be fixed immediately without any relation to number of users (in our case one), but simple include of that -abi.h will cause to application breakage.

Thanks

Quoted 2 lines

Jason

#12 lore raw

Re: [PATCH for-next 4/4] RDMA/vmw_pvrdma: Remove usage of BIT() from UAPI header

In reply to a message not in the archive
Quoted 10 lines · Bryan Tan

BIT() should not be used in the UAPI header. Remove it.

 include/uapi/rdma/vmw_pvrdma-abi.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/uapi/rdma/vmw_pvrdma-abi.h +1 -0
index 4007cac..02ca0d0 100644
+++ b/include/uapi/rdma/vmw_pvrdma-abi.h

include/uapi/rdma/vmw_pvrdma-abi.h line 56

Quoted 7 lines
include/uapi/rdma/vmw_pvrdma-abi.h +2 -2
@@ -52,14 +52,14 @@
 #define PVRDMA_UVERBS_ABI_VERSION	3		/* ABI Version. */
 #define PVRDMA_UAR_HANDLE_MASK		0x00FFFFFF	/* Bottom 24 bits. */
 #define PVRDMA_UAR_QP_OFFSET		0		/* QP doorbell. */
-#define PVRDMA_UAR_QP_SEND		BIT(30)		/* Send bit. */
-#define PVRDMA_UAR_QP_RECV		BIT(31)		/* Recv bit. */
+#define PVRDMA_UAR_QP_SEND		(1 << 30)	/* Send bit. */
+#define PVRDMA_UAR_QP_RECV		(1 << 31)	/* Recv bit. */

I changed the '1<<31' to '1UL<<31' when I applied this to for-next, the constants should be unsigned to avoid problems with sign extensions on the high bit.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw
In reply to a message not in the archive
Quoted 8 lines · Bryan Tan

Do some cleanup and fixes related to comments received when going through the review process for the change to enable SRQs on vmw_pvrdma.

Note, as there are dependencies on the 4.15 fixes, this patch series is based on top of the for-rc fixes for 4.15. The patch series is named "vmw_pvrdma fixes for 4.15" and the last commit of the series is "RDMA/vmw_pvrdma: Avoid use after free due to QP/CQ/SRQ destroy".

Quoted 5 lines

Bryan Tan (4):
RDMA/vmw_pvrdma: Clarify QP and CQ is_kernel logic RDMA/vmw_pvrdma: Use more specific sizeof in kcalloc RDMA/vmw_pvrdma: Use refcount_t instead of atomic_t RDMA/vmw_pvrdma: Remove usage of BIT() from UAPI header

All of these are applied to for-next, thanks

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html