netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/siw: Fix handling netdev going down event
@ 2024-02-15 11:55 Bernard Metzler
  2024-02-19  7:24 ` Leon Romanovsky
  0 siblings, 1 reply; 2+ messages in thread
From: Bernard Metzler @ 2024-02-15 11:55 UTC (permalink / raw)
  To: jgg, leon
  Cc: linux-kernel, linux-rdma, netdev, syzkaller-bugs, Bernard Metzler,
	syzbot+e7c51d3be3a5ddfa0d7a

siw uses the NETDEV_GOING_DOWN event to schedule work which
gracefully clears all related siw devices connections. This
fix avoids re-initiating and re-scheduling this work if still
pending from a previous invocation.

Fixes: bdcf26bf9b3a ("rdma/siw: network and RDMA core interface")
Reported-by: syzbot+e7c51d3be3a5ddfa0d7a@syzkaller.appspotmail.com
Signed-off-by: Bernard Metzler <bmt@zurich.ibm.com>
---
 drivers/infiniband/sw/siw/siw_main.c | 56 ++++++++++++++--------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/infiniband/sw/siw/siw_main.c b/drivers/infiniband/sw/siw/siw_main.c
index 723903bd30c5..6c61f62b322c 100644
--- a/drivers/infiniband/sw/siw/siw_main.c
+++ b/drivers/infiniband/sw/siw/siw_main.c
@@ -276,6 +276,31 @@ static const struct ib_device_ops siw_device_ops = {
 	INIT_RDMA_OBJ_SIZE(ib_ucontext, siw_ucontext, base_ucontext),
 };
 
+/*
+ * Network link becomes unavailable. Mark all
+ * affected QP's accordingly.
+ */
+static void siw_netdev_down(struct work_struct *work)
+{
+	struct siw_device *sdev =
+		container_of(work, struct siw_device, netdev_down);
+
+	struct siw_qp_attrs qp_attrs;
+	struct list_head *pos, *tmp;
+
+	memset(&qp_attrs, 0, sizeof(qp_attrs));
+	qp_attrs.state = SIW_QP_STATE_ERROR;
+
+	list_for_each_safe(pos, tmp, &sdev->qp_list) {
+		struct siw_qp *qp = list_entry(pos, struct siw_qp, devq);
+
+		down_write(&qp->state_lock);
+		WARN_ON(siw_qp_modify(qp, &qp_attrs, SIW_QP_ATTR_STATE));
+		up_write(&qp->state_lock);
+	}
+	ib_device_put(&sdev->base_dev);
+}
+
 static struct siw_device *siw_device_create(struct net_device *netdev)
 {
 	struct siw_device *sdev;
@@ -319,6 +344,7 @@ static struct siw_device *siw_device_create(struct net_device *netdev)
 	xa_init_flags(&sdev->mem_xa, XA_FLAGS_ALLOC1);
 
 	ib_set_device_ops(base_dev, &siw_device_ops);
+	INIT_WORK(&sdev->netdev_down, siw_netdev_down);
 	rv = ib_device_set_netdev(base_dev, netdev, 1);
 	if (rv)
 		goto error;
@@ -364,37 +390,11 @@ static struct siw_device *siw_device_create(struct net_device *netdev)
 	return ERR_PTR(rv);
 }
 
-/*
- * Network link becomes unavailable. Mark all
- * affected QP's accordingly.
- */
-static void siw_netdev_down(struct work_struct *work)
-{
-	struct siw_device *sdev =
-		container_of(work, struct siw_device, netdev_down);
-
-	struct siw_qp_attrs qp_attrs;
-	struct list_head *pos, *tmp;
-
-	memset(&qp_attrs, 0, sizeof(qp_attrs));
-	qp_attrs.state = SIW_QP_STATE_ERROR;
-
-	list_for_each_safe(pos, tmp, &sdev->qp_list) {
-		struct siw_qp *qp = list_entry(pos, struct siw_qp, devq);
-
-		down_write(&qp->state_lock);
-		WARN_ON(siw_qp_modify(qp, &qp_attrs, SIW_QP_ATTR_STATE));
-		up_write(&qp->state_lock);
-	}
-	ib_device_put(&sdev->base_dev);
-}
-
 static void siw_device_goes_down(struct siw_device *sdev)
 {
-	if (ib_device_try_get(&sdev->base_dev)) {
-		INIT_WORK(&sdev->netdev_down, siw_netdev_down);
+	if (ib_device_try_get(&sdev->base_dev) &&
+	    !work_pending(&sdev->netdev_down))
 		schedule_work(&sdev->netdev_down);
-	}
 }
 
 static int siw_netdev_event(struct notifier_block *nb, unsigned long event,
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-19  7:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-15 11:55 [PATCH] RDMA/siw: Fix handling netdev going down event Bernard Metzler
2024-02-19  7:24 ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).