From nobody Wed Nov 5 15:40:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496898784623744.9942243418684; Wed, 7 Jun 2017 22:13:04 -0700 (PDT) Received: from localhost ([::1]:47366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIpkl-00016x-9T for importer@patchew.org; Thu, 08 Jun 2017 01:13:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIphU-0006X2-Ux for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIphQ-0008O1-6T for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:40 -0400 Received: from ozlabs.org ([103.22.144.67]:46671) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIphP-0008NI-QF; Thu, 08 Jun 2017 01:09:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjtl13jSqz9s7f; Thu, 8 Jun 2017 15:09:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496898573; bh=VlV7Velb2Ldaq3mnQYln5Z2M/xitGex1BVz5Ma8Rcj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k43okfPToKW+4lwZLbKFd7hZpyzb+0Ef9Dn6P94MQhXCvJyZJoV/2z60JpQDYq93+ 3OvgxB5EtWPUew4qduK9i7VN/jSJ0SLlh7X1bOxLDUngoZfD5R9y4FfDu3C3PDHOuJ mDH5aLhzxzBQM7knV2AU3wIqHsMU0nga4Zew8Rfs= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Thu, 8 Jun 2017 15:09:25 +1000 Message-Id: <20170608050930.2613-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608050930.2613-1-david@gibson.dropbear.id.au> References: <20170608050930.2613-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PATCH 1/6] spapr: Start hotplugged PCI devices in ISOLATED state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" PCI DRCs, and only PCI DRCs, are immediately moved to UNISOLATED isolation state once the device is attached. This has been there from the initial implementation, and it's not clear why. The state diagram in PAPR 13.4 suggests PCI devices should start in ISOLATED state until the guest moves them into UNISOLATED, and the code in the guest-side drmgr tool seems to work that way too. Signed-off-by: David Gibson Reviewed-by: Michael Roth Reviewed-by: Greg Kurz --- hw/ppc/spapr_drc.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 15ef67d..6186f79 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -315,16 +315,6 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceSta= te *d, void *fdt, } g_assert(fdt || coldplug); =20 - /* NOTE: setting initial isolation state to UNISOLATED means we can't - * detach unless guest has a userspace/kernel that moves this state - * back to ISOLATED in response to an unplug event, or this is done - * manually by the admin prior. if we force things while the guest - * may be accessing the device, we can easily crash the guest, so we - * we defer completion of removal in such cases to the reset() hook. - */ - if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; - } drc->dr_indicator =3D SPAPR_DR_INDICATOR_ACTIVE; =20 drc->dev =3D d; --=20 2.9.4 From nobody Wed Nov 5 15:40:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496898668414318.3640152298059; Wed, 7 Jun 2017 22:11:08 -0700 (PDT) Received: from localhost ([::1]:47359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIpir-0007WA-Sw for importer@patchew.org; Thu, 08 Jun 2017 01:11:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIphS-0006Wr-LQ for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIphQ-0008OQ-RJ for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:38 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:57337) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIphQ-0008NH-6Z; Thu, 08 Jun 2017 01:09:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjtl072sWz9s78; Thu, 8 Jun 2017 15:09:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496898572; bh=Yf70pY4asAlDjI8Sld85ZFwMKG6qZOlTggNQqDTXqFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gCsVpXXVrI5hW3bQOXiR4PUTqRm22XylH8hkGEc476q7QnNtsRGqgKtOJbZYPAEaP Fnt9xCT0lZncC5pKN/CWKRyGgiAsSEgQqcS75CMccgbOKNDZEbuB3QMrLQ7o1wZReK pG1poe5V6SNlQVvFtOnLcshOJjtGvf1TXZXQo31A= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Thu, 8 Jun 2017 15:09:26 +1000 Message-Id: <20170608050930.2613-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608050930.2613-1-david@gibson.dropbear.id.au> References: <20170608050930.2613-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCH 2/6] spapr: Eliminate DRC 'signalled' state variable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The 'signalled' field in the DRC appears to be entirely a torturous workaround for the fact that PCI devices were started in UNISOLATED state for unclear reasons. 1) 'signalled' is already meaningless for logical (so far, all non PCI) DRCs. It's always set to true (at least at any point it might be tested), and can't be assigned any real meaning due to the way signalling works for logical DRCs. 2) For PCI DRCs, the only time signalled would be false is when non-zero functions of a multifunction device are hotplugged, followed by function zero (the other way around is explicitly not permitted). In that case the secondary function DRCs are attached, but the notification isn't sent to the guest until function 0 is plugged. 3) signalled being false is used to allow a DRC detach to switch mode back to ISOLATED state, which allows a secondary function to be hotplugged then unplugged with function 0 never inserted. Without this a secondary function starting in UNISOLATED state couldn't be detached again without function 0 being inserted, all the functions configured by the guest, then sent back to ISOLATED state. 4) But now that PCI DRCs start in ISOLATED state, there's nothing to be done. If the guest doesn't get the notification, it won't switch the device to UNISOLATED state, so nothing prevents it from being unplugged. If the guest does move it to UNISOLATED state without the signal (due to a manual drmgr call, for instance) then it really isn't safe to unplug it. So, this patch removes the signalled variable and all code related to it. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 45 +-----------------------------------------= --- hw/ppc/spapr_events.c | 10 ---------- include/hw/ppc/spapr_drc.h | 2 -- 3 files changed, 1 insertion(+), 56 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 6186f79..afd68f4 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -183,12 +183,6 @@ static const char *spapr_drc_name(sPAPRDRConnector *dr= c) return g_strdup_printf("%s%d", drck->drc_name_prefix, drc->id); } =20 -/* has the guest been notified of device attachment? */ -static void set_signalled(sPAPRDRConnector *drc) -{ - drc->signalled =3D true; -} - /* * dr-entity-sense sensor value * returned via get-sensor-state RTAS calls @@ -321,17 +315,6 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceSta= te *d, void *fdt, drc->fdt =3D fdt; drc->fdt_start_offset =3D fdt_start_offset; drc->configured =3D coldplug; - /* 'logical' DR resources such as memory/cpus are in some cases treated - * as a pool of resources from which the guest is free to choose from - * based on only a count. for resources that can be assigned in this - * fashion, we must assume the resource is signalled immediately - * since a single hotplug request might make an arbitrary number of - * such attached resources available to the guest, as opposed to - * 'physical' DR resources such as PCI where each device/resource is - * signalled individually. - */ - drc->signalled =3D (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_P= CI) - ? true : coldplug; =20 if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { drc->awaiting_allocation =3D true; @@ -347,26 +330,6 @@ void spapr_drc_detach(sPAPRDRConnector *drc, DeviceSta= te *d, Error **errp) { trace_spapr_drc_detach(spapr_drc_index(drc)); =20 - /* 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 - * for the guest to quiesce the device before completing detach. - * Otherwise, we can assume the guest hasn't seen it and complete the - * detach immediately. Note that there is a small race window - * just before, or during, configuration, which is this context - * refers mainly to fetching the device tree via RTAS. - * During this window the device access will be arbitrated by - * associated DRC, which will simply fail the RTAS calls as invalid. - * This is recoverable within guest and current implementations of - * drmgr should be able to cope. - */ - if (!drc->signalled && !drc->configured) { - /* if the guest hasn't seen the device we can't rely on it to - * set it back to an isolated state via RTAS, so do it here manual= ly - */ - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; - } - if (drc->isolation_state !=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { trace_spapr_drc_awaiting_isolated(spapr_drc_index(drc)); drc->awaiting_release =3D true; @@ -455,10 +418,6 @@ static void reset(DeviceState *d) drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_UNUS= ABLE); } } - - if (drck->dr_entity_sense(drc) =3D=3D SPAPR_DR_ENTITY_SENSE_PRESENT) { - drck->set_signalled(drc); - } } =20 static bool spapr_drc_needed(void *opaque) @@ -483,7 +442,7 @@ static bool spapr_drc_needed(void *opaque) case SPAPR_DR_CONNECTOR_TYPE_LMB: rc =3D !((drc->isolation_state =3D=3D SPAPR_DR_ISOLATION_STATE_UNI= SOLATED) && (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_USA= BLE) && - drc->configured && drc->signalled && !drc->awaiting_release= ); + drc->configured && !drc->awaiting_release); break; case SPAPR_DR_CONNECTOR_TYPE_PHB: case SPAPR_DR_CONNECTOR_TYPE_VIO: @@ -505,7 +464,6 @@ static const VMStateDescription vmstate_spapr_drc =3D { VMSTATE_BOOL(configured, sPAPRDRConnector), VMSTATE_BOOL(awaiting_release, sPAPRDRConnector), VMSTATE_BOOL(awaiting_allocation, sPAPRDRConnector), - VMSTATE_BOOL(signalled, sPAPRDRConnector), VMSTATE_END_OF_LIST() } }; @@ -603,7 +561,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) drck->set_isolation_state =3D set_isolation_state; drck->set_allocation_state =3D set_allocation_state; drck->release_pending =3D release_pending; - drck->set_signalled =3D set_signalled; /* * Reason: it crashes FIXME find and document the real reason */ diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index 171aedc..587a3da 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -475,13 +475,6 @@ static void spapr_powerdown_req(Notifier *n, void *opa= que) RTAS_LOG_TYPE_EPOW)= )); } =20 -static void spapr_hotplug_set_signalled(uint32_t drc_index) -{ - sPAPRDRConnector *drc =3D spapr_drc_by_index(drc_index); - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->set_signalled(drc); -} - static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action, sPAPRDRConnectorType drc_type, union drc_identifier *drc_id) @@ -528,9 +521,6 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint= 8_t hp_action, switch (drc_type) { case SPAPR_DR_CONNECTOR_TYPE_PCI: hp->hotplug_type =3D RTAS_LOG_V6_HP_TYPE_PCI; - if (hp->hotplug_action =3D=3D RTAS_LOG_V6_HP_ACTION_ADD) { - spapr_hotplug_set_signalled(drc_id->index); - } break; case SPAPR_DR_CONNECTOR_TYPE_LMB: hp->hotplug_type =3D RTAS_LOG_V6_HP_TYPE_MEMORY; diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index c487123..f24188d 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -199,7 +199,6 @@ typedef struct sPAPRDRConnector { sPAPRConfigureConnectorState *ccs; =20 bool awaiting_release; - bool signalled; bool awaiting_allocation; bool awaiting_allocation_skippable; =20 @@ -226,7 +225,6 @@ typedef struct sPAPRDRConnectorClass { =20 /* QEMU interfaces for managing hotplug operations */ bool (*release_pending)(sPAPRDRConnector *drc); - void (*set_signalled)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass; =20 uint32_t spapr_drc_index(sPAPRDRConnector *drc); --=20 2.9.4 From nobody Wed Nov 5 15:40:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496898669998829.2744968389534; Wed, 7 Jun 2017 22:11:09 -0700 (PDT) Received: from localhost ([::1]:47360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIpiu-0007Y2-MR for importer@patchew.org; Thu, 08 Jun 2017 01:11:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIphV-0006X4-14 for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIphQ-0008OD-Bg for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:40 -0400 Received: from ozlabs.org ([103.22.144.67]:41911) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIphQ-0008NO-03; Thu, 08 Jun 2017 01:09:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjtl15ryQz9s89; Thu, 8 Jun 2017 15:09:33 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496898573; bh=swPlbR0Kq7hiO7WecekrxW/oS2aPgvDs/4xQtr0yxI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FiWLMy5W8w8prbmB5qJIwAotN41Aex6leIlXJmEd8NrnaSlqwSAgQ+Y9JxAk+0As/ gW6IH9cfcw4foK/rVrREcxl6DkIugXXSAah1+mHwZ3ciTzfYbkXq96uANcKNLF00OC J/j9BGTi0/oIFoe5fKEZaDi0Fgf8sjOIPx4uJM9Y= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Thu, 8 Jun 2017 15:09:27 +1000 Message-Id: <20170608050930.2613-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608050930.2613-1-david@gibson.dropbear.id.au> References: <20170608050930.2613-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PATCH 3/6] spapr: Split DRC release from DRC detach X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" spapr_drc_detach() is called when qemu generic code requests a device be unplugged. It makes a number of tests, which could well delay further action until later, before actually detach the device from the DRC. This splits out the part which actually removes the device from the DRC into spapr_drc_release(). This will be useful for further cleanups. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 54 ++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index afd68f4..dc4ac77 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -326,31 +326,9 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceSta= te *d, void *fdt, NULL, 0, NULL); } =20 -void spapr_drc_detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp) -{ - trace_spapr_drc_detach(spapr_drc_index(drc)); - - if (drc->isolation_state !=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { - trace_spapr_drc_awaiting_isolated(spapr_drc_index(drc)); - drc->awaiting_release =3D true; - return; - } - - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI && - drc->allocation_state !=3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { - trace_spapr_drc_awaiting_unusable(spapr_drc_index(drc)); - drc->awaiting_release =3D true; - return; - } - - if (drc->awaiting_allocation) { - if (!drc->awaiting_allocation_skippable) { - drc->awaiting_release =3D true; - trace_spapr_drc_awaiting_allocation(spapr_drc_index(drc)); - return; - } - } =20 +static void spapr_drc_release(sPAPRDRConnector *drc) +{ drc->dr_indicator =3D SPAPR_DR_INDICATOR_INACTIVE; =20 /* Calling release callbacks based on spapr_drc_type(drc). */ @@ -379,6 +357,34 @@ void spapr_drc_detach(sPAPRDRConnector *drc, DeviceSta= te *d, Error **errp) drc->dev =3D NULL; } =20 +void spapr_drc_detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp) +{ + trace_spapr_drc_detach(spapr_drc_index(drc)); + + if (drc->isolation_state !=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { + trace_spapr_drc_awaiting_isolated(spapr_drc_index(drc)); + drc->awaiting_release =3D true; + return; + } + + if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI && + drc->allocation_state !=3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { + trace_spapr_drc_awaiting_unusable(spapr_drc_index(drc)); + drc->awaiting_release =3D true; + return; + } + + if (drc->awaiting_allocation) { + if (!drc->awaiting_allocation_skippable) { + drc->awaiting_release =3D true; + trace_spapr_drc_awaiting_allocation(spapr_drc_index(drc)); + return; + } + } + + spapr_drc_release(drc); +} + static bool release_pending(sPAPRDRConnector *drc) { return drc->awaiting_release; --=20 2.9.4 From nobody Wed Nov 5 15:40:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496898670995651.8239513497762; Wed, 7 Jun 2017 22:11:10 -0700 (PDT) Received: from localhost ([::1]:47361 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIpiv-0007ZK-GV for importer@patchew.org; Thu, 08 Jun 2017 01:11:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIphV-0006X6-2g for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIphQ-0008O7-92 for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:41 -0400 Received: from ozlabs.org ([103.22.144.67]:47035) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIphP-0008NM-UA; Thu, 08 Jun 2017 01:09:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjtl151Jkz9s7M; Thu, 8 Jun 2017 15:09:33 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496898573; bh=3agrDNwrxO7Pkfmb3WdjQlhcvorY0ukZOXnsJgDOK7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MNRgD3oaR6kEfqIBvh/3qoqLdUgwNoigMNPMDeulW+ETSLgsw46IsVvKnljRn952i IWGYIW0SR0j/kJNu+wGDhARDvFiQMlHU9Lnq45gdm2vsv6g5T8h4LEq0HSFdORG8+O BWB2XbclTOynap5O4GVSOKbLz9q5lsubWosP+oMA= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Thu, 8 Jun 2017 15:09:28 +1000 Message-Id: <20170608050930.2613-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608050930.2613-1-david@gibson.dropbear.id.au> References: <20170608050930.2613-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PATCH 4/6] spapr: Make DRC reset force DRC into known state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The reset handler for DRCs attempts several state transitions which are subject to various checks and restrictions. But at reset time we know there is no guest, so we can ignore most of the usual sequencing rules and just set the DRC back to a known state. In fact, it's safer to do so. The existing code also has several redundant checks for drc->awaiting_release inside a block which has already tested that. This patch removes those and sets the DRC to a fixed initial state based only on whether a device is currently plugged or not. With DRCs correctly reset to a state based on device presence, we don't need to force state transitions as cold plugged devices are processed. This allows us to remove all the callers of the set_*_state() methods from outside spapr_drc.c. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr.c | 15 --------------- hw/ppc/spapr_drc.c | 28 ++++++++-------------------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 01dda9e..c988e38 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2545,12 +2545,6 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_= t addr_start, uint64_t size, =20 spapr_drc_attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, errp= ); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; - if (!dev->hotplugged) { - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(d= rc); - /* guests expect coldplugged LMBs to be pre-allocated */ - drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USAB= LE); - drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOL= ATED); - } } /* send hotplug notification to the * guest only in case of hotplugged memory @@ -2901,15 +2895,6 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, * of hotplugged CPUs. */ spapr_hotplug_req_add_by_index(drc); - } else { - /* - * Set the right DRC states for cold plugged CPU. - */ - if (drc) { - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(d= rc); - drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USAB= LE); - drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOL= ATED); - } } core_slot->cpu =3D OBJECT(dev); } diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index dc4ac77..7e17f34 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -393,7 +393,6 @@ static bool release_pending(sPAPRDRConnector *drc) static void reset(DeviceState *d) { sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(d); - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 trace_spapr_drc_reset(spapr_drc_index(drc)); =20 @@ -401,28 +400,17 @@ static void reset(DeviceState *d) drc->ccs =3D NULL; =20 /* immediately upon reset we can safely assume DRCs whose devices - * are pending removal can be safely removed, and that they will - * subsequently be left in an ISOLATED state. move the DRC to this - * state in these cases (which will in turn complete any pending - * device removals) + * are pending removal can be safely removed. */ if (drc->awaiting_release) { - drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_ISOLATED); - /* generally this should also finalize the removal, but if the dev= ice - * hasn't yet been configured we normally defer removal under the - * assumption that this transition is taking place as part of devi= ce - * configuration. so check if we're still waiting after this, and - * force removal if we are - */ - if (drc->awaiting_release) { - spapr_drc_detach(drc, DEVICE(drc->dev), NULL); - } + spapr_drc_release(drc); + } =20 - /* non-PCI devices may be awaiting a transition to UNUSABLE */ - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI && - drc->awaiting_release) { - drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_UNUS= ABLE); - } + drc->isolation_state =3D drc->dev ? SPAPR_DR_ISOLATION_STATE_UNISOLATED + : SPAPR_DR_ISOLATION_STATE_ISOLATED; + if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { + drc->allocation_state =3D drc->dev ? SPAPR_DR_ALLOCATION_STATE_USA= BLE + : SPAPR_DR_ALLOCATION_STATE_UNUSABLE; } } =20 --=20 2.9.4 From nobody Wed Nov 5 15:40:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496898787291974.5981142831264; Wed, 7 Jun 2017 22:13:07 -0700 (PDT) Received: from localhost ([::1]:47367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIpkn-0001C2-LG for importer@patchew.org; Thu, 08 Jun 2017 01:13:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIphV-0006X5-22 for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIphS-0008Ok-EC for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:41 -0400 Received: from ozlabs.org ([103.22.144.67]:37589) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIphS-0008OH-28; Thu, 08 Jun 2017 01:09:38 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjtl16XfWz9s7m; Thu, 8 Jun 2017 15:09:33 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496898573; bh=ae2UYkUNHtI9dJ/k/w45rG8kM3kHBPF2uXVwYePqu7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mTZA8rI1Wd5iPE/JpFhqEwSn1IIVZla70mglKGW2Q/g2KR2r4fG4PmULW0wnlveaK yqi0xAIJSxJwePdwA0+KuKvimwwBKzX7uiFWxgmnevfBtN25T76jycC0QF3V3vHS6w R7G1zmjBORTXW+3bJbktJ0V9lWXMaRcVSJapj0B8= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Thu, 8 Jun 2017 15:09:29 +1000 Message-Id: <20170608050930.2613-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608050930.2613-1-david@gibson.dropbear.id.au> References: <20170608050930.2613-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PATCH 5/6] spapr: Clean up DRC set_allocation_state path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The allocation-state indicator should only actually be implemented for "logical" DRCs, not physical ones. Factor a check for this, and also for valid indicator state values into rtas_set_allocation_state(). Because they don't exist for physical DRCs, there's no reason that we'd ever want more than one method implementation, so it can just be a plain function. In addition, the setting to USABLE and setting to UNUSABLE paths in set_allocation_state() don't actually have much in common. So, split the method separate functions for each parameter value (drc_set_usable() and drc_set_unusable()). Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 85 +++++++++++++++++++++++++-----------------= ---- include/hw/ppc/spapr_drc.h | 2 -- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 7e17f34..9e01d7b 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -114,44 +114,43 @@ static uint32_t set_isolation_state(sPAPRDRConnector = *drc, return RTAS_OUT_SUCCESS; } =20 -static uint32_t set_allocation_state(sPAPRDRConnector *drc, - sPAPRDRAllocationState state) +static uint32_t drc_set_usable(sPAPRDRConnector *drc) { - trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state); - - if (state =3D=3D SPAPR_DR_ALLOCATION_STATE_USABLE) { - /* if there's no resource/device associated with the DRC, there's - * no way for us to put it in an allocation state consistent with - * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should - * result in an RTAS return code of -3 / "no such indicator" + /* if there's no resource/device associated with the DRC, there's + * no way for us to put it in an allocation state consistent with + * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should + * result in an RTAS return code of -3 / "no such indicator" + */ + if (!drc->dev) { + return RTAS_OUT_NO_SUCH_INDICATOR; + } + if (drc->awaiting_release && drc->awaiting_allocation) { + /* kernel is acknowledging a previous hotplug event + * while we are already removing it. + * it's safe to ignore awaiting_allocation here since we know the + * situation is predicated on the guest either already having done + * so (boot-time hotplug), or never being able to acquire in the + * first place (hotplug followed by immediate unplug). */ - if (!drc->dev) { - return RTAS_OUT_NO_SUCH_INDICATOR; - } - if (drc->awaiting_release && drc->awaiting_allocation) { - /* kernel is acknowledging a previous hotplug event - * while we are already removing it. - * it's safe to ignore awaiting_allocation here since we know = the - * situation is predicated on the guest either already having = done - * so (boot-time hotplug), or never being able to acquire in t= he - * first place (hotplug followed by immediate unplug). - */ - drc->awaiting_allocation_skippable =3D true; - return RTAS_OUT_NO_SUCH_INDICATOR; - } + drc->awaiting_allocation_skippable =3D true; + return RTAS_OUT_NO_SUCH_INDICATOR; } =20 - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - drc->allocation_state =3D state; - if (drc->awaiting_release && - drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABL= E) { - uint32_t drc_index =3D spapr_drc_index(drc); - trace_spapr_drc_set_allocation_state_finalizing(drc_index); - spapr_drc_detach(drc, DEVICE(drc->dev), NULL); - } else if (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_= USABLE) { - drc->awaiting_allocation =3D false; - } + drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_USABLE; + drc->awaiting_allocation =3D false; + + return RTAS_OUT_SUCCESS; +} + +static uint32_t drc_set_unusable(sPAPRDRConnector *drc) +{ + drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE; + if (drc->awaiting_release) { + uint32_t drc_index =3D spapr_drc_index(drc); + trace_spapr_drc_set_allocation_state_finalizing(drc_index); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); } + return RTAS_OUT_SUCCESS; } =20 @@ -553,7 +552,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) dk->realize =3D realize; dk->unrealize =3D unrealize; drck->set_isolation_state =3D set_isolation_state; - drck->set_allocation_state =3D set_allocation_state; drck->release_pending =3D release_pending; /* * Reason: it crashes FIXME find and document the real reason @@ -823,14 +821,23 @@ static uint32_t rtas_set_isolation_state(uint32_t idx= , uint32_t state) static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state) { sPAPRDRConnector *drc =3D spapr_drc_by_index(idx); - sPAPRDRConnectorClass *drck; =20 - if (!drc) { - return RTAS_OUT_PARAM_ERROR; + if (!drc || !object_dynamic_cast(OBJECT(drc), TYPE_SPAPR_DRC_LOGICAL))= { + return RTAS_OUT_NO_SUCH_INDICATOR; } =20 - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - return drck->set_allocation_state(drc, state); + trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state); + + switch (state) { + case SPAPR_DR_ALLOCATION_STATE_USABLE: + return drc_set_usable(drc); + + case SPAPR_DR_ALLOCATION_STATE_UNUSABLE: + return drc_set_unusable(drc); + + default: + return RTAS_OUT_PARAM_ERROR; + } } =20 static uint32_t rtas_set_dr_indicator(uint32_t idx, uint32_t state) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index f24188d..0e09afb 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -220,8 +220,6 @@ typedef struct sPAPRDRConnectorClass { /* accessors for guest-visible (generally via RTAS) DR state */ uint32_t (*set_isolation_state)(sPAPRDRConnector *drc, sPAPRDRIsolationState state); - uint32_t (*set_allocation_state)(sPAPRDRConnector *drc, - sPAPRDRAllocationState state); =20 /* QEMU interfaces for managing hotplug operations */ bool (*release_pending)(sPAPRDRConnector *drc); --=20 2.9.4 From nobody Wed Nov 5 15:40:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496898889263700.3648097982699; Wed, 7 Jun 2017 22:14:49 -0700 (PDT) Received: from localhost ([::1]:47375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIpmR-0002jG-V7 for importer@patchew.org; Thu, 08 Jun 2017 01:14:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIphU-0006X1-PT for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIphT-0008P3-4d for qemu-devel@nongnu.org; Thu, 08 Jun 2017 01:09:40 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:58253) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIphS-0008OJ-Ew; Thu, 08 Jun 2017 01:09:39 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjtl2168Xz9s9Y; Thu, 8 Jun 2017 15:09:33 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496898574; bh=lAIK77GU57G3xlRtRO+upqk3jwapv2Xa95xtil8+EK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gr4+ce4rZEBAjwANxkCwINkJATZl+DLqyjsjHyTqXBPDFgcVqF6EEOJ9vvfPX+eC7 4fE1zhjeWQi9g/p0WA31i03nvOZ9l6Za/oauqwF6igrvstce3M+bv3q/s2Bzz/v5jj jXCxyRlp6I50NWV1G5IcgOD4Eyw0xUXYMnnkSxys= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Thu, 8 Jun 2017 15:09:30 +1000 Message-Id: <20170608050930.2613-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608050930.2613-1-david@gibson.dropbear.id.au> References: <20170608050930.2613-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCH 6/6] spapr: Clean up DRC set_isolation_state() path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There are substantial differences in the various paths through set_isolation_state(), both for setting to ISOLATED versus UNISOLATED state and for logical versus physical DRCs. So, split the set_isolation_state() method into isolate() and unisolate() methods, and give it different implementations for the two DRC types. Factor some minimal common checks, including for valid indicator values (which we weren't previously checking) into rtas_set_isolation_state(). Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 145 ++++++++++++++++++++++++++++++++---------= ---- include/hw/ppc/spapr_drc.h | 6 +- 2 files changed, 105 insertions(+), 46 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 9e01d7b..90c0fde 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -46,30 +46,64 @@ uint32_t spapr_drc_index(sPAPRDRConnector *drc) | (drc->id & DRC_INDEX_ID_MASK); } =20 -static uint32_t set_isolation_state(sPAPRDRConnector *drc, - sPAPRDRIsolationState state) +static uint32_t drc_isolate_physical(sPAPRDRConnector *drc) { - trace_spapr_drc_set_isolation_state(spapr_drc_index(drc), state); - /* if the guest is configuring a device attached to this DRC, we * should reset the configuration state at this point since it may * no longer be reliable (guest released device and needs to start * over, or unplug occurred so the FDT is no longer valid) */ - if (state =3D=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { - g_free(drc->ccs); - drc->ccs =3D NULL; - } + g_free(drc->ccs); + drc->ccs =3D NULL; =20 - if (state =3D=3D SPAPR_DR_ISOLATION_STATE_UNISOLATED) { - /* cannot unisolate a non-existent resource, and, or resources - * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, 13.5.3.= 5) - */ - if (!drc->dev || - drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABL= E) { - return RTAS_OUT_NO_SUCH_INDICATOR; + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; + + /* if we're awaiting release, but still in an unconfigured state, + * it's likely the guest is still in the process of configuring + * the device and is transitioning the devices to an ISOLATED + * state as a part of that process. so we only complete the + * removal when this transition happens for a device in a + * configured state, as suggested by the state diagram from PAPR+ + * 2.7, 13.4 + */ + if (drc->awaiting_release) { + uint32_t drc_index =3D spapr_drc_index(drc); + if (drc->configured) { + trace_spapr_drc_set_isolation_state_finalizing(drc_index); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); + } else { + trace_spapr_drc_set_isolation_state_deferring(drc_index); } } + drc->configured =3D false; + + return RTAS_OUT_SUCCESS; +} + +static uint32_t drc_unisolate_physical(sPAPRDRConnector *drc) +{ + /* cannot unisolate a non-existent resource, and, or resources + * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, + * 13.5.3.5) + */ + if (!drc->dev) { + return RTAS_OUT_NO_SUCH_INDICATOR; + } + + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; + + return RTAS_OUT_SUCCESS; +} + +static uint32_t drc_isolate_logical(sPAPRDRConnector *drc) +{ + /* if the guest is configuring a device attached to this DRC, we + * should reset the configuration state at this point since it may + * no longer be reliable (guest released device and needs to start + * over, or unplug occurred so the FDT is no longer valid) + */ + g_free(drc->ccs); + drc->ccs =3D NULL; =20 /* * Fail any requests to ISOLATE the LMB DRC if this LMB doesn't @@ -81,35 +115,47 @@ static uint32_t set_isolation_state(sPAPRDRConnector *= drc, * If the LMB being removed doesn't belong to a DIMM device that is * actually being unplugged, fail the isolation request here. */ - if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_LMB) { - if ((state =3D=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) && - !drc->awaiting_release) { - return RTAS_OUT_HW_ERROR; - } + if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_LMB + && !drc->awaiting_release) { + return RTAS_OUT_HW_ERROR; } =20 - drc->isolation_state =3D state; + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; =20 - if (drc->isolation_state =3D=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { - /* if we're awaiting release, but still in an unconfigured state, - * it's likely the guest is still in the process of configuring - * the device and is transitioning the devices to an ISOLATED - * state as a part of that process. so we only complete the - * removal when this transition happens for a device in a - * configured state, as suggested by the state diagram from - * PAPR+ 2.7, 13.4 - */ - if (drc->awaiting_release) { - uint32_t drc_index =3D spapr_drc_index(drc); - if (drc->configured) { - trace_spapr_drc_set_isolation_state_finalizing(drc_index); - spapr_drc_detach(drc, DEVICE(drc->dev), NULL); - } else { - trace_spapr_drc_set_isolation_state_deferring(drc_index); - } + /* if we're awaiting release, but still in an unconfigured state, + * it's likely the guest is still in the process of configuring + * the device and is transitioning the devices to an ISOLATED + * state as a part of that process. so we only complete the + * removal when this transition happens for a device in a + * configured state, as suggested by the state diagram from PAPR+ + * 2.7, 13.4 + */ + if (drc->awaiting_release) { + uint32_t drc_index =3D spapr_drc_index(drc); + if (drc->configured) { + trace_spapr_drc_set_isolation_state_finalizing(drc_index); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); + } else { + trace_spapr_drc_set_isolation_state_deferring(drc_index); } - drc->configured =3D false; } + drc->configured =3D false; + + return RTAS_OUT_SUCCESS; +} + +static uint32_t drc_unisolate_logical(sPAPRDRConnector *drc) +{ + /* cannot unisolate a non-existent resource, and, or resources + * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, + * 13.5.3.5) + */ + if (!drc->dev || + drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { + return RTAS_OUT_NO_SUCH_INDICATOR; + } + + drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; =20 return RTAS_OUT_SUCCESS; } @@ -551,7 +597,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) dk->reset =3D reset; dk->realize =3D realize; dk->unrealize =3D unrealize; - drck->set_isolation_state =3D set_isolation_state; drck->release_pending =3D release_pending; /* * Reason: it crashes FIXME find and document the real reason @@ -564,6 +609,8 @@ static void spapr_drc_physical_class_init(ObjectClass *= k, void *data) sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); =20 drck->dr_entity_sense =3D physical_entity_sense; + drck->isolate =3D drc_isolate_physical; + drck->unisolate =3D drc_unisolate_physical; } =20 static void spapr_drc_logical_class_init(ObjectClass *k, void *data) @@ -571,6 +618,8 @@ static void spapr_drc_logical_class_init(ObjectClass *k= , void *data) sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); =20 drck->dr_entity_sense =3D logical_entity_sense; + drck->isolate =3D drc_isolate_logical; + drck->unisolate =3D drc_unisolate_logical; } =20 static void spapr_drc_cpu_class_init(ObjectClass *k, void *data) @@ -811,11 +860,23 @@ static uint32_t rtas_set_isolation_state(uint32_t idx= , uint32_t state) sPAPRDRConnectorClass *drck; =20 if (!drc) { - return RTAS_OUT_PARAM_ERROR; + return RTAS_OUT_NO_SUCH_INDICATOR; } =20 + trace_spapr_drc_set_isolation_state(spapr_drc_index(drc), state); + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - return drck->set_isolation_state(drc, state); + + switch (state) { + case SPAPR_DR_ISOLATION_STATE_ISOLATED: + return drck->isolate(drc); + + case SPAPR_DR_ISOLATION_STATE_UNISOLATED: + return drck->unisolate(drc); + + default: + return RTAS_OUT_PARAM_ERROR; + } } =20 static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 0e09afb..3e93bdd 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -216,10 +216,8 @@ typedef struct sPAPRDRConnectorClass { const char *drc_name_prefix; /* used other places in device tree */ =20 sPAPRDREntitySense (*dr_entity_sense)(sPAPRDRConnector *drc); - - /* accessors for guest-visible (generally via RTAS) DR state */ - uint32_t (*set_isolation_state)(sPAPRDRConnector *drc, - sPAPRDRIsolationState state); + uint32_t (*isolate)(sPAPRDRConnector *drc); + uint32_t (*unisolate)(sPAPRDRConnector *drc); =20 /* QEMU interfaces for managing hotplug operations */ bool (*release_pending)(sPAPRDRConnector *drc); --=20 2.9.4