migration/ppc: migrating DRC and ccs_list
v10 cover migration/ppc: migrating DRC and ccs_list
v10:
- removed 'migrating pending_events' patch this series
- patch 1:
* removed extra line between definitions;
* removed spapr_pending_dimms functions definitons from spapr.h
* turned spapr_pending_dimms functions into static
- patch 2:
* fixed the switch() statement - PHB and VIO cases goes to default,
default now executes assert()
- patch 3:
* minor style changes/fixes
* changed switch default to execute assert() and now uses the same
logic for both CPU and LMB DRCs
- patch 4 (*new*):
* this new patch implements a new function to recover the pending DIMM
unplug LMB state inside the spapr_lmb_release callback
v9:
- patch 1 (*new*): added a qtail in sPAPRMachineState called pending_dimm_unplugs that stores the DIMM LMB state during the unplug process.
- patch 2 (*new*): merged v8-patch1 and v8-patch2: removing detach_cb and detach_cb_opaque.
- patch 3:
* removed dk->vmsd entry. We're using vmstate_register instead
* added 'awaiting_allocation' flag in the DRC migration
- patch 4 (*new*): migrating spapr->pending_dimm_unplugs qtailq to allow for an ongoing PCDIMM unplug to continue after a migration.
v8:
- new patch added: 'removing spapr_drc_detach_cb opaques'. This new patch removes the need for the detach_cb_opaques inside the removal callback functions. See the commit message of the patch for more info.
v7:
- removed the first patch. DRC registration is now done by vmstate_register in patch 2.
- added a new patch that changes spapr_dr_connector_new to receive as argument the detach_cb.
- removed the callback logic of patch 2 since there is no need to restore the detach_cb on post-load due to the detach_cb on spapr_dr_connector_new change.
- added word separators in the VMSD names of patch 3 and 4.
v6: - Rebased with QEMU master after 6+ months.
- Simplified the logic in patch 1.
- Reworked patch 2: added CPU DRC migration, removed a function pointer from DRC
class and minor improvements.
- Added clarifications from the previous v5 discussions in the commit messages.
v5: - Rebased to David's ppc-for-2.8.
v4: - Introduce a way to set customized instance_id in SaveStateEntry. Use it
to set instance_id for DRC using its unique index to address David Gibson's concern.
- Rename VMS_CSTM to VMS_LINKED based on Paolo Bonzini's suggestions.
- Clean up qjson stuff in put_qtailq.
- Add trace for put_qtailq and get_qtailq based on David Gilbert's suggestion.
- Based on David's ppc-for-2.7.
v3: - Simplify overall design followng discussion with Paolo. No longer need
metadata to migrate QTAILQ.
- Extend VMStateInfo instead of adding similar fields to VMStateField.
- Clean up macros in qemu/queue.h.
(link: https://lists.nongnu.org/archive/html/qemu-devel/2016-05/msg05695.html)
v2: - Introduce a general approach to migrate QTAILQ in qemu/queue.h.
- Migrate signalled field in the DRC state.
- Put the newly added migrating fields in subsections so that backward migration is not broken.
- Set detach_cb field right after migration so that a migrated hot-unplug event could finish its course.
(link: https://lists.nongnu.org/archive/html/qemu-devel/2016-05/msg04188.html)
v1: - Inital version.
(link: https://lists.nongnu.org/archive/html/qemu-devel/2016-04/msg02601.html)
To make guest devices (PCI, CPU and memory) hotplug work together with guest migration, spapr drc state needs be transmitted in migration. This patch defines the VMStateDescription struct for spapr drc state to enable it.
To fix the potential racing between hotplug events on guest and guest migration and ccs_list of spapr state need be transmitted in migration. This patch set also takes care of it.
Daniel Henrique Barboza (4):
hw/ppc/spapr.c: adding pending_dimm_unplugs to sPAPRMachineState hw/ppc: removing drc->detach_cb and drc->detach_cb_opaque hw/ppc: migrating the DRC state of hotplugged devices hw/ppc/spapr.c: recover pending LMB unplug info in spapr_lmb_release
Jianjun Duan (1):
migration: spapr: migrate ccs_list in spapr state
hw/ppc/spapr.c | 138 ++++++++++++++++++++++++++++++++++++++++---- hw/ppc/spapr_drc.c | 88 +++++++++++++++++++++++----- hw/ppc/spapr_pci.c | 5 +- include/hw/pci-host/spapr.h | 3 + include/hw/ppc/spapr.h | 8 +++ include/hw/ppc/spapr_drc.h | 8 +-- 6 files changed, 215 insertions(+), 35 deletions(-)
Signature · 1 line
2.9.4
PATCH RESEND v10 1/5 hw/ppc/spapr.c: adding pending_dimm_unplugs to sPAPRMachineState
The LMB DRC release callback, spapr_lmb_release(), uses an opaque parameter, a sPAPRDIMMState struct that stores the current LMBs that are allocated to a DIMM (nr_lmbs). After each call to this callback, the nr_lmbs is decremented by one and, when it reaches zero, the callback proceeds with the qdev calls to hot unplug the LMB.
Using drc->detach_cb_opaque is problematic because it can't be migrated in the future DRC migration work. This patch makes the following changes to eliminate the usage of this opaque callback inside spapr_lmb_release:
- sPAPRDIMMState was moved from spapr.c and added to spapr.h. A new attribute called 'addr' was added to it. This is used as an unique identifier to associate a sPAPRDIMMState to a PCDIMM element.
- sPAPRMachineState now hosts a new QTAILQ called 'pending_dimm_unplugs'. This queue of sPAPRDIMMState elements will store the DIMM state of DIMMs that are currently going under an unplug process.
- spapr_lmb_release() will now retrieve the nr_lmbs value by getting the correspondent sPAPRDIMMState. A helper function called spapr_dimm_get_address was created to fetch the address of a PCDIMM device inside spapr_lmb_release. When nr_lmbs reaches zero and the callback proceeds with the qdev hot unplug calls, the sPAPRDIMMState struct is removed from spapr->pending_dimm_unplugs.
After these changes, the opaque argument for spapr_lmb_release is now unused and is passed as NULL inside spapr_del_lmbs. This and the other opaque arguments can now be safely removed from the code.
--- hw/ppc/spapr.c | 57 +++++++++++++++++++++++++++++++++++++++++++++----- include/hw/ppc/spapr.h | 4 ++++ 2 files changed, 56 insertions(+), 5 deletions(-)
hw/ppc/spapr.c +52 -5
@@ -2050,6 +2050,7 @@ static void ppc_spapr_init(MachineState *machine) msi_nonbroken = true;QLIST_INIT (&spapr->phbs); +QTAILQ_INIT (&spapr->pending_dimm_unplugs);/* Allocate RMA if necessary */ rma_alloc_size =kvmppc_alloc_rma (&rma);
@@ -2603,20 +2604,63 @@ out:error_propagate (errp, local_err); } -typedef struct sPAPRDIMMState { +struct sPAPRDIMMState { +uint64_t addr;uint32_t nr_lmbs; -}sPAPRDIMMState ; +QTAILQ_ENTRY (sPAPRDIMMState) next; +}; + +static sPAPRDIMMState *spapr_pending_dimm_unplugs_find (sPAPRMachineState *s, +uint64_t addr) +{ +sPAPRDIMMState *dimm_state =NULL ; + QTAILQ_FOREACH(dimm_state, &s->pending_dimm_unplugs, next) { +if (dimm_state->addr == addr) { +break ; + } + } +return dimm_state; +} + +static void spapr_pending_dimm_unplugs_add (sPAPRMachineState *spapr, +sPAPRDIMMState *dimm_state) +{ +g_assert (!spapr_pending_dimm_unplugs_find (spapr, dimm_state->addr)); +QTAILQ_INSERT_HEAD (&spapr->pending_dimm_unplugs, dimm_state, next); +} + +static void spapr_pending_dimm_unplugs_remove (sPAPRMachineState *spapr, +sPAPRDIMMState *dimm_state) +{ +QTAILQ_REMOVE (&spapr->pending_dimm_unplugs, dimm_state, next); +g_free (dimm_state); +} + +static uint64_t spapr_dimm_get_address (PCDIMMDevice *dimm) +{ +Error *local_err =NULL ; +uint64_t addr; + addr =object_property_get_int (OBJECT (dimm),PC_DIMM_ADDR_PROP , + &local_err); +if (local_err) { +error_propagate (&error_abort, local_err); +return 0 ; + } +return addr; +}static void spapr_lmb_release (DeviceState *dev,void *opaque) { -sPAPRDIMMState *ds = (sPAPRDIMMState *)opaque;HotplugHandler *hotplug_ctrl; +uint64_t addr =spapr_dimm_get_address (PC_DIMM (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRDIMMState *ds =spapr_pending_dimm_unplugs_find (spapr, addr);if (--ds->nr_lmbs) {return ; } -g_free (ds); +spapr_pending_dimm_unplugs_remove (spapr, ds);/* * Now that all the LMBs have been removed by the guest, call the
@@ -2633,17 +2677,20 @@ static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size,sPAPRDRConnectorClass *drck;uint32_t nr_lmbs = size /SPAPR_MEMORY_BLOCK_SIZE ;int i; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());sPAPRDIMMState *ds =g_malloc0 (sizeof (sPAPRDIMMState));uint64_t addr = addr_start; ds->nr_lmbs = nr_lmbs; + ds->addr = addr_start; +spapr_pending_dimm_unplugs_add (spapr, ds);for (i =0 ; i < nr_lmbs; i++) { drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_LMB , addr /SPAPR_MEMORY_BLOCK_SIZE );g_assert (drc); drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc, dev, spapr_lmb_release, ds, errp); + drck->detach (drc, dev, spapr_lmb_release,NULL , errp); addr +=SPAPR_MEMORY_BLOCK_SIZE ; }
include/hw/ppc/spapr.h +4 -0
@@ -32,6 +32,7 @@ struct sPAPRRTCState {int64_t ns_offset; }; +typedef struct sPAPRDIMMState sPAPRDIMMState ;typedef struct sPAPRMachineClass sPAPRMachineClass ;#define TYPE_SPAPR_MACHINE "spapr-machine"
@@ -104,6 +105,9 @@ struct sPAPRMachineState {/* RTAS state */ QTAILQ_HEAD(, sPAPRConfigureConnectorState) ccs_list; +/* pending DIMM unplug queue */ + QTAILQ_HEAD(, sPAPRDIMMState) pending_dimm_unplugs; +/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory;
Signature · 1 line
2.9.4
Re: [Qemu-devel] [RESEND PATCH v10 1/5] hw/ppc/spapr.c: adding pending_dimm_unplugs to sPAPRMachineState
Quoted 47 lines · Daniel Henrique Barboza
The LMB DRC release callback,
spapr_lmb_release(), uses an opaque parameter, a sPAPRDIMMState struct that stores the current LMBs that are allocated to a DIMM (nr_lmbs). After each call to this callback, thenr_lmbsis decremented by one and, when it reaches zero, the callback proceeds with the qdev calls to hot unplug the LMB.Using
drc->detach_cb_opaqueis problematic because it can't be migrated in the future DRC migration work. This patch makes the following changes to eliminate the usage of this opaque callback insidespapr_lmb_release:- sPAPRDIMMState was moved from
spapr.cand added tospapr.h. A new attribute called 'addr' was added to it. This is used as an unique identifier to associate a sPAPRDIMMState to a PCDIMM element.- sPAPRMachineState now hosts a new QTAILQ called '
pending_dimm_unplugs'. This queue of sPAPRDIMMState elements will store the DIMM state of DIMMs that are currently going under an unplug process.-
spapr_lmb_release()will now retrieve thenr_lmbsvalue by getting the correspondent sPAPRDIMMState. A helper function calledspapr_dimm_get_addresswas created to fetch the address of a PCDIMM device insidespapr_lmb_release. Whennr_lmbsreaches zero and the callback proceeds with the qdev hot unplug calls, the sPAPRDIMMState struct is removed fromspapr->pending_dimm_unplugs.After these changes, the opaque argument for
spapr_lmb_releaseis now unused and is passed as NULL insidespapr_del_lmbs. This and the other opaque arguments can now be safely removed from the code.Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/ppc/spapr.c | 57 +++++++++++++++++++++++++++++++++++++++++++++----- include/hw/ppc/spapr.h | 4 ++++ 2 files changed, 56 insertions(+), 5 deletions(-)hw/ppc/spapr.c +1
-0@@ -2050,6 +2050,7 @@ static void ppc_spapr_init(MachineState *machine) msi_nonbroken = true;QLIST_INIT (&spapr->phbs); +QTAILQ_INIT (&spapr->pending_dimm_unplugs);/* Allocate RMA if necessary */ rma_alloc_size =kvmppc_alloc_rma (&rma);
hw/ppc/spapr.c out: · line 2608
Quoted 6 lines
hw/ppc/spapr.c +2
-1@@ -2603,20 +2604,63 @@ out:error_propagate (errp, local_err); } -typedef struct sPAPRDIMMState { +struct sPAPRDIMMState { +uint64_t addr;
Since you're not trying to migrate this any more, you can index the list by an actual PCDIMMDevice *, rather than the base address. You're already passing the DeviceState * for the DIMM around, so this will actually remove the address parameter from some functions.
I think that could actually be done as a preliminary cleanup. It also probably makes sense to merge spapr_del_lmbs() with spapr_memory_unplug_request(), they're both very small.
Quoted 40 lines
hw/ppc/spapr.c +38
-1uint32_t nr_lmbs; -} sPAPRDIMMState; +QTAILQ_ENTRY (sPAPRDIMMState) next; +}; + +static sPAPRDIMMState *spapr_pending_dimm_unplugs_find (sPAPRMachineState *s, +uint64_t addr) +{ +sPAPRDIMMState *dimm_state =NULL ; + QTAILQ_FOREACH(dimm_state, &s->pending_dimm_unplugs, next) { +if (dimm_state->addr == addr) { +break ; + } + } +return dimm_state; +} + +static void spapr_pending_dimm_unplugs_add (sPAPRMachineState *spapr, +sPAPRDIMMState *dimm_state) +{ +g_assert (!spapr_pending_dimm_unplugs_find (spapr, dimm_state->addr)); +QTAILQ_INSERT_HEAD (&spapr->pending_dimm_unplugs, dimm_state, next); +} + +static void spapr_pending_dimm_unplugs_remove (sPAPRMachineState *spapr, +sPAPRDIMMState *dimm_state) +{ +QTAILQ_REMOVE (&spapr->pending_dimm_unplugs, dimm_state, next); +g_free (dimm_state); +} + +static uint64_t spapr_dimm_get_address (PCDIMMDevice *dimm) +{ +Error *local_err =NULL ; +uint64_t addr; + addr =object_property_get_int (OBJECT (dimm),PC_DIMM_ADDR_PROP , + &local_err); +if (local_err) { +error_propagate (&error_abort, local_err); +return 0 ;
hw/ppc/spapr.c out: · line 2656
Quoted 10 lines
hw/ppc/spapr.c +5
-1+ } +return addr; +}static void spapr_lmb_release (DeviceState *dev,void *opaque) { -sPAPRDIMMState *ds = (sPAPRDIMMState *)opaque;HotplugHandler *hotplug_ctrl; +uint64_t addr =spapr_dimm_get_address (PC_DIMM (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());
I prefer not to access the machine as a global when possible. I think it's preferable to pass down the spapr object from above - unplug_request() itself can get it from hotplug_dev.
Quoted 46 lines
hw/ppc/spapr.c +6
-2+sPAPRDIMMState *ds =spapr_pending_dimm_unplugs_find (spapr, addr);if (--ds->nr_lmbs) {return ; } -g_free (ds); +spapr_pending_dimm_unplugs_remove (spapr, ds);/* * Now that all the LMBs have been removed by the guest, call the @@ -2633,17 +2677,20 @@ static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size,sPAPRDRConnectorClass *drck;uint32_t nr_lmbs = size /SPAPR_MEMORY_BLOCK_SIZE ;int i; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());sPAPRDIMMState *ds =g_malloc0 (sizeof (sPAPRDIMMState));uint64_t addr = addr_start; ds->nr_lmbs = nr_lmbs; + ds->addr = addr_start; +spapr_pending_dimm_unplugs_add (spapr, ds);for (i =0 ; i < nr_lmbs; i++) { drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_LMB , addr /SPAPR_MEMORY_BLOCK_SIZE );g_assert (drc); drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc, dev, spapr_lmb_release, ds, errp); + drck->detach (drc, dev, spapr_lmb_release,NULL , errp); addr +=SPAPR_MEMORY_BLOCK_SIZE ; }include/hw/ppc/spapr.h +1
-0@@ -32,6 +32,7 @@ struct sPAPRRTCState {int64_t ns_offset; }; +typedef struct sPAPRDIMMState sPAPRDIMMState ;typedef struct sPAPRMachineClass sPAPRMachineClass ;#define TYPE_SPAPR_MACHINE "spapr-machine"
include/hw/ppc/spapr.h struct sPAPRMachineState { · line 108
Quoted 4 lines
include/hw/ppc/spapr.h +1
-0@@ -104,6 +105,9 @@ struct sPAPRMachineState {/* RTAS state */ QTAILQ_HEAD(, sPAPRConfigureConnectorState) ccs_list; +/* pending DIMM unplug queue */
Perhaps update this to mention that it's a cache which can be regenerated when necessary.
Quoted 5 lines
include/hw/ppc/spapr.h +2
-0+ QTAILQ_HEAD(, sPAPRDIMMState) pending_dimm_unplugs; +/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory;
Signature · 4 lines
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
Re: [Qemu-devel] [Qemu-ppc] [RESEND PATCH v10 1/5] hw/ppc/spapr.c: adding pending_dimm_unplugs to sPAPRMachineState
Quoted 51 lines · David Gibson
Quoted 50 lines · Daniel Henrique Barboza
The LMB DRC release callback,
spapr_lmb_release(), uses an opaque parameter, a sPAPRDIMMState struct that stores the current LMBs that are allocated to a DIMM (nr_lmbs). After each call to this callback, thenr_lmbsis decremented by one and, when it reaches zero, the callback proceeds with the qdev calls to hot unplug the LMB.Using
drc->detach_cb_opaqueis problematic because it can't be migrated in the future DRC migration work. This patch makes the following changes to eliminate the usage of this opaque callback insidespapr_lmb_release:- sPAPRDIMMState was moved from
spapr.cand added tospapr.h. A new attribute called 'addr' was added to it. This is used as an unique identifier to associate a sPAPRDIMMState to a PCDIMM element.- sPAPRMachineState now hosts a new QTAILQ called '
pending_dimm_unplugs'. This queue of sPAPRDIMMState elements will store the DIMM state of DIMMs that are currently going under an unplug process.-
spapr_lmb_release()will now retrieve thenr_lmbsvalue by getting the correspondent sPAPRDIMMState. A helper function calledspapr_dimm_get_addresswas created to fetch the address of a PCDIMM device insidespapr_lmb_release. Whennr_lmbsreaches zero and the callback proceeds with the qdev hot unplug calls, the sPAPRDIMMState struct is removed fromspapr->pending_dimm_unplugs.After these changes, the opaque argument for
spapr_lmb_releaseis now unused and is passed as NULL insidespapr_del_lmbs. This and the other opaque arguments can now be safely removed from the code.Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/ppc/spapr.c | 57 +++++++++++++++++++++++++++++++++++++++++++++----- include/hw/ppc/spapr.h | 4 ++++ 2 files changed, 56 insertions(+), 5 deletions(-)hw/ppc/spapr.c +1
-0@@ -2050,6 +2050,7 @@ static void ppc_spapr_init(MachineState *machine) msi_nonbroken = true;QLIST_INIT (&spapr->phbs); +QTAILQ_INIT (&spapr->pending_dimm_unplugs);/* Allocate RMA if necessary */ rma_alloc_size =kvmppc_alloc_rma (&rma);@@ -2603,20 +2604,63 @@ out:error_propagate (errp, local_err); }
Quoted 7 lines
hw/ppc/spapr.c out: · line 2608
Quoted 3 lines
hw/ppc/spapr.c +2
-1-typedef struct sPAPRDIMMState { +struct sPAPRDIMMState { +uint64_t addr;Since you're not trying to migrate this any more, you can index the list by an actual PCDIMMDevice *, rather than the base address. You're already passing the DeviceState * for the DIMM around, so this will actually remove the address parameter from some functions.
Good idea.
Quoted 4 lines
I think that could actually be done as a preliminary cleanup. It also probably makes sense to merge
spapr_del_lmbs()withspapr_memory_unplug_request(), they're both very small.
Ok.
Quoted 46 lines
Quoted 46 lines
hw/ppc/spapr.c +41
-1uint32_t nr_lmbs; -} sPAPRDIMMState; +QTAILQ_ENTRY (sPAPRDIMMState) next; +}; + +static sPAPRDIMMState *spapr_pending_dimm_unplugs_find (sPAPRMachineState *s, +uint64_t addr) +{ +sPAPRDIMMState *dimm_state =NULL ; + QTAILQ_FOREACH(dimm_state, &s->pending_dimm_unplugs, next) { +if (dimm_state->addr == addr) { +break ; + } + } +return dimm_state; +} + +static void spapr_pending_dimm_unplugs_add (sPAPRMachineState *spapr, +sPAPRDIMMState *dimm_state) +{ +g_assert (!spapr_pending_dimm_unplugs_find (spapr, dimm_state->addr)); +QTAILQ_INSERT_HEAD (&spapr->pending_dimm_unplugs, dimm_state, next); +} + +static void spapr_pending_dimm_unplugs_remove (sPAPRMachineState *spapr, +sPAPRDIMMState *dimm_state) +{ +QTAILQ_REMOVE (&spapr->pending_dimm_unplugs, dimm_state, next); +g_free (dimm_state); +} + +static uint64_t spapr_dimm_get_address (PCDIMMDevice *dimm) +{ +Error *local_err =NULL ; +uint64_t addr; + addr =object_property_get_int (OBJECT (dimm),PC_DIMM_ADDR_PROP , + &local_err); +if (local_err) { +error_propagate (&error_abort, local_err); +return 0 ; + } +return addr; +}
Quoted 9 lines
hw/ppc/spapr.c out: · line 2656
Quoted 6 lines
hw/ppc/spapr.c +2
-1static void spapr_lmb_release (DeviceState *dev,void *opaque) { -sPAPRDIMMState *ds = (sPAPRDIMMState *)opaque;HotplugHandler *hotplug_ctrl; +uint64_t addr =spapr_dimm_get_address (PC_DIMM (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());I prefer not to access the machine as a global when possible. I think it's preferable to pass down the spapr object from above -
unplug_request()itself can get it fromhotplug_dev.
I see that we have access to the hotplug_dev (HotplugHandler) in the end of spapr_lmb_release:
hotplug_ctrl = qdev_get_hotplug_handler(dev);
One alternative would be to move this call up in the function and then retrieve the machine as unplug_request() does:
hotplug_ctrl = qdev_get_hotplug_handler(dev);
sPAPRMachineState *ms = SPAPR_MACHINE(hotplug_ctrl);Quoted 45 lines
Quoted 45 lines
hw/ppc/spapr.c +6
-2+sPAPRDIMMState *ds =spapr_pending_dimm_unplugs_find (spapr, addr);if (--ds->nr_lmbs) {return ; } -g_free (ds); +spapr_pending_dimm_unplugs_remove (spapr, ds);/* * Now that all the LMBs have been removed by the guest, call the @@ -2633,17 +2677,20 @@ static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size,sPAPRDRConnectorClass *drck;uint32_t nr_lmbs = size /SPAPR_MEMORY_BLOCK_SIZE ;int i; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());sPAPRDIMMState *ds =g_malloc0 (sizeof (sPAPRDIMMState));uint64_t addr = addr_start; ds->nr_lmbs = nr_lmbs; + ds->addr = addr_start; +spapr_pending_dimm_unplugs_add (spapr, ds);for (i =0 ; i < nr_lmbs; i++) { drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_LMB , addr /SPAPR_MEMORY_BLOCK_SIZE );g_assert (drc); drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc, dev, spapr_lmb_release, ds, errp); + drck->detach (drc, dev, spapr_lmb_release,NULL , errp); addr +=SPAPR_MEMORY_BLOCK_SIZE ; }include/hw/ppc/spapr.h +1
-0@@ -32,6 +32,7 @@ struct sPAPRRTCState {int64_t ns_offset; }; +typedef struct sPAPRDIMMState sPAPRDIMMState ;typedef struct sPAPRMachineClass sPAPRMachineClass ;
Quoted 8 lines
include/hw/ppc/spapr.h struct sPAPRMachineState { · line 108
Quoted 6 lines
include/hw/ppc/spapr.h +1
-0#define TYPE_SPAPR_MACHINE "spapr-machine"@@ -104,6 +105,9 @@ struct sPAPRMachineState {/* RTAS state */ QTAILQ_HEAD(, sPAPRConfigureConnectorState) ccs_list; +/* pending DIMM unplug queue */ Perhaps update this to mention that it's a cache which can be regenerated when necessary.
Ok.
Quoted 6 lines
Quoted 6 lines
include/hw/ppc/spapr.h +2
-0+ QTAILQ_HEAD(, sPAPRDIMMState) pending_dimm_unplugs; +/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory;
Re: [Qemu-devel] [Qemu-ppc] [RESEND PATCH v10 1/5] hw/ppc/spapr.c: adding pending_dimm_unplugs to sPAPRMachineState
Quoted 125 lines · Daniel Henrique Barboza
Quoted 47 lines · David Gibson
Quoted 46 lines · Daniel Henrique Barboza
The LMB DRC release callback,
spapr_lmb_release(), uses an opaque parameter, a sPAPRDIMMState struct that stores the current LMBs that are allocated to a DIMM (nr_lmbs). After each call to this callback, thenr_lmbsis decremented by one and, when it reaches zero, the callback proceeds with the qdev calls to hot unplug the LMB.Using
drc->detach_cb_opaqueis problematic because it can't be migrated in the future DRC migration work. This patch makes the following changes to eliminate the usage of this opaque callback insidespapr_lmb_release:- sPAPRDIMMState was moved from
spapr.cand added tospapr.h. A new attribute called 'addr' was added to it. This is used as an unique identifier to associate a sPAPRDIMMState to a PCDIMM element.- sPAPRMachineState now hosts a new QTAILQ called '
pending_dimm_unplugs'. This queue of sPAPRDIMMState elements will store the DIMM state of DIMMs that are currently going under an unplug process.-
spapr_lmb_release()will now retrieve thenr_lmbsvalue by getting the correspondent sPAPRDIMMState. A helper function calledspapr_dimm_get_addresswas created to fetch the address of a PCDIMM device insidespapr_lmb_release. Whennr_lmbsreaches zero and the callback proceeds with the qdev hot unplug calls, the sPAPRDIMMState struct is removed fromspapr->pending_dimm_unplugs.After these changes, the opaque argument for
spapr_lmb_releaseis now unused and is passed as NULL insidespapr_del_lmbs. This and the other opaque arguments can now be safely removed from the code.Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/ppc/spapr.c | 57 +++++++++++++++++++++++++++++++++++++++++++++----- include/hw/ppc/spapr.h | 4 ++++ 2 files changed, 56 insertions(+), 5 deletions(-)hw/ppc/spapr.c +1
-0@@ -2050,6 +2050,7 @@ static void ppc_spapr_init(MachineState *machine) msi_nonbroken = true;QLIST_INIT (&spapr->phbs); +QTAILQ_INIT (&spapr->pending_dimm_unplugs);/* Allocate RMA if necessary */ rma_alloc_size =kvmppc_alloc_rma (&rma);@@ -2603,20 +2604,63 @@ out:error_propagate (errp, local_err);Quoted 8 lines
hw/ppc/spapr.c out: · line 2608
Quoted 4 lines
hw/ppc/spapr.c +2
-1} -typedef struct sPAPRDIMMState { +struct sPAPRDIMMState { +uint64_t addr;Since you're not trying to migrate this any more, you can index the list by an actual PCDIMMDevice *, rather than the base address. You're already passing the DeviceState * for the DIMM around, so this will actually remove the address parameter from some functions.
Good idea.
Quoted 4 lines
I think that could actually be done as a preliminary cleanup. It also probably makes sense to merge
spapr_del_lmbs()withspapr_memory_unplug_request(), they're both very small.Ok.
Quoted 46 lines
Quoted 46 lines
hw/ppc/spapr.c +41
-1uint32_t nr_lmbs; -} sPAPRDIMMState; +QTAILQ_ENTRY (sPAPRDIMMState) next; +}; + +static sPAPRDIMMState *spapr_pending_dimm_unplugs_find (sPAPRMachineState *s, +uint64_t addr) +{ +sPAPRDIMMState *dimm_state =NULL ; + QTAILQ_FOREACH(dimm_state, &s->pending_dimm_unplugs, next) { +if (dimm_state->addr == addr) { +break ; + } + } +return dimm_state; +} + +static void spapr_pending_dimm_unplugs_add (sPAPRMachineState *spapr, +sPAPRDIMMState *dimm_state) +{ +g_assert (!spapr_pending_dimm_unplugs_find (spapr, dimm_state->addr)); +QTAILQ_INSERT_HEAD (&spapr->pending_dimm_unplugs, dimm_state, next); +} + +static void spapr_pending_dimm_unplugs_remove (sPAPRMachineState *spapr, +sPAPRDIMMState *dimm_state) +{ +QTAILQ_REMOVE (&spapr->pending_dimm_unplugs, dimm_state, next); +g_free (dimm_state); +} + +static uint64_t spapr_dimm_get_address (PCDIMMDevice *dimm) +{ +Error *local_err =NULL ; +uint64_t addr; + addr =object_property_get_int (OBJECT (dimm),PC_DIMM_ADDR_PROP , + &local_err); +if (local_err) { +error_propagate (&error_abort, local_err); +return 0 ; + } +return addr; +}static void spapr_lmb_release (DeviceState *dev,void *opaque)Quoted 8 lines
hw/ppc/spapr.c out: · line 2656
Quoted 5 lines
hw/ppc/spapr.c +2
-1{ -sPAPRDIMMState *ds = (sPAPRDIMMState *)opaque;HotplugHandler *hotplug_ctrl; +uint64_t addr =spapr_dimm_get_address (PC_DIMM (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());I prefer not to access the machine as a global when possible. I think it's preferable to pass down the spapr object from above -
unplug_request()itself can get it fromhotplug_dev.I see that we have access to the
hotplug_dev(HotplugHandler) in the end ofspapr_lmb_release:
Quoted 7 lines
hotplug_ctrl = qdev_get_hotplug_handler(dev);One alternative would be to move this call up in the function and then retrieve the machine as
unplug_request()does:hotplug_ctrl = qdev_get_hotplug_handler(dev); sPAPRMachineState *ms = SPAPR_MACHINE(hotplug_ctrl);
True. That sounds like a good idea.
Quoted 55 lines
Quoted 39 lines
Quoted 39 lines
hw/ppc/spapr.c +6
-2+sPAPRDIMMState *ds =spapr_pending_dimm_unplugs_find (spapr, addr);if (--ds->nr_lmbs) {return ; } -g_free (ds); +spapr_pending_dimm_unplugs_remove (spapr, ds);/* * Now that all the LMBs have been removed by the guest, call the @@ -2633,17 +2677,20 @@ static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size,sPAPRDRConnectorClass *drck;uint32_t nr_lmbs = size /SPAPR_MEMORY_BLOCK_SIZE ;int i; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());sPAPRDIMMState *ds =g_malloc0 (sizeof (sPAPRDIMMState));uint64_t addr = addr_start; ds->nr_lmbs = nr_lmbs; + ds->addr = addr_start; +spapr_pending_dimm_unplugs_add (spapr, ds);for (i =0 ; i < nr_lmbs; i++) { drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_LMB , addr /SPAPR_MEMORY_BLOCK_SIZE );g_assert (drc); drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc, dev, spapr_lmb_release, ds, errp); + drck->detach (drc, dev, spapr_lmb_release,NULL , errp); addr +=SPAPR_MEMORY_BLOCK_SIZE ; }include/hw/ppc/spapr.h +1
-0@@ -32,6 +32,7 @@ struct sPAPRRTCState {int64_t ns_offset; }; +typedef struct sPAPRDIMMState sPAPRDIMMState ;Quoted 8 lines
include/hw/ppc/spapr.h struct sPAPRMachineState { · line 107
Quoted 6 lines
include/hw/ppc/spapr.h +1
-0typedef struct sPAPRMachineClass sPAPRMachineClass ;#define TYPE_SPAPR_MACHINE "spapr-machine"@@ -104,6 +105,9 @@ struct sPAPRMachineState {/* RTAS state */ QTAILQ_HEAD(, sPAPRConfigureConnectorState) ccs_list; +/* pending DIMM unplug queue */ Perhaps update this to mention that it's a cache which can be regenerated when necessary.
Ok.
Quoted 6 lines
Quoted 6 lines
include/hw/ppc/spapr.h +2
-0+ QTAILQ_HEAD(, sPAPRDIMMState) pending_dimm_unplugs; +/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory;
Signature · 4 lines
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
PATCH RESEND v10 2/5 hw/ppc: removing drc->detach_cb and drc->detach_cb_opaque
In reply to Daniel Henrique BarbozaThe pointer drc->detach_cb is being used as a way of informing the detach() function inside spapr_drc.c which cb to execute. This information can also be retrieved simply by checking drc->type and choosing the right callback based on it. In this context, detach_cb is redundant information that must be managed.
After the previous spapr_lmb_release change, no detach_cb_opaques are being used by any of the three callbacks functions. This is yet another information that is now unused and, on top of that, can't be migrated either.
This patch makes the following changes:
- removal of detach_cb_opaque. the 'opaque' argument was removed from the callbacks and from the detach() function of sPAPRConnectorClass. The attribute detach_cb_opaque of sPAPRConnector was removed.
- removal of detach_cb from the detach() call. The function pointer detach_cb of sPAPRConnector was removed. detach() now uses a switch(drc->type) to execute the apropriate callback. To achieve this, spapr_core_release, spapr_lmb_release and spapr_phb_remove_pci_device_cb callbacks were made public to be visible inside detach().
--- hw/ppc/spapr.c | 10 ++++++---- hw/ppc/spapr_drc.c | 36 ++++++++++++++++++++---------------- hw/ppc/spapr_pci.c | 5 +++-- include/hw/pci-host/spapr.h | 3 +++ include/hw/ppc/spapr.h | 4 ++++ include/hw/ppc/spapr_drc.h | 8 +------- 6 files changed, 37 insertions(+), 29 deletions(-)
hw/ppc/spapr.c +6 -4
@@ -2649,7 +2649,8 @@ static uint64_t spapr_dimm_get_address(PCDIMMDevice *dimm)return addr; } -static void spapr_lmb_release (DeviceState *dev,void *opaque) +/* Callback to be called during DRC release. */ +void spapr_lmb_release (DeviceState *dev) {HotplugHandler *hotplug_ctrl;uint64_t addr =spapr_dimm_get_address (PC_DIMM (dev));
@@ -2690,7 +2691,7 @@ static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size,g_assert (drc); drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc, dev, spapr_lmb_release,NULL , errp); + drck->detach (drc, dev, errp); addr +=SPAPR_MEMORY_BLOCK_SIZE ; }
@@ -2766,7 +2767,8 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,object_unparent (OBJECT (dev)); } -static void spapr_core_release (DeviceState *dev,void *opaque) +/* Callback to be called during DRC release. */ +void spapr_core_release (DeviceState *dev) {HotplugHandler *hotplug_ctrl;
@@ -2799,7 +2801,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,g_assert (drc); drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc, dev, spapr_core_release,NULL , &local_err); + drck->detach (drc, dev, &local_err);if (local_err) {error_propagate (errp, local_err);return ;
hw/ppc/spapr_drc.c +20 -16
@@ -20,6 +20,7 @@#include "qapi/visitor.h" #include "qemu/error-report.h" #include "hw/ppc/spapr.h" /* for RTAS return codes */ +#include "hw/pci-host/spapr.h" /* spapr_phb_remove_pci_device_cb callback */ #include "trace.h" #define DRC_CONTAINER_PATH "/dr-connector"
@@ -99,8 +100,7 @@ static uint32_t set_isolation_state(sPAPRDRConnector *drc,if (drc->awaiting_release) {if (drc->configured) {trace_spapr_drc_set_isolation_state_finalizing (get_index (drc)); - drck->detach (drc,DEVICE (drc->dev), drc->detach_cb, - drc->detach_cb_opaque,NULL ); + drck->detach (drc,DEVICE (drc->dev),NULL ); }else {trace_spapr_drc_set_isolation_state_deferring (get_index (drc)); }
@@ -153,8 +153,7 @@ static uint32_t set_allocation_state(sPAPRDRConnector *drc,if (drc->awaiting_release && drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_UNUSABLE ) {trace_spapr_drc_set_allocation_state_finalizing (get_index (drc)); - drck->detach (drc,DEVICE (drc->dev), drc->detach_cb, - drc->detach_cb_opaque,NULL ); + drck->detach (drc,DEVICE (drc->dev),NULL ); }else if (drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_USABLE ) { drc->awaiting_allocation = false; }
@@ -404,15 +403,10 @@ static void attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, NULL, 0, NULL); } -static void detach (sPAPRDRConnector *drc,DeviceState *d, -spapr_drc_detach_cb *detach_cb, -void *detach_cb_opaque,Error **errp) +static void detach (sPAPRDRConnector *drc,DeviceState *d,Error **errp) {trace_spapr_drc_detach (get_index (drc)); - drc->detach_cb = detach_cb; - drc->detach_cb_opaque = detach_cb_opaque; -/* if we've signalled device presence to the guest, or if the guest * has gone ahead and configured the device (via manually-executed * device add via drmgr in guest, namely), we need to wait
@@ -456,8 +450,21 @@ static void detach(sPAPRDRConnector *drc, DeviceState *d, drc->indicator_state =SPAPR_DR_INDICATOR_STATE_INACTIVE ; -if (drc->detach_cb) { - drc->detach_cb (drc->dev, drc->detach_cb_opaque); +/* Calling release callbacks based on drc->type. */ +switch (drc->type) { +case SPAPR_DR_CONNECTOR_TYPE_CPU : +spapr_core_release (drc->dev); +break ; +case SPAPR_DR_CONNECTOR_TYPE_PCI : +spapr_phb_remove_pci_device_cb (drc->dev); +break ; +case SPAPR_DR_CONNECTOR_TYPE_LMB : +spapr_lmb_release (drc->dev); +break ; +case SPAPR_DR_CONNECTOR_TYPE_PHB : +case SPAPR_DR_CONNECTOR_TYPE_VIO : +default : +g_assert (false); } drc->awaiting_release = false;
@@ -467,8 +474,6 @@ static void detach(sPAPRDRConnector *drc, DeviceState *d, drc->fdt_start_offset =0 ;object_property_del (OBJECT (drc),"device" ,NULL ); drc->dev =NULL ; - drc->detach_cb =NULL ; - drc->detach_cb_opaque =NULL ; }static bool release_pending (sPAPRDRConnector *drc)
@@ -498,8 +503,7 @@ static void reset(DeviceState *d)* force removal if we are */ if (drc->awaiting_release) { - drck->detach (drc,DEVICE (drc->dev), drc->detach_cb, - drc->detach_cb_opaque,NULL ); + drck->detach (drc,DEVICE (drc->dev),NULL ); }/* non-PCI devices may be awaiting a transition to UNUSABLE */
hw/ppc/spapr_pci.c +3 -2
@@ -1369,7 +1369,8 @@ out: } } -static void spapr_phb_remove_pci_device_cb (DeviceState *dev,void *opaque) +/* Callback to be called during DRC release. */ +void spapr_phb_remove_pci_device_cb (DeviceState *dev) {/* some version guests do not wait for completion of a device * cleanup (generally done asynchronously by the kernel) before
@@ -1392,7 +1393,7 @@ static void spapr_phb_remove_pci_device(sPAPRDRConnector *drc, {sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc,DEVICE (pdev), spapr_phb_remove_pci_device_cb, phb, errp); + drck->detach (drc,DEVICE (pdev), errp); } static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb,
include/hw/pci-host/spapr.h +3 -0
@@ -123,6 +123,9 @@ sPAPRPHBState *spapr_pci_find_phb(sPAPRMachineState *spapr, uint64_t buid);PCIDevice *spapr_pci_find_dev (sPAPRMachineState *spapr,uint64_t buid,uint32_t config_addr); +/* PCI release callback. */ +void spapr_phb_remove_pci_device_cb (DeviceState *dev); +/* VFIO EEH hooks */ #ifdef CONFIG_LINUX bool spapr_phb_eeh_available (sPAPRPHBState *sphb);
include/hw/ppc/spapr.h +4 -0
@@ -640,6 +640,10 @@ void spapr_hotplug_req_remove_by_count_indexed(sPAPRDRConnectorType drc_type,void *spapr_populate_hotplug_cpu_dt (CPUState *cs,int *fdt_offset,sPAPRMachineState *spapr); +/* CPU and LMB DRC release callbacks. */ +void spapr_core_release (DeviceState *dev); +void spapr_lmb_release (DeviceState *dev); +/* rtas-configure-connector state */ struct sPAPRConfigureConnectorState {uint32_t drc_index;
include/hw/ppc/spapr_drc.h +1 -7
@@ -130,8 +130,6 @@ typedef enum {SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE =-9003 , } sPAPRDRCCResponse; -typedef void (spapr_drc_detach_cb )(DeviceState *d,void *opaque); - typedef struct sPAPRDRConnector { /*< private >*/ DeviceState parent;
@@ -158,8 +156,6 @@ typedef struct sPAPRDRConnector {/* device pointer, via link property */ DeviceState *dev; -spapr_drc_detach_cb *detach_cb; -void *detach_cb_opaque; } sPAPRDRConnector; typedef struct sPAPRDRConnectorClass {
@@ -188,9 +184,7 @@ typedef struct sPAPRDRConnectorClass {/* QEMU interfaces for managing hotplug operations */ void (*attach)(sPAPRDRConnector *drc,DeviceState *d,void *fdt,int fdt_start_offset,bool coldplug,Error **errp); -void (*detach)(sPAPRDRConnector *drc,DeviceState *d, -spapr_drc_detach_cb *detach_cb, -void *detach_cb_opaque,Error **errp); +void (*detach)(sPAPRDRConnector *drc,DeviceState *d,Error **errp);bool (*release_pending)(sPAPRDRConnector *drc);void (*set_signalled)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass;
Signature · 1 line
2.9.4
Re: [Qemu-devel] [RESEND PATCH v10 2/5] hw/ppc: removing drc->detach_cb and drc->detach_cb_opaque
Quoted 17 lines · Daniel Henrique Barboza
The pointer
drc->detach_cbis being used as a way of informing thedetach()function insidespapr_drc.cwhich cb to execute. This information can also be retrieved simply by checkingdrc->typeand choosing the right callback based on it. In this context,detach_cbis redundant information that must be managed.After the previous
spapr_lmb_releasechange, nodetach_cb_opaquesare being used by any of the three callbacks functions. This is yet another information that is now unused and, on top of that, can't be migrated either.This patch makes the following changes:
- removal of
detach_cb_opaque. the 'opaque' argument was removed from the callbacks and from thedetach()function of sPAPRConnectorClass. The attributedetach_cb_opaqueof sPAPRConnector was removed.
Quoted 7 lines
- removal of
detach_cbfrom thedetach()call. The function pointerdetach_cbof sPAPRConnector was removed.detach()now uses aswitch(drc->type)to execute the apropriate callback. To achieve this,spapr_core_release,spapr_lmb_releaseandspapr_phb_remove_pci_device_cbcallbacks were made public to be visible insidedetach().Signed-off-by Daniel Henrique Barboza <[email protected]>
Quoted 228 lines
--- hw/ppc/spapr.c | 10 ++++++---- hw/ppc/spapr_drc.c | 36 ++++++++++++++++++++---------------- hw/ppc/spapr_pci.c | 5 +++-- include/hw/pci-host/spapr.h | 3 +++ include/hw/ppc/spapr.h | 4 ++++ include/hw/ppc/spapr_drc.h | 8 +------- 6 files changed, 37 insertions(+), 29 deletions(-)hw/ppc/spapr.c +6
-4@@ -2649,7 +2649,8 @@ static uint64_t spapr_dimm_get_address(PCDIMMDevice *dimm)return addr; } -static void spapr_lmb_release (DeviceState *dev,void *opaque) +/* Callback to be called during DRC release. */ +void spapr_lmb_release (DeviceState *dev) {HotplugHandler *hotplug_ctrl;uint64_t addr =spapr_dimm_get_address (PC_DIMM (dev));@@ -2690,7 +2691,7 @@ static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size,g_assert (drc); drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc, dev, spapr_lmb_release,NULL , errp); + drck->detach (drc, dev, errp); addr +=SPAPR_MEMORY_BLOCK_SIZE ; }@@ -2766,7 +2767,8 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,object_unparent (OBJECT (dev)); } -static void spapr_core_release (DeviceState *dev,void *opaque) +/* Callback to be called during DRC release. */ +void spapr_core_release (DeviceState *dev) {HotplugHandler *hotplug_ctrl;@@ -2799,7 +2801,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,g_assert (drc); drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc, dev, spapr_core_release,NULL , &local_err); + drck->detach (drc, dev, &local_err);if (local_err) {error_propagate (errp, local_err);return ;hw/ppc/spapr_drc.c +20
-16@@ -20,6 +20,7 @@#include "qapi/visitor.h" #include "qemu/error-report.h" #include "hw/ppc/spapr.h" /* for RTAS return codes */ +#include "hw/pci-host/spapr.h" /* spapr_phb_remove_pci_device_cb callback */ #include "trace.h" #define DRC_CONTAINER_PATH "/dr-connector"@@ -99,8 +100,7 @@ static uint32_t set_isolation_state(sPAPRDRConnector *drc,if (drc->awaiting_release) {if (drc->configured) {trace_spapr_drc_set_isolation_state_finalizing (get_index (drc)); - drck->detach (drc,DEVICE (drc->dev), drc->detach_cb, - drc->detach_cb_opaque,NULL ); + drck->detach (drc,DEVICE (drc->dev),NULL ); }else {trace_spapr_drc_set_isolation_state_deferring (get_index (drc)); }@@ -153,8 +153,7 @@ static uint32_t set_allocation_state(sPAPRDRConnector *drc,if (drc->awaiting_release && drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_UNUSABLE ) {trace_spapr_drc_set_allocation_state_finalizing (get_index (drc)); - drck->detach (drc,DEVICE (drc->dev), drc->detach_cb, - drc->detach_cb_opaque,NULL ); + drck->detach (drc,DEVICE (drc->dev),NULL ); }else if (drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_USABLE ) { drc->awaiting_allocation = false; }@@ -404,15 +403,10 @@ static void attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, NULL, 0, NULL); } -static void detach (sPAPRDRConnector *drc,DeviceState *d, -spapr_drc_detach_cb *detach_cb, -void *detach_cb_opaque,Error **errp) +static void detach (sPAPRDRConnector *drc,DeviceState *d,Error **errp) {trace_spapr_drc_detach (get_index (drc)); - drc->detach_cb = detach_cb; - drc->detach_cb_opaque = detach_cb_opaque; -/* if we've signalled device presence to the guest, or if the guest * has gone ahead and configured the device (via manually-executed * device add via drmgr in guest, namely), we need to wait @@ -456,8 +450,21 @@ static void detach(sPAPRDRConnector *drc, DeviceState *d, drc->indicator_state =SPAPR_DR_INDICATOR_STATE_INACTIVE ; -if (drc->detach_cb) { - drc->detach_cb (drc->dev, drc->detach_cb_opaque); +/* Calling release callbacks based on drc->type. */ +switch (drc->type) { +case SPAPR_DR_CONNECTOR_TYPE_CPU : +spapr_core_release (drc->dev); +break ; +case SPAPR_DR_CONNECTOR_TYPE_PCI : +spapr_phb_remove_pci_device_cb (drc->dev); +break ; +case SPAPR_DR_CONNECTOR_TYPE_LMB : +spapr_lmb_release (drc->dev); +break ; +case SPAPR_DR_CONNECTOR_TYPE_PHB : +case SPAPR_DR_CONNECTOR_TYPE_VIO : +default : +g_assert (false); } drc->awaiting_release = false;@@ -467,8 +474,6 @@ static void detach(sPAPRDRConnector *drc, DeviceState *d, drc->fdt_start_offset =0 ;object_property_del (OBJECT (drc),"device" ,NULL ); drc->dev =NULL ; - drc->detach_cb =NULL ; - drc->detach_cb_opaque =NULL ; }static bool release_pending (sPAPRDRConnector *drc)@@ -498,8 +503,7 @@ static void reset(DeviceState *d)* force removal if we are */ if (drc->awaiting_release) { - drck->detach (drc,DEVICE (drc->dev), drc->detach_cb, - drc->detach_cb_opaque,NULL ); + drck->detach (drc,DEVICE (drc->dev),NULL ); }/* non-PCI devices may be awaiting a transition to UNUSABLE */ hw/ppc/spapr_pci.c +3
-2@@ -1369,7 +1369,8 @@ out: } } -static void spapr_phb_remove_pci_device_cb (DeviceState *dev,void *opaque) +/* Callback to be called during DRC release. */ +void spapr_phb_remove_pci_device_cb (DeviceState *dev) {/* some version guests do not wait for completion of a device * cleanup (generally done asynchronously by the kernel) before @@ -1392,7 +1393,7 @@ static void spapr_phb_remove_pci_device(sPAPRDRConnector *drc, {sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - drck->detach (drc,DEVICE (pdev), spapr_phb_remove_pci_device_cb, phb, errp); + drck->detach (drc,DEVICE (pdev), errp); } static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb,include/hw/pci-host/spapr.h +3
-0@@ -123,6 +123,9 @@ sPAPRPHBState *spapr_pci_find_phb(sPAPRMachineState *spapr, uint64_t buid);PCIDevice *spapr_pci_find_dev (sPAPRMachineState *spapr,uint64_t buid,uint32_t config_addr); +/* PCI release callback. */ +void spapr_phb_remove_pci_device_cb (DeviceState *dev); +/* VFIO EEH hooks */ #ifdef CONFIG_LINUX bool spapr_phb_eeh_available (sPAPRPHBState *sphb);include/hw/ppc/spapr.h +4
-0@@ -640,6 +640,10 @@ void spapr_hotplug_req_remove_by_count_indexed(sPAPRDRConnectorType drc_type,void *spapr_populate_hotplug_cpu_dt (CPUState *cs,int *fdt_offset,sPAPRMachineState *spapr); +/* CPU and LMB DRC release callbacks. */ +void spapr_core_release (DeviceState *dev); +void spapr_lmb_release (DeviceState *dev); +/* rtas-configure-connector state */ struct sPAPRConfigureConnectorState {uint32_t drc_index;include/hw/ppc/spapr_drc.h +1
-7@@ -130,8 +130,6 @@ typedef enum {SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE =-9003 , } sPAPRDRCCResponse; -typedef void (spapr_drc_detach_cb )(DeviceState *d,void *opaque); - typedef struct sPAPRDRConnector { /*< private >*/ DeviceState parent;@@ -158,8 +156,6 @@ typedef struct sPAPRDRConnector {/* device pointer, via link property */ DeviceState *dev; -spapr_drc_detach_cb *detach_cb; -void *detach_cb_opaque; } sPAPRDRConnector; typedef struct sPAPRDRConnectorClass {@@ -188,9 +184,7 @@ typedef struct sPAPRDRConnectorClass {/* QEMU interfaces for managing hotplug operations */ void (*attach)(sPAPRDRConnector *drc,DeviceState *d,void *fdt,int fdt_start_offset,bool coldplug,Error **errp); -void (*detach)(sPAPRDRConnector *drc,DeviceState *d, -spapr_drc_detach_cb *detach_cb, -void *detach_cb_opaque,Error **errp); +void (*detach)(sPAPRDRConnector *drc,DeviceState *d,Error **errp);bool (*release_pending)(sPAPRDRConnector *drc);void (*set_signalled)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass;
Signature · 4 lines
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
PATCH RESEND v10 3/5 hw/ppc: migrating the DRC state of hotplugged devices
In reply to Daniel Henrique BarbozaIn pseries, a firmware abstraction called Dynamic Reconfiguration Connector (DRC) is used to assign a particular dynamic resource to the guest and provide an interface to manage configuration/removal of the resource associated with it. In other words, DRC is the 'plugged state' of a device.
Before this patch, DRC wasn't being migrated. This causes post-migration problems due to DRC state mismatch between source and target. The DRC state of a device X in the source might
change, while in the target the DRC state of X is still fresh. When migrating the guest, X will not have the same hotplugged state as it did in the source. This means that we can't hot unplug X in the target after migration is completed because its DRC state is not consistent.
https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1677552 is one bug that is caused by this DRC state mismatch between source and target.
To migrate the DRC state, we defined the VMStateDescription struct for spapr_drc to enable the transmission of spapr_drc state in migration. Not all the elements in the DRC state are migrated - only those that can be modified by guest actions or device add/remove operations:
- 'isolation_state', 'allocation_state' and 'indicator_state' are involved in the DR state transition diagram from PAPR+ 2.7, 13.4;
- 'configured', 'signalled', 'awaiting_release' and 'awaiting_allocation' are needed in attaching and detaching devices;
- 'indicator_state' provides users with hardware state information.
These are the DRC elements that are migrated.
In this patch the DRC state is migrated for PCI, LMB and CPU connector types. At this moment there is no support to migrate DRC for the PHB (PCI Host Bridge) type.
In the 'realize' function the DRC is registered using vmstate_register, similar to what hw/ppc/spapr_iommu.c does in 'spapr_tce_table_realize'. This approach works because DRCs are bus-less and do not sit on a BusClass that implements bc->get_dev_path, so as a fallback the VMSD gets identified via "spapr_drc"/get_index(drc).
--- hw/ppc/spapr_drc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
hw/ppc/spapr_drc.c +52 -0
@@ -519,6 +519,56 @@ static void reset(DeviceState *d) } } +static bool spapr_drc_needed (void *opaque) +{ +sPAPRDRConnector *drc = (sPAPRDRConnector *)opaque; +sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); +bool rc = false; +sPAPRDREntitySense value; + drck->entity_sense (drc, &value); + +/* If no dev is plugged in there is no need to migrate the DRC state */ +if (value !=SPAPR_DR_ENTITY_SENSE_PRESENT ) { +return false; + } + +/* +* If there is dev plugged in, we need to migrate the DRC state when +* it is different from cold-plugged state +*/ +switch (drc->type) { +case SPAPR_DR_CONNECTOR_TYPE_PCI : + rc = !((drc->isolation_state ==SPAPR_DR_ISOLATION_STATE_UNISOLATED ) && + (drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_USABLE ) && + drc->configured && drc->signalled && !drc->awaiting_release); +case SPAPR_DR_CONNECTOR_TYPE_CPU : +case SPAPR_DR_CONNECTOR_TYPE_LMB : + rc = !((drc->isolation_state ==SPAPR_DR_ISOLATION_STATE_ISOLATED ) && + (drc->allocation_state ==SPAPR_DR_ALLOCATION_STATE_UNUSABLE ) && + drc->configured && drc->signalled && !drc->awaiting_release); +default : +g_assert (false); + } +return rc; +} + +static const VMStateDescription vmstate_spapr_drc = { + .name ="spapr_drc" , + .version_id =1 , + .minimum_version_id =1 , + .needed = spapr_drc_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32 (isolation_state, sPAPRDRConnector), +VMSTATE_UINT32 (allocation_state, sPAPRDRConnector), +VMSTATE_UINT32 (indicator_state, sPAPRDRConnector), +VMSTATE_BOOL (configured, sPAPRDRConnector), +VMSTATE_BOOL (awaiting_release, sPAPRDRConnector), +VMSTATE_BOOL (awaiting_allocation, sPAPRDRConnector), +VMSTATE_BOOL (signalled, sPAPRDRConnector), +VMSTATE_END_OF_LIST () + } +}; +static void realize (DeviceState *d,Error **errp) {sPAPRDRConnector *drc =SPAPR_DR_CONNECTOR (d);
@@ -547,6 +597,8 @@ static void realize(DeviceState *d, Error **errp)object_unref (OBJECT (drc)); }g_free (child_name); +vmstate_register (DEVICE (drc), drck->get_index (drc), &vmstate_spapr_drc, + drc);trace_spapr_drc_realize_complete (drck->get_index (drc)); }
Signature · 1 line
2.9.4
PATCH RESEND v10 4/5 hw/ppc/spapr.c: recover pending LMB unplug info in spapr_lmb_release
In reply to Daniel Henrique BarbozaWhen a LMB hot unplug starts, the current DRC LMB status is stored at spapr->pending_dimm_unplugs QTAILQ. This queue isn't migrated, thus if a migration occurs in the middle of a LMB unplug the spapr_lmb_release callback will lost track of the LMB unplug progress.
This patch implements a new recover function spapr_recover_pending_dimm_state that is used inside spapr_lmb_release to recover this DRC LMB release status that is lost during the migration.
--- hw/ppc/spapr.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +38 -1
@@ -2649,6 +2649,36 @@ static uint64_t spapr_dimm_get_address(PCDIMMDevice *dimm)return addr; } +static sPAPRDIMMState *spapr_recover_pending_dimm_state (PCDIMMDevice *dimm, +uint64_t addr) +{ +sPAPRDRConnector *drc; +PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm); +MemoryRegion *mr = ddc->get_memory_region (dimm); +uint64_t curr_addr = addr; +uint64_t size =memory_region_size (mr); +uint32_t nr_lmbs = size /SPAPR_MEMORY_BLOCK_SIZE ; +uint32_t avail_lmbs =0 ; +int i =0 ; + +for (i =0 ; i < nr_lmbs; i++) { + drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_LMB , + curr_addr /SPAPR_MEMORY_BLOCK_SIZE ); +g_assert (drc); +if (drc->indicator_state !=SPAPR_DR_INDICATOR_STATE_INACTIVE ) { + avail_lmbs++; + } + curr_addr +=SPAPR_MEMORY_BLOCK_SIZE ; + } + +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRDIMMState *ds =g_malloc0 (sizeof (sPAPRDIMMState)); + ds->nr_lmbs = avail_lmbs; + ds->addr = addr; +spapr_pending_dimm_unplugs_add (spapr, ds); +return ds; +} +/* Callback to be called during DRC release. */ void spapr_lmb_release (DeviceState *dev) {
@@ -2657,7 +2687,14 @@ void spapr_lmb_release(DeviceState *dev)sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());sPAPRDIMMState *ds =spapr_pending_dimm_unplugs_find (spapr, addr); -if (--ds->nr_lmbs) { +/* This information will get lost if a migration occurs +* during the unplug process. In this case recover it. */ +if (ds ==NULL ) { + ds =spapr_recover_pending_dimm_state (PC_DIMM (dev), addr); +if (ds->nr_lmbs) { +return ; + } + }else if (--ds->nr_lmbs) {return ; }
Signature · 1 line
2.9.4
PATCH RESEND v10 5/5 migration: spapr: migrate ccs_list in spapr state
In reply to Daniel Henrique BarbozaFrom: Jianjun Duan <[email protected]>
ccs_list in spapr state maintains the device tree related information on the rtas side for hotplugged devices. In racing situations between hotplug events and migration operation, a rtas hotplug event could be migrated from the source guest to target guest, or the source guest could have not yet finished fetching the device tree when migration is started, the target will try to finish fetching the device tree. By migrating ccs_list, the target can fetch the device tree properly.
In theory there would be other alternatives besides migrating the css_list to fix this. For example, we could add a flag that indicates whether a device is in the middle of the configure_connector during the migration process, in the post_load we can detect if this flag is active and then return an error informing the guest to restart the hotplug process. However, the DRC state can still be modified outside of hotplug. Using:
drmgr -c pci -s <drc_index> -r
drmgr -c pci -s <drc_index> -a
it is possible to return a device to firmware and then later take it back and reconfigure it. This is not a common case but it's not prohibited, and performing a migration between these 2 operations would fail because the default coldplug state on target assumes a configured state in the source*. Migrating ccs_list is one solution that cover this case as well.
ccs_list is put in a subsection in the spapr state VMSD to make sure migration across different versions is not broken.
* see http://lists.nongnu.org/archive/html/qemu-devel/2016-10/msg01763.html
for more information on this discussion.
--- hw/ppc/spapr.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
hw/ppc/spapr.c +32 -0
@@ -1444,6 +1444,37 @@ static bool version_before_3(void *opaque, int version_id)return version_id <3 ; } +static bool spapr_ccs_list_needed (void *opaque) +{ +sPAPRMachineState *spapr = (sPAPRMachineState *)opaque; +return !QTAILQ_EMPTY (&spapr->ccs_list); +} + +static const VMStateDescription vmstate_spapr_ccs = { + .name ="spapr_configure_connector_state" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (drc_index, sPAPRConfigureConnectorState), +VMSTATE_INT32 (fdt_offset, sPAPRConfigureConnectorState), +VMSTATE_INT32 (fdt_depth, sPAPRConfigureConnectorState), +VMSTATE_END_OF_LIST () + }, +}; + +static const VMStateDescription vmstate_spapr_ccs_list = { + .name ="spapr_ccs_list" , + .version_id =1 , + .minimum_version_id =1 , + .needed = spapr_ccs_list_needed, + .fields = (VMStateField []) { +VMSTATE_QTAILQ_V (ccs_list, sPAPRMachineState,1 , + vmstate_spapr_ccs, sPAPRConfigureConnectorState, + next), +VMSTATE_END_OF_LIST () + }, +}; +static bool spapr_ov5_cas_needed (void *opaque) {sPAPRMachineState *spapr = opaque;
@@ -1542,6 +1573,7 @@ static const VMStateDescription vmstate_spapr = { .subsections = (const VMStateDescription*[]) { &vmstate_spapr_ov5_cas, &vmstate_spapr_patb_entry, + &vmstate_spapr_ccs_list,NULL } };
Signature · 1 line
2.9.4