Blame SOURCES/kvm-memory-Store-physical-root-MR-in-FlatView.patch

4a2fec
From 44af3e507b25491e8ee996f83076138925a23e16 Mon Sep 17 00:00:00 2001
4a2fec
From: David Gibson <dgibson@redhat.com>
4a2fec
Date: Thu, 16 Nov 2017 03:07:22 +0100
4a2fec
Subject: [PATCH 18/30] memory: Store physical root MR in FlatView
4a2fec
4a2fec
RH-Author: David Gibson <dgibson@redhat.com>
4a2fec
Message-id: <20171116030732.8560-13-dgibson@redhat.com>
4a2fec
Patchwork-id: 77699
4a2fec
O-Subject: [PATCH 12/22] memory: Store physical root MR in FlatView
4a2fec
Bugzilla: 1481593
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
4a2fec
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
4a2fec
From: Alexey Kardashevskiy <aik@ozlabs.ru>
4a2fec
4a2fec
Address spaces get to keep a root MR (alias or not) but FlatView stores
4a2fec
the actual MR as this is going to be used later on to decide whether to
4a2fec
share a particular FlatView or not.
4a2fec
4a2fec
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
4a2fec
Message-Id: <20170921085110.25598-10-aik@ozlabs.ru>
4a2fec
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
(cherry picked from commit 89c177bbdd6cf8e50b3fd4831697d50e195d6432)
4a2fec
4a2fec
Signed-off-by: David Gibson <dgibson@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 memory.c | 26 ++++++++++++++++++++++----
4a2fec
 1 file changed, 22 insertions(+), 4 deletions(-)
4a2fec
4a2fec
diff --git a/memory.c b/memory.c
4a2fec
index b7d2536..7972235 100644
4a2fec
--- a/memory.c
4a2fec
+++ b/memory.c
4a2fec
@@ -230,6 +230,7 @@ struct FlatView {
4a2fec
     unsigned nr;
4a2fec
     unsigned nr_allocated;
4a2fec
     struct AddressSpaceDispatch *dispatch;
4a2fec
+    MemoryRegion *root;
4a2fec
 };
4a2fec
 
4a2fec
 typedef struct AddressSpaceOps AddressSpaceOps;
4a2fec
@@ -259,12 +260,14 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b)
4a2fec
         && a->readonly == b->readonly;
4a2fec
 }
4a2fec
 
4a2fec
-static FlatView *flatview_new(void)
4a2fec
+static FlatView *flatview_new(MemoryRegion *mr_root)
4a2fec
 {
4a2fec
     FlatView *view;
4a2fec
 
4a2fec
     view = g_new0(FlatView, 1);
4a2fec
     view->ref = 1;
4a2fec
+    view->root = mr_root;
4a2fec
+    memory_region_ref(mr_root);
4a2fec
 
4a2fec
     return view;
4a2fec
 }
4a2fec
@@ -297,6 +300,7 @@ static void flatview_destroy(FlatView *view)
4a2fec
         memory_region_unref(view->ranges[i].mr);
4a2fec
     }
4a2fec
     g_free(view->ranges);
4a2fec
+    memory_region_unref(view->root);
4a2fec
     g_free(view);
4a2fec
 }
4a2fec
 
4a2fec
@@ -722,12 +726,25 @@ static void render_memory_region(FlatView *view,
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
+static MemoryRegion *memory_region_get_flatview_root(MemoryRegion *mr)
4a2fec
+{
4a2fec
+    while (mr->alias && !mr->alias_offset &&
4a2fec
+           int128_ge(mr->size, mr->alias->size)) {
4a2fec
+        /* The alias is included in its entirety.  Use it as
4a2fec
+         * the "real" root, so that we can share more FlatViews.
4a2fec
+         */
4a2fec
+        mr = mr->alias;
4a2fec
+    }
4a2fec
+
4a2fec
+    return mr;
4a2fec
+}
4a2fec
+
4a2fec
 /* Render a memory topology into a list of disjoint absolute ranges. */
4a2fec
 static FlatView *generate_memory_topology(MemoryRegion *mr)
4a2fec
 {
4a2fec
     FlatView *view;
4a2fec
 
4a2fec
-    view = flatview_new();
4a2fec
+    view = flatview_new(mr);
4a2fec
 
4a2fec
     if (mr) {
4a2fec
         render_memory_region(view, mr, int128_zero(),
4a2fec
@@ -906,7 +923,8 @@ static void address_space_update_topology_pass(AddressSpace *as,
4a2fec
 static void address_space_update_topology(AddressSpace *as)
4a2fec
 {
4a2fec
     FlatView *old_view = address_space_get_flatview(as);
4a2fec
-    FlatView *new_view = generate_memory_topology(as->root);
4a2fec
+    MemoryRegion *physmr = memory_region_get_flatview_root(old_view->root);
4a2fec
+    FlatView *new_view = generate_memory_topology(physmr);
4a2fec
     int i;
4a2fec
 
4a2fec
     new_view->dispatch = address_space_dispatch_new(new_view);
4a2fec
@@ -2649,7 +2667,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
4a2fec
     as->ref_count = 1;
4a2fec
     as->root = root;
4a2fec
     as->malloced = false;
4a2fec
-    as->current_map = flatview_new();
4a2fec
+    as->current_map = flatview_new(root);
4a2fec
     as->ioeventfd_nb = 0;
4a2fec
     as->ioeventfds = NULL;
4a2fec
     QTAILQ_INIT(&as->listeners);
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec