target-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* vhost: coding style and flush cleanups
@ 2021-05-25 17:47 Mike Christie
  2021-05-25 17:47 ` [PATCH 1/5] vhost: remove work arg from vhost_work_flush Mike Christie
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Mike Christie @ 2021-05-25 17:47 UTC (permalink / raw)
  To: target-devel, linux-scsi, stefanha, pbonzini, jasowang, mst,
	sgarzare, virtualization

The following patches apply over linus's tree and mst's vhost branch.
The patches are just some flush cleanups and a patch to reduce flush
calls and some coding style fixups.

My worker threading patches are built over these patches, but they seem
like patches that would be ok even if the threading patches never get
merged, so I've broken them out to make the threading patchset easier to
review.

V2:
- Added vhost_work coding style cleanup patch. The worker threading
patchset modifies that code. I thought I would clean it up since my
patch that added a new field looked weird using different styles.



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

* [PATCH 1/5] vhost: remove work arg from vhost_work_flush
  2021-05-25 17:47 vhost: coding style and flush cleanups Mike Christie
@ 2021-05-25 17:47 ` Mike Christie
  2021-05-27 13:22   ` Stefano Garzarella
  2021-05-25 17:47 ` [PATCH 2/5] vhost-scsi: remove extra flushes Mike Christie
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Mike Christie @ 2021-05-25 17:47 UTC (permalink / raw)
  To: target-devel, linux-scsi, stefanha, pbonzini, jasowang, mst,
	sgarzare, virtualization
  Cc: Mike Christie, Chaitanya Kulkarni

vhost_work_flush doesn't do anything with the work arg. This patch drops
it and then renames vhost_work_flush to vhost_work_dev_flush to reflect
that the function flushes all the works in the dev and not just a
specific queue or work item.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/vhost/scsi.c  | 4 ++--
 drivers/vhost/vhost.c | 8 ++++----
 drivers/vhost/vhost.h | 2 +-
 drivers/vhost/vsock.c | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 5de21ad4bd05..051a7f8dadba 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1470,8 +1470,8 @@ static void vhost_scsi_flush(struct vhost_scsi *vs)
 	/* Flush both the vhost poll and vhost work */
 	for (i = 0; i < VHOST_SCSI_MAX_VQ; i++)
 		vhost_scsi_flush_vq(vs, i);
-	vhost_work_flush(&vs->dev, &vs->vs_completion_work);
-	vhost_work_flush(&vs->dev, &vs->vs_event_work);
+	vhost_work_dev_flush(&vs->dev);
+	vhost_work_dev_flush(&vs->dev);
 
 	/* Wait for all reqs issued before the flush to be finished */
 	for (i = 0; i < VHOST_SCSI_MAX_VQ; i++)
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 5ccb0705beae..b9e853e6094d 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -231,7 +231,7 @@ void vhost_poll_stop(struct vhost_poll *poll)
 }
 EXPORT_SYMBOL_GPL(vhost_poll_stop);
 
-void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work)
+void vhost_work_dev_flush(struct vhost_dev *dev)
 {
 	struct vhost_flush_struct flush;
 
@@ -243,13 +243,13 @@ void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work)
 		wait_for_completion(&flush.wait_event);
 	}
 }
-EXPORT_SYMBOL_GPL(vhost_work_flush);
+EXPORT_SYMBOL_GPL(vhost_work_dev_flush);
 
 /* Flush any work that has been scheduled. When calling this, don't hold any
  * locks that are also used by the callback. */
 void vhost_poll_flush(struct vhost_poll *poll)
 {
-	vhost_work_flush(poll->dev, &poll->work);
+	vhost_work_dev_flush(poll->dev);
 }
 EXPORT_SYMBOL_GPL(vhost_poll_flush);
 
@@ -538,7 +538,7 @@ static int vhost_attach_cgroups(struct vhost_dev *dev)
 	attach.owner = current;
 	vhost_work_init(&attach.work, vhost_attach_cgroups_work);
 	vhost_work_queue(dev, &attach.work);
-	vhost_work_flush(dev, &attach.work);
+	vhost_work_dev_flush(dev);
 	return attach.ret;
 }
 
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index b063324c7669..1ba8e814989d 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -46,7 +46,7 @@ int vhost_poll_start(struct vhost_poll *poll, struct file *file);
 void vhost_poll_stop(struct vhost_poll *poll);
 void vhost_poll_flush(struct vhost_poll *poll);
 void vhost_poll_queue(struct vhost_poll *poll);
-void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work);
+void vhost_work_dev_flush(struct vhost_dev *dev);
 long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp);
 
 struct vhost_log {
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 5e78fb719602..f954f4d29c95 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -663,7 +663,7 @@ static void vhost_vsock_flush(struct vhost_vsock *vsock)
 	for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++)
 		if (vsock->vqs[i].handle_kick)
 			vhost_poll_flush(&vsock->vqs[i].poll);
-	vhost_work_flush(&vsock->dev, &vsock->send_pkt_work);
+	vhost_work_dev_flush(&vsock->dev);
 }
 
 static void vhost_vsock_reset_orphans(struct sock *sk)
-- 
2.25.1


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

* [PATCH 2/5] vhost-scsi: remove extra flushes
  2021-05-25 17:47 vhost: coding style and flush cleanups Mike Christie
  2021-05-25 17:47 ` [PATCH 1/5] vhost: remove work arg from vhost_work_flush Mike Christie
@ 2021-05-25 17:47 ` Mike Christie
  2021-05-25 17:47 ` [PATCH 3/5] vhost-scsi: reduce flushes during endpoint clearing Mike Christie
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Mike Christie @ 2021-05-25 17:47 UTC (permalink / raw)
  To: target-devel, linux-scsi, stefanha, pbonzini, jasowang, mst,
	sgarzare, virtualization
  Cc: Mike Christie

The vhost work flush function was flushing the entire work queue, so
there is no need for the double vhost_work_dev_flush calls in
vhost_scsi_flush.

And we do not need to call vhost_poll_flush for each poller because
that call also ends up flushing the same work queue thread the
vhost_work_dev_flush call flushed.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vhost/scsi.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 051a7f8dadba..2f9633ef26aa 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1445,11 +1445,6 @@ static void vhost_scsi_handle_kick(struct vhost_work *work)
 	vhost_scsi_handle_vq(vs, vq);
 }
 
-static void vhost_scsi_flush_vq(struct vhost_scsi *vs, int index)
-{
-	vhost_poll_flush(&vs->vqs[index].vq.poll);
-}
-
 /* Callers must hold dev mutex */
 static void vhost_scsi_flush(struct vhost_scsi *vs)
 {
@@ -1468,9 +1463,6 @@ static void vhost_scsi_flush(struct vhost_scsi *vs)
 		kref_put(&old_inflight[i]->kref, vhost_scsi_done_inflight);
 
 	/* Flush both the vhost poll and vhost work */
-	for (i = 0; i < VHOST_SCSI_MAX_VQ; i++)
-		vhost_scsi_flush_vq(vs, i);
-	vhost_work_dev_flush(&vs->dev);
 	vhost_work_dev_flush(&vs->dev);
 
 	/* Wait for all reqs issued before the flush to be finished */
-- 
2.25.1


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

* [PATCH 3/5] vhost-scsi: reduce flushes during endpoint clearing
  2021-05-25 17:47 vhost: coding style and flush cleanups Mike Christie
  2021-05-25 17:47 ` [PATCH 1/5] vhost: remove work arg from vhost_work_flush Mike Christie
  2021-05-25 17:47 ` [PATCH 2/5] vhost-scsi: remove extra flushes Mike Christie
@ 2021-05-25 17:47 ` Mike Christie
  2021-05-25 17:47 ` [PATCH 4/5] vhost: fix poll coding style Mike Christie
  2021-05-25 17:47 ` [PATCH 5/5] vhost: fix up vhost_work " Mike Christie
  4 siblings, 0 replies; 8+ messages in thread
From: Mike Christie @ 2021-05-25 17:47 UTC (permalink / raw)
  To: target-devel, linux-scsi, stefanha, pbonzini, jasowang, mst,
	sgarzare, virtualization
  Cc: Mike Christie

vhost_scsi_flush will flush everything, so we can clear the backends then
flush, then destroy. We don't need to flush before each vq destruction
because after the flush we will have made sure there can be no new cmds
started and there are no running cmds.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/vhost/scsi.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 2f9633ef26aa..927ebc52d822 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1747,11 +1747,12 @@ vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
 			mutex_lock(&vq->mutex);
 			vhost_vq_set_backend(vq, NULL);
 			mutex_unlock(&vq->mutex);
-			/*
-			 * Make sure cmds are not running before tearing them
-			 * down.
-			 */
-			vhost_scsi_flush(vs);
+		}
+		/* Make sure cmds are not running before tearing them down. */
+		vhost_scsi_flush(vs);
+
+		for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
+			vq = &vs->vqs[i].vq;
 			vhost_scsi_destroy_vq_cmds(vq);
 		}
 	}
-- 
2.25.1


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

* [PATCH 4/5] vhost: fix poll coding style
  2021-05-25 17:47 vhost: coding style and flush cleanups Mike Christie
                   ` (2 preceding siblings ...)
  2021-05-25 17:47 ` [PATCH 3/5] vhost-scsi: reduce flushes during endpoint clearing Mike Christie
@ 2021-05-25 17:47 ` Mike Christie
  2021-05-25 17:47 ` [PATCH 5/5] vhost: fix up vhost_work " Mike Christie
  4 siblings, 0 replies; 8+ messages in thread
From: Mike Christie @ 2021-05-25 17:47 UTC (permalink / raw)
  To: target-devel, linux-scsi, stefanha, pbonzini, jasowang, mst,
	sgarzare, virtualization
  Cc: Mike Christie, Chaitanya Kulkarni

We use 3 coding styles in this struct. Switch to just tabs.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vhost/vhost.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 1ba8e814989d..575c8180caad 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -28,12 +28,12 @@ struct vhost_work {
 /* Poll a file (eventfd or socket) */
 /* Note: there's nothing vhost specific about this structure. */
 struct vhost_poll {
-	poll_table                table;
-	wait_queue_head_t        *wqh;
-	wait_queue_entry_t              wait;
-	struct vhost_work	  work;
-	__poll_t		  mask;
-	struct vhost_dev	 *dev;
+	poll_table		table;
+	wait_queue_head_t	*wqh;
+	wait_queue_entry_t	wait;
+	struct vhost_work	work;
+	__poll_t		mask;
+	struct vhost_dev	*dev;
 };
 
 void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn);
-- 
2.25.1


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

* [PATCH 5/5] vhost: fix up vhost_work coding style
  2021-05-25 17:47 vhost: coding style and flush cleanups Mike Christie
                   ` (3 preceding siblings ...)
  2021-05-25 17:47 ` [PATCH 4/5] vhost: fix poll coding style Mike Christie
@ 2021-05-25 17:47 ` Mike Christie
  2021-05-27 13:23   ` Stefano Garzarella
  4 siblings, 1 reply; 8+ messages in thread
From: Mike Christie @ 2021-05-25 17:47 UTC (permalink / raw)
  To: target-devel, linux-scsi, stefanha, pbonzini, jasowang, mst,
	sgarzare, virtualization
  Cc: Mike Christie

Switch from a mix of tabs and spaces to just tabs.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/vhost/vhost.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 575c8180caad..7d5306d1229d 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -20,9 +20,9 @@ typedef void (*vhost_work_fn_t)(struct vhost_work *work);
 
 #define VHOST_WORK_QUEUED 1
 struct vhost_work {
-	struct llist_node	  node;
-	vhost_work_fn_t		  fn;
-	unsigned long		  flags;
+	struct llist_node	node;
+	vhost_work_fn_t		fn;
+	unsigned long		flags;
 };
 
 /* Poll a file (eventfd or socket) */
-- 
2.25.1


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

* Re: [PATCH 1/5] vhost: remove work arg from vhost_work_flush
  2021-05-25 17:47 ` [PATCH 1/5] vhost: remove work arg from vhost_work_flush Mike Christie
@ 2021-05-27 13:22   ` Stefano Garzarella
  0 siblings, 0 replies; 8+ messages in thread
From: Stefano Garzarella @ 2021-05-27 13:22 UTC (permalink / raw)
  To: Mike Christie
  Cc: target-devel, linux-scsi, stefanha, pbonzini, jasowang, mst,
	virtualization, Chaitanya Kulkarni

On Tue, May 25, 2021 at 12:47:29PM -0500, Mike Christie wrote:
>vhost_work_flush doesn't do anything with the work arg. This patch drops
>it and then renames vhost_work_flush to vhost_work_dev_flush to reflect
>that the function flushes all the works in the dev and not just a
>specific queue or work item.
>
>Signed-off-by: Mike Christie <michael.christie@oracle.com>
>Acked-by: Jason Wang <jasowang@redhat.com>
>Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
>---
> drivers/vhost/scsi.c  | 4 ++--
> drivers/vhost/vhost.c | 8 ++++----
> drivers/vhost/vhost.h | 2 +-
> drivers/vhost/vsock.c | 2 +-
> 4 files changed, 8 insertions(+), 8 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>


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

* Re: [PATCH 5/5] vhost: fix up vhost_work coding style
  2021-05-25 17:47 ` [PATCH 5/5] vhost: fix up vhost_work " Mike Christie
@ 2021-05-27 13:23   ` Stefano Garzarella
  0 siblings, 0 replies; 8+ messages in thread
From: Stefano Garzarella @ 2021-05-27 13:23 UTC (permalink / raw)
  To: Mike Christie
  Cc: target-devel, linux-scsi, stefanha, pbonzini, jasowang, mst,
	virtualization

On Tue, May 25, 2021 at 12:47:33PM -0500, Mike Christie wrote:
>Switch from a mix of tabs and spaces to just tabs.
>
>Signed-off-by: Mike Christie <michael.christie@oracle.com>
>---
> drivers/vhost/vhost.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
>diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
>index 575c8180caad..7d5306d1229d 100644
>--- a/drivers/vhost/vhost.h
>+++ b/drivers/vhost/vhost.h
>@@ -20,9 +20,9 @@ typedef void (*vhost_work_fn_t)(struct vhost_work *work);
>
> #define VHOST_WORK_QUEUED 1
> struct vhost_work {
>-	struct llist_node	  node;
>-	vhost_work_fn_t		  fn;
>-	unsigned long		  flags;
>+	struct llist_node	node;
>+	vhost_work_fn_t		fn;
>+	unsigned long		flags;
> };
>
> /* Poll a file (eventfd or socket) */
>-- 
>2.25.1
>

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>


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

end of thread, other threads:[~2021-05-27 13:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25 17:47 vhost: coding style and flush cleanups Mike Christie
2021-05-25 17:47 ` [PATCH 1/5] vhost: remove work arg from vhost_work_flush Mike Christie
2021-05-27 13:22   ` Stefano Garzarella
2021-05-25 17:47 ` [PATCH 2/5] vhost-scsi: remove extra flushes Mike Christie
2021-05-25 17:47 ` [PATCH 3/5] vhost-scsi: reduce flushes during endpoint clearing Mike Christie
2021-05-25 17:47 ` [PATCH 4/5] vhost: fix poll coding style Mike Christie
2021-05-25 17:47 ` [PATCH 5/5] vhost: fix up vhost_work " Mike Christie
2021-05-27 13:23   ` Stefano Garzarella

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).