aboutsummaryrefslogtreecommitdiff
path: root/hw/core/machine.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2020-02-25 09:19:00 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2020-02-25 09:19:00 +0100
commitca6155c0f2bd39b4b4162533be401c98bd960820 (patch)
tree7e5212409c90fa40b6a50923557f2083c23637ba /hw/core/machine.c
parentc220cdec4845f305034330f80ce297f1f997f2d3 (diff)
parent9584b564198193bd54f00a01ed7e039d4f03fa31 (diff)
Merge tag 'patchew/20200219160953.13771-1-imammedo@redhat.com' of https://github.com/patchew-project/qemu into HEAD
This series removes ad hoc RAM allocation API (memory_region_allocate_system_memory) and consolidates it around hostmem backend. It allows to * resolve conflicts between global -mem-prealloc and hostmem's "policy" option, fixing premature allocation before binding policy is applied * simplify complicated memory allocation routines which had to deal with 2 ways to allocate RAM. * reuse hostmem backends of a choice for main RAM without adding extra CLI options to duplicate hostmem features. A recent case was -mem-shared, to enable vhost-user on targets that don't support hostmem backends [1] (ex: s390) * move RAM allocation from individual boards into generic machine code and provide them with prepared MemoryRegion. * clean up deprecated NUMA features which were tied to the old API (see patches) - "numa: remove deprecated -mem-path fallback to anonymous RAM" - (POSTPONED, waiting on libvirt side) "forbid '-numa node,mem' for 5.0 and newer machine types" - (POSTPONED) "numa: remove deprecated implicit RAM distribution between nodes" Introduce a new machine.memory-backend property and wrapper code that aliases global -mem-path and -mem-alloc into automatically created hostmem backend properties (provided memory-backend was not set explicitly given by user). A bulk of trivial patches then follow to incrementally convert individual boards to using machine.memory-backend provided MemoryRegion. Board conversion typically involves: * providing MachineClass::default_ram_size and MachineClass::default_ram_id so generic code could create default backend if user didn't explicitly provide memory-backend or -m options * dropping memory_region_allocate_system_memory() call * using convenience MachineState::ram MemoryRegion, which points to MemoryRegion allocated by ram-memdev On top of that for some boards: * missing ram_size checks are added (typically it were boards with fixed ram size) * ram_size fixups are replaced by checks and hard errors, forcing user to provide correct "-m" values instead of ignoring it and continuing running. After all boards are converted, the old API is removed and memory allocation routines are cleaned up.
Diffstat (limited to 'hw/core/machine.c')
-rw-r--r--hw/core/machine.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/hw/core/machine.c b/hw/core/machine.c
index ce403ccea9..9e8c06036f 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -26,6 +26,7 @@
#include "sysemu/qtest.h"
#include "hw/pci/pci.h"
#include "hw/mem/nvdimm.h"
+#include "migration/vmstate.h"
GlobalProperty hw_compat_4_2[] = {
{ "virtio-blk-device", "queue-size", "128"},
@@ -510,6 +511,22 @@ static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
}
}
+static char *machine_get_memdev(Object *obj, Error **errp)
+{
+ MachineState *ms = MACHINE(obj);
+
+ return g_strdup(ms->ram_memdev_id);
+}
+
+static void machine_set_memdev(Object *obj, const char *value, Error **errp)
+{
+ MachineState *ms = MACHINE(obj);
+
+ g_free(ms->ram_memdev_id);
+ ms->ram_memdev_id = g_strdup(value);
+}
+
+
static void machine_init_notify(Notifier *notifier, void *data)
{
MachineState *machine = MACHINE(qdev_get_machine());
@@ -891,6 +908,14 @@ static void machine_initfn(Object *obj)
"Table (HMAT)", NULL);
}
+ object_property_add_str(obj, "memory-backend",
+ machine_get_memdev, machine_set_memdev,
+ &error_abort);
+ object_property_set_description(obj, "memory-backend",
+ "Set RAM backend"
+ "Valid value is ID of hostmem based backend",
+ &error_abort);
+
/* Register notifier when init is done for sysbus sanity checks */
ms->sysbus_notifier.notify = machine_init_notify;
qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
@@ -1037,10 +1062,33 @@ static void machine_numa_finish_cpu_init(MachineState *machine)
g_string_free(s, true);
}
+MemoryRegion *machine_consume_memdev(MachineState *machine,
+ HostMemoryBackend *backend)
+{
+ MemoryRegion *ret = host_memory_backend_get_memory(backend);
+
+ if (memory_region_is_mapped(ret)) {
+ char *path = object_get_canonical_path_component(OBJECT(backend));
+ error_report("memory backend %s can't be used multiple times.", path);
+ g_free(path);
+ exit(EXIT_FAILURE);
+ }
+ host_memory_backend_set_mapped(backend, true);
+ vmstate_register_ram_global(ret);
+ return ret;
+}
+
void machine_run_board_init(MachineState *machine)
{
MachineClass *machine_class = MACHINE_GET_CLASS(machine);
+ if (machine->ram_memdev_id) {
+ Object *o;
+ o = object_resolve_path_type(machine->ram_memdev_id,
+ TYPE_MEMORY_BACKEND, NULL);
+ machine->ram = machine_consume_memdev(machine, MEMORY_BACKEND(o));
+ }
+
if (machine->numa_state) {
numa_complete_configuration(machine);
if (machine->numa_state->num_nodes) {