]> git.proxmox.com Git - mirror_qemu.git/blobdiff - numa.c
target/arm: Implement FCSEL for fp16
[mirror_qemu.git] / numa.c
diff --git a/numa.c b/numa.c
index 8d78d959f68c3e93a2aa95bdb744fad976441dc9..1116c90af9ebd3ae77202c587beebeeae1fa54cf 100644 (file)
--- a/numa.c
+++ b/numa.c
 #include "qemu/bitmap.h"
 #include "qom/cpu.h"
 #include "qemu/error-report.h"
-#include "include/exec/cpu-common.h" /* for RAM_ADDR_FMT */
-#include "qapi-visit.h"
+#include "qapi/error.h"
 #include "qapi/opts-visitor.h"
+#include "qapi/qapi-commands-misc.h"
+#include "qapi/qapi-visit-misc.h"
 #include "hw/boards.h"
 #include "sysemu/hostmem.h"
-#include "qmp-commands.h"
 #include "hw/mem/pc-dimm.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
@@ -55,92 +55,6 @@ int nb_numa_nodes;
 bool have_numa_distance;
 NodeInfo numa_info[MAX_NODES];
 
-void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node)
-{
-    struct numa_addr_range *range;
-
-    /*
-     * Memory-less nodes can come here with 0 size in which case,
-     * there is nothing to do.
-     */
-    if (!size) {
-        return;
-    }
-
-    range = g_malloc0(sizeof(*range));
-    range->mem_start = addr;
-    range->mem_end = addr + size - 1;
-    QLIST_INSERT_HEAD(&numa_info[node].addr, range, entry);
-}
-
-void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node)
-{
-    struct numa_addr_range *range, *next;
-
-    QLIST_FOREACH_SAFE(range, &numa_info[node].addr, entry, next) {
-        if (addr == range->mem_start && (addr + size - 1) == range->mem_end) {
-            QLIST_REMOVE(range, entry);
-            g_free(range);
-            return;
-        }
-    }
-}
-
-static void numa_set_mem_ranges(void)
-{
-    int i;
-    ram_addr_t mem_start = 0;
-
-    /*
-     * Deduce start address of each node and use it to store
-     * the address range info in numa_info address range list
-     */
-    for (i = 0; i < nb_numa_nodes; i++) {
-        numa_set_mem_node_id(mem_start, numa_info[i].node_mem, i);
-        mem_start += numa_info[i].node_mem;
-    }
-}
-
-/*
- * Check if @addr falls under NUMA @node.
- */
-static bool numa_addr_belongs_to_node(ram_addr_t addr, uint32_t node)
-{
-    struct numa_addr_range *range;
-
-    QLIST_FOREACH(range, &numa_info[node].addr, entry) {
-        if (addr >= range->mem_start && addr <= range->mem_end) {
-            return true;
-        }
-    }
-    return false;
-}
-
-/*
- * Given an address, return the index of the NUMA node to which the
- * address belongs to.
- */
-uint32_t numa_get_node(ram_addr_t addr, Error **errp)
-{
-    uint32_t i;
-
-    /* For non NUMA configurations, check if the addr falls under node 0 */
-    if (!nb_numa_nodes) {
-        if (numa_addr_belongs_to_node(addr, 0)) {
-            return 0;
-        }
-    }
-
-    for (i = 0; i < nb_numa_nodes; i++) {
-        if (numa_addr_belongs_to_node(addr, i)) {
-            return i;
-        }
-    }
-
-    error_setg(errp, "Address 0x" RAM_ADDR_FMT " doesn't belong to any "
-                "NUMA node", addr);
-    return -1;
-}
 
 static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
                             Error **errp)
@@ -166,7 +80,7 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
         return;
     }
 
-    if (!mc->cpu_index_to_instance_props) {
+    if (!mc->cpu_index_to_instance_props || !mc->get_default_cpu_node_id) {
         error_report("NUMA is not supported by this machine-type");
         exit(1);
     }
@@ -216,6 +130,7 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
     }
     numa_info[nodenr].present = true;
     max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
+    nb_numa_nodes++;
 }
 
 static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
@@ -282,7 +197,6 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
         if (err) {
             goto end;
         }
-        nb_numa_nodes++;
         break;
     case NUMA_OPTIONS_TYPE_DIST:
         parse_numa_distance(&object->u.dist, &err);
@@ -433,6 +347,25 @@ void parse_numa_opts(MachineState *ms)
         exit(1);
     }
 
+    /*
+     * If memory hotplug is enabled (slots > 0) but without '-numa'
+     * options explicitly on CLI, guestes will break.
+     *
+     *   Windows: won't enable memory hotplug without SRAT table at all
+     *
+     *   Linux: if QEMU is started with initial memory all below 4Gb
+     *   and no SRAT table present, guest kernel will use nommu DMA ops,
+     *   which breaks 32bit hw drivers when memory is hotplugged and
+     *   guest tries to use it with that drivers.
+     *
+     * Enable NUMA implicitly by adding a new NUMA node automatically.
+     */
+    if (ms->ram_slots > 0 && nb_numa_nodes == 0 &&
+        mc->auto_enable_numa_with_memhp) {
+            NumaNodeOptions node = { };
+            parse_numa_node(ms, &node, NULL);
+    }
+
     assert(max_numa_nodeid <= MAX_NODES);
 
     /* No support for sparse NUMA node IDs yet: */
@@ -478,12 +411,6 @@ void parse_numa_opts(MachineState *ms)
             exit(1);
         }
 
-        for (i = 0; i < nb_numa_nodes; i++) {
-            QLIST_INIT(&numa_info[i].addr);
-        }
-
-        numa_set_mem_ranges();
-
         /* QEMU needs at least all unique node pair distances to build
          * the whole NUMA distance table. QEMU treats the distance table
          * as symmetric by default, i.e. distance A->B == distance B->A.
@@ -503,8 +430,6 @@ void parse_numa_opts(MachineState *ms)
             /* Validation succeeded, now fill in any missing distances. */
             complete_init_numa_distance();
         }
-    } else {
-        numa_set_mem_node_id(0, ram_size, 0);
     }
 }
 
@@ -532,13 +457,14 @@ static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
     if (mem_path) {
 #ifdef __linux__
         Error *err = NULL;
-        memory_region_init_ram_from_file(mr, owner, name, ram_size, false,
+        memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, false,
                                          mem_path, &err);
         if (err) {
             error_report_err(err);
             if (mem_prealloc) {
                 exit(1);
             }
+            error_report("falling back to regular RAM allocation.");
 
             /* Legacy behavior: if allocation failed, fall back to
              * regular RAM allocation.
@@ -594,29 +520,34 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
 
 static void numa_stat_memory_devices(NumaNodeMem node_mem[])
 {
-    MemoryDeviceInfoList *info_list = NULL;
-    MemoryDeviceInfoList **prev = &info_list;
+    MemoryDeviceInfoList *info_list = qmp_pc_dimm_device_list();
     MemoryDeviceInfoList *info;
     PCDIMMDeviceInfo     *pcdimm_info;
 
-    qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
     for (info = info_list; info; info = info->next) {
         MemoryDeviceInfo *value = info->value;
 
         if (value) {
             switch (value->type) {
-            case MEMORY_DEVICE_INFO_KIND_DIMM: {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
                 pcdimm_info = value->u.dimm.data;
+                break;
+
+            case MEMORY_DEVICE_INFO_KIND_NVDIMM:
+                pcdimm_info = value->u.nvdimm.data;
+                break;
+
+            default:
+                pcdimm_info = NULL;
+                break;
+            }
+
+            if (pcdimm_info) {
                 node_mem[pcdimm_info->node].node_mem += pcdimm_info->size;
                 if (pcdimm_info->hotpluggable && pcdimm_info->hotplugged) {
                     node_mem[pcdimm_info->node].node_plugged_mem +=
                         pcdimm_info->size;
                 }
-                break;
-            }
-
-            default:
-                break;
             }
         }
     }