From nobody Sat Feb 7 06:04:35 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1535558061251950.9833982435613; Wed, 29 Aug 2018 08:54:21 -0700 (PDT) Received: from localhost ([::1]:43709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fv2nU-0007ZY-5u for importer@patchew.org; Wed, 29 Aug 2018 11:54:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fv2XC-00052g-MK for qemu-devel@nongnu.org; Wed, 29 Aug 2018 11:37:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fv2XB-0002Gx-Nq for qemu-devel@nongnu.org; Wed, 29 Aug 2018 11:37:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59590 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fv2XB-0002Gn-H1 for qemu-devel@nongnu.org; Wed, 29 Aug 2018 11:37:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24D81807A0C2; Wed, 29 Aug 2018 15:37:29 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-206.ams2.redhat.com [10.36.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82C51A9FAB; Wed, 29 Aug 2018 15:37:23 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 29 Aug 2018 17:36:23 +0200 Message-Id: <20180829153624.12299-20-david@redhat.com> In-Reply-To: <20180829153624.12299-1-david@redhat.com> References: <20180829153624.12299-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 29 Aug 2018 15:37:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 29 Aug 2018 15:37:29 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 19/20] virtio-pmem: hotplug support functions 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Paolo Bonzini , Igor Mammedov , Luiz Capitulino , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" virtio-pmem devices will have to be hotplugged using the machine hotplug handler just like other memory devices. Therefore, all machines that want to support virtio-pmem will have to modify their machine hotplug handler. virtio-pmem devices are realized when their parent proxy device (virtio-pmem-pci) is realized. Therefore, they are attached to a bus without a hotplug handler. This makes things a lot easier, because without a hotplug handler, we can directly get control over the device in the machine hotplug handler (otherwise we would have to overwrite control and pass control to the bus hotplug handler from the machine hotplug handler). As we have to implement support for each machine we want to support, add a safety net ("pre_plugged") that catches if the pre_plug handler was not called - if trying to realize it with a machine that does not support it. Otherwise creating and realizing virtio-pmem-pci along with virtio-pmem would work, however the memory-device part would not properly get hotplugged. Signed-off-by: David Hildenbrand --- hw/virtio/virtio-pmem.c | 34 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-pmem.h | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c index 27ff064682..ca65be4af2 100644 --- a/hw/virtio/virtio-pmem.c +++ b/hw/virtio/virtio-pmem.c @@ -112,6 +112,12 @@ static void virtio_pmem_realize(DeviceState *dev, Erro= r **errp) return; } =20 + /* pre_plug handler wasn't executed (e.g. from machine hotplug handler= ) */ + if (!pmem->pre_plugged) { + error_setg(errp, "virtio-pmem is not compatible with the machine"); + return; + } + host_memory_backend_set_mapped(pmem->memdev, true); virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM, sizeof(struct virtio_pmem_config= )); @@ -203,6 +209,34 @@ static void virtio_pmem_class_init(ObjectClass *klass,= void *data) mdc->fill_device_info =3D virtio_pmem_md_fill_device_info; } =20 +void virtio_pmem_pre_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp) +{ + /* + * The proxy device (e.g. virtio-pmem-pci) has an hotplug handler and + * will attach the virtio-pmem device to its bus (parent_bus). This + * device will realize the virtio-mem device from its realize function, + * therefore when it is hotplugged itself. The proxy device bus + * therefore has no hotplug handler and we don't have to forward any + * calls. + */ + if (!DEVICE(pmem)->parent_bus || + DEVICE(pmem)->parent_bus->hotplug_handler) { + error_setg(errp, "virtio-pmem is not compatible with the proxy."); + } + memory_device_pre_plug(MEMORY_DEVICE(pmem), ms, NULL, errp); + pmem->pre_plugged =3D true; +} + +void virtio_pmem_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp) +{ + memory_device_plug(MEMORY_DEVICE(pmem), ms); +} + +void virtio_pmem_unplug(VirtIOPMEM *pmem, MachineState *ms, Error **errp) +{ + memory_device_unplug(MEMORY_DEVICE(pmem), ms); +} + static TypeInfo virtio_pmem_info =3D { .name =3D TYPE_VIRTIO_PMEM, .parent =3D TYPE_VIRTIO_DEVICE, diff --git a/include/hw/virtio/virtio-pmem.h b/include/hw/virtio/virtio-pme= m.h index 11e549e0f1..640051f3b6 100644 --- a/include/hw/virtio/virtio-pmem.h +++ b/include/hw/virtio/virtio-pmem.h @@ -31,10 +31,21 @@ typedef struct VirtIOPMEM { VirtQueue *rq_vq; uint64_t start; HostMemoryBackend *memdev; + + /* + * Safety net to make sure we can catch trying to be realized on a + * machine that is not prepared to properly hotplug virtio-pmem from + * its machine hotplug handler. + */ + bool pre_plugged; } VirtIOPMEM; =20 struct virtio_pmem_config { uint64_t start; uint64_t size; }; + +void virtio_pmem_pre_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp= ); +void virtio_pmem_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp); +void virtio_pmem_unplug(VirtIOPMEM *pmem, MachineState *ms, Error **errp); #endif --=20 2.17.1