Blame SOURCES/kvm-hw-arm-virt-Add-properties-to-disable-high-memory-re.patch

7f1c5b
From 30e86a7c4fbcdc95b74bcb2a15745cb221783091 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 7/8] hw/arm/virt: Add properties to disable high memory
7f1c5b
 regions
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: [7/8] 16f8762393b447a590b31c9e4d8d3c58c6bc9fa8
7f1c5b
7f1c5b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2113840
7f1c5b
7f1c5b
The 3 high memory regions are usually enabled by default, but they may
7f1c5b
be not used. For example, VIRT_HIGH_GIC_REDIST2 isn't needed by GICv2.
7f1c5b
This leads to waste in the PA space.
7f1c5b
7f1c5b
Add properties ("highmem-redists", "highmem-ecam", "highmem-mmio") to
7f1c5b
allow users selectively disable them if needed. After that, the high
7f1c5b
memory region for GICv3 or GICv4 redistributor can be disabled by user,
7f1c5b
the number of maximal supported CPUs needs to be calculated based on
7f1c5b
'vms->highmem_redists'. The follow-up error message is also improved
7f1c5b
to indicate if the high memory region for GICv3 and GICv4 has been
7f1c5b
enabled or not.
7f1c5b
7f1c5b
Suggested-by: Marc Zyngier <maz@kernel.org>
7f1c5b
Signed-off-by: Gavin Shan <gshan@redhat.com>
7f1c5b
Reviewed-by: Marc Zyngier <maz@kernel.org>
7f1c5b
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
7f1c5b
Reviewed-by: Eric Auger <eric.auger@redhat.com>
7f1c5b
Message-id: 20221029224307.138822-8-gshan@redhat.com
7f1c5b
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7f1c5b
(cherry picked from commit 6a48c64eec355ab1aff694eb4522d07a8e461368)
7f1c5b
Signed-off-by: Gavin Shan <gshan@redhat.com>
7f1c5b
Conflicts:
7f1c5b
	hw/arm/virt.c
7f1c5b
	Comment out the handlers of the property 'highmem-redists',
7f1c5b
	'highmem-ecam' and 'highmem-mmio' since they aren't exposed.
7f1c5b
---
7f1c5b
 docs/system/arm/virt.rst | 13 +++++++
7f1c5b
 hw/arm/virt.c            | 75 ++++++++++++++++++++++++++++++++++++++--
7f1c5b
 2 files changed, 86 insertions(+), 2 deletions(-)
7f1c5b
7f1c5b
diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst
7f1c5b
index 4454706392..188a4f211f 100644
7f1c5b
--- a/docs/system/arm/virt.rst
7f1c5b
+++ b/docs/system/arm/virt.rst
7f1c5b
@@ -98,6 +98,19 @@ compact-highmem
7f1c5b
   Set ``on``/``off`` to enable/disable the compact layout for high memory regions.
7f1c5b
   The default is ``on`` for machine types later than ``virt-7.2``.
7f1c5b
 
7f1c5b
+highmem-redists
7f1c5b
+  Set ``on``/``off`` to enable/disable the high memory region for GICv3 or
7f1c5b
+  GICv4 redistributor. The default is ``on``. Setting this to ``off`` will
7f1c5b
+  limit the maximum number of CPUs when GICv3 or GICv4 is used.
7f1c5b
+
7f1c5b
+highmem-ecam
7f1c5b
+  Set ``on``/``off`` to enable/disable the high memory region for PCI ECAM.
7f1c5b
+  The default is ``on`` for machine types later than ``virt-3.0``.
7f1c5b
+
7f1c5b
+highmem-mmio
7f1c5b
+  Set ``on``/``off`` to enable/disable the high memory region for PCI MMIO.
7f1c5b
+  The default is ``on``.
7f1c5b
+
7f1c5b
 gic-version
7f1c5b
   Specify the version of the Generic Interrupt Controller (GIC) to provide.
7f1c5b
   Valid values are:
7f1c5b
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
7f1c5b
index 6087511ae9..304fa0d6e7 100644
7f1c5b
--- a/hw/arm/virt.c
7f1c5b
+++ b/hw/arm/virt.c
7f1c5b
@@ -2142,14 +2142,20 @@ static void machvirt_init(MachineState *machine)
7f1c5b
     if (vms->gic_version == VIRT_GIC_VERSION_2) {
7f1c5b
         virt_max_cpus = GIC_NCPU;
7f1c5b
     } else {
7f1c5b
-        virt_max_cpus = virt_redist_capacity(vms, VIRT_GIC_REDIST) +
7f1c5b
-            virt_redist_capacity(vms, VIRT_HIGH_GIC_REDIST2);
7f1c5b
+        virt_max_cpus = virt_redist_capacity(vms, VIRT_GIC_REDIST);
7f1c5b
+        if (vms->highmem_redists) {
7f1c5b
+            virt_max_cpus += virt_redist_capacity(vms, VIRT_HIGH_GIC_REDIST2);
7f1c5b
+        }
7f1c5b
     }
7f1c5b
 
7f1c5b
     if (max_cpus > virt_max_cpus) {
7f1c5b
         error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
7f1c5b
                      "supported by machine 'mach-virt' (%d)",
7f1c5b
                      max_cpus, virt_max_cpus);
7f1c5b
+        if (vms->gic_version != VIRT_GIC_VERSION_2 && !vms->highmem_redists) {
7f1c5b
+            error_printf("Try 'highmem-redists=on' for more CPUs\n");
7f1c5b
+        }
7f1c5b
+
7f1c5b
         exit(1);
7f1c5b
     }
7f1c5b
 
7f1c5b
@@ -2420,6 +2426,49 @@ static void virt_set_compact_highmem(Object *obj, bool value, Error **errp)
7f1c5b
 
7f1c5b
     vms->highmem_compact = value;
7f1c5b
 }
7f1c5b
+
7f1c5b
+static bool virt_get_highmem_redists(Object *obj, Error **errp)
7f1c5b
+{
7f1c5b
+    VirtMachineState *vms = VIRT_MACHINE(obj);
7f1c5b
+
7f1c5b
+    return vms->highmem_redists;
7f1c5b
+}
7f1c5b
+
7f1c5b
+static void virt_set_highmem_redists(Object *obj, bool value, Error **errp)
7f1c5b
+{
7f1c5b
+    VirtMachineState *vms = VIRT_MACHINE(obj);
7f1c5b
+
7f1c5b
+    vms->highmem_redists = value;
7f1c5b
+}
7f1c5b
+
7f1c5b
+static bool virt_get_highmem_ecam(Object *obj, Error **errp)
7f1c5b
+{
7f1c5b
+    VirtMachineState *vms = VIRT_MACHINE(obj);
7f1c5b
+
7f1c5b
+    return vms->highmem_ecam;
7f1c5b
+}
7f1c5b
+
7f1c5b
+static void virt_set_highmem_ecam(Object *obj, bool value, Error **errp)
7f1c5b
+{
7f1c5b
+    VirtMachineState *vms = VIRT_MACHINE(obj);
7f1c5b
+
7f1c5b
+    vms->highmem_ecam = value;
7f1c5b
+}
7f1c5b
+
7f1c5b
+static bool virt_get_highmem_mmio(Object *obj, Error **errp)
7f1c5b
+{
7f1c5b
+    VirtMachineState *vms = VIRT_MACHINE(obj);
7f1c5b
+
7f1c5b
+    return vms->highmem_mmio;
7f1c5b
+}
7f1c5b
+
7f1c5b
+static void virt_set_highmem_mmio(Object *obj, bool value, Error **errp)
7f1c5b
+{
7f1c5b
+    VirtMachineState *vms = VIRT_MACHINE(obj);
7f1c5b
+
7f1c5b
+    vms->highmem_mmio = value;
7f1c5b
+}
7f1c5b
+
7f1c5b
 #endif /* disabled for RHEL */
7f1c5b
 
7f1c5b
 static bool virt_get_its(Object *obj, Error **errp)
7f1c5b
@@ -3052,6 +3101,28 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
7f1c5b
                                           "Set on/off to enable/disable compact "
7f1c5b
                                           "layout for high memory regions");
7f1c5b
 
7f1c5b
+    object_class_property_add_bool(oc, "highmem-redists",
7f1c5b
+                                   virt_get_highmem_redists,
7f1c5b
+                                   virt_set_highmem_redists);
7f1c5b
+    object_class_property_set_description(oc, "highmem-redists",
7f1c5b
+                                          "Set on/off to enable/disable high "
7f1c5b
+                                          "memory region for GICv3 or GICv4 "
7f1c5b
+                                          "redistributor");
7f1c5b
+
7f1c5b
+    object_class_property_add_bool(oc, "highmem-ecam",
7f1c5b
+                                   virt_get_highmem_ecam,
7f1c5b
+                                   virt_set_highmem_ecam);
7f1c5b
+    object_class_property_set_description(oc, "highmem-ecam",
7f1c5b
+                                          "Set on/off to enable/disable high "
7f1c5b
+                                          "memory region for PCI ECAM");
7f1c5b
+
7f1c5b
+    object_class_property_add_bool(oc, "highmem-mmio",
7f1c5b
+                                   virt_get_highmem_mmio,
7f1c5b
+                                   virt_set_highmem_mmio);
7f1c5b
+    object_class_property_set_description(oc, "highmem-mmio",
7f1c5b
+                                          "Set on/off to enable/disable high "
7f1c5b
+                                          "memory region for PCI MMIO");
7f1c5b
+
7f1c5b
     object_class_property_add_str(oc, "gic-version", virt_get_gic_version,
7f1c5b
                                   virt_set_gic_version);
7f1c5b
     object_class_property_set_description(oc, "gic-version",
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b