From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Igor Mammedov <imammedo@redhat.com>
Subject: [Qemu-devel] [PULL 05/38] vhost: add vhost_has_free_slot() interface
Date: Wed, 21 Oct 2015 13:26:42 +0300 [thread overview]
Message-ID: <1445423133-5119-6-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1445423133-5119-1-git-send-email-mst@redhat.com>
From: Igor Mammedov <imammedo@redhat.com>
it will allow for other parts of QEMU check if it's safe
to map memory region during hotplug/runtime.
That way hotplug path will have a chance to cancel
hotplug operation instead of crashing in vhost_commit().
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/vhost-backend.h | 2 ++
include/hw/virtio/vhost.h | 2 ++
hw/virtio/vhost-backend.c | 19 +++++++++++++++++++
hw/virtio/vhost-user.c | 6 ++++++
hw/virtio/vhost.c | 21 +++++++++++++++++++++
stubs/vhost.c | 6 ++++++
stubs/Makefile.objs | 1 +
7 files changed, 57 insertions(+)
create mode 100644 stubs/vhost.c
diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h
index 3a0f6e2..7d4a8ad 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -26,6 +26,7 @@ typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque);
typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
typedef int (*vhost_backend_get_vq_index)(struct vhost_dev *dev, int idx);
typedef int (*vhost_backend_set_vring_enable)(struct vhost_dev *dev, int enable);
+typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev);
typedef struct VhostOps {
VhostBackendType backend_type;
@@ -34,6 +35,7 @@ typedef struct VhostOps {
vhost_backend_cleanup vhost_backend_cleanup;
vhost_backend_get_vq_index vhost_backend_get_vq_index;
vhost_backend_set_vring_enable vhost_backend_set_vring_enable;
+ vhost_backend_memslots_limit vhost_backend_memslots_limit;
} VhostOps;
extern const VhostOps user_ops;
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index c3758f3..080831e 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -59,6 +59,7 @@ struct vhost_dev {
const VhostOps *vhost_ops;
void *opaque;
struct vhost_log *log;
+ QLIST_ENTRY(vhost_dev) entry;
};
int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
@@ -83,4 +84,5 @@ uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits,
uint64_t features);
void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits,
uint64_t features);
+bool vhost_has_free_slot(void);
#endif
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 72d1392..910d8e0 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -11,6 +11,7 @@
#include "hw/virtio/vhost.h"
#include "hw/virtio/vhost-backend.h"
#include "qemu/error-report.h"
+#include "linux/vhost.h"
#include <sys/ioctl.h>
@@ -49,12 +50,30 @@ static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx)
return idx - dev->vq_index;
}
+static int vhost_kernel_memslots_limit(struct vhost_dev *dev)
+{
+ int limit = 64;
+ char *s;
+
+ if (g_file_get_contents("/sys/module/vhost/parameters/max_mem_regions",
+ &s, NULL, NULL)) {
+ uint64_t val = g_ascii_strtoull(s, NULL, 10);
+ if (!((val == G_MAXUINT64 || !val) && errno)) {
+ return val;
+ }
+ error_report("ignoring invalid max_mem_regions value in vhost module:"
+ " %s", s);
+ }
+ return limit;
+}
+
static const VhostOps kernel_ops = {
.backend_type = VHOST_BACKEND_TYPE_KERNEL,
.vhost_call = vhost_kernel_call,
.vhost_backend_init = vhost_kernel_init,
.vhost_backend_cleanup = vhost_kernel_cleanup,
.vhost_backend_get_vq_index = vhost_kernel_get_vq_index,
+ .vhost_backend_memslots_limit = vhost_kernel_memslots_limit,
};
int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index b11c0d2..9585637 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -440,6 +440,11 @@ static int vhost_user_get_vq_index(struct vhost_dev *dev, int idx)
return idx;
}
+static int vhost_user_memslots_limit(struct vhost_dev *dev)
+{
+ return VHOST_MEMORY_MAX_NREGIONS;
+}
+
const VhostOps user_ops = {
.backend_type = VHOST_BACKEND_TYPE_USER,
.vhost_call = vhost_user_call,
@@ -447,4 +452,5 @@ const VhostOps user_ops = {
.vhost_backend_cleanup = vhost_user_cleanup,
.vhost_backend_get_vq_index = vhost_user_get_vq_index,
.vhost_backend_set_vring_enable = vhost_user_set_vring_enable,
+ .vhost_backend_memslots_limit = vhost_user_memslots_limit,
};
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index c0ed5b2..a3b4f9e 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -26,6 +26,22 @@
static struct vhost_log *vhost_log;
+static unsigned int used_memslots;
+static QLIST_HEAD(, vhost_dev) vhost_devices =
+ QLIST_HEAD_INITIALIZER(vhost_devices);
+
+bool vhost_has_free_slot(void)
+{
+ unsigned int slots_limit = ~0U;
+ struct vhost_dev *hdev;
+
+ QLIST_FOREACH(hdev, &vhost_devices, entry) {
+ unsigned int r = hdev->vhost_ops->vhost_backend_memslots_limit(hdev);
+ slots_limit = MIN(slots_limit, r);
+ }
+ return slots_limit > used_memslots;
+}
+
static void vhost_dev_sync_region(struct vhost_dev *dev,
MemoryRegionSection *section,
uint64_t mfirst, uint64_t mlast,
@@ -457,6 +473,7 @@ static void vhost_set_memory(MemoryListener *listener,
dev->mem_changed_start_addr = MIN(dev->mem_changed_start_addr, start_addr);
dev->mem_changed_end_addr = MAX(dev->mem_changed_end_addr, start_addr + size - 1);
dev->memory_changed = true;
+ used_memslots = dev->mem->nregions;
}
static bool vhost_section(MemoryRegionSection *section)
@@ -916,6 +933,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
return -errno;
}
+ QLIST_INSERT_HEAD(&vhost_devices, hdev, entry);
+
r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_OWNER, NULL);
if (r < 0) {
goto fail;
@@ -972,6 +991,7 @@ fail_vq:
fail:
r = -errno;
hdev->vhost_ops->vhost_backend_cleanup(hdev);
+ QLIST_REMOVE(hdev, entry);
return r;
}
@@ -989,6 +1009,7 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)
g_free(hdev->mem);
g_free(hdev->mem_sections);
hdev->vhost_ops->vhost_backend_cleanup(hdev);
+ QLIST_REMOVE(hdev, entry);
}
/* Stop processing guest IO notifications in qemu.
diff --git a/stubs/vhost.c b/stubs/vhost.c
new file mode 100644
index 0000000..d346b85
--- /dev/null
+++ b/stubs/vhost.c
@@ -0,0 +1,6 @@
+#include "hw/virtio/vhost.h"
+
+bool vhost_has_free_slot(void)
+{
+ return true;
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 85e4e81..ce6ce11 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -39,3 +39,4 @@ stub-obj-y += cpus.o
stub-obj-y += kvm.o
stub-obj-y += qmp_pc_dimm_device_list.o
stub-obj-y += target-monitor-defs.o
+stub-obj-y += vhost.o
--
MST
next prev parent reply other threads:[~2015-10-21 10:26 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-21 10:26 [Qemu-devel] [PULL 00/38] vhost, pc, virtio features, fixes, cleanups Michael S. Tsirkin
2015-10-21 10:26 ` [Qemu-devel] [PULL 01/38] intel_iommu: Add support for translation for devices behind bridges Michael S. Tsirkin
2015-10-21 10:26 ` [Qemu-devel] [PULL 02/38] exec: factor out duplicate mmap code Michael S. Tsirkin
2015-10-21 10:26 ` [Qemu-devel] [PULL 03/38] net: don't set native endianness Michael S. Tsirkin
2015-10-21 10:26 ` [Qemu-devel] [PULL 04/38] tests: re-enable vhost-user-test Michael S. Tsirkin
2015-10-22 11:36 ` Michael S. Tsirkin
2015-10-21 10:26 ` Michael S. Tsirkin [this message]
2015-10-21 10:26 ` [Qemu-devel] [PULL 06/38] pc-dimm: add vhost slots limit check before commiting to hotplug Michael S. Tsirkin
2015-10-21 10:26 ` [Qemu-devel] [PULL 07/38] vhost: fail backend intialization early Michael S. Tsirkin
2015-10-21 10:26 ` [Qemu-devel] [PULL 08/38] virtio: add some migration doc Michael S. Tsirkin
2015-10-21 10:26 ` [Qemu-devel] [PULL 09/38] configure: probe for memfd Michael S. Tsirkin
2015-10-21 10:26 ` [Qemu-devel] [PULL 10/38] linux-headers: add unistd.h Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 11/38] build-sys: split util-obj- on multi-lines Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 12/38] util: add linux-only memfd fallback Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 13/38] util: add memfd helpers Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 14/38] util: add fallback for qemu_memfd_alloc() Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 15/38] vhost: document log resizing Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 16/38] vhost: add vhost_set_log_base op Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 17/38] vhost-user: add vhost_user_requires_shm_log() Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 18/38] vhost: alloc shareable log Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 19/38] vhost-user: send log shm fd along with log_base Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 20/38] vhost-user: add a migration blocker Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 21/38] vhost: use a function for each call Michael S. Tsirkin
2015-10-22 14:09 ` Laurent Desnogues
2015-10-22 14:17 ` Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 22/38] vhost-user: document migration log Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 23/38] net: add trace_vhost_user_event Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 24/38] vhost user: add support of live migration Michael S. Tsirkin
2015-10-21 10:27 ` [Qemu-devel] [PULL 25/38] vhost user: add rarp sending after live migration for legacy guest Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 26/38] vhost-user: use an enum helper for features mask Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 27/38] vhost: add migration block if memfd failed Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 28/38] vhost-user-test: move wait_for_fds() out Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 29/38] vhost-user-test: remove useless static check Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 30/38] vhost-user-test: wrap server in TestServer struct Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 31/38] vhost-user-test: learn to tweak various qemu arguments Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 32/38] vhost-user-test: add live-migration test Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 33/38] vhost-user-test: check ownership during migration Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 34/38] seccomp: add memfd_create to whitelist Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 35/38] piix: fix resource leak reported by Coverity Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 36/38] vhost: set the correct queue index in case of migration with multiqueue Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 37/38] i386: keep cpu_model field in MachineState uptodate Michael S. Tsirkin
2015-10-21 10:28 ` [Qemu-devel] [PULL 38/38] hw/isa/lpc_ich9: inject the SMI on the VCPU that is writing to APM_CNT Michael S. Tsirkin
2015-10-21 14:06 ` [Qemu-devel] [PULL 00/38] vhost, pc, virtio features, fixes, cleanups Peter Maydell
2015-10-22 11:40 ` Michael S. Tsirkin
2015-10-22 12:33 ` Peter Maydell
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=1445423133-5119-6-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=imammedo@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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).