hw/ipmi: Don't call vmstate_register() from instance_init() functions
PATCH 1/1 hw/ipmi: Don't call vmstate_register() from instance_init() functions
instance_init() can be called multiple times, e.g. during introspection of the device. We should not install the vmstate handlers here. Do it in the realize() function instead.
--- hw/ipmi/ipmi_bmc_extern.c | 29 +++++++++++------------ hw/ipmi/isa_ipmi_bt.c | 34 +++++++++++++-------------- hw/ipmi/isa_ipmi_kcs.c | 48 +++++++++++++++++++-------------------- 3 files changed, 56 insertions(+), 55 deletions(-)
hw/ipmi/ipmi_bmc_extern.c +15 -14
@@ -453,19 +453,6 @@ static void ipmi_bmc_extern_handle_reset(IPMIBmc *b)continue_send (ibe); } -static void ipmi_bmc_extern_realize (DeviceState *dev,Error **errp) -{ -IPMIBmcExtern *ibe =IPMI_BMC_EXTERN (dev); - -if (!qemu_chr_fe_backend_connected (&ibe->chr)) { -error_setg (errp,"IPMI external bmc requires chardev attribute" ); -return ; - } - -qemu_chr_fe_set_handlers (&ibe->chr, can_receive, receive, - chr_event,NULL , ibe,NULL , true); -} -static int ipmi_bmc_extern_post_migrate (void *opaque,int version_id) {IPMIBmcExtern *ibe = opaque;
@@ -499,12 +486,26 @@ static const VMStateDescription vmstate_ipmi_bmc_extern = { } }; +static void ipmi_bmc_extern_realize (DeviceState *dev,Error **errp) +{ +IPMIBmcExtern *ibe =IPMI_BMC_EXTERN (dev); + +if (!qemu_chr_fe_backend_connected (&ibe->chr)) { +error_setg (errp,"IPMI external bmc requires chardev attribute" ); +return ; + } + +qemu_chr_fe_set_handlers (&ibe->chr, can_receive, receive, + chr_event,NULL , ibe,NULL , true); + +vmstate_register (NULL ,0 , &vmstate_ipmi_bmc_extern, ibe); +} +static void ipmi_bmc_extern_init (Object *obj) {IPMIBmcExtern *ibe =IPMI_BMC_EXTERN (obj); ibe->extern_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , extern_timeout, ibe); -vmstate_register (NULL ,0 , &vmstate_ipmi_bmc_extern, ibe); }static void ipmi_bmc_extern_finalize (Object *obj)
hw/ipmi/isa_ipmi_bt.c +17 -17
@@ -68,6 +68,21 @@ static void isa_ipmi_bt_lower_irq(IPMIBT *ib)qemu_irq_lower (iib->irq); } +static const VMStateDescription vmstate_ISAIPMIBTDevice = { + .name =TYPE_IPMI_INTERFACE_PREFIX "isa-bt" , + .version_id =2 , + .minimum_version_id =2 , +/* +* Version 1 had messed up the array transfer, it's not even usable +* because it used VMSTATE_VBUFFER_UINT32, but it did not transfer +* the buffer length, so random things would happen. +*/ + .fields = (VMStateField []) { +VMSTATE_STRUCT (bt, ISAIPMIBTDevice,1 , vmstate_IPMIBT,IPMIBT ), +VMSTATE_END_OF_LIST () + } +}; +static void isa_ipmi_bt_realize (DeviceState *dev,Error **errp) {Error *err =NULL ;
@@ -102,30 +117,15 @@ static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)qdev_set_legacy_instance_id (dev, iib->bt.io_base, iib->bt.io_length);isa_register_ioport (isadev, &iib->bt.io, iib->bt.io_base); -} -static const VMStateDescription vmstate_ISAIPMIBTDevice = { - .name =TYPE_IPMI_INTERFACE_PREFIX "isa-bt" , - .version_id =2 , - .minimum_version_id =2 , -/* -* Version 1 had messed up the array transfer, it's not even usable -* because it used VMSTATE_VBUFFER_UINT32, but it did not transfer -* the buffer length, so random things would happen. -*/ - .fields = (VMStateField []) { -VMSTATE_STRUCT (bt, ISAIPMIBTDevice,1 , vmstate_IPMIBT,IPMIBT ), -VMSTATE_END_OF_LIST () - } -}; +vmstate_register (NULL ,0 , &vmstate_ISAIPMIBTDevice, dev); +}static void isa_ipmi_bt_init (Object *obj) {ISAIPMIBTDevice *iib =ISA_IPMI_BT (obj);ipmi_bmc_find_and_link (obj, (Object **) &iib->bt.bmc); - -vmstate_register (NULL ,0 , &vmstate_ISAIPMIBTDevice, iib); }static void *isa_ipmi_bt_get_backend_data (IPMIInterface *ii)
hw/ipmi/isa_ipmi_kcs.c +24 -24
68 lines not on this page · raw message
Signature · 1 line
2.41.0
Quoted 5 lines · Thomas Huth
instance_init()can be called multiple times, e.g. during introspection of the device. We should not install the vmstate handlers here. Do it in therealize()function instead.Signed-off-by Thomas Huth <[email protected]>
It fixes my issues.
Should I take this through the Migration tree?
Corey Minyard
Acked-byQuoted 5 lines · Juan Quintela
Quoted 4 lines · Thomas Huth
instance_init()can be called multiple times, e.g. during introspection of the device. We should not install the vmstate handlers here. Do it in therealize()function instead.
Quoted 7 lines
Quoted 1 line
Signed-off-by Thomas Huth <[email protected]>Reviewed-by Juan Quintela <[email protected]>It fixes my issues.
Should I take this through the Migration tree?
That's fine with me.