All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring
@ 2018-10-05  9:20 David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 01/16] memory-device: fix alignment error message David Hildenbrand
                   ` (16 more replies)
  0 siblings, 17 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

This series completes refactoring of pre_plug, plug and unplug logic of
memory devices. With this as a basis, we can built e.g. virtio
based memory devices or internal "RAM chip" devices.

I dropped the virtio-pmem prototype for now, I will look into plugging
it differently next. But this part in this series here is independent of
hotplug handler changes required to make it work for virtio devices.

v4 -> v5:
- Added a bunch of RB's
- Minor spelling fixed
- Dropped "memory-device: add class function get_device_id()"
- Added   "memory-device: improve "range conflicts" error message
- Dropped "memory-device: handle integer overflows properly"
-- Will require more changes. But I am able to reproduce some overflows.
- "memory-device: document MemoryDeviceClass"
-- Changed documentation format as requested by Auger
- "memory-device: trace when pre_plugging/plugging/unplugging"
-- Include device ID and rename tracepoints.

v3 -> v4:
- Minor comment and subject fixes
- Added "memory-device: fix alignment error message"
- Added "pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug"
- Dropped "hw/acpi-build: only indicate nvdimm and pc-dimm"
- "memory-device: document MemoryDeviceClass"
-- add more details about get_plugged_size
- "memory-device: add and use memory_device_get_region_size()"
-- fixed "local_err" usage
-- due to "pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug", keep PC_DIMM cast
- "memory-device: add class function get_device_id()"
-- provide default handler
- "hmp: handle virtio-pmem when printing memory device infos"
-- avoid fall-through switch case
-- add g_assert_not_reached()
- "numa: handle virtio-pmem in NUMA stats"
-- avoid fall-through switch case
-- add g_assert_not_reached()
- Added "qdev: hotplug: provide do_unplug handler"
-- unplug/unplug_request are not called for devices inside a device hierarchy
   This new handler is always called when unrealizing and doesn't trigger
   the unrealize (in contrast to unplug/unplug_request)
- "pc: support for virtio-pmem" and "virtio-pmem: hotplug support functions"
-- use do_unplug handler
- Tested "device_del vp1". It works, and I can see in the traces the
  address getting unassigned. QEMU crashes when shutting down, that most
  most likely is a result of virtio-pmem not properly unrealizing and
  cleaning up virtqueues. (@Pankaj if you read this  )

v2 -> v3:
- Rephrased some patch subjects/descriptions
- Added "memory-device: handle integer overflows properly"
- "memory-device: forward errors in get_region_size()/get_plugged_size()"
-- drop superfluous error check
- "memory-device: document MemoryDeviceClass"
-- some rewording
- replaced "memory-device: convert get_region_size() to get_memory_region()"
        by "memory-device: add and use memory_device_get_region_size()"
       and "memory-device: factor out get_memory_region() from pc-dimm"
       and "memory-device: drop get_region_size()"
- squashed "memory-device: add device class function set_addr()"
       and "pc-dimm: implement memory device class function set_addr()"
- replaced "memory-device: ids of virtio based devices are special"
        by "memory-device: add optional function get_device_id()"
- fixed up the virtio-pmem prototype

v1 -> v2:
- Include virtio-pmem prototype
- Add "memory-device: fix error message when hinted address is too small"
- Add "memory-device: use memory device terminology in error messages"
- Add "hw/acpi-build: only indicate nvdimm and pc-dimm"
- Add "memory-device: ids of virtio based devices are special"
- Add "memory-device: ids of virtio based devices are special"
- Minor changes/fixes for other patches

David Hildenbrand (16):
  memory-device: fix alignment error message
  memory-device: fix error message when hinted address is too small
  memory-device: improve "range conflicts" error message
  pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug
  memory-device: use memory device terminology in error messages
  memory-device: introduce separate config option
  memory-device: forward errors in get_region_size()/get_plugged_size()
  memory-device: document MemoryDeviceClass
  memory-device: add and use memory_device_get_region_size()
  memory-device: factor out get_memory_region() from pc-dimm
  memory-device: drop get_region_size()
  memory-device: add device class function set_addr()
  memory-device: complete factoring out pre_plug handling
  memory-device: complete factoring out plug handling
  memory-device: complete factoring out unplug handling
  memory-device: trace when pre_plugging/plugging/unplugging

 default-configs/i386-softmmu.mak  |   3 +-
 default-configs/ppc64-softmmu.mak |   3 +-
 hw/Makefile.objs                  |   2 +-
 hw/i386/pc.c                      |   6 +-
 hw/mem/Makefile.objs              |   4 +-
 hw/mem/memory-device.c            | 103 ++++++++++++++++++++++++------
 hw/mem/nvdimm.c                   |   9 ++-
 hw/mem/pc-dimm.c                  |  84 ++++++++----------------
 hw/mem/trace-events               |   5 +-
 hw/ppc/spapr.c                    |  29 ++++-----
 include/hw/mem/memory-device.h    |  74 ++++++++++++++++++---
 include/hw/mem/pc-dimm.h          |  10 +--
 qapi/misc.json                    |   2 +-
 13 files changed, 210 insertions(+), 124 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 01/16] memory-device: fix alignment error message
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 02/16] memory-device: fix error message when hinted address is too small David Hildenbrand
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

We're missing "x" after the leading 0.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 6de4f70bb4..0b52fe2c5e 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -120,7 +120,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
 
     /* address_space_start indicates the maximum alignment we expect */
     if (QEMU_ALIGN_UP(address_space_start, align) != address_space_start) {
-        error_setg(errp, "the alignment (0%" PRIx64 ") is not supported",
+        error_setg(errp, "the alignment (0x%" PRIx64 ") is not supported",
                    align);
         return 0;
     }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 02/16] memory-device: fix error message when hinted address is too small
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 01/16] memory-device: fix alignment error message David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 03/16] memory-device: improve "range conflicts" error message David Hildenbrand
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

The "at" should actually be a "before".
    if (new_addr < address_space_start)
     -> "can't add memory ... before... $address_space_start"

So it looks similar to the other check
    } else if ((new_addr + size) > address_space_end)
     -> "can't add memory ... beyond..."

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 0b52fe2c5e..7c706fadfc 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -146,7 +146,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
         new_addr = *hint;
         if (new_addr < address_space_start) {
             error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
-                       "] at 0x%" PRIx64, new_addr, size, address_space_start);
+                       "] before 0x%" PRIx64, new_addr, size,
+                       address_space_start);
             return 0;
         } else if ((new_addr + size) > address_space_end) {
             error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 03/16] memory-device: improve "range conflicts" error message
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 01/16] memory-device: fix alignment error message David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 02/16] memory-device: fix error message when hinted address is too small David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-08  2:05   ` David Gibson
  2018-10-09 10:59   ` Philippe Mathieu-Daudé
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 04/16] pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug David Hildenbrand
                   ` (13 subsequent siblings)
  16 siblings, 2 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

Handle id==NULL better and indicate that we are dealing with memory
devices.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 7c706fadfc..0624184c40 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -175,7 +175,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
         if (ranges_overlap(md_addr, md_size, new_addr, size)) {
             if (hint) {
                 const DeviceState *d = DEVICE(md);
-                error_setg(errp, "address range conflicts with '%s'", d->id);
+                error_setg(errp, "address range conflicts with memory device"
+                           " id='%s'", d->id ? d->id : "(unnamed)");
                 goto out;
             }
             new_addr = QEMU_ALIGN_UP(md_addr + md_size, align);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 04/16] pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (2 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 03/16] memory-device: improve "range conflicts" error message David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 05/16] memory-device: use memory device terminology in error messages David Hildenbrand
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

We're plugging/unplugging a PCDIMMDevice, so directly pass this type
instead of a more generic DeviceState.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/i386/pc.c             |  6 +++---
 hw/mem/pc-dimm.c         | 24 +++++++++++-------------
 hw/ppc/spapr.c           |  8 ++++----
 include/hw/mem/pc-dimm.h |  6 +++---
 4 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 03148450c8..86c16f9aaf 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1699,7 +1699,7 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
-    pc_dimm_pre_plug(dev, MACHINE(hotplug_dev),
+    pc_dimm_pre_plug(PC_DIMM(dev), MACHINE(hotplug_dev),
                      pcmc->enforce_aligned_dimm ? NULL : &legacy_align, errp);
 }
 
@@ -1711,7 +1711,7 @@ static void pc_memory_plug(HotplugHandler *hotplug_dev,
     PCMachineState *pcms = PC_MACHINE(hotplug_dev);
     bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
 
-    pc_dimm_plug(dev, MACHINE(pcms), &local_err);
+    pc_dimm_plug(PC_DIMM(dev), MACHINE(pcms), &local_err);
     if (local_err) {
         goto out;
     }
@@ -1771,7 +1771,7 @@ static void pc_memory_unplug(HotplugHandler *hotplug_dev,
         goto out;
     }
 
-    pc_dimm_unplug(dev, MACHINE(pcms));
+    pc_dimm_unplug(PC_DIMM(dev), MACHINE(pcms));
     object_unparent(OBJECT(dev));
 
  out:
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index fb6bcaedc4..f46fb7ada2 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -29,24 +29,24 @@
 
 static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
 
-void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine,
+void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
                       const uint64_t *legacy_align, Error **errp)
 {
-    PCDIMMDevice *dimm = PC_DIMM(dev);
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
     Error *local_err = NULL;
     MemoryRegion *mr;
     uint64_t addr, align;
     int slot;
 
-    slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+    slot = object_property_get_int(OBJECT(dimm), PC_DIMM_SLOT_PROP,
                                    &error_abort);
     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, &error_abort);
+    object_property_set_int(OBJECT(dimm), slot, PC_DIMM_SLOT_PROP,
+                            &error_abort);
     trace_mhp_pc_dimm_assigned_slot(slot);
 
     mr = ddc->get_memory_region(dimm, &local_err);
@@ -55,7 +55,7 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine,
     }
 
     align = legacy_align ? *legacy_align : memory_region_get_alignment(mr);
-    addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP,
+    addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
                                     &error_abort);
     addr = memory_device_get_free_addr(machine, !addr ? NULL : &addr, align,
                                        memory_region_size(mr), &local_err);
@@ -63,38 +63,36 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine,
         goto out;
     }
     trace_mhp_pc_dimm_assigned_address(addr);
-    object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP,
+    object_property_set_uint(OBJECT(dimm), addr, PC_DIMM_ADDR_PROP,
                              &error_abort);
 out:
     error_propagate(errp, local_err);
 }
 
-void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp)
+void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
 {
-    PCDIMMDevice *dimm = PC_DIMM(dev);
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
     MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
                                                               &error_abort);
     MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
     uint64_t addr;
 
-    addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP,
+    addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
                                     &error_abort);
 
     memory_device_plug_region(machine, mr, addr);
-    vmstate_register_ram(vmstate_mr, dev);
+    vmstate_register_ram(vmstate_mr, DEVICE(dimm));
 }
 
-void pc_dimm_unplug(DeviceState *dev, MachineState *machine)
+void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine)
 {
-    PCDIMMDevice *dimm = PC_DIMM(dev);
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
     MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
                                                               &error_abort);
     MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
 
     memory_device_unplug_region(machine, mr);
-    vmstate_unregister_ram(vmstate_mr, dev);
+    vmstate_unregister_ram(vmstate_mr, DEVICE(dimm));
 }
 
 static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 98868d893a..c078347b66 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3135,7 +3135,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
 
     size = memory_region_size(mr);
 
-    pc_dimm_plug(dev, MACHINE(ms), &local_err);
+    pc_dimm_plug(dimm, MACHINE(ms), &local_err);
     if (local_err) {
         goto out;
     }
@@ -3158,7 +3158,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     return;
 
 out_unplug:
-    pc_dimm_unplug(dev, MACHINE(ms));
+    pc_dimm_unplug(dimm, MACHINE(ms));
 out:
     error_propagate(errp, local_err);
 }
@@ -3202,7 +3202,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
-    pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), NULL, errp);
+    pc_dimm_pre_plug(dimm, MACHINE(hotplug_dev), NULL, errp);
 }
 
 struct sPAPRDIMMState {
@@ -3314,7 +3314,7 @@ static void spapr_memory_unplug(HotplugHandler *hotplug_dev, DeviceState *dev)
     sPAPRMachineState *spapr = SPAPR_MACHINE(hotplug_dev);
     sPAPRDIMMState *ds = spapr_pending_dimm_unplugs_find(spapr, PC_DIMM(dev));
 
-    pc_dimm_unplug(dev, MACHINE(hotplug_dev));
+    pc_dimm_unplug(PC_DIMM(dev), MACHINE(hotplug_dev));
     object_unparent(OBJECT(dev));
     spapr_pending_dimm_unplugs_remove(spapr, ds);
 }
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index b382eb4303..99cbd54de7 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -79,8 +79,8 @@ typedef struct PCDIMMDeviceClass {
                                                Error **errp);
 } PCDIMMDeviceClass;
 
-void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine,
+void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
                       const uint64_t *legacy_align, Error **errp);
-void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp);
-void pc_dimm_unplug(DeviceState *dev, MachineState *machine);
+void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp);
+void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine);
 #endif
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 05/16] memory-device: use memory device terminology in error messages
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (3 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 04/16] pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 06/16] memory-device: introduce separate config option David Hildenbrand
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

While we rephrased most error messages, we missed these.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 0624184c40..87369ef2e1 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -87,7 +87,7 @@ static void memory_device_check_addable(MachineState *ms, uint64_t size,
     memory_device_used_region_size(OBJECT(ms), &used_region_size);
     if (used_region_size + size > ms->maxram_size - ms->ram_size) {
         error_setg(errp, "not enough space, currently 0x%" PRIx64
-                   " in use of total hot pluggable 0x" RAM_ADDR_FMT,
+                   " in use of total space for memory devices 0x" RAM_ADDR_FMT,
                    used_region_size, ms->maxram_size - ms->ram_size);
         return;
     }
@@ -145,12 +145,12 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
     if (hint) {
         new_addr = *hint;
         if (new_addr < address_space_start) {
-            error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
+            error_setg(errp, "can't add memory device [0x%" PRIx64 ":0x%" PRIx64
                        "] before 0x%" PRIx64, new_addr, size,
                        address_space_start);
             return 0;
         } else if ((new_addr + size) > address_space_end) {
-            error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
+            error_setg(errp, "can't add memory device [0x%" PRIx64 ":0x%" PRIx64
                        "] beyond 0x%" PRIx64, new_addr, size,
                        address_space_end);
             return 0;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 06/16] memory-device: introduce separate config option
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (4 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 05/16] memory-device: use memory device terminology in error messages David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 07/16] memory-device: forward errors in get_region_size()/get_plugged_size() David Hildenbrand
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

Some architectures might support memory devices, while they don't
support DIMM/NVDIMM. So let's
- Rename CONFIG_MEM_HOTPLUG to CONFIG_MEM_DEVICE
- Introduce CONFIG_DIMM and use it similarly to CONFIG NVDIMM

CONFIG_DIMM and CONFIG_NVDIMM require CONFIG_MEM_DEVICE.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 default-configs/i386-softmmu.mak  | 3 ++-
 default-configs/ppc64-softmmu.mak | 3 ++-
 hw/Makefile.objs                  | 2 +-
 hw/mem/Makefile.objs              | 4 ++--
 qapi/misc.json                    | 2 +-
 5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 8c7d4a0fa0..4c1637338b 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -50,7 +50,8 @@ CONFIG_PCI_Q35=y
 CONFIG_APIC=y
 CONFIG_IOAPIC=y
 CONFIG_PVPANIC=y
-CONFIG_MEM_HOTPLUG=y
+CONFIG_MEM_DEVICE=y
+CONFIG_DIMM=y
 CONFIG_NVDIMM=y
 CONFIG_ACPI_NVDIMM=y
 CONFIG_PCIE_PORT=y
diff --git a/default-configs/ppc64-softmmu.mak b/default-configs/ppc64-softmmu.mak
index b94af6c7c6..f550573782 100644
--- a/default-configs/ppc64-softmmu.mak
+++ b/default-configs/ppc64-softmmu.mak
@@ -16,4 +16,5 @@ CONFIG_VIRTIO_VGA=y
 CONFIG_XICS=$(CONFIG_PSERIES)
 CONFIG_XICS_SPAPR=$(CONFIG_PSERIES)
 CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM))
-CONFIG_MEM_HOTPLUG=y
+CONFIG_MEM_DEVICE=y
+CONFIG_DIMM=y
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index a19c1417ed..58872e27e0 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -33,7 +33,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += vfio/
 devices-dirs-$(CONFIG_SOFTMMU) += virtio/
 devices-dirs-$(CONFIG_SOFTMMU) += watchdog/
 devices-dirs-$(CONFIG_SOFTMMU) += xen/
-devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/
+devices-dirs-$(CONFIG_MEM_DEVICE) += mem/
 devices-dirs-$(CONFIG_SOFTMMU) += smbios/
 devices-dirs-y += core/
 common-obj-y += $(devices-dirs-y)
diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs
index 10be4df2a2..3e2f7c5ca2 100644
--- a/hw/mem/Makefile.objs
+++ b/hw/mem/Makefile.objs
@@ -1,3 +1,3 @@
-common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o
-common-obj-$(CONFIG_MEM_HOTPLUG) += memory-device.o
+common-obj-$(CONFIG_DIMM) += pc-dimm.o
+common-obj-$(CONFIG_MEM_DEVICE) += memory-device.o
 common-obj-$(CONFIG_NVDIMM) += nvdimm.o
diff --git a/qapi/misc.json b/qapi/misc.json
index ada9af5add..e14efd70b0 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -2066,7 +2066,7 @@
 #
 # @plugged-memory: size of memory that can be hot-unplugged. This field
 #                  is omitted if target doesn't support memory hotplug
-#                  (i.e. CONFIG_MEM_HOTPLUG not defined on build time).
+#                  (i.e. CONFIG_MEM_DEVICE not defined at build time).
 #
 # Since: 2.11.0
 ##
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 07/16] memory-device: forward errors in get_region_size()/get_plugged_size()
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (5 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 06/16] memory-device: introduce separate config option David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 08/16] memory-device: document MemoryDeviceClass David Hildenbrand
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

Let's properly forward the errors, so errors from get_region_size() /
get_plugged_size() can be handled.

Users right now call both functions after the device has been realized,
which is will never fail, so it is fine to continue using error_abort.

While at it, remove a leftover error check (suggested by Igor).

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c         | 9 +++------
 hw/mem/pc-dimm.c               | 5 +++--
 include/hw/mem/memory-device.h | 4 ++--
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 87369ef2e1..c1e1b81cf2 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -60,7 +60,7 @@ static int memory_device_used_region_size(Object *obj, void *opaque)
         const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj);
 
         if (dev->realized) {
-            *size += mdc->get_region_size(md);
+            *size += mdc->get_region_size(md, &error_abort);
         }
     }
 
@@ -167,10 +167,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
         uint64_t md_size, md_addr;
 
         md_addr = mdc->get_addr(md);
-        md_size = mdc->get_region_size(md);
-        if (*errp) {
-            goto out;
-        }
+        md_size = mdc->get_region_size(md, &error_abort);
 
         if (ranges_overlap(md_addr, md_size, new_addr, size)) {
             if (hint) {
@@ -234,7 +231,7 @@ static int memory_device_plugged_size(Object *obj, void *opaque)
         const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj);
 
         if (dev->realized) {
-            *size += mdc->get_plugged_size(md);
+            *size += mdc->get_plugged_size(md, &error_abort);
         }
     }
 
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index f46fb7ada2..130f78d0de 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -234,14 +234,15 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
     return dimm->addr;
 }
 
-static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md)
+static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
+                                           Error **errp)
 {
     /* dropping const here is fine as we don't touch the memory region */
     PCDIMMDevice *dimm = PC_DIMM(md);
     const PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(md);
     MemoryRegion *mr;
 
-    mr = ddc->get_memory_region(dimm, &error_abort);
+    mr = ddc->get_memory_region(dimm, errp);
     if (!mr) {
         return 0;
     }
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 2853b084b5..f02b229837 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -33,8 +33,8 @@ typedef struct MemoryDeviceClass {
     InterfaceClass parent_class;
 
     uint64_t (*get_addr)(const MemoryDeviceState *md);
-    uint64_t (*get_plugged_size)(const MemoryDeviceState *md);
-    uint64_t (*get_region_size)(const MemoryDeviceState *md);
+    uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
+    uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
     void (*fill_device_info)(const MemoryDeviceState *md,
                              MemoryDeviceInfo *info);
 } MemoryDeviceClass;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 08/16] memory-device: document MemoryDeviceClass
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (6 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 07/16] memory-device: forward errors in get_region_size()/get_plugged_size() David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 09/16] memory-device: add and use memory_device_get_region_size() David Hildenbrand
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

Document the functions. Don't document get_region_size(), as we will be
dropping/replacing that one soon.

Use same documentation style as in include/exec/memory.h, but don't
document the parameters, as they are self-explanatory.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 include/hw/mem/memory-device.h | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index f02b229837..0474a3dd11 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -29,12 +29,48 @@ typedef struct MemoryDeviceState {
     Object parent_obj;
 } MemoryDeviceState;
 
+/**
+ * MemoryDeviceClass:
+ *
+ * All memory devices need to implement TYPE_MEMORY_DEVICE as an interface.
+ *
+ * A memory device is a device that owns a memory region which is
+ * mapped into guest physical address space at a certain address. The
+ * address in guest physical memory can either be specified explicitly
+ * or get assigned automatically.
+ */
 typedef struct MemoryDeviceClass {
+    /* private */
     InterfaceClass parent_class;
 
+    /*
+     * Return the address of the memory device in guest physical memory.
+     *
+     * Called when (un)plugging a memory device or when iterating over
+     * all memory devices mapped into guest physical address space.
+     *
+     * If "0" is returned, no address has been specified by the user and
+     * no address has been assigned to this memory device yet.
+     */
     uint64_t (*get_addr)(const MemoryDeviceState *md);
+
+    /*
+     * Return the amount of memory provided by the memory device currently
+     * usable ("plugged") by the VM.
+     *
+     * Called when calculating the total amount of ram available to the
+     * VM (e.g. to report memory stats to the user).
+     *
+     * This is helpful for devices that dynamically manage the amount of
+     * memory accessible by the guest via the reserved memory region. For
+     * most devices, this corresponds to the size of the memory region.
+     */
     uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
     uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
+
+    /*
+     * Translate the memory device into #MemoryDeviceInfo.
+     */
     void (*fill_device_info)(const MemoryDeviceState *md,
                              MemoryDeviceInfo *info);
 } MemoryDeviceClass;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 09/16] memory-device: add and use memory_device_get_region_size()
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (7 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 08/16] memory-device: document MemoryDeviceClass David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 10/16] memory-device: factor out get_memory_region() from pc-dimm David Hildenbrand
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

We will factor out get_memory_region() from pc-dimm to memory device code
soon. Once that is done, get_region_size() can be implemented
generically and essentially be replaced by
memory_device_get_region_size (and work only on get_memory_region()).

We have some users of get_memory_region() (spapr and pc-dimm code) that are
only interested in the size. So let's rework them to use
memory_device_get_region_size() first, then we can factor out
get_memory_region() and eventually remove get_region_size() without
touching the same code multiple times.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c         | 13 ++++++++++---
 hw/mem/pc-dimm.c               | 10 ++++------
 hw/ppc/spapr.c                 | 21 +++++++--------------
 include/hw/mem/memory-device.h |  2 ++
 4 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index c1e1b81cf2..425830c65c 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -57,10 +57,9 @@ static int memory_device_used_region_size(Object *obj, void *opaque)
     if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) {
         const DeviceState *dev = DEVICE(obj);
         const MemoryDeviceState *md = MEMORY_DEVICE(obj);
-        const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj);
 
         if (dev->realized) {
-            *size += mdc->get_region_size(md, &error_abort);
+            *size += memory_device_get_region_size(md, &error_abort);
         }
     }
 
@@ -167,7 +166,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
         uint64_t md_size, md_addr;
 
         md_addr = mdc->get_addr(md);
-        md_size = mdc->get_region_size(md, &error_abort);
+        md_size = memory_device_get_region_size(md, &error_abort);
 
         if (ranges_overlap(md_addr, md_size, new_addr, size)) {
             if (hint) {
@@ -266,6 +265,14 @@ void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr)
     memory_region_del_subregion(&ms->device_memory->mr, mr);
 }
 
+uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
+                                       Error **errp)
+{
+    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+
+    return mdc->get_region_size(md, errp);
+}
+
 static const TypeInfo memory_device_info = {
     .name          = TYPE_MEMORY_DEVICE,
     .parent        = TYPE_INTERFACE,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 130f78d0de..3e43ec8742 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -161,16 +161,14 @@ static Property pc_dimm_properties[] = {
 static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name,
                              void *opaque, Error **errp)
 {
+    Error *local_err = NULL;
     uint64_t value;
-    MemoryRegion *mr;
-    PCDIMMDevice *dimm = PC_DIMM(obj);
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(obj);
 
-    mr = ddc->get_memory_region(dimm, errp);
-    if (!mr) {
+    value = memory_device_get_region_size(MEMORY_DEVICE(obj), &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
         return;
     }
-    value = memory_region_size(mr);
 
     visit_type_uint64(v, name, &value, errp);
 }
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index c078347b66..c08130facb 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3128,12 +3128,10 @@ static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     Error *local_err = NULL;
     sPAPRMachineState *ms = SPAPR_MACHINE(hotplug_dev);
     PCDIMMDevice *dimm = PC_DIMM(dev);
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-    MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
     uint64_t size, addr;
     uint32_t node;
 
-    size = memory_region_size(mr);
+    size = memory_device_get_region_size(MEMORY_DEVICE(dev), &error_abort);
 
     pc_dimm_plug(dimm, MACHINE(ms), &local_err);
     if (local_err) {
@@ -3169,9 +3167,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     const sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(hotplug_dev);
     sPAPRMachineState *spapr = SPAPR_MACHINE(hotplug_dev);
     PCDIMMDevice *dimm = PC_DIMM(dev);
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
     Error *local_err = NULL;
-    MemoryRegion *mr;
     uint64_t size;
     Object *memdev;
     hwaddr pagesize;
@@ -3181,11 +3177,11 @@ static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
-    mr = ddc->get_memory_region(dimm, errp);
-    if (!mr) {
+    size = memory_device_get_region_size(MEMORY_DEVICE(dimm), &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
         return;
     }
-    size = memory_region_size(mr);
 
     if (size % SPAPR_MEMORY_BLOCK_SIZE) {
         error_setg(errp, "Hotplugged memory size must be a multiple of "
@@ -3257,9 +3253,8 @@ static sPAPRDIMMState *spapr_recover_pending_dimm_state(sPAPRMachineState *ms,
                                                         PCDIMMDevice *dimm)
 {
     sPAPRDRConnector *drc;
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-    MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
-    uint64_t size = memory_region_size(mr);
+    uint64_t size = memory_device_get_region_size(MEMORY_DEVICE(dimm),
+                                                  &error_abort);
     uint32_t nr_lmbs = size / SPAPR_MEMORY_BLOCK_SIZE;
     uint32_t avail_lmbs = 0;
     uint64_t addr_start, addr;
@@ -3325,14 +3320,12 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
     sPAPRMachineState *spapr = SPAPR_MACHINE(hotplug_dev);
     Error *local_err = NULL;
     PCDIMMDevice *dimm = PC_DIMM(dev);
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-    MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
     uint32_t nr_lmbs;
     uint64_t size, addr_start, addr;
     int i;
     sPAPRDRConnector *drc;
 
-    size = memory_region_size(mr);
+    size = memory_device_get_region_size(MEMORY_DEVICE(dimm), &error_abort);
     nr_lmbs = size / SPAPR_MEMORY_BLOCK_SIZE;
 
     addr_start = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 0474a3dd11..898df3057d 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -83,5 +83,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
 void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
                                uint64_t addr);
 void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
+uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
+                                       Error **errp);
 
 #endif
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 10/16] memory-device: factor out get_memory_region() from pc-dimm
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (8 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 09/16] memory-device: add and use memory_device_get_region_size() David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 11/16] memory-device: drop get_region_size() David Hildenbrand
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

The memory region is necessary for plugging/unplugging a memory device.
The region size (via get_region_size()) is no longer sufficient, as
besides the alignment, also the region itself is required in order to
add it to the device memory region of the machine via
- memory_region_add_subregion
- memory_region_del_subregion

So, to factor out plugging/unplugging of memory devices from pc-dimm
code, we have to factor out access to the memory region first.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/nvdimm.c                |  9 ++++++---
 hw/mem/pc-dimm.c               | 27 ++++++++++++++++++---------
 include/hw/mem/memory-device.h | 15 +++++++++++++++
 include/hw/mem/pc-dimm.h       |  4 ----
 4 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index 1c6674c4ed..49324f3fae 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -27,6 +27,7 @@
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "hw/mem/nvdimm.h"
+#include "hw/mem/memory-device.h"
 
 static void nvdimm_get_label_size(Object *obj, Visitor *v, const char *name,
                                   void *opaque, Error **errp)
@@ -118,9 +119,10 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice *nvdimm, Error **errp)
     nvdimm->nvdimm_mr->align = align;
 }
 
-static MemoryRegion *nvdimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)
+static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md,
+                                                 Error **errp)
 {
-    NVDIMMDevice *nvdimm = NVDIMM(dimm);
+    NVDIMMDevice *nvdimm = NVDIMM(md);
     Error *local_err = NULL;
 
     if (!nvdimm->nvdimm_mr) {
@@ -190,11 +192,12 @@ static Property nvdimm_properties[] = {
 static void nvdimm_class_init(ObjectClass *oc, void *data)
 {
     PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
+    MemoryDeviceClass *mdc = MEMORY_DEVICE_CLASS(oc);
     NVDIMMClass *nvc = NVDIMM_CLASS(oc);
     DeviceClass *dc = DEVICE_CLASS(oc);
 
     ddc->realize = nvdimm_realize;
-    ddc->get_memory_region = nvdimm_get_memory_region;
+    mdc->get_memory_region = nvdimm_md_get_memory_region;
     dc->props = nvdimm_properties;
 
     nvc->read_label_data = nvdimm_read_label_data;
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 3e43ec8742..c9f6ad589e 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -32,7 +32,7 @@ static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
 void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
                       const uint64_t *legacy_align, Error **errp)
 {
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
     Error *local_err = NULL;
     MemoryRegion *mr;
     uint64_t addr, align;
@@ -49,7 +49,7 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
                             &error_abort);
     trace_mhp_pc_dimm_assigned_slot(slot);
 
-    mr = ddc->get_memory_region(dimm, &local_err);
+    mr = mdc->get_memory_region(MEMORY_DEVICE(dimm), &local_err);
     if (local_err) {
         goto out;
     }
@@ -72,9 +72,11 @@ out:
 void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
 {
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
     MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
                                                               &error_abort);
-    MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
+    MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dimm),
+                                              &error_abort);
     uint64_t addr;
 
     addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
@@ -87,9 +89,11 @@ void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
 void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine)
 {
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
     MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
                                                               &error_abort);
-    MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
+    MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dimm),
+                                              &error_abort);
 
     memory_device_unplug_region(machine, mr);
     vmstate_unregister_ram(vmstate_mr, DEVICE(dimm));
@@ -235,12 +239,11 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
 static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
                                            Error **errp)
 {
-    /* dropping const here is fine as we don't touch the memory region */
-    PCDIMMDevice *dimm = PC_DIMM(md);
-    const PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(md);
+    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
     MemoryRegion *mr;
 
-    mr = ddc->get_memory_region(dimm, errp);
+    /* dropping const here is fine as we don't touch the memory region */
+    mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
     if (!mr) {
         return 0;
     }
@@ -248,6 +251,12 @@ static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
     return memory_region_size(mr);
 }
 
+static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
+                                                  Error **errp)
+{
+    return pc_dimm_get_memory_region(PC_DIMM(md), errp);
+}
+
 static void pc_dimm_md_fill_device_info(const MemoryDeviceState *md,
                                         MemoryDeviceInfo *info)
 {
@@ -289,13 +298,13 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
     dc->props = pc_dimm_properties;
     dc->desc = "DIMM memory module";
 
-    ddc->get_memory_region = pc_dimm_get_memory_region;
     ddc->get_vmstate_memory_region = pc_dimm_get_memory_region;
 
     mdc->get_addr = pc_dimm_md_get_addr;
     /* for a dimm plugged_size == region_size */
     mdc->get_plugged_size = pc_dimm_md_get_region_size;
     mdc->get_region_size = pc_dimm_md_get_region_size;
+    mdc->get_memory_region = pc_dimm_md_get_memory_region;
     mdc->fill_device_info = pc_dimm_md_fill_device_info;
 }
 
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 898df3057d..659f38385c 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -38,6 +38,11 @@ typedef struct MemoryDeviceState {
  * mapped into guest physical address space at a certain address. The
  * address in guest physical memory can either be specified explicitly
  * or get assigned automatically.
+ *
+ * Conceptually, memory devices only span one memory region. If multiple
+ * successive memory regions are used, a covering memory region has to
+ * be provided. Scattered memory regions are not supported for single
+ * devices.
  */
 typedef struct MemoryDeviceClass {
     /* private */
@@ -68,6 +73,16 @@ typedef struct MemoryDeviceClass {
     uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
     uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
 
+    /*
+     * Return the memory region of the memory device.
+     *
+     * Called when (un)plugging the memory device, to (un)map the
+     * memory region in guest physical memory, but also to detect the
+     * required alignment during address assignment or when the size of the
+     * memory region is required.
+     */
+    MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp);
+
     /*
      * Translate the memory device into #MemoryDeviceInfo.
      */
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 99cbd54de7..01436b9f50 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -61,9 +61,6 @@ typedef struct PCDIMMDevice {
  * PCDIMMDeviceClass:
  * @realize: called after common dimm is realized so that the dimm based
  * devices get the chance to do specified operations.
- * @get_memory_region: returns #MemoryRegion associated with @dimm which
- * is directly mapped into the physical address space of guest. Will not
- * fail after the device was realized.
  * @get_vmstate_memory_region: returns #MemoryRegion which indicates the
  * memory of @dimm should be kept during live migration. Will not fail
  * after the device was realized.
@@ -74,7 +71,6 @@ typedef struct PCDIMMDeviceClass {
 
     /* public */
     void (*realize)(PCDIMMDevice *dimm, Error **errp);
-    MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm, Error **errp);
     MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm,
                                                Error **errp);
 } PCDIMMDeviceClass;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 11/16] memory-device: drop get_region_size()
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (9 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 10/16] memory-device: factor out get_memory_region() from pc-dimm David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 12/16] memory-device: add device class function set_addr() David Hildenbrand
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

There are no remaining users of get_region_size() except
memory_device_get_region_size() itself. We can make
memory_device_get_region_size() work directly on get_memory_region()
instead and drop get_region_size().

In addition, we can now use memory_device_get_region_size() in pc-dimm
code to implement get_plugged_size()"

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c         | 11 +++++++++--
 hw/mem/pc-dimm.c               | 18 +-----------------
 include/hw/mem/memory-device.h |  1 -
 3 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 425830c65c..07749bab69 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -268,9 +268,16 @@ void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr)
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
                                        Error **errp)
 {
-    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+    MemoryRegion *mr;
 
-    return mdc->get_region_size(md, errp);
+    /* dropping const here is fine as we don't touch the memory region */
+    mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
+    if (!mr) {
+        return 0;
+    }
+
+    return memory_region_size(mr);
 }
 
 static const TypeInfo memory_device_info = {
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index c9f6ad589e..47b2e83389 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -236,21 +236,6 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
     return dimm->addr;
 }
 
-static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
-                                           Error **errp)
-{
-    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
-    MemoryRegion *mr;
-
-    /* dropping const here is fine as we don't touch the memory region */
-    mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
-    if (!mr) {
-        return 0;
-    }
-
-    return memory_region_size(mr);
-}
-
 static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
                                                   Error **errp)
 {
@@ -302,8 +287,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
 
     mdc->get_addr = pc_dimm_md_get_addr;
     /* for a dimm plugged_size == region_size */
-    mdc->get_plugged_size = pc_dimm_md_get_region_size;
-    mdc->get_region_size = pc_dimm_md_get_region_size;
+    mdc->get_plugged_size = memory_device_get_region_size;
     mdc->get_memory_region = pc_dimm_md_get_memory_region;
     mdc->fill_device_info = pc_dimm_md_fill_device_info;
 }
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 659f38385c..9c3398bc4a 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -71,7 +71,6 @@ typedef struct MemoryDeviceClass {
      * most devices, this corresponds to the size of the memory region.
      */
     uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
-    uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
 
     /*
      * Return the memory region of the memory device.
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 12/16] memory-device: add device class function set_addr()
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (10 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 11/16] memory-device: drop get_region_size() David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 13/16] memory-device: complete factoring out pre_plug handling David Hildenbrand
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

To be able to factor out address assignment of memory devices, we will
have to read (get_addr()) and write (set_addr()) the address.

We can't use properties for this purpose, as properties are device
specific. E.g. while the address property for a DIMM is called "addr", it
might be called differently (e.g. "memaddr") for other devices.

Especially virtio based memory devices cannot use "addr" as that is already
reserved and used for the address on the bus (for the proxy device).

Also, it might be possible to have memory devices without address
properties (e.g. internal DIMM-like thingies).

In contrast to get_addr(), we expect that set_addr() can fail.

Keep it simple for now for pc-dimm and simply set the static property, that
will fail once realized.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/pc-dimm.c               | 7 +++++++
 include/hw/mem/memory-device.h | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 47b2e83389..4a15091734 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -236,6 +236,12 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
     return dimm->addr;
 }
 
+static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr,
+                                Error **errp)
+{
+    object_property_set_uint(OBJECT(md), addr, PC_DIMM_ADDR_PROP, errp);
+}
+
 static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
                                                   Error **errp)
 {
@@ -286,6 +292,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
     ddc->get_vmstate_memory_region = pc_dimm_get_memory_region;
 
     mdc->get_addr = pc_dimm_md_get_addr;
+    mdc->set_addr = pc_dimm_md_set_addr;
     /* for a dimm plugged_size == region_size */
     mdc->get_plugged_size = memory_device_get_region_size;
     mdc->get_memory_region = pc_dimm_md_get_memory_region;
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 9c3398bc4a..ed7cf5bf4b 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -59,6 +59,14 @@ typedef struct MemoryDeviceClass {
      */
     uint64_t (*get_addr)(const MemoryDeviceState *md);
 
+    /*
+     * Set the address of the memory device in guest physical memory.
+     *
+     * Called when plugging the memory device to configure the determined
+     * address in guest physical memory.
+     */
+    void (*set_addr)(MemoryDeviceState *md, uint64_t addr, Error **errp);
+
     /*
      * Return the amount of memory provided by the memory device currently
      * usable ("plugged") by the VM.
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 13/16] memory-device: complete factoring out pre_plug handling
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (11 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 12/16] memory-device: add device class function set_addr() David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 14/16] memory-device: complete factoring out plug handling David Hildenbrand
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

With all required memory device class functions in place, we can factor
out pre_plug handling of memory devices. Take proper care of errors. We
still have to carry along legacy_align required for pc compatibility
handling.

We will factor out tracing of the address separately in a follow-up
patch.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c         | 32 +++++++++++++++++++++++++++++---
 hw/mem/pc-dimm.c               | 15 +++------------
 include/hw/mem/memory-device.h |  5 ++---
 3 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 07749bab69..aa4ddd5918 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -93,9 +93,10 @@ static void memory_device_check_addable(MachineState *ms, uint64_t size,
 
 }
 
-uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
-                                     uint64_t align, uint64_t size,
-                                     Error **errp)
+static uint64_t memory_device_get_free_addr(MachineState *ms,
+                                            const uint64_t *hint,
+                                            uint64_t align, uint64_t size,
+                                            Error **errp)
 {
     uint64_t address_space_start, address_space_end;
     GSList *list = NULL, *item;
@@ -247,6 +248,31 @@ uint64_t get_plugged_memory_size(void)
     return size;
 }
 
+void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
+                            const uint64_t *legacy_align, Error **errp)
+{
+    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+    Error *local_err = NULL;
+    uint64_t addr, align;
+    MemoryRegion *mr;
+
+    mr = mdc->get_memory_region(md, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    align = legacy_align ? *legacy_align : memory_region_get_alignment(mr);
+    addr = mdc->get_addr(md);
+    addr = memory_device_get_free_addr(ms, !addr ? NULL : &addr, align,
+                                       memory_region_size(mr), &local_err);
+    if (local_err) {
+        goto out;
+    }
+    mdc->set_addr(md, addr, &local_err);
+out:
+    error_propagate(errp, local_err);
+}
+
 void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
                                uint64_t addr)
 {
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 4a15091734..b2959bcf0e 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -32,10 +32,8 @@ static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
 void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
                       const uint64_t *legacy_align, Error **errp)
 {
-    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
     Error *local_err = NULL;
-    MemoryRegion *mr;
-    uint64_t addr, align;
+    uint64_t addr;
     int slot;
 
     slot = object_property_get_int(OBJECT(dimm), PC_DIMM_SLOT_PROP,
@@ -49,22 +47,15 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
                             &error_abort);
     trace_mhp_pc_dimm_assigned_slot(slot);
 
-    mr = mdc->get_memory_region(MEMORY_DEVICE(dimm), &local_err);
+    memory_device_pre_plug(MEMORY_DEVICE(dimm), machine, legacy_align,
+                           &local_err);
     if (local_err) {
         goto out;
     }
 
-    align = legacy_align ? *legacy_align : memory_region_get_alignment(mr);
     addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
                                     &error_abort);
-    addr = memory_device_get_free_addr(machine, !addr ? NULL : &addr, align,
-                                       memory_region_size(mr), &local_err);
-    if (local_err) {
-        goto out;
-    }
     trace_mhp_pc_dimm_assigned_address(addr);
-    object_property_set_uint(OBJECT(dimm), addr, PC_DIMM_ADDR_PROP,
-                             &error_abort);
 out:
     error_propagate(errp, local_err);
 }
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index ed7cf5bf4b..d92acd2425 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -99,9 +99,8 @@ typedef struct MemoryDeviceClass {
 
 MemoryDeviceInfoList *qmp_memory_device_list(void);
 uint64_t get_plugged_memory_size(void);
-uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
-                                     uint64_t align, uint64_t size,
-                                     Error **errp);
+void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
+                            const uint64_t *legacy_align, Error **errp);
 void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
                                uint64_t addr);
 void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 14/16] memory-device: complete factoring out plug handling
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (12 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 13/16] memory-device: complete factoring out pre_plug handling David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 15/16] memory-device: complete factoring out unplug handling David Hildenbrand
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

With the new memory device functions in place, we can factor out
plugging of memory devices completely.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c         | 13 ++++++++++---
 hw/mem/pc-dimm.c               |  9 +--------
 include/hw/mem/memory-device.h |  3 +--
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index aa4ddd5918..6569896b7e 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -273,10 +273,17 @@ out:
     error_propagate(errp, local_err);
 }
 
-void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
-                               uint64_t addr)
+void memory_device_plug(MemoryDeviceState *md, MachineState *ms)
 {
-    /* we expect a previous call to memory_device_get_free_addr() */
+    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+    const uint64_t addr = mdc->get_addr(md);
+    MemoryRegion *mr;
+
+    /*
+     * We expect that a previous call to memory_device_pre_plug() succeeded, so
+     * it can't fail at this point.
+     */
+    mr = mdc->get_memory_region(md, &error_abort);
     g_assert(ms->device_memory);
 
     memory_region_add_subregion(&ms->device_memory->mr,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index b2959bcf0e..647841bcd4 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -63,17 +63,10 @@ out:
 void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
 {
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
     MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
                                                               &error_abort);
-    MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dimm),
-                                              &error_abort);
-    uint64_t addr;
-
-    addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
-                                    &error_abort);
 
-    memory_device_plug_region(machine, mr, addr);
+    memory_device_plug(MEMORY_DEVICE(dimm), machine);
     vmstate_register_ram(vmstate_mr, DEVICE(dimm));
 }
 
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index d92acd2425..53d89dac89 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -101,8 +101,7 @@ MemoryDeviceInfoList *qmp_memory_device_list(void);
 uint64_t get_plugged_memory_size(void);
 void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
                             const uint64_t *legacy_align, Error **errp);
-void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
-                               uint64_t addr);
+void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
 void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
                                        Error **errp);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 15/16] memory-device: complete factoring out unplug handling
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (13 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 14/16] memory-device: complete factoring out plug handling David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 16/16] memory-device: trace when pre_plugging/plugging/unplugging David Hildenbrand
  2018-10-09  9:32 ` [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

With the new memory device functions in place, we can factor out
unplugging of memory devices completely.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c         | 11 +++++++++--
 hw/mem/pc-dimm.c               |  5 +----
 include/hw/mem/memory-device.h |  2 +-
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 6569896b7e..30585d6148 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -290,9 +290,16 @@ void memory_device_plug(MemoryDeviceState *md, MachineState *ms)
                                 addr - ms->device_memory->base, mr);
 }
 
-void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr)
+void memory_device_unplug(MemoryDeviceState *md, MachineState *ms)
 {
-    /* we expect a previous call to memory_device_get_free_addr() */
+    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+    MemoryRegion *mr;
+
+    /*
+     * We expect that a previous call to memory_device_pre_plug() succeeded, so
+     * it can't fail at this point.
+     */
+    mr = mdc->get_memory_region(md, &error_abort);
     g_assert(ms->device_memory);
 
     memory_region_del_subregion(&ms->device_memory->mr, mr);
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 647841bcd4..6c854139a7 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -73,13 +73,10 @@ void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
 void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine)
 {
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
     MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
                                                               &error_abort);
-    MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dimm),
-                                              &error_abort);
 
-    memory_device_unplug_region(machine, mr);
+    memory_device_unplug(MEMORY_DEVICE(dimm), machine);
     vmstate_unregister_ram(vmstate_mr, DEVICE(dimm));
 }
 
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 53d89dac89..e904e194d5 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -102,7 +102,7 @@ uint64_t get_plugged_memory_size(void);
 void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
                             const uint64_t *legacy_align, Error **errp);
 void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
-void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
+void memory_device_unplug(MemoryDeviceState *md, MachineState *ms);
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
                                        Error **errp);
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [Qemu-devel] [PATCH v5 16/16] memory-device: trace when pre_plugging/plugging/unplugging
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (14 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 15/16] memory-device: complete factoring out unplug handling David Hildenbrand
@ 2018-10-05  9:20 ` David Hildenbrand
  2018-10-09  9:32 ` [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
  16 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2018-10-05  9:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric, David Hildenbrand

Let's trace the address and the id of a memory device when
pre_plugging/plugging/unplugging succeeded.

Trace it when pre_plugging as well as when plugging, so we really know
when a specific address is actually used.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c | 8 ++++++++
 hw/mem/pc-dimm.c       | 8 --------
 hw/mem/trace-events    | 5 ++++-
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 30585d6148..7de1ccd497 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -17,6 +17,7 @@
 #include "qemu/range.h"
 #include "hw/virtio/vhost.h"
 #include "sysemu/kvm.h"
+#include "trace.h"
 
 static gint memory_device_addr_sort(gconstpointer a, gconstpointer b)
 {
@@ -269,6 +270,10 @@ void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
         goto out;
     }
     mdc->set_addr(md, addr, &local_err);
+    if (!local_err) {
+        trace_memory_device_pre_plug(DEVICE(md)->id ? DEVICE(md)->id : "",
+                                     addr);
+    }
 out:
     error_propagate(errp, local_err);
 }
@@ -288,6 +293,7 @@ void memory_device_plug(MemoryDeviceState *md, MachineState *ms)
 
     memory_region_add_subregion(&ms->device_memory->mr,
                                 addr - ms->device_memory->base, mr);
+    trace_memory_device_plug(DEVICE(md)->id ? DEVICE(md)->id : "", addr);
 }
 
 void memory_device_unplug(MemoryDeviceState *md, MachineState *ms)
@@ -303,6 +309,8 @@ void memory_device_unplug(MemoryDeviceState *md, MachineState *ms)
     g_assert(ms->device_memory);
 
     memory_region_del_subregion(&ms->device_memory->mr, mr);
+    trace_memory_device_unplug(DEVICE(md)->id ? DEVICE(md)->id : "",
+                               mdc->get_addr(md));
 }
 
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 6c854139a7..0c9b9e8292 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -33,7 +33,6 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
                       const uint64_t *legacy_align, Error **errp)
 {
     Error *local_err = NULL;
-    uint64_t addr;
     int slot;
 
     slot = object_property_get_int(OBJECT(dimm), PC_DIMM_SLOT_PROP,
@@ -49,13 +48,6 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
 
     memory_device_pre_plug(MEMORY_DEVICE(dimm), machine, legacy_align,
                            &local_err);
-    if (local_err) {
-        goto out;
-    }
-
-    addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
-                                    &error_abort);
-    trace_mhp_pc_dimm_assigned_address(addr);
 out:
     error_propagate(errp, local_err);
 }
diff --git a/hw/mem/trace-events b/hw/mem/trace-events
index e150dcc497..0f2f278ff2 100644
--- a/hw/mem/trace-events
+++ b/hw/mem/trace-events
@@ -2,4 +2,7 @@
 
 # hw/mem/pc-dimm.c
 mhp_pc_dimm_assigned_slot(int slot) "%d"
-mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
+# hw/mem/memory-device.c
+memory_device_pre_plug(const char *id, uint64_t addr) "id=%s addr=0x%"PRIx64
+memory_device_plug(const char *id, uint64_t addr) "id=%s addr=0x%"PRIx64
+memory_device_unplug(const char *id, uint64_t addr) "id=%s addr=0x%"PRIx64
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [PATCH v5 03/16] memory-device: improve "range conflicts" error message
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 03/16] memory-device: improve "range conflicts" error message David Hildenbrand
@ 2018-10-08  2:05   ` David Gibson
  2018-10-09 10:59   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 21+ messages in thread
From: David Gibson @ 2018-10-08  2:05 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, qemu-ppc, Dr . David Alan Gilbert,
	Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Paolo Bonzini, Richard Henderson, Eduardo Habkost, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	Alexander Graf, Auger Eric

[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]

On Fri, Oct 05, 2018 at 11:20:11AM +0200, David Hildenbrand wrote:
> Handle id==NULL better and indicate that we are dealing with memory
> devices.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  hw/mem/memory-device.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
> index 7c706fadfc..0624184c40 100644
> --- a/hw/mem/memory-device.c
> +++ b/hw/mem/memory-device.c
> @@ -175,7 +175,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
>          if (ranges_overlap(md_addr, md_size, new_addr, size)) {
>              if (hint) {
>                  const DeviceState *d = DEVICE(md);
> -                error_setg(errp, "address range conflicts with '%s'", d->id);
> +                error_setg(errp, "address range conflicts with memory device"
> +                           " id='%s'", d->id ? d->id : "(unnamed)");
>                  goto out;
>              }
>              new_addr = QEMU_ALIGN_UP(md_addr + md_size, align);

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring
  2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
                   ` (15 preceding siblings ...)
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 16/16] memory-device: trace when pre_plugging/plugging/unplugging David Hildenbrand
@ 2018-10-09  9:32 ` David Hildenbrand
  2018-10-11 17:44   ` Eduardo Habkost
  16 siblings, 1 reply; 21+ messages in thread
From: David Hildenbrand @ 2018-10-09  9:32 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini, Eduardo Habkost
  Cc: qemu-ppc, Dr . David Alan Gilbert, Michael S . Tsirkin,
	Igor Mammedov, Marcel Apfelbaum, Richard Henderson, Eric Blake,
	Markus Armbruster, Pankaj Gupta, Luiz Capitulino, Xiao Guangrong,
	David Gibson, Alexander Graf, Auger Eric

On 05/10/2018 11:20, David Hildenbrand wrote:
> This series completes refactoring of pre_plug, plug and unplug logic of
> memory devices. With this as a basis, we can built e.g. virtio
> based memory devices or internal "RAM chip" devices.
> 
> I dropped the virtio-pmem prototype for now, I will look into plugging
> it differently next. But this part in this series here is independent of
> hotplug handler changes required to make it work for virtio devices.
> 
> v4 -> v5:
> - Added a bunch of RB's
> - Minor spelling fixed
> - Dropped "memory-device: add class function get_device_id()"
> - Added   "memory-device: improve "range conflicts" error message
> - Dropped "memory-device: handle integer overflows properly"
> -- Will require more changes. But I am able to reproduce some overflows.
> - "memory-device: document MemoryDeviceClass"
> -- Changed documentation format as requested by Auger
> - "memory-device: trace when pre_plugging/plugging/unplugging"
> -- Include device ID and rename tracepoints.

@Paolo, @Eduardo this seems to be ready to get picked up. Thanks!


-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [PATCH v5 03/16] memory-device: improve "range conflicts" error message
  2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 03/16] memory-device: improve "range conflicts" error message David Hildenbrand
  2018-10-08  2:05   ` David Gibson
@ 2018-10-09 10:59   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 21+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-09 10:59 UTC (permalink / raw)
  To: David Hildenbrand, qemu-devel
  Cc: Pankaj Gupta, Eduardo Habkost, Michael S . Tsirkin,
	Xiao Guangrong, Dr . David Alan Gilbert, Markus Armbruster,
	Auger Eric, Alexander Graf, qemu-ppc, Paolo Bonzini,
	Igor Mammedov, Luiz Capitulino, David Gibson, Richard Henderson

On 05/10/2018 11:20, David Hildenbrand wrote:
> Handle id==NULL better and indicate that we are dealing with memory
> devices.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  hw/mem/memory-device.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
> index 7c706fadfc..0624184c40 100644
> --- a/hw/mem/memory-device.c
> +++ b/hw/mem/memory-device.c
> @@ -175,7 +175,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
>          if (ranges_overlap(md_addr, md_size, new_addr, size)) {
>              if (hint) {
>                  const DeviceState *d = DEVICE(md);
> -                error_setg(errp, "address range conflicts with '%s'", d->id);
> +                error_setg(errp, "address range conflicts with memory device"
> +                           " id='%s'", d->id ? d->id : "(unnamed)");
>                  goto out;
>              }
>              new_addr = QEMU_ALIGN_UP(md_addr + md_size, align);
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring
  2018-10-09  9:32 ` [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
@ 2018-10-11 17:44   ` Eduardo Habkost
  0 siblings, 0 replies; 21+ messages in thread
From: Eduardo Habkost @ 2018-10-11 17:44 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Paolo Bonzini, Pankaj Gupta, Xiao Guangrong,
	Michael S . Tsirkin, Dr . David Alan Gilbert, Markus Armbruster,
	Auger Eric, Alexander Graf, qemu-ppc, Igor Mammedov,
	Luiz Capitulino, David Gibson, Richard Henderson

On Tue, Oct 09, 2018 at 11:32:32AM +0200, David Hildenbrand wrote:
> On 05/10/2018 11:20, David Hildenbrand wrote:
> > This series completes refactoring of pre_plug, plug and unplug logic of
> > memory devices. With this as a basis, we can built e.g. virtio
> > based memory devices or internal "RAM chip" devices.
> > 
> > I dropped the virtio-pmem prototype for now, I will look into plugging
> > it differently next. But this part in this series here is independent of
> > hotplug handler changes required to make it work for virtio devices.
> > 
> > v4 -> v5:
> > - Added a bunch of RB's
> > - Minor spelling fixed
> > - Dropped "memory-device: add class function get_device_id()"
> > - Added   "memory-device: improve "range conflicts" error message
> > - Dropped "memory-device: handle integer overflows properly"
> > -- Will require more changes. But I am able to reproduce some overflows.
> > - "memory-device: document MemoryDeviceClass"
> > -- Changed documentation format as requested by Auger
> > - "memory-device: trace when pre_plugging/plugging/unplugging"
> > -- Include device ID and rename tracepoints.
> 
> @Paolo, @Eduardo this seems to be ready to get picked up. Thanks!

Queued on machine-next, thanks!

-- 
Eduardo

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2018-10-11 17:44 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-05  9:20 [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 01/16] memory-device: fix alignment error message David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 02/16] memory-device: fix error message when hinted address is too small David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 03/16] memory-device: improve "range conflicts" error message David Hildenbrand
2018-10-08  2:05   ` David Gibson
2018-10-09 10:59   ` Philippe Mathieu-Daudé
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 04/16] pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 05/16] memory-device: use memory device terminology in error messages David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 06/16] memory-device: introduce separate config option David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 07/16] memory-device: forward errors in get_region_size()/get_plugged_size() David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 08/16] memory-device: document MemoryDeviceClass David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 09/16] memory-device: add and use memory_device_get_region_size() David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 10/16] memory-device: factor out get_memory_region() from pc-dimm David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 11/16] memory-device: drop get_region_size() David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 12/16] memory-device: add device class function set_addr() David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 13/16] memory-device: complete factoring out pre_plug handling David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 14/16] memory-device: complete factoring out plug handling David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 15/16] memory-device: complete factoring out unplug handling David Hildenbrand
2018-10-05  9:20 ` [Qemu-devel] [PATCH v5 16/16] memory-device: trace when pre_plugging/plugging/unplugging David Hildenbrand
2018-10-09  9:32 ` [Qemu-devel] [PATCH v5 00/16] memory-device: complete refactoring David Hildenbrand
2018-10-11 17:44   ` Eduardo Habkost

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.