public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Eli Cohen <elic@nvidia.com>
To: <mst@redhat.com>, <jasowang@redhat.com>,
	<linux-kernel@vger.kernel.org>,
	<virtualization@lists.linux-foundation.org>
Cc: <si-wei.liu@oracle.com>, <eperezma@redhat.com>, <lulu@redhat.com>,
	"Eli Cohen" <elic@nvidia.com>
Subject: [PATCH 6/7] vdpa/mlx5: Avoid using reslock in event_handler
Date: Sun, 13 Nov 2022 15:44:41 +0200	[thread overview]
Message-ID: <20221113134442.152695-7-elic@nvidia.com> (raw)
In-Reply-To: <20221113134442.152695-1-elic@nvidia.com>

event_handler runs under atomic context and may not acquire reslock. We
can still guarantee that the handler won't be called after suspend by
clearing nb_registered, unregistering the handler and flushing the
workqueue.

Signed-off-by: Eli Cohen <elic@nvidia.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 6e6490c85be2..bebfba530247 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -2872,8 +2872,8 @@ static int mlx5_vdpa_suspend(struct vdpa_device *vdev)
 	int i;
 
 	down_write(&ndev->reslock);
-	mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
 	ndev->nb_registered = false;
+	mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
 	flush_workqueue(ndev->mvdev.wq);
 	for (i = 0; i < ndev->cur_num_vqs; i++) {
 		mvq = &ndev->vqs[i];
@@ -3051,7 +3051,7 @@ static void update_carrier(struct work_struct *work)
 	else
 		ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
 
-	if (ndev->config_cb.callback)
+	if (ndev->nb_registered && ndev->config_cb.callback)
 		ndev->config_cb.callback(ndev->config_cb.private);
 
 	kfree(wqent);
@@ -3068,21 +3068,13 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p
 		switch (eqe->sub_type) {
 		case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
 		case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
-			down_read(&ndev->reslock);
-			if (!ndev->nb_registered) {
-				up_read(&ndev->reslock);
-				return NOTIFY_DONE;
-			}
 			wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC);
-			if (!wqent) {
-				up_read(&ndev->reslock);
+			if (!wqent)
 				return NOTIFY_DONE;
-			}
 
 			wqent->mvdev = &ndev->mvdev;
 			INIT_WORK(&wqent->work, update_carrier);
 			queue_work(ndev->mvdev.wq, &wqent->work);
-			up_read(&ndev->reslock);
 			ret = NOTIFY_OK;
 			break;
 		default:
-- 
2.38.1


  parent reply	other threads:[~2022-11-13 13:45 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-13 13:44 [PATCH 0/7] vdpa/mlx5: Add debugfs subtree and fixes Eli Cohen
2022-11-13 13:44 ` [PATCH 1/7] vdpa/mlx5: Fix rule forwarding VLAN to TIR Eli Cohen
2022-11-14  4:38   ` Jason Wang
2022-11-14  6:44     ` Eli Cohen
2022-11-14  8:07       ` Michael S. Tsirkin
2022-11-14  8:58         ` Eli Cohen
2022-11-13 13:44 ` [PATCH 2/7] vdpa/mlx5: Fix wrong mac address deletion Eli Cohen
2022-11-14  4:40   ` Jason Wang
2022-11-13 13:44 ` [PATCH 3/7] vdpa/mlx5: Move some definitions to a new header file Eli Cohen
2022-11-14  4:41   ` Jason Wang
2022-11-13 13:44 ` [PATCH 4/7] vdpa/mlx5: Add debugfs subtree Eli Cohen
2022-11-14  4:42   ` Jason Wang
2022-11-13 13:44 ` [PATCH 5/7] vdpa/mlx5: Add RX counters to debugfs Eli Cohen
2022-11-14  7:26   ` Jason Wang
2022-11-14  8:51     ` Eli Cohen
2022-11-13 13:44 ` Eli Cohen [this message]
2022-11-14  7:53   ` [PATCH 6/7] vdpa/mlx5: Avoid using reslock in event_handler Jason Wang
2022-11-14  8:58     ` Eli Cohen
2022-11-23  4:00       ` Jason Wang
2022-11-24  4:04         ` Jason Wang
2022-11-13 13:44 ` [PATCH 7/7] vdpa/mlx5: Avoid overwriting CVQ iotlb Eli Cohen
2022-11-13 13:51 ` [PATCH 0/7] vdpa/mlx5: Add debugfs subtree and fixes Michael S. Tsirkin
2022-11-13 13:56   ` Eli Cohen
2022-11-13 13:57     ` Michael S. Tsirkin
2022-11-13 14:01       ` Eli Cohen

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=20221113134442.152695-7-elic@nvidia.com \
    --to=elic@nvidia.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lulu@redhat.com \
    --cc=mst@redhat.com \
    --cc=si-wei.liu@oracle.com \
    --cc=virtualization@lists.linux-foundation.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox