Blame SOURCES/kvm-hw-arm-virt-Introduce-virt_set_high_memmap-helper.patch

7f1c5b
From 5dff87c5ea60054709021025c9513ec259433ce2 Mon Sep 17 00:00:00 2001
7f1c5b
From: Gavin Shan <gshan@redhat.com>
7f1c5b
Date: Wed, 21 Dec 2022 08:48:45 +0800
7f1c5b
Subject: [PATCH 1/8] hw/arm/virt: Introduce virt_set_high_memmap() helper
7f1c5b
7f1c5b
RH-Author: Gavin Shan <gshan@redhat.com>
7f1c5b
RH-MergeRequest: 126: hw/arm/virt: Optimize high memory region address assignment
7f1c5b
RH-Bugzilla: 2113840
7f1c5b
RH-Acked-by: Eric Auger <eric.auger@redhat.com>
7f1c5b
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
7f1c5b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7f1c5b
RH-Commit: [1/8] 5f6ba5af7a2c21d8473c58e088ee99b11336c673
7f1c5b
7f1c5b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2113840
7f1c5b
7f1c5b
This introduces virt_set_high_memmap() helper. The logic of high
7f1c5b
memory region address assignment is moved to the helper. The intention
7f1c5b
is to make the subsequent optimization for high memory region address
7f1c5b
assignment easier.
7f1c5b
7f1c5b
No functional change intended.
7f1c5b
7f1c5b
Signed-off-by: Gavin Shan <gshan@redhat.com>
7f1c5b
Reviewed-by: Eric Auger <eric.auger@redhat.com>
7f1c5b
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
7f1c5b
Reviewed-by: Marc Zyngier <maz@kernel.org>
7f1c5b
Tested-by: Zhenyu Zhang <zhenyzha@redhat.com>
7f1c5b
Message-id: 20221029224307.138822-2-gshan@redhat.com
7f1c5b
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7f1c5b
(cherry picked from commit 4af6b6edece5ef273d29972d53547f823d2bc1c0)
7f1c5b
Signed-off-by: Gavin Shan <gshan@redhat.com>
7f1c5b
---
7f1c5b
 hw/arm/virt.c | 74 ++++++++++++++++++++++++++++-----------------------
7f1c5b
 1 file changed, 41 insertions(+), 33 deletions(-)
7f1c5b
7f1c5b
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
7f1c5b
index bf18838b87..bea5f54720 100644
7f1c5b
--- a/hw/arm/virt.c
7f1c5b
+++ b/hw/arm/virt.c
7f1c5b
@@ -1736,6 +1736,46 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
7f1c5b
     return arm_cpu_mp_affinity(idx, clustersz);
7f1c5b
 }
7f1c5b
 
7f1c5b
+static void virt_set_high_memmap(VirtMachineState *vms,
7f1c5b
+                                 hwaddr base, int pa_bits)
7f1c5b
+{
7f1c5b
+    int i;
7f1c5b
+
7f1c5b
+    for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) {
7f1c5b
+        hwaddr size = extended_memmap[i].size;
7f1c5b
+        bool fits;
7f1c5b
+
7f1c5b
+        base = ROUND_UP(base, size);
7f1c5b
+        vms->memmap[i].base = base;
7f1c5b
+        vms->memmap[i].size = size;
7f1c5b
+
7f1c5b
+        /*
7f1c5b
+         * Check each device to see if they fit in the PA space,
7f1c5b
+         * moving highest_gpa as we go.
7f1c5b
+         *
7f1c5b
+         * For each device that doesn't fit, disable it.
7f1c5b
+         */
7f1c5b
+        fits = (base + size) <= BIT_ULL(pa_bits);
7f1c5b
+        if (fits) {
7f1c5b
+            vms->highest_gpa = base + size - 1;
7f1c5b
+        }
7f1c5b
+
7f1c5b
+        switch (i) {
7f1c5b
+        case VIRT_HIGH_GIC_REDIST2:
7f1c5b
+            vms->highmem_redists &= fits;
7f1c5b
+            break;
7f1c5b
+        case VIRT_HIGH_PCIE_ECAM:
7f1c5b
+            vms->highmem_ecam &= fits;
7f1c5b
+            break;
7f1c5b
+        case VIRT_HIGH_PCIE_MMIO:
7f1c5b
+            vms->highmem_mmio &= fits;
7f1c5b
+            break;
7f1c5b
+        }
7f1c5b
+
7f1c5b
+        base += size;
7f1c5b
+    }
7f1c5b
+}
7f1c5b
+
7f1c5b
 static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
7f1c5b
 {
7f1c5b
     MachineState *ms = MACHINE(vms);
7f1c5b
@@ -1791,39 +1831,7 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
7f1c5b
     /* We know for sure that at least the memory fits in the PA space */
7f1c5b
     vms->highest_gpa = memtop - 1;
7f1c5b
 
7f1c5b
-    for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) {
7f1c5b
-        hwaddr size = extended_memmap[i].size;
7f1c5b
-        bool fits;
7f1c5b
-
7f1c5b
-        base = ROUND_UP(base, size);
7f1c5b
-        vms->memmap[i].base = base;
7f1c5b
-        vms->memmap[i].size = size;
7f1c5b
-
7f1c5b
-        /*
7f1c5b
-         * Check each device to see if they fit in the PA space,
7f1c5b
-         * moving highest_gpa as we go.
7f1c5b
-         *
7f1c5b
-         * For each device that doesn't fit, disable it.
7f1c5b
-         */
7f1c5b
-        fits = (base + size) <= BIT_ULL(pa_bits);
7f1c5b
-        if (fits) {
7f1c5b
-            vms->highest_gpa = base + size - 1;
7f1c5b
-        }
7f1c5b
-
7f1c5b
-        switch (i) {
7f1c5b
-        case VIRT_HIGH_GIC_REDIST2:
7f1c5b
-            vms->highmem_redists &= fits;
7f1c5b
-            break;
7f1c5b
-        case VIRT_HIGH_PCIE_ECAM:
7f1c5b
-            vms->highmem_ecam &= fits;
7f1c5b
-            break;
7f1c5b
-        case VIRT_HIGH_PCIE_MMIO:
7f1c5b
-            vms->highmem_mmio &= fits;
7f1c5b
-            break;
7f1c5b
-        }
7f1c5b
-
7f1c5b
-        base += size;
7f1c5b
-    }
7f1c5b
+    virt_set_high_memmap(vms, base, pa_bits);
7f1c5b
 
7f1c5b
     if (device_memory_size > 0) {
7f1c5b
         ms->device_memory = g_malloc0(sizeof(*ms->device_memory));
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b