From nobody Thu May 2 07:35:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496160470249564.7635817354766; Tue, 30 May 2017 09:07:50 -0700 (PDT) Received: from localhost ([::1]:54851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFjgS-00061S-Ql for importer@patchew.org; Tue, 30 May 2017 12:07:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFjdd-0003va-7T for qemu-devel@nongnu.org; Tue, 30 May 2017 12:04:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFjda-0007GC-0P for qemu-devel@nongnu.org; Tue, 30 May 2017 12:04:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFjdZ-0007G3-Nx; Tue, 30 May 2017 12:04:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6493E3680A; Tue, 30 May 2017 16:04:48 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F6BD18B8E; Tue, 30 May 2017 16:04:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6493E3680A Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lvivier@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6493E3680A From: Laurent Vivier To: David Gibson Date: Tue, 30 May 2017 18:04:45 +0200 Message-Id: <20170530160445.12810-1-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 30 May 2017 16:04:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] spapr: manage hotplugged devices while the VM is not started 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: Laurent Vivier , Thomas Huth , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For QEMU, a hotlugged device is a device added using the HMP/QMP interface. For SPAPR, a hotplugged device is a device added while the machine is running. In this case QEMU doesn't update internal state but relies on the OS for this part In the case of migration, when we (libvirt) hotplug a device on the source guest, we (libvirt) generally hotplug the same device on the destination guest. But in this case, the machine is stopped (RUN_STATE_INMIGRATE) and QEMU must not expect the OS will manage it as an hotplugged device as it will be "imported" by the migration. This patch changes the meaning of "hotplugged" in spapr.c to manage a QEMU hotplugged device like a "coldplugged" one when the machine is awaiting an incoming migration. Signed-off-by: Laurent Vivier Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 0980d73..f1302d0 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2511,6 +2511,12 @@ static void spapr_nmi(NMIState *n, int cpu_index, Er= ror **errp) } } =20 +static bool spapr_coldplugged(DeviceState *dev) +{ + return runstate_check(RUN_STATE_INMIGRATE) || + !dev->hotplugged; +} + static void spapr_add_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t= size, uint32_t node, bool dedicated_hp_event_source, Error **errp) @@ -2521,6 +2527,7 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, int i, fdt_offset, fdt_size; void *fdt; uint64_t addr =3D addr_start; + bool coldplugged =3D spapr_coldplugged(dev); =20 for (i =3D 0; i < nr_lmbs; i++) { drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB, @@ -2532,9 +2539,9 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, SPAPR_MEMORY_BLOCK_SIZE); =20 drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, errp); + drck->attach(drc, dev, fdt, fdt_offset, coldplugged, errp); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; - if (!dev->hotplugged) { + if (coldplugged) { /* guests expect coldplugged LMBs to be pre-allocated */ drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USAB= LE); drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOL= ATED); @@ -2543,7 +2550,7 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, /* send hotplug notification to the * guest only in case of hotplugged memory */ - if (dev->hotplugged) { + if (!coldplugged) { if (dedicated_hp_event_source) { drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB, addr_start / SPAPR_MEMORY_BLOCK_SIZE); @@ -2776,6 +2783,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev, int smt =3D kvmppc_smt_threads(); CPUArchId *core_slot; int index; + bool coldplugged =3D spapr_coldplugged(dev); =20 core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &= index); if (!core_slot) { @@ -2797,7 +2805,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev, =20 if (drc) { sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, &local_e= rr); + drck->attach(drc, dev, fdt, fdt_offset, coldplugged, &local_err); if (local_err) { g_free(fdt); error_propagate(errp, local_err); @@ -2805,7 +2813,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev, } } =20 - if (dev->hotplugged) { + if (!coldplugged) { /* * Send hotplug notification interrupt to the guest only in case * of hotplugged CPUs. @@ -2838,7 +2846,7 @@ static void spapr_core_pre_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, int node_id; int index; =20 - if (dev->hotplugged && !mc->has_hotpluggable_cpus) { + if (!spapr_coldplugged(dev) && !mc->has_hotpluggable_cpus) { error_setg(&local_err, "CPU hotplug not supported for this machine= "); goto out; } --=20 2.9.4