hw/ppc: CAS reset on early device hotplug
v3 cover hw/ppc: CAS reset on early device hotplug
v3:
- split into 3 patches, first 2 are fixes that are independent of the reboot code that can be applied separately:
- patch 1: spapr_drc_needed fix
- patch 2: clear pending_events on reboot, following David's
suggestions on the v2 review.
- patch 3: CAS reboot
v2:
- rebased with ppc-for-2.11
- function 'spapr_cas_completed' dropped
- function 'spapr_drc_needed' made public and it's now used inside 'spapr_hotplugged_dev_before_cas'
- 'spapr_drc_needed' was changed to support the migration of logical DRCs with devs attached in UNUSED state
- new function: 'spapr_clear_pending_events'. This function is used inside ppc_spapr_reset to reset the pending_events QTAILQ
Daniel Henrique Barboza (3):
hw/ppc/spapr_drc.c: change spapr_drc_needed to use drc->dev hw/ppc: clear pending_events on machine reset hw/ppc: CAS reset on early device hotplug
hw/ppc/spapr.c | 27 ++++++++++++++++++++++++++- hw/ppc/spapr_drc.c | 5 ++--- hw/ppc/spapr_events.c | 11 +++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_drc.h | 1 + 5 files changed, 41 insertions(+), 4 deletions(-)
Signature · 1 line
2.9.4
PATCH v3 1/3 hw/ppc/spapr_drc.c: change spapr_drc_needed to use drc->dev
This patch makes a small fix in 'spapr_drc_needed' to change how we detect if a DRC has a device attached. Previously it used dr_entity_sense for this, which works for physical DRCs.
However, for logical DRCs, it didn't cover the case where a logical DRC has a drc->dev but the state is LOGICAL_UNUSABLE (e.g. a hotplugged CPU before CAS). In this case, the dr_entity_sense of this DRC returns UNUSABLE and the code was considering that there were no dev attached, making spapr_drc_needed return 'false' when in fact we would like to migrate the DRC.
Changing it to check for drc->dev instead works for all DRC types.
--- hw/ppc/spapr_drc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc/spapr_drc.c +1 -2
@@ -464,10 +464,9 @@ static bool spapr_drc_needed(void *opaque) {sPAPRDRConnector *drc = (sPAPRDRConnector *)opaque;sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); -sPAPRDREntitySense value = drck->dr_entity_sense (drc);/* If no dev is plugged in there is no need to migrate the DRC state */ -if (value !=SPAPR_DR_ENTITY_SENSE_PRESENT ) { +if (!drc->dev) {return false; }
Signature · 1 line
2.9.4
PATCH v3 2/3 hw/ppc: clear pending_events on machine reset
In reply to Daniel Henrique BarbozaThe sPAPR machine isn't clearing up the pending events QTAILQ on machine reboot. This allows for unprocessed hotplug/epow events to persist in the queue after reset and, when reasserting the IRQs in check_exception later on, these will be being processed by the OS.
This patch implements a new function called 'spapr_clear_pending_events' that clears up the pending_events QTAILQ. This helper is then called inside ppc_spapr_reset to clear up the events queue, preventing old/deprecated events from persisting after a reset.
--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_events.c | 11 +++++++++++ include/hw/ppc/spapr.h | 1 + 3 files changed, 13 insertions(+)
hw/ppc/spapr.c +1 -0
@@ -1392,6 +1392,7 @@ static void ppc_spapr_reset(void) }qemu_devices_reset (); +spapr_clear_pending_events (spapr);/* * We place the device tree and RTAS just below either the top of the RMA,
hw/ppc/spapr_events.c +11 -0
@@ -700,6 +700,17 @@ static void event_scan(PowerPCCPU *cpu, sPAPRMachineState *spapr,rtas_st (rets,0 ,RTAS_OUT_NO_ERRORS_FOUND ); } +void spapr_clear_pending_events (sPAPRMachineState *spapr) +{ +sPAPREventLogEntry *entry =NULL ; + + QTAILQ_FOREACH(entry, &spapr->pending_events, next) { +QTAILQ_REMOVE (&spapr->pending_events, entry, next); +g_free (entry->extended_log); +g_free (entry); + } +} +void spapr_events_init (sPAPRMachineState *spapr) {QTAILQ_INIT (&spapr->pending_events);
include/hw/ppc/spapr.h +1 -0
@@ -662,6 +662,7 @@ void spapr_cpu_parse_features(sPAPRMachineState *spapr);int spapr_hpt_shift_for_ramsize (uint64_t ramsize);void spapr_reallocate_hpt (sPAPRMachineState *spapr,int shift,Error **errp); +void spapr_clear_pending_events (sPAPRMachineState *spapr);/* CPU and LMB DRC release callbacks. */ void spapr_core_release (DeviceState *dev);
Signature · 1 line
2.9.4
PATCH v3 3/3 hw/ppc: CAS reset on early device hotplug
In reply to Daniel Henrique BarbozaThis patch is a follow up on the discussions made in patch "hw/ppc: disable hotplug before CAS is completed" that can be found at [1].
At this moment, we do not support CPU/memory hotplug in early boot stages, before CAS. When a hotplug occurs, the event is logged in an internal RTAS event log queue and an IRQ pulse is fired. In regular conditions, the guest handles the interrupt by executing check_exception, fetching the generated hotplug event and enabling the device for use.
In early boot, this IRQ isn't caught (SLOF does not handle hotplug events), leaving the event in the rtas event log queue. If the guest executes check_exception due to another hotplug event, the re-assertion of the IRQ ends up de-queuing the first hotplug event as well. In short, a device hotplugged before CAS is considered coldplugged by SLOF. This leads to device misbehavior and, in some cases, guest kernel Ooops when trying to unplug the device.
A proper fix would be to turn every device hotplugged before CAS as a colplugged device. This is not trivial to do with the current code base though - the FDT is written in the guest memory at ppc_spapr_reset and can't be retrieved without adding extra state (fdt_size for example) that will need to managed and migrated. Adding the hotplugged DT in the middle of CAS negotiation via the updated DT tree works with CPU devs, but panics the guest kernel at boot. Additional analysis would be necessary for LMBs and PCI devices. There are questions to be made in QEMU/SLOF/kernel level about how we can make this change in a sustainable way.
With Linux guests, a fix would be the kernel executing check_exception at boot time, de-queueing the events that happened in early boot and processing them. However, even if/when the newer kernels start fetching these events at boot time, we need to take care of older kernels that won't be doing that.
This patch works around the situation by issuing a CAS reset if a hotplugged device is detected during CAS:
- the DRC conditions that warrant a CAS reset is the same as those that triggers a DRC migration - the DRC must have a device attached and the DRC state is not equal to its ready_state. With that in mind, this patch makes use of 'spapr_drc_needed' to determine if a CAS reset is needed.
- In the middle of CAS negotiations, the function 'spapr_hotplugged_dev_before_cas' goes through all the DRCs to see if there are any DRC that requires a reset, using spapr_drc_needed. If that happens, returns '1' in 'spapr_h_cas_compose_response' which will set spapr->cas_reboot to true, causing the machine to reboot.
No changes are made for coldplug devices.
[1] http://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02855.html
--- hw/ppc/spapr.c | 26 +++++++++++++++++++++++++- hw/ppc/spapr_drc.c | 2 +- include/hw/ppc/spapr_drc.h | 1 + 3 files changed, 27 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +25 -1
@@ -790,6 +790,26 @@ out:return ret; } +static bool spapr_hotplugged_dev_before_cas (void ) +{ +Object *drc_container, *obj; +ObjectProperty *prop; +ObjectPropertyIterator iter; + + drc_container =container_get (object_get_root (),"/dr-connector" ); +object_property_iter_init (&iter, drc_container); +while ((prop =object_property_iter_next (&iter))) { +if (!strstart (prop->type,"link<" ,NULL )) { +continue ; + } + obj =object_property_get_link (drc_container, prop->name,NULL ); +if (spapr_drc_needed (obj)) { +return true; + } + } +return false; +} +int spapr_h_cas_compose_response (sPAPRMachineState *spapr,target_ulong addr,target_ulong size,sPAPROptionVector *ov5_updates)
@@ -797,9 +817,13 @@ int spapr_h_cas_compose_response(sPAPRMachineState *spapr,void *fdt, *fdt_skel;sPAPRDeviceTreeUpdateHeader hdr = { .version_id =1 }; +if (spapr_hotplugged_dev_before_cas ()) { +return 1 ; + } + size -=sizeof (hdr); -/* Create sceleton */ +/* Create skeleton */ fdt_skel =g_malloc0 (size);_FDT ((fdt_create (fdt_skel, size)));_FDT ((fdt_begin_node (fdt_skel,"" )));
hw/ppc/spapr_drc.c +1 -1
@@ -460,7 +460,7 @@ static void drc_reset(void *opaque)spapr_drc_reset (SPAPR_DR_CONNECTOR (opaque)); } -static bool spapr_drc_needed (void *opaque) +bool spapr_drc_needed (void *opaque) {sPAPRDRConnector *drc = (sPAPRDRConnector *)opaque;sPAPRDRConnectorClass *drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc);
include/hw/ppc/spapr_drc.h +1 -0
@@ -257,6 +257,7 @@ int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,void spapr_drc_attach (sPAPRDRConnector *drc,DeviceState *d,void *fdt,int fdt_start_offset,Error **errp);void spapr_drc_detach (sPAPRDRConnector *drc); +bool spapr_drc_needed (void *opaque);static inline bool spapr_drc_unplug_requested (sPAPRDRConnector *drc) {
Signature · 1 line
2.9.4
David Gibson
AppliedQuoted 8 lines · Daniel Henrique Barboza
v3:
- split into 3 patches, first 2 are fixes that are independent of the reboot code that can be applied separately:
- patch 1:spapr_drc_neededfix
- patch 2: clearpending_eventson reboot, following David's
suggestions on the v2 review.
- patch 3: CAS reboot
Quoted 9 lines
v2:
- rebased with ppc-for-2.11
- function 'spapr_cas_completed' dropped
- function 'spapr_drc_needed' made public and it's now used inside 'spapr_hotplugged_dev_before_cas'
- 'spapr_drc_needed' was changed to support the migration of logical DRCs with devs attached in UNUSED state
- new function: 'spapr_clear_pending_events'. This function is used insideppc_spapr_resetto reset thepending_eventsQTAILQ
Applied to ppc-for-2.11. The first two I'm also considering sending off for the 2.10 stable branch.
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