yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
902636
From c35466c168e5219bf585aa65ac31fc9bdc7cbf36 Mon Sep 17 00:00:00 2001
902636
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
902636
Date: Fri, 24 Jan 2020 19:46:12 +0100
902636
Subject: [PATCH 003/116] vhost: Only align sections for vhost-user
902636
MIME-Version: 1.0
902636
Content-Type: text/plain; charset=UTF-8
902636
Content-Transfer-Encoding: 8bit
902636
902636
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
Message-id: <20200124194613.41119-3-dgilbert@redhat.com>
902636
Patchwork-id: 93452
902636
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 2/3] vhost: Only align sections for vhost-user
902636
Bugzilla: 1779041
902636
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
902636
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
902636
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
902636
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
902636
902636
I added hugepage alignment code in c1ece84e7c9 to deal with
902636
vhost-user + postcopy which needs aligned pages when using userfault.
902636
However, on x86 the lower 2MB of address space tends to be shotgun'd
902636
with small fragments around the 512-640k range - e.g. video RAM, and
902636
with HyperV synic pages tend to sit around there - again splitting
902636
it up.  The alignment code complains with a 'Section rounded to ...'
902636
error and gives up.
902636
902636
Since vhost-user already filters out devices without an fd
902636
(see vhost-user.c vhost_user_mem_section_filter) it shouldn't be
902636
affected by those overlaps.
902636
902636
Turn the alignment off on vhost-kernel so that it doesn't try
902636
and align, and thus won't hit the rounding issues.
902636
902636
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
Message-Id: <20200116202414.157959-3-dgilbert@redhat.com>
902636
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
902636
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
902636
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
902636
(cherry picked from commit 76525114736e8f669766e69b715fa59ce8648aae)
902636
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
902636
---
902636
 hw/virtio/vhost.c | 34 ++++++++++++++++++----------------
902636
 1 file changed, 18 insertions(+), 16 deletions(-)
902636
902636
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
902636
index 774d87d..25fd469 100644
902636
--- a/hw/virtio/vhost.c
902636
+++ b/hw/virtio/vhost.c
902636
@@ -547,26 +547,28 @@ static void vhost_region_add_section(struct vhost_dev *dev,
902636
     uintptr_t mrs_host = (uintptr_t)memory_region_get_ram_ptr(section->mr) +
902636
                          section->offset_within_region;
902636
     RAMBlock *mrs_rb = section->mr->ram_block;
902636
-    size_t mrs_page = qemu_ram_pagesize(mrs_rb);
902636
 
902636
     trace_vhost_region_add_section(section->mr->name, mrs_gpa, mrs_size,
902636
                                    mrs_host);
902636
 
902636
-    /* Round the section to it's page size */
902636
-    /* First align the start down to a page boundary */
902636
-    uint64_t alignage = mrs_host & (mrs_page - 1);
902636
-    if (alignage) {
902636
-        mrs_host -= alignage;
902636
-        mrs_size += alignage;
902636
-        mrs_gpa  -= alignage;
902636
-    }
902636
-    /* Now align the size up to a page boundary */
902636
-    alignage = mrs_size & (mrs_page - 1);
902636
-    if (alignage) {
902636
-        mrs_size += mrs_page - alignage;
902636
-    }
902636
-    trace_vhost_region_add_section_aligned(section->mr->name, mrs_gpa, mrs_size,
902636
-                                           mrs_host);
902636
+    if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER) {   
902636
+        /* Round the section to it's page size */
902636
+        /* First align the start down to a page boundary */
902636
+        size_t mrs_page = qemu_ram_pagesize(mrs_rb);
902636
+        uint64_t alignage = mrs_host & (mrs_page - 1);
902636
+        if (alignage) {
902636
+            mrs_host -= alignage;
902636
+            mrs_size += alignage;
902636
+            mrs_gpa  -= alignage;
902636
+        }
902636
+        /* Now align the size up to a page boundary */
902636
+        alignage = mrs_size & (mrs_page - 1);
902636
+        if (alignage) {
902636
+            mrs_size += mrs_page - alignage;
902636
+        }
902636
+        trace_vhost_region_add_section_aligned(section->mr->name, mrs_gpa, mrs_size,
902636
+                                               mrs_host);
902636
+    }
902636
 
902636
     if (dev->n_tmp_sections) {
902636
         /* Since we already have at least one section, lets see if
902636
-- 
902636
1.8.3.1
902636