From nobody Wed Feb 11 05:59:59 2026 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 150821459174335.940567609113145; Mon, 16 Oct 2017 21:29:51 -0700 (PDT) Received: from localhost ([::1]:36371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4JVh-0005va-RO for importer@patchew.org; Tue, 17 Oct 2017 00:29:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50391) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4JOT-0008IC-S2 for qemu-devel@nongnu.org; Tue, 17 Oct 2017 00:22:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4JOS-0006vc-AY for qemu-devel@nongnu.org; Tue, 17 Oct 2017 00:22:17 -0400 Received: from ozlabs.org ([103.22.144.67]:45247) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e4JOR-0006s5-Va; Tue, 17 Oct 2017 00:22:16 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3yGMTq5Vmkz9t2Q; Tue, 17 Oct 2017 15:22:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1508214127; bh=GBRH10Lmv89cs6cKDkcHX0K1PgNr+h3t9RmcrjhG3xo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oFDTb4oOJMGWErkl/p7ECkhX0tKSfuGZv9hSjYBoDkcfsLl9b29QnB4sjtSdtBIMk tixpztb4wFpsR7srO3yam8BOEThTmquKBppcKoYZWKV4Lh6IVbG9Vhy3wef61sscO1 01c60n1T84D6nczG+GnqsvhJvIakaRGunyLGPrI4= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 17 Oct 2017 15:21:26 +1100 Message-Id: <20171017042152.29443-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171017042152.29443-1-david@gibson.dropbear.id.au> References: <20171017042152.29443-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] [PULL 08/34] hw/ppc/spapr.c: abort unplug_request if previous unplug isn't done 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: agraf@suse.de, ehabkost@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, imammedo@redhat.com, Daniel Henrique Barboza , 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: Daniel Henrique Barboza LMB removal is completed only when the spapr_lmb_release callback is called after all DRCs of the dimm are detached. During this time, it is possible that a unplug request for the same dimm arrives, trying to detach DRCs that were detached by the guest in the first unplug_request. BQL doesn't help in this case - the lock will prevent any concurrent removal from happening until the end of spapr_memory_unplug_request only. What happens is that the second unplug_request ends up calling spapr_drc_detach in a DRC that were detached already, causing an assert error in spapr_drc_detach (e.g https://bugs.launchpad.net/qemu/+bug/1718118). spapr_lmb_release uses a structure called sPAPRDIMMState, stored in the spapr->pending_dimm_unplugs QTAIL, to track how many LMB DRCs are left to be detached by the guest. When there are no more DRCs left, this structure is deleted and the pc-dimm unplug handler is called to finish the process. This patch reuses the sPAPRDIMMState to allow unplug_request to know if there is an ongoing unplug process for a given dimm, aborting the unplug request in this case, by doing the following changes: - in spapr_lmb_release callback, move the dimm state removal to the end, after pc-dimm unplug handler. With this change we can check for the existence of the dimm state to see if the unplug process is done. - use spapr_pending_dimm_unplugs_find in spapr_memory_unplug_request to check if the dimm state exists. If positive, there is an unplug operation already in progress for this dimm, meaning that we should abort it and warn the user about it. Fixes: https://bugs.launchpad.net/qemu/+bug/1718118 Signed-off-by: Daniel Henrique Barboza Signed-off-by: David Gibson --- hw/ppc/spapr.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 079e493ef4..147fd2cfd3 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3061,14 +3061,13 @@ void spapr_lmb_release(DeviceState *dev) return; } =20 - spapr_pending_dimm_unplugs_remove(spapr, ds); - /* * Now that all the LMBs have been removed by the guest, call the * pc-dimm unplug handler to cleanup up the pc-dimm device. */ pc_dimm_memory_unplug(dev, &spapr->hotplug_memory, mr); object_unparent(OBJECT(dev)); + spapr_pending_dimm_unplugs_remove(spapr, ds); } =20 static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev, @@ -3097,6 +3096,19 @@ static void spapr_memory_unplug_request(HotplugHandl= er *hotplug_dev, goto out; } =20 + /* + * An existing pending dimm state for this DIMM means that there is an + * unplug operation in progress, waiting for the spapr_lmb_release + * callback to complete the job (BQL can't cover that far). In this ca= se, + * bail out to avoid detaching DRCs that were already released. + */ + if (spapr_pending_dimm_unplugs_find(spapr, dimm)) { + error_setg(&local_err, + "Memory unplug already in progress for device %s", + dev->id); + goto out; + } + spapr_pending_dimm_unplugs_add(spapr, nr_lmbs, dimm); =20 addr =3D addr_start; --=20 2.13.6