Skip to contentSkip to conversation

pc: ACPI memory hotplug

PATCH Applied Igor Mammedov 5 participants 49 messages Jun 2, 2014 – Jun 11, 2014 Arm STM32

lore
Share & tools
lore
#0 lore raw

v4 cover pc: ACPI memory hotplug

NOTE to commiter:
* update precompiled ACPI hex files for iasl-less hosts and ACPI tables test to match new ACPI tables.

What's new since v10:
* rename DimmDevice to PCDIMMDevice
* allow anonymous DIMMs
* fix error handling in hostmemory_backend_set_size()
* fix ACPI read callback for case when guest tries to read addr/length from slot without a present DIMM

What's new since v9:
* drop usage of error_is_set()
* exit QEMU if it's started with memory hotplug but compat machine doesn't support it
* rename cpu_hotplug_defs.h to pc-hotplug.h
* use subsection when migrating acpi memory hotplug state
* add property to PC_MACHINE for getting hotplug memory region size

What's new since v8:
* rebased on top of Marcel's QOMyfing machine work depends on patch from qom-next:
"machine: Conversion of QEMUMachineInitArgs to MachineState"
* fixed QEMU abort if it's running in daemonized mode
* fixed leak in memdev backend
* introduced custom PCMachine
* DIMM devices are now bus-less and use bus-less hotplug method
* DIMMDevice: renamed property/field 'start' to 'addr'
* ACPI tables:
* avoid punching hotples in PCI CRS by placing MEMORY_HOPTLUG_DEVICE on PCI0 bus
* incorporated most of comments/fixes from reviewers

What's new since v7:
* Per Andreas' suggestion dropped DIMMBus concept.
* Added hotplug binding for bus-less devices
* DIMM device is split to backend and frontend. Therefore following command/options were added for supporting it:

For memory-ram backend:
CLI: -object-add memory-ram,
with options: 'id' and 'size'
For dimm frontend:
option "size" became readonly, pulling it's size from attached backend added option "memdev" for specifying backend by 'id'

* dropped support for 32 bit guests
* failed hotplug action doesn't consume 1 slot anymore
* vaious fixes adressing reviewer's comments most of them in ACPI part
---

This series allows to hotplug 'arbitrary' DIMM devices specifying size, NUMA node mapping (guest side), slot and address where to map it, at runtime.

Due to ACPI limitation there is need to specify a number of possible DIMM devices. For this task -m option was extended to support following format:

-m [mem=]RamSize[,slots=N,maxmem=M]

To allow memory hotplug user must specify a pair of additional parameters:
'slots' - number of possible increments
'maxmem' - max possible total memory size QEMU is allowed to use,
including RamSize.

minimal monitor command syntax to hotplug DIMM device:

object_add memory-ram,id=memX,size=1G
device_add pc-dimm,id=dimmX,memdev=memX

pc-dimm device provides following properties that could be used with device_add / -device to alter default behavior:

id - unique string identifying device [mandatory]
slot - number in range [0-slots) [optional], if not specified
the first free slot is used
node - NUMA node id [optional] (default: 0)
size - amount of memory to add, readonly derived from backing memdev addr - guest's physical address where to plug DIMM [optional],
if not specified the first gap in hotplug memory region that fits DIMM is used

-device option could be used for adding potentially hotunplugable DIMMs
and also for specifying hotplugged DIMMs in migration case.

Tested guests:
- RHEL 6x64
- Windows 2012DCx64
- Windows 2008DCx64

Known limitations/bugs/TODOs:
- hot-remove is not supported, yet
- max number of supported DIMM devices 256 (due to ACPI object name limit), could be increased creating several containers and putting DIMMs there. (exercise for future)
- e820 table doesn't include DIMM devices added with -device / (or after reboot devices added with device_add)
- Windows 2008 remembers DIMM configuration, so if DIMM with other addr/size is added into the same slot, it refuses to use it insisting on old mapping.

QEMU git tree for testing is available at:
https://github.com/imammedo/qemu/commits/memory-hotplug-v11

Example QEMU cmd line:

  qemu-system-x86_64 -enable-kvm -monitor unix:/tmp/mon,server,nowait \ 
     -m 4096,slots=4,maxmem=8G guest.img

PS:
Windows guest requires SRAT table for hotplug to work so add an extra option:
-numa node

Igor Mammedov (32):
pc: create custom generic PC machine type
pc: ACPI BIOS: use enum for defining memory affinity flags
object_add: allow completion handler to get canonical path vl.c: daemonize before guest memory allocation
add memdev backend infrastructure
vl.c: extend -m option to support options for memory hotplug
qdev: hotplug for buss-less devices
qdev: expose DeviceState.hotplugged field as a property
memory: add memory_region_is_mapped() API
pc-dimm: do not allow to set already used memdev
pc: initialize memory hotplug address space
pc: exit QEMU if number of slots more than supported 256
pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS
pc: exit QEMU if compat machine doesn't support memory hotlpug
pc: add memory hotplug handler to PC_MACHINE
pc-dimm: add busy address check and address auto-allocation
pc-dimm: add busy slot check and slot auto-allocation
acpi: rename cpu_hotplug_defs.h to pc-hotplug.h
acpi: memory hotplug ACPI hardware implementation
trace: add acpi memory hotplug IO region events
trace: pc: add PC_DIMM slot & address allocation acpi:piix4: allow plug/unlug callbacks handle not only PCI devices acpi:piix4: add memory hotplug handling
pc: ich9 lpc: make it work with global/compat properties acpi:ich9: add memory hotplug handling
pc: migrate piix4 & ich9 MemHotplugState
pc: add acpi-device link to PCMachineState
pc: propagate memory hotplug event to ACPI device
pc: ACPI BIOS: implement memory hotplug interface
pc: add "hotplug-memory-region-size" property to PC_MACHINE
pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole
pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35
machines

Vasilis Liaskovitis (1):
pc: implement pc-dimm device abstraction

 backends/Makefile.objs             |    2 +
 backends/hostmem-ram.c             |   54 ++++++++
 backends/hostmem.c                 |   97 +++++++++++++++
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 docs/specs/acpi_mem_hotplug.txt    |   44 +++++++
 hw/Makefile.objs                   |    1 +
 hw/acpi/Makefile.objs              |    1 +
 hw/acpi/ich9.c                     |   62 ++++++++++
 hw/acpi/memory_hotplug.c           |  187 ++++++++++++++++++++++++++++
 hw/acpi/piix4.c                    |   74 ++++++++++--
 hw/core/qdev.c                     |   30 +++++
 hw/i386/Makefile.objs              |    3 +-
 hw/i386/acpi-build.c               |   75 ++++++++++-
 hw/i386/acpi-dsdt.dsl              |    7 +-
 hw/i386/pc.c                       |  227 ++++++++++++++++++++++++++++++++++-
 hw/i386/pc_piix.c                  |   51 +++++---
 hw/i386/pc_q35.c                   |   25 +++-
 hw/i386/q35-acpi-dsdt.dsl          |    7 +-
 hw/i386/ssdt-mem.dsl               |   77 ++++++++++++
 hw/i386/ssdt-misc.dsl              |  164 +++++++++++++++++++++++++
 hw/isa/lpc_ich9.c                  |   33 +++++-
 hw/mem/Makefile.objs               |    1 +
 hw/mem/pc-dimm.c                   |  236 ++++++++++++++++++++++++++++++++++++
 hw/mips/mips_malta.c               |    2 +-
 include/exec/memory.h              |    8 ++
 include/hw/acpi/acpi.h             |    6 +
 include/hw/acpi/cpu_hotplug.h      |    2 +-
 include/hw/acpi/cpu_hotplug_defs.h |   32 -----
 include/hw/acpi/ich9.h             |    4 +
 include/hw/acpi/memory_hotplug.h   |   37 ++++++
 include/hw/acpi/pc-hotplug.h       |   56 +++++++++
 include/hw/boards.h                |   10 ++
 include/hw/i386/pc.h               |   64 ++++++++++-
 include/hw/mem/pc-dimm.h           |   79 ++++++++++++
 include/sysemu/hostmem.h           |   60 +++++++++
 memory.c                           |   10 ++-
 qemu-options.hx                    |    9 +-
 qmp.c                              |   11 ++-
 trace-events                       |   17 +++
 vl.c                               |   64 +++++++++-
 41 files changed, 1829 insertions(+), 102 deletions(-)
 create mode 100644 backends/hostmem-ram.c
 create mode 100644 backends/hostmem.c
 create mode 100644 docs/specs/acpi_mem_hotplug.txt
 create mode 100644 hw/acpi/memory_hotplug.c
 create mode 100644 hw/i386/ssdt-mem.dsl
 create mode 100644 hw/mem/Makefile.objs
 create mode 100644 hw/mem/pc-dimm.c
 delete mode 100644 include/hw/acpi/cpu_hotplug_defs.h
 create mode 100644 include/hw/acpi/memory_hotplug.h
 create mode 100644 include/hw/acpi/pc-hotplug.h
 create mode 100644 include/hw/mem/pc-dimm.h
 create mode 100644 include/sysemu/hostmem.h
#1 lore raw

PATCH v4 1/33 pc: create custom generic PC machine type

it will be used for PC specific options/variables

---
 hw/i386/pc.c         |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/pc_piix.c    |   36 +++++++++++++++---------------
 hw/i386/pc_q35.c     |   12 +++++-----
 include/hw/i386/pc.h |   24 +++++++++++++++++++++
 4 files changed, 105 insertions(+), 24 deletions(-)
hw/i386/pc.c +57 -0
index e6369d5..f6781d8 100644
@@ -1459,3 +1459,60 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
         gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i);
     }
 }
+
+static void pc_generic_machine_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    QEMUMachine *qm = data;
+
+    mc->name = qm->name;
+    mc->alias = qm->alias;
+    mc->desc = qm->desc;
+    mc->init = qm->init;
+    mc->reset = qm->reset;
+    mc->hot_add_cpu = qm->hot_add_cpu;
+    mc->kvm_type = qm->kvm_type;
+    mc->block_default_type = qm->block_default_type;
+    mc->max_cpus = qm->max_cpus;
+    mc->no_serial = qm->no_serial;
+    mc->no_parallel = qm->no_parallel;
+    mc->use_virtcon = qm->use_virtcon;
+    mc->use_sclp = qm->use_sclp;
+    mc->no_floppy = qm->no_floppy;
+    mc->no_cdrom = qm->no_cdrom;
+    mc->no_sdcard = qm->no_sdcard;
+    mc->is_default = qm->is_default;
+    mc->default_machine_opts = qm->default_machine_opts;
+    mc->default_boot_order = qm->default_boot_order;
+    mc->compat_props = qm->compat_props;
+    mc->hw_version = qm->hw_version;
+}
+
+void qemu_register_pc_machine(QEMUMachine *m)
+{
+    char *name = g_strconcat(m->name, TYPE_MACHINE_SUFFIX, NULL);
+    TypeInfo ti = {
+        .name       = name,
+        .parent     = TYPE_PC_MACHINE,
+        .class_init = pc_generic_machine_class_init,
+        .class_data = (void *)m,
+    };
+
+    type_register(&ti);
+    g_free(name);
+}
+
+static const TypeInfo pc_machine_info = {
+    .name = TYPE_PC_MACHINE,
+    .parent = TYPE_MACHINE,
+    .abstract = true,
+    .instance_size = sizeof(PCMachineState),
+    .class_size = sizeof(PCMachineClass),
+};
+
+static void pc_machine_register_types(void)
+{
+    type_register_static(&pc_machine_info);
+}
+
+type_init(pc_machine_register_types)
hw/i386/pc_piix.c +18 -18
index a48e263..abb599b 100644
@@ -843,25 +843,25 @@ static QEMUMachine xenfv_machine = {
 
 static void pc_machine_init(void)
 {
-    qemu_register_machine(&pc_i440fx_machine_v2_1);
-    qemu_register_machine(&pc_i440fx_machine_v2_0);
-    qemu_register_machine(&pc_i440fx_machine_v1_7);
-    qemu_register_machine(&pc_i440fx_machine_v1_6);
-    qemu_register_machine(&pc_i440fx_machine_v1_5);
-    qemu_register_machine(&pc_i440fx_machine_v1_4);
-    qemu_register_machine(&pc_machine_v1_3);
-    qemu_register_machine(&pc_machine_v1_2);
-    qemu_register_machine(&pc_machine_v1_1);
-    qemu_register_machine(&pc_machine_v1_0);
-    qemu_register_machine(&pc_machine_v0_15);
-    qemu_register_machine(&pc_machine_v0_14);
-    qemu_register_machine(&pc_machine_v0_13);
-    qemu_register_machine(&pc_machine_v0_12);
-    qemu_register_machine(&pc_machine_v0_11);
-    qemu_register_machine(&pc_machine_v0_10);
-    qemu_register_machine(&isapc_machine);
+    qemu_register_pc_machine(&pc_i440fx_machine_v2_1);
+    qemu_register_pc_machine(&pc_i440fx_machine_v2_0);
+    qemu_register_pc_machine(&pc_i440fx_machine_v1_7);
+    qemu_register_pc_machine(&pc_i440fx_machine_v1_6);
+    qemu_register_pc_machine(&pc_i440fx_machine_v1_5);
+    qemu_register_pc_machine(&pc_i440fx_machine_v1_4);
+    qemu_register_pc_machine(&pc_machine_v1_3);
+    qemu_register_pc_machine(&pc_machine_v1_2);
+    qemu_register_pc_machine(&pc_machine_v1_1);
+    qemu_register_pc_machine(&pc_machine_v1_0);
+    qemu_register_pc_machine(&pc_machine_v0_15);
+    qemu_register_pc_machine(&pc_machine_v0_14);
+    qemu_register_pc_machine(&pc_machine_v0_13);
+    qemu_register_pc_machine(&pc_machine_v0_12);
+    qemu_register_pc_machine(&pc_machine_v0_11);
+    qemu_register_pc_machine(&pc_machine_v0_10);
+    qemu_register_pc_machine(&isapc_machine);
 #ifdef CONFIG_XEN
-    qemu_register_machine(&xenfv_machine);
+    qemu_register_pc_machine(&xenfv_machine);
 #endif
 }
 
hw/i386/pc_q35.c +6 -6
index b3c02c1..d211393 100644
@@ -384,12 +384,12 @@ static QEMUMachine pc_q35_machine_v1_4 = {
 
 static void pc_q35_machine_init(void)
 {
-    qemu_register_machine(&pc_q35_machine_v2_1);
-    qemu_register_machine(&pc_q35_machine_v2_0);
-    qemu_register_machine(&pc_q35_machine_v1_7);
-    qemu_register_machine(&pc_q35_machine_v1_6);
-    qemu_register_machine(&pc_q35_machine_v1_5);
-    qemu_register_machine(&pc_q35_machine_v1_4);
+    qemu_register_pc_machine(&pc_q35_machine_v2_1);
+    qemu_register_pc_machine(&pc_q35_machine_v2_0);
+    qemu_register_pc_machine(&pc_q35_machine_v1_7);
+    qemu_register_pc_machine(&pc_q35_machine_v1_6);
+    qemu_register_pc_machine(&pc_q35_machine_v1_5);
+    qemu_register_pc_machine(&pc_q35_machine_v1_4);
 }
 
 machine_init(pc_q35_machine_init);
include/hw/i386/pc.h +24 -0
index 32a7687..c7b053c 100644
@@ -12,9 +12,33 @@
 #include "qemu/bitmap.h"
 #include "sysemu/sysemu.h"
 #include "hw/pci/pci.h"
+#include "hw/boards.h"
 
 #define HPET_INTCAP "hpet-intcap"
 
+struct PCMachineState {
+    /*< private >*/
+    MachineState parent_obj;
+};
+
+struct PCMachineClass {
+    /*< private >*/
+    MachineClass parent_class;
+};
+
+typedef struct PCMachineState PCMachineState;
+typedef struct PCMachineClass PCMachineClass;
+
+#define TYPE_PC_MACHINE "generic-pc-machine"
+#define PC_MACHINE(obj) \
+    OBJECT_CHECK(PCMachineState, (obj), TYPE_PC_MACHINE)
+#define PC_MACHINE_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(PCMachineClass, (obj), TYPE_PC_MACHINE)
+#define PC_MACHINE_CLASS(klass) \
+    OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE)
+
+void qemu_register_pc_machine(QEMUMachine *m);
+
 /* PC-style peripherals (also used by other machines).  */
 
 typedef struct PcPciInfo {
Signature · 1 line
1.7.1
#2 lore raw

PATCH v4 2/33 pc: ACPI BIOS: use enum for defining memory affinity flags

In reply to Igor Mammedov

replace magic numbers with enum describing Flags field of memory affinity in SRAT table.

MemoryAffinityFlags enum will define flags decribed by:
ACPI spec 5.0, "5.2.16.2 Memory Affinity Structure", "Table 5-69 Flags - Memory Affinity Structure"

---
 hw/i386/acpi-build.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
hw/i386/acpi-build.c +16 -7
index 9fac589..34c0f42 100644
@@ -1132,15 +1132,22 @@ build_hpet(GArray *table_data, GArray *linker)
                  (void *)hpet, "HPET", sizeof(*hpet), 1);
 }
 
+typedef enum {
+    MEM_AFFINITY_NOFLAGS      = 0,
+    MEM_AFFINITY_ENABLED      = (1 << 0),
+    MEM_AFFINITY_HOTPLUGGABLE = (1 << 1),
+    MEM_AFFINITY_NON_VOLATILE = (1 << 2),
+} MemoryAffinityFlags;
+
 static void
-acpi_build_srat_memory(AcpiSratMemoryAffinity *numamem,
-                       uint64_t base, uint64_t len, int node, int enabled)
+acpi_build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base,
+                       uint64_t len, int node, MemoryAffinityFlags flags)
 {
     numamem->type = ACPI_SRAT_MEMORY;
     numamem->length = sizeof(*numamem);
     memset(numamem->proximity, 0, 4);
     numamem->proximity[0] = node;
-    numamem->flags = cpu_to_le32(!!enabled);
+    numamem->flags = cpu_to_le32(flags);
     numamem->base_addr = cpu_to_le64(base);
     numamem->range_length = cpu_to_le64(len);
 }
@@ -1188,7 +1195,7 @@ build_srat(GArray *table_data, GArray *linker,
     numa_start = table_data->len;
 
     numamem = acpi_data_push(table_data, sizeof *numamem);
-    acpi_build_srat_memory(numamem, 0, 640*1024, 0, 1);
+    acpi_build_srat_memory(numamem, 0, 640*1024, 0, MEM_AFFINITY_ENABLED);
     next_base = 1024 * 1024;
     for (i = 1; i < guest_info->numa_nodes + 1; ++i) {
         mem_base = next_base;
@@ -1204,19 +1211,21 @@ build_srat(GArray *table_data, GArray *linker,
             mem_len -= next_base - guest_info->ram_size_below_4g;
             if (mem_len > 0) {
                 numamem = acpi_data_push(table_data, sizeof *numamem);
-                acpi_build_srat_memory(numamem, mem_base, mem_len, i-1, 1);
+                acpi_build_srat_memory(numamem, mem_base, mem_len, i - 1,
+                                       MEM_AFFINITY_ENABLED);
             }
             mem_base = 1ULL << 32;
             mem_len = next_base - guest_info->ram_size_below_4g;
             next_base += (1ULL << 32) - guest_info->ram_size_below_4g;
         }
         numamem = acpi_data_push(table_data, sizeof *numamem);
-        acpi_build_srat_memory(numamem, mem_base, mem_len, i - 1, 1);
+        acpi_build_srat_memory(numamem, mem_base, mem_len, i - 1,
+                               MEM_AFFINITY_ENABLED);
     }
     slots = (table_data->len - numa_start) / sizeof *numamem;
     for (; slots < guest_info->numa_nodes + 2; slots++) {
         numamem = acpi_data_push(table_data, sizeof *numamem);
-        acpi_build_srat_memory(numamem, 0, 0, 0, 0);
+        acpi_build_srat_memory(numamem, 0, 0, 0, MEM_AFFINITY_NOFLAGS);
     }
 
     build_header(linker, table_data,
Signature · 1 line
1.7.1
#3 lore raw

PATCH v4 3/33 object_add: allow completion handler to get canonical path

In reply to Igor Mammedov

Add object to /objects before calling user_creatable_complete() handler, so that object might be able to call object_get_canonical_path() in its completion handler.

---
 qmp.c |   11 ++++++++---
 vl.c  |    9 +++++----
 2 files changed, 13 insertions(+), 7 deletions(-)
qmp.c +8 -3
index a7f432b..b722dbe 100644
@@ -565,13 +565,18 @@ void object_add(const char *type, const char *id, const QDict *qdict,
         }
     }
 
-    user_creatable_complete(obj, &local_err);
+    object_property_add_child(container_get(object_get_root(), "/objects"),
+                              id, obj, &local_err);
     if (local_err) {
         goto out;
     }
 
-    object_property_add_child(container_get(object_get_root(), "/objects"),
-                              id, obj, &local_err);
+    user_creatable_complete(obj, &local_err);
+    if (local_err) {
+        object_property_del(container_get(object_get_root(), "/objects"),
+                            id, &error_abort);
+        goto out;
+    }
 out:
     if (local_err) {
         error_propagate(errp, local_err);
vl.c +5 -4
index 0c15608..037aa62 100644
@@ -2935,14 +2935,15 @@ static int object_create(QemuOpts *opts, void *opaque)
         goto out;
     }
 
+    object_property_add_child(container_get(object_get_root(), "/objects"),
+                              id, obj, &local_err);
+
     user_creatable_complete(obj, &local_err);
     if (local_err) {
+        object_property_del(container_get(object_get_root(), "/objects"),
+                            id, &error_abort);
         goto out;
     }
-
-    object_property_add_child(container_get(object_get_root(), "/objects"),
-                              id, obj, &local_err);
-
 out:
     object_unref(obj);
     if (local_err) {
Signature · 1 line
1.7.1
#4 lore raw

PATCH v4 4/33 vl.c: daemonize before guest memory allocation

In reply to Igor Mammedov

memory allocated for guest before QEMU is daemonized and then mapped later in guest's address space after it is daemonized, leads to EPT violation and QEMU aborts.

To avoid this and similar issues switch to daemonized mode early before applying/processing other options.

---
I haven't digged in kvm itself yet why EPT violation happens, but fix on QEMU side looks trivial so it won't hurt to use it anyway.

there is simpler reporoducer without migration, start guest with
'-object memory-ram,id=foo,size=1G'
when guest is up and running hotplug dimm device using 'foo' memdev as backend.

---
 vl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
index 037aa62..2449d78 100644
@@ -3965,6 +3965,8 @@ int main(int argc, char **argv, char **envp)
     }
     loc_set_none();
 
+    os_daemonize();
+
     if (qemu_init_main_loop()) {
         fprintf(stderr, "qemu_init_main_loop failed\n");
         exit(1);
@@ -4206,8 +4208,6 @@ int main(int argc, char **argv, char **envp)
     }
 #endif
 
-    os_daemonize();
-
     if (pid_file && qemu_create_pidfile(pid_file) != 0) {
         os_pidfile_error();
         exit(1);
Signature · 1 line
1.7.1
#5 lore raw

PATCH v4 5/33 add memdev backend infrastructure

In reply to Igor Mammedov

Provides framework for splitting host RAM allocation/ policies into a separate backend that could be used by devices.

Initially only legacy RAM backend is provided, which uses memory_region_init_ram() allocator and compatible with every CLI option that affects memory_region_init_ram().

---
v5:
- drop default 'complete' method, allowing child not to implement it
- codestyle cleanups
v4:
- don't use nonexisting anymore error_is_set()
v3:
- fix path leak & use object_get_canonical_path_component() for getting object name
v2:
- reuse UserCreatable interface instead of custom callbacks

---
 backends/Makefile.objs   |    2 +
 backends/hostmem-ram.c   |   54 +++++++++++++++++++++++++
 backends/hostmem.c       |   97 ++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/hostmem.h |   60 ++++++++++++++++++++++++++++
 4 files changed, 213 insertions(+), 0 deletions(-)
 create mode 100644 backends/hostmem-ram.c
 create mode 100644 backends/hostmem.c
 create mode 100644 include/sysemu/hostmem.h
backends/Makefile.objs +2 -0
index 591ddcf..7fb7acd 100644
@@ -6,3 +6,5 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
 baum.o-cflags := $(SDL_CFLAGS)
 
 common-obj-$(CONFIG_TPM) += tpm.o
+
+common-obj-y += hostmem.o hostmem-ram.o
backends/hostmem-ram.c new file +54 -0

54 lines not on this page · raw message

backends/hostmem.c new file +97 -0

97 lines not on this page · raw message

include/sysemu/hostmem.h new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
1.7.1
#6 lore raw

Re: [Qemu-devel] [PATCH v4 05/33] add memdev backend infrastructure

This change fails to pass "make check" for me:

dcs-xen-54:~/qemu/out>rm -rf *;../configure --enable-debug --disable-pie --enable-trace-backend=stderr;make -j8 && make check && make check-block && echo ok
...
GTESTER check-qtest-sh4eb
GTESTER check-qtest-sparc
Registering `memory' which already exists
socket_accept failed: Resource temporarily unavailable
**
ERROR:/home/don/qemu/tests/libqtest.c:189:qtest_init: assertion failed: (s->fd >= 0 && s->qmp_fd >= 0)
make: *** [check-qtest-sparc] Error 1

dcs-xen-54:~/qemu>git-bisect bad 18e673e5a3f549671b345a778a84de5f0777e6bf is the first bad commit commit 18e673e5a3f549671b345a778a84de5f0777e6bf

Author: Igor Mammedov <[email protected]>
Date:   Wed Dec 11 13:19:20 2013 +0100

add memdev backend infrastructure

Provides framework for splitting host RAM allocation/ policies into a separate backend that could be used by devices.

Initially only legacy RAM backend is provided, which uses memory_region_init_ram() allocator and compatible with every CLI option that affects memory_region_init_ram().

---
v5:
- drop default 'complete' method, allowing child not to implement it
- codestyle cleanups
v4:
- don't use nonexisting anymore error_is_set()
v3:
- fix path leak & use object_get_canonical_path_component() for getting object name
v2:
- reuse UserCreatable interface instead of custom callbacks

:040000 040000 7af148ee7e1a49b04749a4d8261b13f208ac69e2 6e17d4ee053ab73ed6268ee0af358c545f7d48f7 M backends
:040000 040000 8c80a6fa88899769dd98319142bacce811ed9378 6d11a9e95270aa80f70a1cb7045fb57113b21458 M include

-Don Slutz

Quoted 270 lines · Igor Mammedov

Provides framework for splitting host RAM allocation/ policies into a separate backend that could be used by devices.

Initially only legacy RAM backend is provided, which uses memory_region_init_ram() allocator and compatible with every CLI option that affects memory_region_init_ram().

---
v5:
- drop default 'complete' method, allowing child not to implement it
- codestyle cleanups
v4:
- don't use nonexisting anymore error_is_set()
v3:
- fix path leak & use object_get_canonical_path_component() for getting object name
v2:
- reuse UserCreatable interface instead of custom callbacks

---
  backends/Makefile.objs   |    2 +
  backends/hostmem-ram.c   |   54 +++++++++++++++++++++++++
  backends/hostmem.c       |   97 ++++++++++++++++++++++++++++++++++++++++++++++
  include/sysemu/hostmem.h |   60 ++++++++++++++++++++++++++++
  4 files changed, 213 insertions(+), 0 deletions(-)

create mode 100644 backends/hostmem-ram.c
create mode 100644 backends/hostmem.c
create mode 100644 include/sysemu/hostmem.h

backends/Makefile.objs +2 -0
index 591ddcf..7fb7acd 100644
@@ -6,3 +6,5 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
  baum.o-cflags := $(SDL_CFLAGS)
 
  common-obj-$(CONFIG_TPM) += tpm.o
+
+common-obj-y += hostmem.o hostmem-ram.o
backends/hostmem-ram.c new file +54 -0
new file mode 100644
index 0000000..6c52ddc
@@ -0,0 +1,54 @@
+/*
+ * QEMU Host Memory Backend
+ *
+ * Copyright (C) 2013-2014 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "sysemu/hostmem.h"
+#include "qom/object_interfaces.h"
+
+#define TYPE_MEMORY_BACKEND_RAM "memory-ram"
+
+
+static void
+ram_backend_memory_init(UserCreatable *uc, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(uc);
+    char *path;
+
+    if (!backend->size) {
+        error_setg(errp, "can't create backend with size 0");
+        return;
+    }
+
+    path = object_get_canonical_path_component(OBJECT(backend));
+    memory_region_init_ram(&backend->mr, OBJECT(backend), path,
+                           backend->size);
+    g_free(path);
+}
+
+static void
+ram_backend_class_init(ObjectClass *oc, void *data)
+{
+    UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
+
+    ucc->complete = ram_backend_memory_init;
+}
+
+static const TypeInfo ram_backend_info = {
+    .name = TYPE_MEMORY_BACKEND_RAM,
+    .parent = TYPE_MEMORY_BACKEND,
+    .class_init = ram_backend_class_init,
+};
+
+static void register_types(void)
+{
+    type_register_static(&ram_backend_info);
+}
+
+type_init(register_types);
backends/hostmem.c new file +97 -0
new file mode 100644
index 0000000..2f578ac
@@ -0,0 +1,97 @@
+/*
+ * QEMU Host Memory Backend
+ *
+ * Copyright (C) 2013-2014 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "sysemu/hostmem.h"
+#include "sysemu/sysemu.h"
+#include "qapi/visitor.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu/config-file.h"
+#include "qom/object_interfaces.h"
+
+static void
+hostmemory_backend_get_size(Object *obj, Visitor *v, void *opaque,
+                            const char *name, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+    uint64_t value = backend->size;
+
+    visit_type_size(v, &value, name, errp);
+}
+
+static void
+hostmemory_backend_set_size(Object *obj, Visitor *v, void *opaque,
+                            const char *name, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+    Error *local_err = NULL;
+    uint64_t value;
+
+    if (memory_region_size(&backend->mr)) {
+        error_setg(&local_err, "cannot change property value");
+        goto out;
+    }
+
+    visit_type_size(v, &value, name, &local_err);
+    if (local_err) {
+        goto out;
+    }
+    if (!value) {
+        error_setg(&local_err, "Property '%s.%s' doesn't take value '%"
+                   PRIu64 "'", object_get_typename(obj), name, value);
+        goto out;
+    }
+    backend->size = value;
+out:
+    error_propagate(errp, local_err);
+}
+
+static void hostmemory_backend_init(Object *obj)
+{
+    object_property_add(obj, "size", "int",
+                        hostmemory_backend_get_size,
+                        hostmemory_backend_set_size, NULL, NULL, NULL);
+}
+
+static void hostmemory_backend_finalize(Object *obj)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    if (memory_region_size(&backend->mr)) {
+        memory_region_destroy(&backend->mr);
+    }
+}
+
+MemoryRegion *
+host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp)
+{
+    return memory_region_size(&backend->mr) ? &backend->mr : NULL;
+}
+
+static const TypeInfo hostmemory_backend_info = {
+    .name = TYPE_MEMORY_BACKEND,
+    .parent = TYPE_OBJECT,
+    .abstract = true,
+    .class_size = sizeof(HostMemoryBackendClass),
+    .instance_size = sizeof(HostMemoryBackend),
+    .instance_init = hostmemory_backend_init,
+    .instance_finalize = hostmemory_backend_finalize,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_USER_CREATABLE },
+        { }
+    }
+};
+
+static void register_types(void)
+{
+    type_register_static(&hostmemory_backend_info);
+}
+
+type_init(register_types);
include/sysemu/hostmem.h new file +60 -0
new file mode 100644
index 0000000..6899fc3
@@ -0,0 +1,60 @@
+/*
+ * QEMU Host Memory Backend
+ *
+ * Copyright (C) 2013-2014 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_RAM_H
+#define QEMU_RAM_H
+
+#include "qom/object.h"
+#include "qapi/error.h"
+#include "exec/memory.h"
+#include "qemu/option.h"
+
+#define TYPE_MEMORY_BACKEND "memory"
+#define MEMORY_BACKEND(obj) \
+    OBJECT_CHECK(HostMemoryBackend, (obj), TYPE_MEMORY_BACKEND)
+#define MEMORY_BACKEND_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(HostMemoryBackendClass, (obj), TYPE_MEMORY_BACKEND)
+#define MEMORY_BACKEND_CLASS(klass) \
+    OBJECT_CLASS_CHECK(HostMemoryBackendClass, (klass), TYPE_MEMORY_BACKEND)
+
+typedef struct HostMemoryBackend HostMemoryBackend;
+typedef struct HostMemoryBackendClass HostMemoryBackendClass;
+
+/**
+ * HostMemoryBackendClass:
+ * @parent_class: opaque parent class container
+ */
+struct HostMemoryBackendClass {
+    ObjectClass parent_class;
+};
+
+/**
+ * @HostMemoryBackend
+ *
+ * @parent: opaque parent object container
+ * @size: amount of memory backend provides
+ * @id: unique identification string in memdev namespace
+ * @mr: MemoryRegion representing host memory belonging to backend
+ */
+struct HostMemoryBackend {
+    /* private */
+    Object parent;
+
+    /* protected */
+    uint64_t size;
+
+    MemoryRegion mr;
+};
+
+MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend,
+                                             Error **errp);
+
+#endif
#7 lore raw

PATCH v4 5/33 add memdev backend infrastructure

Provides framework for splitting host RAM allocation/ policies into a separate backend that could be used by devices.

Initially only legacy RAM backend is provided, which uses memory_region_init_ram() allocator and compatible with every CLI option that affects memory_region_init_ram().

---
v6:
- change memory backend type from "memory" to "memory-backend" to avoid conflict with sparc arch where they also have "memory" type
- the same as above for "memory-ram" -> "memory-backend-ram" to keep ram backend in memory-backend namespace
v5:
- drop default 'complete' method, allowing child not to implement it
- codestyle cleanups
v4:
- don't use nonexisting anymore error_is_set()
v3:
- fix path leak & use object_get_canonical_path_component() for getting object name
v2:
- reuse UserCreatable interface instead of custom callbacks

---
 backends/Makefile.objs   |    2 +
 backends/hostmem-ram.c   |   54 +++++++++++++++++++++++++
 backends/hostmem.c       |   97 ++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/hostmem.h |   60 ++++++++++++++++++++++++++++
 4 files changed, 213 insertions(+), 0 deletions(-)
 create mode 100644 backends/hostmem-ram.c
 create mode 100644 backends/hostmem.c
 create mode 100644 include/sysemu/hostmem.h
backends/Makefile.objs +2 -0
index 591ddcf..7fb7acd 100644
@@ -6,3 +6,5 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
 baum.o-cflags := $(SDL_CFLAGS)
 
 common-obj-$(CONFIG_TPM) += tpm.o
+
+common-obj-y += hostmem.o hostmem-ram.o
backends/hostmem-ram.c new file +54 -0

54 lines not on this page · raw message

backends/hostmem.c new file +97 -0

97 lines not on this page · raw message

include/sysemu/hostmem.h new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
1.7.1
#8 lore raw

Re: [Qemu-devel] [PATCH v4.1 5/33 FIXED] add memdev backend infrastructure

Tested that "make check" no longer fails with this version.

-Don Slutz

Quoted 276 lines · Igor Mammedov

Provides framework for splitting host RAM allocation/ policies into a separate backend that could be used by devices.

Initially only legacy RAM backend is provided, which uses memory_region_init_ram() allocator and compatible with every CLI option that affects memory_region_init_ram().

---
v6:
- change memory backend type from "memory" to "memory-backend" to avoid conflict with sparc arch where they also have "memory" type
- the same as above for "memory-ram" -> "memory-backend-ram" to keep ram backend in memory-backend namespace
v5:
- drop default 'complete' method, allowing child not to implement it
- codestyle cleanups
v4:
- don't use nonexisting anymore error_is_set()
v3:
- fix path leak & use object_get_canonical_path_component() for getting object name
v2:
- reuse UserCreatable interface instead of custom callbacks

---
  backends/Makefile.objs   |    2 +
  backends/hostmem-ram.c   |   54 +++++++++++++++++++++++++
  backends/hostmem.c       |   97 ++++++++++++++++++++++++++++++++++++++++++++++
  include/sysemu/hostmem.h |   60 ++++++++++++++++++++++++++++
  4 files changed, 213 insertions(+), 0 deletions(-)

create mode 100644 backends/hostmem-ram.c
create mode 100644 backends/hostmem.c
create mode 100644 include/sysemu/hostmem.h

backends/Makefile.objs +2 -0
index 591ddcf..7fb7acd 100644
@@ -6,3 +6,5 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
  baum.o-cflags := $(SDL_CFLAGS)
 
  common-obj-$(CONFIG_TPM) += tpm.o
+
+common-obj-y += hostmem.o hostmem-ram.o
backends/hostmem-ram.c new file +54 -0
new file mode 100644
index 0000000..bba2ebc
@@ -0,0 +1,54 @@
+/*
+ * QEMU Host Memory Backend
+ *
+ * Copyright (C) 2013-2014 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "sysemu/hostmem.h"
+#include "qom/object_interfaces.h"
+
+#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
+
+
+static void
+ram_backend_memory_init(UserCreatable *uc, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(uc);
+    char *path;
+
+    if (!backend->size) {
+        error_setg(errp, "can't create backend with size 0");
+        return;
+    }
+
+    path = object_get_canonical_path_component(OBJECT(backend));
+    memory_region_init_ram(&backend->mr, OBJECT(backend), path,
+                           backend->size);
+    g_free(path);
+}
+
+static void
+ram_backend_class_init(ObjectClass *oc, void *data)
+{
+    UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
+
+    ucc->complete = ram_backend_memory_init;
+}
+
+static const TypeInfo ram_backend_info = {
+    .name = TYPE_MEMORY_BACKEND_RAM,
+    .parent = TYPE_MEMORY_BACKEND,
+    .class_init = ram_backend_class_init,
+};
+
+static void register_types(void)
+{
+    type_register_static(&ram_backend_info);
+}
+
+type_init(register_types);
backends/hostmem.c new file +97 -0
new file mode 100644
index 0000000..2f578ac
@@ -0,0 +1,97 @@
+/*
+ * QEMU Host Memory Backend
+ *
+ * Copyright (C) 2013-2014 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "sysemu/hostmem.h"
+#include "sysemu/sysemu.h"
+#include "qapi/visitor.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu/config-file.h"
+#include "qom/object_interfaces.h"
+
+static void
+hostmemory_backend_get_size(Object *obj, Visitor *v, void *opaque,
+                            const char *name, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+    uint64_t value = backend->size;
+
+    visit_type_size(v, &value, name, errp);
+}
+
+static void
+hostmemory_backend_set_size(Object *obj, Visitor *v, void *opaque,
+                            const char *name, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+    Error *local_err = NULL;
+    uint64_t value;
+
+    if (memory_region_size(&backend->mr)) {
+        error_setg(&local_err, "cannot change property value");
+        goto out;
+    }
+
+    visit_type_size(v, &value, name, &local_err);
+    if (local_err) {
+        goto out;
+    }
+    if (!value) {
+        error_setg(&local_err, "Property '%s.%s' doesn't take value '%"
+                   PRIu64 "'", object_get_typename(obj), name, value);
+        goto out;
+    }
+    backend->size = value;
+out:
+    error_propagate(errp, local_err);
+}
+
+static void hostmemory_backend_init(Object *obj)
+{
+    object_property_add(obj, "size", "int",
+                        hostmemory_backend_get_size,
+                        hostmemory_backend_set_size, NULL, NULL, NULL);
+}
+
+static void hostmemory_backend_finalize(Object *obj)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    if (memory_region_size(&backend->mr)) {
+        memory_region_destroy(&backend->mr);
+    }
+}
+
+MemoryRegion *
+host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp)
+{
+    return memory_region_size(&backend->mr) ? &backend->mr : NULL;
+}
+
+static const TypeInfo hostmemory_backend_info = {
+    .name = TYPE_MEMORY_BACKEND,
+    .parent = TYPE_OBJECT,
+    .abstract = true,
+    .class_size = sizeof(HostMemoryBackendClass),
+    .instance_size = sizeof(HostMemoryBackend),
+    .instance_init = hostmemory_backend_init,
+    .instance_finalize = hostmemory_backend_finalize,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_USER_CREATABLE },
+        { }
+    }
+};
+
+static void register_types(void)
+{
+    type_register_static(&hostmemory_backend_info);
+}
+
+type_init(register_types);
include/sysemu/hostmem.h new file +60 -0
new file mode 100644
index 0000000..4fc081e
@@ -0,0 +1,60 @@
+/*
+ * QEMU Host Memory Backend
+ *
+ * Copyright (C) 2013-2014 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_RAM_H
+#define QEMU_RAM_H
+
+#include "qom/object.h"
+#include "qapi/error.h"
+#include "exec/memory.h"
+#include "qemu/option.h"
+
+#define TYPE_MEMORY_BACKEND "memory-backend"
+#define MEMORY_BACKEND(obj) \
+    OBJECT_CHECK(HostMemoryBackend, (obj), TYPE_MEMORY_BACKEND)
+#define MEMORY_BACKEND_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(HostMemoryBackendClass, (obj), TYPE_MEMORY_BACKEND)
+#define MEMORY_BACKEND_CLASS(klass) \
+    OBJECT_CLASS_CHECK(HostMemoryBackendClass, (klass), TYPE_MEMORY_BACKEND)
+
+typedef struct HostMemoryBackend HostMemoryBackend;
+typedef struct HostMemoryBackendClass HostMemoryBackendClass;
+
+/**
+ * HostMemoryBackendClass:
+ * @parent_class: opaque parent class container
+ */
+struct HostMemoryBackendClass {
+    ObjectClass parent_class;
+};
+
+/**
+ * @HostMemoryBackend
+ *
+ * @parent: opaque parent object container
+ * @size: amount of memory backend provides
+ * @id: unique identification string in memdev namespace
+ * @mr: MemoryRegion representing host memory belonging to backend
+ */
+struct HostMemoryBackend {
+    /* private */
+    Object parent;
+
+    /* protected */
+    uint64_t size;
+
+    MemoryRegion mr;
+};
+
+MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend,
+                                             Error **errp);
+
+#endif
#9 lore raw

PATCH v4 6/33 vl.c: extend -m option to support options for memory hotplug

In reply to Igor Mammedov

Add following parameters:
"slots" - total number of hotplug memory slots
"maxmem" - maximum possible memory

"slots" and "maxmem" should go in pair and "maxmem" should be greater than "mem" for memory hotplug to be enabled.

---
v4:
- store maxmem & slots values in MachineState
v3:
- store maxmem & slots values in QEMUMachineInitArgs
v2:
- rebased on top of the latest "vl: convert -m to QemuOpts"

---
 include/hw/boards.h |    2 ++
 qemu-options.hx     |    9 ++++++---
 vl.c                |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 3 deletions(-)
include/hw/boards.h +2 -0
index 2d2e2be..184d245 100644
@@ -113,6 +113,8 @@ struct MachineState {
     char *firmware;
 
     ram_addr_t ram_size;
+    ram_addr_t maxram_size;
+    uint64_t   ram_slots;
     const char *boot_order;
     char *kernel_filename;
     char *kernel_cmdline;
qemu-options.hx +6 -3
index 4011d46..46d6f7c 100644
@@ -210,17 +210,20 @@ use is discouraged as it may be removed from future versions.
 ETEXI
 
 DEF("m", HAS_ARG, QEMU_OPTION_m,
-    "-m [size=]megs\n"
+    "-m[emory] [size=]megs[,slots=n,maxmem=size]\n"
     "                configure guest RAM\n"
     "                size: initial amount of guest memory (default: "
-    stringify(DEFAULT_RAM_SIZE) "MiB)\n",
+    stringify(DEFAULT_RAM_SIZE) "MiB)\n"
+    "                slots: number of hotplug slots (default: none)\n"
+    "                maxmem: maximum amount of guest memory (default: none)\n",
     QEMU_ARCH_ALL)
 STEXI
 @item -m [size=]@var{megs}
 @findex -m
 Set virtual RAM size to @var{megs} megabytes. Default is 128 MiB.  Optionally,
 a suffix of ``M'' or ``G'' can be used to signify a value in megabytes or
-gigabytes respectively.
+gigabytes respectively. Optional pair @var{slots}, @var{maxmem} could be used
+to set amount of hotluggable memory slots and possible maximum amount of memory.
 ETEXI
 
 DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,
vl.c +51 -0

81 lines not on this page · raw message

Signature · 1 line
1.7.1
#10 lore raw

PATCH v4 7/33 qdev: hotplug for buss-less devices

In reply to Igor Mammedov

Adds get_hotplug_handler() method to machine, and makes bus-less device to use it during hotplug as a means to discover hotplug handler controller. Returned controller is used to permorm a hotplug action.

---
 hw/core/qdev.c      |   13 +++++++++++++
 include/hw/boards.h |    8 ++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
hw/core/qdev.c +13 -0
index e65a5aa..fded645 100644
@@ -34,6 +34,7 @@
 #include "qapi/qmp/qjson.h"
 #include "monitor/monitor.h"
 #include "hw/hotplug.h"
+#include "hw/boards.h"
 
 int qdev_hotplug = 0;
 static bool qdev_hot_added = false;
@@ -813,6 +814,18 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
             local_err == NULL) {
             hotplug_handler_plug(dev->parent_bus->hotplug_handler,
                                  dev, &local_err);
+        } else if (local_err == NULL &&
+                   object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
+            HotplugHandler *hotplug_ctrl;
+            MachineState *machine = MACHINE(qdev_get_machine());
+            MachineClass *mc = MACHINE_GET_CLASS(machine);
+
+            if (mc->get_hotplug_handler) {
+                hotplug_ctrl = mc->get_hotplug_handler(machine, dev);
+                if (hotplug_ctrl) {
+                    hotplug_handler_plug(hotplug_ctrl, dev, &local_err);
+                }
+            }
         }
 
         if (qdev_get_vmsd(dev) && local_err == NULL) {
include/hw/boards.h +8 -0
index 184d245..429ac43 100644
@@ -61,6 +61,11 @@ extern MachineState *current_machine;
 /**
  * MachineClass:
  * @qemu_machine: #QEMUMachine
+ * @get_hotplug_handler: this function is called during bus-less
+ *    device hotplug. If defined it returns pointer to an instance
+ *    of HotplugHandler object, which handles hotplug operation
+ *    for a given @dev. It may return NULL if @dev doesn't require
+ *    any actions to be performed by hotplug handler.
  */
 struct MachineClass {
     /*< private >*/
@@ -90,6 +95,9 @@ struct MachineClass {
     const char *default_boot_order;
     GlobalProperty *compat_props;
     const char *hw_version;
+
+    HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
+                                           DeviceState *dev);
 };
 
 /**
Signature · 1 line
1.7.1
#11 lore raw

PATCH v4 8/33 qdev: expose DeviceState.hotplugged field as a property

In reply to Igor Mammedov

so that management could detect via QOM interface if device was hotplugged

---
v2:
- fix typo in commit message (afaerber)

---
 hw/core/qdev.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
hw/core/qdev.c +17 -0
index fded645..3226a71 100644
@@ -878,6 +878,20 @@ static bool device_get_hotpluggable(Object *obj, Error **errp)
                                 dev->parent_bus->allow_hotplug);
 }
 
+static bool device_get_hotplugged(Object *obj, Error **err)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    return dev->hotplugged;
+}
+
+static void device_set_hotplugged(Object *obj, bool value, Error **err)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    dev->hotplugged = value;
+}
+
 static void device_initfn(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
@@ -896,6 +910,9 @@ static void device_initfn(Object *obj)
                              device_get_realized, device_set_realized, NULL);
     object_property_add_bool(obj, "hotpluggable",
                              device_get_hotpluggable, NULL, NULL);
+    object_property_add_bool(obj, "hotplugged",
+                             device_get_hotplugged, device_set_hotplugged,
+                             &error_abort);
 
     class = object_get_class(OBJECT(dev));
     do {
Signature · 1 line
1.7.1
#12 lore raw

PATCH v4 9/33 pc: implement pc-dimm device abstraction

In reply to Igor Mammedov

From: Vasilis Liaskovitis <[email protected]>

Each hotplug-able memory slot is a PCDIMMDevice.
A hot-add operation for a memory device:
- creates a new PCDIMMDevice and makes hotplug controller to map it into guest address space

Hotplug operations are done through normal device_add commands. For migration case, all hotplugged memory devices on source should be specified on target's command line using '-device' option with properties set to the same values as on source.

To simplify review, patch introduces only PCDIMMDevice QOM skeleton that will be extended by following patches to implement actual memory hotplug and related functions.

---
v5:
rename DimmDevice to PCDIMMDevice
v4:
drop DimmBus in favor of bus-less device hotplug rename property/field 'start' to 'addr' use defines for property names
v3:
pc: compile memhotplug on i386 target too
v2:
fix typo s/DimmBus/DimmDevice/ in doc comment s/klass/oc/;s/*/parent_obj/;a/gtk-doc markup/

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/Makefile.objs                   |    1 +
 hw/mem/Makefile.objs               |    1 +
 hw/mem/pc-dimm.c                   |   99 ++++++++++++++++++++++++++++++++++++
 include/hw/mem/pc-dimm.h           |   73 ++++++++++++++++++++++++++
 6 files changed, 176 insertions(+), 0 deletions(-)
 create mode 100644 hw/mem/Makefile.objs
 create mode 100644 hw/mem/pc-dimm.c
 create mode 100644 include/hw/mem/pc-dimm.h
default-configs/i386-softmmu.mak +1 -0
index 37ef90f..8e08841 100644
@@ -44,3 +44,4 @@ CONFIG_APIC=y
 CONFIG_IOAPIC=y
 CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
+CONFIG_MEM_HOTPLUG=y
default-configs/x86_64-softmmu.mak +1 -0
index 31bddce..66557ac 100644
@@ -44,3 +44,4 @@ CONFIG_APIC=y
 CONFIG_IOAPIC=y
 CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
+CONFIG_MEM_HOTPLUG=y
hw/Makefile.objs +1 -0
index d178b65..52a1464 100644
@@ -29,6 +29,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += usb/
 devices-dirs-$(CONFIG_VIRTIO) += virtio/
 devices-dirs-$(CONFIG_SOFTMMU) += watchdog/
 devices-dirs-$(CONFIG_SOFTMMU) += xen/
+devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/
 devices-dirs-y += core/
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
hw/mem/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..b000fb4
@@ -0,0 +1 @@
+common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o
hw/mem/pc-dimm.c new file +99 -0

99 lines not on this page · raw message

include/hw/mem/pc-dimm.h new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
1.7.1
#13 lore raw

PATCH v4 10/33 memory: add memory_region_is_mapped() API

In reply to Igor Mammedov

which allows to check if MemoryRegion is already mapped.

---
v2:
simplify check, just by checking if MR has parent

---
 include/exec/memory.h |    8 ++++++++
 memory.c              |   10 +++++++++-
 2 files changed, 17 insertions(+), 1 deletions(-)
include/exec/memory.h +8 -0
index 1d55ad9..ab11c32 100644
@@ -848,6 +848,14 @@ void memory_region_set_alias_offset(MemoryRegion *mr,
 bool memory_region_present(MemoryRegion *parent, hwaddr addr);
 
 /**
+ * memory_region_is_mapped: returns true if #MemoryRegion is mapped
+ * into any address space.
+ *
+ * @mr: a #MemoryRegion which should be checked if it's mapped
+ */
+bool memory_region_is_mapped(MemoryRegion *mr);
+
+/**
  * memory_region_find: translate an address/size relative to a
  * MemoryRegion into a #MemoryRegionSection.
  *
memory.c +9 -1
index 3f1df23..2c952ea 100644
@@ -492,7 +492,7 @@ static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)
             return as;
         }
     }
-    abort();
+    return NULL;
 }
 
 /* Render a memory region into the global view.  Ranges in @view obscure
@@ -1569,6 +1569,11 @@ bool memory_region_present(MemoryRegion *parent, hwaddr addr)
     return true;
 }
 
+bool memory_region_is_mapped(MemoryRegion *mr)
+{
+    return mr->parent ? true : false;
+}
+
 MemoryRegionSection memory_region_find(MemoryRegion *mr,
                                        hwaddr addr, uint64_t size)
 {
@@ -1586,6 +1591,9 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
     }
 
     as = memory_region_to_address_space(root);
+    if (!as) {
+        return ret;
+    }
     range = addrrange_make(int128_make64(addr), int128_make64(size));
 
     view = address_space_get_flatview(as);
Signature · 1 line
1.7.1
#14 lore raw

PATCH v4 11/33 pc-dimm: do not allow to set already used memdev

In reply to Igor Mammedov

using the same memdev backend more than once will cause assersion at MemoryRegion mapping time becase it's already mapped. Prevent it by checking that associated MemoryRegion is not mapped.

---
 hw/mem/pc-dimm.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
hw/mem/pc-dimm.c +16 -1
index b4937fe..3cced63 100644
@@ -43,6 +43,21 @@ static void pc_dimm_get_size(Object *obj, Visitor *v, void *opaque,
     visit_type_int(v, &value, name, errp);
 }
 
+static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name,
+                                      Object *val, Error **errp)
+{
+    MemoryRegion *mr;
+
+    mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), errp);
+    if (memory_region_is_mapped(mr)) {
+        char *path = object_get_canonical_path_component(val);
+        error_setg(errp, "can't use already busy memdev: %s", path);
+        g_free(path);
+    } else {
+        qdev_prop_allow_set_link_before_realize(obj, name, val, errp);
+    }
+}
+
 static void pc_dimm_init(Object *obj)
 {
     PCDIMMDevice *dimm = PC_DIMM(obj);
@@ -51,7 +66,7 @@ static void pc_dimm_init(Object *obj)
                         NULL, NULL, NULL, &error_abort);
     object_property_add_link(obj, PC_DIMM_MEMDEV_PROP, TYPE_MEMORY_BACKEND,
                              (Object **)&dimm->hostmem,
-                             qdev_prop_allow_set_link_before_realize,
+                             pc_dimm_check_memdev_is_busy,
                              OBJ_PROP_LINK_UNREF_ON_RELEASE,
                              &error_abort);
 }
Signature · 1 line
1.7.1
#15 lore raw

PATCH v4 12/33 pc: initialize memory hotplug address space

In reply to Igor Mammedov

initialize and map hotplug memory address space container into guest's RAM address space.

---
v2:
* fix uint64_t overflow reported by Hu Tao
* rebase on top of Marcel's patch
"machine: Conversion of QEMUMachineInitArgs to MachineState"

---
 hw/i386/pc.c         |   26 ++++++++++++++++++++++++--
 include/hw/i386/pc.h |   10 ++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
hw/i386/pc.c +24 -2
index f6781d8..f94cfd9 100644
@@ -1201,6 +1201,9 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
     MemoryRegion *ram, *option_rom_mr;
     MemoryRegion *ram_below_4g, *ram_above_4g;
     FWCfgState *fw_cfg;
+    ram_addr_t ram_size = below_4g_mem_size + above_4g_mem_size;
+    MachineState *machine = MACHINE(qdev_get_machine());
+    PCMachineState *pcms = PC_MACHINE(machine);
 
     linux_boot = (kernel_filename != NULL);
 
@@ -1209,8 +1212,7 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
      * with older qemus that used qemu_ram_alloc().
      */
     ram = g_malloc(sizeof(*ram));
-    memory_region_init_ram(ram, NULL, "pc.ram",
-                           below_4g_mem_size + above_4g_mem_size);
+    memory_region_init_ram(ram, NULL, "pc.ram", ram_size);
     vmstate_register_ram_global(ram);
     *ram_memory = ram;
     ram_below_4g = g_malloc(sizeof(*ram_below_4g));
@@ -1227,6 +1229,26 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
         e820_add_entry(0x100000000ULL, above_4g_mem_size, E820_RAM);
     }
 
+    /* initialize hotplug memory address space */
+    if (ram_size < machine->maxram_size) {
+        ram_addr_t hotplug_mem_size =
+            machine->maxram_size - ram_size;
+
+        pcms->hotplug_memory_base =
+            ROUND_UP(0x100000000ULL + above_4g_mem_size, 1ULL << 30);
+
+        if ((pcms->hotplug_memory_base + hotplug_mem_size) <
+            hotplug_mem_size) {
+            error_report("unsupported amount of maximum memory: %"PRIu64,
+                         machine->maxram_size);
+            exit(EXIT_FAILURE);
+        }
+
+        memory_region_init(&pcms->hotplug_memory, OBJECT(pcms),
+                           "hotplug-memory", hotplug_mem_size);
+        memory_region_add_subregion(system_memory, pcms->hotplug_memory_base,
+                                    &pcms->hotplug_memory);
+    }
 
     /* Initialize PC system firmware */
     pc_system_firmware_init(rom_memory, guest_info->isapc_ram_fw);
include/hw/i386/pc.h +10 -0
index c7b053c..3ae6c56 100644
@@ -16,9 +16,19 @@
 
 #define HPET_INTCAP "hpet-intcap"
 
+/**
+ * PCMachineState:
+ * @hotplug_memory_base: address in guest RAM address space where hotplug memory
+ * address space begins.
+ * @hotplug_memory: hotplug memory addess space container
+ */
 struct PCMachineState {
     /*< private >*/
     MachineState parent_obj;
+
+    /* <public> */
+    ram_addr_t hotplug_memory_base;
+    MemoryRegion hotplug_memory;
 };
 
 struct PCMachineClass {
Signature · 1 line
1.7.1
#16 lore raw

PATCH v4 13/33 pc: exit QEMU if number of slots more than supported 256

In reply to Igor Mammedov

... which is imposed by current naming scheme of ACPI memory devices.

---
v2:
* use define for amount of supported slots, requested by Eduardo Habkost

---
 hw/i386/pc.c           |    6 ++++++
 include/hw/acpi/acpi.h |    6 ++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
hw/i386/pc.c +6 -0
index f94cfd9..5522503 100644
@@ -1234,6 +1234,12 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
         ram_addr_t hotplug_mem_size =
             machine->maxram_size - ram_size;
 
+        if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) {
+            error_report("unsupported amount of memory slots: %"PRIu64,
+                         machine->ram_slots);
+            exit(EXIT_FAILURE);
+        }
+
         pcms->hotplug_memory_base =
             ROUND_UP(0x100000000ULL + above_4g_mem_size, 1ULL << 30);
 
include/hw/acpi/acpi.h +6 -0
index a9fae9d..e93de6c 100644
@@ -26,6 +26,12 @@
 #include "exec/memory.h"
 #include "hw/irq.h"
 
+/*
+ * current device naming scheme supports
+ * only upto 256 memory devices
+ */
+#define ACPI_MAX_RAM_SLOTS 256
+
 /* from linux include/acpi/actype.h */
 /* Default ACPI register widths */
 
Signature · 1 line
1.7.1
#17 lore raw

PATCH v4 14/33 pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS

In reply to Igor Mammedov

'etc/reserved-memory-end' will allow QEMU to tell BIOS where PCI BARs mapping could safely start in high memory.

Allowing BIOS to start mapping 64-bit PCI BARs at address where it wouldn't conflict with other mappings QEMU might place before it.

That permits QEMU to reserve extra address space before 64-bit PCI hole for memory hotplug.

---
Seabios part is already commited: 0f474d07d

---
 hw/i386/pc.c         |    9 ++++++++-
 hw/i386/pc_piix.c    |    3 +++
 hw/i386/pc_q35.c     |    3 +++
 include/hw/i386/pc.h |    1 +
 4 files changed, 15 insertions(+), 1 deletions(-)
hw/i386/pc.c +8 -1
index 5522503..5be7b33 100644
@@ -1230,7 +1230,8 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
     }
 
     /* initialize hotplug memory address space */
-    if (ram_size < machine->maxram_size) {
+    if (guest_info->has_reserved_memory &&
+        (ram_size < machine->maxram_size)) {
         ram_addr_t hotplug_mem_size =
             machine->maxram_size - ram_size;
 
@@ -1270,6 +1271,12 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
     fw_cfg = bochs_bios_init();
     rom_set_fw(fw_cfg);
 
+    if (guest_info->has_reserved_memory && pcms->hotplug_memory_base) {
+        uint64_t *val = g_malloc(sizeof(*val));
+        *val = cpu_to_le64(ROUND_UP(pcms->hotplug_memory_base, 0x1ULL << 30));
+        fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
+    }
+
     if (linux_boot) {
         load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size);
     }
hw/i386/pc_piix.c +3 -0
index abb599b..e133b6a 100644
@@ -67,6 +67,7 @@ static bool smbios_legacy_mode;
  * pages in the host.
  */
 static bool gigabyte_align = true;
+static bool has_reserved_memory = true;
 
 /* PC hardware initialisation */
 static void pc_init1(MachineState *machine,
@@ -143,6 +144,7 @@ static void pc_init1(MachineState *machine,
 
     guest_info->has_pci_info = has_pci_info;
     guest_info->isapc_ram_fw = !pci_enabled;
+    guest_info->has_reserved_memory = has_reserved_memory;
 
     if (smbios_defaults) {
         MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -267,6 +269,7 @@ static void pc_init_pci(MachineState *machine)
 static void pc_compat_2_0(MachineState *machine)
 {
     smbios_legacy_mode = true;
+    has_reserved_memory = false;
 }
 
 static void pc_compat_1_7(MachineState *machine)
hw/i386/pc_q35.c +3 -0
index d211393..0e77476 100644
@@ -57,6 +57,7 @@ static bool smbios_legacy_mode;
  * pages in the host.
  */
 static bool gigabyte_align = true;
+static bool has_reserved_memory = true;
 
 /* PC hardware initialisation */
 static void pc_q35_init(MachineState *machine)
@@ -130,6 +131,7 @@ static void pc_q35_init(MachineState *machine)
     guest_info->has_pci_info = has_pci_info;
     guest_info->isapc_ram_fw = false;
     guest_info->has_acpi_build = has_acpi_build;
+    guest_info->has_reserved_memory = has_reserved_memory;
 
     if (smbios_defaults) {
         MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -245,6 +247,7 @@ static void pc_q35_init(MachineState *machine)
 static void pc_compat_2_0(MachineState *machine)
 {
     smbios_legacy_mode = true;
+    has_reserved_memory = false;
 }
 
 static void pc_compat_1_7(MachineState *machine)
include/hw/i386/pc.h +1 -0
index 3ae6c56..3fed471 100644
@@ -77,6 +77,7 @@ struct PcGuestInfo {
     uint64_t *node_cpu;
     FWCfgState *fw_cfg;
     bool has_acpi_build;
+    bool has_reserved_memory;
 };
 
 /* parallel.c */
Signature · 1 line
1.7.1
#18 lore raw

PATCH v4 15/33 pc: exit QEMU if compat machine doesn't support memory hotlpug

In reply to Igor Mammedov

... if user attempts to start it with memory hotplug enabled.

---
 hw/i386/pc.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
hw/i386/pc.c +10 -0
index 5be7b33..af68c99 100644
@@ -1229,6 +1229,16 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
         e820_add_entry(0x100000000ULL, above_4g_mem_size, E820_RAM);
     }
 
+    if (!guest_info->has_reserved_memory &&
+        (machine->ram_slots ||
+         (machine->maxram_size > ram_size))) {
+        MachineClass *mc = MACHINE_GET_CLASS(machine);
+
+        error_report("\"-memory 'slots|maxmem'\" is not supported by: %s",
+                     mc->name);
+        exit(EXIT_FAILURE);
+    }
+
     /* initialize hotplug memory address space */
     if (guest_info->has_reserved_memory &&
         (ram_size < machine->maxram_size)) {
Signature · 1 line
1.7.1
#19 lore raw

PATCH v4 16/33 pc: add memory hotplug handler to PC_MACHINE

In reply to Igor Mammedov

that will perform mapping of PC_DIMM device into guest's RAM address space

---
 hw/i386/pc.c         |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h |    8 ++++++
 2 files changed, 67 insertions(+), 0 deletions(-)
hw/i386/pc.c +59 -0
index af68c99..93ead25 100644
@@ -58,6 +58,7 @@
 #include "hw/boards.h"
 #include "hw/pci/pci_host.h"
 #include "acpi-build.h"
+#include "hw/mem/pc-dimm.h"
 
 /* debug PC/ISA interrupts */
 //#define DEBUG_IRQ
@@ -1547,12 +1548,70 @@ void qemu_register_pc_machine(QEMUMachine *m)
     g_free(name);
 }
 
+static void pc_dimm_plug(HotplugHandler *hotplug_dev,
+                         DeviceState *dev, Error **errp)
+{
+    Error *local_err = NULL;
+    PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+    PCDIMMDevice *dimm = PC_DIMM(dev);
+    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+    MemoryRegion *mr = ddc->get_memory_region(dimm);
+    ram_addr_t addr = object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP,
+                                              &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    memory_region_add_subregion(&pcms->hotplug_memory,
+                                addr - pcms->hotplug_memory_base, mr);
+    vmstate_register_ram(mr, dev);
+out:
+    error_propagate(errp, local_err);
+}
+
+static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
+                                      DeviceState *dev, Error **errp)
+{
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+        pc_dimm_plug(hotplug_dev, dev, errp);
+    }
+}
+
+static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
+                                             DeviceState *dev)
+{
+    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
+
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+        return HOTPLUG_HANDLER(machine);
+    }
+
+    return pcmc->get_hotplug_handler ?
+        pcmc->get_hotplug_handler(machine, dev) : NULL;
+}
+
+static void pc_machine_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
+    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
+
+    pcmc->get_hotplug_handler = mc->get_hotplug_handler;
+    mc->get_hotplug_handler = pc_get_hotpug_handler;
+    hc->plug = pc_machine_device_plug_cb;
+}
+
 static const TypeInfo pc_machine_info = {
     .name = TYPE_PC_MACHINE,
     .parent = TYPE_MACHINE,
     .abstract = true,
     .instance_size = sizeof(PCMachineState),
     .class_size = sizeof(PCMachineClass),
+    .class_init = pc_machine_class_init,
+    .interfaces = (InterfaceInfo[]) {
+         { TYPE_HOTPLUG_HANDLER },
+         { }
+    },
 };
 
 static void pc_machine_register_types(void)
include/hw/i386/pc.h +8 -0
index 3fed471..e541c51 100644
@@ -31,9 +31,17 @@ struct PCMachineState {
     MemoryRegion hotplug_memory;
 };
 
+/**
+ * PCMachineClass:
+ * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler
+ */
 struct PCMachineClass {
     /*< private >*/
     MachineClass parent_class;
+
+    /*< public >*/
+    HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
+                                           DeviceState *dev);
 };
 
 typedef struct PCMachineState PCMachineState;
Signature · 1 line
1.7.1
#20 lore raw

PATCH v4 17/33 pc-dimm: add busy address check and address auto-allocation

In reply to Igor Mammedov

- if 'addr' property is not specified on -device/device_add command, treat default value as request for assigning PCDIMMDevice to the first free memory region.

- if 'addr' is provided with -device/device_add command, attempt to use it or fail command if it's already occupied or falls inside of an existing PCDIMMDevice memory region.

---
v2:
* abort if hotplug address-space size is too big, reported by Hu Tao
* do not reset previous error in dimm_get_free_addr(), fixed by Tang Chen

---
 hw/i386/pc.c             |    9 +++++
 hw/mem/pc-dimm.c         |   76 ++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/mem/pc-dimm.h |    4 ++
 3 files changed, 89 insertions(+), 0 deletions(-)
hw/i386/pc.c +9 -0
index 93ead25..d4232ec 100644
@@ -1562,6 +1562,15 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
         goto out;
     }
 
+    addr = pc_dimm_get_free_addr(pcms->hotplug_memory_base,
+                                 memory_region_size(&pcms->hotplug_memory),
+                                 !addr ? NULL : &addr,
+                                 memory_region_size(mr), &local_err);
+    if (local_err) {
+        goto out;
+    }
+    object_property_set_int(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_err);
+
     memory_region_add_subregion(&pcms->hotplug_memory,
                                 addr - pcms->hotplug_memory_base, mr);
     vmstate_register_ram(mr, dev);
hw/mem/pc-dimm.c +76 -0

82 lines not on this page · raw message

include/hw/mem/pc-dimm.h +4 -0
index e1f5ca4..5cd8f35 100644
@@ -70,4 +70,8 @@ typedef struct PCDIMMDeviceClass {
     MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm);
 } PCDIMMDeviceClass;
 
+uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
+                               uint64_t address_space_size,
+                               uint64_t *hint, uint64_t size,
+                               Error **errp);
 #endif
Signature · 1 line
1.7.1
#21 lore raw

PATCH v4 18/33 pc-dimm: add busy slot check and slot auto-allocation

In reply to Igor Mammedov

- if slot property is not specified on -device/device_add command, treat default value as request for assigning PCDIMMDevice to the first free slot.

- if slot is provided with -device/device_add command, attempt to use it or fail command if it's already occupied.

---
 hw/i386/pc.c             |   21 +++++++++++++++++++++
 hw/mem/pc-dimm.c         |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/mem/pc-dimm.h |    2 ++
 3 files changed, 69 insertions(+), 0 deletions(-)
hw/i386/pc.c +21 -0
index d4232ec..7b0cba3 100644
@@ -1551,8 +1551,10 @@ void qemu_register_pc_machine(QEMUMachine *m)
 static void pc_dimm_plug(HotplugHandler *hotplug_dev,
                          DeviceState *dev, Error **errp)
 {
+    int slot;
     Error *local_err = NULL;
     PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+    MachineState *machine = MACHINE(hotplug_dev);
     PCDIMMDevice *dimm = PC_DIMM(dev);
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
     MemoryRegion *mr = ddc->get_memory_region(dimm);
@@ -1569,7 +1571,26 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
     if (local_err) {
         goto out;
     }
+
     object_property_set_int(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot,
+                                 machine->ram_slots, &local_err);
+    if (local_err) {
+        goto out;
+    }
+    object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &local_err);
+    if (local_err) {
+        goto out;
+    }
 
     memory_region_add_subregion(&pcms->hotplug_memory,
                                 addr - pcms->hotplug_memory_base, mr);
hw/mem/pc-dimm.c +46 -0

52 lines not on this page · raw message

include/hw/mem/pc-dimm.h +2 -0
index 5cd8f35..5f80d14 100644
@@ -74,4 +74,6 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
                                uint64_t address_space_size,
                                uint64_t *hint, uint64_t size,
                                Error **errp);
+
+int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
 #endif
Signature · 1 line
1.7.1
#22 lore raw

PATCH v4 19/33 acpi: rename cpu_hotplug_defs.h to pc-hotplug.h

In reply to Igor Mammedov

to make it more generic, so it could be used for memory hotplug as well.

---
v2:
- s/acpi_defs.h/pc-hotplug.h/, requested by mst

---
 hw/i386/acpi-dsdt.dsl              |    2 +-
 hw/i386/q35-acpi-dsdt.dsl          |    2 +-
 include/hw/acpi/cpu_hotplug.h      |    2 +-
 include/hw/acpi/cpu_hotplug_defs.h |   32 --------------------------------
 include/hw/acpi/pc-hotplug.h       |   32 ++++++++++++++++++++++++++++++++
 5 files changed, 35 insertions(+), 35 deletions(-)
 delete mode 100644 include/hw/acpi/cpu_hotplug_defs.h
 create mode 100644 include/hw/acpi/pc-hotplug.h
hw/i386/acpi-dsdt.dsl +1 -1
index 0a1e252..8ae933b 100644
@@ -306,7 +306,7 @@ DefinitionBlock (
         }
     }
 
-#include "hw/acpi/cpu_hotplug_defs.h"
+#include "hw/acpi/pc-hotplug.h"
 #define CPU_STATUS_BASE PIIX4_CPU_HOTPLUG_IO_BASE
 #include "acpi-dsdt-cpu-hotplug.dsl"
 
hw/i386/q35-acpi-dsdt.dsl +1 -1
index f4d2a2d..fddc3b2 100644
@@ -402,7 +402,7 @@ DefinitionBlock (
         define_gsi_link(GSIH, 0, 0x17)
     }
 
-#include "hw/acpi/cpu_hotplug_defs.h"
+#include "hw/acpi/pc-hotplug.h"
 #define CPU_STATUS_BASE ICH9_CPU_HOTPLUG_IO_BASE
 #include "acpi-dsdt-cpu-hotplug.dsl"
 
include/hw/acpi/cpu_hotplug.h +1 -1
index 4576400..9e5d30c 100644
@@ -13,7 +13,7 @@
 #define ACPI_HOTPLUG_H
 
 #include "hw/acpi/acpi.h"
-#include "hw/acpi/cpu_hotplug_defs.h"
+#include "hw/acpi/pc-hotplug.h"
 
 typedef struct AcpiCpuHotplug {
     MemoryRegion io;
include/hw/acpi/cpu_hotplug_defs.h deleted +0 -32
deleted file mode 100644
index 9f33663..0000000
@@ -1,32 +0,0 @@
-/*
- * QEMU ACPI hotplug utilities shared defines
- *
- * Copyright (C) 2013 Red Hat Inc
- *
- * Authors:
- *   Igor Mammedov <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-#ifndef ACPI_HOTPLUG_DEFS_H
-#define ACPI_HOTPLUG_DEFS_H
-
-/*
- * ONLY DEFINEs are permited in this file since it's shared
- * between C and ASL code.
- */
-#define ACPI_CPU_HOTPLUG_STATUS 4
-
-/* Limit for CPU arch IDs for CPU hotplug. All hotpluggable CPUs should
- * have CPUClass.get_arch_id() < ACPI_CPU_HOTPLUG_ID_LIMIT.
- */
-#define ACPI_CPU_HOTPLUG_ID_LIMIT 256
-
-/* 256 CPU IDs, 8 bits per entry: */
-#define ACPI_GPE_PROC_LEN 32
-
-#define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
-#define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00
-
-#endif
include/hw/acpi/pc-hotplug.h new file +32 -0
new file mode 100644
index 0000000..cee479d
@@ -0,0 +1,32 @@
+/*
+ * QEMU ACPI hotplug utilities shared defines
+ *
+ * Copyright (C) 2014 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef PC_HOTPLUG_H
+#define PC_HOTPLUG_H
+
+/*
+ * ONLY DEFINEs are permited in this file since it's shared
+ * between C and ASL code.
+ */
+#define ACPI_CPU_HOTPLUG_STATUS 4
+
+/* Limit for CPU arch IDs for CPU hotplug. All hotpluggable CPUs should
+ * have CPUClass.get_arch_id() < ACPI_CPU_HOTPLUG_ID_LIMIT.
+ */
+#define ACPI_CPU_HOTPLUG_ID_LIMIT 256
+
+/* 256 CPU IDs, 8 bits per entry: */
+#define ACPI_GPE_PROC_LEN 32
+
+#define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
+#define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00
+
+#endif
Signature · 1 line
1.7.1
#23 lore raw

PATCH v4 20/33 acpi: memory hotplug ACPI hardware implementation

In reply to Igor Mammedov

- implements QEMU hardware part of memory hotplug protocol described at "docs/specs/acpi_mem_hotplug.txt"
- handles only memory add notification event for now

---
 docs/specs/acpi_mem_hotplug.txt  |   44 +++++++++++
 hw/acpi/Makefile.objs            |    1 +
 hw/acpi/memory_hotplug.c         |  147 ++++++++++++++++++++++++++++++++++++++
 include/hw/acpi/memory_hotplug.h |   29 ++++++++
 include/hw/acpi/pc-hotplug.h     |    3 +
 5 files changed, 224 insertions(+), 0 deletions(-)
 create mode 100644 docs/specs/acpi_mem_hotplug.txt
 create mode 100644 hw/acpi/memory_hotplug.c
 create mode 100644 include/hw/acpi/memory_hotplug.h
docs/specs/acpi_mem_hotplug.txt new file +44 -0
new file mode 100644
index 0000000..1290994
@@ -0,0 +1,44 @@
+QEMU<->ACPI BIOS memory hotplug interface
+--------------------------------------
+
+ACPI BIOS GPE.3 handler is dedicated for notifying OS about memory hot-add
+events.
+
+Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte access):
+---------------------------------------------------------------
+0xa00:
+  read access:
+      [0x0-0x3] Lo part of memory device phys address
+      [0x4-0x7] Hi part of memory device phys address
+      [0x8-0xb] Lo part of memory device size in bytes
+      [0xc-0xf] Hi part of memory device size in bytes
+      [0x10-0x13] Memory device proximity domain
+      [0x14] Memory device status fields
+          bits:
+              0: Device is enabled and may be used by guest
+              1: Device insert event, used to distinguish device for which
+                 no device check event to OSPM was issued.
+                 It's valid only when bit 1 is set.
+              2-7: reserved and should be ignored by OSPM
+      [0x15-0x17] reserved
+
+  write access:
+      [0x0-0x3] Memory device slot selector, selects active memory device.
+                All following accesses to other registers in 0xa00-0xa17
+                region will read/store data from/to selected memory device.
+      [0x4-0x7] OST event code reported by OSPM
+      [0x8-0xb] OST status code reported by OSPM
+      [0xc-0x13] reserved, writes into it are ignored
+      [0x14] Memory device control fields
+          bits:
+              0: reserved, OSPM must clear it before writing to register
+              1: if set to 1 clears device insert event, set by OSPM
+                 after it has emitted device check event for the
+                 selected memory device
+              2-7: reserved, OSPM must clear them before writing to register
+
+Selecting memory device slot beyond present range has no effect on platform:
+   - write accesses to memory hot-plug registers not documented above are
+     ignored
+   - read accesses to memory hot-plug registers not documented above return
+     all bits set to 1.
hw/acpi/Makefile.objs +1 -0
index 397d32b..004e1b2 100644
@@ -1 +1,2 @@
 common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
+common-obj-$(CONFIG_ACPI) += memory_hotplug.o
hw/acpi/memory_hotplug.c new file +147 -0

147 lines not on this page · raw message

include/hw/acpi/memory_hotplug.h new file +29 -0
new file mode 100644
index 0000000..8f90f72
@@ -0,0 +1,29 @@
+#ifndef QEMU_HW_ACPI_MEMORY_HOTPLUG_H
+#define QEMU_HW_ACPI_MEMORY_HOTPLUG_H
+
+#include "hw/qdev-core.h"
+#include "hw/acpi/acpi.h"
+
+#define ACPI_MEMORY_HOTPLUG_STATUS 8
+
+typedef struct MemStatus {
+    DeviceState *dimm;
+    bool is_enabled;
+    bool is_inserting;
+    uint32_t ost_event;
+    uint32_t ost_status;
+} MemStatus;
+
+typedef struct MemHotplugState {
+    MemoryRegion io;
+    uint32_t selector;
+    uint32_t dev_count;
+    MemStatus *devs;
+} MemHotplugState;
+
+void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner,
+                              MemHotplugState *state);
+
+void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+                         DeviceState *dev, Error **errp);
+#endif
include/hw/acpi/pc-hotplug.h +3 -0
index cee479d..01d38e2 100644
@@ -29,4 +29,7 @@
 #define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
 #define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00
 
+#define ACPI_MEMORY_HOTPLUG_IO_LEN 24
+#define ACPI_MEMORY_HOTPLUG_BASE 0x0a00
+
 #endif
Signature · 1 line
1.7.1
#24 lore raw

PATCH v4 21/33 trace: add acpi memory hotplug IO region events

In reply to Igor Mammedov

Add events for tracing accesses to memory hotplug IO ports.

---
 hw/acpi/memory_hotplug.c |   13 +++++++++++++
 trace-events             |   13 +++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)
hw/acpi/memory_hotplug.c +13 -0
index e3a13ed..8944ad3 100644
@@ -2,6 +2,7 @@
 #include "hw/acpi/pc-hotplug.h"
 #include "hw/mem/pc-dimm.h"
 #include "hw/boards.h"
+#include "trace.h"
 
 static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr,
                                          unsigned int size)
@@ -12,6 +13,7 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr,
     Object *o;
 
     if (mem_st->selector >= mem_st->dev_count) {
+        trace_mhp_acpi_invalid_slot_selected(mem_st->selector);
         return 0;
     }
 
@@ -20,22 +22,28 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr,
     switch (addr) {
     case 0x0: /* Lo part of phys address where DIMM is mapped */
         val = o ? object_property_get_int(o, PC_DIMM_ADDR_PROP, NULL) : 0;
+        trace_mhp_acpi_read_addr_lo(mem_st->selector, val);
         break;
     case 0x4: /* Hi part of phys address where DIMM is mapped */
         val = o ? object_property_get_int(o, PC_DIMM_ADDR_PROP, NULL) >> 32 : 0;
+        trace_mhp_acpi_read_addr_hi(mem_st->selector, val);
         break;
     case 0x8: /* Lo part of DIMM size */
         val = o ? object_property_get_int(o, PC_DIMM_SIZE_PROP, NULL) : 0;
+        trace_mhp_acpi_read_size_lo(mem_st->selector, val);
         break;
     case 0xc: /* Hi part of DIMM size */
         val = o ? object_property_get_int(o, PC_DIMM_SIZE_PROP, NULL) >> 32 : 0;
+        trace_mhp_acpi_read_size_hi(mem_st->selector, val);
         break;
     case 0x10: /* node proximity for _PXM method */
         val = o ? object_property_get_int(o, PC_DIMM_NODE_PROP, NULL) : 0;
+        trace_mhp_acpi_read_pxm(mem_st->selector, val);
         break;
     case 0x14: /* pack and return is_* fields */
         val |= mdev->is_enabled   ? 1 : 0;
         val |= mdev->is_inserting ? 2 : 0;
+        trace_mhp_acpi_read_flags(mem_st->selector, val);
         break;
     default:
         val = ~0;
@@ -56,6 +64,7 @@ static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data,
 
     if (addr) {
         if (mem_st->selector >= mem_st->dev_count) {
+            trace_mhp_acpi_invalid_slot_selected(mem_st->selector);
             return;
         }
     }
@@ -63,6 +72,7 @@ static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data,
     switch (addr) {
     case 0x0: /* DIMM slot selector */
         mem_st->selector = data;
+        trace_mhp_acpi_write_slot(mem_st->selector);
         break;
     case 0x4: /* _OST event  */
         mdev = &mem_st->devs[mem_st->selector];
@@ -72,10 +82,12 @@ static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data,
             /* TODO: handle device remove OST event */
         }
         mdev->ost_event = data;
+        trace_mhp_acpi_write_ost_ev(mem_st->selector, mdev->ost_event);
         break;
     case 0x8: /* _OST status */
         mdev = &mem_st->devs[mem_st->selector];
         mdev->ost_status = data;
+        trace_mhp_acpi_write_ost_status(mem_st->selector, mdev->ost_status);
         /* TODO: report async error */
         /* TODO: implement memory removal on guest signal */
         break;
@@ -83,6 +95,7 @@ static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data,
         mdev = &mem_st->devs[mem_st->selector];
         if (data & 2) { /* clear insert event */
             mdev->is_inserting  = false;
+            trace_mhp_acpi_clear_insert_evt(mem_st->selector);
         }
         break;
     }
trace-events +13 -0
index f256ca5..74c67d1 100644
@@ -1250,3 +1250,16 @@ xen_pv_mmio_write(uint64_t addr) "WARNING: write to Xen PV Device MMIO space (ad
 # hw/pci/pci_host.c
 pci_cfg_read(const char *dev, unsigned devid, unsigned fnid, unsigned offs, unsigned val) "%s %02u:%u @0x%x -> 0x%x"
 pci_cfg_write(const char *dev, unsigned devid, unsigned fnid, unsigned offs, unsigned val) "%s %02u:%u @0x%x <- 0x%x"
+
+#hw/acpi/memory_hotplug.c
+mhp_acpi_invalid_slot_selected(uint32_t slot) "0x%"PRIx32
+mhp_acpi_read_addr_lo(uint32_t slot, uint32_t addr) "slot[0x%"PRIx32"] addr lo: 0x%"PRIx32
+mhp_acpi_read_addr_hi(uint32_t slot, uint32_t addr) "slot[0x%"PRIx32"] addr hi: 0x%"PRIx32
+mhp_acpi_read_size_lo(uint32_t slot, uint32_t size) "slot[0x%"PRIx32"] size lo: 0x%"PRIx32
+mhp_acpi_read_size_hi(uint32_t slot, uint32_t size) "slot[0x%"PRIx32"] size hi: 0x%"PRIx32
+mhp_acpi_read_pxm(uint32_t slot, uint32_t pxm) "slot[0x%"PRIx32"] proximity: 0x%"PRIx32
+mhp_acpi_read_flags(uint32_t slot, uint32_t flags) "slot[0x%"PRIx32"] flags: 0x%"PRIx32
+mhp_acpi_write_slot(uint32_t slot) "set active slot: 0x%"PRIx32
+mhp_acpi_write_ost_ev(uint32_t slot, uint32_t ev) "slot[0x%"PRIx32"] OST EVENT: 0x%"PRIx32
+mhp_acpi_write_ost_status(uint32_t slot, uint32_t st) "slot[0x%"PRIx32"] OST STATUS: 0x%"PRIx32
+mhp_acpi_clear_insert_evt(uint32_t slot) "slot[0x%"PRIx32"] clear insert event"
Signature · 1 line
1.7.1
#25 lore raw

PATCH v4 22/33 trace: pc: add PC_DIMM slot & address allocation

In reply to Igor Mammedov

Add mhp_pc_dimm_assigned_slot & mhp_pc_dimm_assigned_address events to trace which address and slot where assigned to plugged in PC_DIMM device on target-i386 machine.

---
 hw/i386/pc.c |    3 +++
 trace-events |    4 ++++
 2 files changed, 7 insertions(+), 0 deletions(-)
hw/i386/pc.c +3 -0
index 7b0cba3..6b8940a 100644
@@ -59,6 +59,7 @@
 #include "hw/pci/pci_host.h"
 #include "acpi-build.h"
 #include "hw/mem/pc-dimm.h"
+#include "trace.h"
 
 /* debug PC/ISA interrupts */
 //#define DEBUG_IRQ
@@ -1576,6 +1577,7 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
     if (local_err) {
         goto out;
     }
+    trace_mhp_pc_dimm_assigned_address(addr);
 
     slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &local_err);
     if (local_err) {
@@ -1591,6 +1593,7 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
     if (local_err) {
         goto out;
     }
+    trace_mhp_pc_dimm_assigned_slot(slot);
 
     memory_region_add_subregion(&pcms->hotplug_memory,
                                 addr - pcms->hotplug_memory_base, mr);
trace-events +4 -0
index 74c67d1..f981396 100644
@@ -1263,3 +1263,7 @@ mhp_acpi_write_slot(uint32_t slot) "set active slot: 0x%"PRIx32
 mhp_acpi_write_ost_ev(uint32_t slot, uint32_t ev) "slot[0x%"PRIx32"] OST EVENT: 0x%"PRIx32
 mhp_acpi_write_ost_status(uint32_t slot, uint32_t st) "slot[0x%"PRIx32"] OST STATUS: 0x%"PRIx32
 mhp_acpi_clear_insert_evt(uint32_t slot) "slot[0x%"PRIx32"] clear insert event"
+
+#hw/i386/pc.c
+mhp_pc_dimm_assigned_slot(int slot) "0x%d"
+mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
Signature · 1 line
1.7.1
#26 lore raw

PATCH v4 23/33 acpi:piix4: allow plug/unlug callbacks handle not only PCI devices

In reply to Igor Mammedov

... and report error if plugged in device is not supported. Later these callbacks will be used by memory hotplug.

---
 hw/acpi/piix4.c |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)
hw/acpi/piix4.c +22 -9
index 67dc075..4341f82 100644
@@ -310,19 +310,32 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
     acpi_pm1_evt_power_down(&s->ar);
 }
 
-static void piix4_pci_device_plug_cb(HotplugHandler *hotplug_dev,
-                                     DeviceState *dev, Error **errp)
+static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
+                                 DeviceState *dev, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(hotplug_dev);
-    acpi_pcihp_device_plug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev, errp);
+
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+        acpi_pcihp_device_plug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev,
+                                  errp);
+    } else {
+        error_setg(errp, "acpi: device plug request for not supported device"
+                   " type: %s", object_get_typename(OBJECT(dev)));
+    }
 }
 
-static void piix4_pci_device_unplug_cb(HotplugHandler *hotplug_dev,
-                                       DeviceState *dev, Error **errp)
+static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
+                                   DeviceState *dev, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(hotplug_dev);
-    acpi_pcihp_device_unplug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev,
-                                errp);
+
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+        acpi_pcihp_device_unplug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev,
+                                    errp);
+    } else {
+        error_setg(errp, "acpi: device unplug request for not supported device"
+                   " type: %s", object_get_typename(OBJECT(dev)));
+    }
 }
 
 static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
@@ -553,8 +566,8 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
      */
     dc->cannot_instantiate_with_device_add_yet = true;
     dc->hotpluggable = false;
-    hc->plug = piix4_pci_device_plug_cb;
-    hc->unplug = piix4_pci_device_unplug_cb;
+    hc->plug = piix4_device_plug_cb;
+    hc->unplug = piix4_device_unplug_cb;
 }
 
 static const TypeInfo piix4_pm_info = {
Signature · 1 line
1.7.1
#27 lore raw

PATCH v4 24/33 acpi:piix4: add memory hotplug handling

In reply to Igor Mammedov

Add memory hotplug initialization/handling to PIIX4_PM device and enable it by default for post 2.0 machine types

---
 hw/acpi/piix4.c                  |   15 ++++++++++++++-
 include/hw/acpi/memory_hotplug.h |    1 +
 include/hw/i386/pc.h             |    5 +++++
 3 files changed, 20 insertions(+), 1 deletions(-)
hw/acpi/piix4.c +14 -1
index 4341f82..7cd1920 100644
@@ -33,6 +33,8 @@
 #include "hw/acpi/pcihp.h"
 #include "hw/acpi/cpu_hotplug.h"
 #include "hw/hotplug.h"
+#include "hw/mem/pc-dimm.h"
+#include "hw/acpi/memory_hotplug.h"
 
 //#define DEBUG
 
@@ -81,6 +83,8 @@ typedef struct PIIX4PMState {
 
     AcpiCpuHotplug gpe_cpu;
     Notifier cpu_added_notifier;
+
+    MemHotplugState acpi_memory_hotplug;
 } PIIX4PMState;
 
 #define TYPE_PIIX4_PM "PIIX4_PM"
@@ -315,7 +319,10 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
 {
     PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+    if (s->acpi_memory_hotplug.is_enabled &&
+        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+        acpi_memory_plug_cb(&s->ar, s->irq, &s->acpi_memory_hotplug, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
         acpi_pcihp_device_plug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev,
                                   errp);
     } else {
@@ -533,6 +540,10 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
                         PIIX4_CPU_HOTPLUG_IO_BASE);
     s->cpu_added_notifier.notify = piix4_cpu_added_req;
     qemu_register_cpu_added_notifier(&s->cpu_added_notifier);
+
+    if (s->acpi_memory_hotplug.is_enabled) {
+        acpi_memory_hotplug_init(parent, OBJECT(s), &s->acpi_memory_hotplug);
+    }
 }
 
 static Property piix4_pm_properties[] = {
@@ -542,6 +553,8 @@ static Property piix4_pm_properties[] = {
     DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_VAL, PIIX4PMState, s4_val, 2),
     DEFINE_PROP_BOOL("acpi-pci-hotplug-with-bridge-support", PIIX4PMState,
                      use_acpi_pci_hotplug, true),
+    DEFINE_PROP_BOOL("memory-hotplug-support", PIIX4PMState,
+                     acpi_memory_hotplug.is_enabled, true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
include/hw/acpi/memory_hotplug.h +1 -0
index 8f90f72..912c53f 100644
@@ -15,6 +15,7 @@ typedef struct MemStatus {
 } MemStatus;
 
 typedef struct MemHotplugState {
+    bool is_enabled; /* true if memory hotplug is supported */
     MemoryRegion io;
     uint32_t selector;
     uint32_t dev_count;
include/hw/i386/pc.h +5 -0
index e541c51..34c3a63 100644
@@ -314,6 +314,11 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
             .driver   = "apic",\
             .property = "version",\
             .value    = stringify(0x11),\
+        },\
+        {\
+            .driver   = "PIIX4_PM",\
+            .property = "memory-hotplug-support",\
+            .value    = "off",\
         }
 
 #define PC_COMPAT_1_7 \
Signature · 1 line
1.7.1
#28 lore raw

PATCH v4 25/33 pc: ich9 lpc: make it work with global/compat properties

In reply to Igor Mammedov

Propeties of object should be available after its instances_init() callback is finished and not added in PCIDeviceClass.init which is roughly corresponds to realize() method.
Moving properties adding into instances_init will fix missing property error when global/compat property mechanism is used.

---
 hw/isa/lpc_ich9.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
hw/isa/lpc_ich9.c +10 -5
index 51ce12d..46de3b6 100644
@@ -563,7 +563,14 @@ static void ich9_lpc_add_properties(ICH9LPCState *lpc)
     ich9_pm_add_properties(OBJECT(lpc), &lpc->pm, NULL);
 }
 
-static int ich9_lpc_initfn(PCIDevice *d)
+static void ich9_lpc_initfn(Object *obj)
+{
+    ICH9LPCState *lpc = ICH9_LPC_DEVICE(obj);
+
+    ich9_lpc_add_properties(lpc);
+}
+
+static int ich9_lpc_init(PCIDevice *d)
 {
     ICH9LPCState *lpc = ICH9_LPC_DEVICE(d);
     ISABus *isa_bus;
@@ -589,9 +596,6 @@ static int ich9_lpc_initfn(PCIDevice *d)
     memory_region_add_subregion_overlap(pci_address_space_io(d),
                                         ICH9_RST_CNT_IOPORT, &lpc->rst_cnt_mem,
                                         1);
-
-    ich9_lpc_add_properties(lpc);
-
     return 0;
 }
 
@@ -642,7 +646,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
 
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     dc->reset = ich9_lpc_reset;
-    k->init = ich9_lpc_initfn;
+    k->init = ich9_lpc_init;
     dc->vmsd = &vmstate_ich9_lpc;
     k->config_write = ich9_lpc_config_write;
     dc->desc = "ICH9 LPC bridge";
@@ -661,6 +665,7 @@ static const TypeInfo ich9_lpc_info = {
     .name       = TYPE_ICH9_LPC_DEVICE,
     .parent     = TYPE_PCI_DEVICE,
     .instance_size = sizeof(struct ICH9LPCState),
+    .instance_init = ich9_lpc_initfn,
     .class_init  = ich9_lpc_class_init,
 };
 
Signature · 1 line
1.7.1
#29 lore raw

PATCH v4 26/33 acpi:ich9: add memory hotplug handling

In reply to Igor Mammedov

Add memory hotplug initialization/handling to ICH9 LPC device and enable it by default for post 2.0 machine types

---
 hw/acpi/ich9.c         |   38 ++++++++++++++++++++++++++++++++++++++
 hw/isa/lpc_ich9.c      |   20 ++++++++++++++++++++
 include/hw/acpi/ich9.h |    4 ++++
 include/hw/i386/pc.h   |    7 ++++++-
 4 files changed, 68 insertions(+), 1 deletions(-)
hw/acpi/ich9.c +38 -0
index 0afac42..7b10c27 100644
@@ -34,6 +34,7 @@
 #include "exec/address-spaces.h"
 
 #include "hw/i386/ich9.h"
+#include "hw/mem/pc-dimm.h"
 
 //#define DEBUG
 
@@ -224,6 +225,11 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
                         &pm->gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
     pm->cpu_added_notifier.notify = ich9_cpu_added_req;
     qemu_register_cpu_added_notifier(&pm->cpu_added_notifier);
+
+    if (pm->acpi_memory_hotplug.is_enabled) {
+        acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
+                                 &pm->acpi_memory_hotplug);
+    }
 }
 
 static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v,
@@ -236,9 +242,25 @@ static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v,
     visit_type_uint32(v, &value, name, errp);
 }
 
+static bool ich9_pm_get_memory_hotplug_support(Object *obj, Error **errp)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
+
+    return s->pm.acpi_memory_hotplug.is_enabled;
+}
+
+static void ich9_pm_set_memory_hotplug_support(Object *obj, bool value,
+                                               Error **errp)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
+
+    s->pm.acpi_memory_hotplug.is_enabled = value;
+}
+
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
 {
     static const uint32_t gpe0_len = ICH9_PMIO_GPE0_LEN;
+    pm->acpi_memory_hotplug.is_enabled = true;
 
     object_property_add_uint32_ptr(obj, ACPI_PM_PROP_PM_IO_BASE,
                                    &pm->pm_io_base, errp);
@@ -247,4 +269,20 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
                         NULL, NULL, pm, NULL);
     object_property_add_uint32_ptr(obj, ACPI_PM_PROP_GPE0_BLK_LEN,
                                    &gpe0_len, errp);
+    object_property_add_bool(obj, "memory-hotplug-support",
+                             ich9_pm_get_memory_hotplug_support,
+                             ich9_pm_set_memory_hotplug_support,
+                             NULL);
+}
+
+void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)
+{
+    if (pm->acpi_memory_hotplug.is_enabled &&
+        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+        acpi_memory_plug_cb(&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug,
+                            dev, errp);
+    } else {
+        error_setg(errp, "acpi: device plug request for not supported device"
+                   " type: %s", object_get_typename(OBJECT(dev)));
+    }
 }
hw/isa/lpc_ich9.c +20 -0
index 46de3b6..2adf29a 100644
@@ -599,6 +599,19 @@ static int ich9_lpc_init(PCIDevice *d)
     return 0;
 }
 
+static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
+                                DeviceState *dev, Error **errp)
+{
+    ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+    ich9_pm_device_plug_cb(&lpc->pm, dev, errp);
+}
+
+static void ich9_device_unplug_cb(HotplugHandler *hotplug_dev,
+                                  DeviceState *dev, Error **errp)
+{
+}
+
 static bool ich9_rst_cnt_needed(void *opaque)
 {
     ICH9LPCState *lpc = opaque;
@@ -643,6 +656,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
 
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     dc->reset = ich9_lpc_reset;
@@ -659,6 +673,8 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
      * pc_q35_init()
      */
     dc->cannot_instantiate_with_device_add_yet = true;
+    hc->plug = ich9_device_plug_cb;
+    hc->unplug = ich9_device_unplug_cb;
 }
 
 static const TypeInfo ich9_lpc_info = {
@@ -667,6 +683,10 @@ static const TypeInfo ich9_lpc_info = {
     .instance_size = sizeof(struct ICH9LPCState),
     .instance_init = ich9_lpc_initfn,
     .class_init  = ich9_lpc_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_HOTPLUG_HANDLER },
+        { }
+    }
 };
 
 static void ich9_lpc_register(void)
include/hw/acpi/ich9.h +4 -0
index 104f419..1977f1b 100644
@@ -23,6 +23,7 @@
 
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/cpu_hotplug.h"
+#include "hw/acpi/memory_hotplug.h"
 
 typedef struct ICH9LPCPMRegs {
     /*
@@ -46,6 +47,8 @@ typedef struct ICH9LPCPMRegs {
 
     AcpiCpuHotplug gpe_cpu;
     Notifier cpu_added_notifier;
+
+    MemHotplugState acpi_memory_hotplug;
 } ICH9LPCPMRegs;
 
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
@@ -55,4 +58,5 @@ extern const VMStateDescription vmstate_ich9_pm;
 
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
+void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp);
 #endif /* HW_ACPI_ICH9_H */
include/hw/i386/pc.h +6 -1
index 34c3a63..cecd4c2 100644
@@ -286,7 +286,12 @@ int e820_get_num_entries(void);
 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 
 #define PC_Q35_COMPAT_2_0 \
-        PC_COMPAT_2_0
+        PC_COMPAT_2_0, \
+        {\
+            .driver   = "ICH9 LPC",\
+            .property = "memory-hotplug-support",\
+            .value    = "off",\
+        }
 
 #define PC_Q35_COMPAT_1_7 \
         PC_COMPAT_1_7, \
Signature · 1 line
1.7.1
#30 lore raw

Re: [Qemu-devel] [PATCH v4 26/33] acpi:ich9: add memory hotplug handling

Quoted 4 lines · Igor Mammedov

Add memory hotplug initialization/handling to ICH9 LPC device and enable it by default for post 2.0 machine types

I applied this, resolving a conflict.
Minor comments below, would like to see them addressed in follow-up patches.

Quoted 87 lines
---
 hw/acpi/ich9.c         |   38 ++++++++++++++++++++++++++++++++++++++
 hw/isa/lpc_ich9.c      |   20 ++++++++++++++++++++
 include/hw/acpi/ich9.h |    4 ++++
 include/hw/i386/pc.h   |    7 ++++++-
 4 files changed, 68 insertions(+), 1 deletions(-)
hw/acpi/ich9.c +38 -0
index 0afac42..7b10c27 100644
@@ -34,6 +34,7 @@
 #include "exec/address-spaces.h"
 
 #include "hw/i386/ich9.h"
+#include "hw/mem/pc-dimm.h"
 
 //#define DEBUG
 
@@ -224,6 +225,11 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
                         &pm->gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
     pm->cpu_added_notifier.notify = ich9_cpu_added_req;
     qemu_register_cpu_added_notifier(&pm->cpu_added_notifier);
+
+    if (pm->acpi_memory_hotplug.is_enabled) {
+        acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
+                                 &pm->acpi_memory_hotplug);
+    }
 }
 
 static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v,
@@ -236,9 +242,25 @@ static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v,
     visit_type_uint32(v, &value, name, errp);
 }
 
+static bool ich9_pm_get_memory_hotplug_support(Object *obj, Error **errp)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
+
+    return s->pm.acpi_memory_hotplug.is_enabled;
+}
+
+static void ich9_pm_set_memory_hotplug_support(Object *obj, bool value,
+                                               Error **errp)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
+
+    s->pm.acpi_memory_hotplug.is_enabled = value;
+}
+
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
 {
     static const uint32_t gpe0_len = ICH9_PMIO_GPE0_LEN;
+    pm->acpi_memory_hotplug.is_enabled = true;
 
     object_property_add_uint32_ptr(obj, ACPI_PM_PROP_PM_IO_BASE,
                                    &pm->pm_io_base, errp);
@@ -247,4 +269,20 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
                         NULL, NULL, pm, NULL);
     object_property_add_uint32_ptr(obj, ACPI_PM_PROP_GPE0_BLK_LEN,
                                    &gpe0_len, errp);
+    object_property_add_bool(obj, "memory-hotplug-support",
+                             ich9_pm_get_memory_hotplug_support,
+                             ich9_pm_set_memory_hotplug_support,
+                             NULL);
+}
+
+void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)
+{
+    if (pm->acpi_memory_hotplug.is_enabled &&
+        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+        acpi_memory_plug_cb(&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug,
+                            dev, errp);
+    } else {
+        error_setg(errp, "acpi: device plug request for not supported device"
+                   " type: %s", object_get_typename(OBJECT(dev)));
+    }
 }
hw/isa/lpc_ich9.c +1 -0
index 46de3b6..2adf29a 100644
@@ -599,6 +599,19 @@ static int ich9_lpc_init(PCIDevice *d)
     return 0;
 }
 
+static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,

hw/isa/lpc_ich9.c static int ich9_lpc_init(PCIDevice *d) · line 612

Quoted 10 lines
hw/isa/lpc_ich9.c +10 -0
+                                DeviceState *dev, Error **errp)
+{
+    ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+    ich9_pm_device_plug_cb(&lpc->pm, dev, errp);
+}
+
+static void ich9_device_unplug_cb(HotplugHandler *hotplug_dev,
+                                  DeviceState *dev, Error **errp)
+{

Can this set error so user knows this does not work?

Quoted 66 lines
hw/isa/lpc_ich9.c +9 -0
+}
+
 static bool ich9_rst_cnt_needed(void *opaque)
 {
     ICH9LPCState *lpc = opaque;
@@ -643,6 +656,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
 
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     dc->reset = ich9_lpc_reset;
@@ -659,6 +673,8 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
      * pc_q35_init()
      */
     dc->cannot_instantiate_with_device_add_yet = true;
+    hc->plug = ich9_device_plug_cb;
+    hc->unplug = ich9_device_unplug_cb;
 }
 
 static const TypeInfo ich9_lpc_info = {
@@ -667,6 +683,10 @@ static const TypeInfo ich9_lpc_info = {
     .instance_size = sizeof(struct ICH9LPCState),
     .instance_init = ich9_lpc_initfn,
     .class_init  = ich9_lpc_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_HOTPLUG_HANDLER },
+        { }
+    }
 };
 
 static void ich9_lpc_register(void)
include/hw/acpi/ich9.h +4 -0
index 104f419..1977f1b 100644
@@ -23,6 +23,7 @@
 
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/cpu_hotplug.h"
+#include "hw/acpi/memory_hotplug.h"
 
 typedef struct ICH9LPCPMRegs {
     /*
@@ -46,6 +47,8 @@ typedef struct ICH9LPCPMRegs {
 
     AcpiCpuHotplug gpe_cpu;
     Notifier cpu_added_notifier;
+
+    MemHotplugState acpi_memory_hotplug;
 } ICH9LPCPMRegs;
 
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
@@ -55,4 +58,5 @@ extern const VMStateDescription vmstate_ich9_pm;
 
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
+void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp);
 #endif /* HW_ACPI_ICH9_H */
include/hw/i386/pc.h +0 -0
index 34c3a63..cecd4c2 100644
@@ -286,7 +286,12 @@ int e820_get_num_entries(void);
 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);

include/hw/i386/pc.h int e820_get_num_entries(void); · line 295

Quoted 10 lines
include/hw/i386/pc.h +6 -1
 
 #define PC_Q35_COMPAT_2_0 \
-        PC_COMPAT_2_0
+        PC_COMPAT_2_0, \
+        {\
+            .driver   = "ICH9 LPC",\
+            .property = "memory-hotplug-support",\
+            .value    = "off",\
+        }
 

Spaces in names are evil.
Let's rename to ICH9_LPC or something.

Quoted 4 lines
include/hw/i386/pc.h +0 -0
 #define PC_Q35_COMPAT_1_7 \
         PC_COMPAT_1_7, \
Signature · 1 line
1.7.1
#31 lore raw

PATCH v4 27/33 pc: migrate piix4 & ich9 MemHotplugState

In reply to Igor Mammedov

Adds an optional subsection that allows to migrate current state of acpi_memory_hotplug of ACPI PM device.

---
v2:
* use subsection, requested by pbonzini

---
 hw/acpi/ich9.c                   |   24 ++++++++++++++++++++++++
 hw/acpi/memory_hotplug.c         |   27 +++++++++++++++++++++++++++
 hw/acpi/piix4.c                  |   24 ++++++++++++++++++++++++
 include/hw/acpi/memory_hotplug.h |    7 +++++++
 4 files changed, 82 insertions(+), 0 deletions(-)
hw/acpi/ich9.c +24 -0
index 7b10c27..2f66524 100644
@@ -140,6 +140,23 @@ static int ich9_pm_post_load(void *opaque, int version_id)
      .offset     = vmstate_offset_pointer(_state, _field, uint8_t),  \
  }
 
+static bool vmstate_test_use_memhp(void *opaque)
+{
+    ICH9LPCPMRegs *s = opaque;
+    return s->acpi_memory_hotplug.is_enabled;
+}
+
+static const VMStateDescription vmstate_memhp_state = {
+    .name = "ich9_pm/memhp",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_MEMORY_HOTPLUG(acpi_memory_hotplug, ICH9LPCPMRegs),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 const VMStateDescription vmstate_ich9_pm = {
     .name = "ich9_pm",
     .version_id = 1,
@@ -157,6 +174,13 @@ const VMStateDescription vmstate_ich9_pm = {
         VMSTATE_UINT32(smi_en, ICH9LPCPMRegs),
         VMSTATE_UINT32(smi_sts, ICH9LPCPMRegs),
         VMSTATE_END_OF_LIST()
+    },
+    .subsections = (VMStateSubsection[]) {
+        {
+            .vmsd = &vmstate_memhp_state,
+            .needed = vmstate_test_use_memhp,
+        },
+        VMSTATE_END_OF_LIST()
     }
 };
 
hw/acpi/memory_hotplug.c +27 -0
index 8944ad3..71c7a5e 100644
@@ -158,3 +158,30 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
     acpi_update_sci(ar, irq);
     return;
 }
+
+static const VMStateDescription vmstate_memhp_sts = {
+    .name = "memory hotplug device state",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_BOOL(is_enabled, MemStatus),
+        VMSTATE_BOOL(is_inserting, MemStatus),
+        VMSTATE_UINT32(ost_event, MemStatus),
+        VMSTATE_UINT32(ost_status, MemStatus),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+const VMStateDescription vmstate_memory_hotplug = {
+    .name = "memory hotplug state",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_UINT32(selector, MemHotplugState),
+        VMSTATE_STRUCT_VARRAY_POINTER_UINT32(devs, MemHotplugState, dev_count,
+                                             vmstate_memhp_sts, MemStatus),
+        VMSTATE_END_OF_LIST()
+    }
+};
hw/acpi/piix4.c +24 -0
index 7cd1920..777dfde 100644
@@ -250,6 +250,23 @@ static bool vmstate_test_no_use_acpi_pci_hotplug(void *opaque, int version_id)
     return !s->use_acpi_pci_hotplug;
 }
 
+static bool vmstate_test_use_memhp(void *opaque)
+{
+    PIIX4PMState *s = opaque;
+    return s->acpi_memory_hotplug.is_enabled;
+}
+
+static const VMStateDescription vmstate_memhp_state = {
+    .name = "piix4_pm/memhp",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_MEMORY_HOTPLUG(acpi_memory_hotplug, PIIX4PMState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 /* qemu-kvm 1.2 uses version 3 but advertised as 2
  * To support incoming qemu-kvm 1.2 migration, change version_id
  * and minimum_version_id to 2 below (which breaks migration from
@@ -281,6 +298,13 @@ static const VMStateDescription vmstate_acpi = {
         VMSTATE_PCI_HOTPLUG(acpi_pci_hotplug, PIIX4PMState,
                             vmstate_test_use_acpi_pci_hotplug),
         VMSTATE_END_OF_LIST()
+    },
+    .subsections = (VMStateSubsection[]) {
+        {
+            .vmsd = &vmstate_memhp_state,
+            .needed = vmstate_test_use_memhp,
+        },
+        VMSTATE_END_OF_LIST()
     }
 };
 
include/hw/acpi/memory_hotplug.h +7 -0
index 912c53f..4588459 100644
@@ -3,6 +3,7 @@
 
 #include "hw/qdev-core.h"
 #include "hw/acpi/acpi.h"
+#include "migration/vmstate.h"
 
 #define ACPI_MEMORY_HOTPLUG_STATUS 8
 
@@ -27,4 +28,10 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner,
 
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
                          DeviceState *dev, Error **errp);
+
+extern const VMStateDescription vmstate_memory_hotplug;
+#define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
+    VMSTATE_STRUCT(memhp, state, 1, \
+                   vmstate_memory_hotplug, MemHotplugState)
+
 #endif
Signature · 1 line
1.7.1
#32 lore raw

PATCH v4 28/33 pc: add acpi-device link to PCMachineState

In reply to Igor Mammedov

the link will used later to access device implementing ACPI functions instead of adhoc lookup in QOM tree.

---
 hw/acpi/piix4.c      |    6 +++++-
 hw/i386/pc_piix.c    |   12 +++++++++++-
 hw/i386/pc_q35.c     |   10 ++++++++++
 hw/mips/mips_malta.c |    2 +-
 include/hw/i386/pc.h |    8 +++++++-
 5 files changed, 34 insertions(+), 4 deletions(-)
hw/acpi/piix4.c +5 -1
index 777dfde..7473485 100644
@@ -485,13 +485,17 @@ Object *piix4_pm_find(void)
 
 I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
                       qemu_irq sci_irq, qemu_irq smi_irq,
-                      int kvm_enabled, FWCfgState *fw_cfg)
+                      int kvm_enabled, FWCfgState *fw_cfg,
+                      DeviceState **piix4_pm)
 {
     DeviceState *dev;
     PIIX4PMState *s;
 
     dev = DEVICE(pci_create(bus, devfn, TYPE_PIIX4_PM));
     qdev_prop_set_uint32(dev, "smb_io_base", smb_io_base);
+    if (piix4_pm) {
+        *piix4_pm = dev;
+    }
 
     s = PIIX4_PM(dev);
     s->irq = sci_irq;
hw/i386/pc_piix.c +11 -1
index e133b6a..a13e8d6 100644
@@ -74,6 +74,7 @@ static void pc_init1(MachineState *machine,
                      int pci_enabled,
                      int kvmclock_enabled)
 {
+    PCMachineState *pc_machine = PC_MACHINE(machine);
     MemoryRegion *system_memory = get_system_memory();
     MemoryRegion *system_io = get_system_io();
     int i;
@@ -246,14 +247,23 @@ static void pc_init1(MachineState *machine,
     }
 
     if (pci_enabled && acpi_enabled) {
+        DeviceState *piix4_pm;
         I2CBus *smbus;
 
         smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
         /* TODO: Populate SPD eeprom data.  */
         smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
                               gsi[9], *smi_irq,
-                              kvm_enabled(), fw_cfg);
+                              kvm_enabled(), fw_cfg, &piix4_pm);
         smbus_eeprom_init(smbus, 8, NULL, 0);
+
+        object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
+                                 TYPE_HOTPLUG_HANDLER,
+                                 (Object **)&pc_machine->acpi_dev,
+                                 object_property_allow_set_link,
+                                 OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
+        object_property_set_link(OBJECT(machine), OBJECT(piix4_pm),
+                                 PC_MACHINE_ACPI_DEVICE_PROP, &error_abort);
     }
 
     if (pci_enabled) {
hw/i386/pc_q35.c +10 -0
index 0e77476..629eb2d 100644
@@ -62,6 +62,7 @@ static bool has_reserved_memory = true;
 /* PC hardware initialisation */
 static void pc_q35_init(MachineState *machine)
 {
+    PCMachineState *pc_machine = PC_MACHINE(machine);
     ram_addr_t below_4g_mem_size, above_4g_mem_size;
     Q35PCIHost *q35_host;
     PCIHostState *phb;
@@ -178,6 +179,15 @@ static void pc_q35_init(MachineState *machine)
     lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV,
                                           ICH9_LPC_FUNC), true,
                                           TYPE_ICH9_LPC_DEVICE);
+
+    object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
+                             TYPE_HOTPLUG_HANDLER,
+                             (Object **)&pc_machine->acpi_dev,
+                             object_property_allow_set_link,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
+    object_property_set_link(OBJECT(machine), OBJECT(lpc),
+                             PC_MACHINE_ACPI_DEVICE_PROP, &error_abort);
+
     ich9_lpc = ICH9_LPC_DEVICE(lpc);
     ich9_lpc->pic = gsi;
     ich9_lpc->ioapic = gsi_state->ioapic_irq;
hw/mips/mips_malta.c +1 -1
index 9fe775e..6685c7e 100644
@@ -1104,7 +1104,7 @@ void mips_malta_init(MachineState *machine)
     pci_piix4_ide_init(pci_bus, hd, piix4_devfn + 1);
     pci_create_simple(pci_bus, piix4_devfn + 2, "piix4-usb-uhci");
     smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100,
-                          isa_get_irq(NULL, 9), NULL, 0, NULL);
+                          isa_get_irq(NULL, 9), NULL, 0, NULL, NULL);
     smbus_eeprom_init(smbus, 8, smbus_eeprom_buf, smbus_eeprom_size);
     g_free(smbus_eeprom_buf);
     pit = pit_init(isa_bus, 0x40, 0, NULL);
include/hw/i386/pc.h +7 -1
index cecd4c2..26526a8 100644
@@ -21,6 +21,7 @@
  * @hotplug_memory_base: address in guest RAM address space where hotplug memory
  * address space begins.
  * @hotplug_memory: hotplug memory addess space container
+ * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
  */
 struct PCMachineState {
     /*< private >*/
@@ -29,8 +30,12 @@ struct PCMachineState {
     /* <public> */
     ram_addr_t hotplug_memory_base;
     MemoryRegion hotplug_memory;
+
+    HotplugHandler *acpi_dev;
 };
 
+#define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
+
 /**
  * PCMachineClass:
  * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler
@@ -210,7 +215,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name);
 
 I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
                       qemu_irq sci_irq, qemu_irq smi_irq,
-                      int kvm_enabled, FWCfgState *fw_cfg);
+                      int kvm_enabled, FWCfgState *fw_cfg,
+                      DeviceState **piix4_pm);
 void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);
 
 /* hpet.c */
Signature · 1 line
1.7.1
#33 lore raw

PATCH v4 29/33 pc: propagate memory hotplug event to ACPI device

In reply to Igor Mammedov

Notify PIIX4_PM/ICH9LPC device about hotplug event, so that it would send SCI to guest notifying about newly added memory.

---
v2:
* fix memory leak, reported by pbonzini
* use link to ACPI device instead of looking it up in QOM tree

---
 hw/i386/pc.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
hw/i386/pc.c +10 -0
index 6b8940a..7c23274 100644
@@ -1553,6 +1553,7 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
                          DeviceState *dev, Error **errp)
 {
     int slot;
+    HotplugHandlerClass *hhc;
     Error *local_err = NULL;
     PCMachineState *pcms = PC_MACHINE(hotplug_dev);
     MachineState *machine = MACHINE(hotplug_dev);
@@ -1595,9 +1596,18 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
     }
     trace_mhp_pc_dimm_assigned_slot(slot);
 
+    if (!pcms->acpi_dev) {
+        error_setg(&local_err,
+                   "memory hotplug is not enabled: missing acpi device");
+        goto out;
+    }
+
     memory_region_add_subregion(&pcms->hotplug_memory,
                                 addr - pcms->hotplug_memory_base, mr);
     vmstate_register_ram(mr, dev);
+
+    hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev);
+    hhc->plug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err);
 out:
     error_propagate(errp, local_err);
 }
Signature · 1 line
1.7.1
#34 lore raw

PATCH v4 30/33 pc: ACPI BIOS: implement memory hotplug interface

In reply to Igor Mammedov

- provides static SSDT object for memory hotplug that can handle upto 256 hotplugable memory slots
- SSDT template for memory devices and runtime generator of them in SSDT table.

---
v2:
* use define for amount of supported slots, requested by Eduardo Habkost
* use defines in ASL code to make names more decriptive, requested by Michael S. Tsirkin
* drop unneeded "Serialized" attr in ASL code
* put memory ctrl ACPI device under PCI bus to avoid punching holes in its _CRS

---
 hw/i386/Makefile.objs        |    3 +-
 hw/i386/acpi-build.c         |   35 +++++++++
 hw/i386/ssdt-mem.dsl         |   77 ++++++++++++++++++++
 hw/i386/ssdt-misc.dsl        |  164 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/acpi/pc-hotplug.h |   21 ++++++
 5 files changed, 299 insertions(+), 1 deletions(-)
 create mode 100644 hw/i386/ssdt-mem.dsl
hw/i386/Makefile.objs +2 -1
index f66c349..a65473c 100644
@@ -9,7 +9,8 @@ obj-y += acpi-build.o
 obj-y += bios-linker-loader.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
 	hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
-	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex
+	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
+	hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
     ; then echo "$(2)"; else echo "$(3)"; fi ;)
hw/i386/acpi-build.c +35 -0
index 34c0f42..58e7306 100644
@@ -37,6 +37,7 @@
 #include "bios-linker-loader.h"
 #include "hw/loader.h"
 #include "hw/isa/isa.h"
+#include "hw/acpi/memory_hotplug.h"
 
 /* Supported chipsets: */
 #include "hw/acpi/piix4.h"
@@ -667,6 +668,14 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
 #define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
 
+#include "hw/i386/ssdt-mem.hex"
+
+/* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
+#define ACPI_MEM_OFFSET_HEX (*ssdt_mem_name - *ssdt_mem_start + 2)
+#define ACPI_MEM_OFFSET_ID (*ssdt_mem_id - *ssdt_mem_start + 7)
+#define ACPI_MEM_SIZEOF (*ssdt_mem_end - *ssdt_mem_start)
+#define ACPI_MEM_AML (ssdm_mem_aml + *ssdt_mem_start)
+
 #define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
 #define ACPI_SSDT_HEADER_LENGTH 36
 
@@ -1003,6 +1012,8 @@ build_ssdt(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
            PcPciInfo *pci, PcGuestInfo *guest_info)
 {
+    MachineState *machine = MACHINE(qdev_get_machine());
+    uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
     int ssdt_start = table_data->len;
     uint8_t *ssdt_ptr;
@@ -1031,6 +1042,9 @@ build_ssdt(GArray *table_data, GArray *linker,
     ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
                       ssdt_isa_pest[0], 16, misc->pvpanic_port);
 
+    ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
+                      ssdt_mctrl_nr_slots[0], 32, nr_mem);
+
     {
         GArray *sb_scope = build_alloc_array();
         uint8_t op = 0x10; /* ScopeOp */
@@ -1084,6 +1098,27 @@ build_ssdt(GArray *table_data, GArray *linker,
             build_free_array(package);
         }
 
+        if (nr_mem) {
+            assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
+            /* build memory devices */
+            for (i = 0; i < nr_mem; i++) {
+                char id[3];
+                uint8_t *mem = acpi_data_push(sb_scope, ACPI_MEM_SIZEOF);
+
+                snprintf(id, sizeof(id), "%02X", i);
+                memcpy(mem, ACPI_MEM_AML, ACPI_MEM_SIZEOF);
+                memcpy(mem + ACPI_MEM_OFFSET_HEX, id, 2);
+                memcpy(mem + ACPI_MEM_OFFSET_ID, id, 2);
+            }
+
+            /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
+             *     If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
+             */
+            build_append_notify_method(sb_scope,
+                                       stringify(MEMORY_SLOT_NOTIFY_METHOD),
+                                       "MP%0.02X", nr_mem);
+        }
+
         {
             AcpiBuildPciBusHotplugState hotplug_state;
             Object *pci_host;
hw/i386/ssdt-mem.dsl new file +77 -0

77 lines not on this page · raw message

hw/i386/ssdt-misc.dsl +164 -0

174 lines not on this page · raw message

include/hw/acpi/pc-hotplug.h +21 -0
index 01d38e2..bf5157d 100644
@@ -32,4 +32,25 @@
 #define ACPI_MEMORY_HOTPLUG_IO_LEN 24
 #define ACPI_MEMORY_HOTPLUG_BASE 0x0a00
 
+#define MEMORY_HOPTLUG_DEVICE        MHPD
+#define MEMORY_SLOTS_NUMBER          MDNR
+#define MEMORY_HOTPLUG_IO_REGION     HPMR
+#define MEMORY_SLOT_ADDR_LOW         MRBL
+#define MEMORY_SLOT_ADDR_HIGH        MRBH
+#define MEMORY_SLOT_SIZE_LOW         MRLL
+#define MEMORY_SLOT_SIZE_HIGH        MRLH
+#define MEMORY_SLOT_PROXIMITY        MPX
+#define MEMORY_SLOT_ENABLED          MES
+#define MEMORY_SLOT_INSERT_EVENT     MINS
+#define MEMORY_SLOT_SLECTOR          MSEL
+#define MEMORY_SLOT_OST_EVENT        MOEV
+#define MEMORY_SLOT_OST_STATUS       MOSC
+#define MEMORY_SLOT_LOCK             MLCK
+#define MEMORY_SLOT_STATUS_METHOD    MRST
+#define MEMORY_SLOT_CRS_METHOD       MCRS
+#define MEMORY_SLOT_OST_METHOD       MOST
+#define MEMORY_SLOT_PROXIMITY_METHOD MPXM
+#define MEMORY_SLOT_NOTIFY_METHOD    MTFY
+#define MEMORY_SLOT_SCAN_METHOD      MSCN
+
 #endif
Signature · 1 line
1.7.1
#35 lore raw

PATCH v4 31/33 pc: add "hotplug-memory-region-size" property to PC_MACHINE

In reply to Igor Mammedov

... it will be used by acpi-build code and by unit tests

---
 hw/i386/pc.c         |   19 +++++++++++++++++++
 include/hw/i386/pc.h |    1 +
 2 files changed, 20 insertions(+), 0 deletions(-)
hw/i386/pc.c +19 -0
index 7c23274..7cdba10 100644
@@ -60,6 +60,7 @@
 #include "acpi-build.h"
 #include "hw/mem/pc-dimm.h"
 #include "trace.h"
+#include "qapi/visitor.h"
 
 /* debug PC/ISA interrupts */
 //#define DEBUG_IRQ
@@ -1633,6 +1634,23 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
         pcmc->get_hotplug_handler(machine, dev) : NULL;
 }
 
+static void
+pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque,
+                                          const char *name, Error **errp)
+{
+    PCMachineState *pcms = PC_MACHINE(obj);
+    int64_t value = memory_region_size(&pcms->hotplug_memory);
+
+    visit_type_int(v, &value, name, errp);
+}
+
+static void pc_machine_initfn(Object *obj)
+{
+    object_property_add(obj, PC_MACHINE_MEMHP_REGION_SIZE, "int",
+                        pc_machine_get_hotplug_memory_region_size,
+                        NULL, NULL, NULL, NULL);
+}
+
 static void pc_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -1649,6 +1667,7 @@ static const TypeInfo pc_machine_info = {
     .parent = TYPE_MACHINE,
     .abstract = true,
     .instance_size = sizeof(PCMachineState),
+    .instance_init = pc_machine_initfn,
     .class_size = sizeof(PCMachineClass),
     .class_init = pc_machine_class_init,
     .interfaces = (InterfaceInfo[]) {
include/hw/i386/pc.h +1 -0
index 26526a8..c62df3c 100644
@@ -35,6 +35,7 @@ struct PCMachineState {
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
+#define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size"
 
 /**
  * PCMachineClass:
Signature · 1 line
1.7.1
#36 lore raw

PATCH v4 32/33 pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole

In reply to Igor Mammedov

Needed for Windows to use hotplugged memory device, otherwise it complains that server is not configured for memory hotplug. Tests shows that aftewards it uses dynamically provided proximity value from _PXM() method if available.

---
v2:
- reword comment in build_srat() to make it more clear
- s/hotplug_as_size/hotplugabble_address_space_size/, requested by mst
- use property for getting hotplugabble_address_space_size, requested by mst

---
 hw/i386/acpi-build.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
hw/i386/acpi-build.c +17 -0
index 58e7306..c53f0c7 100644
@@ -1199,6 +1199,10 @@ build_srat(GArray *table_data, GArray *linker,
     uint64_t curnode;
     int srat_start, numa_start, slots;
     uint64_t mem_len, mem_base, next_base;
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    ram_addr_t hotplugabble_address_space_size =
+        object_property_get_int(OBJECT(pcms), PC_MACHINE_MEMHP_REGION_SIZE,
+                                NULL);
 
     srat_start = table_data->len;
 
@@ -1263,6 +1267,19 @@ build_srat(GArray *table_data, GArray *linker,
         acpi_build_srat_memory(numamem, 0, 0, 0, MEM_AFFINITY_NOFLAGS);
     }
 
+    /*
+     * Entry is required for Windows to enable memory hotplug in OS.
+     * Memory devices may override proximity set by this entry,
+     * providing _PXM method if necessary.
+     */
+    if (hotplugabble_address_space_size) {
+        numamem = acpi_data_push(table_data, sizeof *numamem);
+        acpi_build_srat_memory(numamem, pcms->hotplug_memory_base,
+                               hotplugabble_address_space_size, 0,
+                               MEM_AFFINITY_HOTPLUGGABLE |
+                               MEM_AFFINITY_ENABLED);
+    }
+
     build_header(linker, table_data,
                  (void *)(table_data->data + srat_start),
                  "SRAT",
Signature · 1 line
1.7.1
#37 lore raw

PATCH v4 33/33 pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 machines

In reply to Igor Mammedov

also make handler edge based to avoid losing events, the same as it has been done for PCI and CPU hotplug handlers.

---
v2:
* use memory hotplug crtl located under PCI0

---
 hw/i386/acpi-dsdt.dsl     |    5 ++++-
 hw/i386/q35-acpi-dsdt.dsl |    5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
hw/i386/acpi-dsdt.dsl +4 -1
index 8ae933b..3cc0ea0 100644
@@ -314,6 +314,7 @@ DefinitionBlock (
 /****************************************************************
  * General purpose events
  ****************************************************************/
+    External(\_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD, MethodObj)
 
     Scope(\_GPE) {
         Name(_HID, "ACPI0006")
@@ -330,7 +331,9 @@ DefinitionBlock (
             // CPU hotplug event
             \_SB.PRSC()
         }
-        Method(_L03) {
+        Method(_E03) {
+            // Memory hotplug event
+            \_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD()
         }
         Method(_L04) {
         }
hw/i386/q35-acpi-dsdt.dsl +4 -1
index fddc3b2..8c3eae7 100644
@@ -410,6 +410,7 @@ DefinitionBlock (
 /****************************************************************
  * General purpose events
  ****************************************************************/
+    External(\_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD, MethodObj)
 
     Scope(\_GPE) {
         Name(_HID, "ACPI0006")
@@ -422,7 +423,9 @@ DefinitionBlock (
             // CPU hotplug event
             \_SB.PRSC()
         }
-        Method(_L03) {
+        Method(_E03) {
+            // Memory hotplug event
+            \_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD()
         }
         Method(_L04) {
         }
Signature · 1 line
1.7.1
#38 lore raw

Re: [Qemu-devel] [PATCH v4 33/33] pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 machines

This also generates warnings during "make check":

GTESTER check-qtest-i386
blkdebug: Suspended request 'A'
blkdebug: Resuming request 'A'
main-loop: WARNING: I/O thread spun for 1000 iterations
acpi-test: Warning! DSDT mismatch. Actual [asl:/tmp/asl-6P9HHX.dsl, aml:/tmp/aml-ACAIHX], Expected [asl:/tmp/asl-2Y4GHX.dsl, aml:tests/acpi-test-data/pc/DSDT].
main-loop: WARNING: I/O thread spun for 1000 iterations
acpi-test: Warning! DSDT mismatch. Actual [asl:/tmp/asl-T24HHX.dsl, aml:/tmp/aml-SO5HHX], Expected [asl:/tmp/asl-BYAIHX.dsl, aml:tests/acpi-test-data/q35/DSDT].

-Don Slutz

Quoted 59 lines · Igor Mammedov

also make handler edge based to avoid losing events, the same as it has been done for PCI and CPU hotplug handlers.

---
v2:
* use memory hotplug crtl located under PCI0

---
  hw/i386/acpi-dsdt.dsl     |    5 ++++-
  hw/i386/q35-acpi-dsdt.dsl |    5 ++++-
  2 files changed, 8 insertions(+), 2 deletions(-)
hw/i386/acpi-dsdt.dsl +4 -1
index 8ae933b..3cc0ea0 100644
@@ -314,6 +314,7 @@ DefinitionBlock (
  /****************************************************************
   * General purpose events
   ****************************************************************/
+    External(\_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD, MethodObj)
 
      Scope(\_GPE) {
          Name(_HID, "ACPI0006")
@@ -330,7 +331,9 @@ DefinitionBlock (
              // CPU hotplug event
              \_SB.PRSC()
          }
-        Method(_L03) {
+        Method(_E03) {
+            // Memory hotplug event
+            \_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD()
          }
          Method(_L04) {
          }
hw/i386/q35-acpi-dsdt.dsl +4 -1
index fddc3b2..8c3eae7 100644
@@ -410,6 +410,7 @@ DefinitionBlock (
  /****************************************************************
   * General purpose events
   ****************************************************************/
+    External(\_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD, MethodObj)
 
      Scope(\_GPE) {
          Name(_HID, "ACPI0006")
@@ -422,7 +423,9 @@ DefinitionBlock (
              // CPU hotplug event
              \_SB.PRSC()
          }
-        Method(_L03) {
+        Method(_E03) {
+            // Memory hotplug event
+            \_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD()
          }
          Method(_L04) {
          }
#39 lore raw

Re: [Qemu-devel] [PATCH v4 33/33] pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 machines

Quoted 10 lines · On Fri, 06 Jun 2014 08:44:23 -0400 Don Slutz <[email protected]> wrote:

This also generates warnings during "make check":

GTESTER check-qtest-i386
blkdebug: Suspended request 'A'
blkdebug: Resuming request 'A'
main-loop: WARNING: I/O thread spun for 1000 iterations
acpi-test: Warning! DSDT mismatch. Actual [asl:/tmp/asl-6P9HHX.dsl, aml:/tmp/aml-ACAIHX], Expected [asl:/tmp/asl-2Y4GHX.dsl, aml:tests/acpi-test-data/pc/DSDT].
main-loop: WARNING: I/O thread spun for 1000 iterations
acpi-test: Warning! DSDT mismatch. Actual [asl:/tmp/asl-T24HHX.dsl, aml:/tmp/aml-SO5HHX], Expected [asl:/tmp/asl-BYAIHX.dsl, aml:tests/acpi-test-data/q35/DSDT].

That should be so for now, series intended to go through pci tree,
and commiter /mst/ is going to update tests and binary *.hex blobs for iasl-less setups.

Quoted 65 lines

-Don Slutz

Quoted 59 lines · Igor Mammedov

also make handler edge based to avoid losing events, the same as it has been done for PCI and CPU hotplug handlers.

---
v2:
* use memory hotplug crtl located under PCI0

---
  hw/i386/acpi-dsdt.dsl     |    5 ++++-
  hw/i386/q35-acpi-dsdt.dsl |    5 ++++-
  2 files changed, 8 insertions(+), 2 deletions(-)
hw/i386/acpi-dsdt.dsl +4 -1
index 8ae933b..3cc0ea0 100644
@@ -314,6 +314,7 @@ DefinitionBlock (
  /****************************************************************
   * General purpose events
   ****************************************************************/
+    External(\_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD, MethodObj)
 
      Scope(\_GPE) {
          Name(_HID, "ACPI0006")
@@ -330,7 +331,9 @@ DefinitionBlock (
              // CPU hotplug event
              \_SB.PRSC()
          }
-        Method(_L03) {
+        Method(_E03) {
+            // Memory hotplug event
+            \_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD()
          }
          Method(_L04) {
          }
hw/i386/q35-acpi-dsdt.dsl +4 -1
index fddc3b2..8c3eae7 100644
@@ -410,6 +410,7 @@ DefinitionBlock (
  /****************************************************************
   * General purpose events
   ****************************************************************/
+    External(\_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD, MethodObj)
 
      Scope(\_GPE) {
          Name(_HID, "ACPI0006")
@@ -422,7 +423,9 @@ DefinitionBlock (
              // CPU hotplug event
              \_SB.PRSC()
          }
-        Method(_L03) {
+        Method(_E03) {
+            // Memory hotplug event
+            \_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD()
          }
          Method(_L04) {
          }
#40 lore raw

Re: [Qemu-devel] [PATCH v4 33/33] pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 machines

Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Fri, 06 Jun 2014 08:44:23 -0400 Don Slutz <[email protected]> wrote:

This also generates warnings during "make check":

GTESTER check-qtest-i386
blkdebug: Suspended request 'A'
blkdebug: Resuming request 'A'
main-loop: WARNING: I/O thread spun for 1000 iterations
acpi-test: Warning! DSDT mismatch. Actual [asl:/tmp/asl-6P9HHX.dsl, aml:/tmp/aml-ACAIHX], Expected [asl:/tmp/asl-2Y4GHX.dsl, aml:tests/acpi-test-data/pc/DSDT].
main-loop: WARNING: I/O thread spun for 1000 iterations
acpi-test: Warning! DSDT mismatch. Actual [asl:/tmp/asl-T24HHX.dsl, aml:/tmp/aml-SO5HHX], Expected [asl:/tmp/asl-BYAIHX.dsl, aml:tests/acpi-test-data/q35/DSDT].

Quoted 2 lines

That should be so for now, series intended to go through pci tree,
and commiter /mst/ is going to update tests and binary *.hex blobs for iasl-less setups.

Yes, these warnings are fine.
It's exactly the reason these are warnings and not errors, they tend to pop up in the intermediate stage after patch applied and before expected binary is updated.

Quoted 64 lines
Quoted 64 lines

-Don Slutz

Quoted 59 lines · Igor Mammedov

also make handler edge based to avoid losing events, the same as it has been done for PCI and CPU hotplug handlers.

---
v2:
* use memory hotplug crtl located under PCI0

---
  hw/i386/acpi-dsdt.dsl     |    5 ++++-
  hw/i386/q35-acpi-dsdt.dsl |    5 ++++-
  2 files changed, 8 insertions(+), 2 deletions(-)
hw/i386/acpi-dsdt.dsl +4 -1
index 8ae933b..3cc0ea0 100644
@@ -314,6 +314,7 @@ DefinitionBlock (
  /****************************************************************
   * General purpose events
   ****************************************************************/
+    External(\_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD, MethodObj)
 
      Scope(\_GPE) {
          Name(_HID, "ACPI0006")
@@ -330,7 +331,9 @@ DefinitionBlock (
              // CPU hotplug event
              \_SB.PRSC()
          }
-        Method(_L03) {
+        Method(_E03) {
+            // Memory hotplug event
+            \_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD()
          }
          Method(_L04) {
          }
hw/i386/q35-acpi-dsdt.dsl +4 -1
index fddc3b2..8c3eae7 100644
@@ -410,6 +410,7 @@ DefinitionBlock (
  /****************************************************************
   * General purpose events
   ****************************************************************/
+    External(\_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD, MethodObj)
 
      Scope(\_GPE) {
          Name(_HID, "ACPI0006")
@@ -422,7 +423,9 @@ DefinitionBlock (
              // CPU hotplug event
              \_SB.PRSC()
          }
-        Method(_L03) {
+        Method(_E03) {
+            // Memory hotplug event
+            \_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_SCAN_METHOD()
          }
          Method(_L04) {
          }
#41 lore raw
In reply to Igor Mammedov
Quoted 5 lines · Igor Mammedov

NOTE to commiter:
* update precompiled ACPI hex files for iasl-less hosts and ACPI tables test to match new ACPI tables.

What's new since v10:

The subject says v4, not v10. Am I missing something?

Quoted 5 lines

* rename DimmDevice to PCDIMMDevice
* allow anonymous DIMMs
* fix error handling in hostmemory_backend_set_size()
* fix ACPI read callback for case when guest tries to read addr/length from slot without a present DIMM

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#42 lore raw
Quoted 8 lines · On Mon, 02 Jun 2014 08:32:37 -0600 Eric Blake <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov

NOTE to commiter:
* update precompiled ACPI hex files for iasl-less hosts and ACPI tables test to match new ACPI tables.

What's new since v10:

The subject says v4, not v10. Am I missing something?

it's v10 with RFCs and v4 since series posted with PATCH prefix.

Quoted 12 lines
Quoted 6 lines

* rename DimmDevice to PCDIMMDevice
* allow anonymous DIMMs
* fix error handling in hostmemory_backend_set_size()
* fix ACPI read callback for case when guest tries to read addr/length from slot without a present DIMM

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Signature · 2 lines
Regards,
  Igor
#43 lore raw
In reply to Igor Mammedov
Quoted 3 lines · Igor Mammedov

NOTE to commiter:
* update precompiled ACPI hex files for iasl-less hosts and ACPI tables test to match new ACPI tables.

Applied, thanks everyone!

Quoted 200 lines

What's new since v10:
* rename DimmDevice to PCDIMMDevice
* allow anonymous DIMMs
* fix error handling in hostmemory_backend_set_size()
* fix ACPI read callback for case when guest tries to read addr/length from slot without a present DIMM

What's new since v9:
* drop usage of error_is_set()
* exit QEMU if it's started with memory hotplug but compat machine doesn't support it
* rename cpu_hotplug_defs.h to pc-hotplug.h
* use subsection when migrating acpi memory hotplug state
* add property to PC_MACHINE for getting hotplug memory region size

What's new since v8:
* rebased on top of Marcel's QOMyfing machine work depends on patch from qom-next:
"machine: Conversion of QEMUMachineInitArgs to MachineState"
* fixed QEMU abort if it's running in daemonized mode
* fixed leak in memdev backend
* introduced custom PCMachine
* DIMM devices are now bus-less and use bus-less hotplug method
* DIMMDevice: renamed property/field 'start' to 'addr'
* ACPI tables:
* avoid punching hotples in PCI CRS by placing MEMORY_HOPTLUG_DEVICE on PCI0 bus
* incorporated most of comments/fixes from reviewers

What's new since v7:
* Per Andreas' suggestion dropped DIMMBus concept.
* Added hotplug binding for bus-less devices
* DIMM device is split to backend and frontend. Therefore following command/options were added for supporting it:

For memory-ram backend:
CLI: -object-add memory-ram,
with options: 'id' and 'size'
For dimm frontend:
option "size" became readonly, pulling it's size from attached backend added option "memdev" for specifying backend by 'id'

* dropped support for 32 bit guests
* failed hotplug action doesn't consume 1 slot anymore
* vaious fixes adressing reviewer's comments most of them in ACPI part
---

This series allows to hotplug 'arbitrary' DIMM devices specifying size, NUMA node mapping (guest side), slot and address where to map it, at runtime.

Due to ACPI limitation there is need to specify a number of possible DIMM devices. For this task -m option was extended to support following format:

-m [mem=]RamSize[,slots=N,maxmem=M]

To allow memory hotplug user must specify a pair of additional parameters:
'slots' - number of possible increments
'maxmem' - max possible total memory size QEMU is allowed to use,
including RamSize.

minimal monitor command syntax to hotplug DIMM device:

object_add memory-ram,id=memX,size=1G
device_add pc-dimm,id=dimmX,memdev=memX

pc-dimm device provides following properties that could be used with device_add / -device to alter default behavior:

id - unique string identifying device [mandatory]
slot - number in range [0-slots) [optional], if not specified
the first free slot is used
node - NUMA node id [optional] (default: 0)
size - amount of memory to add, readonly derived from backing memdev addr - guest's physical address where to plug DIMM [optional],
if not specified the first gap in hotplug memory region that fits DIMM is used

-device option could be used for adding potentially hotunplugable DIMMs
and also for specifying hotplugged DIMMs in migration case.

Tested guests:
- RHEL 6x64
- Windows 2012DCx64
- Windows 2008DCx64

Known limitations/bugs/TODOs:
- hot-remove is not supported, yet
- max number of supported DIMM devices 256 (due to ACPI object name limit), could be increased creating several containers and putting DIMMs there. (exercise for future)
- e820 table doesn't include DIMM devices added with -device / (or after reboot devices added with device_add)
- Windows 2008 remembers DIMM configuration, so if DIMM with other addr/size is added into the same slot, it refuses to use it insisting on old mapping.

QEMU git tree for testing is available at:
https://github.com/imammedo/qemu/commits/memory-hotplug-v11

Example QEMU cmd line:

  qemu-system-x86_64 -enable-kvm -monitor unix:/tmp/mon,server,nowait \ 
     -m 4096,slots=4,maxmem=8G guest.img

PS:
Windows guest requires SRAT table for hotplug to work so add an extra option:
-numa node

Igor Mammedov (32):
pc: create custom generic PC machine type
pc: ACPI BIOS: use enum for defining memory affinity flags
object_add: allow completion handler to get canonical path vl.c: daemonize before guest memory allocation
add memdev backend infrastructure
vl.c: extend -m option to support options for memory hotplug
qdev: hotplug for buss-less devices
qdev: expose DeviceState.hotplugged field as a property
memory: add memory_region_is_mapped() API
pc-dimm: do not allow to set already used memdev
pc: initialize memory hotplug address space
pc: exit QEMU if number of slots more than supported 256
pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS
pc: exit QEMU if compat machine doesn't support memory hotlpug
pc: add memory hotplug handler to PC_MACHINE
pc-dimm: add busy address check and address auto-allocation
pc-dimm: add busy slot check and slot auto-allocation
acpi: rename cpu_hotplug_defs.h to pc-hotplug.h
acpi: memory hotplug ACPI hardware implementation
trace: add acpi memory hotplug IO region events
trace: pc: add PC_DIMM slot & address allocation acpi:piix4: allow plug/unlug callbacks handle not only PCI devices acpi:piix4: add memory hotplug handling
pc: ich9 lpc: make it work with global/compat properties acpi:ich9: add memory hotplug handling
pc: migrate piix4 & ich9 MemHotplugState
pc: add acpi-device link to PCMachineState
pc: propagate memory hotplug event to ACPI device
pc: ACPI BIOS: implement memory hotplug interface
pc: add "hotplug-memory-region-size" property to PC_MACHINE
pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole
pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35
machines

Vasilis Liaskovitis (1):
pc: implement pc-dimm device abstraction

 backends/Makefile.objs             |    2 +
 backends/hostmem-ram.c             |   54 ++++++++
 backends/hostmem.c                 |   97 +++++++++++++++
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 docs/specs/acpi_mem_hotplug.txt    |   44 +++++++
 hw/Makefile.objs                   |    1 +
 hw/acpi/Makefile.objs              |    1 +
 hw/acpi/ich9.c                     |   62 ++++++++++
 hw/acpi/memory_hotplug.c           |  187 ++++++++++++++++++++++++++++
 hw/acpi/piix4.c                    |   74 ++++++++++--
 hw/core/qdev.c                     |   30 +++++
 hw/i386/Makefile.objs              |    3 +-
 hw/i386/acpi-build.c               |   75 ++++++++++-
 hw/i386/acpi-dsdt.dsl              |    7 +-
 hw/i386/pc.c                       |  227 ++++++++++++++++++++++++++++++++++-
 hw/i386/pc_piix.c                  |   51 +++++---
 hw/i386/pc_q35.c                   |   25 +++-
 hw/i386/q35-acpi-dsdt.dsl          |    7 +-
 hw/i386/ssdt-mem.dsl               |   77 ++++++++++++
 hw/i386/ssdt-misc.dsl              |  164 +++++++++++++++++++++++++
 hw/isa/lpc_ich9.c                  |   33 +++++-
 hw/mem/Makefile.objs               |    1 +
 hw/mem/pc-dimm.c                   |  236 ++++++++++++++++++++++++++++++++++++
 hw/mips/mips_malta.c               |    2 +-
 include/exec/memory.h              |    8 ++
 include/hw/acpi/acpi.h             |    6 +
 include/hw/acpi/cpu_hotplug.h      |    2 +-
 include/hw/acpi/cpu_hotplug_defs.h |   32 -----
 include/hw/acpi/ich9.h             |    4 +
 include/hw/acpi/memory_hotplug.h   |   37 ++++++
 include/hw/acpi/pc-hotplug.h       |   56 +++++++++
 include/hw/boards.h                |   10 ++
 include/hw/i386/pc.h               |   64 ++++++++++-
 include/hw/mem/pc-dimm.h           |   79 ++++++++++++
 include/sysemu/hostmem.h           |   60 +++++++++
 memory.c                           |   10 ++-
 qemu-options.hx                    |    9 +-
 qmp.c                              |   11 ++-
 trace-events                       |   17 +++
 vl.c                               |   64 +++++++++-
 41 files changed, 1829 insertions(+), 102 deletions(-)
 create mode 100644 backends/hostmem-ram.c
 create mode 100644 backends/hostmem.c
 create mode 100644 docs/specs/acpi_mem_hotplug.txt
 create mode 100644 hw/acpi/memory_hotplug.c
 create mode 100644 hw/i386/ssdt-mem.dsl
 create mode 100644 hw/mem/Makefile.objs
 create mode 100644 hw/mem/pc-dimm.c
 delete mode 100644 include/hw/acpi/cpu_hotplug_defs.h
 create mode 100644 include/hw/acpi/memory_hotplug.h
 create mode 100644 include/hw/acpi/pc-hotplug.h
 create mode 100644 include/hw/mem/pc-dimm.h
 create mode 100644 include/sysemu/hostmem.h
#44 lore raw

Hi Igor,

I tried building your repository and got build break on ssdt-mem.hex, have you face this problem or Its just me (:-

No rule to make target `hw/i386/ssdt-mem.hex', needed by
`hw/i386/acpi-build.o'. Stop

using this rule to qemu config: ../configure --enable-kvm --enable-debug --target-list=x86_64-softmmu --iasl=IASL

Thanks.

Quoted 216 lines · Michael S. Tsirkin
Quoted 3 lines · Igor Mammedov

NOTE to commiter:
* update precompiled ACPI hex files for iasl-less hosts and ACPI tables test to match new ACPI tables.

Applied, thanks everyone!

Quoted 35 lines

What's new since v10:
* rename DimmDevice to PCDIMMDevice
* allow anonymous DIMMs
* fix error handling in hostmemory_backend_set_size()
* fix ACPI read callback for case when guest tries to read addr/length from slot without a present DIMM

What's new since v9:
* drop usage of error_is_set()
* exit QEMU if it's started with memory hotplug but compat machine doesn't support it
* rename cpu_hotplug_defs.h to pc-hotplug.h
* use subsection when migrating acpi memory hotplug state
* add property to PC_MACHINE for getting hotplug memory region size

What's new since v8:
* rebased on top of Marcel's QOMyfing machine work depends on patch from qom-next:
"machine: Conversion of QEMUMachineInitArgs to MachineState"
* fixed QEMU abort if it's running in daemonized mode
* fixed leak in memdev backend
* introduced custom PCMachine
* DIMM devices are now bus-less and use bus-less hotplug method
* DIMMDevice: renamed property/field 'start' to 'addr'
* ACPI tables:
* avoid punching hotples in PCI CRS by placing MEMORY_HOPTLUG_DEVICE on PCI0 bus
* incorporated most of comments/fixes from reviewers

What's new since v7:
* Per Andreas' suggestion dropped DIMMBus concept.
* Added hotplug binding for bus-less devices
* DIMM device is split to backend and frontend. Therefore following command/options were added for supporting it:

Quoted 5 lines

For memory-ram backend:
CLI: -object-add memory-ram,
with options: 'id' and 'size'
For dimm frontend:
option "size" became readonly, pulling it's size from attached

backend

Quoted 9 lines

added option "memdev" for specifying backend by 'id'

* dropped support for 32 bit guests
* failed hotplug action doesn't consume 1 slot anymore
* vaious fixes adressing reviewer's comments most of them in ACPI part
---

This series allows to hotplug 'arbitrary' DIMM devices specifying size, NUMA node mapping (guest side), slot and address where to map it, at

runtime.

Quoted 8 lines

Due to ACPI limitation there is need to specify a number of possible DIMM devices. For this task -m option was extended to support following format:

-m [mem=]RamSize[,slots=N,maxmem=M]

To allow memory hotplug user must specify a pair of additional

parameters:

Quoted 43 lines

'slots' - number of possible increments
'maxmem' - max possible total memory size QEMU is allowed to use,
including RamSize.

minimal monitor command syntax to hotplug DIMM device:

object_add memory-ram,id=memX,size=1G
device_add pc-dimm,id=dimmX,memdev=memX

pc-dimm device provides following properties that could be used with device_add / -device to alter default behavior:

id - unique string identifying device [mandatory]
slot - number in range [0-slots) [optional], if not specified
the first free slot is used
node - NUMA node id [optional] (default: 0)
size - amount of memory to add, readonly derived from backing memdev addr - guest's physical address where to plug DIMM [optional],
if not specified the first gap in hotplug memory region that fits DIMM is used

-device option could be used for adding potentially hotunplugable DIMMs
and also for specifying hotplugged DIMMs in migration case.

Tested guests:
- RHEL 6x64
- Windows 2012DCx64
- Windows 2008DCx64

Known limitations/bugs/TODOs:
- hot-remove is not supported, yet
- max number of supported DIMM devices 256 (due to ACPI object name limit), could be increased creating several containers and putting DIMMs there. (exercise for future)
- e820 table doesn't include DIMM devices added with -device / (or after reboot devices added with device_add)
- Windows 2008 remembers DIMM configuration, so if DIMM with other addr/size is added into the same slot, it refuses to use it insisting on old mapping.

QEMU git tree for testing is available at:
https://github.com/imammedo/qemu/commits/memory-hotplug-v11

Quoted 6 lines

Example QEMU cmd line:

  qemu-system-x86_64 -enable-kvm -monitor unix:/tmp/mon,server,nowait \
     -m 4096,slots=4,maxmem=8G guest.img

PS:
Windows guest requires SRAT table for hotplug to work so add an extra

option:

Quoted 40 lines

-numa node

Igor Mammedov (32):
pc: create custom generic PC machine type
pc: ACPI BIOS: use enum for defining memory affinity flags
object_add: allow completion handler to get canonical path vl.c: daemonize before guest memory allocation
add memdev backend infrastructure
vl.c: extend -m option to support options for memory hotplug
qdev: hotplug for buss-less devices
qdev: expose DeviceState.hotplugged field as a property
memory: add memory_region_is_mapped() API
pc-dimm: do not allow to set already used memdev
pc: initialize memory hotplug address space
pc: exit QEMU if number of slots more than supported 256
pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS
pc: exit QEMU if compat machine doesn't support memory hotlpug
pc: add memory hotplug handler to PC_MACHINE
pc-dimm: add busy address check and address auto-allocation
pc-dimm: add busy slot check and slot auto-allocation
acpi: rename cpu_hotplug_defs.h to pc-hotplug.h
acpi: memory hotplug ACPI hardware implementation
trace: add acpi memory hotplug IO region events
trace: pc: add PC_DIMM slot & address allocation acpi:piix4: allow plug/unlug callbacks handle not only PCI devices acpi:piix4: add memory hotplug handling
pc: ich9 lpc: make it work with global/compat properties acpi:ich9: add memory hotplug handling
pc: migrate piix4 & ich9 MemHotplugState
pc: add acpi-device link to PCMachineState
pc: propagate memory hotplug event to ACPI device
pc: ACPI BIOS: implement memory hotplug interface
pc: add "hotplug-memory-region-size" property to PC_MACHINE
pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole
pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35
machines

Vasilis Liaskovitis (1):
pc: implement pc-dimm device abstraction

Quoted 16 lines
 backends/Makefile.objs             |    2 +
 backends/hostmem-ram.c             |   54 ++++++++
 backends/hostmem.c                 |   97 +++++++++++++++
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 docs/specs/acpi_mem_hotplug.txt    |   44 +++++++
 hw/Makefile.objs                   |    1 +
 hw/acpi/Makefile.objs              |    1 +
 hw/acpi/ich9.c                     |   62 ++++++++++
 hw/acpi/memory_hotplug.c           |  187 ++++++++++++++++++++++++++++
 hw/acpi/piix4.c                    |   74 ++++++++++--
 hw/core/qdev.c                     |   30 +++++
 hw/i386/Makefile.objs              |    3 +-
 hw/i386/acpi-build.c               |   75 ++++++++++-
 hw/i386/acpi-dsdt.dsl              |    7 +-
 hw/i386/pc.c                       |  227

++++++++++++++++++++++++++++++++++-

Quoted 8 lines
 hw/i386/pc_piix.c                  |   51 +++++---
 hw/i386/pc_q35.c                   |   25 +++-
 hw/i386/q35-acpi-dsdt.dsl          |    7 +-
 hw/i386/ssdt-mem.dsl               |   77 ++++++++++++
 hw/i386/ssdt-misc.dsl              |  164 +++++++++++++++++++++++++
 hw/isa/lpc_ich9.c                  |   33 +++++-
 hw/mem/Makefile.objs               |    1 +
 hw/mem/pc-dimm.c                   |  236

++++++++++++++++++++++++++++++++++++

Quoted 30 lines
 hw/mips/mips_malta.c               |    2 +-
 include/exec/memory.h              |    8 ++
 include/hw/acpi/acpi.h             |    6 +
 include/hw/acpi/cpu_hotplug.h      |    2 +-
 include/hw/acpi/cpu_hotplug_defs.h |   32 -----
 include/hw/acpi/ich9.h             |    4 +
 include/hw/acpi/memory_hotplug.h   |   37 ++++++
 include/hw/acpi/pc-hotplug.h       |   56 +++++++++
 include/hw/boards.h                |   10 ++
 include/hw/i386/pc.h               |   64 ++++++++++-
 include/hw/mem/pc-dimm.h           |   79 ++++++++++++
 include/sysemu/hostmem.h           |   60 +++++++++
 memory.c                           |   10 ++-
 qemu-options.hx                    |    9 +-
 qmp.c                              |   11 ++-
 trace-events                       |   17 +++
 vl.c                               |   64 +++++++++-
 41 files changed, 1829 insertions(+), 102 deletions(-)
 create mode 100644 backends/hostmem-ram.c
 create mode 100644 backends/hostmem.c
 create mode 100644 docs/specs/acpi_mem_hotplug.txt
 create mode 100644 hw/acpi/memory_hotplug.c
 create mode 100644 hw/i386/ssdt-mem.dsl
 create mode 100644 hw/mem/Makefile.objs
 create mode 100644 hw/mem/pc-dimm.c
 delete mode 100644 include/hw/acpi/cpu_hotplug_defs.h
 create mode 100644 include/hw/acpi/memory_hotplug.h
 create mode 100644 include/hw/acpi/pc-hotplug.h
 create mode 100644 include/hw/mem/pc-dimm.h
 create mode 100644 include/sysemu/hostmem.h
#45 lore raw
Quoted 5 lines · Santosh Shukla

Hi Igor,

I tried building your repository and got build break on ssdt-mem.hex, have you face this problem or Its just me (:-

Quoted 7 lines

 No rule to make target hw/i386/ssdt-mem.hex', needed by hw/i386/ acpi-build.o'.  Stop

using this rule to qemu config: ../configure --enable-kvm --enable-debug --target-list=x86_64-softmmu --iasl=IASL

Thanks.

This means you don't have iasl.

Try this tree:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci

Quoted 220 lines · Michael S. Tsirkin

On Mon, Jun 02, 2014 at 03:24:56PM +0200, Igor Mammedov wrote:
> NOTE to commiter:
>  * update precompiled ACPI hex files for iasl-less hosts >    and ACPI tables test to match new ACPI tables.

Applied, thanks everyone!

> What's new since v10:
>  * rename DimmDevice to PCDIMMDevice
>  * allow anonymous DIMMs
>  * fix error handling in hostmemory_backend_set_size()
>  * fix ACPI read callback for case when guest tries to read >    addr/length from slot without a present DIMM
>
> What's new since v9:
>  * drop usage of error_is_set()
>  * exit QEMU if it's started with memory hotplug but
>    compat machine doesn't support it
>  * rename cpu_hotplug_defs.h to pc-hotplug.h
>  * use subsection when migrating acpi memory hotplug state >  * add property to PC_MACHINE for getting hotplug memory region size >
> What's new since v8:
>  * rebased on top of Marcel's QOMyfing machine work
>     depends on patch from qom-next:
>      "machine: Conversion of QEMUMachineInitArgs to MachineState" >  * fixed QEMU abort if it's running in daemonized mode
>  * fixed leak in memdev backend
>  * introduced custom PCMachine
>  * DIMM devices are now bus-less and use bus-less hotplug method >  * DIMMDevice: renamed property/field 'start' to 'addr'
>  * ACPI tables:
>    * avoid punching hotples in PCI CRS by placing
>      MEMORY_HOPTLUG_DEVICE on PCI0 bus
>  * incorporated most of comments/fixes from reviewers
>
> What's new since v7:
> * Per Andreas' suggestion dropped DIMMBus concept.
> * Added hotplug binding for bus-less devices
> * DIMM device is split to backend and frontend. Therefore following >   command/options were added for supporting it:
>
>   For memory-ram backend:
>       CLI: -object-add memory-ram,
>           with options: 'id' and 'size'
>   For dimm frontend:
>       option "size" became readonly, pulling it's size from attached backend
>       added option "memdev" for specifying backend by 'id' >
> * dropped support for 32 bit guests
> * failed hotplug action doesn't consume 1 slot anymore
> * vaious fixes adressing reviewer's comments most of them in ACPI part > ---
>
> This series allows to hotplug 'arbitrary' DIMM devices specifying size, > NUMA node mapping (guest side), slot and address where to map it, at runtime.
>
> Due to ACPI limitation there is need to specify a number of possible > DIMM devices. For this task -m option was extended to support > following format:
>
>   -m [mem=]RamSize[,slots=N,maxmem=M]
>
> To allow memory hotplug user must specify a pair of additional parameters:
>     'slots' - number of possible increments
>     'maxmem' - max possible total memory size QEMU is allowed to use, >                including RamSize.
>
> minimal monitor command syntax to hotplug DIMM device:
>
>   object_add memory-ram,id=memX,size=1G
>   device_add pc-dimm,id=dimmX,memdev=memX
>
> pc-dimm device provides following properties that could be used with > device_add / -device to alter default behavior:
>
>   id    - unique string identifying device [mandatory]
>   slot  - number in range [0-slots) [optional], if not specified >           the first free slot is used
>   node  - NUMA node id [optional] (default: 0)
>   size  - amount of memory to add, readonly derived from backing memdev >   addr - guest's physical address where to plug DIMM [optional], >           if not specified the first gap in hotplug memory region >           that fits DIMM is used
>
>  -device option could be used for adding potentially hotunplugable DIMMs > and also for specifying hotplugged DIMMs in migration case. >
> Tested guests:
>  - RHEL 6x64
>  - Windows 2012DCx64
>  - Windows 2008DCx64
>
> Known limitations/bugs/TODOs:
>  - hot-remove is not supported, yet
>  - max number of supported DIMM devices 256 (due to ACPI object name >    limit), could be increased creating several containers and putting >    DIMMs there. (exercise for future)
>  - e820 table doesn't include DIMM devices added with -device / >    (or after reboot devices added with device_add)
>  - Windows 2008 remembers DIMM configuration, so if DIMM with other >    addr/size is added into the same slot, it refuses to use it insisting >    on old mapping.
>
> QEMU git tree for testing is available at:
>   https://github.com/imammedo/qemu/commits/memory-hotplug-v11
>
> Example QEMU cmd line:
>   qemu-system-x86_64 -enable-kvm -monitor unix:/tmp/mon,server,nowait \
>      -m 4096,slots=4,maxmem=8G guest.img
>
> PS:
>   Windows guest requires SRAT table for hotplug to work so add an extra option:
>    -numa node
>
> Igor Mammedov (32):
>   pc: create custom generic PC machine type
>   pc: ACPI BIOS: use enum for defining memory affinity flags >   object_add: allow completion handler to get canonical path >   vl.c: daemonize before guest memory allocation
>   add memdev backend infrastructure
>   vl.c: extend -m option to support options for memory hotplug >   qdev: hotplug for buss-less devices
>   qdev: expose DeviceState.hotplugged field as a property
>   memory: add memory_region_is_mapped() API
>   pc-dimm: do not allow to set already used memdev
>   pc: initialize memory hotplug address space
>   pc: exit QEMU if number of slots more than supported 256 >   pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS >   pc: exit QEMU if compat machine doesn't support memory hotlpug >   pc: add memory hotplug handler to PC_MACHINE
>   pc-dimm: add busy address check and address auto-allocation >   pc-dimm: add busy slot check and slot auto-allocation
>   acpi: rename cpu_hotplug_defs.h to pc-hotplug.h
>   acpi: memory hotplug ACPI hardware implementation
>   trace: add acpi memory hotplug IO region events
>   trace: pc: add PC_DIMM slot & address allocation
>   acpi:piix4: allow plug/unlug callbacks handle not only PCI devices >   acpi:piix4: add memory hotplug handling
>   pc: ich9 lpc: make it work with global/compat properties >   acpi:ich9: add memory hotplug handling
>   pc: migrate piix4 & ich9 MemHotplugState
>   pc: add acpi-device link to PCMachineState
>   pc: propagate memory hotplug event to ACPI device
>   pc: ACPI BIOS: implement memory hotplug interface
>   pc: add "hotplug-memory-region-size" property to PC_MACHINE >   pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole
>   pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 >     machines
>
> Vasilis Liaskovitis (1):
>   pc: implement pc-dimm device abstraction
>
>  backends/Makefile.objs             |    2 +
>  backends/hostmem-ram.c             |   54 ++++++++
>  backends/hostmem.c                 |   97 +++++++++++++++ >  default-configs/i386-softmmu.mak   |    1 +
>  default-configs/x86_64-softmmu.mak |    1 +
>  docs/specs/acpi_mem_hotplug.txt    |   44 +++++++
>  hw/Makefile.objs                   |    1 +
>  hw/acpi/Makefile.objs              |    1 +
>  hw/acpi/ich9.c                     |   62 ++++++++++
>  hw/acpi/memory_hotplug.c           |  187 ++++++++++++++++++++++++++++ >  hw/acpi/piix4.c                    |   74 ++++++++++--
>  hw/core/qdev.c                     |   30 +++++
>  hw/i386/Makefile.objs              |    3 +-
>  hw/i386/acpi-build.c               |   75 ++++++++++-
>  hw/i386/acpi-dsdt.dsl              |    7 +-
>  hw/i386/pc.c                       |  227
++++++++++++++++++++++++++++++++++-
>  hw/i386/pc_piix.c                  |   51 +++++---
>  hw/i386/pc_q35.c                   |   25 +++-
>  hw/i386/q35-acpi-dsdt.dsl          |    7 +-
>  hw/i386/ssdt-mem.dsl               |   77 ++++++++++++
>  hw/i386/ssdt-misc.dsl              |  164 +++++++++++++++++++++++++ >  hw/isa/lpc_ich9.c                  |   33 +++++-
>  hw/mem/Makefile.objs               |    1 +
>  hw/mem/pc-dimm.c                   |  236
++++++++++++++++++++++++++++++++++++
>  hw/mips/mips_malta.c               |    2 +-
>  include/exec/memory.h              |    8 ++
>  include/hw/acpi/acpi.h             |    6 +
>  include/hw/acpi/cpu_hotplug.h      |    2 +-
>  include/hw/acpi/cpu_hotplug_defs.h |   32 -----
>  include/hw/acpi/ich9.h             |    4 +
>  include/hw/acpi/memory_hotplug.h   |   37 ++++++
>  include/hw/acpi/pc-hotplug.h       |   56 +++++++++
>  include/hw/boards.h                |   10 ++
>  include/hw/i386/pc.h               |   64 ++++++++++-
>  include/hw/mem/pc-dimm.h           |   79 ++++++++++++
>  include/sysemu/hostmem.h           |   60 +++++++++
>  memory.c                           |   10 ++-
>  qemu-options.hx                    |    9 +-
>  qmp.c                              |   11 ++-
>  trace-events                       |   17 +++
>  vl.c                               |   64 +++++++++-
>  41 files changed, 1829 insertions(+), 102 deletions(-)
>  create mode 100644 backends/hostmem-ram.c
>  create mode 100644 backends/hostmem.c
>  create mode 100644 docs/specs/acpi_mem_hotplug.txt
>  create mode 100644 hw/acpi/memory_hotplug.c
>  create mode 100644 hw/i386/ssdt-mem.dsl
>  create mode 100644 hw/mem/Makefile.objs
>  create mode 100644 hw/mem/pc-dimm.c
>  delete mode 100644 include/hw/acpi/cpu_hotplug_defs.h
>  create mode 100644 include/hw/acpi/memory_hotplug.h
>  create mode 100644 include/hw/acpi/pc-hotplug.h
>  create mode 100644 include/hw/mem/pc-dimm.h
>  create mode 100644 include/sysemu/hostmem.h

#46 lore raw
Quoted 13 lines · Michael S. Tsirkin
Quoted 3 lines · Santosh Shukla

Hi Igor,

I tried building your repository and got build break on ssdt-mem.hex,

have you

Quoted 8 lines

face this problem or Its just me (:-

No rule to make target hw/i386/ssdt-mem.hex', needed by hw/i386/
acpi-build.o'. Stop

using this rule to qemu config: ../configure --enable-kvm --enable-debug --target-list=x86_64-softmmu --iasl=IASL

Quoted 7 lines
Quoted 1 line

Thanks.

This means you don't have iasl.

Try this tree:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci

I have iasl installed in my system, and tried both repo, getting same error, I believe to build acpi's dls file, iasl=IASL option good enough, right.
any iasl vs qemu version dependency am i missing?

Thanks.

Quoted 241 lines
Quoted 2 lines

On Sun, Jun 8, 2014 at 6:31 PM, Michael S. Tsirkin <[email protected]>

Quoted 16 lines · wrote:

On Mon, Jun 02, 2014 at 03:24:56PM +0200, Igor Mammedov wrote:
> NOTE to commiter:
> * update precompiled ACPI hex files for iasl-less hosts
> and ACPI tables test to match new ACPI tables.

Applied, thanks everyone!

> What's new since v10:
> * rename DimmDevice to PCDIMMDevice
> * allow anonymous DIMMs
> * fix error handling in hostmemory_backend_set_size() > * fix ACPI read callback for case when guest tries to read
> addr/length from slot without a present DIMM
>

Quoted 7 lines

> What's new since v9:
> * drop usage of error_is_set()
> * exit QEMU if it's started with memory hotplug but
> compat machine doesn't support it
> * rename cpu_hotplug_defs.h to pc-hotplug.h
> * use subsection when migrating acpi memory hotplug state > * add property to PC_MACHINE for getting hotplug memory region

size

Quoted 21 lines
Quoted 21 lines

What's new since v8:
* rebased on top of Marcel's QOMyfing machine work depends on patch from qom-next:
"machine: Conversion of QEMUMachineInitArgs to MachineState"
* fixed QEMU abort if it's running in daemonized mode
* fixed leak in memdev backend
* introduced custom PCMachine
* DIMM devices are now bus-less and use bus-less hotplug method
* DIMMDevice: renamed property/field 'start' to 'addr'
* ACPI tables:
* avoid punching hotples in PCI CRS by placing MEMORY_HOPTLUG_DEVICE on PCI0 bus
* incorporated most of comments/fixes from reviewers

What's new since v7:
* Per Andreas' suggestion dropped DIMMBus concept.
* Added hotplug binding for bus-less devices
* DIMM device is split to backend and frontend. Therefore following command/options were added for supporting it:

Quoted 5 lines
Quoted 5 lines

For memory-ram backend:
CLI: -object-add memory-ram,
with options: 'id' and 'size'
For dimm frontend:
option "size" became readonly, pulling it's size from

attached

Quoted 6 lines

backend
> added option "memdev" for specifying backend by 'id'
>
> * dropped support for 32 bit guests
> * failed hotplug action doesn't consume 1 slot anymore > * vaious fixes adressing reviewer's comments most of them in ACPI

part

Quoted 3 lines
Quoted 3 lines

---

This series allows to hotplug 'arbitrary' DIMM devices specifying

size,

Quoted 1 line
Quoted 1 line

NUMA node mapping (guest side), slot and address where to map it,

at

Quoted 3 lines

runtime.
>
> Due to ACPI limitation there is need to specify a number of

possible

Quoted 9 lines
Quoted 6 lines

DIMM devices. For this task -m option was extended to support following format:

-m [mem=]RamSize[,slots=N,maxmem=M]

To allow memory hotplug user must specify a pair of additional

parameters:
> 'slots' - number of possible increments
> 'maxmem' - max possible total memory size QEMU is allowed to

use,

Quoted 8 lines
Quoted 8 lines

including RamSize.

minimal monitor command syntax to hotplug DIMM device:

object_add memory-ram,id=memX,size=1G
device_add pc-dimm,id=dimmX,memdev=memX

pc-dimm device provides following properties that could be used

with

Quoted 7 lines
Quoted 7 lines

device_add / -device to alter default behavior:

id - unique string identifying device [mandatory]
slot - number in range [0-slots) [optional], if not specified
the first free slot is used
node - NUMA node id [optional] (default: 0)
size - amount of memory to add, readonly derived from backing

memdev

Quoted 5 lines
Quoted 5 lines

addr - guest's physical address where to plug DIMM [optional],
if not specified the first gap in hotplug memory region that fits DIMM is used

-device option could be used for adding potentially hotunplugable

DIMMs

Quoted 10 lines
Quoted 10 lines

and also for specifying hotplugged DIMMs in migration case.

Tested guests:
- RHEL 6x64
- Windows 2012DCx64
- Windows 2008DCx64

Known limitations/bugs/TODOs:
- hot-remove is not supported, yet
- max number of supported DIMM devices 256 (due to ACPI object

name

Quoted 1 line
Quoted 1 line

limit), could be increased creating several containers and

putting

Quoted 5 lines
Quoted 5 lines

DIMMs there. (exercise for future)
- e820 table doesn't include DIMM devices added with -device / (or after reboot devices added with device_add)
- Windows 2008 remembers DIMM configuration, so if DIMM with other addr/size is added into the same slot, it refuses to use it

insisting

Quoted 7 lines
Quoted 7 lines

on old mapping.

QEMU git tree for testing is available at:
https://github.com/imammedo/qemu/commits/memory-hotplug-v11

Example QEMU cmd line:
qemu-system-x86_64 -enable-kvm -monitor

unix:/tmp/mon,server,nowait \

Quoted 4 lines
Quoted 4 lines
     -m 4096,slots=4,maxmem=8G guest.img

PS:
Windows guest requires SRAT table for hotplug to work so add an

extra

Quoted 18 lines

option:
> -numa node
>
> Igor Mammedov (32):
> pc: create custom generic PC machine type
> pc: ACPI BIOS: use enum for defining memory affinity flags
> object_add: allow completion handler to get canonical path
> vl.c: daemonize before guest memory allocation
> add memdev backend infrastructure
> vl.c: extend -m option to support options for memory hotplug
> qdev: hotplug for buss-less devices
> qdev: expose DeviceState.hotplugged field as a property
> memory: add memory_region_is_mapped() API
> pc-dimm: do not allow to set already used memdev
> pc: initialize memory hotplug address space
> pc: exit QEMU if number of slots more than supported 256
> pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS
> pc: exit QEMU if compat machine doesn't support memory hotlpug

Quoted 8 lines

> pc: add memory hotplug handler to PC_MACHINE
> pc-dimm: add busy address check and address auto-allocation
> pc-dimm: add busy slot check and slot auto-allocation
> acpi: rename cpu_hotplug_defs.h to pc-hotplug.h
> acpi: memory hotplug ACPI hardware implementation
> trace: add acpi memory hotplug IO region events
> trace: pc: add PC_DIMM slot & address allocation
> acpi:piix4: allow plug/unlug callbacks handle not only PCI

devices

Quoted 10 lines
Quoted 10 lines

acpi:piix4: add memory hotplug handling
pc: ich9 lpc: make it work with global/compat properties acpi:ich9: add memory hotplug handling
pc: migrate piix4 & ich9 MemHotplugState
pc: add acpi-device link to PCMachineState
pc: propagate memory hotplug event to ACPI device
pc: ACPI BIOS: implement memory hotplug interface
pc: add "hotplug-memory-region-size" property to PC_MACHINE
pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole
pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX

and Q35

Quoted 5 lines
Quoted 5 lines

machines

Vasilis Liaskovitis (1):
pc: implement pc-dimm device abstraction

Quoted 10 lines
Quoted 10 lines
 backends/Makefile.objs             |    2 +
 backends/hostmem-ram.c             |   54 ++++++++
 backends/hostmem.c                 |   97 +++++++++++++++
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 docs/specs/acpi_mem_hotplug.txt    |   44 +++++++
 hw/Makefile.objs                   |    1 +
 hw/acpi/Makefile.objs              |    1 +
 hw/acpi/ich9.c                     |   62 ++++++++++
 hw/acpi/memory_hotplug.c           |  187

++++++++++++++++++++++++++++

Quoted 6 lines
Quoted 6 lines
 hw/acpi/piix4.c                    |   74 ++++++++++--
 hw/core/qdev.c                     |   30 +++++
 hw/i386/Makefile.objs              |    3 +-
 hw/i386/acpi-build.c               |   75 ++++++++++-
 hw/i386/acpi-dsdt.dsl              |    7 +-
 hw/i386/pc.c                       |  227
Quoted 6 lines
    ++++++++++++++++++++++++++++++++++-
    >  hw/i386/pc_piix.c                  |   51 +++++---
    >  hw/i386/pc_q35.c                   |   25 +++-
    >  hw/i386/q35-acpi-dsdt.dsl          |    7 +-
    >  hw/i386/ssdt-mem.dsl               |   77 ++++++++++++
    >  hw/i386/ssdt-misc.dsl              |  164

+++++++++++++++++++++++++

Quoted 37 lines
Quoted 3 lines
 hw/isa/lpc_ich9.c                  |   33 +++++-
 hw/mem/Makefile.objs               |    1 +
 hw/mem/pc-dimm.c                   |  236

++++++++++++++++++++++++++++++++++++
> hw/mips/mips_malta.c | 2 +-
> include/exec/memory.h | 8 ++
> include/hw/acpi/acpi.h | 6 +
> include/hw/acpi/cpu_hotplug.h | 2 +-
> include/hw/acpi/cpu_hotplug_defs.h | 32 -----
> include/hw/acpi/ich9.h | 4 +
> include/hw/acpi/memory_hotplug.h | 37 ++++++
> include/hw/acpi/pc-hotplug.h | 56 +++++++++
> include/hw/boards.h | 10 ++
> include/hw/i386/pc.h | 64 ++++++++++-
> include/hw/mem/pc-dimm.h | 79 ++++++++++++
> include/sysemu/hostmem.h | 60 +++++++++
> memory.c | 10 ++-
> qemu-options.hx | 9 +-
> qmp.c | 11 ++-
> trace-events | 17 +++
> vl.c | 64 +++++++++-
> 41 files changed, 1829 insertions(+), 102 deletions(-) > create mode 100644 backends/hostmem-ram.c
> create mode 100644 backends/hostmem.c
> create mode 100644 docs/specs/acpi_mem_hotplug.txt > create mode 100644 hw/acpi/memory_hotplug.c > create mode 100644 hw/i386/ssdt-mem.dsl
> create mode 100644 hw/mem/Makefile.objs
> create mode 100644 hw/mem/pc-dimm.c
> delete mode 100644 include/hw/acpi/cpu_hotplug_defs.h > create mode 100644 include/hw/acpi/memory_hotplug.h > create mode 100644 include/hw/acpi/pc-hotplug.h > create mode 100644 include/hw/mem/pc-dimm.h > create mode 100644 include/sysemu/hostmem.h

#47 lore raw
Quoted 20 lines · Santosh Shukla

On Wed, Jun 11, 2014 at 1:38 PM, Michael S. Tsirkin <[email protected]> wrote:

On Wed, Jun 11, 2014 at 12:43:03PM +0530, Santosh Shukla wrote:
> Hi Igor,
>
> I tried building your repository and got build break on ssdt-mem.hex, have you
> face this problem or Its just me (:-
>
>  No rule to make target hw/i386/ssdt-mem.hex', needed by hw/i386/ > acpi-build.o'.  Stop
>
> using this rule to qemu config: ../configure --enable-kvm --enable-debug > --target-list=x86_64-softmmu --iasl=IASL
>
> Thanks.

Quoted 8 lines

This means you don't have iasl.

Try this tree:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci

I have iasl installed in my system, and tried both repo, getting same error, I believe to build acpi's dls file, iasl=IASL option good enough, right.

Is your iasl binary really named IASL in upper case? And is it on path?

Quoted 4 lines

any iasl vs qemu version dependency am i missing?

Thanks.

Try removing --iasl=IASL from configure line.

Quoted 243 lines
Quoted 3 lines

On Sun, Jun 8, 2014 at 6:31 PM, Michael S. Tsirkin <[email protected]>

wrote:
>
>     On Mon, Jun 02, 2014 at 03:24:56PM +0200, Igor Mammedov wrote:
>     > NOTE to commiter:
>     >  * update precompiled ACPI hex files for iasl-less hosts >     >    and ACPI tables test to match new ACPI tables.
>
>     Applied, thanks everyone!
>
>
>     > What's new since v10:
>     >  * rename DimmDevice to PCDIMMDevice
>     >  * allow anonymous DIMMs
>     >  * fix error handling in hostmemory_backend_set_size() >     >  * fix ACPI read callback for case when guest tries to read >     >    addr/length from slot without a present DIMM
>     >
>     > What's new since v9:
>     >  * drop usage of error_is_set()
>     >  * exit QEMU if it's started with memory hotplug but
>     >    compat machine doesn't support it
>     >  * rename cpu_hotplug_defs.h to pc-hotplug.h
>     >  * use subsection when migrating acpi memory hotplug state >     >  * add property to PC_MACHINE for getting hotplug memory region size
>     >
>     > What's new since v8:
>     >  * rebased on top of Marcel's QOMyfing machine work
>     >     depends on patch from qom-next:
>     >      "machine: Conversion of QEMUMachineInitArgs to MachineState" >     >  * fixed QEMU abort if it's running in daemonized mode >     >  * fixed leak in memdev backend
>     >  * introduced custom PCMachine
>     >  * DIMM devices are now bus-less and use bus-less hotplug method >     >  * DIMMDevice: renamed property/field 'start' to 'addr' >     >  * ACPI tables:
>     >    * avoid punching hotples in PCI CRS by placing
>     >      MEMORY_HOPTLUG_DEVICE on PCI0 bus
>     >  * incorporated most of comments/fixes from reviewers >     >
>     > What's new since v7:
>     > * Per Andreas' suggestion dropped DIMMBus concept.
>     > * Added hotplug binding for bus-less devices
>     > * DIMM device is split to backend and frontend. Therefore following >     >   command/options were added for supporting it:
>     >
>     >   For memory-ram backend:
>     >       CLI: -object-add memory-ram,
>     >           with options: 'id' and 'size'
>     >   For dimm frontend:
>     >       option "size" became readonly, pulling it's size from attached
>     backend
>     >       added option "memdev" for specifying backend by 'id' >     >
>     > * dropped support for 32 bit guests
>     > * failed hotplug action doesn't consume 1 slot anymore >     > * vaious fixes adressing reviewer's comments most of them in ACPI part
>     > ---
>     >
>     > This series allows to hotplug 'arbitrary' DIMM devices specifying size,
>     > NUMA node mapping (guest side), slot and address where to map it, at
>     runtime.
>     >
>     > Due to ACPI limitation there is need to specify a number of possible
>     > DIMM devices. For this task -m option was extended to support >     > following format:
>     >
>     >   -m [mem=]RamSize[,slots=N,maxmem=M]
>     >
>     > To allow memory hotplug user must specify a pair of additional >     parameters:
>     >     'slots' - number of possible increments
>     >     'maxmem' - max possible total memory size QEMU is allowed to use,
>     >                including RamSize.
>     >
>     > minimal monitor command syntax to hotplug DIMM device:
>     >
>     >   object_add memory-ram,id=memX,size=1G
>     >   device_add pc-dimm,id=dimmX,memdev=memX
>     >
>     > pc-dimm device provides following properties that could be used with
>     > device_add / -device to alter default behavior:
>     >
>     >   id    - unique string identifying device [mandatory] >     >   slot  - number in range [0-slots) [optional], if not specified >     >           the first free slot is used
>     >   node  - NUMA node id [optional] (default: 0)
>     >   size  - amount of memory to add, readonly derived from backing memdev
>     >   addr - guest's physical address where to plug DIMM [optional], >     >           if not specified the first gap in hotplug memory region >     >           that fits DIMM is used
>     >
>     >  -device option could be used for adding potentially hotunplugable DIMMs
>     > and also for specifying hotplugged DIMMs in migration case. >     >
>     > Tested guests:
>     >  - RHEL 6x64
>     >  - Windows 2012DCx64
>     >  - Windows 2008DCx64
>     >
>     > Known limitations/bugs/TODOs:
>     >  - hot-remove is not supported, yet
>     >  - max number of supported DIMM devices 256 (due to ACPI object name
>     >    limit), could be increased creating several containers and putting
>     >    DIMMs there. (exercise for future)
>     >  - e820 table doesn't include DIMM devices added with -device / >     >    (or after reboot devices added with device_add)
>     >  - Windows 2008 remembers DIMM configuration, so if DIMM with other >     >    addr/size is added into the same slot, it refuses to use it insisting
>     >    on old mapping.
>     >
>     > QEMU git tree for testing is available at:
>     >   https://github.com/imammedo/qemu/commits/memory-hotplug-v11
>     >
>     > Example QEMU cmd line:
>     >   qemu-system-x86_64 -enable-kvm -monitor unix:/tmp/ mon,server,nowait \
>     >      -m 4096,slots=4,maxmem=8G guest.img
>     >
>     > PS:
>     >   Windows guest requires SRAT table for hotplug to work so add an extra
>     option:
>     >    -numa node
>     >
>     > Igor Mammedov (32):
>     >   pc: create custom generic PC machine type
>     >   pc: ACPI BIOS: use enum for defining memory affinity flags >     >   object_add: allow completion handler to get canonical path >     >   vl.c: daemonize before guest memory allocation
>     >   add memdev backend infrastructure
>     >   vl.c: extend -m option to support options for memory hotplug >     >   qdev: hotplug for buss-less devices
>     >   qdev: expose DeviceState.hotplugged field as a property >     >   memory: add memory_region_is_mapped() API
>     >   pc-dimm: do not allow to set already used memdev
>     >   pc: initialize memory hotplug address space
>     >   pc: exit QEMU if number of slots more than supported 256 >     >   pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS >     >   pc: exit QEMU if compat machine doesn't support memory hotlpug >     >   pc: add memory hotplug handler to PC_MACHINE
>     >   pc-dimm: add busy address check and address auto-allocation >     >   pc-dimm: add busy slot check and slot auto-allocation >     >   acpi: rename cpu_hotplug_defs.h to pc-hotplug.h
>     >   acpi: memory hotplug ACPI hardware implementation
>     >   trace: add acpi memory hotplug IO region events
>     >   trace: pc: add PC_DIMM slot & address allocation
>     >   acpi:piix4: allow plug/unlug callbacks handle not only PCI devices
>     >   acpi:piix4: add memory hotplug handling
>     >   pc: ich9 lpc: make it work with global/compat properties >     >   acpi:ich9: add memory hotplug handling
>     >   pc: migrate piix4 & ich9 MemHotplugState
>     >   pc: add acpi-device link to PCMachineState
>     >   pc: propagate memory hotplug event to ACPI device
>     >   pc: ACPI BIOS: implement memory hotplug interface
>     >   pc: add "hotplug-memory-region-size" property to PC_MACHINE >     >   pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole >     >   pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35
>     >     machines
>     >
>     > Vasilis Liaskovitis (1):
>     >   pc: implement pc-dimm device abstraction
>     >
>     >  backends/Makefile.objs             |    2 +
>     >  backends/hostmem-ram.c             |   54 ++++++++
>     >  backends/hostmem.c                 |   97 +++++++++++++++ >     >  default-configs/i386-softmmu.mak   |    1 +
>     >  default-configs/x86_64-softmmu.mak |    1 +
>     >  docs/specs/acpi_mem_hotplug.txt    |   44 +++++++
>     >  hw/Makefile.objs                   |    1 +
>     >  hw/acpi/Makefile.objs              |    1 +
>     >  hw/acpi/ich9.c                     |   62 ++++++++++ >     >  hw/acpi/memory_hotplug.c           |  187
++++++++++++++++++++++++++++
>     >  hw/acpi/piix4.c                    |   74 ++++++++++-- >     >  hw/core/qdev.c                     |   30 +++++
>     >  hw/i386/Makefile.objs              |    3 +-
>     >  hw/i386/acpi-build.c               |   75 ++++++++++- >     >  hw/i386/acpi-dsdt.dsl              |    7 +-
>     >  hw/i386/pc.c                       |  227
>     ++++++++++++++++++++++++++++++++++-
>     >  hw/i386/pc_piix.c                  |   51 +++++---
>     >  hw/i386/pc_q35.c                   |   25 +++-
>     >  hw/i386/q35-acpi-dsdt.dsl          |    7 +-
>     >  hw/i386/ssdt-mem.dsl               |   77 ++++++++++++ >     >  hw/i386/ssdt-misc.dsl              |  164
+++++++++++++++++++++++++
>     >  hw/isa/lpc_ich9.c                  |   33 +++++-
>     >  hw/mem/Makefile.objs               |    1 +
>     >  hw/mem/pc-dimm.c                   |  236
>     ++++++++++++++++++++++++++++++++++++
>     >  hw/mips/mips_malta.c               |    2 +-
>     >  include/exec/memory.h              |    8 ++
>     >  include/hw/acpi/acpi.h             |    6 +
>     >  include/hw/acpi/cpu_hotplug.h      |    2 +-
>     >  include/hw/acpi/cpu_hotplug_defs.h |   32 -----
>     >  include/hw/acpi/ich9.h             |    4 +
>     >  include/hw/acpi/memory_hotplug.h   |   37 ++++++
>     >  include/hw/acpi/pc-hotplug.h       |   56 +++++++++
>     >  include/hw/boards.h                |   10 ++
>     >  include/hw/i386/pc.h               |   64 ++++++++++- >     >  include/hw/mem/pc-dimm.h           |   79 ++++++++++++ >     >  include/sysemu/hostmem.h           |   60 +++++++++
>     >  memory.c                           |   10 ++-
>     >  qemu-options.hx                    |    9 +-
>     >  qmp.c                              |   11 ++-
>     >  trace-events                       |   17 +++
>     >  vl.c                               |   64 +++++++++- >     >  41 files changed, 1829 insertions(+), 102 deletions(-) >     >  create mode 100644 backends/hostmem-ram.c
>     >  create mode 100644 backends/hostmem.c
>     >  create mode 100644 docs/specs/acpi_mem_hotplug.txt
>     >  create mode 100644 hw/acpi/memory_hotplug.c
>     >  create mode 100644 hw/i386/ssdt-mem.dsl
>     >  create mode 100644 hw/mem/Makefile.objs
>     >  create mode 100644 hw/mem/pc-dimm.c
>     >  delete mode 100644 include/hw/acpi/cpu_hotplug_defs.h >     >  create mode 100644 include/hw/acpi/memory_hotplug.h
>     >  create mode 100644 include/hw/acpi/pc-hotplug.h
>     >  create mode 100644 include/hw/mem/pc-dimm.h
>     >  create mode 100644 include/sysemu/hostmem.h
>
>
>

#48 lore raw
Quoted 30 lines · Michael S. Tsirkin
Quoted 4 lines · Santosh Shukla

On Wed, Jun 11, 2014 at 1:38 PM, Michael S. Tsirkin <[email protected]>

Quoted 5 lines · wrote:

On Wed, Jun 11, 2014 at 12:43:03PM +0530, Santosh Shukla wrote:
> Hi Igor,
>
> I tried building your repository and got build break on

ssdt-mem.hex,

Quoted 7 lines

have you
> face this problem or Its just me (:-
>
> No rule to make target hw/i386/ssdt-mem.hex', needed by hw/i386/ > acpi-build.o'. Stop
>
> using this rule to qemu config: ../configure --enable-kvm

--enable-debug

Quoted 10 lines
Quoted 3 lines

--target-list=x86_64-softmmu --iasl=IASL

Thanks.

This means you don't have iasl.

Try this tree:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci

Quoted 7 lines
Quoted 1 line

I have iasl installed in my system, and tried both repo, getting same

error, I

Quoted 1 line

believe to build acpi's dls file, iasl=IASL option good enough, right.

Is your iasl binary really named IASL in upper case? And is it on path?

Oops, my mount directory was different which export var IASL couldn't recognize for me. My bad, sorry for noise.

Thanks.

Quoted 278 lines
Quoted 5 lines

any iasl vs qemu version dependency am i missing?

Thanks.

Try removing --iasl=IASL from configure line.

Quoted 21 lines
Quoted 3 lines

On Sun, Jun 8, 2014 at 6:31 PM, Michael S. Tsirkin <[email protected]

wrote:
>
> On Mon, Jun 02, 2014 at 03:24:56PM +0200, Igor Mammedov wrote:
> > NOTE to commiter:
> > * update precompiled ACPI hex files for iasl-less hosts
> > and ACPI tables test to match new ACPI tables.
>
> Applied, thanks everyone!
>
>
> > What's new since v10:
> > * rename DimmDevice to PCDIMMDevice
> > * allow anonymous DIMMs
> > * fix error handling in hostmemory_backend_set_size()
> > * fix ACPI read callback for case when guest tries to read
> > addr/length from slot without a present DIMM
> >

Quoted 7 lines

> > What's new since v9:
> > * drop usage of error_is_set()
> > * exit QEMU if it's started with memory hotplug but
> > compat machine doesn't support it
> > * rename cpu_hotplug_defs.h to pc-hotplug.h
> > * use subsection when migrating acpi memory hotplug state
> > * add property to PC_MACHINE for getting hotplug memory

region

Quoted 6 lines

size
> >
> > What's new since v8:
> > * rebased on top of Marcel's QOMyfing machine work
> > depends on patch from qom-next:
> > "machine: Conversion of QEMUMachineInitArgs to

MachineState"

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

* fixed QEMU abort if it's running in daemonized mode
* fixed leak in memdev backend
* introduced custom PCMachine
* DIMM devices are now bus-less and use bus-less hotplug

method

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

* DIMMDevice: renamed property/field 'start' to 'addr'
* ACPI tables:
* avoid punching hotples in PCI CRS by placing MEMORY_HOPTLUG_DEVICE on PCI0 bus
* incorporated most of comments/fixes from reviewers

What's new since v7:
* Per Andreas' suggestion dropped DIMMBus concept.
* Added hotplug binding for bus-less devices
* DIMM device is split to backend and frontend. Therefore

following

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

command/options were added for supporting it:

For memory-ram backend:
CLI: -object-add memory-ram,
with options: 'id' and 'size'
For dimm frontend:
option "size" became readonly, pulling it's size from

Quoted 7 lines

attached
> backend
> > added option "memdev" for specifying backend by 'id'
> >
> > * dropped support for 32 bit guests
> > * failed hotplug action doesn't consume 1 slot anymore
> > * vaious fixes adressing reviewer's comments most of them in

ACPI

Quoted 4 lines
    part
    >     > ---
    >     >
    >     > This series allows to hotplug 'arbitrary' DIMM devices

specifying

Quoted 2 lines

size,
> > NUMA node mapping (guest side), slot and address where to

map it,

Quoted 11 lines

at
> runtime.
> >
> > Due to ACPI limitation there is need to specify a number of
possible
> > DIMM devices. For this task -m option was extended to support
> > following format:
> >
> > -m [mem=]RamSize[,slots=N,maxmem=M]
> >
> > To allow memory hotplug user must specify a pair of

additional

Quoted 3 lines
Quoted 3 lines

parameters:
> 'slots' - number of possible increments
> 'maxmem' - max possible total memory size QEMU is

allowed to

Quoted 9 lines

use,
> > including RamSize.
> >
> > minimal monitor command syntax to hotplug DIMM device:
> >
> > object_add memory-ram,id=memX,size=1G
> > device_add pc-dimm,id=dimmX,memdev=memX
> >
> > pc-dimm device provides following properties that could be

used

Quoted 5 lines

with
> > device_add / -device to alter default behavior:
> >
> > id - unique string identifying device [mandatory]
> > slot - number in range [0-slots) [optional], if not

specified

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

the first free slot is used
node - NUMA node id [optional] (default: 0) size - amount of memory to add, readonly derived from

backing

Quoted 2 lines

memdev
> > addr - guest's physical address where to plug DIMM

[optional],

Quoted 1 line
Quoted 1 line
Quoted 1 line

if not specified the first gap in hotplug memory

region

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

that fits DIMM is used

-device option could be used for adding potentially

hotunplugable

Quoted 11 lines

DIMMs
> > and also for specifying hotplugged DIMMs in migration case.
> >
> > Tested guests:
> > - RHEL 6x64
> > - Windows 2012DCx64
> > - Windows 2008DCx64
> >
> > Known limitations/bugs/TODOs:
> > - hot-remove is not supported, yet
> > - max number of supported DIMM devices 256 (due to ACPI

object

Quoted 5 lines

name
> > limit), could be increased creating several containers and
putting
> > DIMMs there. (exercise for future)
> > - e820 table doesn't include DIMM devices added with

-device /

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

(or after reboot devices added with device_add)
- Windows 2008 remembers DIMM configuration, so if DIMM

with other

Quoted 1 line
Quoted 1 line
Quoted 1 line

addr/size is added into the same slot, it refuses to use

it

Quoted 5 lines

insisting
> > on old mapping.
> >
> > QEMU git tree for testing is available at:
> >

https://github.com/imammedo/qemu/commits/memory-hotplug-v11

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Example QEMU cmd line:
qemu-system-x86_64 -enable-kvm -monitor unix:/tmp/

    mon,server,nowait \
    >     >      -m 4096,slots=4,maxmem=8G guest.img
    >     >
    >     > PS:
    >     >   Windows guest requires SRAT table for hotplug to work so

add an

Quoted 11 lines

extra
> option:
> > -numa node
> >
> > Igor Mammedov (32):
> > pc: create custom generic PC machine type
> > pc: ACPI BIOS: use enum for defining memory affinity flags
> > object_add: allow completion handler to get canonical path
> > vl.c: daemonize before guest memory allocation
> > add memdev backend infrastructure
> > vl.c: extend -m option to support options for memory

hotplug

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

qdev: hotplug for buss-less devices
qdev: expose DeviceState.hotplugged field as a property
memory: add memory_region_is_mapped() API
pc-dimm: do not allow to set already used memdev
pc: initialize memory hotplug address space
pc: exit QEMU if number of slots more than supported 256
pc: add 'etc/reserved-memory-end' fw_cfg interface for

SeaBIOS

Quoted 1 line
Quoted 1 line
Quoted 1 line

pc: exit QEMU if compat machine doesn't support memory

hotlpug

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

pc: add memory hotplug handler to PC_MACHINE
pc-dimm: add busy address check and address auto-allocation
pc-dimm: add busy slot check and slot auto-allocation
acpi: rename cpu_hotplug_defs.h to pc-hotplug.h
acpi: memory hotplug ACPI hardware implementation
trace: add acpi memory hotplug IO region events
trace: pc: add PC_DIMM slot & address allocation acpi:piix4: allow plug/unlug callbacks handle not only PCI

Quoted 11 lines

devices
> > acpi:piix4: add memory hotplug handling
> > pc: ich9 lpc: make it work with global/compat properties
> > acpi:ich9: add memory hotplug handling
> > pc: migrate piix4 & ich9 MemHotplugState
> > pc: add acpi-device link to PCMachineState
> > pc: propagate memory hotplug event to ACPI device
> > pc: ACPI BIOS: implement memory hotplug interface
> > pc: add "hotplug-memory-region-size" property to PC_MACHINE
> > pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole
> > pc: ACPI BIOS: make GPE.3 handle memory hotplug event on

PIIX and

Quoted 69 lines

Q35
> > machines
> >
> > Vasilis Liaskovitis (1):
> > pc: implement pc-dimm device abstraction
> >
> > backends/Makefile.objs | 2 +
> > backends/hostmem-ram.c | 54 ++++++++
> > backends/hostmem.c | 97 +++++++++++++++
> > default-configs/i386-softmmu.mak | 1 +
> > default-configs/x86_64-softmmu.mak | 1 +
> > docs/specs/acpi_mem_hotplug.txt | 44 +++++++
> > hw/Makefile.objs | 1 +
> > hw/acpi/Makefile.objs | 1 +
> > hw/acpi/ich9.c | 62 ++++++++++
> > hw/acpi/memory_hotplug.c | 187
++++++++++++++++++++++++++++
> > hw/acpi/piix4.c | 74 ++++++++++--
> > hw/core/qdev.c | 30 +++++
> > hw/i386/Makefile.objs | 3 +-
> > hw/i386/acpi-build.c | 75 ++++++++++-
> > hw/i386/acpi-dsdt.dsl | 7 +-
> > hw/i386/pc.c | 227
> ++++++++++++++++++++++++++++++++++-
> > hw/i386/pc_piix.c | 51 +++++---
> > hw/i386/pc_q35.c | 25 +++-
> > hw/i386/q35-acpi-dsdt.dsl | 7 +-
> > hw/i386/ssdt-mem.dsl | 77 ++++++++++++
> > hw/i386/ssdt-misc.dsl | 164
+++++++++++++++++++++++++
> > hw/isa/lpc_ich9.c | 33 +++++-
> > hw/mem/Makefile.objs | 1 +
> > hw/mem/pc-dimm.c | 236
> ++++++++++++++++++++++++++++++++++++
> > hw/mips/mips_malta.c | 2 +-
> > include/exec/memory.h | 8 ++
> > include/hw/acpi/acpi.h | 6 +
> > include/hw/acpi/cpu_hotplug.h | 2 +-
> > include/hw/acpi/cpu_hotplug_defs.h | 32 -----
> > include/hw/acpi/ich9.h | 4 +
> > include/hw/acpi/memory_hotplug.h | 37 ++++++
> > include/hw/acpi/pc-hotplug.h | 56 +++++++++
> > include/hw/boards.h | 10 ++
> > include/hw/i386/pc.h | 64 ++++++++++-
> > include/hw/mem/pc-dimm.h | 79 ++++++++++++
> > include/sysemu/hostmem.h | 60 +++++++++
> > memory.c | 10 ++-
> > qemu-options.hx | 9 +-
> > qmp.c | 11 ++-
> > trace-events | 17 +++
> > vl.c | 64 +++++++++-
> > 41 files changed, 1829 insertions(+), 102 deletions(-)
> > create mode 100644 backends/hostmem-ram.c
> > create mode 100644 backends/hostmem.c
> > create mode 100644 docs/specs/acpi_mem_hotplug.txt
> > create mode 100644 hw/acpi/memory_hotplug.c
> > create mode 100644 hw/i386/ssdt-mem.dsl
> > create mode 100644 hw/mem/Makefile.objs
> > create mode 100644 hw/mem/pc-dimm.c
> > delete mode 100644 include/hw/acpi/cpu_hotplug_defs.h
> > create mode 100644 include/hw/acpi/memory_hotplug.h
> > create mode 100644 include/hw/acpi/pc-hotplug.h
> > create mode 100644 include/hw/mem/pc-dimm.h
> > create mode 100644 include/sysemu/hostmem.h
>
>
>