From nobody Wed Nov 5 21:46:05 2025 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 1537440719992433.0300699370016; Thu, 20 Sep 2018 03:51:59 -0700 (PDT) Received: from localhost ([::1]:49448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wYw-0002GO-IE for importer@patchew.org; Thu, 20 Sep 2018 06:51:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wIM-00042O-OJ for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wIL-0007TN-OJ for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18023) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wIL-0007SR-GO; Thu, 20 Sep 2018 06:34:49 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE0ED3003091; Thu, 20 Sep 2018 10:34:48 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 623AE3091327; Thu, 20 Sep 2018 10:34:45 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:42 +0200 Message-Id: <20180920103243.28474-22-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 20 Sep 2018 10:34:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 21/22] 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , 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 0f8b509f0f..0342e4482b 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= )); @@ -205,6 +211,34 @@ static void virtio_pmem_class_init(ObjectClass *klass,= void *data) mdc->get_device_id =3D virtio_pmem_md_get_device_id; } =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