Blame SOURCES/kvm-vhost-allow-backends-to-filter-memory-sections.patch

1bdc94
From 6f1ec0b51c03a266c26f3108bbdf45987f01b53f Mon Sep 17 00:00:00 2001
1bdc94
From: "plai@redhat.com" <plai@redhat.com>
1bdc94
Date: Thu, 21 Jun 2018 18:54:41 +0200
1bdc94
Subject: [PATCH 32/57] vhost: allow backends to filter memory sections
1bdc94
1bdc94
RH-Author: plai@redhat.com
1bdc94
Message-id: <1529607285-9942-7-git-send-email-plai@redhat.com>
1bdc94
Patchwork-id: 80941
1bdc94
O-Subject: [RHEL7.6 PATCH BZ 1526645 06/10] vhost: allow backends to filter memory sections
1bdc94
Bugzilla: 1526645
1bdc94
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
1bdc94
RH-Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>
1bdc94
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
1bdc94
1bdc94
From: Tiwei Bie <tiwei.bie@intel.com>
1bdc94
1bdc94
This patch introduces a vhost op for vhost backends to allow
1bdc94
them to filter the memory sections that they can handle.
1bdc94
1bdc94
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
1bdc94
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
1bdc94
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1bdc94
(cherry picked from commit 988a27754bbbc45698f7acb54352e5a1ae699514)
1bdc94
Signed-off-by: Paul Lai <plai@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 hw/virtio/vhost-user.c            | 11 +++++++++++
1bdc94
 hw/virtio/vhost.c                 |  9 +++++++--
1bdc94
 include/hw/virtio/vhost-backend.h |  4 ++++
1bdc94
 3 files changed, 22 insertions(+), 2 deletions(-)
1bdc94
1bdc94
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
1bdc94
index 85d8fd2..ebb946a 100644
1bdc94
--- a/hw/virtio/vhost-user.c
1bdc94
+++ b/hw/virtio/vhost-user.c
1bdc94
@@ -1620,6 +1620,16 @@ vhost_user_crypto_close_session(struct vhost_dev *dev, uint64_t session_id)
1bdc94
     return 0;
1bdc94
 }
1bdc94
 
1bdc94
+static bool vhost_user_mem_section_filter(struct vhost_dev *dev,
1bdc94
+                                          MemoryRegionSection *section)
1bdc94
+{
1bdc94
+    bool result;
1bdc94
+
1bdc94
+    result = memory_region_get_fd(section->mr) >= 0;
1bdc94
+
1bdc94
+    return result;
1bdc94
+}
1bdc94
+
1bdc94
 const VhostOps user_ops = {
1bdc94
         .backend_type = VHOST_BACKEND_TYPE_USER,
1bdc94
         .vhost_backend_init = vhost_user_init,
1bdc94
@@ -1650,4 +1660,5 @@ const VhostOps user_ops = {
1bdc94
         .vhost_set_config = vhost_user_set_config,
1bdc94
         .vhost_crypto_create_session = vhost_user_crypto_create_session,
1bdc94
         .vhost_crypto_close_session = vhost_user_crypto_close_session,
1bdc94
+        .vhost_backend_mem_section_filter = vhost_user_mem_section_filter,
1bdc94
 };
1bdc94
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
1bdc94
index 9d5850a..1ae68ff 100644
1bdc94
--- a/hw/virtio/vhost.c
1bdc94
+++ b/hw/virtio/vhost.c
1bdc94
@@ -386,7 +386,7 @@ static int vhost_verify_ring_mappings(struct vhost_dev *dev,
1bdc94
     return r;
1bdc94
 }
1bdc94
 
1bdc94
-static bool vhost_section(MemoryRegionSection *section)
1bdc94
+static bool vhost_section(struct vhost_dev *dev, MemoryRegionSection *section)
1bdc94
 {
1bdc94
     bool result;
1bdc94
     bool log_dirty = memory_region_get_dirty_log_mask(section->mr) &
1bdc94
@@ -399,6 +399,11 @@ static bool vhost_section(MemoryRegionSection *section)
1bdc94
      */
1bdc94
     result &= !log_dirty;
1bdc94
 
1bdc94
+    if (result && dev->vhost_ops->vhost_backend_mem_section_filter) {
1bdc94
+        result &=
1bdc94
+            dev->vhost_ops->vhost_backend_mem_section_filter(dev, section);
1bdc94
+    }
1bdc94
+
1bdc94
     trace_vhost_section(section->mr->name, result);
1bdc94
     return result;
1bdc94
 }
1bdc94
@@ -632,7 +637,7 @@ static void vhost_region_addnop(MemoryListener *listener,
1bdc94
     struct vhost_dev *dev = container_of(listener, struct vhost_dev,
1bdc94
                                          memory_listener);
1bdc94
 
1bdc94
-    if (!vhost_section(section)) {
1bdc94
+    if (!vhost_section(dev, section)) {
1bdc94
         return;
1bdc94
     }
1bdc94
     vhost_region_add_section(dev, section);
1bdc94
diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h
1bdc94
index 5dac61f..81283ec 100644
1bdc94
--- a/include/hw/virtio/vhost-backend.h
1bdc94
+++ b/include/hw/virtio/vhost-backend.h
1bdc94
@@ -101,6 +101,9 @@ typedef int (*vhost_crypto_create_session_op)(struct vhost_dev *dev,
1bdc94
 typedef int (*vhost_crypto_close_session_op)(struct vhost_dev *dev,
1bdc94
                                              uint64_t session_id);
1bdc94
 
1bdc94
+typedef bool (*vhost_backend_mem_section_filter_op)(struct vhost_dev *dev,
1bdc94
+                                                MemoryRegionSection *section);
1bdc94
+
1bdc94
 typedef struct VhostOps {
1bdc94
     VhostBackendType backend_type;
1bdc94
     vhost_backend_init vhost_backend_init;
1bdc94
@@ -138,6 +141,7 @@ typedef struct VhostOps {
1bdc94
     vhost_set_config_op vhost_set_config;
1bdc94
     vhost_crypto_create_session_op vhost_crypto_create_session;
1bdc94
     vhost_crypto_close_session_op vhost_crypto_close_session;
1bdc94
+    vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter;
1bdc94
 } VhostOps;
1bdc94
 
1bdc94
 extern const VhostOps user_ops;
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94