Skip to contentSkip to conversation

PCDIMM cleanup

PATCH Superseded Wei Yang 4 participants 11 messages Feb 19, 2019 – Feb 22, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

cover PCDIMM cleanup

Two trivial cleanup for pc-dimm.

Patch [1] remove the check on class->hotpluggable since pc-dimm is always hotpluggable.
Patch [2] remove realized callback since the task is done in pre_plug stage.

Wei Yang (2):
pc-dimm: remove check on pc-dimm hotpluggable
pc-dimm: remove realize callback

 hw/acpi/memory_hotplug.c |  5 -----
 hw/mem/nvdimm.c          | 11 -----------
 hw/mem/pc-dimm.c         |  5 -----
 include/hw/mem/pc-dimm.h |  3 ---
 4 files changed, 24 deletions(-)
Signature · 1 line
2.19.1
author
#1 lore raw

PATCH 1/2 pc-dimm: remove check on pc-dimm hotpluggable

Function acpi_memory_plug_cb() is only invoked when dev is a PCDIMM, which is hotpluggable. This means it is not necessary to check this property again.

This patch removes this check.

---
 hw/acpi/memory_hotplug.c | 4 ----
 1 file changed, 4 deletions(-)
hw/acpi/memory_hotplug.c +0 -4
index 8c7c1013f3..b19673d337 100644
@@ -266,10 +266,6 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,
     MemStatus *mdev;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (!dc->hotpluggable) {
-        return;
-    }
-
     mdev = acpi_memory_slot_status(mem_st, dev, errp);
     if (!mdev) {
         return;
Signature · 1 line
2.19.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] pc-dimm: remove check on pc-dimm hotpluggable

hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,

Quoted 16 lines · Wei Yang

Function acpi_memory_plug_cb() is only invoked when dev is a PCDIMM, which is hotpluggable. This means it is not necessary to check this property again.

This patch removes this check.

---
 hw/acpi/memory_hotplug.c | 4 ----
 1 file changed, 4 deletions(-)
hw/acpi/memory_hotplug.c +0 -0
index 8c7c1013f3..b19673d337 100644
@@ -266,10 +266,6 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,

This is also obvious because it takes a HotplugHandler argument.

Quoted 11 lines
hw/acpi/memory_hotplug.c +0 -4
     MemStatus *mdev;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (!dc->hotpluggable) {
-        return;
-    }
-
     mdev = acpi_memory_slot_status(mem_st, dev, errp);
     if (!mdev) {
         return;
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] pc-dimm: remove check on pc-dimm hotpluggable

Quoted 12 lines · On Tue, 19 Feb 2019 13:26:47 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 11 lines · Wei Yang

Function acpi_memory_plug_cb() is only invoked when dev is a PCDIMM, which is hotpluggable. This means it is not necessary to check this property again.

This patch removes this check.

---
 hw/acpi/memory_hotplug.c | 4 ----
 1 file changed, 4 deletions(-)
Quoted 7 lines

hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,

Quoted 5 lines
hw/acpi/memory_hotplug.c +0 -0
index 8c7c1013f3..b19673d337 100644
@@ -266,10 +266,6 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,  

This is also obvious because it takes a HotplugHandler argument.

                                          ^^^^

that's a sort of atavism, handler also takes care of coldplug wiring nowdays. (it's just nobody came up with new name and fixed it up)

Quoted 15 lines
Quoted 11 lines
hw/acpi/memory_hotplug.c +0 -4
     MemStatus *mdev;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (!dc->hotpluggable) {
-        return;
-    }
-
     mdev = acpi_memory_slot_status(mem_st, dev, errp);
     if (!mdev) {
         return;
Tested-by on v1 1/2
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] pc-dimm: remove check on pc-dimm hotpluggable

In reply to Wei Yang
Quoted 16 lines · Wei Yang

Function acpi_memory_plug_cb() is only invoked when dev is a PCDIMM, which is hotpluggable. This means it is not necessary to check this property again.

This patch removes this check.

---
 hw/acpi/memory_hotplug.c | 4 ----
 1 file changed, 4 deletions(-)
hw/acpi/memory_hotplug.c +0 -0
index 8c7c1013f3..b19673d337 100644

hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, · line 267

Quoted 2 lines
hw/acpi/memory_hotplug.c +0 -0
@@ -266,10 +266,6 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,
     MemStatus *mdev;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);

You have to remove the 'dc' variable now:

CC hw/acpi/memory_hotplug.o
hw/acpi/memory_hotplug.c: In function ‘acpi_memory_plug_cb’:
hw/acpi/memory_hotplug.c:267:18: error: unused variable ‘dc’ [-Werror=unused-variable]

     DeviceClass *dc = DEVICE_GET_CLASS(dev);
                  ^~

Once removed:

Quoted 9 lines
hw/acpi/memory_hotplug.c +0 -4
-    if (!dc->hotpluggable) {
-        return;
-    }
-
     mdev = acpi_memory_slot_status(mem_st, dev, errp);
     if (!mdev) {
         return;
 
#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] pc-dimm: remove check on pc-dimm hotpluggable

Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Wei Yang

Function acpi_memory_plug_cb() is only invoked when dev is a PCDIMM, which is hotpluggable. This means it is not necessary to check this property again.

This patch removes this check.

---
 hw/acpi/memory_hotplug.c | 4 ----
 1 file changed, 4 deletions(-)
hw/acpi/memory_hotplug.c +0 -0
index 8c7c1013f3..b19673d337 100644

hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, · line 267

Quoted 2 lines
hw/acpi/memory_hotplug.c +0 -0
@@ -266,10 +266,6 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,
     MemStatus *mdev;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);

You have to remove the 'dc' variable now:

Quoted 6 lines

CC hw/acpi/memory_hotplug.o
hw/acpi/memory_hotplug.c: In function ‘acpi_memory_plug_cb’:
hw/acpi/memory_hotplug.c:267:18: error: unused variable ‘dc’ [-Werror=unused-variable]

    DeviceClass *dc = DEVICE_GET_CLASS(dev);
                 ^~

Thanks, I didn't notice this warning.

Quoted 13 lines

Once removed:

Quoted 9 lines
hw/acpi/memory_hotplug.c +0 -4
-    if (!dc->hotpluggable) {
-        return;
-    }
-
     mdev = acpi_memory_slot_status(mem_st, dev, errp);
     if (!mdev) {
         return;
 
Signature · 2 lines
Wei Yang
Help you, Help me
author
#6 lore raw

PATCH 2/2 pc-dimm: remove realize callback

In reply to Wei Yang

PCDIMM's realize callback is introduced to do proper setup for NVDIMM.

Currently the NVDIMM setup task is nvdimm_prepare_memory_region(), which is done in pre_plug stage. This means related task has already been done at realize point.

This patch remove PCDIMM realize callback.

---
 hw/acpi/memory_hotplug.c |  1 -
 hw/mem/nvdimm.c          | 11 -----------
 hw/mem/pc-dimm.c         |  5 -----
 include/hw/mem/pc-dimm.h |  3 ---
 4 files changed, 20 deletions(-)
hw/acpi/memory_hotplug.c +0 -1
index b19673d337..cb5284d36f 100644
@@ -264,7 +264,6 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,
                          DeviceState *dev, Error **errp)
 {
     MemStatus *mdev;
-    DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
     mdev = acpi_memory_slot_status(mem_st, dev, errp);
     if (!mdev) {
hw/mem/nvdimm.c +0 -11
index bf2adf5e16..8f69576926 100644
@@ -136,15 +136,6 @@ static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md,
     return nvdimm->nvdimm_mr;
 }
 
-static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp)
-{
-    NVDIMMDevice *nvdimm = NVDIMM(dimm);
-
-    if (!nvdimm->nvdimm_mr) {
-        nvdimm_prepare_memory_region(nvdimm, errp);
-    }
-}
-
 /*
  * the caller should check the input parameters before calling
  * label read/write functions.
@@ -192,12 +183,10 @@ 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;
     mdc->get_memory_region = nvdimm_md_get_memory_region;
     dc->props = nvdimm_properties;
 
hw/mem/pc-dimm.c +0 -5
index 152400b1fc..5832c0ba92 100644
@@ -159,7 +159,6 @@ static void pc_dimm_init(Object *obj)
 static void pc_dimm_realize(DeviceState *dev, Error **errp)
 {
     PCDIMMDevice *dimm = PC_DIMM(dev);
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
 
     if (!dimm->hostmem) {
         error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set");
@@ -178,10 +177,6 @@ static void pc_dimm_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (ddc->realize) {
-        ddc->realize(dimm, errp);
-    }
-
     host_memory_backend_set_mapped(dimm->hostmem, true);
 }
 
include/hw/mem/pc-dimm.h +0 -3
index 01436b9f50..d18f8246b7 100644
@@ -59,8 +59,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_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.
@@ -70,7 +68,6 @@ typedef struct PCDIMMDeviceClass {
     DeviceClass parent_class;
 
     /* public */
-    void (*realize)(PCDIMMDevice *dimm, Error **errp);
     MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm,
                                                Error **errp);
 } PCDIMMDeviceClass;
Signature · 1 line
2.19.1
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] pc-dimm: remove realize callback

Quoted 21 lines · Wei Yang

PCDIMM's realize callback is introduced to do proper setup for NVDIMM.

Currently the NVDIMM setup task is nvdimm_prepare_memory_region(), which is done in pre_plug stage. This means related task has already been done at realize point.

This patch remove PCDIMM realize callback.

---
 hw/acpi/memory_hotplug.c |  1 -
 hw/mem/nvdimm.c          | 11 -----------
 hw/mem/pc-dimm.c         |  5 -----
 include/hw/mem/pc-dimm.h |  3 ---
 4 files changed, 20 deletions(-)
hw/acpi/memory_hotplug.c +0 -0
index b19673d337..cb5284d36f 100644

hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, · line 267

Quoted 4 lines
hw/acpi/memory_hotplug.c +0 -1
@@ -264,7 +264,6 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,
                          DeviceState *dev, Error **errp)
 {
     MemStatus *mdev;
-    DeviceClass *dc = DEVICE_GET_CLASS(dev);

OK now I see the leftover of patch #1.

Quoted 26 lines
hw/acpi/memory_hotplug.c +0 -0
     mdev = acpi_memory_slot_status(mem_st, dev, errp);
     if (!mdev) {
hw/mem/nvdimm.c +0 -9
index bf2adf5e16..8f69576926 100644
@@ -136,15 +136,6 @@ static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md,
     return nvdimm->nvdimm_mr;
 }
 
-static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp)
-{
-    NVDIMMDevice *nvdimm = NVDIMM(dimm);
-
-    if (!nvdimm->nvdimm_mr) {
-        nvdimm_prepare_memory_region(nvdimm, errp);
-    }
-}
-
 /*
  * the caller should check the input parameters before calling
  * label read/write functions.
@@ -192,12 +183,10 @@ static Property nvdimm_properties[] = {
 
 static void nvdimm_class_init(ObjectClass *oc, void *data)

hw/mem/nvdimm.c static Property nvdimm_properties[] = { · line 192

Quoted 10 lines
hw/mem/nvdimm.c +0 -2
 {
-    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;
     mdc->get_memory_region = nvdimm_md_get_memory_region;
     dc->props = nvdimm_properties;
 

I'd split your patch in 2:
- the previous part, cleaning NVDIMM,
- the part below, doing "git revert 9f318f8f7e6" and improving the commit description.

Quoted 45 lines
hw/mem/pc-dimm.c +0 -5
index 152400b1fc..5832c0ba92 100644
@@ -159,7 +159,6 @@ static void pc_dimm_init(Object *obj)
 static void pc_dimm_realize(DeviceState *dev, Error **errp)
 {
     PCDIMMDevice *dimm = PC_DIMM(dev);
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
 
     if (!dimm->hostmem) {
         error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set");
@@ -178,10 +177,6 @@ static void pc_dimm_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (ddc->realize) {
-        ddc->realize(dimm, errp);
-    }
-
     host_memory_backend_set_mapped(dimm->hostmem, true);
 }
 
include/hw/mem/pc-dimm.h +0 -3
index 01436b9f50..d18f8246b7 100644
@@ -59,8 +59,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_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.
@@ -70,7 +68,6 @@ typedef struct PCDIMMDeviceClass {
     DeviceClass parent_class;
 
     /* public */
-    void (*realize)(PCDIMMDevice *dimm, Error **errp);
     MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm,
                                                Error **errp);
 } PCDIMMDeviceClass;
#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] pc-dimm: remove realize callback

Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Wei Yang

PCDIMM's realize callback is introduced to do proper setup for NVDIMM.

Currently the NVDIMM setup task is nvdimm_prepare_memory_region(), which is done in pre_plug stage. This means related task has already been done at realize point.

This patch remove PCDIMM realize callback.

---
 hw/acpi/memory_hotplug.c |  1 -
 hw/mem/nvdimm.c          | 11 -----------
 hw/mem/pc-dimm.c         |  5 -----
 include/hw/mem/pc-dimm.h |  3 ---
 4 files changed, 20 deletions(-)
Quoted 12 lines

hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, · line 267

Quoted 9 lines
hw/acpi/memory_hotplug.c +0 -1
index b19673d337..cb5284d36f 100644
@@ -264,7 +264,6 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,
                          DeviceState *dev, Error **errp)
 {
     MemStatus *mdev;
-    DeviceClass *dc = DEVICE_GET_CLASS(dev);

OK now I see the leftover of patch #1.

Ah, I should move this in patch #1.

Thanks.

Quoted 32 lines
Quoted 32 lines
hw/acpi/memory_hotplug.c +0 -0
     mdev = acpi_memory_slot_status(mem_st, dev, errp);
     if (!mdev) {
hw/mem/nvdimm.c +0 -10
index bf2adf5e16..8f69576926 100644
@@ -136,15 +136,6 @@ static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md,
     return nvdimm->nvdimm_mr;
 }
 
-static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp)
-{
-    NVDIMMDevice *nvdimm = NVDIMM(dimm);
-
-    if (!nvdimm->nvdimm_mr) {
-        nvdimm_prepare_memory_region(nvdimm, errp);
-    }
-}
-
 /*
  * the caller should check the input parameters before calling
  * label read/write functions.
@@ -192,12 +183,10 @@ 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);
 
Quoted 10 lines

hw/mem/nvdimm.c static Property nvdimm_properties[] = { · line 192

Quoted 4 lines
hw/mem/nvdimm.c +0 -1
-    ddc->realize = nvdimm_realize;
     mdc->get_memory_region = nvdimm_md_get_memory_region;
     dc->props = nvdimm_properties;
 

I'd split your patch in 2:
- the previous part, cleaning NVDIMM,
- the part below, doing "git revert 9f318f8f7e6" and improving the commit description.

Sounds reasonable. Let me split this into two.

Quoted 45 lines
Quoted 45 lines
hw/mem/pc-dimm.c +0 -5
index 152400b1fc..5832c0ba92 100644
@@ -159,7 +159,6 @@ static void pc_dimm_init(Object *obj)
 static void pc_dimm_realize(DeviceState *dev, Error **errp)
 {
     PCDIMMDevice *dimm = PC_DIMM(dev);
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
 
     if (!dimm->hostmem) {
         error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set");
@@ -178,10 +177,6 @@ static void pc_dimm_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (ddc->realize) {
-        ddc->realize(dimm, errp);
-    }
-
     host_memory_backend_set_mapped(dimm->hostmem, true);
 }
 
include/hw/mem/pc-dimm.h +0 -3
index 01436b9f50..d18f8246b7 100644
@@ -59,8 +59,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_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.
@@ -70,7 +68,6 @@ typedef struct PCDIMMDeviceClass {
     DeviceClass parent_class;
 
     /* public */
-    void (*realize)(PCDIMMDevice *dimm, Error **errp);
     MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm,
                                                Error **errp);
 } PCDIMMDeviceClass;
Signature · 2 lines
Wei Yang
Help you, Help me
#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] pc-dimm: remove realize callback

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · On Tue, 19 Feb 2019 13:36:57 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 7 lines · Wei Yang

PCDIMM's realize callback is introduced to do proper setup for NVDIMM.

Currently the NVDIMM setup task is nvdimm_prepare_memory_region(), which is done in pre_plug stage. This means related task has already been done at realize point.

This patch remove PCDIMM realize callback.

pre_plug is machine helper and that it calls nvdimm_prepare_memory_region() indirectly is just of side effect of current nvdimm impl. Another machine might choose to implement it's own pre_plug to use with nvdimms, in which case it might not call the function before realize, hence this patch makes nvdimm device model incomplete and less robust.

Pls drop this patch

Quoted 107 lines
Quoted 13 lines
---
 hw/acpi/memory_hotplug.c |  1 -
 hw/mem/nvdimm.c          | 11 -----------
 hw/mem/pc-dimm.c         |  5 -----
 include/hw/mem/pc-dimm.h |  3 ---
 4 files changed, 20 deletions(-)
hw/acpi/memory_hotplug.c +0 -0
index b19673d337..cb5284d36f 100644

hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, · line 267

Quoted 4 lines
hw/acpi/memory_hotplug.c +0 -1
@@ -264,7 +264,6 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st,
                          DeviceState *dev, Error **errp)
 {
     MemStatus *mdev;
-    DeviceClass *dc = DEVICE_GET_CLASS(dev);  

OK now I see the leftover of patch #1.

Quoted 26 lines
hw/acpi/memory_hotplug.c +0 -0
     mdev = acpi_memory_slot_status(mem_st, dev, errp);
     if (!mdev) {
hw/mem/nvdimm.c +0 -9
index bf2adf5e16..8f69576926 100644
@@ -136,15 +136,6 @@ static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md,
     return nvdimm->nvdimm_mr;
 }
 
-static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp)
-{
-    NVDIMMDevice *nvdimm = NVDIMM(dimm);
-
-    if (!nvdimm->nvdimm_mr) {
-        nvdimm_prepare_memory_region(nvdimm, errp);
-    }
-}
-
 /*
  * the caller should check the input parameters before calling
  * label read/write functions.
@@ -192,12 +183,10 @@ static Property nvdimm_properties[] = {
 
 static void nvdimm_class_init(ObjectClass *oc, void *data)

hw/mem/nvdimm.c static Property nvdimm_properties[] = { · line 192

Quoted 10 lines
hw/mem/nvdimm.c +0 -2
 {
-    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;
     mdc->get_memory_region = nvdimm_md_get_memory_region;
     dc->props = nvdimm_properties;
 

I'd split your patch in 2:
- the previous part, cleaning NVDIMM,
- the part below, doing "git revert 9f318f8f7e6" and improving the commit description.

Quoted 45 lines
hw/mem/pc-dimm.c +0 -5
index 152400b1fc..5832c0ba92 100644
@@ -159,7 +159,6 @@ static void pc_dimm_init(Object *obj)
 static void pc_dimm_realize(DeviceState *dev, Error **errp)
 {
     PCDIMMDevice *dimm = PC_DIMM(dev);
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
 
     if (!dimm->hostmem) {
         error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set");
@@ -178,10 +177,6 @@ static void pc_dimm_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (ddc->realize) {
-        ddc->realize(dimm, errp);
-    }
-
     host_memory_backend_set_mapped(dimm->hostmem, true);
 }
 
include/hw/mem/pc-dimm.h +0 -3
index 01436b9f50..d18f8246b7 100644
@@ -59,8 +59,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_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.
@@ -70,7 +68,6 @@ typedef struct PCDIMMDeviceClass {
     DeviceClass parent_class;
 
     /* public */
-    void (*realize)(PCDIMMDevice *dimm, Error **errp);
     MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm,
                                                Error **errp);
 } PCDIMMDeviceClass;
author
#10 lore raw

Re: [Qemu-devel] [PATCH 2/2] pc-dimm: remove realize callback

Quoted 10 lines · Igor Mammedov
Quoted 7 lines · On Tue, 19 Feb 2019 13:36:57 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 6 lines · Wei Yang

PCDIMM's realize callback is introduced to do proper setup for NVDIMM.

Currently the NVDIMM setup task is nvdimm_prepare_memory_region(), which is done in pre_plug stage. This means related task has already been done at realize point.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

This patch remove PCDIMM realize callback.

pre_plug is machine helper and that it calls nvdimm_prepare_memory_region() indirectly is just of side effect of current nvdimm impl. Another machine might choose to implement it's own pre_plug to use with nvdimms, in which case it might not call the function before realize, hence this patch makes nvdimm device model incomplete and less robust.

Sounds reasonable.

Call nvdimm_prepare_memory_region() two times is really ugly. Hmm... could we improve this?

Signature · 2 lines
Wei Yang
Help you, Help me