From nobody Thu Mar 28 21:06:06 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=1605915980; cv=none; d=zohomail.com; s=zohoarc; b=ElQvSOhxFkUoh2zMEXzBlrp13rRZzlXugfSLxPuzAPn+WLNGU0npbAh+0YOl9X+JDFYfAH4oNiGbrNOU6O5hYtXj8P9rykV6Y/iy7Cu/izAQFyUiykOFnQRqO3f6+W9z3NaTVdHDdvykbOtfKqG978GrwaxEodIQAMd34tGmjz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605915980; 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=01u0YiXs9UOiyipOWXoHCxpMP6ceo797Ybmvg4mc0jg=; b=VipgvY01raXLrTDVYAzsbV9ietuoCrU98Pbs1ujuR6Y1r27rqGia5TQElAER4TijIGyNzVsLecxRUEa5uL8+uLqXZvP9QvcBmSG4rsaxZ+YTFWMTklRK5f9i9oNoWVTMlOcSnmhBolG7VFYM3KMMznRtH/rK2/kw0wIhodsubHs= 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 1605915980221766.6896145968107; Fri, 20 Nov 2020 15:46:20 -0800 (PST) Received: from localhost ([::1]:43598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgG6d-00027W-2x for importer@patchew.org; Fri, 20 Nov 2020 18:46:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgG2o-0005oh-Jg for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:22 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:31624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgG2l-0003lL-LU for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:22 -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-386-3w8wJV-EPi2qEVOJ3GTMAA-1; Fri, 20 Nov 2020 18:42:13 -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 C83B1107AD38; Fri, 20 Nov 2020 23:42:12 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9800260BFA; Fri, 20 Nov 2020 23:42:11 +0000 (UTC) X-MC-Unique: 3w8wJV-EPi2qEVOJ3GTMAA-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 1/9] spapr: Do PCI device hotplug sanity checks at pre-plug only Date: Sat, 21 Nov 2020 00:42:00 +0100 Message-Id: <20201120234208.683521-2-groug@kaod.org> In-Reply-To: <20201120234208.683521-1-groug@kaod.org> References: <20201120234208.683521-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=205.139.111.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, RCVD_IN_DNSWL_NONE=-0.0001, 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: Igor Mammedov , 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" The PHB acts as the hotplug handler for PCI devices. It does some sanity checks on DR enablement, PCI bridge chassis numbers and multifunction. These checks are currently performed at plug time, but they would best sit in a pre-plug handler in order to error out as early as possible. Create a spapr_pci_pre_plug() handler and move all the checking there. Add a check that the associated DRC doesn't already have an attached device. This is equivalent to the slot availability check performed by do_pci_register_device() upon realization of the PCI device. This allows to pass &error_abort to spapr_drc_attach() and to end up with a plug handler that doesn't need to report errors anymore. Signed-off-by: Greg Kurz --- hw/ppc/spapr_pci.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 88ce87f130a5..2829f298d9c1 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1532,8 +1532,8 @@ static bool bridge_has_valid_chassis_nr(Object *bridg= e, Error **errp) return true; } =20 -static void spapr_pci_plug(HotplugHandler *plug_handler, - DeviceState *plugged_dev, Error **errp) +static void spapr_pci_pre_plug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, Error **errp) { SpaprPhbState *phb =3D SPAPR_PCI_HOST_BRIDGE(DEVICE(plug_handler)); PCIDevice *pdev =3D PCI_DEVICE(plugged_dev); @@ -1542,9 +1542,6 @@ static void spapr_pci_plug(HotplugHandler *plug_handl= er, PCIBus *bus =3D PCI_BUS(qdev_get_parent_bus(DEVICE(pdev))); uint32_t slotnr =3D PCI_SLOT(pdev->devfn); =20 - /* if DR is disabled we don't need to do anything in the case of - * hotplug or coldplug callbacks - */ if (!phb->dr_enabled) { /* if this is a hotplug operation initiated by the user * we need to let them know it's not enabled @@ -1552,17 +1549,14 @@ static void spapr_pci_plug(HotplugHandler *plug_han= dler, if (plugged_dev->hotplugged) { error_setg(errp, QERR_BUS_NO_HOTPLUG, object_get_typename(OBJECT(phb))); + return; } - return; } =20 - g_assert(drc); - if (pc->is_bridge) { if (!bridge_has_valid_chassis_nr(OBJECT(plugged_dev), errp)) { return; } - spapr_pci_bridge_plug(phb, PCI_BRIDGE(plugged_dev)); } =20 /* Following the QEMU convention used for PCIe multifunction @@ -1574,13 +1568,41 @@ static void spapr_pci_plug(HotplugHandler *plug_han= dler, error_setg(errp, "PCI: slot %d function 0 already occupied by %s," " additional functions can no longer be exposed to gues= t.", slotnr, bus->devices[PCI_DEVFN(slotnr, 0)]->name); + } + + if (drc && drc->dev) { + error_setg(errp, "PCI: slot %d already occupied by %s", slotnr, + pci_get_function_0(PCI_DEVICE(drc->dev))->name); return; } +} + +static void spapr_pci_plug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, Error **errp) +{ + SpaprPhbState *phb =3D SPAPR_PCI_HOST_BRIDGE(DEVICE(plug_handler)); + PCIDevice *pdev =3D PCI_DEVICE(plugged_dev); + PCIDeviceClass *pc =3D PCI_DEVICE_GET_CLASS(plugged_dev); + SpaprDrc *drc =3D drc_from_dev(phb, pdev); + uint32_t slotnr =3D PCI_SLOT(pdev->devfn); =20 - if (!spapr_drc_attach(drc, DEVICE(pdev), errp)) { + /* + * If DR is disabled we don't need to do anything in the case of + * hotplug or coldplug callbacks. + */ + if (!phb->dr_enabled) { return; } =20 + g_assert(drc); + + if (pc->is_bridge) { + spapr_pci_bridge_plug(phb, PCI_BRIDGE(plugged_dev)); + } + + /* spapr_pci_pre_plug() already checked the DRC is attachable */ + spapr_drc_attach(drc, DEVICE(pdev), &error_abort); + /* If this is function 0, signal hotplug for all the device functions. * Otherwise defer sending the hotplug event. */ @@ -2223,6 +2245,7 @@ static void spapr_phb_class_init(ObjectClass *klass, = void *data) /* Supported by TYPE_SPAPR_MACHINE */ dc->user_creatable =3D true; set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + hp->pre_plug =3D spapr_pci_pre_plug; hp->plug =3D spapr_pci_plug; hp->unplug =3D spapr_pci_unplug; hp->unplug_request =3D spapr_pci_unplug_request; --=20 2.26.2 From nobody Thu Mar 28 21:06:06 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=1605915869; cv=none; d=zohomail.com; s=zohoarc; b=agJ4XqrixJdsVP8zLQ6Fybkn7gzwmYSKzIZPrvdCmYJhf4bdXmiYmj1q0nscT36RGHHovl99DSGC8gyQ+HQtmszsjYSZG/pGTYmYJv341DZsmhfTxtl6UtyY9QGzhDlLtrwTTUTAmwlC/wljrY9k7knUcBgIiRyucYi/zq6KI4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605915869; 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=To7DTjOG1K/18WI0nh5+GTsfFf46TaPFB+bgwkxCwcU=; b=DkENMG4JaaubVbGfURzklxXLjXeswpHDEPcwsR4tiEeSPgjwlPYBC4pkpi/ERvNYszElhsdWUKYoKkXU6p16FfP2XN0k+N0//krgdoAlaXVshYiHAL3h7SgxFqooYkTpFHhhzFTHGIpHKInM05P5vx45qKzrIIqR5yDJHw4JcYI= 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 1605915869198953.6007138215892; Fri, 20 Nov 2020 15:44:29 -0800 (PST) Received: from localhost ([::1]:36294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgG4q-0007ZD-0J for importer@patchew.org; Fri, 20 Nov 2020 18:44:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgG2o-0005os-NR for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:22 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:22316) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgG2m-0003lc-GU for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:22 -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-545-rCgckIQEMPKOzJnqLoTVfQ-1; Fri, 20 Nov 2020 18:42:15 -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 4C4118030A8; Fri, 20 Nov 2020 23:42:14 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21C7860BFA; Fri, 20 Nov 2020 23:42:12 +0000 (UTC) X-MC-Unique: rCgckIQEMPKOzJnqLoTVfQ-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 2/9] spapr: Do NVDIMM/PC-DIMM device hotplug sanity checks at pre-plug only Date: Sat, 21 Nov 2020 00:42:01 +0100 Message-Id: <20201120234208.683521-3-groug@kaod.org> In-Reply-To: <20201120234208.683521-1-groug@kaod.org> References: <20201120234208.683521-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: Igor Mammedov , 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" Pre-plug of a memory device, be it an NVDIMM or a PC-DIMM, ensures that the memory slot is available and that addresses don't overlap with existing memory regions. The corresponding DRCs in the LMB and PMEM namespaces are thus necessarily attachable at plug time. Pass &error_abort to spapr_drc_attach() in spapr_add_lmbs() and spapr_add_nvdimm(). This allows to greatly simplify error handling on the plug path. Signed-off-by: Greg Kurz --- include/hw/ppc/spapr_nvdimm.h | 2 +- hw/ppc/spapr.c | 40 ++++++++++++----------------------- hw/ppc/spapr_nvdimm.c | 11 +++++----- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/include/hw/ppc/spapr_nvdimm.h b/include/hw/ppc/spapr_nvdimm.h index 344582d2f5f7..73be250e2ac9 100644 --- a/include/hw/ppc/spapr_nvdimm.h +++ b/include/hw/ppc/spapr_nvdimm.h @@ -30,6 +30,6 @@ int spapr_pmem_dt_populate(SpaprDrc *drc, SpaprMachineSta= te *spapr, void spapr_dt_persistent_memory(SpaprMachineState *spapr, void *fdt); bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdi= mm, uint64_t size, Error **errp); -bool spapr_add_nvdimm(DeviceState *dev, uint64_t slot, Error **errp); +void spapr_add_nvdimm(DeviceState *dev, uint64_t slot); =20 #endif diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 12a012d9dd09..394d28d9e081 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3382,8 +3382,8 @@ int spapr_lmb_dt_populate(SpaprDrc *drc, SpaprMachine= State *spapr, return 0; } =20 -static bool spapr_add_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t= size, - bool dedicated_hp_event_source, Error **errp) +static void spapr_add_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t= size, + bool dedicated_hp_event_source) { SpaprDrc *drc; uint32_t nr_lmbs =3D size/SPAPR_MEMORY_BLOCK_SIZE; @@ -3396,15 +3396,12 @@ static bool spapr_add_lmbs(DeviceState *dev, uint64= _t addr_start, uint64_t size, addr / SPAPR_MEMORY_BLOCK_SIZE); g_assert(drc); =20 - if (!spapr_drc_attach(drc, dev, errp)) { - while (addr > addr_start) { - 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); - } - return false; - } + /* + * memory_device_get_free_addr() provided a range of free addresses + * that doesn't overlap with any existing mapping at pre-plug. The + * corresponding LMB DRCs are thus assumed to be all attachable. + */ + spapr_drc_attach(drc, dev, &error_abort); if (!hotplugged) { spapr_drc_reset(drc); } @@ -3425,11 +3422,9 @@ static bool spapr_add_lmbs(DeviceState *dev, uint64_= t addr_start, uint64_t size, nr_lmbs); } } - return true; } =20 -static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *de= v, - Error **errp) +static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *de= v) { SpaprMachineState *ms =3D SPAPR_MACHINE(hotplug_dev); PCDIMMDevice *dimm =3D PC_DIMM(dev); @@ -3444,24 +3439,15 @@ static void spapr_memory_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, if (!is_nvdimm) { addr =3D object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP, &error_abort); - if (!spapr_add_lmbs(dev, addr, size, - spapr_ovec_test(ms->ov5_cas, OV5_HP_EVT), errp= )) { - goto out_unplug; - } + spapr_add_lmbs(dev, addr, size, + spapr_ovec_test(ms->ov5_cas, OV5_HP_EVT)); } else { slot =3D object_property_get_int(OBJECT(dimm), PC_DIMM_SLOT_PROP, &error_abort); /* We should have valid slot number at this point */ g_assert(slot >=3D 0); - if (!spapr_add_nvdimm(dev, slot, errp)) { - goto out_unplug; - } + spapr_add_nvdimm(dev, slot); } - - return; - -out_unplug: - pc_dimm_unplug(dimm, MACHINE(ms)); } =20 static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState= *dev, @@ -4009,7 +3995,7 @@ static void spapr_machine_device_plug(HotplugHandler = *hotplug_dev, DeviceState *dev, Error **errp) { if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { - spapr_memory_plug(hotplug_dev, dev, errp); + spapr_memory_plug(hotplug_dev, dev); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { spapr_core_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE= )) { diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c index a833a63b5ed3..2f1c196e1b76 100644 --- a/hw/ppc/spapr_nvdimm.c +++ b/hw/ppc/spapr_nvdimm.c @@ -89,7 +89,7 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, N= VDIMMDevice *nvdimm, } =20 =20 -bool spapr_add_nvdimm(DeviceState *dev, uint64_t slot, Error **errp) +void spapr_add_nvdimm(DeviceState *dev, uint64_t slot) { SpaprDrc *drc; bool hotplugged =3D spapr_drc_hotplugged(dev); @@ -97,14 +97,15 @@ bool spapr_add_nvdimm(DeviceState *dev, uint64_t slot, = Error **errp) drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_PMEM, slot); g_assert(drc); =20 - if (!spapr_drc_attach(drc, dev, errp)) { - return false; - } + /* + * pc_dimm_get_free_slot() provided a free slot at pre-plug. The + * corresponding DRC is thus assumed to be attachable. + */ + spapr_drc_attach(drc, dev, &error_abort); =20 if (hotplugged) { spapr_hotplug_req_add_by_index(drc); } - return true; } =20 static int spapr_dt_nvdimm(SpaprMachineState *spapr, void *fdt, --=20 2.26.2 From nobody Thu Mar 28 21:06:06 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=1605916080; cv=none; d=zohomail.com; s=zohoarc; b=LwbG/Y1tDtAAlRCjM6ZWhN0BsHsPaFKBVhAGhmtpXFmbwhtiXgZLgfwBISiHV8sYjEL17PViZMWGl1FbK/XjkNUyfaa3eQqNUe+F4bVlOzwp8R5VLCoHE1uAnsto79Ig3TefgqAF3WudKTCrPc1U3MM/3n16rDAF4Iokoj7mVbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605916080; 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=QXU4OuqXogyCTxnHF70qUpIWZRCRYa5TO6lH/tGYL7Y=; b=L8vE6TzKeW08v1ameRVeqXTORGt4dXj2OUaiNQQN1eOTBbvw6v+T3SPLCu0e+SuNzaW+0Vx0eHyC8aAyFIE3xv1DcYhyCH0H+1lpCbsZSmyplUFTocMPvdV4Oh2yOZ5mPWmfaFaYTpqrZ5SxfdTpPPN/pXnoKGLx00BnIw+zfe4= 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 1605916080211495.1448244263562; Fri, 20 Nov 2020 15:48:00 -0800 (PST) Received: from localhost ([::1]:47844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgG8F-0003uM-4e for importer@patchew.org; Fri, 20 Nov 2020 18:47:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgG2q-0005su-RO for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:24 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:56164) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgG2p-0003mu-CR for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:24 -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-108-2aFfESXHMBaUy86Wwsp1tQ-1; Fri, 20 Nov 2020 18:42:16 -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 C34621842142; Fri, 20 Nov 2020 23:42:15 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9907660BFA; Fri, 20 Nov 2020 23:42:14 +0000 (UTC) X-MC-Unique: 2aFfESXHMBaUy86Wwsp1tQ-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 3/9] spapr: Fix pre-2.10 dummy ICP hack Date: Sat, 21 Nov 2020 00:42:02 +0100 Message-Id: <20201120234208.683521-4-groug@kaod.org> In-Reply-To: <20201120234208.683521-1-groug@kaod.org> References: <20201120234208.683521-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: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, 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: Igor Mammedov , 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" This hack registers dummy VMState entries of ICPs in order to support migration of old pseries machine types that used to create all smp.max_cpus possible ICPs at machine init. Part of the work is to unregister the dummy entries when plugging an actual vCPU core, and to register them back when unplugging the core. The code that unregisters the dummy ICPs in spapr_core_plug() is misplaced: if ppc_set_compat() fails afterwards, the hotplug operation will be cancelled and the dummy ICPs won't be registered back since the unplug handler isn't called. Unregister the dummy ICPs at the end of spapr_core_plug(). Signed-off-by: Greg Kurz --- The next patch makes this patch a bit useless. I post it anyway for the records because it is a programming error. --- hw/ppc/spapr.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 394d28d9e081..f58f77389e8e 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3785,13 +3785,6 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, =20 core_slot->cpu =3D OBJECT(dev); =20 - if (smc->pre_2_10_has_unused_icps) { - for (i =3D 0; i < cc->nr_threads; i++) { - cs =3D CPU(core->threads[i]); - pre_2_10_vmstate_unregister_dummy_icp(cs->cpu_index); - } - } - /* * Set compatibility mode to match the boot CPU, which was either set * by the machine reset code or by CAS. @@ -3805,6 +3798,13 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, } } } + + if (smc->pre_2_10_has_unused_icps) { + for (i =3D 0; i < cc->nr_threads; i++) { + cs =3D CPU(core->threads[i]); + pre_2_10_vmstate_unregister_dummy_icp(cs->cpu_index); + } + } } =20 static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *= dev, --=20 2.26.2 From nobody Thu Mar 28 21:06:06 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=1605916148; cv=none; d=zohomail.com; s=zohoarc; b=HO2E/tWNZ7ISca1RbXJhNjOjUiNrzBZ3BYQeVQ/ROLN7Ruetit/XIJqZD+wWlSro606cBUOI7E9XqNsYh5O5MWSS7zhi6AB7WnLpnpe/rkpEkOidX3+KRtssk9TZR/kZmxnyexDepqppHyNR7JNGi+96LVCnIyCMJm7cS3hBJgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605916148; 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=Zf41aSuBC3oGhKlsunb7CKLdbBTuV7YMmi6L7hYbIv4=; b=lk3izDABesuwcHGb+JjJEX+yBzqTDZbD5dZkOAj/v5v9xd6h6+25DJUtB7vc3cRdK0dE3299Ra+1wXPrltBcdCLc+536WeDZDG+MJ8+daqqx5AcgoVgHvrSlZZUVYoP5STjNlSLl82R3vxg3Gc7KHVCx+GQNveQimMK2ahG6pxw= 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 1605916148728900.9283671999661; Fri, 20 Nov 2020 15:49:08 -0800 (PST) Received: from localhost ([::1]:52562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgG9L-0005nR-CX for importer@patchew.org; Fri, 20 Nov 2020 18:49:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgG2z-00064k-FJ for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:33 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:23082) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgG2w-0003p3-6s for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:33 -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-577-YmoUWXCHMnCSpOqAD4tUUw-1; Fri, 20 Nov 2020 18:42:18 -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 472CD8030A8; Fri, 20 Nov 2020 23:42:17 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D93260BFA; Fri, 20 Nov 2020 23:42:15 +0000 (UTC) X-MC-Unique: YmoUWXCHMnCSpOqAD4tUUw-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 4/9] spapr: Set compat mode in spapr_reset_vcpu() Date: Sat, 21 Nov 2020 00:42:03 +0100 Message-Id: <20201120234208.683521-5-groug@kaod.org> In-Reply-To: <20201120234208.683521-1-groug@kaod.org> References: <20201120234208.683521-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: Igor Mammedov , 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" When it comes to resetting the compat mode of the vCPUS, there are two situations to consider: (1) machine reset should set the compat mode back to the machine default, ie. spapr->max_compat_pvr (2) hot plugged vCPUs should set their compat mode to mach the boot vCPU, ie. POWERPC_CPU(first_cpu)->compat_pvr This is currently handled in two separate places: globally for all vCPUs from the machine reset code for (1) and for each thread of a core from the hotplug path for (2). Since the machine reset code already resets all vCPUs, starting with boot vCPU, consolidate the logic in spapr_reset_vcpu(). Special case the boot vCPU so that it resets its compat mode back to the machine default. Any other vCPU just need to match the compat mode of the boot vCPU. Failing to set the compat mode during machine reset is a fatal error, but not for hot plugged vCPUs. This is arguable because if we've been able to set the boot vCPU compat mode at CAS or during machine reset, it should definitely not fail for other vCPUs. Since spapr_reset_vcpu() already has a fatal error path for kvm_check_mmu() failures, do the same for ppc_set_compat(). This gets rid of an error path in spapr_core_plug(). It will allow further simplifications. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 16 ---------------- hw/ppc/spapr_cpu_core.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index f58f77389e8e..da7586f548df 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1606,8 +1606,6 @@ static void spapr_machine_reset(MachineState *machine) spapr_ovec_cleanup(spapr->ov5_cas); spapr->ov5_cas =3D spapr_ovec_new(); =20 - ppc_set_compat_all(spapr->max_compat_pvr, &error_fatal); - /* * This is fixing some of the default configuration of the XIVE * devices. To be called after the reset of the machine devices. @@ -3785,20 +3783,6 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, =20 core_slot->cpu =3D OBJECT(dev); =20 - /* - * Set compatibility mode to match the boot CPU, which was either set - * by the machine reset code or by CAS. - */ - if (hotplugged) { - for (i =3D 0; i < cc->nr_threads; i++) { - if (ppc_set_compat(core->threads[i], - POWERPC_CPU(first_cpu)->compat_pvr, - errp) < 0) { - return; - } - } - } - if (smc->pre_2_10_has_unused_icps) { for (i =3D 0; i < cc->nr_threads; i++) { cs =3D CPU(core->threads[i]); diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 2f7dc3c23ded..17741a3fb77f 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -27,6 +27,7 @@ =20 static void spapr_reset_vcpu(PowerPCCPU *cpu) { + PowerPCCPU *first_ppc_cpu =3D POWERPC_CPU(first_cpu); CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); @@ -69,6 +70,18 @@ static void spapr_reset_vcpu(PowerPCCPU *cpu) kvm_check_mmu(cpu, &error_fatal); =20 spapr_irq_cpu_intc_reset(spapr, cpu); + + /* + * The boot CPU is only reset during machine reset : reset its + * compatibility mode to the machine default. For other CPUs, + * either cold plugged or hot plugged, set the compatibility mode + * to match the boot CPU, which was either set by the machine reset + * code or by CAS. + */ + ppc_set_compat(cpu, + cpu =3D=3D first_ppc_cpu ? + spapr->max_compat_pvr : first_ppc_cpu->compat_pvr, + &error_fatal); } =20 void spapr_cpu_set_entry_state(PowerPCCPU *cpu, target_ulong nip, --=20 2.26.2 From nobody Thu Mar 28 21:06:06 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=1605915899; cv=none; d=zohomail.com; s=zohoarc; b=VtEK+cKXie8h3fsn6W9i7m/f8aUhcwlTYIH5SlNk6DjxuVaIo8BnWPc00cDjlwtbO9Ui+lv2fg2FXMXNxtjNzbnm7Ifn4BQ9mA5EbOa2O4k5nsgHoJ48zQ4Q/lCjA7gnTOD1lEQhDFAk6C8xNomFNSL05FCRswP2Mg2IrZmNjE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605915899; 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=IYmA2K6XowhEbkKAnB6omygR5/IqarxyD2mfLPmC//8=; b=f+EWCt6TPBvQX12r9u+p1O+oAJGp/C+1+j11lFE9rUaw8IDHGGLmmXqm9vLsRhckmZcKfqbRZe92mGLC3Iu4I1n4eMBGsJrn929I4EOiRKStYZKmvGxyCVajzR2d/pwfIAlq+G3LC18pKhaywGG/ixpffGibhZ+yYua2Dcbp36Q= 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 1605915899092468.94555673673904; Fri, 20 Nov 2020 15:44:59 -0800 (PST) Received: from localhost ([::1]:37448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgG5J-000833-Vv for importer@patchew.org; Fri, 20 Nov 2020 18:44:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgG2w-0005wd-Ds for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:30 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:29533) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgG2r-0003oE-Ln for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:27 -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-67-W2nDmzIRMOOfUqAo2nWi3w-1; Fri, 20 Nov 2020 18:42:19 -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 C2CDC184215F; Fri, 20 Nov 2020 23:42:18 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 945F760BFA; Fri, 20 Nov 2020 23:42:17 +0000 (UTC) X-MC-Unique: W2nDmzIRMOOfUqAo2nWi3w-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 5/9] spapr: Simplify error path of spapr_core_plug() Date: Sat, 21 Nov 2020 00:42:04 +0100 Message-Id: <20201120234208.683521-6-groug@kaod.org> In-Reply-To: <20201120234208.683521-1-groug@kaod.org> References: <20201120234208.683521-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: Igor Mammedov , 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" spapr_core_pre_plug() already guarantees that the slot for the given core ID is available. It is thus safe to assume that spapr_find_cpu_slot() returns a slot during plug. Turn the error path into an assertion. It is also safe to assume that no device is attached to the corresponding DRC and that spapr_drc_attach() shouldn't fail. Pass &error_abort to spapr_drc_attach() and simplify error handling. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index da7586f548df..cfca033c7b14 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3739,8 +3739,7 @@ int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachin= eState *spapr, return 0; } =20 -static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, - Error **errp) +static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev) { SpaprMachineState *spapr =3D SPAPR_MACHINE(OBJECT(hotplug_dev)); MachineClass *mc =3D MACHINE_GET_CLASS(spapr); @@ -3755,20 +3754,20 @@ static void spapr_core_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, int i; =20 core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &= index); - if (!core_slot) { - error_setg(errp, "Unable to find CPU core with core-id: %d", - cc->core_id); - return; - } + g_assert(core_slot); /* Already checked in spapr_core_pre_plug() */ + drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, spapr_vcpu_id(spapr, cc->core_id)); =20 g_assert(drc || !mc->has_hotpluggable_cpus); =20 if (drc) { - if (!spapr_drc_attach(drc, dev, errp)) { - return; - } + /* + * spapr_core_pre_plug() already buys us this is a brand new + * core being plugged into a free slot. Nothing should already + * be attached to the corresponding DRC. + */ + spapr_drc_attach(drc, dev, &error_abort); =20 if (hotplugged) { /* @@ -3981,7 +3980,7 @@ static void spapr_machine_device_plug(HotplugHandler = *hotplug_dev, if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { spapr_memory_plug(hotplug_dev, dev); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { - spapr_core_plug(hotplug_dev, dev, errp); + spapr_core_plug(hotplug_dev, dev); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE= )) { spapr_phb_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_TPM_PROXY)) { --=20 2.26.2 From nobody Thu Mar 28 21:06:06 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=1605915903; cv=none; d=zohomail.com; s=zohoarc; b=d74db19peBI3wJ6DL8oVXaUU62SYv2ShqzrPgGrjiUIKdgp+PSXB4EATngNEzSGanpofTiOzfT6m7xslzierRx3+WP4YZ8leAeglv45Ouyem+V5+HzQ2VneT6s4EW6lcNgYycYeF+zmrmA+7/U26OW/mYZo0vucrYn0bsmHtmn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605915903; 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=yeTdKyxpflQxka1XicOsmUPq3O77zU77fYV8ntE91jg=; b=IpoihmsHZH9wu9DDUfVtRHPSZMdHjAg0a1+RvYKOto+qDccpfmm4HAc6bn1VrlHSPL5se0Jaz0TUi/ld16eN2z+NHWdSBoit2X5rwzvBOBHJWwtB6H38Xg5BbrdlPrFK2a5ts+jFAQO4UTvrYvoEG1uFksoML2ASNXejLmhUfoI= 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 1605915903296718.7446175052917; Fri, 20 Nov 2020 15:45:03 -0800 (PST) Received: from localhost ([::1]:37864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgG5O-0008D5-0Z for importer@patchew.org; Fri, 20 Nov 2020 18:45:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgG2w-0005wc-Dg for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:30 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:54345) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgG2s-0003oM-43 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:27 -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-450-sByPjo2fMH2LtGZFZB8Ztg-1; Fri, 20 Nov 2020 18:42:21 -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 4B19E107AD30; Fri, 20 Nov 2020 23:42:20 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BBE560BFA; Fri, 20 Nov 2020 23:42:18 +0000 (UTC) X-MC-Unique: sByPjo2fMH2LtGZFZB8Ztg-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 6/9] spapr: Make PHB placement functions and spapr_pre_plug_phb() return status Date: Sat, 21 Nov 2020 00:42:05 +0100 Message-Id: <20201120234208.683521-7-groug@kaod.org> In-Reply-To: <20201120234208.683521-1-groug@kaod.org> References: <20201120234208.683521-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: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, 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: Igor Mammedov , 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" Read documentation in "qapi/error.h" and changelog of commit e3fe3988d785 ("error: Document Error API usage rules") for rationale. Signed-off-by: Greg Kurz --- include/hw/ppc/spapr.h | 2 +- hw/ppc/spapr.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 2e89e36cfbdc..b7ced9faebf5 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -140,7 +140,7 @@ struct SpaprMachineClass { bool pre_5_1_assoc_refpoints; bool pre_5_2_numa_associativity; =20 - void (*phb_placement)(SpaprMachineState *spapr, uint32_t index, + bool (*phb_placement)(SpaprMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio,=20 hwaddr *mmio32, hwaddr *mmio64, unsigned n_dma, uint32_t *liobns, hwaddr *nv2gpa, diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index cfca033c7b14..81bac59887ab 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3865,7 +3865,7 @@ int spapr_phb_dt_populate(SpaprDrc *drc, SpaprMachine= State *spapr, return 0; } =20 -static void spapr_phb_pre_plug(HotplugHandler *hotplug_dev, DeviceState *d= ev, +static bool spapr_phb_pre_plug(HotplugHandler *hotplug_dev, DeviceState *d= ev, Error **errp) { SpaprMachineState *spapr =3D SPAPR_MACHINE(OBJECT(hotplug_dev)); @@ -3875,24 +3875,25 @@ static void spapr_phb_pre_plug(HotplugHandler *hotp= lug_dev, DeviceState *dev, =20 if (dev->hotplugged && !smc->dr_phb_enabled) { error_setg(errp, "PHB hotplug not supported for this machine"); - return; + return false; } =20 if (sphb->index =3D=3D (uint32_t)-1) { error_setg(errp, "\"index\" for PAPR PHB is mandatory"); - return; + return false; } =20 /* * This will check that sphb->index doesn't exceed the maximum number = of * PHBs for the current machine type. */ - smc->phb_placement(spapr, sphb->index, - &sphb->buid, &sphb->io_win_addr, - &sphb->mem_win_addr, &sphb->mem64_win_addr, - windows_supported, sphb->dma_liobn, - &sphb->nv2_gpa_win_addr, &sphb->nv2_atsd_win_addr, - errp); + return + smc->phb_placement(spapr, sphb->index, + &sphb->buid, &sphb->io_win_addr, + &sphb->mem_win_addr, &sphb->mem64_win_addr, + windows_supported, sphb->dma_liobn, + &sphb->nv2_gpa_win_addr, &sphb->nv2_atsd_win_ad= dr, + errp); } =20 static void spapr_phb_plug(HotplugHandler *hotplug_dev, DeviceState *dev, @@ -4130,7 +4131,7 @@ static const CPUArchIdList *spapr_possible_cpu_arch_i= ds(MachineState *machine) return machine->possible_cpus; } =20 -static void spapr_phb_placement(SpaprMachineState *spapr, uint32_t index, +static bool spapr_phb_placement(SpaprMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64, unsigned n_dma, uint32_t *liobns, @@ -4168,7 +4169,7 @@ static void spapr_phb_placement(SpaprMachineState *sp= apr, uint32_t index, if (index >=3D SPAPR_MAX_PHBS) { error_setg(errp, "\"index\" for PAPR PHB is too large (max %llu)", SPAPR_MAX_PHBS - 1); - return; + return false; } =20 *buid =3D base_buid + index; @@ -4182,6 +4183,7 @@ static void spapr_phb_placement(SpaprMachineState *sp= apr, uint32_t index, =20 *nv2gpa =3D SPAPR_PCI_NV2RAM64_WIN_BASE + index * SPAPR_PCI_NV2RAM64_W= IN_SIZE; *nv2atsd =3D SPAPR_PCI_NV2ATSD_WIN_BASE + index * SPAPR_PCI_NV2ATSD_WI= N_SIZE; + return true; } =20 static ICSState *spapr_ics_get(XICSFabric *dev, int irq) @@ -4561,18 +4563,21 @@ DEFINE_SPAPR_MACHINE(4_1, "4.1", false); /* * pseries-4.0 */ -static void phb_placement_4_0(SpaprMachineState *spapr, uint32_t index, +static bool phb_placement_4_0(SpaprMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64, unsigned n_dma, uint32_t *liobns, hwaddr *nv2gpa, hwaddr *nv2atsd, Error **err= p) { - spapr_phb_placement(spapr, index, buid, pio, mmio32, mmio64, n_dma, li= obns, - nv2gpa, nv2atsd, errp); + if (!spapr_phb_placement(spapr, index, buid, pio, mmio32, mmio64, n_dm= a, + liobns, nv2gpa, nv2atsd, errp)) { + return false; + } + *nv2gpa =3D 0; *nv2atsd =3D 0; + return true; } - static void spapr_machine_4_0_class_options(MachineClass *mc) { SpaprMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); @@ -4732,7 +4737,7 @@ DEFINE_SPAPR_MACHINE(2_8, "2.8", false); * pseries-2.7 */ =20 -static void phb_placement_2_7(SpaprMachineState *spapr, uint32_t index, +static bool phb_placement_2_7(SpaprMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, hwaddr *mmio32, hwaddr *mmio64, unsigned n_dma, uint32_t *liobns, @@ -4764,7 +4769,7 @@ static void phb_placement_2_7(SpaprMachineState *spap= r, uint32_t index, if (index > max_index) { error_setg(errp, "\"index\" for PAPR PHB is too large (max %u)", max_index); - return; + return false; } =20 *buid =3D base_buid + index; @@ -4783,6 +4788,7 @@ static void phb_placement_2_7(SpaprMachineState *spap= r, uint32_t index, =20 *nv2gpa =3D 0; *nv2atsd =3D 0; + return true; } =20 static void spapr_machine_2_7_class_options(MachineClass *mc) --=20 2.26.2 From nobody Thu Mar 28 21:06:06 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=1605916007; cv=none; d=zohomail.com; s=zohoarc; b=mXybQiRznEapz39jN37/wSOcBq5rX6j3GqmYdy69lR0Q0UGv7md4OuJwYbx93FE6xxn3Bnb2RSMyTwrNfcbjfE/F9MDIDAWkArM/hI1lUlSh3v7R3mCvPEqhKisChU9SA8x9kWq5sSaIOlcbSbTNQNXSL7+Q4dI8G335hDuOA3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605916007; 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=rdtt46NB4a3t7SCrHoqwFeY9WaMbxERUABp0eWgPkLQ=; b=KUp5LrM3XNNcZHaqqbIGmIPmj3I12gk0NjAthNc585z1vDN1Nn33wAqSRo9DgQ4LxuRaLoVNQ9shn6fBgpt212CZLI4aSQ3vB9ofwYM9bcijAmptS4Q1pxMv/vLtvcuudEAVchZKkSa/oIaHQ4PKdU2sUCfUQAYgRDJLvZhFM34= 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 1605916007672923.9230718350329; Fri, 20 Nov 2020 15:46:47 -0800 (PST) Received: from localhost ([::1]:45474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgG74-0002vZ-My for importer@patchew.org; Fri, 20 Nov 2020 18:46:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgG2z-00064e-Eo for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:33 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:46997) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgG2w-0003ot-L1 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:33 -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-165-CA_hywLVPN28yxIKbMp6QA-1; Fri, 20 Nov 2020 18:42:23 -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 C474080ED8B; Fri, 20 Nov 2020 23:42:21 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98C8C60BFA; Fri, 20 Nov 2020 23:42:20 +0000 (UTC) X-MC-Unique: CA_hywLVPN28yxIKbMp6QA-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 7/9] spapr: Do PHB hoplug sanity check at pre-plug Date: Sat, 21 Nov 2020 00:42:06 +0100 Message-Id: <20201120234208.683521-8-groug@kaod.org> In-Reply-To: <20201120234208.683521-1-groug@kaod.org> References: <20201120234208.683521-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: Igor Mammedov , 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" We currently detect that a PHB index is already in use at plug time. But this can be decteted at pre-plug in order to error out earlier. This allows to pass &error_abort to spapr_drc_attach() and to end up with a plug handler that doesn't need to report errors anymore. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 81bac59887ab..bded059d59c8 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3872,6 +3872,7 @@ static bool spapr_phb_pre_plug(HotplugHandler *hotplu= g_dev, DeviceState *dev, SpaprPhbState *sphb =3D SPAPR_PCI_HOST_BRIDGE(dev); SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(spapr); const unsigned windows_supported =3D spapr_phb_windows_supported(sphb); + SpaprDrc *drc; =20 if (dev->hotplugged && !smc->dr_phb_enabled) { error_setg(errp, "PHB hotplug not supported for this machine"); @@ -3883,6 +3884,12 @@ static bool spapr_phb_pre_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, return false; } =20 + drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_PHB, sphb->index); + if (drc && drc->dev) { + error_setg(errp, "PHB %d already attached", sphb->index); + return false; + } + /* * This will check that sphb->index doesn't exceed the maximum number = of * PHBs for the current machine type. @@ -3896,8 +3903,7 @@ static bool spapr_phb_pre_plug(HotplugHandler *hotplu= g_dev, DeviceState *dev, errp); } =20 -static void spapr_phb_plug(HotplugHandler *hotplug_dev, DeviceState *dev, - Error **errp) +static void spapr_phb_plug(HotplugHandler *hotplug_dev, DeviceState *dev) { SpaprMachineState *spapr =3D SPAPR_MACHINE(OBJECT(hotplug_dev)); SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(spapr); @@ -3913,9 +3919,8 @@ static void spapr_phb_plug(HotplugHandler *hotplug_de= v, DeviceState *dev, /* hotplug hooks should check it's enabled before getting this far */ assert(drc); =20 - if (!spapr_drc_attach(drc, dev, errp)) { - return; - } + /* spapr_phb_pre_plug() already checked the DRC is attachable */ + spapr_drc_attach(drc, dev, &error_abort); =20 if (hotplugged) { spapr_hotplug_req_add_by_index(drc); @@ -3983,7 +3988,7 @@ static void spapr_machine_device_plug(HotplugHandler = *hotplug_dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { spapr_core_plug(hotplug_dev, dev); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE= )) { - spapr_phb_plug(hotplug_dev, dev, errp); + spapr_phb_plug(hotplug_dev, dev); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_TPM_PROXY)) { spapr_tpm_proxy_plug(hotplug_dev, dev, errp); } --=20 2.26.2 From nobody Thu Mar 28 21:06:06 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=1605916109; cv=none; d=zohomail.com; s=zohoarc; b=P1a8ZHRGaPnYUQY6mXSS4vidx0wsc7aJ2VKZWUZcT9XJLrrkRcbvl7Xy5y8TWUOXwwLrp5eNm1eVrsxhkhfQjSbC5Ibaj60VefUjCcUwNIrrbVfIkstD+Itpf32p41Y9XHBOILwdoy0DeyLWBWrqzeOsmpk6QjVrUlRQVsHB+5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605916109; 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=GuDEmZ40+380i8LP/tXZWPlqNcMq8TrKCGuD6OguxeY=; b=gD0J96a8IO/1sbxmXbZgKPQOC8tLmC9Hfjr7P86t7ZI2mM3azDQy7UL2QLasJFPpz/8GhZPyfG82WLISKAiwz9Fcan5O/vlvdbGrKC1rf5KhRKXIOnHZ6uqwL2WKX7Kn+y5G/X1T+vN0kOFatdiXPX2bhFWVfLp0NdBFeN0qWB8= 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 160591610955091.8057900473924; Fri, 20 Nov 2020 15:48:29 -0800 (PST) Received: from localhost ([::1]:49882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgG8i-0004jc-Hl for importer@patchew.org; Fri, 20 Nov 2020 18:48:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgG31-00068T-02 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:35 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:44215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgG2x-0003qg-3n for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:34 -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-427-WnjQsAg_M9eiGMbRVaTiLQ-1; Fri, 20 Nov 2020 18:42:26 -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 518C88030BF; Fri, 20 Nov 2020 23:42:25 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C92F60BFA; Fri, 20 Nov 2020 23:42:21 +0000 (UTC) X-MC-Unique: WnjQsAg_M9eiGMbRVaTiLQ-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 8/9] spapr: Do TPM proxy hotplug sanity checks at pre-plug Date: Sat, 21 Nov 2020 00:42:07 +0100 Message-Id: <20201120234208.683521-9-groug@kaod.org> In-Reply-To: <20201120234208.683521-1-groug@kaod.org> References: <20201120234208.683521-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: Igor Mammedov , 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" There can be only one TPM proxy at a time. This is currently checked at plug time. But this can be detected at pre-plug in order to error out earlier. This allows to get rid of error handling in the plug handler. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index bded059d59c8..5e32d1d396b4 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3957,17 +3957,28 @@ static void spapr_phb_unplug_request(HotplugHandler= *hotplug_dev, } } =20 -static void spapr_tpm_proxy_plug(HotplugHandler *hotplug_dev, DeviceState = *dev, - Error **errp) +static +bool spapr_tpm_proxy_pre_plug(HotplugHandler *hotplug_dev, DeviceState *de= v, + Error **errp) { SpaprMachineState *spapr =3D SPAPR_MACHINE(OBJECT(hotplug_dev)); - SpaprTpmProxy *tpm_proxy =3D SPAPR_TPM_PROXY(dev); =20 if (spapr->tpm_proxy !=3D NULL) { error_setg(errp, "Only one TPM proxy can be specified for this mac= hine"); - return; + return false; } =20 + return true; +} + +static void spapr_tpm_proxy_plug(HotplugHandler *hotplug_dev, DeviceState = *dev) +{ + SpaprMachineState *spapr =3D SPAPR_MACHINE(OBJECT(hotplug_dev)); + SpaprTpmProxy *tpm_proxy =3D SPAPR_TPM_PROXY(dev); + + /* Already checked in spapr_tpm_proxy_pre_plug() */ + g_assert(spapr->tpm_proxy =3D=3D NULL); + spapr->tpm_proxy =3D tpm_proxy; } =20 @@ -3990,7 +4001,7 @@ static void spapr_machine_device_plug(HotplugHandler = *hotplug_dev, } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE= )) { spapr_phb_plug(hotplug_dev, dev); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_TPM_PROXY)) { - spapr_tpm_proxy_plug(hotplug_dev, dev, errp); + spapr_tpm_proxy_plug(hotplug_dev, dev); } } =20 @@ -4053,6 +4064,8 @@ static void spapr_machine_device_pre_plug(HotplugHand= ler *hotplug_dev, spapr_core_pre_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE= )) { spapr_phb_pre_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_TPM_PROXY)) { + spapr_tpm_proxy_pre_plug(hotplug_dev, dev, errp); } } =20 --=20 2.26.2 From nobody Thu Mar 28 21:06:06 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=1605916262; cv=none; d=zohomail.com; s=zohoarc; b=EH/3Q7Ki0TyFu6o3sFkptTddC2wyr3A+SIQ4DM/yvfbW8vnjRyYhLl6uLiuHy/U4NHGpcy2sVQAykOcDVyjm7wYt5zNw2PxjD1cQ2+w2Bo0qIx/IhDlCubAhQx8raZ/VRvtfz4l0Z2uW4JFeFnxmu3KqNCBcseqx1//Eiw+kUM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605916262; 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=DA59ZcL23gtOHShJMzohtLWtvLn5FBAaDb87pj6ITdo=; b=UadQRtlCRTN/aFBLV/edxN0E7bfFqZAdsCeYREc3sRhREV+lEuXGqXi9Xq4eswA9Y94a48RroXkPPo0lbH0mZsHIX6AD0RhSS6dHHpKAvGVPrITeV0cerqSBIjgahafAMutqDk6m4vH77M6eK/2nVjIfj/IFnK1MtRJa3oDQN8o= 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 1605916262490795.8709328497522; Fri, 20 Nov 2020 15:51:02 -0800 (PST) Received: from localhost ([::1]:55794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgGBB-0007BN-BH for importer@patchew.org; Fri, 20 Nov 2020 18:51:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgG32-0006CH-32 for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:36 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:23481) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kgG2y-0003ri-Af for qemu-devel@nongnu.org; Fri, 20 Nov 2020 18:42:35 -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-222-sJ6QseE9NEiTFkV_EfkmOg-1; Fri, 20 Nov 2020 18:42:27 -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 C7BD580ED9D; Fri, 20 Nov 2020 23:42:26 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F25060BFA; Fri, 20 Nov 2020 23:42:25 +0000 (UTC) X-MC-Unique: sJ6QseE9NEiTFkV_EfkmOg-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 9/9] spapr: spapr_drc_attach() cannot fail Date: Sat, 21 Nov 2020 00:42:08 +0100 Message-Id: <20201120234208.683521-10-groug@kaod.org> In-Reply-To: <20201120234208.683521-1-groug@kaod.org> References: <20201120234208.683521-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=205.139.111.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, RCVD_IN_DNSWL_NONE=-0.0001, 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: Igor Mammedov , 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" All users are passing &error_abort already. Document the fact that spapr_drc_attach() should only be passed a free DRC, which is supposedly the case if appropriate checking is done earlier. Signed-off-by: Greg Kurz --- include/hw/ppc/spapr_drc.h | 8 +++++++- hw/ppc/spapr.c | 6 +++--- hw/ppc/spapr_drc.c | 8 ++------ hw/ppc/spapr_nvdimm.c | 2 +- hw/ppc/spapr_pci.c | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 165b281496bb..def3593adc8b 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -235,7 +235,13 @@ 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); =20 -bool spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp); +/* + * These functions respectively abort if called with a device already + * attached or no device attached. In the case of spapr_drc_attach(), + * this means that the attachability of the DRC *must* be checked + * beforehand (eg. check drc->dev at pre-plug). + */ +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 */ diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 5e32d1d396b4..e0047f41073e 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3399,7 +3399,7 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, * that doesn't overlap with any existing mapping at pre-plug. The * corresponding LMB DRCs are thus assumed to be all attachable. */ - spapr_drc_attach(drc, dev, &error_abort); + spapr_drc_attach(drc, dev); if (!hotplugged) { spapr_drc_reset(drc); } @@ -3767,7 +3767,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev) * core being plugged into a free slot. Nothing should already * be attached to the corresponding DRC. */ - spapr_drc_attach(drc, dev, &error_abort); + spapr_drc_attach(drc, dev); =20 if (hotplugged) { /* @@ -3920,7 +3920,7 @@ static void spapr_phb_plug(HotplugHandler *hotplug_de= v, DeviceState *dev) assert(drc); =20 /* spapr_phb_pre_plug() already checked the DRC is attachable */ - spapr_drc_attach(drc, dev, &error_abort); + spapr_drc_attach(drc, dev); =20 if (hotplugged) { spapr_hotplug_req_add_by_index(drc); diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 77718cde1ff2..f991cf89a08a 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -369,14 +369,11 @@ static void prop_get_fdt(Object *obj, Visitor *v, con= st char *name, } while (fdt_depth !=3D 0); } =20 -bool spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp) +void spapr_drc_attach(SpaprDrc *drc, DeviceState *d) { trace_spapr_drc_attach(spapr_drc_index(drc)); =20 - if (drc->dev) { - error_setg(errp, "an attached device is still awaiting release"); - return false; - } + g_assert(!drc->dev); g_assert((drc->state =3D=3D SPAPR_DRC_STATE_LOGICAL_UNUSABLE) || (drc->state =3D=3D SPAPR_DRC_STATE_PHYSICAL_POWERON)); =20 @@ -386,7 +383,6 @@ bool spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Er= ror **errp) object_get_typename(OBJECT(drc->dev)), (Object **)(&drc->dev), NULL, 0); - return true; } =20 static void spapr_drc_release(SpaprDrc *drc) diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c index 2f1c196e1b76..73ee006541a6 100644 --- a/hw/ppc/spapr_nvdimm.c +++ b/hw/ppc/spapr_nvdimm.c @@ -101,7 +101,7 @@ void spapr_add_nvdimm(DeviceState *dev, uint64_t slot) * pc_dimm_get_free_slot() provided a free slot at pre-plug. The * corresponding DRC is thus assumed to be attachable. */ - spapr_drc_attach(drc, dev, &error_abort); + spapr_drc_attach(drc, dev); =20 if (hotplugged) { spapr_hotplug_req_add_by_index(drc); diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 2829f298d9c1..e946bd5055cc 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1601,7 +1601,7 @@ static void spapr_pci_plug(HotplugHandler *plug_handl= er, } =20 /* spapr_pci_pre_plug() already checked the DRC is attachable */ - spapr_drc_attach(drc, DEVICE(pdev), &error_abort); + spapr_drc_attach(drc, DEVICE(pdev)); =20 /* If this is function 0, signal hotplug for all the device functions. * Otherwise defer sending the hotplug event. --=20 2.26.2