]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
Merge tag 'patchew/20200219160953.13771-1-imammedo@redhat.com' of https://github...
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 25 Feb 2020 08:19:00 +0000 (09:19 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 25 Feb 2020 08:19:00 +0000 (09:19 +0100)
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.

1  2 
exec.c
hw/arm/xlnx-versal-virt.c
hw/core/machine.c
hw/m68k/next-cube.c
hw/ppc/e500.c
hw/ppc/pnv.c
hw/ppc/spapr.c
hw/ppc/virtex_ml507.c
include/sysemu/sysemu.h
softmmu/vl.c

diff --cc exec.c
Simple merge
Simple merge
index ce403ccea94a2bbc718b7694a0652152a1d0bc95,c8d361b710087a377705c4a0b6444b94d1a63a89..9e8c06036faf9c14f203a5f31e4bd42e32523c1d
  #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"},
 +    { "virtio-scsi-device", "virtqueue_size", "128"},
      { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
      { "virtio-blk-device", "seg-max-adjust", "off"},
      { "virtio-scsi-device", "seg_max_adjust", "off"},
Simple merge
diff --cc hw/ppc/e500.c
Simple merge
diff --cc hw/ppc/pnv.c
Simple merge
diff --cc hw/ppc/spapr.c
Simple merge
Simple merge
Simple merge
diff --cc softmmu/vl.c
index 92c7b3a6e95e085f76a7796a8888d1e95b505404,54857f7afabfe76df5c55756d2faec77491385e1..a9cce78f457e5a6f1b148e93b0b016f89a0641a6
--- 2/vl.c
@@@ -2786,7 -2827,25 +2808,25 @@@ static void configure_accelerators(cons
      }
  }
  
 -int main(int argc, char **argv, char **envp)
+ static void create_default_memdev(MachineState *ms, const char *path)
+ {
+     Object *obj;
+     MachineClass *mc = MACHINE_GET_CLASS(ms);
+     obj = object_new(path ? TYPE_MEMORY_BACKEND_FILE : TYPE_MEMORY_BACKEND_RAM);
+     if (path) {
+         object_property_set_str(obj, path, "mem-path", &error_fatal);
+     }
+     object_property_set_int(obj, ms->ram_size, "size", &error_fatal);
+     object_property_add_child(object_get_objects_root(), mc->default_ram_id,
+                               obj, &error_fatal);
+     user_creatable_complete(USER_CREATABLE(obj), &error_fatal);
+     object_unref(obj);
+     object_property_set_str(OBJECT(ms), mc->default_ram_id, "memory-backend",
+                             &error_fatal);
+ }
 +void qemu_init(int argc, char **argv, char **envp)
  {
      int i;
      int snapshot, linux_boot;
      machine_class = select_machine();
      object_set_machine_compat_props(machine_class->compat_props);
  
-     set_memory_options(&ram_slots, &maxram_size, machine_class);
      os_daemonize();
 -    rcu_disable_atfork();
 +
 +    /*
 +     * If QTest is enabled, keep the rcu_atfork enabled, since system processes
 +     * may be forked testing purposes (e.g. fork-server based fuzzing) The fork
 +     * should happen before a signle cpu instruction is executed, to prevent
 +     * deadlocks. See commit 73c6e40, rcu: "completely disable pthread_atfork
 +     * callbacks as soon as possible"
 +     */
 +    if (!qtest_enabled()) {
 +        rcu_disable_atfork();
 +    }
  
      if (pid_file && !qemu_write_pidfile(pid_file, &err)) {
          error_reportf_err(err, "cannot create PID file: ");
      if (cpu_option) {
          current_machine->cpu_type = parse_cpu_option(cpu_option);
      }
+     set_memory_options(&ram_slots, &maxram_size, machine_class);
+     current_machine->ram_size = ram_size;
+     current_machine->maxram_size = maxram_size;
+     current_machine->ram_slots = ram_slots;
      parse_numa_opts(current_machine);
  
+     if (machine_class->default_ram_id && current_machine->ram_size &&
+         numa_uses_legacy_mem() && !current_machine->ram_memdev_id) {
+         create_default_memdev(current_machine, mem_path);
+     }
      /* do monitor/qmp handling at preconfig state if requested */
 -    main_loop();
 +    qemu_main_loop();
  
      audio_init_audiodevs();