From nobody Mon Apr 29 13:53:21 2024 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.zohomail.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 1499839105731789.5782437241008; Tue, 11 Jul 2017 22:58:25 -0700 (PDT) Received: from localhost ([::1]:50521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAfH-0004zr-8F for importer@patchew.org; Wed, 12 Jul 2017 01:58:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAb0-0001WY-Rb for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:54:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAaw-0004uV-9h for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:58 -0400 Received: from ozlabs.org ([103.22.144.67]:55219) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVAav-0004u6-Tg; Wed, 12 Jul 2017 01:53:54 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3x6p5s2X7nz9sNx; Wed, 12 Jul 2017 15:53:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1499838801; bh=XxwX8dTRFEO7PzrtE5loDGUg7vJsaBH6vGZHfAAfLCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=namGCCFE2CeY4MA77KqZ6ra9XvRocZl4JmAFgPmOj9f6WrOsqv+KQnvqVuWo5zwP5 JeWxSQ1ilYcs9fduUtgPOJs9lzq27mQlb9+/4NdAPa8j5D2bF1tkaWPlG9huZNbva8 Dz+jNEtuA1xkwzicRmXmcBrXZlA+q2+nLZLKDn3c= From: David Gibson To: mdroth@linux.vnet.ibm.com, groug@kaod.org, danielhb@linux.vnet.ibm.com Date: Wed, 12 Jul 2017 15:53:10 +1000 Message-Id: <20170712055317.26225-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170712055317.26225-1-david@gibson.dropbear.id.au> References: <20170712055317.26225-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] [PATCHv2 1/8] spapr: Treat devices added before inbound migration as coldplugged 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: lvivier@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, sjitindarsingh@gmail.com, 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" From: Laurent Vivier When migrating a guest which has already had devices hotplugged, libvirt typically starts the destination qemu with -incoming defer, adds those hotplugged devices with qmp, then initiates the incoming migration. This causes problems for the management of spapr DRC state. Because the device is treated as hotplugged, it goes into a DRC state for a device immediately after it's plugged, but before the guest has acknowledged its presence. However, chances are the guest on the source machine *has* acknowledged the device's presence and configured it. If the source has fully configured the device, then DRC state won't be sent in the migration stream: for maximum migration compatibility with earlier versions we don't migrate DRCs in coldplug-equivalent state. That means that the DRC effectively changes state over the migrate, causing problems later on. In addition, logging hotplug events for these devices isn't what we want because a) those events should already have been issued on the source host and b) the event queue should get wiped out by the incoming state anyway. In short, what we really want is to treat devices added before an incoming migration as if they were coldplugged. To do this, we first add a spapr_drc_hotplugged() helper which determines if the device is hotplugged in the sense relevant for DRC state management. We only send hotplug events when this is true. Second, when we add a device which isn't hotplugged in this sense, we force a reset of the DRC state - this ensures the DRC is in a coldplug-equivalent state (there isn't usually a system reset between these device adds and the incoming migration). This is based on an earlier patch by Laurent Vivier, cleaned up and extended. Signed-off-by: Laurent Vivier Signed-off-by: David Gibson Reviewed-by: Greg Kurz Tested-by: Daniel Barboza --- hw/ppc/spapr.c | 24 ++++++++++++++++-------- hw/ppc/spapr_drc.c | 9 ++++++--- hw/ppc/spapr_pci.c | 4 +++- include/hw/ppc/spapr_drc.h | 8 ++++++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 12b3f09..2a059d5 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2636,6 +2636,7 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, int i, fdt_offset, fdt_size; void *fdt; uint64_t addr =3D addr_start; + bool hotplugged =3D spapr_drc_hotplugged(dev); Error *local_err =3D NULL; =20 for (i =3D 0; i < nr_lmbs; i++) { @@ -2659,12 +2660,15 @@ static void spapr_add_lmbs(DeviceState *dev, uint64= _t addr_start, uint64_t size, error_propagate(errp, local_err); return; } + if (!hotplugged) { + spapr_drc_reset(drc); + } addr +=3D SPAPR_MEMORY_BLOCK_SIZE; } /* send hotplug notification to the * guest only in case of hotplugged memory */ - if (dev->hotplugged) { + if (hotplugged) { if (dedicated_hp_event_source) { drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_LMB, addr_start / SPAPR_MEMORY_BLOCK_SIZE); @@ -2998,6 +3002,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev, int smt =3D kvmppc_smt_threads(); CPUArchId *core_slot; int index; + bool hotplugged =3D spapr_drc_hotplugged(dev); =20 core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &= index); if (!core_slot) { @@ -3018,15 +3023,18 @@ static void spapr_core_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, error_propagate(errp, local_err); return; } - } =20 - if (dev->hotplugged) { - /* - * Send hotplug notification interrupt to the guest only in case - * of hotplugged CPUs. - */ - spapr_hotplug_req_add_by_index(drc); + if (hotplugged) { + /* + * Send hotplug notification interrupt to the guest only + * in case of hotplugged CPUs. + */ + spapr_hotplug_req_add_by_index(drc); + } else { + spapr_drc_reset(drc); + } } + core_slot->cpu =3D OBJECT(dev); =20 if (smc->pre_2_10_has_unused_icps) { diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index f34355d..9b07f80 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -412,10 +412,8 @@ static bool release_pending(sPAPRDRConnector *drc) return drc->awaiting_release; } =20 -static void drc_reset(void *opaque) +void spapr_drc_reset(sPAPRDRConnector *drc) { - sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(opaque); - trace_spapr_drc_reset(spapr_drc_index(drc)); =20 g_free(drc->ccs); @@ -447,6 +445,11 @@ static void drc_reset(void *opaque) } } =20 +static void drc_reset(void *opaque) +{ + spapr_drc_reset(SPAPR_DR_CONNECTOR(opaque)); +} + static bool spapr_drc_needed(void *opaque) { sPAPRDRConnector *drc =3D (sPAPRDRConnector *)opaque; diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index a52dcf8..1e84c55 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1443,7 +1443,9 @@ static void spapr_pci_plug(HotplugHandler *plug_handl= er, /* If this is function 0, signal hotplug for all the device functions. * Otherwise defer sending the hotplug event. */ - if (plugged_dev->hotplugged && PCI_FUNC(pdev->devfn) =3D=3D 0) { + if (!spapr_drc_hotplugged(plugged_dev)) { + spapr_drc_reset(drc); + } else if (PCI_FUNC(pdev->devfn) =3D=3D 0) { int i; =20 for (i =3D 0; i < 8; i++) { diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index d15e9eb..715016b 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -15,6 +15,7 @@ =20 #include #include "qom/object.h" +#include "sysemu/sysemu.h" #include "hw/qdev.h" =20 #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector" @@ -223,6 +224,13 @@ typedef struct sPAPRDRConnectorClass { bool (*release_pending)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass; =20 +static inline bool spapr_drc_hotplugged(DeviceState *dev) +{ + return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); +} + +void spapr_drc_reset(sPAPRDRConnector *drc); + uint32_t spapr_drc_index(sPAPRDRConnector *drc); sPAPRDRConnectorType spapr_drc_type(sPAPRDRConnector *drc); =20 --=20 2.9.4 From nobody Mon Apr 29 13:53:21 2024 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.zohomail.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 1499839136718828.64210881764; Tue, 11 Jul 2017 22:58:56 -0700 (PDT) Received: from localhost ([::1]:50524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAfn-0005WX-Db for importer@patchew.org; Wed, 12 Jul 2017 01:58:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAb1-0001X3-30 for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:54:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAaw-0004ub-HX for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:59 -0400 Received: from ozlabs.org ([103.22.144.67]:46311) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVAaw-0004uB-5g; Wed, 12 Jul 2017 01:53:54 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3x6p5s43wGz9sRg; Wed, 12 Jul 2017 15:53:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1499838801; bh=1OFsIIRkliGBxVZDaWKwzYpZ6hW1lRGEe+mU3t1FOFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2xEepAJt9/YwLpALq7OiP5DIJQvMDwvXwgk+nZk584lRtl4W7I9Mf7Nv7303T2oz hHiv8XtI2rzkXxwL6In3X4iV+QVPzyUQ/UEh1J7/+HsDUuK/ap7IJ0LCAkd1A6Xu45 1GQV0i5ZpdrenR66i+judkiA7EKc7frUKHm9jPmo= From: David Gibson To: mdroth@linux.vnet.ibm.com, groug@kaod.org, danielhb@linux.vnet.ibm.com Date: Wed, 12 Jul 2017 15:53:11 +1000 Message-Id: <20170712055317.26225-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170712055317.26225-1-david@gibson.dropbear.id.au> References: <20170712055317.26225-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] [PATCHv2 2/8] spapr: Remove 'awaiting_allocation' DRC flag 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: lvivier@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, sjitindarsingh@gmail.com, 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 awaiting_allocation flag in the DRC was introduced by aab9913 "spapr_drc: Prevent detach racing against attach for CPU DR", allegedly to prevent a guest crash on racing attach and detach. Except.. information from the BZ actually suggests a qemu crash, not a guest crash. And there shouldn't be a problem here anyway: if the guest has already moved the DRC away from UNUSABLE state, the detach would already be deferred, and if it hadn't it should be safe to detach it (the guest should fail gracefully when it attempts to change the allocation state). I think this was probably just a bandaid for some other problem in the state management. So, remove awaiting_allocation and associated code. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Laurent Vivier Tested-by: Daniel Barboza Tested-by: Greg Kurz --- hw/ppc/spapr_drc.c | 25 +++---------------------- include/hw/ppc/spapr_drc.h | 1 - 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 9b07f80..89ba3d6 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -170,19 +170,13 @@ static uint32_t drc_set_usable(sPAPRDRConnector *drc) 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->awaiting_release) { + /* Don't allow the guest to move a device away from UNUSABLE + * state when we want to unplug it */ return RTAS_OUT_NO_SUCH_INDICATOR; } =20 drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_USABLE; - drc->awaiting_allocation =3D false; =20 return RTAS_OUT_SUCCESS; } @@ -357,10 +351,6 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceSta= te *d, void *fdt, drc->fdt =3D fdt; drc->fdt_start_offset =3D fdt_start_offset; =20 - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - drc->awaiting_allocation =3D true; - } - object_property_add_link(OBJECT(drc), "device", object_get_typename(OBJECT(drc->dev)), (Object **)(&drc->dev), @@ -398,12 +388,6 @@ void spapr_drc_detach(sPAPRDRConnector *drc, DeviceSta= te *d, Error **errp) return; } =20 - if (drc->awaiting_allocation) { - drc->awaiting_release =3D true; - trace_spapr_drc_awaiting_allocation(spapr_drc_index(drc)); - return; - } - spapr_drc_release(drc); } =20 @@ -426,8 +410,6 @@ void spapr_drc_reset(sPAPRDRConnector *drc) spapr_drc_release(drc); } =20 - drc->awaiting_allocation =3D false; - if (drc->dev) { /* A device present at reset is coldplugged */ drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; @@ -493,7 +475,6 @@ static const VMStateDescription vmstate_spapr_drc =3D { VMSTATE_UINT32(dr_indicator, sPAPRDRConnector), VMSTATE_BOOL(configured, sPAPRDRConnector), VMSTATE_BOOL(awaiting_release, sPAPRDRConnector), - VMSTATE_BOOL(awaiting_allocation, sPAPRDRConnector), VMSTATE_END_OF_LIST() } }; diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 715016b..18a196e 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -200,7 +200,6 @@ typedef struct sPAPRDRConnector { sPAPRConfigureConnectorState *ccs; =20 bool awaiting_release; - bool awaiting_allocation; =20 /* device pointer, via link property */ DeviceState *dev; --=20 2.9.4 From nobody Mon Apr 29 13:53:21 2024 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.zohomail.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 1499839246665260.3364470626698; Tue, 11 Jul 2017 23:00:46 -0700 (PDT) Received: from localhost ([::1]:50538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAhY-000767-EA for importer@patchew.org; Wed, 12 Jul 2017 02:00:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAaX-0000iI-Hb for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAaT-0004ml-Aw for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:29 -0400 Received: from ozlabs.org ([103.22.144.67]:45967) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVAaS-0004lr-Vs; Wed, 12 Jul 2017 01:53:25 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3x6p5s5p9kz9t16; Wed, 12 Jul 2017 15:53:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1499838801; bh=ZE6IDwrKiPffR8ZOsYCfIfwUUnGthVs4KoZrcCgOXeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m+PfqSTdlavPfklwac5Ony0REi5PuDLEva3FRfIxpcMYME2BGmh3RR3FE6XNOCpy0 wUUZcpl5Cq87Q3RkBnhlvAEFAAyKItlGI4lGy8cz+WdOTgMMvfNtdxk7b1xoeO6aj9 EGLLqy3JxXl9A3zog8krrxGzsVl0JRdLOIE6ns1Y= From: David Gibson To: mdroth@linux.vnet.ibm.com, groug@kaod.org, danielhb@linux.vnet.ibm.com Date: Wed, 12 Jul 2017 15:53:12 +1000 Message-Id: <20170712055317.26225-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170712055317.26225-1-david@gibson.dropbear.id.au> References: <20170712055317.26225-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] [PATCHv2 3/8] spapr: Simplify unplug 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: lvivier@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, sjitindarsingh@gmail.com, 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_lmb_release() and spapr_core_release() call hotplug_handler_unplug() which after a bunch of indirection calls spapr_memory_unplug() or spapr_core_unplug(). But we already know which is the appropriate thing to call here, so we can just fold it directly into the release function. Once that's done, there's no need for an hc->unplug method in the spapr machine at all: since we also have an hc->unplug_request method, the hotplug core will never use ->unplug. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Tested-by: Daniel Barboza --- hw/ppc/spapr.c | 54 ++++++++---------------------------------------------- 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 2a059d5..ff2aa6b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2818,6 +2818,9 @@ void spapr_lmb_release(DeviceState *dev) { HotplugHandler *hotplug_ctrl =3D qdev_get_hotplug_handler(dev); sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_ctrl); + PCDIMMDevice *dimm =3D PC_DIMM(dev); + PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + MemoryRegion *mr =3D ddc->get_memory_region(dimm); sPAPRDIMMState *ds =3D spapr_pending_dimm_unplugs_find(spapr, PC_DIMM(= dev)); =20 /* This information will get lost if a migration occurs @@ -2838,18 +2841,7 @@ void spapr_lmb_release(DeviceState *dev) * Now that all the LMBs have been removed by the guest, call the * pc-dimm unplug handler to cleanup up the pc-dimm device. */ - hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); -} - -static void spapr_memory_unplug(HotplugHandler *hotplug_dev, DeviceState *= dev, - Error **errp) -{ - sPAPRMachineState *ms =3D SPAPR_MACHINE(hotplug_dev); - PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr =3D ddc->get_memory_region(dimm); - - pc_dimm_memory_unplug(dev, &ms->hotplug_memory, mr); + pc_dimm_memory_unplug(dev, &spapr->hotplug_memory, mr); object_unparent(OBJECT(dev)); } =20 @@ -2918,10 +2910,11 @@ static void *spapr_populate_hotplug_cpu_dt(CPUState= *cs, int *fdt_offset, return fdt; } =20 -static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *de= v, - Error **errp) +/* Callback to be called during DRC release. */ +void spapr_core_release(DeviceState *dev) { - MachineState *ms =3D MACHINE(qdev_get_machine()); + HotplugHandler *hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + MachineState *ms =3D MACHINE(hotplug_ctrl); sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(ms); CPUCore *cc =3D CPU_CORE(dev); CPUArchId *core_slot =3D spapr_find_cpu_slot(ms, cc->core_id, NULL); @@ -2945,15 +2938,6 @@ static void spapr_core_unplug(HotplugHandler *hotplu= g_dev, DeviceState *dev, object_unparent(OBJECT(dev)); } =20 -/* Callback to be called during DRC release. */ -void spapr_core_release(DeviceState *dev) -{ - HotplugHandler *hotplug_ctrl; - - hotplug_ctrl =3D qdev_get_hotplug_handler(dev); - hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); -} - static void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *d= ev, Error **errp) @@ -3159,27 +3143,6 @@ static void spapr_machine_device_plug(HotplugHandler= *hotplug_dev, } } =20 -static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) -{ - sPAPRMachineState *sms =3D SPAPR_MACHINE(qdev_get_machine()); - MachineClass *mc =3D MACHINE_GET_CLASS(qdev_get_machine()); - - if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { - if (spapr_ovec_test(sms->ov5_cas, OV5_HP_EVT)) { - spapr_memory_unplug(hotplug_dev, dev, errp); - } else { - error_setg(errp, "Memory hot unplug not supported for this gue= st"); - } - } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { - if (!mc->has_hotpluggable_cpus) { - error_setg(errp, "CPU hot unplug not supported on this machine= "); - return; - } - spapr_core_unplug(hotplug_dev, dev, errp); - } -} - static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_de= v, DeviceState *dev, Error **= errp) { @@ -3397,7 +3360,6 @@ static void spapr_machine_class_init(ObjectClass *oc,= void *data) mc->get_hotplug_handler =3D spapr_get_hotplug_handler; hc->pre_plug =3D spapr_machine_device_pre_plug; hc->plug =3D spapr_machine_device_plug; - hc->unplug =3D spapr_machine_device_unplug; mc->cpu_index_to_instance_props =3D spapr_cpu_index_to_props; mc->possible_cpu_arch_ids =3D spapr_possible_cpu_arch_ids; hc->unplug_request =3D spapr_machine_device_unplug_request; --=20 2.9.4 From nobody Mon Apr 29 13:53:21 2024 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.zohomail.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 1499839129964740.8860842639067; Tue, 11 Jul 2017 22:58:49 -0700 (PDT) Received: from localhost ([::1]:50523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAfg-0005Q5-Je for importer@patchew.org; Wed, 12 Jul 2017 01:58:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAaX-0000iL-IN for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAaT-0004md-6H for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:29 -0400 Received: from ozlabs.org ([103.22.144.67]:60061) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVAaS-0004lu-QC; Wed, 12 Jul 2017 01:53:25 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3x6p5s6vkBz9t1G; Wed, 12 Jul 2017 15:53:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1499838801; bh=MbI1n1iqOqlChg4d4WhqQbgDtnWRLNERXc+JYorI9TU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ItZXt9rMfTBHpQAwh8mSvprSMeshXlkkUQg7hGDW0RK74Zg24WTSjf61HWUlTci5W Iw1fO+Ukj4V6nfYCfNi+717qX07MHj+Tkot1nBEumGQ2VYm31EqaRQnpr85Cv0psAL 6a6LbVauRDA45UiIyDwQbAcMYUt7H+W32/46TMZw= From: David Gibson To: mdroth@linux.vnet.ibm.com, groug@kaod.org, danielhb@linux.vnet.ibm.com Date: Wed, 12 Jul 2017 15:53:13 +1000 Message-Id: <20170712055317.26225-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170712055317.26225-1-david@gibson.dropbear.id.au> References: <20170712055317.26225-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] [PATCHv2 4/8] spapr: Refactor spapr_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: lvivier@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, sjitindarsingh@gmail.com, 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" This function has two unused parameters - remove them. It also sets awaiting_release on all paths, except one. On that path setting it is harmless, since it will be immediately cleared by spapr_drc_release(). So factor it out of the if statements. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Tested-by: Daniel Barboza --- hw/ppc/spapr.c | 11 +++-------- hw/ppc/spapr_drc.c | 12 ++++++------ hw/ppc/spapr_pci.c | 7 +------ include/hw/ppc/spapr_drc.h | 2 +- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index ff2aa6b..5c528e2 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2654,7 +2654,7 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, addr -=3D SPAPR_MEMORY_BLOCK_SIZE; drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_LMB, addr / SPAPR_MEMORY_BLOCK_SIZE); - spapr_drc_detach(drc, dev, NULL); + spapr_drc_detach(drc); } g_free(fdt); error_propagate(errp, local_err); @@ -2877,7 +2877,7 @@ static void spapr_memory_unplug_request(HotplugHandle= r *hotplug_dev, addr / SPAPR_MEMORY_BLOCK_SIZE); g_assert(drc); =20 - spapr_drc_detach(drc, dev, errp); + spapr_drc_detach(drc); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; } =20 @@ -2944,7 +2944,6 @@ void spapr_core_unplug_request(HotplugHandler *hotplu= g_dev, DeviceState *dev, { int index; sPAPRDRConnector *drc; - Error *local_err =3D NULL; CPUCore *cc =3D CPU_CORE(dev); int smt =3D kvmppc_smt_threads(); =20 @@ -2961,11 +2960,7 @@ void spapr_core_unplug_request(HotplugHandler *hotpl= ug_dev, DeviceState *dev, drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, index * smt); g_assert(drc); =20 - spapr_drc_detach(drc, dev, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } + spapr_drc_detach(drc); =20 spapr_hotplug_req_remove_by_index(drc); } diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 89ba3d6..08fc715 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -70,7 +70,7 @@ static uint32_t drc_isolate_physical(sPAPRDRConnector *dr= c) 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); + spapr_drc_detach(drc); } else { trace_spapr_drc_set_isolation_state_deferring(drc_index); } @@ -134,7 +134,7 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *d= rc) 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); + spapr_drc_detach(drc); } else { trace_spapr_drc_set_isolation_state_deferring(drc_index); } @@ -187,7 +187,7 @@ static uint32_t drc_set_unusable(sPAPRDRConnector *drc) 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); + spapr_drc_detach(drc); } =20 return RTAS_OUT_SUCCESS; @@ -371,20 +371,20 @@ static void spapr_drc_release(sPAPRDRConnector *drc) drc->dev =3D NULL; } =20 -void spapr_drc_detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp) +void spapr_drc_detach(sPAPRDRConnector *drc) { trace_spapr_drc_detach(spapr_drc_index(drc)); =20 + drc->awaiting_release =3D true; + 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; } =20 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; } =20 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 1e84c55..092a2f5 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1478,7 +1478,6 @@ static void spapr_pci_unplug_request(HotplugHandler *= plug_handler, PCIDevice *pdev =3D PCI_DEVICE(plugged_dev); sPAPRDRConnectorClass *drck; sPAPRDRConnector *drc =3D spapr_phb_get_pci_drc(phb, pdev); - Error *local_err =3D NULL; =20 if (!phb->dr_enabled) { error_setg(errp, QERR_BUS_NO_HOTPLUG, @@ -1516,11 +1515,7 @@ static void spapr_pci_unplug_request(HotplugHandler = *plug_handler, } } =20 - spapr_drc_detach(drc, DEVICE(pdev), &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } + spapr_drc_detach(drc); =20 /* if this isn't func 0, defer unplug event. otherwise signal remo= val * for all present functions diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 18a196e..fc8b721 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -242,6 +242,6 @@ int spapr_drc_populate_dt(void *fdt, int fdt_offset, Ob= ject *owner, =20 void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, int fdt_start_offset, Error **errp); -void spapr_drc_detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp); +void spapr_drc_detach(sPAPRDRConnector *drc); =20 #endif /* HW_SPAPR_DRC_H */ --=20 2.9.4 From nobody Mon Apr 29 13:53:21 2024 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.zohomail.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 1499838978017326.3544840819761; Tue, 11 Jul 2017 22:56:18 -0700 (PDT) Received: from localhost ([::1]:50510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAdE-0003A8-Jh for importer@patchew.org; Wed, 12 Jul 2017 01:56:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAaX-0000iJ-He for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAaV-0004nl-RW for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:29 -0400 Received: from ozlabs.org ([103.22.144.67]:34893) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVAaV-0004mb-7X; Wed, 12 Jul 2017 01:53:27 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3x6p5t0zzTz9t1m; Wed, 12 Jul 2017 15:53:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1499838802; bh=wf+50/UhxSeUcYw5XS9B6ygoKll9s13x7pInuAwlzmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E+p6gqJR/1JzkwLtaTL242lvjuCinOJHAgI/qMtRBOYZ88+uu0korw7KO2HB4j0qE P8/6W0wk0qpmacWeJH/W+P6CJIU3hJTnJ6ElJ13Xzg8/d8ye4phUcFpi2tZXaNEzaP phMSUzO4PD0TpOhPtjC30wd0T8Sahi4eKPNgkyq8= From: David Gibson To: mdroth@linux.vnet.ibm.com, groug@kaod.org, danielhb@linux.vnet.ibm.com Date: Wed, 12 Jul 2017 15:53:14 +1000 Message-Id: <20170712055317.26225-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170712055317.26225-1-david@gibson.dropbear.id.au> References: <20170712055317.26225-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] [PATCHv2 5/8] spapr: Cleanups relating to DRC awaiting_release field 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: lvivier@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, sjitindarsingh@gmail.com, 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" 'awaiting_release' indicates that the host has requested an unplug of the device attached to the DRC, but the guest has not (yet) put the device into a state where it is safe to complete removal. 1. Rename it to 'unplug_requested' which to me at least is clearer 2. Remove the ->release_pending() method used to check this from outside spapr_drc.c. The method only plausibly has one implementation, so use a plain function (spapr_drc_unplug_requested()) instead. 3. Remove it from the migration stream. Attempting to migrate mid-unplug is broken not just for spapr - in general management has no good way to determine if the device should be present on the destination or not. So, until that's fixed, there's no point adding extra things to the stream. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Tested-by: Daniel Barboza --- hw/ppc/spapr_drc.c | 26 +++++++++----------------- hw/ppc/spapr_pci.c | 6 ++---- include/hw/ppc/spapr_drc.h | 11 ++++++----- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 08fc715..8326f3a 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -66,7 +66,7 @@ static uint32_t drc_isolate_physical(sPAPRDRConnector *dr= c) * configured state, as suggested by the state diagram from PAPR+ * 2.7, 13.4 */ - if (drc->awaiting_release) { + if (drc->unplug_requested) { uint32_t drc_index =3D spapr_drc_index(drc); if (drc->configured) { trace_spapr_drc_set_isolation_state_finalizing(drc_index); @@ -116,7 +116,7 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *d= rc) * actually being unplugged, fail the isolation request here. */ if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_LMB - && !drc->awaiting_release) { + && !drc->unplug_requested) { return RTAS_OUT_HW_ERROR; } =20 @@ -130,7 +130,7 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *d= rc) * configured state, as suggested by the state diagram from PAPR+ * 2.7, 13.4 */ - if (drc->awaiting_release) { + if (drc->unplug_requested) { uint32_t drc_index =3D spapr_drc_index(drc); if (drc->configured) { trace_spapr_drc_set_isolation_state_finalizing(drc_index); @@ -170,7 +170,7 @@ static uint32_t drc_set_usable(sPAPRDRConnector *drc) if (!drc->dev) { return RTAS_OUT_NO_SUCH_INDICATOR; } - if (drc->awaiting_release) { + if (drc->unplug_requested) { /* Don't allow the guest to move a device away from UNUSABLE * state when we want to unplug it */ return RTAS_OUT_NO_SUCH_INDICATOR; @@ -184,7 +184,7 @@ static uint32_t drc_set_usable(sPAPRDRConnector *drc) static uint32_t drc_set_unusable(sPAPRDRConnector *drc) { drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE; - if (drc->awaiting_release) { + if (drc->unplug_requested) { uint32_t drc_index =3D spapr_drc_index(drc); trace_spapr_drc_set_allocation_state_finalizing(drc_index); spapr_drc_detach(drc); @@ -363,7 +363,7 @@ static void spapr_drc_release(sPAPRDRConnector *drc) =20 drck->release(drc->dev); =20 - drc->awaiting_release =3D false; + drc->unplug_requested =3D false; g_free(drc->fdt); drc->fdt =3D NULL; drc->fdt_start_offset =3D 0; @@ -375,7 +375,7 @@ void spapr_drc_detach(sPAPRDRConnector *drc) { trace_spapr_drc_detach(spapr_drc_index(drc)); =20 - drc->awaiting_release =3D true; + drc->unplug_requested =3D true; =20 if (drc->isolation_state !=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { trace_spapr_drc_awaiting_isolated(spapr_drc_index(drc)); @@ -391,11 +391,6 @@ void spapr_drc_detach(sPAPRDRConnector *drc) spapr_drc_release(drc); } =20 -static bool release_pending(sPAPRDRConnector *drc) -{ - return drc->awaiting_release; -} - void spapr_drc_reset(sPAPRDRConnector *drc) { trace_spapr_drc_reset(spapr_drc_index(drc)); @@ -406,7 +401,7 @@ void spapr_drc_reset(sPAPRDRConnector *drc) /* immediately upon reset we can safely assume DRCs whose devices * are pending removal can be safely removed. */ - if (drc->awaiting_release) { + if (drc->unplug_requested) { spapr_drc_release(drc); } =20 @@ -454,7 +449,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->awaiting_release); + drc->configured); break; case SPAPR_DR_CONNECTOR_TYPE_PHB: case SPAPR_DR_CONNECTOR_TYPE_VIO: @@ -474,7 +469,6 @@ static const VMStateDescription vmstate_spapr_drc =3D { VMSTATE_UINT32(allocation_state, sPAPRDRConnector), VMSTATE_UINT32(dr_indicator, sPAPRDRConnector), VMSTATE_BOOL(configured, sPAPRDRConnector), - VMSTATE_BOOL(awaiting_release, sPAPRDRConnector), VMSTATE_END_OF_LIST() } }; @@ -565,11 +559,9 @@ static void spapr_dr_connector_instance_init(Object *o= bj) static void spapr_dr_connector_class_init(ObjectClass *k, void *data) { DeviceClass *dk =3D DEVICE_CLASS(k); - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); =20 dk->realize =3D realize; dk->unrealize =3D unrealize; - drck->release_pending =3D release_pending; /* * Reason: it crashes FIXME find and document the real reason */ diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 092a2f5..6ecdf29 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1476,7 +1476,6 @@ static void spapr_pci_unplug_request(HotplugHandler *= plug_handler, { sPAPRPHBState *phb =3D SPAPR_PCI_HOST_BRIDGE(DEVICE(plug_handler)); PCIDevice *pdev =3D PCI_DEVICE(plugged_dev); - sPAPRDRConnectorClass *drck; sPAPRDRConnector *drc =3D spapr_phb_get_pci_drc(phb, pdev); =20 if (!phb->dr_enabled) { @@ -1488,8 +1487,7 @@ static void spapr_pci_unplug_request(HotplugHandler *= plug_handler, g_assert(drc); g_assert(drc->dev =3D=3D plugged_dev); =20 - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - if (!drck->release_pending(drc)) { + if (!spapr_drc_unplug_requested(drc)) { PCIBus *bus =3D PCI_BUS(qdev_get_parent_bus(DEVICE(pdev))); uint32_t slotnr =3D PCI_SLOT(pdev->devfn); sPAPRDRConnector *func_drc; @@ -1505,7 +1503,7 @@ static void spapr_pci_unplug_request(HotplugHandler *= plug_handler, func_drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); state =3D func_drck->dr_entity_sense(func_drc); if (state =3D=3D SPAPR_DR_ENTITY_SENSE_PRESENT - && !func_drck->release_pending(func_drc)) { + && !spapr_drc_unplug_requested(func_drc)) { error_setg(errp, "PCI: slot %d, function %d still present. " "Must unplug all non-0 functions first.", diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index fc8b721..5fa502e 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -199,10 +199,9 @@ typedef struct sPAPRDRConnector { bool configured; sPAPRConfigureConnectorState *ccs; =20 - bool awaiting_release; - /* device pointer, via link property */ DeviceState *dev; + bool unplug_requested; } sPAPRDRConnector; =20 typedef struct sPAPRDRConnectorClass { @@ -218,9 +217,6 @@ typedef struct sPAPRDRConnectorClass { uint32_t (*isolate)(sPAPRDRConnector *drc); uint32_t (*unisolate)(sPAPRDRConnector *drc); void (*release)(DeviceState *dev); - - /* QEMU interfaces for managing hotplug operations */ - bool (*release_pending)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass; =20 static inline bool spapr_drc_hotplugged(DeviceState *dev) @@ -244,4 +240,9 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceStat= e *d, void *fdt, int fdt_start_offset, Error **errp); void spapr_drc_detach(sPAPRDRConnector *drc); =20 +static inline bool spapr_drc_unplug_requested(sPAPRDRConnector *drc) +{ + return drc->unplug_requested; +} + #endif /* HW_SPAPR_DRC_H */ --=20 2.9.4 From nobody Mon Apr 29 13:53:21 2024 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.zohomail.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 1499839225617300.18784886718674; Tue, 11 Jul 2017 23:00:25 -0700 (PDT) Received: from localhost ([::1]:50533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAhE-0006j5-41 for importer@patchew.org; Wed, 12 Jul 2017 02:00:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAb2-0001YX-Fi for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:54:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAb0-0004ve-0b for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:54:00 -0400 Received: from ozlabs.org ([103.22.144.67]:33769) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVAaz-0004v1-Cj; Wed, 12 Jul 2017 01:53:57 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3x6p5v0HhTz9t0j; Wed, 12 Jul 2017 15:53:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1499838803; bh=yk7bGP+gj/4qlOiTyU/BUVrVXfWgYSmqNuuciv/818E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L4wLA1OT9LiNMi3cuTYoVpA9jJu1bseuoCKAXuF+pjWiR8MOsqR+TtvT36kUb2J4h wlby1HN7RbtnG4JID8ReYwQWplfs4cnkyPZMQ6rFDTKSieHbouqMyoOWKiQItuaI5d d0ZIt1hvuhQYqqBr4NngdMkbJaHfqIP9vHJHk1TA= From: David Gibson To: mdroth@linux.vnet.ibm.com, groug@kaod.org, danielhb@linux.vnet.ibm.com Date: Wed, 12 Jul 2017 15:53:15 +1000 Message-Id: <20170712055317.26225-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170712055317.26225-1-david@gibson.dropbear.id.au> References: <20170712055317.26225-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] [PATCHv2 6/8] spapr: Consolidate DRC state variables 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: lvivier@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, sjitindarsingh@gmail.com, 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" Each DRC has three fields describing its state: isolation_state, allocation_state and configured. At first this seems like a reasonable representation, since its based directly on the PAPR defined isolation-state and allocation-state indicators. However: * Only a few combinations of the two fields' values are permitted * allocation_state isn't used at all for physical DRCs * The indicators are write only so they don't really have a well defined current value independent of each other This replaces these variables with a single state variable, whose names and numbers are based on the diagram in LoPAPR section 13.4. Along with this we add code to check the current state on various operations and make sure the requested transition is permitted. Strictly speaking, this makes guest visible changes to behaviour (since we probably allowed some transitions we shouldn't have before). However, a hypothetical guest broken by that wasn't PAPR compliant, and probably wouldn't have worked under PowerVM. Signed-off-by: David Gibson Reviewed-by: Daniel Barboza Tested-by: Daniel Barboza --- hw/ppc/spapr_drc.c | 225 +++++++++++++++++++++++++----------------= ---- hw/ppc/trace-events | 3 +- include/hw/ppc/spapr_drc.h | 25 ++++- 3 files changed, 145 insertions(+), 108 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 8326f3a..dbc9c0f 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -48,6 +48,17 @@ uint32_t spapr_drc_index(sPAPRDRConnector *drc) =20 static uint32_t drc_isolate_physical(sPAPRDRConnector *drc) { + switch (drc->state) { + case SPAPR_DRC_STATE_PHYSICAL_POWERON: + return RTAS_OUT_SUCCESS; /* Nothing to do */ + case SPAPR_DRC_STATE_PHYSICAL_CONFIGURED: + break; /* see below */ + case SPAPR_DRC_STATE_PHYSICAL_UNISOLATE: + return RTAS_OUT_PARAM_ERROR; /* not allowed */ + default: + g_assert_not_reached(); + } + /* 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 @@ -56,32 +67,29 @@ static uint32_t drc_isolate_physical(sPAPRDRConnector *= drc) g_free(drc->ccs); drc->ccs =3D NULL; =20 - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; + drc->state =3D SPAPR_DRC_STATE_PHYSICAL_POWERON; =20 - /* 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->unplug_requested) { 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); - } else { - trace_spapr_drc_set_isolation_state_deferring(drc_index); - } + trace_spapr_drc_set_isolation_state_finalizing(drc_index); + spapr_drc_detach(drc); } - drc->configured =3D false; =20 return RTAS_OUT_SUCCESS; } =20 static uint32_t drc_unisolate_physical(sPAPRDRConnector *drc) { + switch (drc->state) { + case SPAPR_DRC_STATE_PHYSICAL_UNISOLATE: + case SPAPR_DRC_STATE_PHYSICAL_CONFIGURED: + return RTAS_OUT_SUCCESS; /* Nothing to do */ + case SPAPR_DRC_STATE_PHYSICAL_POWERON: + break; /* see below */ + default: + g_assert_not_reached(); + } + /* cannot unisolate a non-existent resource, and, or resources * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, * 13.5.3.5) @@ -90,13 +98,25 @@ static uint32_t drc_unisolate_physical(sPAPRDRConnector= *drc) return RTAS_OUT_NO_SUCH_INDICATOR; } =20 - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; + drc->state =3D SPAPR_DRC_STATE_PHYSICAL_UNISOLATE; =20 return RTAS_OUT_SUCCESS; } =20 static uint32_t drc_isolate_logical(sPAPRDRConnector *drc) { + switch (drc->state) { + case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: + case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: + return RTAS_OUT_SUCCESS; /* Nothing to do */ + case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: + break; /* see below */ + case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: + return RTAS_OUT_PARAM_ERROR; /* not allowed */ + default: + g_assert_not_reached(); + } + /* 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 @@ -120,7 +140,7 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *d= rc) return RTAS_OUT_HW_ERROR; } =20 - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; + drc->state =3D SPAPR_DRC_STATE_LOGICAL_AVAILABLE; =20 /* if we're awaiting release, but still in an unconfigured state, * it's likely the guest is still in the process of configuring @@ -132,36 +152,46 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector = *drc) */ if (drc->unplug_requested) { 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); - } else { - trace_spapr_drc_set_isolation_state_deferring(drc_index); - } + trace_spapr_drc_set_isolation_state_finalizing(drc_index); + spapr_drc_detach(drc); } - drc->configured =3D false; - return RTAS_OUT_SUCCESS; } =20 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; + switch (drc->state) { + case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: + case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: + return RTAS_OUT_SUCCESS; /* Nothing to do */ + case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: + break; /* see below */ + case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: + return RTAS_OUT_NO_SUCH_INDICATOR; /* not allowed */ + default: + g_assert_not_reached(); } =20 - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; + /* Move to AVAILABLE state should have ensured device was present */ + g_assert(drc->dev); =20 + drc->state =3D SPAPR_DRC_STATE_LOGICAL_UNISOLATE; return RTAS_OUT_SUCCESS; } =20 static uint32_t drc_set_usable(sPAPRDRConnector *drc) { + switch (drc->state) { + case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: + case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: + case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: + return RTAS_OUT_SUCCESS; /* Nothing to do */ + case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: + break; /* see below */ + default: + g_assert_not_reached(); + } + /* 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 @@ -176,14 +206,26 @@ static uint32_t drc_set_usable(sPAPRDRConnector *drc) return RTAS_OUT_NO_SUCH_INDICATOR; } =20 - drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_USABLE; + drc->state =3D SPAPR_DRC_STATE_LOGICAL_AVAILABLE; =20 return RTAS_OUT_SUCCESS; } =20 static uint32_t drc_set_unusable(sPAPRDRConnector *drc) { - drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE; + switch (drc->state) { + case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: + return RTAS_OUT_SUCCESS; /* Nothing to do */ + case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: + break; /* see below */ + case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: + case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: + return RTAS_OUT_NO_SUCH_INDICATOR; /* not allowed */ + default: + g_assert_not_reached(); + } + + drc->state =3D SPAPR_DRC_STATE_LOGICAL_UNUSABLE; if (drc->unplug_requested) { uint32_t drc_index =3D spapr_drc_index(drc); trace_spapr_drc_set_allocation_state_finalizing(drc_index); @@ -241,11 +283,16 @@ static sPAPRDREntitySense physical_entity_sense(sPAPR= DRConnector *drc) =20 static sPAPRDREntitySense logical_entity_sense(sPAPRDRConnector *drc) { - if (drc->dev - && (drc->allocation_state !=3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE)= ) { - return SPAPR_DR_ENTITY_SENSE_PRESENT; - } else { + switch (drc->state) { + case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: return SPAPR_DR_ENTITY_SENSE_UNUSABLE; + case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: + case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: + case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: + g_assert(drc->dev); + return SPAPR_DR_ENTITY_SENSE_PRESENT; + default: + g_assert_not_reached(); } } =20 @@ -338,13 +385,12 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceSt= ate *d, void *fdt, { trace_spapr_drc_attach(spapr_drc_index(drc)); =20 - if (drc->isolation_state !=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { + if (drc->dev) { error_setg(errp, "an attached device is still awaiting release"); return; } - if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - g_assert(drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_US= ABLE); - } + g_assert((drc->state =3D=3D SPAPR_DRC_STATE_LOGICAL_UNUSABLE) + || (drc->state =3D=3D SPAPR_DRC_STATE_PHYSICAL_POWERON)); g_assert(fdt); =20 drc->dev =3D d; @@ -373,18 +419,16 @@ static void spapr_drc_release(sPAPRDRConnector *drc) =20 void spapr_drc_detach(sPAPRDRConnector *drc) { + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + trace_spapr_drc_detach(spapr_drc_index(drc)); =20 - drc->unplug_requested =3D true; + g_assert(drc->dev); =20 - if (drc->isolation_state !=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { - trace_spapr_drc_awaiting_isolated(spapr_drc_index(drc)); - return; - } + drc->unplug_requested =3D true; =20 - 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)); + if (drc->state !=3D drck->empty_state) { + trace_spapr_drc_awaiting_quiesce(spapr_drc_index(drc)); return; } =20 @@ -393,6 +437,8 @@ void spapr_drc_detach(sPAPRDRConnector *drc) =20 void spapr_drc_reset(sPAPRDRConnector *drc) { + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + trace_spapr_drc_reset(spapr_drc_index(drc)); =20 g_free(drc->ccs); @@ -406,19 +452,10 @@ void spapr_drc_reset(sPAPRDRConnector *drc) } =20 if (drc->dev) { - /* A device present at reset is coldplugged */ - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_USABLE; - } - drc->dr_indicator =3D SPAPR_DR_INDICATOR_ACTIVE; + /* A device present at reset is ready to go, same as coldplugged */ + drc->state =3D drck->ready_state; } else { - /* Otherwise device is absent, but might be hotplugged */ - drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_ISOLATED; - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE; - } - drc->dr_indicator =3D SPAPR_DR_INDICATOR_INACTIVE; + drc->state =3D drck->empty_state; } } =20 @@ -431,7 +468,6 @@ static bool spapr_drc_needed(void *opaque) { sPAPRDRConnector *drc =3D (sPAPRDRConnector *)opaque; sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - bool rc =3D false; sPAPRDREntitySense value =3D drck->dr_entity_sense(drc); =20 /* If no dev is plugged in there is no need to migrate the DRC state */ @@ -440,23 +476,10 @@ static bool spapr_drc_needed(void *opaque) } =20 /* - * If there is dev plugged in, we need to migrate the DRC state when - * it is different from cold-plugged state - */ - switch (spapr_drc_type(drc)) { - case SPAPR_DR_CONNECTOR_TYPE_PCI: - case SPAPR_DR_CONNECTOR_TYPE_CPU: - 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); - break; - case SPAPR_DR_CONNECTOR_TYPE_PHB: - case SPAPR_DR_CONNECTOR_TYPE_VIO: - default: - g_assert_not_reached(); - } - return rc; + * We need to migrate the state if it's not equal to the expected + * long-term state, which is the same as the coldplugged initial + * state */ + return (drc->state !=3D drck->ready_state); } =20 static const VMStateDescription vmstate_spapr_drc =3D { @@ -465,10 +488,8 @@ static const VMStateDescription vmstate_spapr_drc =3D { .minimum_version_id =3D 1, .needed =3D spapr_drc_needed, .fields =3D (VMStateField []) { - VMSTATE_UINT32(isolation_state, sPAPRDRConnector), - VMSTATE_UINT32(allocation_state, sPAPRDRConnector), + VMSTATE_UINT32(state, sPAPRDRConnector), VMSTATE_UINT32(dr_indicator, sPAPRDRConnector), - VMSTATE_BOOL(configured, sPAPRDRConnector), VMSTATE_END_OF_LIST() } }; @@ -537,23 +558,20 @@ sPAPRDRConnector *spapr_dr_connector_new(Object *owne= r, const char *type, object_property_set_bool(OBJECT(drc), true, "realized", NULL); g_free(prop_name); =20 - /* PCI slot always start in a USABLE state, and stay there */ - if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_USABLE; - } - return drc; } =20 static void spapr_dr_connector_instance_init(Object *obj) { sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(obj); + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 object_property_add_uint32_ptr(obj, "id", &drc->id, NULL); object_property_add(obj, "index", "uint32", prop_get_index, NULL, NULL, NULL, NULL); object_property_add(obj, "fdt", "struct", prop_get_fdt, NULL, NULL, NULL, NULL); + drc->state =3D drck->empty_state; } =20 static void spapr_dr_connector_class_init(ObjectClass *k, void *data) @@ -575,6 +593,8 @@ static void spapr_drc_physical_class_init(ObjectClass *= k, void *data) drck->dr_entity_sense =3D physical_entity_sense; drck->isolate =3D drc_isolate_physical; drck->unisolate =3D drc_unisolate_physical; + drck->ready_state =3D SPAPR_DRC_STATE_PHYSICAL_CONFIGURED; + drck->empty_state =3D SPAPR_DRC_STATE_PHYSICAL_POWERON; } =20 static void spapr_drc_logical_class_init(ObjectClass *k, void *data) @@ -584,6 +604,8 @@ static void spapr_drc_logical_class_init(ObjectClass *k= , void *data) drck->dr_entity_sense =3D logical_entity_sense; drck->isolate =3D drc_isolate_logical; drck->unisolate =3D drc_unisolate_logical; + drck->ready_state =3D SPAPR_DRC_STATE_LOGICAL_CONFIGURED; + drck->empty_state =3D SPAPR_DRC_STATE_LOGICAL_UNUSABLE; } =20 static void spapr_drc_cpu_class_init(ObjectClass *k, void *data) @@ -987,6 +1009,7 @@ static void rtas_ibm_configure_connector(PowerPCCPU *c= pu, uint64_t wa_offset; uint32_t drc_index; sPAPRDRConnector *drc; + sPAPRDRConnectorClass *drck; sPAPRConfigureConnectorState *ccs; sPAPRDRCCResponse resp =3D SPAPR_DR_CC_RESPONSE_CONTINUE; int rc; @@ -1006,12 +1029,17 @@ static void rtas_ibm_configure_connector(PowerPCCPU= *cpu, goto out; } =20 - if (!drc->fdt) { - trace_spapr_rtas_ibm_configure_connector_missing_fdt(drc_index); + if ((drc->state !=3D SPAPR_DRC_STATE_LOGICAL_UNISOLATE) + && (drc->state !=3D SPAPR_DRC_STATE_PHYSICAL_UNISOLATE)) { + /* Need to unisolate the device before configuring */ rc =3D SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE; goto out; } =20 + g_assert(drc->fdt); + + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + ccs =3D drc->ccs; if (!ccs) { ccs =3D g_new0(sPAPRConfigureConnectorState, 1); @@ -1041,18 +1069,11 @@ static void rtas_ibm_configure_connector(PowerPCCPU= *cpu, case FDT_END_NODE: ccs->fdt_depth--; if (ccs->fdt_depth =3D=3D 0) { - sPAPRDRIsolationState state =3D drc->isolation_state; uint32_t drc_index =3D spapr_drc_index(drc); - /* done sending the device tree, don't need to track - * the state anymore - */ + + /* done sending the device tree, move to configured state = */ trace_spapr_drc_set_configured(drc_index); - if (state =3D=3D SPAPR_DR_ISOLATION_STATE_UNISOLATED) { - drc->configured =3D true; - } else { - /* guest should be not configuring an isolated device = */ - trace_spapr_drc_set_configured_skipping(drc_index); - } + drc->state =3D drck->ready_state; g_free(ccs); drc->ccs =3D NULL; ccs =3D NULL; diff --git a/hw/ppc/trace-events b/hw/ppc/trace-events index 3e8e3cf..8e79f7e 100644 --- a/hw/ppc/trace-events +++ b/hw/ppc/trace-events @@ -46,8 +46,7 @@ spapr_drc_set_configured(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_set_configured_skipping(uint32_t index) "drc: 0x%"PRIx32", isola= ted device" spapr_drc_attach(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_detach(uint32_t index) "drc: 0x%"PRIx32 -spapr_drc_awaiting_isolated(uint32_t index) "drc: 0x%"PRIx32 -spapr_drc_awaiting_unusable(uint32_t index) "drc: 0x%"PRIx32 +spapr_drc_awaiting_quiesce(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_awaiting_allocation(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_reset(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_realize(uint32_t index) "drc: 0x%"PRIx32 diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 5fa502e..4ceaaf0 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -173,6 +173,24 @@ typedef enum { SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE =3D -9003, } sPAPRDRCCResponse; =20 +typedef enum { + /* + * Values come from Fig. 12 in LoPAPR section 13.4 + * + * These are exposed in the migration stream, so don't change + * them. + */ + SPAPR_DRC_STATE_INVALID =3D 0, + SPAPR_DRC_STATE_LOGICAL_UNUSABLE =3D 1, + SPAPR_DRC_STATE_LOGICAL_AVAILABLE =3D 2, + SPAPR_DRC_STATE_LOGICAL_UNISOLATE =3D 3, + SPAPR_DRC_STATE_LOGICAL_CONFIGURED =3D 4, + SPAPR_DRC_STATE_PHYSICAL_AVAILABLE =3D 5, + SPAPR_DRC_STATE_PHYSICAL_POWERON =3D 6, + SPAPR_DRC_STATE_PHYSICAL_UNISOLATE =3D 7, + SPAPR_DRC_STATE_PHYSICAL_CONFIGURED =3D 8, +} sPAPRDRCState; + /* rtas-configure-connector state */ typedef struct sPAPRConfigureConnectorState { int fdt_offset; @@ -189,14 +207,11 @@ typedef struct sPAPRDRConnector { /* DR-indicator */ uint32_t dr_indicator; =20 - /* sensor/indicator states */ - uint32_t isolation_state; - uint32_t allocation_state; + uint32_t state; =20 /* configure-connector state */ void *fdt; int fdt_start_offset; - bool configured; sPAPRConfigureConnectorState *ccs; =20 /* device pointer, via link property */ @@ -207,6 +222,8 @@ typedef struct sPAPRDRConnector { typedef struct sPAPRDRConnectorClass { /*< private >*/ DeviceClass parent; + sPAPRDRCState empty_state; + sPAPRDRCState ready_state; =20 /*< public >*/ sPAPRDRConnectorTypeShift typeshift; --=20 2.9.4 From nobody Mon Apr 29 13:53:21 2024 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.zohomail.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 14998389856231011.9815986245064; Tue, 11 Jul 2017 22:56:25 -0700 (PDT) Received: from localhost ([::1]:50511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAdM-0003Hh-6F for importer@patchew.org; Wed, 12 Jul 2017 01:56:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAb1-0001X8-5Y for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:54:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAaz-0004vT-Hd for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:59 -0400 Received: from ozlabs.org ([103.22.144.67]:40103) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVAay-0004uo-U3; Wed, 12 Jul 2017 01:53:57 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3x6p5t3W7cz9t1y; Wed, 12 Jul 2017 15:53:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1499838802; bh=gvzOVl/0UJhdbNq1SmcPgOglN3XrrchU3LPWw2U6+fY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m5KFdHji2bb7R1Doe609hBHHj//CbdBRG8gul/vZOPz4HH0zur7sXBhIE2ROUOkNb JUa1TxuOO2so6Rl4KwKVJocUf37XnOg1HILNgE+oRcUWpV42fxksSIWTVpS/LRwEe2 mGxB2td2Om0bz94axxZbsGNAeod+YACfODDrTuLk= From: David Gibson To: mdroth@linux.vnet.ibm.com, groug@kaod.org, danielhb@linux.vnet.ibm.com Date: Wed, 12 Jul 2017 15:53:16 +1000 Message-Id: <20170712055317.26225-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170712055317.26225-1-david@gibson.dropbear.id.au> References: <20170712055317.26225-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] [PATCHv2 7/8] spapr: Remove sPAPRConfigureConnectorState sub-structure 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: lvivier@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, sjitindarsingh@gmail.com, 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" Most of the time, the state of a DRC object is contained in the single 'state' variable. However, during the transition from UNISOLATE to CONFIGURED state requires multiple calls to the ibm,configure-connector RTAS call to retrieve the device tree for the attached device. We need some extra state to keep track of where we're up to in delivering the device tree information to the guest. Currently that extra state is in a sPAPRConfigureConnectorState substructure which is only allocated when we're in the middle of the configure connector process. That sounds like a good idea, but the extra state is only two integers - on many platforms that will take up the same room as the (maybe NULL) ccs pointer even before malloc() overhead. Plus it's another object whose lifetime we need to manage. In short, it's not worth it. So, fold the sPAPRConfigureConnectorState substructure directly into the DRC object. Previously the structure was allocated lazily when the configure-connector call discovers it's not there. Now, we need to initialize the subfields pre-emptively, as soon as we enter UNISOLATE state. Although it's not strictly necessary (the field values should only ever be consulted when in UNISOLATE state), we try to keep them at -1 when in other states, as a debugging aid. Signed-off-by: David Gibson Reviewed-by: Daniel Barboza Tested-by: Daniel Barboza --- hw/ppc/spapr_drc.c | 56 +++++++++++++++---------------------------= ---- include/hw/ppc/spapr_drc.h | 16 +++++-------- 2 files changed, 24 insertions(+), 48 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index dbc9c0f..423db80 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -59,14 +59,6 @@ static uint32_t drc_isolate_physical(sPAPRDRConnector *d= rc) g_assert_not_reached(); } =20 - /* 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; - drc->state =3D SPAPR_DRC_STATE_PHYSICAL_POWERON; =20 if (drc->unplug_requested) { @@ -99,6 +91,8 @@ static uint32_t drc_unisolate_physical(sPAPRDRConnector *= drc) } =20 drc->state =3D SPAPR_DRC_STATE_PHYSICAL_UNISOLATE; + drc->ccs_offset =3D drc->fdt_start_offset; + drc->ccs_depth =3D 0; =20 return RTAS_OUT_SUCCESS; } @@ -117,14 +111,6 @@ static uint32_t drc_isolate_logical(sPAPRDRConnector *= drc) g_assert_not_reached(); } =20 - /* 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; - /* * Fail any requests to ISOLATE the LMB DRC if this LMB doesn't * belong to a DIMM device that is marked for removal. @@ -176,6 +162,9 @@ static uint32_t drc_unisolate_logical(sPAPRDRConnector = *drc) g_assert(drc->dev); =20 drc->state =3D SPAPR_DRC_STATE_LOGICAL_UNISOLATE; + drc->ccs_offset =3D drc->fdt_start_offset; + drc->ccs_depth =3D 0; + return RTAS_OUT_SUCCESS; } =20 @@ -441,9 +430,6 @@ void spapr_drc_reset(sPAPRDRConnector *drc) =20 trace_spapr_drc_reset(spapr_drc_index(drc)); =20 - g_free(drc->ccs); - drc->ccs =3D NULL; - /* immediately upon reset we can safely assume DRCs whose devices * are pending removal can be safely removed. */ @@ -457,6 +443,9 @@ void spapr_drc_reset(sPAPRDRConnector *drc) } else { drc->state =3D drck->empty_state; } + + drc->ccs_offset =3D -1; + drc->ccs_depth =3D -1; } =20 static void drc_reset(void *opaque) @@ -1010,7 +999,6 @@ static void rtas_ibm_configure_connector(PowerPCCPU *c= pu, uint32_t drc_index; sPAPRDRConnector *drc; sPAPRDRConnectorClass *drck; - sPAPRConfigureConnectorState *ccs; sPAPRDRCCResponse resp =3D SPAPR_DR_CC_RESPONSE_CONTINUE; int rc; =20 @@ -1040,25 +1028,18 @@ static void rtas_ibm_configure_connector(PowerPCCPU= *cpu, =20 drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 - ccs =3D drc->ccs; - if (!ccs) { - ccs =3D g_new0(sPAPRConfigureConnectorState, 1); - ccs->fdt_offset =3D drc->fdt_start_offset; - drc->ccs =3D ccs; - } - do { uint32_t tag; const char *name; const struct fdt_property *prop; int fdt_offset_next, prop_len; =20 - tag =3D fdt_next_tag(drc->fdt, ccs->fdt_offset, &fdt_offset_next); + tag =3D fdt_next_tag(drc->fdt, drc->ccs_offset, &fdt_offset_next); =20 switch (tag) { case FDT_BEGIN_NODE: - ccs->fdt_depth++; - name =3D fdt_get_name(drc->fdt, ccs->fdt_offset, NULL); + drc->ccs_depth++; + name =3D fdt_get_name(drc->fdt, drc->ccs_offset, NULL); =20 /* provide the name of the next OF node */ wa_offset =3D CC_VAL_DATA_OFFSET; @@ -1067,23 +1048,22 @@ static void rtas_ibm_configure_connector(PowerPCCPU= *cpu, resp =3D SPAPR_DR_CC_RESPONSE_NEXT_CHILD; break; case FDT_END_NODE: - ccs->fdt_depth--; - if (ccs->fdt_depth =3D=3D 0) { + drc->ccs_depth--; + if (drc->ccs_depth =3D=3D 0) { uint32_t drc_index =3D spapr_drc_index(drc); =20 /* done sending the device tree, move to configured state = */ trace_spapr_drc_set_configured(drc_index); drc->state =3D drck->ready_state; - g_free(ccs); - drc->ccs =3D NULL; - ccs =3D NULL; + drc->ccs_offset =3D -1; + drc->ccs_depth =3D -1; resp =3D SPAPR_DR_CC_RESPONSE_SUCCESS; } else { resp =3D SPAPR_DR_CC_RESPONSE_PREV_PARENT; } break; case FDT_PROP: - prop =3D fdt_get_property_by_offset(drc->fdt, ccs->fdt_offset, + prop =3D fdt_get_property_by_offset(drc->fdt, drc->ccs_offset, &prop_len); name =3D fdt_string(drc->fdt, fdt32_to_cpu(prop->nameoff)); =20 @@ -1108,8 +1088,8 @@ static void rtas_ibm_configure_connector(PowerPCCPU *= cpu, /* keep seeking for an actionable tag */ break; } - if (ccs) { - ccs->fdt_offset =3D fdt_offset_next; + if (drc->ccs_offset >=3D 0) { + drc->ccs_offset =3D fdt_offset_next; } } while (resp =3D=3D SPAPR_DR_CC_RESPONSE_CONTINUE); =20 diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 4ceaaf0..9d4fd41 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -191,12 +191,6 @@ typedef enum { SPAPR_DRC_STATE_PHYSICAL_CONFIGURED =3D 8, } sPAPRDRCState; =20 -/* rtas-configure-connector state */ -typedef struct sPAPRConfigureConnectorState { - int fdt_offset; - int fdt_depth; -} sPAPRConfigureConnectorState; - typedef struct sPAPRDRConnector { /*< private >*/ DeviceState parent; @@ -209,14 +203,16 @@ typedef struct sPAPRDRConnector { =20 uint32_t state; =20 - /* configure-connector state */ - void *fdt; - int fdt_start_offset; - sPAPRConfigureConnectorState *ccs; + /* RTAS ibm,configure-connector state */ + /* (only valid in UNISOLATE state) */ + int ccs_offset; + int ccs_depth; =20 /* device pointer, via link property */ DeviceState *dev; bool unplug_requested; + void *fdt; + int fdt_start_offset; } sPAPRDRConnector; =20 typedef struct sPAPRDRConnectorClass { --=20 2.9.4 From nobody Mon Apr 29 13:53:21 2024 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.zohomail.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 1499838917498540.8338418001991; Tue, 11 Jul 2017 22:55:17 -0700 (PDT) Received: from localhost ([::1]:50504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAcG-0002J7-46 for importer@patchew.org; Wed, 12 Jul 2017 01:55:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAaX-0000iK-I0 for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAaW-0004o7-7n for qemu-devel@nongnu.org; Wed, 12 Jul 2017 01:53:29 -0400 Received: from ozlabs.org ([103.22.144.67]:40927) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVAaV-0004mv-TA; Wed, 12 Jul 2017 01:53:28 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3x6p5v1g1Gz9t1n; Wed, 12 Jul 2017 15:53:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1499838803; bh=5LvqOyE3ApRsMRnYERzyD3BE3KG00RL/9eYEDsBEtIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hX6Z4t15EoyO0OPj+EGoCkrHO5FEhuNOjKUtYglb1oj4f2cYVjm1KXKiyYfOmgHP4 XCU9G7BqnFo+LgywrTAm9X6Fqqn84/yk+1/WCVnzchB32XNSOJRFS0fvS89CcghTuE oDZTI8QvKPTAeUpTBoBHQdS2Fd84iO/3Sxam+FI0= From: David Gibson To: mdroth@linux.vnet.ibm.com, groug@kaod.org, danielhb@linux.vnet.ibm.com Date: Wed, 12 Jul 2017 15:53:17 +1000 Message-Id: <20170712055317.26225-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170712055317.26225-1-david@gibson.dropbear.id.au> References: <20170712055317.26225-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] [PATCHv2 8/8] spapr: Implement DR-indicator for physical DRCs only 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: lvivier@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, sjitindarsingh@gmail.com, 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" According to PAPR, the DR-indicator should only be valid for physical DRCs, not logical DRCs. At the moment we implement it for all DRCs, so restrict it to physical ones only. We move the state to the physical DRC subclass, which means adding some QOM boilerplate to handle the newly distinct type. Signed-off-by: David Gibson Reviewed-by: Daniel Barboza Tested-by: Daniel Barboza --- hw/ppc/spapr_drc.c | 68 ++++++++++++++++++++++++++++++++++++++++++= ---- include/hw/ppc/spapr_drc.h | 13 ++++++--- 2 files changed, 72 insertions(+), 9 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 423db80..39b7cef 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -478,7 +478,6 @@ static const VMStateDescription vmstate_spapr_drc =3D { .needed =3D spapr_drc_needed, .fields =3D (VMStateField []) { VMSTATE_UINT32(state, sPAPRDRConnector), - VMSTATE_UINT32(dr_indicator, sPAPRDRConnector), VMSTATE_END_OF_LIST() } }; @@ -575,10 +574,63 @@ static void spapr_dr_connector_class_init(ObjectClass= *k, void *data) dk->user_creatable =3D false; } =20 +static bool drc_physical_needed(void *opaque) +{ + sPAPRDRCPhysical *drcp =3D (sPAPRDRCPhysical *)opaque; + sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(drcp); + + if ((drc->dev && (drcp->dr_indicator =3D=3D SPAPR_DR_INDICATOR_ACTIVE)) + || (!drc->dev && (drcp->dr_indicator =3D=3D SPAPR_DR_INDICATOR_INA= CTIVE))) { + return false; + } + return true; +} + +static const VMStateDescription vmstate_spapr_drc_physical =3D { + .name =3D "spapr_drc", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D drc_physical_needed, + .fields =3D (VMStateField []) { + VMSTATE_UINT32(dr_indicator, sPAPRDRCPhysical), + VMSTATE_END_OF_LIST() + } +}; + +static void drc_physical_reset(void *opaque) +{ + sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(opaque); + sPAPRDRCPhysical *drcp =3D SPAPR_DRC_PHYSICAL(drc); + + if (drc->dev) { + drcp->dr_indicator =3D SPAPR_DR_INDICATOR_ACTIVE; + } else { + drcp->dr_indicator =3D SPAPR_DR_INDICATOR_INACTIVE; + } +} + +static void realize_physical(DeviceState *d, Error **errp) +{ + sPAPRDRCPhysical *drcp =3D SPAPR_DRC_PHYSICAL(d); + Error *local_err =3D NULL; + + realize(d, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + vmstate_register(DEVICE(drcp), spapr_drc_index(SPAPR_DR_CONNECTOR(drcp= )), + &vmstate_spapr_drc_physical, drcp); + qemu_register_reset(drc_physical_reset, drcp); +} + static void spapr_drc_physical_class_init(ObjectClass *k, void *data) { + DeviceClass *dk =3D DEVICE_CLASS(k); sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); =20 + dk->realize =3D realize_physical; drck->dr_entity_sense =3D physical_entity_sense; drck->isolate =3D drc_isolate_physical; drck->unisolate =3D drc_unisolate_physical; @@ -640,7 +692,7 @@ static const TypeInfo spapr_dr_connector_info =3D { static const TypeInfo spapr_drc_physical_info =3D { .name =3D TYPE_SPAPR_DRC_PHYSICAL, .parent =3D TYPE_SPAPR_DR_CONNECTOR, - .instance_size =3D sizeof(sPAPRDRConnector), + .instance_size =3D sizeof(sPAPRDRCPhysical), .class_init =3D spapr_drc_physical_class_init, .abstract =3D true, }; @@ -883,12 +935,18 @@ static uint32_t rtas_set_dr_indicator(uint32_t idx, u= int32_t state) { sPAPRDRConnector *drc =3D spapr_drc_by_index(idx); =20 - if (!drc) { - return RTAS_OUT_PARAM_ERROR; + if (!drc || !object_dynamic_cast(OBJECT(drc), TYPE_SPAPR_DRC_PHYSICAL)= ) { + return RTAS_OUT_NO_SUCH_INDICATOR; + } + if ((state !=3D SPAPR_DR_INDICATOR_INACTIVE) + && (state !=3D SPAPR_DR_INDICATOR_ACTIVE) + && (state !=3D SPAPR_DR_INDICATOR_IDENTIFY) + && (state !=3D SPAPR_DR_INDICATOR_ACTION)) { + return RTAS_OUT_PARAM_ERROR; /* bad state parameter */ } =20 trace_spapr_drc_set_dr_indicator(idx, state); - drc->dr_indicator =3D state; + SPAPR_DRC_PHYSICAL(drc)->dr_indicator =3D state; return RTAS_OUT_SUCCESS; } =20 diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 9d4fd41..a7958d0 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -33,7 +33,7 @@ #define SPAPR_DRC_PHYSICAL_CLASS(klass) \ OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \ TYPE_SPAPR_DRC_PHYSICAL) -#define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \ +#define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(sPAPRDRCPhysical, (obj), \ TYPE_SPAPR_DRC_PHYSICAL) =20 #define TYPE_SPAPR_DRC_LOGICAL "spapr-drc-logical" @@ -198,9 +198,6 @@ typedef struct sPAPRDRConnector { uint32_t id; Object *owner; =20 - /* DR-indicator */ - uint32_t dr_indicator; - uint32_t state; =20 /* RTAS ibm,configure-connector state */ @@ -232,6 +229,14 @@ typedef struct sPAPRDRConnectorClass { void (*release)(DeviceState *dev); } sPAPRDRConnectorClass; =20 +typedef struct sPAPRDRCPhysical { + /*< private >*/ + sPAPRDRConnector parent; + + /* DR-indicator */ + uint32_t dr_indicator; +} sPAPRDRCPhysical; + static inline bool spapr_drc_hotplugged(DeviceState *dev) { return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); --=20 2.9.4