[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 01/31] vhost: allow backends to filter memory section
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 01/31] vhost: allow backends to filter memory sections |
Date: |
Fri, 1 Jun 2018 19:26:40 +0300 |
From: Tiwei Bie <address@hidden>
This patch introduces a vhost op for vhost backends to allow
them to filter the memory sections that they can handle.
Signed-off-by: Tiwei Bie <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/hw/virtio/vhost-backend.h | 4 ++++
hw/virtio/vhost-user.c | 11 +++++++++++
hw/virtio/vhost.c | 9 +++++++--
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/include/hw/virtio/vhost-backend.h
b/include/hw/virtio/vhost-backend.h
index 5dac61f9ea..81283ec50f 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -101,6 +101,9 @@ typedef int (*vhost_crypto_create_session_op)(struct
vhost_dev *dev,
typedef int (*vhost_crypto_close_session_op)(struct vhost_dev *dev,
uint64_t session_id);
+typedef bool (*vhost_backend_mem_section_filter_op)(struct vhost_dev *dev,
+ MemoryRegionSection *section);
+
typedef struct VhostOps {
VhostBackendType backend_type;
vhost_backend_init vhost_backend_init;
@@ -138,6 +141,7 @@ typedef struct VhostOps {
vhost_set_config_op vhost_set_config;
vhost_crypto_create_session_op vhost_crypto_create_session;
vhost_crypto_close_session_op vhost_crypto_close_session;
+ vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter;
} VhostOps;
extern const VhostOps user_ops;
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index ca554d4ff1..da0756effe 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -1620,6 +1620,16 @@ vhost_user_crypto_close_session(struct vhost_dev *dev,
uint64_t session_id)
return 0;
}
+static bool vhost_user_mem_section_filter(struct vhost_dev *dev,
+ MemoryRegionSection *section)
+{
+ bool result;
+
+ result = memory_region_get_fd(section->mr) >= 0;
+
+ return result;
+}
+
const VhostOps user_ops = {
.backend_type = VHOST_BACKEND_TYPE_USER,
.vhost_backend_init = vhost_user_init,
@@ -1650,4 +1660,5 @@ const VhostOps user_ops = {
.vhost_set_config = vhost_user_set_config,
.vhost_crypto_create_session = vhost_user_crypto_create_session,
.vhost_crypto_close_session = vhost_user_crypto_close_session,
+ .vhost_backend_mem_section_filter = vhost_user_mem_section_filter,
};
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index b08290036d..624ade9682 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -386,7 +386,7 @@ static int vhost_verify_ring_mappings(struct vhost_dev *dev,
return r;
}
-static bool vhost_section(MemoryRegionSection *section)
+static bool vhost_section(struct vhost_dev *dev, MemoryRegionSection *section)
{
bool result;
bool log_dirty = memory_region_get_dirty_log_mask(section->mr) &
@@ -399,6 +399,11 @@ static bool vhost_section(MemoryRegionSection *section)
*/
result &= !log_dirty;
+ if (result && dev->vhost_ops->vhost_backend_mem_section_filter) {
+ result &=
+ dev->vhost_ops->vhost_backend_mem_section_filter(dev, section);
+ }
+
trace_vhost_section(section->mr->name, result);
return result;
}
@@ -632,7 +637,7 @@ static void vhost_region_addnop(MemoryListener *listener,
struct vhost_dev *dev = container_of(listener, struct vhost_dev,
memory_listener);
- if (!vhost_section(section)) {
+ if (!vhost_section(dev, section)) {
return;
}
vhost_region_add_section(dev, section);
--
MST
- [Qemu-devel] [PULL 00/31] acpi, vhost, misc: fixes, features, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 01/31] vhost: allow backends to filter memory sections,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 02/31] vhost-user: allow slave to send fds via slave channel, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 04/31] vhost-user: support registering external host notifiers, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 03/31] vhost-user: introduce shared vhost-user state, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 05/31] libvhost-user: support host notifier, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 10/31] crypto: use local path for local headers, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 07/31] osdep: add wait.h compat macros, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 08/31] libqtest: fail if child coredumps, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 06/31] vhost-user-bridge: support host notifier, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 11/31] hppa: use local path for local headers, Michael S. Tsirkin, 2018/06/01
- [Qemu-devel] [PULL 12/31] migration: drop an unused include, Michael S. Tsirkin, 2018/06/01