All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bernard Metzler <bmt@zurich.ibm.com>
To: jgg@ziepe.ca, leon@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org,
	netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	Bernard Metzler <bmt@zurich.ibm.com>,
	syzbot+e7c51d3be3a5ddfa0d7a@syzkaller.appspotmail.com
Subject: [PATCH] RDMA/siw: Fix handling netdev going down event
Date: Thu, 15 Feb 2024 12:55:24 +0100	[thread overview]
Message-ID: <20240215115524.126477-1-bmt@zurich.ibm.com> (raw)

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


             reply	other threads:[~2024-02-15 11:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-15 11:55 Bernard Metzler [this message]
2024-02-19  7:24 ` [PATCH] RDMA/siw: Fix handling netdev going down event Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240215115524.126477-1-bmt@zurich.ibm.com \
    --to=bmt@zurich.ibm.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=syzbot+e7c51d3be3a5ddfa0d7a@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.