Blame SOURCES/kvm-memory-Get-rid-of-address_space_init_shareable.patch

9bac43
From 9695c6db4ca09b6bebcffcccfd37aae5c1845021 Mon Sep 17 00:00:00 2001
9bac43
From: David Gibson <dgibson@redhat.com>
9bac43
Date: Thu, 16 Nov 2017 03:07:28 +0100
9bac43
Subject: [PATCH 24/30] memory: Get rid of address_space_init_shareable
9bac43
9bac43
RH-Author: David Gibson <dgibson@redhat.com>
9bac43
Message-id: <20171116030732.8560-19-dgibson@redhat.com>
9bac43
Patchwork-id: 77710
9bac43
O-Subject: [PATCH 18/22] memory: Get rid of address_space_init_shareable
9bac43
Bugzilla: 1481593
9bac43
RH-Acked-by: Thomas Huth <thuth@redhat.com>
9bac43
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9bac43
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
9bac43
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
9bac43
9bac43
From: Alexey Kardashevskiy <aik@ozlabs.ru>
9bac43
9bac43
Since FlatViews are shared now and ASes not, this gets rid of
9bac43
address_space_init_shareable().
9bac43
9bac43
This should cause no behavioural change.
9bac43
9bac43
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
9bac43
Message-Id: <20170921085110.25598-17-aik@ozlabs.ru>
9bac43
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9bac43
(cherry picked from commit b516572f31c0ea0937cd9d11d9bd72dd83809886)
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
Conflicts:
9bac43
	target/arm/cpu.c
9bac43
9bac43
Conflicts because we don't have 1d2091bc75a "target/arm: Register
9bac43
second AddressSpace for secure v8M CPUs" downstream.
9bac43
9bac43
Signed-off-by: David Gibson <dgibson@redhat.com>
9bac43
---
9bac43
 cpus.c                  |  5 +++--
9bac43
 hw/arm/armv7m.c         |  9 ++++-----
9bac43
 include/exec/memory.h   | 19 -------------------
9bac43
 include/hw/arm/armv7m.h |  2 +-
9bac43
 memory.c                | 21 ---------------------
9bac43
 target/arm/cpu.c        | 15 ++++++++-------
9bac43
 target/i386/cpu.c       |  5 +++--
9bac43
 7 files changed, 19 insertions(+), 57 deletions(-)
9bac43
9bac43
diff --git a/cpus.c b/cpus.c
9bac43
index 9bed61e..c9a6240 100644
9bac43
--- a/cpus.c
9bac43
+++ b/cpus.c
9bac43
@@ -1764,8 +1764,9 @@ void qemu_init_vcpu(CPUState *cpu)
9bac43
         /* If the target cpu hasn't set up any address spaces itself,
9bac43
          * give it the default one.
9bac43
          */
9bac43
-        AddressSpace *as = address_space_init_shareable(cpu->memory,
9bac43
-                                                        "cpu-memory");
9bac43
+        AddressSpace *as = g_new0(AddressSpace, 1);
9bac43
+
9bac43
+        address_space_init(as, cpu->memory, "cpu-memory");
9bac43
         cpu->num_ases = 1;
9bac43
         cpu_address_space_init(cpu, as, 0);
9bac43
     }
9bac43
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
9bac43
index c8a11f2..475a88f 100644
9bac43
--- a/hw/arm/armv7m.c
9bac43
+++ b/hw/arm/armv7m.c
9bac43
@@ -41,7 +41,7 @@ static MemTxResult bitband_read(void *opaque, hwaddr offset,
9bac43
 
9bac43
     /* Find address in underlying memory and round down to multiple of size */
9bac43
     addr = bitband_addr(s, offset) & (-size);
9bac43
-    res = address_space_read(s->source_as, addr, attrs, buf, size);
9bac43
+    res = address_space_read(&s->source_as, addr, attrs, buf, size);
9bac43
     if (res) {
9bac43
         return res;
9bac43
     }
9bac43
@@ -66,7 +66,7 @@ static MemTxResult bitband_write(void *opaque, hwaddr offset, uint64_t value,
9bac43
 
9bac43
     /* Find address in underlying memory and round down to multiple of size */
9bac43
     addr = bitband_addr(s, offset) & (-size);
9bac43
-    res = address_space_read(s->source_as, addr, attrs, buf, size);
9bac43
+    res = address_space_read(&s->source_as, addr, attrs, buf, size);
9bac43
     if (res) {
9bac43
         return res;
9bac43
     }
9bac43
@@ -79,7 +79,7 @@ static MemTxResult bitband_write(void *opaque, hwaddr offset, uint64_t value,
9bac43
     } else {
9bac43
         buf[bitpos >> 3] &= ~bit;
9bac43
     }
9bac43
-    return address_space_write(s->source_as, addr, attrs, buf, size);
9bac43
+    return address_space_write(&s->source_as, addr, attrs, buf, size);
9bac43
 }
9bac43
 
9bac43
 static const MemoryRegionOps bitband_ops = {
9bac43
@@ -117,8 +117,7 @@ static void bitband_realize(DeviceState *dev, Error **errp)
9bac43
         return;
9bac43
     }
9bac43
 
9bac43
-    s->source_as = address_space_init_shareable(s->source_memory,
9bac43
-                                                "bitband-source");
9bac43
+    address_space_init(&s->source_as, s->source_memory, "bitband-source");
9bac43
 }
9bac43
 
9bac43
 /* Board init.  */
9bac43
diff --git a/include/exec/memory.h b/include/exec/memory.h
9bac43
index 157eae6..8d772b9 100644
9bac43
--- a/include/exec/memory.h
9bac43
+++ b/include/exec/memory.h
9bac43
@@ -319,8 +319,6 @@ struct AddressSpace {
9bac43
     struct rcu_head rcu;
9bac43
     char *name;
9bac43
     MemoryRegion *root;
9bac43
-    int ref_count;
9bac43
-    bool malloced;
9bac43
 
9bac43
     /* Accessed via RCU.  */
9bac43
     struct FlatView *current_map;
9bac43
@@ -1596,23 +1594,6 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr,
9bac43
 void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name);
9bac43
 
9bac43
 /**
9bac43
- * address_space_init_shareable: return an address space for a memory region,
9bac43
- *                               creating it if it does not already exist
9bac43
- *
9bac43
- * @root: a #MemoryRegion that routes addresses for the address space
9bac43
- * @name: an address space name.  The name is only used for debugging
9bac43
- *        output.
9bac43
- *
9bac43
- * This function will return a pointer to an existing AddressSpace
9bac43
- * which was initialized with the specified MemoryRegion, or it will
9bac43
- * create and initialize one if it does not already exist. The ASes
9bac43
- * are reference-counted, so the memory will be freed automatically
9bac43
- * when the AddressSpace is destroyed via address_space_destroy.
9bac43
- */
9bac43
-AddressSpace *address_space_init_shareable(MemoryRegion *root,
9bac43
-                                           const char *name);
9bac43
-
9bac43
-/**
9bac43
  * address_space_destroy: destroy an address space
9bac43
  *
9bac43
  * Releases all resources associated with an address space.  After an address space
9bac43
diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h
9bac43
index a9b3f2a..dba77df 100644
9bac43
--- a/include/hw/arm/armv7m.h
9bac43
+++ b/include/hw/arm/armv7m.h
9bac43
@@ -21,7 +21,7 @@ typedef struct {
9bac43
     SysBusDevice parent_obj;
9bac43
     /*< public >*/
9bac43
 
9bac43
-    AddressSpace *source_as;
9bac43
+    AddressSpace source_as;
9bac43
     MemoryRegion iomem;
9bac43
     uint32_t base;
9bac43
     MemoryRegion *source_memory;
9bac43
diff --git a/memory.c b/memory.c
9bac43
index 25a8bf2..00d5788 100644
9bac43
--- a/memory.c
9bac43
+++ b/memory.c
9bac43
@@ -2721,9 +2721,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
9bac43
 {
9bac43
     memory_region_ref(root);
9bac43
     memory_region_transaction_begin();
9bac43
-    as->ref_count = 1;
9bac43
     as->root = root;
9bac43
-    as->malloced = false;
9bac43
     as->current_map = NULL;
9bac43
     as->ioeventfd_nb = 0;
9bac43
     as->ioeventfds = NULL;
9bac43
@@ -2736,37 +2734,18 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
9bac43
 
9bac43
 static void do_address_space_destroy(AddressSpace *as)
9bac43
 {
9bac43
-    bool do_free = as->malloced;
9bac43
-
9bac43
     assert(QTAILQ_EMPTY(&as->listeners));
9bac43
 
9bac43
     flatview_unref(as->current_map);
9bac43
     g_free(as->name);
9bac43
     g_free(as->ioeventfds);
9bac43
     memory_region_unref(as->root);
9bac43
-    if (do_free) {
9bac43
-        g_free(as);
9bac43
-    }
9bac43
-}
9bac43
-
9bac43
-AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)
9bac43
-{
9bac43
-    AddressSpace *as;
9bac43
-
9bac43
-    as = g_malloc0(sizeof *as);
9bac43
-    address_space_init(as, root, name);
9bac43
-    as->malloced = true;
9bac43
-    return as;
9bac43
 }
9bac43
 
9bac43
 void address_space_destroy(AddressSpace *as)
9bac43
 {
9bac43
     MemoryRegion *root = as->root;
9bac43
 
9bac43
-    as->ref_count--;
9bac43
-    if (as->ref_count) {
9bac43
-        return;
9bac43
-    }
9bac43
     /* Flush out anything from MemoryListeners listening in on this */
9bac43
     memory_region_transaction_begin();
9bac43
     as->root = NULL;
9bac43
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
9bac43
index 3f90b7e..b6c8d93 100644
9bac43
--- a/target/arm/cpu.c
9bac43
+++ b/target/arm/cpu.c
9bac43
@@ -650,6 +650,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
9bac43
     CPUARMState *env = &cpu->env;
9bac43
     int pagebits;
9bac43
     Error *local_err = NULL;
9bac43
+#ifndef CONFIG_USER_ONLY
9bac43
+    AddressSpace *as;
9bac43
+#endif
9bac43
 
9bac43
     cpu_exec_realizefn(cs, &local_err);
9bac43
     if (local_err != NULL) {
9bac43
@@ -835,19 +838,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
9bac43
     }
9bac43
 
9bac43
     if (cpu->has_el3) {
9bac43
-        AddressSpace *as;
9bac43
+        as = g_new0(AddressSpace, 1);
9bac43
 
9bac43
         if (!cpu->secure_memory) {
9bac43
             cpu->secure_memory = cs->memory;
9bac43
         }
9bac43
-        as = address_space_init_shareable(cpu->secure_memory,
9bac43
-                                          "cpu-secure-memory");
9bac43
+        address_space_init(as, cpu->secure_memory, "cpu-secure-memory");
9bac43
         cpu_address_space_init(cs, as, ARMASIdx_S);
9bac43
     }
9bac43
-    cpu_address_space_init(cs,
9bac43
-                           address_space_init_shareable(cs->memory,
9bac43
-                                                        "cpu-memory"),
9bac43
-                           ARMASIdx_NS);
9bac43
+    as = g_new0(AddressSpace, 1);
9bac43
+    address_space_init(as, cs->memory, "cpu-memory");
9bac43
+    cpu_address_space_init(cs, as, ARMASIdx_NS);
9bac43
 #endif
9bac43
 
9bac43
     qemu_init_vcpu(cs);
9bac43
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
9bac43
index 1cae8fe..ca95336 100644
9bac43
--- a/target/i386/cpu.c
9bac43
+++ b/target/i386/cpu.c
9bac43
@@ -3772,10 +3772,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
9bac43
 
9bac43
 #ifndef CONFIG_USER_ONLY
9bac43
     if (tcg_enabled()) {
9bac43
-        AddressSpace *as_normal = address_space_init_shareable(cs->memory,
9bac43
-                                                               "cpu-memory");
9bac43
+        AddressSpace *as_normal = g_new0(AddressSpace, 1);
9bac43
         AddressSpace *as_smm = g_new(AddressSpace, 1);
9bac43
 
9bac43
+        address_space_init(as_normal, cs->memory, "cpu-memory");
9bac43
+
9bac43
         cpu->cpu_as_mem = g_new(MemoryRegion, 1);
9bac43
         cpu->cpu_as_root = g_new(MemoryRegion, 1);
9bac43
 
9bac43
-- 
9bac43
1.8.3.1
9bac43