aboutsummaryrefslogtreecommitdiff
path: root/hw/core
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2022-04-14 12:53:00 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2022-05-12 12:29:44 +0200
commitfb56b7a052e1443409334c579e617e287a7250d3 (patch)
treefef537f1565dc41a343339c8b4842ee112672860 /hw/core
parent26f88d84dab62e6eb3ec72737ccb155d06049e3a (diff)
downloadqemu-fb56b7a052e1443409334c579e617e287a7250d3.zip
qemu-fb56b7a052e1443409334c579e617e287a7250d3.tar.gz
qemu-fb56b7a052e1443409334c579e617e287a7250d3.tar.bz2
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>
Diffstat (limited to 'hw/core')
-rw-r--r--hw/core/machine.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 8aab541..3264c1e 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;
}