CPU unplug timeout/LMB unplug cleanup in DRC reconfiguration
v4 cover CPU unplug timeout/LMB unplug cleanup in DRC reconfiguration
Hi,
This new version contains fixes proposed during the review of v3. Patches were rebased on top of David's ppc-for-6.0.
changes from v3:
- former patch 1: already pushed to ppc-for-6.0
- former patch 2: dropped
- all patches: commit message trimmed to < 76 chars per line
- all patches: added R-bs from previous review
- patch 3:
* removed the migratable state of the unplug timer
* added a 'spapr_drc_start_unplug_timeout_timer()' helper to start the timer
* added a .post_load implementation to vmstate_spapr_drc, pointed to a new spapr_drc_post_load() function
* spapr_drc_post_load() starts the DRC unplug timer from the beginning using spapr_drc_start_unplug_timeout_timer()
- patch 4:
* use spapr_drc_start_unplug_timeout_timer() to start the timer in spapr_drc_unplug_request() (To David: I kept your Reviewed-by in this patch despite this change - feel free to review it again)
- patch 5:
* removed the 'DIMM' wording when referring to kernel internals
* move the g_assert() to spapr_clear_pending_dimm_unplug_state()
* do not g_assert(dev), but g_assert(ds) if dev != NULL inside spapr_clear_pending_dimm_unplug_state()
- v3 link: https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg04196.html
Daniel Henrique Barboza (5):
spapr_drc.c: use spapr_drc_release() in isolate_physical/set_unusable
spapr: rename spapr_drc_detach() to spapr_drc_unplug_request() spapr_drc.c: introduce unplug_timeout_timer
spapr_drc.c: add hotunplug timeout for CPUs
spapr_drc.c: use DRC reconfiguration to cleanup DIMM unplug state
hw/ppc/spapr.c | 53 ++++++++++++++++++-- hw/ppc/spapr_drc.c | 99 +++++++++++++++++++++++++++++++------- hw/ppc/spapr_pci.c | 4 +- hw/ppc/trace-events | 2 +- include/hw/ppc/spapr.h | 2 + include/hw/ppc/spapr_drc.h | 7 ++- 6 files changed, 142 insertions(+), 25 deletions(-)
Signature · 1 line
2.29.2
PATCH v4 1/5 spapr_drc.c: use spapr_drc_release() in isolate_physical/set_unusable
When moving a physical DRC to "Available", drc_isolate_physical() will move the DRC state to STATE_PHYSICAL_POWERON and, if the DRC is marked for unplug, call spapr_drc_detach(). For physical DRCs, drck->empty_state is STATE_PHYSICAL_POWERON, meaning that we're sure that spapr_drc_detach() will end up calling spapr_drc_release() in the end.
Likewise, for logical DRCs, drc_set_unusable will move the DRC to "Unusable" state, setting drc->state to STATE_LOGICAL_UNUSABLE, which is the drck->empty_state for logical DRCs. spapr_drc_detach() will call spapr_drc_release() in this case as well.
In both scenarios, spapr_drc_detach() is being used as a spapr_drc_release(), wrapper, where we also set unplug_requested (which is already true, otherwise spapr_drc_detach() wouldn't be called in the first place) and check if drc->state == drck->empty_state, which we also know it's guaranteed to be true because we just set it.
Just use spapr_drc_release() in these functions to be clear of our intentions in both these functions.
--- hw/ppc/spapr_drc.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
hw/ppc/spapr_drc.c +16 -16
@@ -50,6 +50,20 @@ uint32_t spapr_drc_index(SpaprDrc *drc) | (drc->id & DRC_INDEX_ID_MASK); } +static void spapr_drc_release (SpaprDrc *drc) +{ +SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + + drck->release (drc->dev); + + drc->unplug_requested = false; +g_free (drc->fdt); + drc->fdt =NULL ; + drc->fdt_start_offset =0 ; +object_property_del (OBJECT (drc),"device" ); + drc->dev =NULL ; +} +static uint32_t drc_isolate_physical (SpaprDrc *drc) {switch (drc->state) {
@@ -68,7 +82,7 @@ static uint32_t drc_isolate_physical(SpaprDrc *drc)if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc);trace_spapr_drc_set_isolation_state_finalizing (drc_index); -spapr_drc_detach (drc); +spapr_drc_release (drc); }return RTAS_OUT_SUCCESS ;
@@ -209,7 +223,7 @@ static uint32_t drc_set_unusable(SpaprDrc *drc)if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc);trace_spapr_drc_set_allocation_state_finalizing (drc_index); -spapr_drc_detach (drc); +spapr_drc_release (drc); }return RTAS_OUT_SUCCESS ;
@@ -372,20 +386,6 @@ void spapr_drc_attach(SpaprDrc *drc, DeviceState *d) NULL, 0); } -static void spapr_drc_release (SpaprDrc *drc) -{ -SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - - drck->release (drc->dev); - - drc->unplug_requested = false; -g_free (drc->fdt); - drc->fdt =NULL ; - drc->fdt_start_offset =0 ; -object_property_del (OBJECT (drc),"device" ); - drc->dev =NULL ; -} -void spapr_drc_detach (SpaprDrc *drc) {SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc);
Signature · 1 line
2.29.2
David Gibson
AppliedRe: [PATCH v4 1/5] spapr_drc.c: use spapr_drc_release() in isolate_physical/set_unusable
Quoted 18 lines · Daniel Henrique Barboza
When moving a physical DRC to "Available",
drc_isolate_physical()will move the DRC state toSTATE_PHYSICAL_POWERONand, if the DRC is marked for unplug, callspapr_drc_detach(). For physical DRCs,drck->empty_stateisSTATE_PHYSICAL_POWERON, meaning that we're sure thatspapr_drc_detach()will end up callingspapr_drc_release()in the end.Likewise, for logical DRCs,
drc_set_unusablewill move the DRC to "Unusable" state, settingdrc->statetoSTATE_LOGICAL_UNUSABLE, which is thedrck->empty_statefor logical DRCs.spapr_drc_detach()will callspapr_drc_release()in this case as well.In both scenarios,
spapr_drc_detach()is being used as aspapr_drc_release(), wrapper, where we also setunplug_requested(which is already true, otherwisespapr_drc_detach()wouldn't be called in the first place) and check ifdrc->state==drck->empty_state, which we also know it's guaranteed to be true because we just set it.
Quoted 6 lines
Just use
spapr_drc_release()in these functions to be clear of our intentions in both these functions.Reviewed-by Greg Kurz <[email protected]>Reviewed-by David Gibson <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>
Applied to ppc-for-6.0, thanks.
Quoted 68 lines
--- hw/ppc/spapr_drc.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)hw/ppc/spapr_drc.c +16
-16@@ -50,6 +50,20 @@ uint32_t spapr_drc_index(SpaprDrc *drc) | (drc->id & DRC_INDEX_ID_MASK); } +static void spapr_drc_release (SpaprDrc *drc) +{ +SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + + drck->release (drc->dev); + + drc->unplug_requested = false; +g_free (drc->fdt); + drc->fdt =NULL ; + drc->fdt_start_offset =0 ; +object_property_del (OBJECT (drc),"device" ); + drc->dev =NULL ; +} +static uint32_t drc_isolate_physical (SpaprDrc *drc) {switch (drc->state) {@@ -68,7 +82,7 @@ static uint32_t drc_isolate_physical(SpaprDrc *drc)if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc);trace_spapr_drc_set_isolation_state_finalizing (drc_index); -spapr_drc_detach (drc); +spapr_drc_release (drc); }return RTAS_OUT_SUCCESS ;@@ -209,7 +223,7 @@ static uint32_t drc_set_unusable(SpaprDrc *drc)if (drc->unplug_requested) {uint32_t drc_index =spapr_drc_index (drc);trace_spapr_drc_set_allocation_state_finalizing (drc_index); -spapr_drc_detach (drc); +spapr_drc_release (drc); }return RTAS_OUT_SUCCESS ;@@ -372,20 +386,6 @@ void spapr_drc_attach(SpaprDrc *drc, DeviceState *d) NULL, 0); } -static void spapr_drc_release (SpaprDrc *drc) -{ -SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); - - drck->release (drc->dev); - - drc->unplug_requested = false; -g_free (drc->fdt); - drc->fdt =NULL ; - drc->fdt_start_offset =0 ; -object_property_del (OBJECT (drc),"device" ); - drc->dev =NULL ; -} -void spapr_drc_detach (SpaprDrc *drc) {SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc);
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 v4 2/5 spapr: rename spapr_drc_detach() to spapr_drc_unplug_request()
In reply to Daniel Henrique Barbozaspapr_drc_detach() is not the best name for what the function does. The function does not detach the DRC, it makes an uncommited attempt to do it. It'll mark the DRC as pending unplug, via the 'unplug_request' flag, and only if the DRC state is drck->empty_state it will detach the DRC, via spapr_drc_release().
This is a contrast with its pair spapr_drc_attach(), where the function is indeed creating the DRC QOM object. If you know what spapr_drc_attach() does, you can be misled into thinking that spapr_drc_detach() is removing the DRC from QEMU internal state, which isn't true.
The current role of this function is better described as a request for detach, since there's no guarantee that we're going to detach the DRC in the end. Rename the function to spapr_drc_unplug_request to reflect what is is doing.
The initial idea was to change the name to spapr_drc_detach_request(), and later on change the unplug_request flag to detach_request. However, unplug_request is a migratable boolean for a long time now and renaming it is not worth the trouble. spapr_drc_unplug_request() setting drc->unplug_request is more natural than spapr_drc_detach_request setting drc->unplug_request.
--- hw/ppc/spapr.c | 6 +++--- hw/ppc/spapr_drc.c | 4 ++-- hw/ppc/spapr_pci.c | 4 ++-- hw/ppc/trace-events | 2 +- include/hw/ppc/spapr_drc.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)
hw/ppc/spapr.c +3 -3
@@ -3654,7 +3654,7 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev, addr / SPAPR_MEMORY_BLOCK_SIZE);g_assert (drc); -spapr_drc_detach (drc); +spapr_drc_unplug_request (drc); addr +=SPAPR_MEMORY_BLOCK_SIZE ; }
@@ -3722,7 +3722,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,g_assert (drc);if (!spapr_drc_unplug_requested (drc)) { -spapr_drc_detach (drc); +spapr_drc_unplug_request (drc);spapr_hotplug_req_remove_by_index (drc); } }
@@ -3985,7 +3985,7 @@ static void spapr_phb_unplug_request(HotplugHandler *hotplug_dev,assert (drc);if (!spapr_drc_unplug_requested (drc)) { -spapr_drc_detach (drc); +spapr_drc_unplug_request (drc);spapr_hotplug_req_remove_by_index (drc); } }
hw/ppc/spapr_drc.c +2 -2
@@ -386,11 +386,11 @@ void spapr_drc_attach(SpaprDrc *drc, DeviceState *d) NULL, 0); } -void spapr_drc_detach (SpaprDrc *drc) +void spapr_drc_unplug_request (SpaprDrc *drc) {SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); -trace_spapr_drc_detach (spapr_drc_index (drc)); +trace_spapr_drc_unplug_request (spapr_drc_index (drc));g_assert (drc->dev);
hw/ppc/spapr_pci.c +2 -2
@@ -1723,12 +1723,12 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler,* functions, even if their unplug weren't requested * beforehand. */ -spapr_drc_detach (func_drc); +spapr_drc_unplug_request (func_drc); } } } -spapr_drc_detach (drc); +spapr_drc_unplug_request (drc);/* if this isn't func 0, defer unplug event. otherwise signal removal * for all present functions
hw/ppc/trace-events +1 -1
@@ -50,7 +50,7 @@ spapr_drc_set_allocation_state(uint32_t index, int state) "drc: 0x%"PRIx32", sta spapr_drc_set_allocation_state_finalizing(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_set_configured(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_attach(uint32_t index) "drc: 0x%"PRIx32 -spapr_drc_detach(uint32_t index) "drc: 0x%"PRIx32 +spapr_drc_unplug_request(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_awaiting_quiesce(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_reset(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_realize(uint32_t index) "drc: 0x%"PRIx32
include/hw/ppc/spapr_drc.h +1 -1
@@ -243,7 +243,7 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask);* beforehand (eg. check drc->dev at pre-plug). */ void spapr_drc_attach (SpaprDrc *drc,DeviceState *d); -void spapr_drc_detach (SpaprDrc *drc); +void spapr_drc_unplug_request (SpaprDrc *drc);/* * Reset all DRCs, causing pending hot-plug/unplug requests to complete.
Signature · 1 line
2.29.2
David Gibson
AppliedRe: [PATCH v4 2/5] spapr: rename spapr_drc_detach() to spapr_drc_unplug_request()
Quoted 24 lines · Daniel Henrique Barboza
spapr_drc_detach()is not the best name for what the function does. The function does not detach the DRC, it makes an uncommited attempt to do it. It'll mark the DRC as pending unplug, via the 'unplug_request' flag, and only if the DRC state isdrck->empty_stateit will detach the DRC, viaspapr_drc_release().This is a contrast with its pair
spapr_drc_attach(), where the function is indeed creating the DRC QOM object. If you know whatspapr_drc_attach()does, you can be misled into thinking thatspapr_drc_detach()is removing the DRC from QEMU internal state, which isn't true.The current role of this function is better described as a request for detach, since there's no guarantee that we're going to detach the DRC in the end. Rename the function to
spapr_drc_unplug_requestto reflect what is is doing.The initial idea was to change the name to
spapr_drc_detach_request(), and later on change theunplug_requestflag todetach_request. However,unplug_requestis a migratable boolean for a long time now and renaming it is not worth the trouble.spapr_drc_unplug_request()settingdrc->unplug_requestis more natural thanspapr_drc_detach_requestsettingdrc->unplug_request.
Quoted 3 lines
Reviewed-by Greg Kurz <[email protected]>Reviewed-by David Gibson <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>
Applied to ppc-for-6.0, thanks.
Quoted 102 lines
--- hw/ppc/spapr.c | 6 +++--- hw/ppc/spapr_drc.c | 4 ++-- hw/ppc/spapr_pci.c | 4 ++-- hw/ppc/trace-events | 2 +- include/hw/ppc/spapr_drc.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)hw/ppc/spapr.c +3
-3@@ -3654,7 +3654,7 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev, addr / SPAPR_MEMORY_BLOCK_SIZE);g_assert (drc); -spapr_drc_detach (drc); +spapr_drc_unplug_request (drc); addr +=SPAPR_MEMORY_BLOCK_SIZE ; }@@ -3722,7 +3722,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,g_assert (drc);if (!spapr_drc_unplug_requested (drc)) { -spapr_drc_detach (drc); +spapr_drc_unplug_request (drc);spapr_hotplug_req_remove_by_index (drc); } }@@ -3985,7 +3985,7 @@ static void spapr_phb_unplug_request(HotplugHandler *hotplug_dev,assert (drc);if (!spapr_drc_unplug_requested (drc)) { -spapr_drc_detach (drc); +spapr_drc_unplug_request (drc);spapr_hotplug_req_remove_by_index (drc); } }hw/ppc/spapr_drc.c +2
-2@@ -386,11 +386,11 @@ void spapr_drc_attach(SpaprDrc *drc, DeviceState *d) NULL, 0); } -void spapr_drc_detach (SpaprDrc *drc) +void spapr_drc_unplug_request (SpaprDrc *drc) {SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); -trace_spapr_drc_detach (spapr_drc_index (drc)); +trace_spapr_drc_unplug_request (spapr_drc_index (drc));g_assert (drc->dev);hw/ppc/spapr_pci.c +2
-2@@ -1723,12 +1723,12 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler,* functions, even if their unplug weren't requested * beforehand. */ -spapr_drc_detach (func_drc); +spapr_drc_unplug_request (func_drc); } } } -spapr_drc_detach (drc); +spapr_drc_unplug_request (drc);/* if this isn't func 0, defer unplug event. otherwise signal removal * for all present functions hw/ppc/trace-events +1
-1@@ -50,7 +50,7 @@ spapr_drc_set_allocation_state(uint32_t index, int state) "drc: 0x%"PRIx32", sta spapr_drc_set_allocation_state_finalizing(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_set_configured(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_attach(uint32_t index) "drc: 0x%"PRIx32 -spapr_drc_detach(uint32_t index) "drc: 0x%"PRIx32 +spapr_drc_unplug_request(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_awaiting_quiesce(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_reset(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_realize(uint32_t index) "drc: 0x%"PRIx32include/hw/ppc/spapr_drc.h +1
-1@@ -243,7 +243,7 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask);* beforehand (eg. check drc->dev at pre-plug). */ void spapr_drc_attach (SpaprDrc *drc,DeviceState *d); -void spapr_drc_detach (SpaprDrc *drc); +void spapr_drc_unplug_request (SpaprDrc *drc);/* * Reset all DRCs, causing pending hot-plug/unplug requests to complete.
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 v4 3/5 spapr_drc.c: introduce unplug_timeout_timer
In reply to Daniel Henrique BarbozaThe LoPAR spec provides no way for the guest kernel to report failure of hotplug/hotunplug events. This wouldn't be bad if those operations were granted to always succeed, but that's far for the reality.
What ends up happening is that, in the case of a failed hotunplug, regardless of whether it was a QEMU error or a guest misbehavior, the pSeries machine is retaining the unplug state of the device in the running guest. This state is cleanup in machine reset, where it is assumed that this state represents a device that is pending unplug, and the device is hotunpluged from the board. Until the reset occurs, any hotunplug operation of the same device is forbid because there is a pending unplug state.
This behavior has at least one undesirable side effect. A long standing pending unplug state is, more often than not, the result of a hotunplug error. The user had to dealt with it, since retrying to unplug the device is noy allowed, and then in the machine reset we're removing the device from the guest. This means that we're failing the user twice - failed to hotunplug when asked, then hotunplugged without notice.
Solutions to this problem range between trying to predict when the hotunplug will fail and forbid the operation from the QEMU layer, from opening up the IRQ queue to allow for multiple hotunplug attempts, from telling the users to 'reboot the machine if something goes wrong'. The first solution is flawed because we can't fully predict guest behavior from QEMU, the second solution is a trial and error remediation that counts on a hope that the unplug will eventually succeed, and the third is ... well.
This patch introduces a crude, but effective solution to hotunplug errors in the pSeries machine. For each unplug done, we'll timeout after some time. If a certain amount of time passes, we'll cleanup the hotunplug state from the machine. During the timeout period, any unplug operations in the same device will still be blocked. After that, we'll assume that the guest failed the operation, and allow the user to try again. If the timeout is too short we'll prevent legitimate hotunplug situations to occur, so we'll need to overestimate the regular time an unplug operation takes to succeed to account that.
The true solution for the hotunplug errors in the pSeries machines is a PAPR change to allow for the guest to warn the platform about it. For now, the work done in this timeout design can be used for the new PAPR 'abort hcall' in the future, given that for both cases we'll need code to cleanup the existing unplug states of the DRCs.
At this moment we're adding the basic wiring of the timer into the DRC. Next patch will use the timer to timeout failed CPU hotunplugs.
--- hw/ppc/spapr_drc.c | 40 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_drc.h | 4 ++++ 2 files changed, 44 insertions(+)
hw/ppc/spapr_drc.c +40 -0
@@ -57,6 +57,8 @@ static void spapr_drc_release(SpaprDrc *drc) drck->release (drc->dev); drc->unplug_requested = false; +timer_del (drc->unplug_timeout_timer); +g_free (drc->fdt); drc->fdt =NULL ; drc->fdt_start_offset =0 ;
@@ -370,6 +372,17 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name, }while (fdt_depth !=0 ); } +static void spapr_drc_start_unplug_timeout_timer (SpaprDrc *drc) +{ +SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + +if (drck->unplug_timeout_seconds !=0 ) { +timer_mod (drc->unplug_timeout_timer, +qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) + + drck->unplug_timeout_seconds *1000 ); + } +} +void spapr_drc_attach (SpaprDrc *drc,DeviceState *d) {trace_spapr_drc_attach (spapr_drc_index (drc));
@@ -475,11 +488,23 @@ static bool spapr_drc_needed(void *opaque)spapr_drc_unplug_requested (drc); } +static int spapr_drc_post_load (void *opaque,int version_id) +{ +SpaprDrc *drc = opaque; + +if (drc->unplug_requested) { +spapr_drc_start_unplug_timeout_timer (drc); + } + +return 0 ; +} +static const VMStateDescription vmstate_spapr_drc = { .name ="spapr_drc" , .version_id =1 , .minimum_version_id =1 , .needed = spapr_drc_needed, + .post_load = spapr_drc_post_load, .fields = (VMStateField []) {VMSTATE_UINT32 (state, SpaprDrc),VMSTATE_END_OF_LIST ()
@@ -490,6 +515,15 @@ static const VMStateDescription vmstate_spapr_drc = { } }; +static void drc_unplug_timeout_cb (void *opaque) +{ +SpaprDrc *drc = opaque; + +if (drc->unplug_requested) { + drc->unplug_requested = false; + } +} +static void drc_realize (DeviceState *d,Error **errp) {SpaprDrc *drc =SPAPR_DR_CONNECTOR (d);
@@ -512,6 +546,11 @@ static void drc_realize(DeviceState *d, Error **errp)object_property_add_alias (root_container, link_name, drc->owner, child_name);g_free (link_name); + + drc->unplug_timeout_timer =timer_new_ms (QEMU_CLOCK_VIRTUAL , + drc_unplug_timeout_cb, + drc); +vmstate_register (VMSTATE_IF (drc),spapr_drc_index (drc), &vmstate_spapr_drc, drc);trace_spapr_drc_realize_complete (spapr_drc_index (drc));
@@ -529,6 +568,7 @@ static void drc_unrealize(DeviceState *d) name =g_strdup_printf ("%x" ,spapr_drc_index (drc));object_property_del (root_container, name);g_free (name); +timer_free (drc->unplug_timeout_timer); } SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type,
include/hw/ppc/spapr_drc.h +4 -0
@@ -187,6 +187,8 @@ typedef struct SpaprDrc {bool unplug_requested;void *fdt;int fdt_start_offset; + +QEMUTimer *unplug_timeout_timer; } SpaprDrc;struct SpaprMachineState ;
@@ -209,6 +211,8 @@ typedef struct SpaprDrcClass {int (*dt_populate)(SpaprDrc *drc,struct SpaprMachineState *spapr,void *fdt,int *fdt_start_offset,Error **errp); + +int unplug_timeout_seconds; } SpaprDrcClass; typedef struct SpaprDrcPhysical {
Signature · 1 line
2.29.2
PATCH v4 4/5 spapr_drc.c: add hotunplug timeout for CPUs
In reply to Daniel Henrique BarbozaThere is a reliable way to make a CPU hotunplug fail in the pseries machine. Hotplug a CPU A, then offline all other CPUs inside the guest but A. When trying to hotunplug A the guest kernel will refuse to do it, because A is now the last online CPU of the guest. PAPR has no 'error callback' in this situation to report back to the platform, so the guest kernel will deny the unplug in silent and QEMU will never know what happened. The unplug pending state of A will remain until the guest is shutdown or rebooted.
Previous attempts of fixing it (see [1] and [2]) were aimed at trying to mitigate the effects of the problem. In [1] we were trying to guess which guest CPUs were online to forbid hotunplug of the last online CPU in the QEMU layer, avoiding the scenario described above because QEMU is now failing in behalf of the guest. This is not robust because the last online CPU of the guest can change while we're in the middle of the unplug process, and our initial assumptions are now invalid. In [2] we were accepting that our unplug process is uncertain and the user should be allowed to spam the IRQ hotunplug queue of the guest in case the CPU hotunplug fails.
This patch presents another alternative, using the timeout infrastructure introduced in the previous patch. CPU hotunplugs in the pSeries machine will now timeout after 15 seconds. This is a long time for a single CPU unplug to occur, regardless of guest load - although the user is *strongly* encouraged to *not* hotunplug devices from a guest under high load - and we can be sure that something went wrong if it takes longer than that for the guest to release the CPU (the same can't be said about memory hotunplug - more on that in the next patch).
Timing out the unplug operation will reset the unplug state of the CPU and allow the user to try it again, regardless of the error situation that prevented the hotunplug to occur. Of all the not so pretty fixes/mitigations for CPU hotunplug errors in pSeries, timing out the operation is an admission that we have no control in the process, and must assume the worst case if the operation doesn't succeed in a sensible time frame.
[1] https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg03353.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg04400.html
--- hw/ppc/spapr.c | 4 ++++ hw/ppc/spapr_drc.c | 13 +++++++++++++ include/hw/ppc/spapr_drc.h | 1 + 3 files changed, 18 insertions(+)
hw/ppc/spapr.c +4 -0
@@ -3724,6 +3724,10 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,if (!spapr_drc_unplug_requested (drc)) {spapr_drc_unplug_request (drc);spapr_hotplug_req_remove_by_index (drc); + }else { +error_setg (errp,"core-id %d unplug is still pending, %d seconds " +"timeout remaining" , + cc->core_id,spapr_drc_unplug_timeout_remaining_sec (drc)); } }
hw/ppc/spapr_drc.c +13 -0
@@ -409,6 +409,8 @@ void spapr_drc_unplug_request(SpaprDrc *drc) drc->unplug_requested = true; +spapr_drc_start_unplug_timeout_timer (drc); +if (drc->state != drck->empty_state) {trace_spapr_drc_awaiting_quiesce (spapr_drc_index (drc));return ;
@@ -417,6 +419,16 @@ void spapr_drc_unplug_request(SpaprDrc *drc)spapr_drc_release (drc); } +int spapr_drc_unplug_timeout_remaining_sec (SpaprDrc *drc) +{ +if (drc->unplug_requested &&timer_pending (drc->unplug_timeout_timer)) { +return (qemu_timeout_ns_to_ms (drc->unplug_timeout_timer->expire_time) - +qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL )) /1000 ; + } + +return 0 ; +} +bool spapr_drc_reset (SpaprDrc *drc) {SpaprDrcClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc);
@@ -710,6 +722,7 @@ static void spapr_drc_cpu_class_init(ObjectClass *k, void *data) drck->drc_name_prefix ="CPU " ; drck->release = spapr_core_release; drck->dt_populate = spapr_core_dt_populate; + drck->unplug_timeout_seconds =15 ; }static void spapr_drc_pci_class_init (ObjectClass *k,void *data)
include/hw/ppc/spapr_drc.h +1 -0
@@ -248,6 +248,7 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask);*/ void spapr_drc_attach (SpaprDrc *drc,DeviceState *d);void spapr_drc_unplug_request (SpaprDrc *drc); +int spapr_drc_unplug_timeout_remaining_sec (SpaprDrc *drc);/* * Reset all DRCs, causing pending hot-plug/unplug requests to complete.
Signature · 1 line
2.29.2
PATCH v4 5/5 spapr_drc.c: use DRC reconfiguration to cleanup DIMM unplug state
In reply to Daniel Henrique BarbozaHandling errors in memory hotunplug in the pSeries machine is more complex than any other device type, because there are all the complications that other devices has, and more.
For instance, determining a timeout for a DIMM hotunplug must consider if it's a Hash-MMU or a Radix-MMU guest, because Hash guests takes longer to hotunplug DIMMs. The size of the DIMM is also a factor, given that longer DIMMs naturally takes longer to be hotunplugged from the kernel. And there's also the guest memory usage to be considered: if there's a process that is consuming memory that would be lost by the DIMM unplug, the kernel will postpone the unplug process until the process finishes, and then initiate the regular hotunplug process. The first two considerations are manageable, but the last one is a deal breaker.
There is no sane way for the pSeries machine to determine the memory load in the guest when attempting a DIMM hotunplug - and even if there was a way, the guest can start using all the RAM in the middle of the unplug process and invalidate our previous assumptions - and in result we can't even begin to calculate a timeout for the operation. This means that we can't implement a viable timeout mechanism for memory unplug in pSeries.
Going back to why we would consider an unplug timeout, the reason is that we can't know if the kernel is giving up the unplug. Turns out that, sometimes, we can. Consider a failed memory hotunplug attempt where the kernel will error out with the following message:
'pseries-hotplug-mem: Memory indexed-count-remove failed, adding any removed LMBs'
This happens when there is a LMB that the kernel gave up in removing, and the LMBs previously marked for removal are now being added back. This happens in the pseries kernel in [1], dlpar_memory_remove_by_ic() into dlpar_add_lmb(), and after that update_lmb_associativity_index(). In this function, the kernel is configuring the LMB DRC connector again. Note that this is a valid usage in LOPAR, as stated in section "ibm,configure-connector RTAS Call":
'A subsequent sequence of calls to ibm,configure-connector with the same entry from the “ibm,drc-indexes” or “ibm,drc-info” property will restart the configuration of devices which were not completely configured.'
We can use this kernel behavior in our favor. If a DRC connector reconfiguration for a LMB that we marked as unplug pending happens, this indicates that the kernel changed its mind about the unplug and is reasserting that it will keep using all the LMBs of the DIMM. In this case, it's safe to assume that the whole DIMM device unplug was cancelled.
This patch hops into rtas_ibm_configure_connector() and, in the scenario described above, clear the unplug state for the DIMM device. This will not solve all the problems we still have with memory unplug, but it will cover this case where the kernel reconfigures LMBs after a failed unplug. We are a bit more resilient, without using an unreliable timeout, and we didn't make the remaining error cases any worse.
[1] arch/powerpc/platforms/pseries/hotplug-memory.c
--- hw/ppc/spapr.c | 43 ++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_drc.c | 10 ++++++++++ include/hw/ppc/spapr.h | 2 ++ 3 files changed, 55 insertions(+)
hw/ppc/spapr.c +43 -0
@@ -3575,6 +3575,49 @@ static SpaprDimmState *spapr_recover_pending_dimm_state(SpaprMachineState *ms,return spapr_pending_dimm_unplugs_add (ms, avail_lmbs, dimm); } +void spapr_clear_pending_dimm_unplug_state (SpaprMachineState *spapr, +DeviceState *dev) +{ +SpaprDimmState *ds; +PCDIMMDevice *dimm; +SpaprDrc *drc; +uint32_t nr_lmbs; +uint64_t size, addr_start, addr; +int i; + +if (!dev) { +return ; + } + + dimm =PC_DIMM (dev); + ds =spapr_pending_dimm_unplugs_find (spapr, dimm); + +/* +* 'ds == NULL' would mean that the DIMM doesn't have a pending +* unplug state, but one of its DRC is marked as unplug_requested. +* This is bad and weird enough to g_assert() out. +*/ +g_assert (ds); + +spapr_pending_dimm_unplugs_remove (spapr, ds); + + 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 , + &error_abort); + + addr = addr_start; +for (i =0 ; i < nr_lmbs; i++) { + drc =spapr_drc_by_id (TYPE_SPAPR_DRC_LMB , + addr /SPAPR_MEMORY_BLOCK_SIZE ); +g_assert (drc); + + drc->unplug_requested = false; + addr +=SPAPR_MEMORY_BLOCK_SIZE ; + } +} +/* Callback to be called during DRC release. */ void spapr_lmb_release (DeviceState *dev) {
hw/ppc/spapr_drc.c +10 -0
@@ -1230,6 +1230,16 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu, drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); +/* +* This indicates that the kernel is reconfiguring a LMB due to +* a failed hotunplug. Clear the pending unplug state for the whole +* DIMM. +*/ +if (spapr_drc_type (drc) ==SPAPR_DR_CONNECTOR_TYPE_LMB && + drc->unplug_requested) { +spapr_clear_pending_dimm_unplug_state (spapr, drc->dev); + } +if (!drc->fdt) {void *fdt;int fdt_size;
include/hw/ppc/spapr.h +2 -0
@@ -847,6 +847,8 @@ int spapr_hpt_shift_for_ramsize(uint64_t ramsize);int spapr_reallocate_hpt (SpaprMachineState *spapr,int shift,Error **errp);void spapr_clear_pending_events (SpaprMachineState *spapr);void spapr_clear_pending_hotplug_events (SpaprMachineState *spapr); +void spapr_clear_pending_dimm_unplug_state (SpaprMachineState *spapr, +DeviceState *dev);int spapr_max_server_number (SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1);
Signature · 1 line
2.29.2
David Gibson
AppliedQuoted 4 lines · Daniel Henrique Barboza
Hi,
This new version contains fixes proposed during the review of v3. Patches were rebased on top of David's ppc-for-6.0.
Applied to ppc-for-6.0.
Quoted 43 lines
changes from v3:
- former patch 1: already pushed to ppc-for-6.0
- former patch 2: dropped
- all patches: commit message trimmed to < 76 chars per line
- all patches: added R-bs from previous review
- patch 3:
* removed the migratable state of the unplug timer
* added a 'spapr_drc_start_unplug_timeout_timer()' helper to start the timer
* added a .post_load implementation tovmstate_spapr_drc, pointed to a newspapr_drc_post_load()function
*spapr_drc_post_load()starts the DRC unplug timer from the beginning usingspapr_drc_start_unplug_timeout_timer()- patch 4:
* usespapr_drc_start_unplug_timeout_timer()to start the timer inspapr_drc_unplug_request()(To David: I kept your Reviewed-by in this patch despite this change - feel free to review it again)- patch 5:
* removed the 'DIMM' wording when referring to kernel internals
* move theg_assert()tospapr_clear_pending_dimm_unplug_state()
* do notg_assert(dev), butg_assert(ds)if dev != NULL insidespapr_clear_pending_dimm_unplug_state()- v3 link: https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg04196.html
Daniel Henrique Barboza (5):
spapr_drc.c: usespapr_drc_release()in isolate_physical/set_unusable
spapr: renamespapr_drc_detach()tospapr_drc_unplug_request()spapr_drc.c: introduceunplug_timeout_timer
spapr_drc.c: add hotunplug timeout for CPUs
spapr_drc.c: use DRC reconfiguration to cleanup DIMM unplug statehw/ppc/spapr.c | 53 ++++++++++++++++++-- hw/ppc/spapr_drc.c | 99 +++++++++++++++++++++++++++++++------- hw/ppc/spapr_pci.c | 4 +- hw/ppc/trace-events | 2 +- include/hw/ppc/spapr.h | 2 + include/hw/ppc/spapr_drc.h | 7 ++- 6 files changed, 142 insertions(+), 25 deletions(-)
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