qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 4/5] softmmu/memory_mapping: factor out adding physical memory


From: David Hildenbrand
Subject: [PATCH v1 4/5] softmmu/memory_mapping: factor out adding physical memory ranges
Date: Wed, 10 Feb 2021 18:15:36 +0100

Let's factor out adding an item to the list, to be reused in
RamDiscardMgr context next.

Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Claudio Fontana <cfontana@suse.de>
Cc: Thomas Huth <thuth@redhat.com>
Cc: "Alex Bennée" <alex.bennee@linaro.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 softmmu/memory_mapping.c | 64 +++++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c
index ad4911427a..05e8270edc 100644
--- a/softmmu/memory_mapping.c
+++ b/softmmu/memory_mapping.c
@@ -194,35 +194,17 @@ typedef struct GuestPhysListener {
     MemoryListener listener;
 } GuestPhysListener;
 
-static void guest_phys_blocks_region_add(MemoryListener *listener,
-                                         MemoryRegionSection *section)
+static void guest_phys_block_add(GuestPhysBlockList *list, MemoryRegion *mr,
+                                 hwaddr target_start, hwaddr target_end,
+                                 uint8_t *host_addr)
 {
-    GuestPhysListener *g;
-    uint64_t section_size;
-    hwaddr target_start, target_end;
-    uint8_t *host_addr;
-    GuestPhysBlock *predecessor;
-
-    /* we only care about RAM */
-    if (!memory_region_is_ram(section->mr) ||
-        memory_region_is_ram_device(section->mr) ||
-        memory_region_is_nonvolatile(section->mr)) {
-        return;
-    }
-
-    g            = container_of(listener, GuestPhysListener, listener);
-    section_size = int128_get64(section->size);
-    target_start = section->offset_within_address_space;
-    target_end   = target_start + section_size;
-    host_addr    = memory_region_get_ram_ptr(section->mr) +
-                   section->offset_within_region;
-    predecessor  = NULL;
+    GuestPhysBlock *predecessor = NULL;
 
     /* find continuity in guest physical address space */
-    if (!QTAILQ_EMPTY(&g->list->head)) {
+    if (!QTAILQ_EMPTY(&list->head)) {
         hwaddr predecessor_size;
 
-        predecessor = QTAILQ_LAST(&g->list->head);
+        predecessor = QTAILQ_LAST(&list->head);
         predecessor_size = predecessor->target_end - predecessor->target_start;
 
         /* the memory API guarantees monotonically increasing traversal */
@@ -231,7 +213,7 @@ static void guest_phys_blocks_region_add(MemoryListener 
*listener,
         /* we want continuity in both guest-physical and host-virtual memory */
         if (predecessor->target_end < target_start ||
             predecessor->host_addr + predecessor_size != host_addr ||
-            predecessor->mr != section->mr) {
+            predecessor->mr != mr) {
             predecessor = NULL;
         }
     }
@@ -243,11 +225,11 @@ static void guest_phys_blocks_region_add(MemoryListener 
*listener,
         block->target_start = target_start;
         block->target_end   = target_end;
         block->host_addr    = host_addr;
-        block->mr           = section->mr;
-        memory_region_ref(section->mr);
+        block->mr           = mr;
+        memory_region_ref(mr);
 
-        QTAILQ_INSERT_TAIL(&g->list->head, block, next);
-        ++g->list->num;
+        QTAILQ_INSERT_TAIL(&list->head, block, next);
+        ++list->num;
     } else {
         /* expand predecessor until @target_end; predecessor's start doesn't
          * change
@@ -258,10 +240,32 @@ static void guest_phys_blocks_region_add(MemoryListener 
*listener,
 #ifdef DEBUG_GUEST_PHYS_REGION_ADD
     fprintf(stderr, "%s: target_start=" TARGET_FMT_plx " target_end="
             TARGET_FMT_plx ": %s (count: %u)\n", __func__, target_start,
-            target_end, predecessor ? "joined" : "added", g->list->num);
+            target_end, predecessor ? "joined" : "added", list->num);
 #endif
 }
 
+static void guest_phys_blocks_region_add(MemoryListener *listener,
+                                         MemoryRegionSection *section)
+{
+    GuestPhysListener *g = container_of(listener, GuestPhysListener, listener);
+    hwaddr target_start, target_end;
+    uint8_t *host_addr;
+
+    /* we only care about RAM */
+    if (!memory_region_is_ram(section->mr) ||
+        memory_region_is_ram_device(section->mr) ||
+        memory_region_is_nonvolatile(section->mr)) {
+        return;
+    }
+
+    target_start = section->offset_within_address_space;
+    target_end = target_start + int128_get64(section->size);
+    host_addr = memory_region_get_ram_ptr(section->mr) +
+                section->offset_within_region;
+    guest_phys_block_add(g->list, section->mr, target_start, target_end,
+                         host_addr);
+}
+
 void guest_phys_blocks_append(GuestPhysBlockList *list)
 {
     GuestPhysListener g = { 0 };
-- 
2.29.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]