From: Mike Christie <michael.christie@oracle.com>
To: virtualization@lists.linux-foundation.org, mst@redhat.com,
sgarzare@redhat.com, jasowang@redhat.com, stefanha@redhat.com
Subject: [PATCH 10/14] vhost_scsi: flush IO vqs then send TMF rsp
Date: Fri, 28 Apr 2023 11:31:27 -0500 [thread overview]
Message-ID: <20230428163131.92777-10-michael.christie@oracle.com> (raw)
In-Reply-To: <20230428163131.92777-1-michael.christie@oracle.com>
With one worker we will always send the scsi cmd responses then send the
TMF rsp, because LIO will always complete the scsi cmds first then call
into us to send the TMF response.
With multiple workers, the IO vq workers could be running while the
TMF/ctl vq worker is so this has us do a flush before completing the TMF
to make sure cmds are completed when it's work is later queued and run.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
drivers/vhost/scsi.c | 21 ++++++++++++++++++---
drivers/vhost/vhost.c | 6 ++++++
drivers/vhost/vhost.h | 1 +
3 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 1668009bd489..2c3cf487cc71 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1133,12 +1133,27 @@ static void vhost_scsi_tmf_resp_work(struct vhost_work *work)
{
struct vhost_scsi_tmf *tmf = container_of(work, struct vhost_scsi_tmf,
vwork);
- int resp_code;
+ struct vhost_virtqueue *ctl_vq, *vq;
+ int resp_code, i;
+
+ if (tmf->scsi_resp == TMR_FUNCTION_COMPLETE) {
+ /*
+ * Flush IO vqs that don't share a worker with the ctl to make
+ * sure they have sent their responses before us.
+ */
+ ctl_vq = &tmf->vhost->vqs[VHOST_SCSI_VQ_CTL].vq;
+ for (i = VHOST_SCSI_VQ_IO; i < tmf->vhost->dev.nvqs; i++) {
+ vq = &tmf->vhost->vqs[i].vq;
+
+ if (vhost_vq_is_setup(vq) &&
+ vq->worker != ctl_vq->worker)
+ vhost_vq_flush(vq);
+ }
- if (tmf->scsi_resp == TMR_FUNCTION_COMPLETE)
resp_code = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED;
- else
+ } else {
resp_code = VIRTIO_SCSI_S_FUNCTION_REJECTED;
+ }
vhost_scsi_send_tmf_resp(tmf->vhost, &tmf->svq->vq, tmf->in_iovs,
tmf->vq_desc, &tmf->resp_iov, resp_code);
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index adc2678a7b80..2e27d24634f5 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -275,6 +275,12 @@ void vhost_dev_flush(struct vhost_dev *dev)
}
EXPORT_SYMBOL_GPL(vhost_dev_flush);
+void vhost_vq_flush(struct vhost_virtqueue *vq)
+{
+ vhost_work_flush_on(vq->worker);
+}
+EXPORT_SYMBOL_GPL(vhost_vq_flush);
+
/* A lockless hint for busy polling code to exit the loop */
bool vhost_vq_has_work(struct vhost_virtqueue *vq)
{
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index ef55fae2517c..395707c680e5 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -53,6 +53,7 @@ int vhost_poll_start(struct vhost_poll *poll, struct file *file);
void vhost_poll_stop(struct vhost_poll *poll);
void vhost_poll_queue(struct vhost_poll *poll);
void vhost_dev_flush(struct vhost_dev *dev);
+void vhost_vq_flush(struct vhost_virtqueue *vq);
struct vhost_log {
u64 addr;
--
2.25.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2023-04-28 16:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-28 16:31 [PATCH 01/14] vhost: add vhost_worker pointer to vhost_virtqueue Mike Christie
2023-04-28 16:31 ` [PATCH 02/14] vhost, vhost_net: add helper to check if vq has work Mike Christie
2023-04-28 16:31 ` [PATCH 03/14] vhost: take worker or vq instead of dev for queueing Mike Christie
2023-04-28 16:31 ` [PATCH 04/14] vhost: take worker or vq instead of dev for flushing Mike Christie
2023-04-28 16:31 ` [PATCH 05/14] vhost: convert poll work to be vq based Mike Christie
2023-04-28 16:31 ` [PATCH 06/14] vhost_sock: convert to vhost_vq_work_queue Mike Christie
2023-04-28 16:31 ` [PATCH 07/14] vhost_scsi: make SCSI cmd completion per vq Mike Christie
2023-04-28 16:31 ` [PATCH 08/14] vhost_scsi: convert to vhost_vq_work_queue Mike Christie
2023-04-28 16:31 ` [PATCH 09/14] vhost: remove vhost_work_queue Mike Christie
2023-04-28 16:31 ` Mike Christie [this message]
2023-04-28 16:31 ` [PATCH 11/14] vhost: add helper to parse userspace vring state/file Mike Christie
2023-04-28 16:31 ` [PATCH 12/14] vhost: replace single worker pointer with xarray Mike Christie
2023-04-28 16:31 ` [PATCH 13/14] vhost: allow userspace to create workers Mike Christie
2023-05-17 3:10 ` Jason Wang
2023-05-18 23:21 ` Mike Christie
2023-04-28 16:31 ` [PATCH 14/14] vhost_scsi: add support for worker ioctls Mike Christie
2023-04-28 16:35 ` [PATCH v7 00/14] vhost: multiple worker support michael.christie
2023-06-02 11:49 ` Michael S. Tsirkin
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=20230428163131.92777-10-michael.christie@oracle.com \
--to=michael.christie@oracle.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.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;
as well as URLs for NNTP newsgroup(s).