Skip to contentSkip to conversation

RDMA/bnxt_re: Fixes for handling device references

PATCH Superseded Selvin Xavier 2 participants 6 messages Mar 13, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Selvin Xavier

author maintainer
#0 lore raw

cover RDMA/bnxt_re: Fixes for handling device references

Avoid the driver's internal mechanisms to check for device registered state and counting the work queue scheduling.

Jason Gunthorpe (2):
RDMA/bnxt_re: Use ib_device_try_get()
RDMA/bnxt_re: Fix lifetimes in bnxt_re_task

Selvin Xavier (1):
RDMA/bnxt_re: Remove unnecessary sched count

 drivers/infiniband/hw/bnxt_re/bnxt_re.h |  1 -
 drivers/infiniband/hw/bnxt_re/main.c    | 34 ++++++++++++++++-----------------
 2 files changed, 16 insertions(+), 19 deletions(-)
Signature · 1 line
2.5.5
author maintainer
#1 lore raw

PATCH 1/3 RDMA/bnxt_re: Use ib_device_try_get()

From: Jason Gunthorpe <[email protected]>

There are a couple places in this driver running from a work queue that need the ib_device to be registered. Instead of using a broken internal bit rely on the new core code to guarantee device registration.

---
 drivers/infiniband/hw/bnxt_re/main.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/infiniband/hw/bnxt_re/main.c +14 -11
index 415693f..d5019b3 100644
@@ -1171,12 +1171,13 @@ static int bnxt_re_update_gid(struct bnxt_re_dev *rdev)
 	u16 gid_idx, index;
 	int rc = 0;
 
-	if (!test_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags))
+	if (!ib_device_try_get(&rdev->ibdev))
 		return 0;
 
 	if (!sgid_tbl) {
 		ibdev_err(&rdev->ibdev, "QPLIB: SGID table not allocated");
-		return -EINVAL;
+		rc = -EINVAL;
+		goto out;
 	}
 
 	for (index = 0; index < sgid_tbl->active; index++) {
@@ -1196,7 +1197,8 @@ static int bnxt_re_update_gid(struct bnxt_re_dev *rdev)
 		rc = bnxt_qplib_update_sgid(sgid_tbl, &gid, gid_idx,
 					    rdev->qplib_res.netdev->dev_addr);
 	}
-
+out:
+	ib_device_put(&rdev->ibdev);
 	return rc;
 }
 
@@ -1630,12 +1632,7 @@ static void bnxt_re_task(struct work_struct *work)
 	re_work = container_of(work, struct bnxt_re_work, work);
 	rdev = re_work->rdev;
 
-	if (re_work->event != NETDEV_REGISTER &&
-	    !test_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags))
-		goto done;
-
-	switch (re_work->event) {
-	case NETDEV_REGISTER:
+	if (re_work->event == NETDEV_REGISTER) {
 		rc = bnxt_re_ib_init(rdev);
 		if (rc) {
 			ibdev_err(&rdev->ibdev,
@@ -1645,7 +1642,13 @@ static void bnxt_re_task(struct work_struct *work)
 			rtnl_unlock();
 			goto exit;
 		}
-		break;
+		goto exit;
+	}
+
+	if (!ib_device_try_get(&rdev->ibdev))
+		goto exit;
+
+	switch (re_work->event) {
 	case NETDEV_UP:
 		bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1,
 				       IB_EVENT_PORT_ACTIVE);
@@ -1665,7 +1668,7 @@ static void bnxt_re_task(struct work_struct *work)
 	default:
 		break;
 	}
-done:
+	ib_device_put(&rdev->ibdev);
 	smp_mb__before_atomic();
 	atomic_dec(&rdev->sched_count);
 exit:
Signature · 1 line
2.5.5
#2 lore raw

Re: [PATCH for-next 1/3] RDMA/bnxt_re: Use ib_device_try_get()

Quoted 11 lines · Selvin Xavier

From: Jason Gunthorpe <[email protected]>

There are a couple places in this driver running from a work queue that need the ib_device to be registered. Instead of using a broken internal bit rely on the new core code to guarantee device registration.

---
 drivers/infiniband/hw/bnxt_re/main.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

All readers of BNXT_RE_FLAG_IBDEV_REGISTERED are deleted now, the bit and the writers should be deleted too in this patch

Jason

author maintainer
#3 lore raw

PATCH 2/3 RDMA/bnxt_re: Fix lifetimes in bnxt_re_task

In reply to Selvin Xavier

From: Jason Gunthorpe <[email protected]>

A work queue cannot just rely on the ib_device not being freed, it must hold a kref on the memory so that the BNXT_RE_FLAG_IBDEV_REGISTERED check works.

Fixes 1ac5a4047975 ("RDMA/bnxt_re: Add bnxt_re RoCE driver")
---
 drivers/infiniband/hw/bnxt_re/main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/infiniband/hw/bnxt_re/main.c +2 -0
index d5019b3..82062d8 100644
@@ -1672,6 +1672,7 @@ static void bnxt_re_task(struct work_struct *work)
 	smp_mb__before_atomic();
 	atomic_dec(&rdev->sched_count);
 exit:
+	put_device(&rdev->ibdev.dev);
 	kfree(re_work);
 }
 
@@ -1737,6 +1738,7 @@ static int bnxt_re_netdev_event(struct notifier_block *notifier,
 		/* Allocate for the deferred task */
 		re_work = kzalloc(sizeof(*re_work), GFP_ATOMIC);
 		if (re_work) {
+			get_device(&rdev->ibdev.dev);
 			re_work->rdev = rdev;
 			re_work->event = event;
 			re_work->vlan_dev = (real_dev == netdev ?
Signature · 1 line
2.5.5
author maintainer
#4 lore raw

PATCH 3/3 RDMA/bnxt_re: Remove unnecessary sched count

In reply to Selvin Xavier

Since the lifetime of bnxt_re_task is controlled by the kref of device, sched_count is no longer required. Remove it.

---
 drivers/infiniband/hw/bnxt_re/bnxt_re.h | 1 -
 drivers/infiniband/hw/bnxt_re/main.c    | 7 -------
 2 files changed, 8 deletions(-)
drivers/infiniband/hw/bnxt_re/bnxt_re.h +0 -1
index c736e82..e35cc6c 100644
@@ -177,7 +177,6 @@ struct bnxt_re_dev {
 	atomic_t			srq_count;
 	atomic_t			mr_count;
 	atomic_t			mw_count;
-	atomic_t			sched_count;
 	/* Max of 2 lossless traffic class supported per port */
 	u16				cosq[2];
 
drivers/infiniband/hw/bnxt_re/main.c +0 -7
index 82062d8..4df0f8e 100644
@@ -1670,7 +1670,6 @@ static void bnxt_re_task(struct work_struct *work)
 	}
 	ib_device_put(&rdev->ibdev);
 	smp_mb__before_atomic();
-	atomic_dec(&rdev->sched_count);
 exit:
 	put_device(&rdev->ibdev.dev);
 	kfree(re_work);
@@ -1722,11 +1721,6 @@ static int bnxt_re_netdev_event(struct notifier_block *notifier,
 		break;
 
 	case NETDEV_UNREGISTER:
-		/* netdev notifier will call NETDEV_UNREGISTER again later since
-		 * we are still holding the reference to the netdev
-		 */
-		if (atomic_read(&rdev->sched_count) > 0)
-			goto exit;
 		ib_unregister_device_queued(&rdev->ibdev);
 		break;
 
@@ -1744,7 +1738,6 @@ static int bnxt_re_netdev_event(struct notifier_block *notifier,
 			re_work->vlan_dev = (real_dev == netdev ?
 					     NULL : netdev);
 			INIT_WORK(&re_work->work, bnxt_re_task);
-			atomic_inc(&rdev->sched_count);
 			queue_work(bnxt_re_wq, &re_work->work);
 		}
 	}
Signature · 1 line
2.5.5
#5 lore raw

Re: [PATCH for-next 3/3] RDMA/bnxt_re: Remove unnecessary sched count

Quoted 24 lines · Selvin Xavier

Since the lifetime of bnxt_re_task is controlled by the kref of device, sched_count is no longer required. Remove it.

 drivers/infiniband/hw/bnxt_re/bnxt_re.h | 1 -
 drivers/infiniband/hw/bnxt_re/main.c    | 7 -------
 2 files changed, 8 deletions(-)
drivers/infiniband/hw/bnxt_re/bnxt_re.h +1 -1
index c736e82..e35cc6c 100644
+++ b/drivers/infiniband/hw/bnxt_re/bnxt_re.h
@@ -177,7 +177,6 @@ struct bnxt_re_dev {
 	atomic_t			srq_count;
 	atomic_t			mr_count;
 	atomic_t			mw_count;
-	atomic_t			sched_count;
 	/* Max of 2 lossless traffic class supported per port */
 	u16				cosq[2];
 
drivers/infiniband/hw/bnxt_re/main.c +1 -0
index 82062d8..4df0f8e 100644
+++ b/drivers/infiniband/hw/bnxt_re/main.c

drivers/infiniband/hw/bnxt_re/main.c static void bnxt_re_task(struct work_struct *work) · line 1673

Quoted 4 lines
drivers/infiniband/hw/bnxt_re/main.c +0 -1
@@ -1670,7 +1670,6 @@ static void bnxt_re_task(struct work_struct *work)
 	}
 	ib_device_put(&rdev->ibdev);
 	smp_mb__before_atomic();
-	atomic_dec(&rdev->sched_count);

All these smp_mb's need to be deleted too

Jason