machine: move more memory validation to Machine object
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>
This commit is contained in:
parent
26f88d84da
commit
fb56b7a052
|
@ -21,12 +21,14 @@
|
||||||
#include "qapi/qapi-visit-common.h"
|
#include "qapi/qapi-visit-common.h"
|
||||||
#include "qapi/qapi-visit-machine.h"
|
#include "qapi/qapi-visit-machine.h"
|
||||||
#include "qapi/visitor.h"
|
#include "qapi/visitor.h"
|
||||||
|
#include "qom/object_interfaces.h"
|
||||||
#include "hw/sysbus.h"
|
#include "hw/sysbus.h"
|
||||||
#include "sysemu/cpus.h"
|
#include "sysemu/cpus.h"
|
||||||
#include "sysemu/sysemu.h"
|
#include "sysemu/sysemu.h"
|
||||||
#include "sysemu/reset.h"
|
#include "sysemu/reset.h"
|
||||||
#include "sysemu/runstate.h"
|
#include "sysemu/runstate.h"
|
||||||
#include "sysemu/numa.h"
|
#include "sysemu/numa.h"
|
||||||
|
#include "sysemu/xen.h"
|
||||||
#include "qemu/error-report.h"
|
#include "qemu/error-report.h"
|
||||||
#include "sysemu/qtest.h"
|
#include "sysemu/qtest.h"
|
||||||
#include "hw/pci/pci.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. */
|
clock values from the log. */
|
||||||
replay_checkpoint(CHECKPOINT_INIT);
|
replay_checkpoint(CHECKPOINT_INIT);
|
||||||
|
|
||||||
if (machine_class->default_ram_id && machine->ram_size &&
|
if (!xen_enabled()) {
|
||||||
numa_uses_legacy_mem() && !machine->memdev) {
|
/* 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)) {
|
if (!create_default_memdev(current_machine, mem_path, errp)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
15
softmmu/vl.c
15
softmmu/vl.c
|
@ -2027,24 +2027,13 @@ static void qemu_resolve_machine_memdev(void)
|
||||||
error_report("Memory backend '%s' not found", ram_memdev_id);
|
error_report("Memory backend '%s' not found", ram_memdev_id);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
if (!have_custom_ram_size) {
|
||||||
backend_size = object_property_get_uint(backend, "size", &error_abort);
|
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);
|
|
||||||
}
|
|
||||||
current_machine->ram_size = backend_size;
|
current_machine->ram_size = backend_size;
|
||||||
|
}
|
||||||
object_property_set_link(OBJECT(current_machine),
|
object_property_set_link(OBJECT(current_machine),
|
||||||
"memory-backend", backend, &error_fatal);
|
"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)
|
static void parse_memory_options(const char *arg)
|
||||||
|
|
Loading…
Reference in New Issue