From: Hanna Czenczek <hreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Hanna Czenczek" <hreitz@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"German Maglione" <gmaglione@redhat.com>
Subject: [PATCH 3/6] vhost: Do not reset suspended devices on stop
Date: Tue, 11 Jul 2023 17:52:25 +0200 [thread overview]
Message-ID: <20230711155230.64277-4-hreitz@redhat.com> (raw)
In-Reply-To: <20230711155230.64277-1-hreitz@redhat.com>
Move the `suspended` field from vhost_vdpa into the global vhost_dev
struct, so vhost_dev_stop() can check whether the back-end has been
suspended by `vhost_ops->vhost_dev_start(hdev, false)`. If it has,
there is no need to reset it; the reset is just a fall-back to stop
device operations for back-ends that do not support suspend.
Unfortunately, for vDPA specifically, RESUME is not yet implemented, so
when the device is re-started, we still have to do the reset to have it
un-suspend.
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
---
include/hw/virtio/vhost-vdpa.h | 2 --
include/hw/virtio/vhost.h | 8 ++++++++
hw/virtio/vhost-vdpa.c | 11 +++++++----
hw/virtio/vhost.c | 8 +++++++-
4 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
index e64bfc7f98..72c3686b7f 100644
--- a/include/hw/virtio/vhost-vdpa.h
+++ b/include/hw/virtio/vhost-vdpa.h
@@ -42,8 +42,6 @@ typedef struct vhost_vdpa {
bool shadow_vqs_enabled;
/* Vdpa must send shadow addresses as IOTLB key for data queues, not GPA */
bool shadow_data;
- /* Device suspended successfully */
- bool suspended;
/* IOVA mapping used by the Shadow Virtqueue */
VhostIOVATree *iova_tree;
GPtrArray *shadow_vqs;
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 6a173cb9fa..69bf59d630 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -120,6 +120,14 @@ struct vhost_dev {
uint64_t backend_cap;
/* @started: is the vhost device started? */
bool started;
+ /**
+ * @suspended: Whether the vhost device is currently suspended. Set
+ * and reset by implementations (vhost-user, vhost-vdpa, ...), which
+ * are supposed to automatically suspend/resume in their
+ * vhost_dev_start handlers as required. Must also be cleared when
+ * the device is reset.
+ */
+ bool suspended;
bool log_enabled;
uint64_t log_size;
Error *migration_blocker;
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 7b7dee468e..f7fd19a203 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -858,13 +858,12 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,
static int vhost_vdpa_reset_device(struct vhost_dev *dev)
{
- struct vhost_vdpa *v = dev->opaque;
int ret;
uint8_t status = 0;
ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status);
trace_vhost_vdpa_reset_device(dev);
- v->suspended = false;
+ dev->suspended = false;
return ret;
}
@@ -1278,7 +1277,7 @@ static void vhost_vdpa_suspend(struct vhost_dev *dev)
if (unlikely(r)) {
error_report("Cannot suspend: %s(%d)", g_strerror(errno), errno);
} else {
- v->suspended = true;
+ dev->suspended = true;
return;
}
}
@@ -1313,6 +1312,10 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
return -1;
}
vhost_vdpa_set_vring_ready(dev);
+ if (dev->suspended) {
+ /* TODO: When RESUME is available, use it instead of resetting */
+ vhost_vdpa_reset_status(dev);
+ }
} else {
vhost_vdpa_suspend(dev);
vhost_vdpa_svqs_stop(dev);
@@ -1400,7 +1403,7 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev,
return 0;
}
- if (!v->suspended) {
+ if (!dev->suspended) {
/*
* Cannot trust in value returned by device, let vhost recover used
* idx from guest.
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index abf0d03c8d..2e28e58da7 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -2059,7 +2059,13 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
hdev->vqs + i,
hdev->vq_index + i);
}
- if (hdev->vhost_ops->vhost_reset_status) {
+
+ /*
+ * If we failed to successfully stop the device via SUSPEND (should have
+ * been attempted by `vhost_dev_start(hdev, false)`), reset it to stop it.
+ * Stateful devices where this would be problematic must implement SUSPEND.
+ */
+ if (!hdev->suspended && hdev->vhost_ops->vhost_reset_status) {
hdev->vhost_ops->vhost_reset_status(hdev);
}
--
2.41.0
next prev parent reply other threads:[~2023-07-11 15:53 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-11 15:52 [PATCH 0/6] vhost-user: Add suspend/resume Hanna Czenczek
2023-07-11 15:52 ` [PATCH 1/6] vhost-user.rst: " Hanna Czenczek
2023-07-18 14:25 ` Stefan Hajnoczi
2023-07-19 13:59 ` Hanna Czenczek
2023-07-24 17:55 ` Stefan Hajnoczi
2023-07-25 8:30 ` Hanna Czenczek
2023-07-27 21:12 ` Stefan Hajnoczi
2023-07-11 15:52 ` [PATCH 2/6] vhost-vdpa: Move vhost_vdpa_reset_status() up Hanna Czenczek
2023-07-18 14:29 ` Stefan Hajnoczi
2023-07-11 15:52 ` Hanna Czenczek [this message]
2023-07-18 14:33 ` [PATCH 3/6] vhost: Do not reset suspended devices on stop Stefan Hajnoczi
2023-07-21 15:25 ` Eugenio Perez Martin
2023-07-21 16:07 ` Hanna Czenczek
2023-07-24 15:48 ` Eugenio Perez Martin
2023-07-25 7:53 ` Hanna Czenczek
2023-07-25 10:03 ` Eugenio Perez Martin
2023-07-25 13:09 ` Hanna Czenczek
2023-07-25 18:53 ` Eugenio Perez Martin
2023-07-26 6:57 ` Hanna Czenczek
2023-07-27 12:49 ` Eugenio Perez Martin
2023-07-27 20:26 ` Stefan Hajnoczi
2023-07-11 15:52 ` [PATCH 4/6] vhost-user: Implement suspend/resume Hanna Czenczek
2023-07-18 14:37 ` Stefan Hajnoczi
2023-07-11 15:52 ` [PATCH 5/6] vhost-vdpa: Match vhost-user's status reset Hanna Czenczek
2023-07-18 14:50 ` Stefan Hajnoczi
2023-07-19 14:09 ` Hanna Czenczek
2023-07-19 15:06 ` Stefan Hajnoczi
2023-07-21 15:47 ` Eugenio Perez Martin
2023-07-11 15:52 ` [PATCH 6/6] vhost-user: Have reset_status fall back to reset Hanna Czenczek
2023-07-18 15:10 ` Stefan Hajnoczi
2023-07-19 14:11 ` Hanna Czenczek
2023-07-19 14:27 ` Hanna Czenczek
2023-07-20 16:03 ` Stefan Hajnoczi
2023-07-21 14:16 ` Hanna Czenczek
2023-07-24 18:04 ` Stefan Hajnoczi
2023-07-25 8:39 ` Hanna Czenczek
2023-07-18 15:14 ` [PATCH 0/6] vhost-user: Add suspend/resume Stefan Hajnoczi
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=20230711155230.64277-4-hreitz@redhat.com \
--to=hreitz@redhat.com \
--cc=eperezma@redhat.com \
--cc=gmaglione@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 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).