From nobody Sat May 18 19:47:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1608287946; cv=none; d=zohomail.com; s=zohoarc; b=YjIINxNjf3AR6J6UV1+hBwVIh1PPEVGpLNt816tUqF2TTWtichJg40iAT8/UVN4hY2ONAzGlNpKvyckzDGm6UgJTyIMtN80shws9iNzcjWLWDqNP3q37OPT6k7aBn8/nGpEJOcO2wRH73Dj4URvgUR465vpX71NursB7Q5x1pjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608287946; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hlqlwvnu3oLEpWeUdduAr1qvYBnsXDssHerTLUWmU3c=; b=JRa/epk7xAC0dbK2nNZxfUZW6IrmoY2ny1vKOkcPewcM1pyt1X/plqdvMmKBheKolI7ihkpwTRGiOTMC/AbBElWRgmWeas1LaheAtt8hgfql+Yjy8vy8eNM54sVzHs5yG9mYnn2vZFFm3KzxBOORphS6jh547MgorbcHS877Xyw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608287946622229.52527610213565; Fri, 18 Dec 2020 02:39:06 -0800 (PST) Received: from localhost ([::1]:35720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqDA9-00070D-FS for importer@patchew.org; Fri, 18 Dec 2020 05:39:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqD5Q-0000hR-CJ for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:13 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:40806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqD5O-0001xX-1H for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:11 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-242-iw4SOYyTM4ecKMcDBR9hAA-1; Fri, 18 Dec 2020 05:34:05 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B82910054FF; Fri, 18 Dec 2020 10:34:04 +0000 (UTC) Received: from bahia.redhat.com (ovpn-114-254.ams2.redhat.com [10.36.114.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02A5560BE5; Fri, 18 Dec 2020 10:34:02 +0000 (UTC) X-MC-Unique: iw4SOYyTM4ecKMcDBR9hAA-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 1/6] spapr: Call spapr_drc_reset() for all DRCs at CAS Date: Fri, 18 Dec 2020 11:33:55 +0100 Message-Id: <20201218103400.689660-2-groug@kaod.org> In-Reply-To: <20201218103400.689660-1-groug@kaod.org> References: <20201218103400.689660-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Non-transient DRCs are either in the empty or the ready state, which means spapr_drc_reset() doesn't change their state. It is thus not needed to do any checking. Call spapr_drc_reset() unconditionally and squash spapr_drc_transient() into its only user, spapr_drc_needed(). Signed-off-by: Greg Kurz Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- include/hw/ppc/spapr_drc.h | 3 --- hw/ppc/spapr_drc.c | 8 ++------ hw/ppc/spapr_hcall.c | 7 ++++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index def3593adc8b..cff5e707d0d9 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -244,9 +244,6 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, = uint32_t drc_type_mask); void spapr_drc_attach(SpaprDrc *drc, DeviceState *d); void spapr_drc_detach(SpaprDrc *drc); =20 -/* Returns true if a hot plug/unplug request is pending */ -bool spapr_drc_transient(SpaprDrc *drc); - static inline bool spapr_drc_unplug_requested(SpaprDrc *drc) { return drc->unplug_requested; diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index fc7e321fcdf6..8d62f55066b6 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -462,8 +462,9 @@ static const VMStateDescription vmstate_spapr_drc_unplu= g_requested =3D { } }; =20 -bool spapr_drc_transient(SpaprDrc *drc) +static bool spapr_drc_needed(void *opaque) { + SpaprDrc *drc =3D opaque; SpaprDrcClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 /* @@ -483,11 +484,6 @@ bool spapr_drc_transient(SpaprDrc *drc) spapr_drc_unplug_requested(drc); } =20 -static bool spapr_drc_needed(void *opaque) -{ - return spapr_drc_transient(opaque); -} - static const VMStateDescription vmstate_spapr_drc =3D { .name =3D "spapr_drc", .version_id =3D 1, diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index c0ea0bd5794b..4e9d50c254f0 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1650,9 +1650,10 @@ static void spapr_handle_transient_dev_before_cas(Sp= aprMachineState *spapr) prop->name, &error_abort)); =20 - if (spapr_drc_transient(drc)) { - spapr_drc_reset(drc); - } + /* + * This will complete any pending plug/unplug requests. + */ + spapr_drc_reset(drc); } =20 spapr_clear_pending_hotplug_events(spapr); --=20 2.26.2 From nobody Sat May 18 19:47:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1608287823; cv=none; d=zohomail.com; s=zohoarc; b=R810ndO9utmbX9+e7ISaGWiACoBmu0JqzUv3q703Xb3Pnm2lSU1JrD4C52oAU0t1N7dV3C/mZ1j8gON7xOPtpVbj14vCOxT6aZDrgDXTz8fWntkL7vOp4t5uVxOscDGI/gNPZL7ttwpZ8veX2imLIHxeN0Lx/iiIfeN1U9BjvWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608287823; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=h4jJF4ZR/QSTJAcx0mMpCmDze+Bb2tvvuqDMSSdVnwo=; b=kUCRVOKmVToyNxJ80/JujVyhwz+2laEPSBImWMTx7ORafzFJX8KJk3IBL3d24ZH86f2sKQ81wNsma4rPKErqhMGYt3CRnma+bPPXlaDVXXGtFX6Z7j5qSNevW07n3Gq5YU0SsKnfHpTlNmgVUqmBRwUEaorWu/9Pgjh++MT5BgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608287823768670.4443666730983; Fri, 18 Dec 2020 02:37:03 -0800 (PST) Received: from localhost ([::1]:58094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqD8A-0004Tw-JW for importer@patchew.org; Fri, 18 Dec 2020 05:37:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqD5S-0000jC-P1 for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:15 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:21623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqD5Q-0001yS-5V for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:13 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-335-bwShnYEUPFWPsXAiR96pRg-1; Fri, 18 Dec 2020 05:34:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D53F835DE1; Fri, 18 Dec 2020 10:34:05 +0000 (UTC) Received: from bahia.redhat.com (ovpn-114-254.ams2.redhat.com [10.36.114.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77E5460BE5; Fri, 18 Dec 2020 10:34:04 +0000 (UTC) X-MC-Unique: bwShnYEUPFWPsXAiR96pRg-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 2/6] spapr: Fix reset of transient DR connectors Date: Fri, 18 Dec 2020 11:33:56 +0100 Message-Id: <20201218103400.689660-3-groug@kaod.org> In-Reply-To: <20201218103400.689660-1-groug@kaod.org> References: <20201218103400.689660-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Documentation of object_property_iter_init() clearly stipulates that "it is forbidden to modify the property list while iterating". But this is exactly what we do when resetting transient DR connectors during CAS. The call to spapr_drc_reset() can finalize the hot-unplug sequence of a PHB or a PCI bridge, both of which will then in turn destroy their PCI DRCs. This could potentially invalidate the iterator. It is pure luck that this haven't caused any issues so far. Change spapr_drc_reset() to return true if it caused a device to be removed. Restart from scratch in this case. This can potentially increase the overall DRC reset time, especially with a high maxmem which generates a lot of LMB DRCs. But this kind of setup is rare, and so is the use case of rebooting a guest while doing hot-unplug. Signed-off-by: Greg Kurz Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- include/hw/ppc/spapr_drc.h | 3 ++- hw/ppc/spapr_drc.c | 6 +++++- hw/ppc/spapr_hcall.c | 8 +++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index cff5e707d0d9..5d80019f82e2 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -224,7 +224,8 @@ static inline bool spapr_drc_hotplugged(DeviceState *de= v) return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); } =20 -void spapr_drc_reset(SpaprDrc *drc); +/* Returns true if an unplug request completed */ +bool spapr_drc_reset(SpaprDrc *drc); =20 uint32_t spapr_drc_index(SpaprDrc *drc); SpaprDrcType spapr_drc_type(SpaprDrc *drc); diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 8d62f55066b6..5b5e2ac58a7e 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -417,9 +417,10 @@ void spapr_drc_detach(SpaprDrc *drc) spapr_drc_release(drc); } =20 -void spapr_drc_reset(SpaprDrc *drc) +bool spapr_drc_reset(SpaprDrc *drc) { SpaprDrcClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + bool unplug_completed =3D false; =20 trace_spapr_drc_reset(spapr_drc_index(drc)); =20 @@ -428,6 +429,7 @@ void spapr_drc_reset(SpaprDrc *drc) */ if (drc->unplug_requested) { spapr_drc_release(drc); + unplug_completed =3D true; } =20 if (drc->dev) { @@ -444,6 +446,8 @@ void spapr_drc_reset(SpaprDrc *drc) drc->ccs_offset =3D -1; drc->ccs_depth =3D -1; } + + return unplug_completed; } =20 static bool spapr_drc_unplug_requested_needed(void *opaque) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 4e9d50c254f0..aa22830ac4bd 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1639,6 +1639,7 @@ static void spapr_handle_transient_dev_before_cas(Spa= prMachineState *spapr) ObjectPropertyIterator iter; =20 drc_container =3D container_get(object_get_root(), "/dr-connector"); +restart: object_property_iter_init(&iter, drc_container); while ((prop =3D object_property_iter_next(&iter))) { SpaprDrc *drc; @@ -1652,8 +1653,13 @@ static void spapr_handle_transient_dev_before_cas(Sp= aprMachineState *spapr) =20 /* * This will complete any pending plug/unplug requests. + * In case of a unplugged PHB or PCI bridge, this will + * cause some DRCs to be destroyed and thus potentially + * invalidate the iterator. */ - spapr_drc_reset(drc); + if (spapr_drc_reset(drc)) { + goto restart; + } } =20 spapr_clear_pending_hotplug_events(spapr); --=20 2.26.2 From nobody Sat May 18 19:47:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1608287888; cv=none; d=zohomail.com; s=zohoarc; b=Av4AJYdW6GVp6LkESjdj+y+VFm4sPPV56Jd/hBMPl3zuwwVjxFuq9go3BL9bxXNIPh11QRpMI8wDYDvYcpwv3tK2cnwlO4ZMmajpjE4JtFs98F2vxxXi4Q5ownuqMc+zceamOU4XeOzBbsb5jc9M17RD8wt41b9/wuPVly9hvyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608287888; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qqtxcRGh9Cei/NYdKrpW38NsOLRRPqop8pgJCFHNBlI=; b=GYl6S0Ya1d8DNj9lYjurCeP/7Gng1mGfnBvi7BA7RjaVUPAf9tbG2Vyfb3ZGd+e3znM5nu4WbLr7rOdwNKDAaju0rwRg9ZF98TJ1IhibUw/hXTYrcxEKnA3BMTwgAfilV4une0XcjgjMyKXE1tuCWRIzhX1VBDMOJsYu1OKv72U= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608287888540299.18937300604057; Fri, 18 Dec 2020 02:38:08 -0800 (PST) Received: from localhost ([::1]:60758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqD9D-0005cM-7q for importer@patchew.org; Fri, 18 Dec 2020 05:38:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqD5T-0000jH-1N for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:15 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:36968) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqD5R-0001yi-5R for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:14 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-179-xrFI2bRXO6yBgkg2dL775g-1; Fri, 18 Dec 2020 05:34:08 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B414801B16; Fri, 18 Dec 2020 10:34:07 +0000 (UTC) Received: from bahia.redhat.com (ovpn-114-254.ams2.redhat.com [10.36.114.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id E97A860BE5; Fri, 18 Dec 2020 10:34:05 +0000 (UTC) X-MC-Unique: xrFI2bRXO6yBgkg2dL775g-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 3/6] spapr: Introduce spapr_drc_reset_all() Date: Fri, 18 Dec 2020 11:33:57 +0100 Message-Id: <20201218103400.689660-4-groug@kaod.org> In-Reply-To: <20201218103400.689660-1-groug@kaod.org> References: <20201218103400.689660-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" No need to expose the way DRCs are traversed outside of spapr_drc.c. Signed-off-by: Greg Kurz Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- include/hw/ppc/spapr_drc.h | 6 ++++++ hw/ppc/spapr_drc.c | 31 +++++++++++++++++++++++++++++ hw/ppc/spapr_hcall.c | 40 ++++++-------------------------------- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 5d80019f82e2..8982927d5c24 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -245,6 +245,12 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner,= uint32_t drc_type_mask); void spapr_drc_attach(SpaprDrc *drc, DeviceState *d); void spapr_drc_detach(SpaprDrc *drc); =20 +/* + * Reset all DRCs, causing pending hot-plug/unplug requests to complete. + * Safely handles potential DRC removal (eg. PHBs or PCI bridges). + */ +void spapr_drc_reset_all(struct SpaprMachineState *spapr); + static inline bool spapr_drc_unplug_requested(SpaprDrc *drc) { return drc->unplug_requested; diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 5b5e2ac58a7e..a4d2608017c5 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -949,6 +949,37 @@ out: return ret; } =20 +void spapr_drc_reset_all(SpaprMachineState *spapr) +{ + Object *drc_container; + ObjectProperty *prop; + ObjectPropertyIterator iter; + + drc_container =3D container_get(object_get_root(), DRC_CONTAINER_PATH); +restart: + object_property_iter_init(&iter, drc_container); + while ((prop =3D object_property_iter_next(&iter))) { + SpaprDrc *drc; + + if (!strstart(prop->type, "link<", NULL)) { + continue; + } + drc =3D SPAPR_DR_CONNECTOR(object_property_get_link(drc_container, + prop->name, + &error_abort)); + + /* + * This will complete any pending plug/unplug requests. + * In case of a unplugged PHB or PCI bridge, this will + * cause some DRCs to be destroyed and thus potentially + * invalidate the iterator. + */ + if (spapr_drc_reset(drc)) { + goto restart; + } + } +} + /* * RTAS calls */ diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index aa22830ac4bd..e5dfc1ba7acc 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1632,39 +1632,6 @@ static uint32_t cas_check_pvr(PowerPCCPU *cpu, uint3= 2_t max_compat, return best_compat; } =20 -static void spapr_handle_transient_dev_before_cas(SpaprMachineState *spapr) -{ - Object *drc_container; - ObjectProperty *prop; - ObjectPropertyIterator iter; - - drc_container =3D container_get(object_get_root(), "/dr-connector"); -restart: - object_property_iter_init(&iter, drc_container); - while ((prop =3D object_property_iter_next(&iter))) { - SpaprDrc *drc; - - if (!strstart(prop->type, "link<", NULL)) { - continue; - } - drc =3D SPAPR_DR_CONNECTOR(object_property_get_link(drc_container, - prop->name, - &error_abort)); - - /* - * This will complete any pending plug/unplug requests. - * In case of a unplugged PHB or PCI bridge, this will - * cause some DRCs to be destroyed and thus potentially - * invalidate the iterator. - */ - if (spapr_drc_reset(drc)) { - goto restart; - } - } - - spapr_clear_pending_hotplug_events(spapr); -} - target_ulong do_client_architecture_support(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong vec, @@ -1822,7 +1789,12 @@ target_ulong do_client_architecture_support(PowerPCC= PU *cpu, =20 spapr_irq_update_active_intc(spapr); =20 - spapr_handle_transient_dev_before_cas(spapr); + /* + * Process all pending hot-plug/unplug requests now. An updated full + * rendered FDT will be returned to the guest. + */ + spapr_drc_reset_all(spapr); + spapr_clear_pending_hotplug_events(spapr); =20 /* * If spapr_machine_reset() did not set up a HPT but one is necessary --=20 2.26.2 From nobody Sat May 18 19:47:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1608288104; cv=none; d=zohomail.com; s=zohoarc; b=mxmw1Cixhtf6lMXH7E4UXa1jVpmPy8ViO/aaHNAvZk7zGGUd38DLh2Emq12tD8kDqWnUGGDkLh5QhAoRUx+RrRmGDhvOaJPMILb5Qko10OZklfj/Q+JTLxgmHdY3SumF+0DNxS/ShHEQ1v6BWp+0cOEuZxA9yu2DIsDFkxia/BI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608288104; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mW1ZDAKtTTpQz+OHKfP1adhJwaZnIr1eS85wXPsYxCk=; b=ibp96XgxGLqDU0rGuMzJFtAHjzen/FAaoN66luwWDcmlm2e11qSekS/kQQenA64VfH6WXmpNQzMbreagTL0hybBkqECD9OvGxTmhYWmcjHlT2wZSo1ha/W8rQAi8Nr08gfuZ5sz4JqdJrmZHTu6lF1W57hAFRMlaWCxBAAQJSzQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608288104048543.7759880355804; Fri, 18 Dec 2020 02:41:44 -0800 (PST) Received: from localhost ([::1]:44832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqDCg-0002XI-W7 for importer@patchew.org; Fri, 18 Dec 2020 05:41:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqD5V-0000kO-Nq for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:17 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:31670) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqD5T-0001zM-7M for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:16 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-86-LEGz206sOdCmX2uoMkzq-g-1; Fri, 18 Dec 2020 05:34:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E8B9104ED15; Fri, 18 Dec 2020 10:34:08 +0000 (UTC) Received: from bahia.redhat.com (ovpn-114-254.ams2.redhat.com [10.36.114.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6796460BE5; Fri, 18 Dec 2020 10:34:07 +0000 (UTC) X-MC-Unique: LEGz206sOdCmX2uoMkzq-g-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 4/6] spapr: Use spapr_drc_reset_all() at machine reset Date: Fri, 18 Dec 2020 11:33:58 +0100 Message-Id: <20201218103400.689660-5-groug@kaod.org> In-Reply-To: <20201218103400.689660-1-groug@kaod.org> References: <20201218103400.689660-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Documentation of object_child_foreach_recursive() clearly stipulates that "it is forbidden to add or remove children from @obj from the @fn callback". But this is exactly what we do during machine reset. The call to spapr_drc_reset() can finalize the hot-unplug sequence of a PHB or a PCI bridge, both of which will then in turn destroy their PCI DRCs. This could potentially invalidate the iterator used by do_object_child_foreach(). It is pure luck that this haven't caused any issues so far. Use spapr_drc_reset_all() since it can cope with DRC removal. Signed-off-by: Greg Kurz Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 43dded87f498..8528bc90fec4 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1566,19 +1566,6 @@ void spapr_setup_hpt(SpaprMachineState *spapr) } } =20 -static int spapr_reset_drcs(Object *child, void *opaque) -{ - SpaprDrc *drc =3D - (SpaprDrc *) object_dynamic_cast(child, - TYPE_SPAPR_DR_CONNECTOR); - - if (drc) { - spapr_drc_reset(drc); - } - - return 0; -} - static void spapr_machine_reset(MachineState *machine) { SpaprMachineState *spapr =3D SPAPR_MACHINE(machine); @@ -1633,7 +1620,7 @@ static void spapr_machine_reset(MachineState *machine) * will crash QEMU if the DIMM holding the vring goes away). To avoid = such * situations, we reset DRCs after all devices have been reset. */ - object_child_foreach_recursive(object_get_root(), spapr_reset_drcs, NU= LL); + spapr_drc_reset_all(spapr); =20 spapr_clear_pending_events(spapr); =20 --=20 2.26.2 From nobody Sat May 18 19:47:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1608287997; cv=none; d=zohomail.com; s=zohoarc; b=FEYgYpFxd65l74izNA7uoalr8qTCei9/Djw/p4wE2eMxDocG3YdU/tNHgUvOn9doA+oZJIO+PfVUDLgLvo1IkdcKIVWrT537y8xBn2l48oQoaMplWbNncJ/J9cf3SeBaEXI9dVg29oELiiPMx8SbgExmEBQqU9lsUYmgFqnv64c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608287997; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kNA/tGR2IVZqonhvawu+hxXiBvcKbvLpoDY0750wnGw=; b=haQJvsVUkEDZmWPp/RlDFX+BMCmBrw/RBFs3ii/6/Ji56YVlLpTvkTB81swZcCInNwLzP2f7V7mfxun7G7qdAUWA5RZMN0DaLJcu/SYybGxJSdU5Jl+NaTldzGrHrK//i1h3t7CExEWXt8n73H4V3TF7NyL4/iIU/AV8K0eRU5E= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608287997425733.727079668847; Fri, 18 Dec 2020 02:39:57 -0800 (PST) Received: from localhost ([::1]:38328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqDAy-0008Ai-AG for importer@patchew.org; Fri, 18 Dec 2020 05:39:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqD5Z-0000ta-9u for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:21 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:40715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqD5V-00020Q-Jr for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:21 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-106-CWDrG8YIPFSicWchJJz8OQ-1; Fri, 18 Dec 2020 05:34:11 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0ED1983DBC7; Fri, 18 Dec 2020 10:34:10 +0000 (UTC) Received: from bahia.redhat.com (ovpn-114-254.ams2.redhat.com [10.36.114.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAECB60BE5; Fri, 18 Dec 2020 10:34:08 +0000 (UTC) X-MC-Unique: CWDrG8YIPFSicWchJJz8OQ-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 5/6] spapr: Add drc_ prefix to the DRC realize and unrealize functions Date: Fri, 18 Dec 2020 11:33:59 +0100 Message-Id: <20201218103400.689660-6-groug@kaod.org> In-Reply-To: <20201218103400.689660-1-groug@kaod.org> References: <20201218103400.689660-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use a less generic name for an easier experience with tools such as cscope or grep. Signed-off-by: Greg Kurz Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- hw/ppc/spapr_drc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index a4d2608017c5..8571d5bafe4e 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -503,7 +503,7 @@ static const VMStateDescription vmstate_spapr_drc =3D { } }; =20 -static void realize(DeviceState *d, Error **errp) +static void drc_realize(DeviceState *d, Error **errp) { SpaprDrc *drc =3D SPAPR_DR_CONNECTOR(d); Object *root_container; @@ -530,7 +530,7 @@ static void realize(DeviceState *d, Error **errp) trace_spapr_drc_realize_complete(spapr_drc_index(drc)); } =20 -static void unrealize(DeviceState *d) +static void drc_unrealize(DeviceState *d) { SpaprDrc *drc =3D SPAPR_DR_CONNECTOR(d); Object *root_container; @@ -579,8 +579,8 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) { DeviceClass *dk =3D DEVICE_CLASS(k); =20 - dk->realize =3D realize; - dk->unrealize =3D unrealize; + dk->realize =3D drc_realize; + dk->unrealize =3D drc_unrealize; /* * Reason: DR connector needs to be wired to either the machine or to a * PHB in spapr_dr_connector_new(). @@ -628,7 +628,7 @@ static void realize_physical(DeviceState *d, Error **er= rp) SpaprDrcPhysical *drcp =3D SPAPR_DRC_PHYSICAL(d); Error *local_err =3D NULL; =20 - realize(d, &local_err); + drc_realize(d, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -644,7 +644,7 @@ static void unrealize_physical(DeviceState *d) { SpaprDrcPhysical *drcp =3D SPAPR_DRC_PHYSICAL(d); =20 - unrealize(d); + drc_unrealize(d); vmstate_unregister(VMSTATE_IF(drcp), &vmstate_spapr_drc_physical, drcp= ); qemu_unregister_reset(drc_physical_reset, drcp); } --=20 2.26.2 From nobody Sat May 18 19:47:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1608287794; cv=none; d=zohomail.com; s=zohoarc; b=YZkNVrAz0J3IF2j4SSZ05NBm6gM2UPzFJs7Ik5QSlAAJpLH4W/OPQQEK4HwlT0ofNTIg8djvSzi2/rECLv+vW0tcP8uTFP6K7YQNT70CLMOncqCcPW4eIFIobbpMQ2dJY5zJmqHI3Z5R6iEMHpG6uplyAaMXm7yUx4SnQSFD87s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608287794; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=e9TPFR8l5alQN3CqhDXzy5DCQE+nSCEb2CDqYEcSpP8=; b=Rm7sFmbNGGa8MAeP7ruS2azPDbM4bCQLzzAV7oZLGgwP0C1BqKLl9jdwfHDygEksEYWU51CLqbbFjeE/SYisJSkoLeghYmwstqJyvLZa+m96RanblST4pCgC13Nd3NXtoYJpCuzEocLF0lQNqu4roQu1W3J7FwZM4gPKEtKh/RE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608287794725670.7122420684846; Fri, 18 Dec 2020 02:36:34 -0800 (PST) Received: from localhost ([::1]:55406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqD7h-0003P4-EW for importer@patchew.org; Fri, 18 Dec 2020 05:36:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqD5Z-0000uz-Sn for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:21 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:53990) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqD5V-00020M-HH for qemu-devel@nongnu.org; Fri, 18 Dec 2020 05:34:21 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-478-LGMM8i7LN8Ovh-JGaMoIig-1; Fri, 18 Dec 2020 05:34:12 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 848C2800479; Fri, 18 Dec 2020 10:34:11 +0000 (UTC) Received: from bahia.redhat.com (ovpn-114-254.ams2.redhat.com [10.36.114.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B0E560C47; Fri, 18 Dec 2020 10:34:10 +0000 (UTC) X-MC-Unique: LGMM8i7LN8Ovh-JGaMoIig-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 6/6] spapr: Model DR connectors as simple objects Date: Fri, 18 Dec 2020 11:34:00 +0100 Message-Id: <20201218103400.689660-7-groug@kaod.org> In-Reply-To: <20201218103400.689660-1-groug@kaod.org> References: <20201218103400.689660-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Modeling DR connectors as individual devices raises some concerns, as already discussed a year ago in this thread: https://patchew.org/QEMU/20191017205953.13122-1-cheloha@linux.vnet.ibm.com/ First, high maxmem settings creates too many DRC devices. This causes scalability issues. It severely increase boot time because the multiple traversals of the DRC list that are performed during machine setup are quadratic operations. This is directly related to the fact that DRCs are modeled as individual devices and added to the composition tree. Second, DR connectors are really an internal concept of PAPR. They aren't something that the user or management layer can manipulate in any way. We already don't allow their creation with device_add by clearing user_creatable. DR connectors don't even need to be modeled as actual devices since they don't sit in a bus. They just need to be associated to an 'owner' object and to have the equivalent of realize/unrealize functions. Downgrade them to be simple objects. Convert the existing realize() and unrealize() to be methods of the DR connector base class. Also have the base class to inherit from the vmstate_if interface directly. The get_id() hook simply returns NULL, just as device_vmstate_if_get_id() does for devices that don't sit in a bus. The DR connector is no longer made a child object. This means that it must be explicitely freed when no longer needed. This is only required for PHBs and PCI bridges actually : have them to free the DRC with spapr_dr_connector_free() instead of object_unparent(). No longer add the DRCs to the QOM composition tree. Track them with a glib hash table using the global DRC index as the key instead. This makes traversal a linear operation. Signed-off-by: Greg Kurz Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- include/hw/ppc/spapr_drc.h | 8 +- hw/ppc/spapr_drc.c | 166 ++++++++++++++----------------------- hw/ppc/spapr_pci.c | 2 +- 3 files changed, 69 insertions(+), 107 deletions(-) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 8982927d5c24..a26aa8b9d4c3 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -170,7 +170,7 @@ typedef enum { =20 typedef struct SpaprDrc { /*< private >*/ - DeviceState parent; + Object parent; =20 uint32_t id; Object *owner; @@ -193,7 +193,7 @@ struct SpaprMachineState; =20 typedef struct SpaprDrcClass { /*< private >*/ - DeviceClass parent; + ObjectClass parent; SpaprDrcState empty_state; SpaprDrcState ready_state; =20 @@ -209,6 +209,9 @@ typedef struct SpaprDrcClass { =20 int (*dt_populate)(SpaprDrc *drc, struct SpaprMachineState *spapr, void *fdt, int *fdt_start_offset, Error **errp); + + void (*realize)(SpaprDrc *drc); + void (*unrealize)(SpaprDrc *drc); } SpaprDrcClass; =20 typedef struct SpaprDrcPhysical { @@ -232,6 +235,7 @@ SpaprDrcType spapr_drc_type(SpaprDrc *drc); =20 SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type, uint32_t id); +void spapr_dr_connector_free(SpaprDrc *drc); SpaprDrc *spapr_drc_by_index(uint32_t index); SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id); int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_m= ask); diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 8571d5bafe4e..e26763f8b5a4 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -27,7 +27,6 @@ #include "sysemu/reset.h" #include "trace.h" =20 -#define DRC_CONTAINER_PATH "/dr-connector" #define DRC_INDEX_TYPE_SHIFT 28 #define DRC_INDEX_ID_MASK ((1ULL << DRC_INDEX_TYPE_SHIFT) - 1) =20 @@ -503,65 +502,56 @@ static const VMStateDescription vmstate_spapr_drc =3D= { } }; =20 -static void drc_realize(DeviceState *d, Error **errp) +static GHashTable *drc_hash_table(void) { - SpaprDrc *drc =3D SPAPR_DR_CONNECTOR(d); - Object *root_container; - gchar *link_name; - const char *child_name; + static GHashTable *dht; =20 + if (!dht) { + dht =3D g_hash_table_new(NULL, NULL); + } + + return dht; +} + + +static void drc_realize(SpaprDrc *drc) +{ trace_spapr_drc_realize(spapr_drc_index(drc)); - /* NOTE: we do this as part of realize/unrealize due to the fact - * that the guest will communicate with the DRC via RTAS calls - * referencing the global DRC index. By unlinking the DRC - * from DRC_CONTAINER_PATH/ we effectively make it - * inaccessible by the guest, since lookups rely on this path - * existing in the composition tree - */ - root_container =3D container_get(object_get_root(), DRC_CONTAINER_PATH= ); - link_name =3D g_strdup_printf("%x", spapr_drc_index(drc)); - child_name =3D object_get_canonical_path_component(OBJECT(drc)); - trace_spapr_drc_realize_child(spapr_drc_index(drc), child_name); - object_property_add_alias(root_container, link_name, - drc->owner, child_name); - g_free(link_name); + + g_hash_table_insert(drc_hash_table(), + GUINT_TO_POINTER(spapr_drc_index(drc)), drc); vmstate_register(VMSTATE_IF(drc), spapr_drc_index(drc), &vmstate_spapr= _drc, drc); trace_spapr_drc_realize_complete(spapr_drc_index(drc)); } =20 -static void drc_unrealize(DeviceState *d) +static void drc_unrealize(SpaprDrc *drc) { - SpaprDrc *drc =3D SPAPR_DR_CONNECTOR(d); - Object *root_container; - gchar *name; - trace_spapr_drc_unrealize(spapr_drc_index(drc)); vmstate_unregister(VMSTATE_IF(drc), &vmstate_spapr_drc, drc); - root_container =3D container_get(object_get_root(), DRC_CONTAINER_PATH= ); - name =3D g_strdup_printf("%x", spapr_drc_index(drc)); - object_property_del(root_container, name); - g_free(name); + g_hash_table_remove(drc_hash_table(), + GUINT_TO_POINTER(spapr_drc_index(drc))); } =20 SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type, uint32_t id) { SpaprDrc *drc =3D SPAPR_DR_CONNECTOR(object_new(type)); - char *prop_name; =20 drc->id =3D id; - drc->owner =3D owner; - prop_name =3D g_strdup_printf("dr-connector[%"PRIu32"]", - spapr_drc_index(drc)); - object_property_add_child(owner, prop_name, OBJECT(drc)); - object_unref(OBJECT(drc)); - qdev_realize(DEVICE(drc), NULL, NULL); - g_free(prop_name); + drc->owner =3D object_ref(owner); + SPAPR_DR_CONNECTOR_GET_CLASS(drc)->realize(drc); =20 return drc; } =20 +void spapr_dr_connector_free(SpaprDrc *drc) +{ + SPAPR_DR_CONNECTOR_GET_CLASS(drc)->unrealize(drc); + object_unref(drc->owner); + object_unref(drc); +} + static void spapr_dr_connector_instance_init(Object *obj) { SpaprDrc *drc =3D SPAPR_DR_CONNECTOR(obj); @@ -575,17 +565,19 @@ static void spapr_dr_connector_instance_init(Object *= obj) drc->state =3D drck->empty_state; } =20 +static char *drc_vmstate_if_get_id(VMStateIf *obj) +{ + return NULL; +} + static void spapr_dr_connector_class_init(ObjectClass *k, void *data) { - DeviceClass *dk =3D DEVICE_CLASS(k); + SpaprDrcClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); + VMStateIfClass *vc =3D VMSTATE_IF_CLASS(k); =20 - dk->realize =3D drc_realize; - dk->unrealize =3D drc_unrealize; - /* - * Reason: DR connector needs to be wired to either the machine or to a - * PHB in spapr_dr_connector_new(). - */ - dk->user_creatable =3D false; + drck->realize =3D drc_realize; + drck->unrealize =3D drc_unrealize; + vc->get_id =3D drc_vmstate_if_get_id; } =20 static bool drc_physical_needed(void *opaque) @@ -623,39 +615,32 @@ static void drc_physical_reset(void *opaque) } } =20 -static void realize_physical(DeviceState *d, Error **errp) +static void realize_physical(SpaprDrc *drc) { - SpaprDrcPhysical *drcp =3D SPAPR_DRC_PHYSICAL(d); - Error *local_err =3D NULL; - - drc_realize(d, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } + SpaprDrcPhysical *drcp =3D SPAPR_DRC_PHYSICAL(drc); =20 + drc_realize(drc); vmstate_register(VMSTATE_IF(drcp), spapr_drc_index(SPAPR_DR_CONNECTOR(drcp)), &vmstate_spapr_drc_physical, drcp); qemu_register_reset(drc_physical_reset, drcp); } =20 -static void unrealize_physical(DeviceState *d) +static void unrealize_physical(SpaprDrc *drc) { - SpaprDrcPhysical *drcp =3D SPAPR_DRC_PHYSICAL(d); + SpaprDrcPhysical *drcp =3D SPAPR_DRC_PHYSICAL(drc); =20 - drc_unrealize(d); - vmstate_unregister(VMSTATE_IF(drcp), &vmstate_spapr_drc_physical, drcp= ); qemu_unregister_reset(drc_physical_reset, drcp); + vmstate_unregister(VMSTATE_IF(drcp), &vmstate_spapr_drc_physical, drcp= ); + drc_unrealize(drc); } =20 static void spapr_drc_physical_class_init(ObjectClass *k, void *data) { - DeviceClass *dk =3D DEVICE_CLASS(k); SpaprDrcClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); =20 - dk->realize =3D realize_physical; - dk->unrealize =3D unrealize_physical; + drck->realize =3D realize_physical; + drck->unrealize =3D unrealize_physical; drck->dr_entity_sense =3D physical_entity_sense; drck->isolate =3D drc_isolate_physical; drck->unisolate =3D drc_unisolate_physical; @@ -731,12 +716,16 @@ static void spapr_drc_pmem_class_init(ObjectClass *k,= void *data) =20 static const TypeInfo spapr_dr_connector_info =3D { .name =3D TYPE_SPAPR_DR_CONNECTOR, - .parent =3D TYPE_DEVICE, + .parent =3D TYPE_OBJECT, .instance_size =3D sizeof(SpaprDrc), .instance_init =3D spapr_dr_connector_instance_init, .class_size =3D sizeof(SpaprDrcClass), .class_init =3D spapr_dr_connector_class_init, .abstract =3D true, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_VMSTATE_IF }, + { } + }, }; =20 static const TypeInfo spapr_drc_physical_info =3D { @@ -789,14 +778,9 @@ static const TypeInfo spapr_drc_pmem_info =3D { =20 SpaprDrc *spapr_drc_by_index(uint32_t index) { - Object *obj; - gchar *name; - - name =3D g_strdup_printf("%s/%x", DRC_CONTAINER_PATH, index); - obj =3D object_resolve_path(name, NULL); - g_free(name); - - return !obj ? NULL : SPAPR_DR_CONNECTOR(obj); + return + SPAPR_DR_CONNECTOR(g_hash_table_lookup(drc_hash_table(), + GUINT_TO_POINTER(index))); } =20 SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id) @@ -824,13 +808,12 @@ SpaprDrc *spapr_drc_by_id(const char *type, uint32_t = id) */ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_m= ask) { - Object *root_container; - ObjectProperty *prop; - ObjectPropertyIterator iter; + GHashTableIter iter; uint32_t drc_count =3D 0; GArray *drc_indexes, *drc_power_domains; GString *drc_names, *drc_types; int ret; + SpaprDrc *drc; =20 /* * This should really be only called once per node since it overwrites @@ -851,26 +834,12 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner= , uint32_t drc_type_mask) drc_names =3D g_string_set_size(g_string_new(NULL), sizeof(uint32_t)); drc_types =3D g_string_set_size(g_string_new(NULL), sizeof(uint32_t)); =20 - /* aliases for all DRConnector objects will be rooted in QOM - * composition tree at DRC_CONTAINER_PATH - */ - root_container =3D container_get(object_get_root(), DRC_CONTAINER_PATH= ); - - object_property_iter_init(&iter, root_container); - while ((prop =3D object_property_iter_next(&iter))) { - Object *obj; - SpaprDrc *drc; + g_hash_table_iter_init(&iter, drc_hash_table()); + while (g_hash_table_iter_next(&iter, NULL, (gpointer) &drc)) { SpaprDrcClass *drck; char *drc_name =3D NULL; uint32_t drc_index, drc_power_domain; =20 - if (!strstart(prop->type, "link<", NULL)) { - continue; - } - - obj =3D object_property_get_link(root_container, prop->name, - &error_abort); - drc =3D SPAPR_DR_CONNECTOR(obj); drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 if (owner && (drc->owner !=3D owner)) { @@ -951,23 +920,12 @@ out: =20 void spapr_drc_reset_all(SpaprMachineState *spapr) { - Object *drc_container; - ObjectProperty *prop; - ObjectPropertyIterator iter; + GHashTableIter iter; + SpaprDrc *drc; =20 - drc_container =3D container_get(object_get_root(), DRC_CONTAINER_PATH); restart: - object_property_iter_init(&iter, drc_container); - while ((prop =3D object_property_iter_next(&iter))) { - SpaprDrc *drc; - - if (!strstart(prop->type, "link<", NULL)) { - continue; - } - drc =3D SPAPR_DR_CONNECTOR(object_property_get_link(drc_container, - prop->name, - &error_abort)); - + g_hash_table_iter_init(&iter, drc_hash_table()); + while (g_hash_table_iter_next(&iter, NULL, (gpointer) &drc)) { /* * This will complete any pending plug/unplug requests. * In case of a unplugged PHB or PCI bridge, this will diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 76d7c91e9c64..ca0cca664e3c 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1262,7 +1262,7 @@ static void remove_drcs(SpaprPhbState *phb, PCIBus *b= us) SpaprDrc *drc =3D drc_from_devfn(phb, chassis, i); =20 if (drc) { - object_unparent(OBJECT(drc)); + spapr_dr_connector_free(drc); } } } --=20 2.26.2