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

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