Blame SOURCES/kvm-pc-acpi-revert-back-to-1-SRAT-entry-for-hotpluggable.patch

357786
From cffbabd734488678614832ff26222aaa10920472 Mon Sep 17 00:00:00 2001
357786
From: Igor Mammedov <imammedo@redhat.com>
357786
Date: Wed, 12 Sep 2018 15:21:41 +0200
357786
Subject: [PATCH 06/49] pc: acpi: revert back to 1 SRAT entry for hotpluggable
357786
 area
357786
357786
RH-Author: Igor Mammedov <imammedo@redhat.com>
357786
Message-id: <1536765701-266415-1-git-send-email-imammedo@redhat.com>
357786
Patchwork-id: 82145
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH] pc: acpi: revert back to 1 SRAT entry for hotpluggable area
357786
Bugzilla: 1626059
357786
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
357786
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
357786
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
357786
357786
Commit
357786
  10efd7e108 "pc: acpi: fix memory hotplug regression by reducing stub SRAT entry size"
357786
attemped to fix hotplug regression introduced by
357786
  848a1cc1e "hw/acpi-build: build SRAT memory affinity structures for DIMM devices"
357786
357786
fixed issue for Windows/3.0+ linux kernels, however it regressed 2.6 based
357786
kernels (RHEL6) to the point where guest might crash at boot.
357786
Reason is that 2.6 kernel discards SRAT table due too small last entry
357786
which down the road leads to crashes. Hack I've tried in 10efd7e108 is also
357786
not ACPI spec compliant according to which whole possible RAM should be
357786
described in SRAT. Revert 10efd7e108 to fix regression for 2.6 based kernels.
357786
357786
With 10efd7e108 reverted, I've also tried splitting SRAT table statically
357786
in different ways %/node and %/slot but Windows still fails to online
357786
2nd pc-dimm hot-plugged into node 0 (as described in 10efd7e108) and
357786
sometimes even coldplugged pc-dimms where affected with static SRAT
357786
partitioning.
357786
The only known so far way where Windows stays happy is when we have 1
357786
SRAT entry in the last node covering all hotplug area.
357786
357786
Revert 848a1cc1e until we come up with a way to avoid regression
357786
on Windows with hotplug area split in several entries.
357786
Tested this with 2.6/3.0 based kernels (RHEL6/7) and WS20[08/12/12R2/16]).
357786
357786
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
357786
Acked-by: Laszlo Ersek <lersek@redhat.com>
357786
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
357786
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
357786
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
357786
(pull request  https://www.mail-archive.com/qemu-devel@nongnu.org/msg560638.html)
357786
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
357786
Conflicts:
357786
  hw/i386/acpi-build.c
357786
    - contextual conflict since we do not have
357786
         (d471bf3e hw/i386: Use the IEC binary prefix definitions)
357786
         (b0c14ec4 machine: make MemoryHotplugState accessible via the machine)
357786
357786
Since it's blocker and urgent, sending patch without waiting for upstream
357786
commit id (pull req is out there but it looks like Peter is absent to merge it)
357786
---
357786
 hw/i386/acpi-build.c | 74 +++++++++-------------------------------------------
357786
 1 file changed, 13 insertions(+), 61 deletions(-)
357786
357786
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
357786
index 683e5f4..2bc8117 100644
357786
--- a/hw/i386/acpi-build.c
357786
+++ b/hw/i386/acpi-build.c
357786
@@ -2253,64 +2253,6 @@ build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
357786
 #define HOLE_640K_START  (640 * 1024)
357786
 #define HOLE_640K_END   (1024 * 1024)
357786
 
357786
-static void build_srat_hotpluggable_memory(GArray *table_data, uint64_t base,
357786
-                                           uint64_t len, int default_node)
357786
-{
357786
-    MemoryDeviceInfoList *info_list = qmp_pc_dimm_device_list();
357786
-    MemoryDeviceInfoList *info;
357786
-    MemoryDeviceInfo *mi;
357786
-    PCDIMMDeviceInfo *di;
357786
-    uint64_t end = base + len, cur, size;
357786
-    bool is_nvdimm;
357786
-    AcpiSratMemoryAffinity *numamem;
357786
-    MemoryAffinityFlags flags;
357786
-
357786
-    for (cur = base, info = info_list;
357786
-         cur < end;
357786
-         cur += size, info = info->next) {
357786
-        numamem = acpi_data_push(table_data, sizeof *numamem);
357786
-
357786
-        if (!info) {
357786
-            /*
357786
-             * Entry is required for Windows to enable memory hotplug in OS
357786
-             * and for Linux to enable SWIOTLB when booted with less than
357786
-             * 4G of RAM. Windows works better if the entry sets proximity
357786
-             * to the highest NUMA node in the machine at the end of the
357786
-             * reserved space.
357786
-             * Memory devices may override proximity set by this entry,
357786
-             * providing _PXM method if necessary.
357786
-             */
357786
-            build_srat_memory(numamem, end - 1, 1, default_node,
357786
-                              MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED);
357786
-            break;
357786
-        }
357786
-
357786
-        mi = info->value;
357786
-        is_nvdimm = (mi->type == MEMORY_DEVICE_INFO_KIND_NVDIMM);
357786
-        di = !is_nvdimm ? mi->u.dimm.data : mi->u.nvdimm.data;
357786
-
357786
-        if (cur < di->addr) {
357786
-            build_srat_memory(numamem, cur, di->addr - cur, default_node,
357786
-                              MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED);
357786
-            numamem = acpi_data_push(table_data, sizeof *numamem);
357786
-        }
357786
-
357786
-        size = di->size;
357786
-
357786
-        flags = MEM_AFFINITY_ENABLED;
357786
-        if (di->hotpluggable) {
357786
-            flags |= MEM_AFFINITY_HOTPLUGGABLE;
357786
-        }
357786
-        if (is_nvdimm) {
357786
-            flags |= MEM_AFFINITY_NON_VOLATILE;
357786
-        }
357786
-
357786
-        build_srat_memory(numamem, di->addr, size, di->node, flags);
357786
-    }
357786
-
357786
-    qapi_free_MemoryDeviceInfoList(info_list);
357786
-}
357786
-
357786
 static void
357786
 build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
357786
 {
357786
@@ -2413,10 +2355,20 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
357786
         build_srat_memory(numamem, 0, 0, 0, MEM_AFFINITY_NOFLAGS);
357786
     }
357786
 
357786
+    /*
357786
+     * Entry is required for Windows to enable memory hotplug in OS
357786
+     * and for Linux to enable SWIOTLB when booted with less than
357786
+     * 4G of RAM. Windows works better if the entry sets proximity
357786
+     * to the highest NUMA node in the machine at the end of the
357786
+     * reserved space.
357786
+     * Memory devices may override proximity set by this entry,
357786
+     * providing _PXM method if necessary.
357786
+     */
357786
     if (hotplugabble_address_space_size) {
357786
-        build_srat_hotpluggable_memory(table_data, pcms->hotplug_memory.base,
357786
-                                       hotplugabble_address_space_size,
357786
-                                       pcms->numa_nodes - 1);
357786
+        numamem = acpi_data_push(table_data, sizeof *numamem);
357786
+        build_srat_memory(numamem, pcms->hotplug_memory.base,
357786
+                          hotplugabble_address_space_size, pcms->numa_nodes - 1,
357786
+                          MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED);
357786
     }
357786
 
357786
     build_header(linker, table_data,
357786
-- 
357786
1.8.3.1
357786