From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Si-Wei Liu <si-wei.liu@oracle.com>
Subject: [PULL v2 01/91] vhost: dirty log should be per backend type
Date: Tue, 2 Jul 2024 16:13:35 -0400 [thread overview]
Message-ID: <51d59a64eed6c2cd2d2f991f44ffbe21eb33c733.1719951026.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1719951026.git.mst@redhat.com>
From: Si-Wei Liu <si-wei.liu@oracle.com>
There could be a mix of both vhost-user and vhost-kernel clients
in the same QEMU process, where separate vhost loggers for the
specific vhost type have to be used. Make the vhost logger per
backend type, and have them properly reference counted.
Suggested-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
Message-Id: <1710448055-11709-1-git-send-email-si-wei.liu@oracle.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/vhost.c | 45 +++++++++++++++++++++++++++++++++------------
1 file changed, 33 insertions(+), 12 deletions(-)
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 4acd77e890..a1e8b79e1a 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -43,8 +43,8 @@
do { } while (0)
#endif
-static struct vhost_log *vhost_log;
-static struct vhost_log *vhost_log_shm;
+static struct vhost_log *vhost_log[VHOST_BACKEND_TYPE_MAX];
+static struct vhost_log *vhost_log_shm[VHOST_BACKEND_TYPE_MAX];
/* Memslots used by backends that support private memslots (without an fd). */
static unsigned int used_memslots;
@@ -287,6 +287,10 @@ static int vhost_set_backend_type(struct vhost_dev *dev,
r = -1;
}
+ if (r == 0) {
+ assert(dev->vhost_ops->backend_type == backend_type);
+ }
+
return r;
}
@@ -319,16 +323,22 @@ static struct vhost_log *vhost_log_alloc(uint64_t size, bool share)
return log;
}
-static struct vhost_log *vhost_log_get(uint64_t size, bool share)
+static struct vhost_log *vhost_log_get(VhostBackendType backend_type,
+ uint64_t size, bool share)
{
- struct vhost_log *log = share ? vhost_log_shm : vhost_log;
+ struct vhost_log *log;
+
+ assert(backend_type > VHOST_BACKEND_TYPE_NONE);
+ assert(backend_type < VHOST_BACKEND_TYPE_MAX);
+
+ log = share ? vhost_log_shm[backend_type] : vhost_log[backend_type];
if (!log || log->size != size) {
log = vhost_log_alloc(size, share);
if (share) {
- vhost_log_shm = log;
+ vhost_log_shm[backend_type] = log;
} else {
- vhost_log = log;
+ vhost_log[backend_type] = log;
}
} else {
++log->refcnt;
@@ -340,11 +350,20 @@ static struct vhost_log *vhost_log_get(uint64_t size, bool share)
static void vhost_log_put(struct vhost_dev *dev, bool sync)
{
struct vhost_log *log = dev->log;
+ VhostBackendType backend_type;
if (!log) {
return;
}
+ assert(dev->vhost_ops);
+ backend_type = dev->vhost_ops->backend_type;
+
+ if (backend_type == VHOST_BACKEND_TYPE_NONE ||
+ backend_type >= VHOST_BACKEND_TYPE_MAX) {
+ return;
+ }
+
--log->refcnt;
if (log->refcnt == 0) {
/* Sync only the range covered by the old log */
@@ -352,13 +371,13 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync)
vhost_log_sync_range(dev, 0, dev->log_size * VHOST_LOG_CHUNK - 1);
}
- if (vhost_log == log) {
+ if (vhost_log[backend_type] == log) {
g_free(log->log);
- vhost_log = NULL;
- } else if (vhost_log_shm == log) {
+ vhost_log[backend_type] = NULL;
+ } else if (vhost_log_shm[backend_type] == log) {
qemu_memfd_free(log->log, log->size * sizeof(*(log->log)),
log->fd);
- vhost_log_shm = NULL;
+ vhost_log_shm[backend_type] = NULL;
}
g_free(log);
@@ -376,7 +395,8 @@ static bool vhost_dev_log_is_shared(struct vhost_dev *dev)
static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size)
{
- struct vhost_log *log = vhost_log_get(size, vhost_dev_log_is_shared(dev));
+ struct vhost_log *log = vhost_log_get(dev->vhost_ops->backend_type,
+ size, vhost_dev_log_is_shared(dev));
uint64_t log_base = (uintptr_t)log->log;
int r;
@@ -2044,7 +2064,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
uint64_t log_base;
hdev->log_size = vhost_get_log_size(hdev);
- hdev->log = vhost_log_get(hdev->log_size,
+ hdev->log = vhost_log_get(hdev->vhost_ops->backend_type,
+ hdev->log_size,
vhost_dev_log_is_shared(hdev));
log_base = (uintptr_t)hdev->log->log;
r = hdev->vhost_ops->vhost_set_log_base(hdev,
--
MST
next prev parent reply other threads:[~2024-07-02 20:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 20:13 [PULL v2 00/91] virtio: features,fixes Michael S. Tsirkin
2024-07-02 20:13 ` Michael S. Tsirkin [this message]
2024-07-02 20:13 ` [PULL v2 02/91] vhost: Perform memory section dirty scans once per iteration Michael S. Tsirkin
2024-07-02 20:13 ` [PULL v2 03/91] vhost-vdpa: check vhost_vdpa_set_vring_ready() return value Michael S. Tsirkin
2024-07-02 20:13 ` [PULL v2 04/91] virtio/virtio-pci: Handle extra notification data Michael S. Tsirkin
2024-07-02 20:13 ` [PULL v2 05/91] virtio: Prevent creation of device using notification-data with ioeventfd Michael S. Tsirkin
2024-07-02 20:13 ` [PULL v2 06/91] virtio-mmio: Handle extra notification data Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 07/91] virtio-ccw: " Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 08/91] vhost/vhost-user: Add VIRTIO_F_NOTIFICATION_DATA to vhost feature bits Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 09/91] Fix vhost user assertion when sending more than one fd Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 10/91] vhost-vsock: add VIRTIO_F_RING_PACKED to feature_bits Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 11/91] hw/virtio: Fix obtain the buffer id from the last descriptor Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 12/91] virtio-pci: only reset pm state during resetting Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 13/91] vhost-user-gpu: fix import of DMABUF Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 14/91] Revert "vhost-user: fix lost reconnect" Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 15/91] vhost-user: fix lost reconnect again Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 16/91] hw/cxl/mailbox: change CCI cmd set structure to be a member, not a reference Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 17/91] hw/cxl/mailbox: interface to add CCI commands to an existing CCI Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 18/91] hw/cxl/cxl-mailbox-utils: Add dc_event_log_size field to output payload of identify memory device command Michael S. Tsirkin
2024-07-02 20:14 ` [PULL v2 19/91] hw/cxl/cxl-mailbox-utils: Add dynamic capacity region representative and mailbox command support 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=51d59a64eed6c2cd2d2f991f44ffbe21eb33c733.1719951026.git.mst@redhat.com \
--to=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=si-wei.liu@oracle.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).