yeahuh / rpms / qemu-kvm

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