[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/27] machine: move more memory validation to Machine object
From: |
Paolo Bonzini |
Subject: |
[PULL 15/27] machine: move more memory validation to Machine object |
Date: |
Thu, 12 May 2022 19:24:53 +0200 |
This allows setting memory properties without going through
vl.c, and have them validated just the same.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20220414165300.555321-6-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/core/machine.c | 21 +++++++++++++++++++--
softmmu/vl.c | 17 +++--------------
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 8aab5416dd..3264c1e11d 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -21,12 +21,14 @@
#include "qapi/qapi-visit-common.h"
#include "qapi/qapi-visit-machine.h"
#include "qapi/visitor.h"
+#include "qom/object_interfaces.h"
#include "hw/sysbus.h"
#include "sysemu/cpus.h"
#include "sysemu/sysemu.h"
#include "sysemu/reset.h"
#include "sysemu/runstate.h"
#include "sysemu/numa.h"
+#include "sysemu/xen.h"
#include "qemu/error-report.h"
#include "sysemu/qtest.h"
#include "hw/pci/pci.h"
@@ -1301,8 +1303,23 @@ void machine_run_board_init(MachineState *machine, const
char *mem_path, Error *
clock values from the log. */
replay_checkpoint(CHECKPOINT_INIT);
- if (machine_class->default_ram_id && machine->ram_size &&
- numa_uses_legacy_mem() && !machine->memdev) {
+ if (!xen_enabled()) {
+ /* On 32-bit hosts, QEMU is limited by virtual address space */
+ if (machine->ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
+ error_setg(errp, "at most 2047 MB RAM can be simulated");
+ return;
+ }
+ }
+
+ if (machine->memdev) {
+ ram_addr_t backend_size =
object_property_get_uint(OBJECT(machine->memdev),
+ "size",
&error_abort);
+ if (backend_size != machine->ram_size) {
+ error_setg(errp, "Machine memory size does not match the size of
the memory backend");
+ return;
+ }
+ } else if (machine_class->default_ram_id && machine->ram_size &&
+ numa_uses_legacy_mem()) {
if (!create_default_memdev(current_machine, mem_path, errp)) {
return;
}
diff --git a/softmmu/vl.c b/softmmu/vl.c
index f6deec9380..edba74f075 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2027,24 +2027,13 @@ static void qemu_resolve_machine_memdev(void)
error_report("Memory backend '%s' not found", ram_memdev_id);
exit(EXIT_FAILURE);
}
- backend_size = object_property_get_uint(backend, "size",
&error_abort);
- if (have_custom_ram_size && backend_size != current_machine->ram_size)
{
- error_report("Size specified by -m option must match size of "
- "explicitly specified 'memory-backend' property");
- exit(EXIT_FAILURE);
+ if (!have_custom_ram_size) {
+ backend_size = object_property_get_uint(backend, "size",
&error_abort);
+ current_machine->ram_size = backend_size;
}
- current_machine->ram_size = backend_size;
object_property_set_link(OBJECT(current_machine),
"memory-backend", backend, &error_fatal);
}
-
- if (!xen_enabled()) {
- /* On 32-bit hosts, QEMU is limited by virtual address space */
- if (current_machine->ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
- error_report("at most 2047 MB RAM can be simulated");
- exit(1);
- }
- }
}
static void parse_memory_options(const char *arg)
--
2.36.0
- [PULL 18/27] net: slirp: switch to slirp_new, (continued)
- [PULL 18/27] net: slirp: switch to slirp_new, Paolo Bonzini, 2022/05/12
- [PULL 20/27] net: slirp: allow CFI with libslirp >= 4.7, Paolo Bonzini, 2022/05/12
- [PULL 21/27] coroutine-lock: qemu_co_queue_next is a coroutine-only qemu_co_enter_next, Paolo Bonzini, 2022/05/12
- [PULL 22/27] coroutine-lock: introduce qemu_co_queue_enter_all, Paolo Bonzini, 2022/05/12
- [PULL 08/27] tests/qtest/libqos/pci: Introduce pio_limit, Paolo Bonzini, 2022/05/12
- [PULL 04/27] checkpatch: fix g_malloc check, Paolo Bonzini, 2022/05/12
- [PULL 07/27] hw/xen/xen_pt: Resolve igd_passthrough_isa_bridge_create() indirection, Paolo Bonzini, 2022/05/12
- [PULL 09/27] tests/qtest/libqos: Skip hotplug tests if pci root bus is not hotpluggable, Paolo Bonzini, 2022/05/12
- [PULL 10/27] tests/qtest/libqos: Add generic pci host bridge in arm-virt machine, Paolo Bonzini, 2022/05/12
- [PULL 13/27] machine: add mem compound property, Paolo Bonzini, 2022/05/12
- [PULL 15/27] machine: move more memory validation to Machine object,
Paolo Bonzini <=
- [PULL 19/27] net: slirp: add support for CFI-friendly timer API, Paolo Bonzini, 2022/05/12
- [PULL 23/27] coroutine-lock: qemu_co_queue_restart_all is a coroutine-only qemu_co_enter_all, Paolo Bonzini, 2022/05/12
- [PULL 25/27] meson: link libpng independent of vnc, Paolo Bonzini, 2022/05/12
- [PULL 26/27] vl: make machine type deprecation a warning, Paolo Bonzini, 2022/05/12
- [PULL 24/27] vhost-backend: do not depend on CONFIG_VHOST_VSOCK, Paolo Bonzini, 2022/05/12
- [PULL 27/27] vmxcap: add tertiary execution controls, Paolo Bonzini, 2022/05/12
- Re: [PULL 00/27] Misc patches for 2022-05-12, Richard Henderson, 2022/05/12