From nobody Sun Apr 28 23:05:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558608116; cv=none; d=zoho.com; s=zohoarc; b=Z/6kWHrvVTmqwGNZiCE1r6wPAgqfV50e+e1mqZY33CzD6u/YbpzFIvPycZOFqZmWgCD+7/N9KiqMGiRxmGr8pXQNaxr6PJXTEgTi9VBPED1yCHoBpk560NggqkG0wPMTL02cLbP57/IXSZ1KLxUaJ43fICWoX+Rqv8Eu6MDfEeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558608116; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=StSwD4a9FM6AyGKXCje+Xzgg0gcmBejw9hTuImnwd4U=; b=Sn3Z/EqmeroSJL04QS/qJjCdgfyg3bl191T6Peqw7y1TcWzb8B0YbcmAQeBowl3m0dGhuniXm3KhdSrHx9nHNCHeg6UlfNg6GdZbn4U4EQnyIkL3el8iTretEqq1sF3KAUpM1xZThDGznyByBeZB7EruEXRH5tQwEZT0jrelqhk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558608116695501.0886247989488; Thu, 23 May 2019 03:41:56 -0700 (PDT) Received: from localhost ([127.0.0.1]:33317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTlAQ-0002ai-Is for importer@patchew.org; Thu, 23 May 2019 06:41:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTkvP-00060Y-5b for qemu-devel@nongnu.org; Thu, 23 May 2019 06:26:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTkvM-0001Vl-7v for qemu-devel@nongnu.org; Thu, 23 May 2019 06:26:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55640) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTkvK-00014n-3i for qemu-devel@nongnu.org; Thu, 23 May 2019 06:26:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8F4A21BAA; Thu, 23 May 2019 10:25:47 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (ovpn-116-162.sin2.redhat.com [10.67.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D41A6606C; Thu, 23 May 2019 10:25:20 +0000 (UTC) From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 15:54:43 +0530 Message-Id: <20190523102449.2642-2-pagupta@redhat.com> In-Reply-To: <20190523102449.2642-1-pagupta@redhat.com> References: <20190523102449.2642-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 23 May 2019 10:25:47 +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 1/7] virtio-pmem: add virtio device 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: kwolf@redhat.com, aarcange@redhat.com, cohuck@redhat.com, xiaoguangrong.eric@gmail.com, mst@redhat.com, pagupta@redhat.com, riel@surriel.com, david@redhat.com, armbru@redhat.com, ehabkost@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, dan.j.williams@intel.com, nilal@redhat.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is the implementation of virtio-pmem device. Support will require machine changes for the architectures that will support it, so it will not yet be compiled. It can be unlocked with VIRTIO_PMEM_SUPPORTED per machine and disabled globally via VIRTIO_PMEM. We cannot use the "addr" property as that is already used e.g. for virtio-pci/pci devices. And we will have e.g. virtio-pmem-pci as a proxy. So we have to choose a different one (unfortunately). "memaddr" it is. That name should ideally be used by all other virtio-* based memory devices in the future. -device virtio-pmem-pci,id=3Dp0,bus=3Dbux0,addr=3D0x01,memaddr=3D0x1000= 000... Acked-by: Markus Armbruster [ QAPI bits ] Signed-off-by: Pankaj Gupta [ MemoryDevice/MemoryRegion changes, cleanups, addr property "memaddr", split up patches, unplug handler ] Signed-off-by: David Hildenbrand --- hw/virtio/Kconfig | 10 +++ hw/virtio/Makefile.objs | 1 + hw/virtio/virtio-pmem.c | 190 ++++++++++++++++++++++++++++++++++++= ++++ include/hw/virtio/virtio-pmem.h | 49 +++++++++++ qapi/misc.json | 28 +++++- 5 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 hw/virtio/virtio-pmem.c create mode 100644 include/hw/virtio/virtio-pmem.h diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index e0452de4ba..3724ff8bac 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -29,3 +29,13 @@ config VIRTIO_CRYPTO bool default y depends on VIRTIO + +config VIRTIO_PMEM_SUPPORTED + bool + +config VIRTIO_PMEM + bool + default y + depends on VIRTIO + depends on VIRTIO_PMEM_SUPPORTED + select MEM_DEVICE diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index f2ab667a21..a5bdbb16aa 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -12,6 +12,7 @@ common-obj-$(CONFIG_VIRTIO_MMIO) +=3D virtio-mmio.o obj-$(CONFIG_VIRTIO_BALLOON) +=3D virtio-balloon.o obj-$(CONFIG_VIRTIO_CRYPTO) +=3D virtio-crypto.o obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) +=3D virtio-= crypto-pci.o +obj-$(CONFIG_VIRTIO_PMEM) +=3D virtio-pmem.o obj-$(CONFIG_VHOST_VSOCK) +=3D vhost-vsock.o =20 ifeq ($(CONFIG_VIRTIO_PCI),y) diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c new file mode 100644 index 0000000000..c462d2c942 --- /dev/null +++ b/hw/virtio/virtio-pmem.c @@ -0,0 +1,190 @@ +/* + * Virtio PMEM device + * + * Copyright (C) 2018-2019 Red Hat, Inc. + * + * Authors: + * Pankaj Gupta + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "qemu/error-report.h" +#include "hw/virtio/virtio-pmem.h" +#include "hw/virtio/virtio-access.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_pmem.h" +#include "block/aio.h" +#include "block/thread-pool.h" + +typedef struct VirtIODeviceRequest { + VirtQueueElement elem; + int fd; + VirtIOPMEM *pmem; + VirtIODevice *vdev; + struct virtio_pmem_req req; + struct virtio_pmem_resp resp; +} VirtIODeviceRequest; + +static int worker_cb(void *opaque) +{ + VirtIODeviceRequest *req_data =3D opaque; + int err =3D 0; + + /* flush raw backing image */ + err =3D fsync(req_data->fd); + if (err !=3D 0) { + err =3D 1; + } + + virtio_stw_p(req_data->vdev, &req_data->resp.ret, err); + + return 0; +} + +static void done_cb(void *opaque, int ret) +{ + VirtIODeviceRequest *req_data =3D opaque; + int len =3D iov_from_buf(req_data->elem.in_sg, req_data->elem.in_num, = 0, + &req_data->resp, sizeof(struct virtio_pmem_r= esp)); + + /* Callbacks are serialized, so no need to use atomic ops. */ + virtqueue_push(req_data->pmem->rq_vq, &req_data->elem, len); + virtio_notify((VirtIODevice *)req_data->pmem, req_data->pmem->rq_vq); + g_free(req_data); +} + +static void virtio_pmem_flush(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIODeviceRequest *req_data; + VirtIOPMEM *pmem =3D VIRTIO_PMEM(vdev); + HostMemoryBackend *backend =3D MEMORY_BACKEND(pmem->memdev); + ThreadPool *pool =3D aio_get_thread_pool(qemu_get_aio_context()); + + req_data =3D virtqueue_pop(vq, sizeof(VirtIODeviceRequest)); + if (!req_data) { + virtio_error(vdev, "virtio-pmem missing request data"); + return; + } + + if (req_data->elem.out_num < 1 || req_data->elem.in_num < 1) { + virtio_error(vdev, "virtio-pmem request not proper"); + g_free(req_data); + return; + } + req_data->fd =3D memory_region_get_fd(&backend->mr); + req_data->pmem =3D pmem; + req_data->vdev =3D vdev; + thread_pool_submit_aio(pool, worker_cb, req_data, done_cb, req_data); +} + +static void virtio_pmem_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VirtIOPMEM *pmem =3D VIRTIO_PMEM(vdev); + struct virtio_pmem_config *pmemcfg =3D (struct virtio_pmem_config *) c= onfig; + + virtio_stq_p(vdev, &pmemcfg->start, pmem->start); + virtio_stq_p(vdev, &pmemcfg->size, memory_region_size(&pmem->memdev->m= r)); +} + +static uint64_t virtio_pmem_get_features(VirtIODevice *vdev, uint64_t feat= ures, + Error **errp) +{ + return features; +} + +static void virtio_pmem_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VirtIOPMEM *pmem =3D VIRTIO_PMEM(dev); + + if (!pmem->memdev) { + error_setg(errp, "virtio-pmem memdev not set"); + return; + } + + if (host_memory_backend_is_mapped(pmem->memdev)) { + char *path =3D object_get_canonical_path_component(OBJECT(pmem->me= mdev)); + error_setg(errp, "can't use already busy memdev: %s", path); + g_free(path); + return; + } + + host_memory_backend_set_mapped(pmem->memdev, true); + virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM, + sizeof(struct virtio_pmem_config)); + pmem->rq_vq =3D virtio_add_queue(vdev, 128, virtio_pmem_flush); +} + +static void virtio_pmem_unrealize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VirtIOPMEM *pmem =3D VIRTIO_PMEM(dev); + + host_memory_backend_set_mapped(pmem->memdev, false); + pmem->rq_vq =3D virtio_add_queue(vdev, 128, virtio_pmem_flush); + virtio_cleanup(vdev); +} + +static void virtio_pmem_fill_device_info(const VirtIOPMEM *pmem, + VirtioPMEMDeviceInfo *vi) +{ + vi->memaddr =3D pmem->start; + vi->size =3D pmem->memdev ? memory_region_size(&pmem->memdev->mr) : 0; + vi->memdev =3D object_get_canonical_path(OBJECT(pmem->memdev)); +} + +static MemoryRegion *virtio_pmem_get_memory_region(VirtIOPMEM *pmem, + Error **errp) +{ + if (!pmem->memdev) { + error_setg(errp, "'%s' property must be set", VIRTIO_PMEM_MEMDEV_P= ROP); + return NULL; + } + + return &pmem->memdev->mr; +} + +static Property virtio_pmem_properties[] =3D { + DEFINE_PROP_UINT64(VIRTIO_PMEM_ADDR_PROP, VirtIOPMEM, start, 0), + DEFINE_PROP_LINK(VIRTIO_PMEM_MEMDEV_PROP, VirtIOPMEM, memdev, + TYPE_MEMORY_BACKEND, HostMemoryBackend *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_pmem_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + VirtIOPMEMClass *vpc =3D VIRTIO_PMEM_CLASS(klass); + + dc->props =3D virtio_pmem_properties; + + vdc->realize =3D virtio_pmem_realize; + vdc->unrealize =3D virtio_pmem_unrealize; + vdc->get_config =3D virtio_pmem_get_config; + vdc->get_features =3D virtio_pmem_get_features; + + vpc->fill_device_info =3D virtio_pmem_fill_device_info; + vpc->get_memory_region =3D virtio_pmem_get_memory_region; +} + +static TypeInfo virtio_pmem_info =3D { + .name =3D TYPE_VIRTIO_PMEM, + .parent =3D TYPE_VIRTIO_DEVICE, + .class_size =3D sizeof(VirtIOPMEMClass), + .class_init =3D virtio_pmem_class_init, + .instance_size =3D sizeof(VirtIOPMEM), +}; + +static void virtio_register_types(void) +{ + type_register_static(&virtio_pmem_info); +} + +type_init(virtio_register_types) diff --git a/include/hw/virtio/virtio-pmem.h b/include/hw/virtio/virtio-pme= m.h new file mode 100644 index 0000000000..19b6ee6d75 --- /dev/null +++ b/include/hw/virtio/virtio-pmem.h @@ -0,0 +1,49 @@ +/* + * Virtio PMEM device + * + * Copyright (C) 2018-2019 Red Hat, Inc. + * + * Authors: + * Pankaj Gupta + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_VIRTIO_PMEM_H +#define HW_VIRTIO_PMEM_H + +#include "hw/virtio/virtio.h" +#include "sysemu/hostmem.h" + +#define TYPE_VIRTIO_PMEM "virtio-pmem" + +#define VIRTIO_PMEM(obj) \ + OBJECT_CHECK(VirtIOPMEM, (obj), TYPE_VIRTIO_PMEM) +#define VIRTIO_PMEM_CLASS(oc) \ + OBJECT_CLASS_CHECK(VirtIOPMEMClass, (oc), TYPE_VIRTIO_PMEM) +#define VIRTIO_PMEM_GET_CLASS(obj) \ + OBJECT_GET_CLASS(VirtIOPMEMClass, (obj), TYPE_VIRTIO_PMEM) + +#define VIRTIO_PMEM_ADDR_PROP "memaddr" +#define VIRTIO_PMEM_MEMDEV_PROP "memdev" + +typedef struct VirtIOPMEM { + VirtIODevice parent_obj; + + VirtQueue *rq_vq; + uint64_t start; + HostMemoryBackend *memdev; +} VirtIOPMEM; + +typedef struct VirtIOPMEMClass { + /* private */ + VirtIODevice parent; + + /* public */ + void (*fill_device_info)(const VirtIOPMEM *pmem, VirtioPMEMDeviceInfo = *vi); + MemoryRegion *(*get_memory_region)(VirtIOPMEM *pmem, Error **errp); +} VirtIOPMEMClass; + +#endif diff --git a/qapi/misc.json b/qapi/misc.json index 8b3ca4fdd3..605c347003 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2742,16 +2742,42 @@ } } =20 +## +# @VirtioPMEMDeviceInfo: +# +# VirtioPMEM state information +# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @size: size of memory that the device provides +# +# @memdev: memory backend linked with device +# +# Since: 4.0 +## +{ 'struct': 'VirtioPMEMDeviceInfo', + 'data': { '*id': 'str', + 'memaddr': 'size', + 'size': 'size', + 'memdev': 'str' + } +} + ## # @MemoryDeviceInfo: # # Union containing information about a memory device # +# nvdimm is included since 2.12. virtio-pmem is included since 4.0. +# # Since: 2.1 ## { 'union': 'MemoryDeviceInfo', 'data': { 'dimm': 'PCDIMMDeviceInfo', - 'nvdimm': 'PCDIMMDeviceInfo' + 'nvdimm': 'PCDIMMDeviceInfo', + 'virtio-pmem': 'VirtioPMEMDeviceInfo' } } =20 --=20 2.14.5 From nobody Sun Apr 28 23:05:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558608029; cv=none; d=zoho.com; s=zohoarc; b=T/UexkVIZZ1o9bJ8eJTwlr53DKVYDL68Io2z3XVy9BcZTaCPkycHX0RXh5IYEcpn0sMAoTd9Lh1ad824Uu7J8l/tGfoDj6wZMsNCh6E+iMxVQRiFvhyZ9FflJDzbx/hssq0ouZDh1uPXxi+ufl2TyEN49i/fmn14rN/CeNk/gvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558608029; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=OCzARLI2rCH3zYps46VBs4fIVgBjEJwAJKgHlE/iX2U=; b=m2a6xAqXO2TFvxsNPQdu3iO6N29/c6HBNqxFgwwfxXaQUKg3EcUqkS3Mqrp0TCSUUOFzF5oZaa4t5rnflXcJoRxOu2xb7HV29lBeHfZraOcXnwN5R4xAMZyuSHGrQPNXvLHx+INBH2rO3P4Bgnfo1Rj0Qf+SAAdITD0ofksB0VQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558608029899888.9194710596817; Thu, 23 May 2019 03:40:29 -0700 (PDT) Received: from localhost ([127.0.0.1]:33275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTl94-0000i7-Tu for importer@patchew.org; Thu, 23 May 2019 06:40:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTkvN-0005zC-SE for qemu-devel@nongnu.org; Thu, 23 May 2019 06:26:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTkvM-0001Vq-8H for qemu-devel@nongnu.org; Thu, 23 May 2019 06:26:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55444) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTkvK-0001RB-6Z for qemu-devel@nongnu.org; Thu, 23 May 2019 06:26:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07CDC308FEE2; Thu, 23 May 2019 10:26:09 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (ovpn-116-162.sin2.redhat.com [10.67.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCA956767F; Thu, 23 May 2019 10:25:48 +0000 (UTC) From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 15:54:44 +0530 Message-Id: <20190523102449.2642-3-pagupta@redhat.com> In-Reply-To: <20190523102449.2642-1-pagupta@redhat.com> References: <20190523102449.2642-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 23 May 2019 10:26:09 +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 2/7] virtio-pci: Allow to specify additional interfaces for the base type 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: kwolf@redhat.com, aarcange@redhat.com, cohuck@redhat.com, xiaoguangrong.eric@gmail.com, mst@redhat.com, pagupta@redhat.com, riel@surriel.com, david@redhat.com, armbru@redhat.com, ehabkost@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, dan.j.williams@intel.com, nilal@redhat.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's allow to specify additional interfaces for the base type (e.g. later TYPE_MEMORY_DEVICE), something that was possible before the rework of virtio PCI device instantiation. Reviewed-by: Cornelia Huck Signed-off-by: David Hildenbrand --- hw/virtio/virtio-pci.c | 1 + hw/virtio/virtio-pci.h | 1 + 2 files changed, 2 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index cb44e19b67..0ac451ed0f 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1939,6 +1939,7 @@ void virtio_pci_types_register(const VirtioPCIDeviceT= ypeInfo *t) .class_init =3D virtio_pci_base_class_init, .class_data =3D (void *)t, .abstract =3D true, + .interfaces =3D t->interfaces, }; TypeInfo generic_type_info =3D { .name =3D t->generic_name, diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 18581854ca..292275acb1 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -233,6 +233,7 @@ typedef struct VirtioPCIDeviceTypeInfo { size_t class_size; void (*instance_init)(Object *obj); void (*class_init)(ObjectClass *klass, void *data); + InterfaceInfo *interfaces; } VirtioPCIDeviceTypeInfo; =20 /* Register virtio-pci type(s). @t must be static. */ --=20 2.14.5 From nobody Sun Apr 28 23:05:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558608491; cv=none; d=zoho.com; s=zohoarc; b=eC0RDz8b2IxI2IvV93w5yCqYCPAd44SRonqxETMnQlRk6t4YPqq/bgxZKGWsTreFvI9sVl7FrUwqLKr6zBKvtMSU8lVDxrfAUtFEotrzHhTD2781NdpuJHCuQj4sUEryGprqHUCyW5nxhheJa7mlLwVkdJaq97pX1qJ8JAEf93w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558608491; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=mhf3mhhyMKiwymUHoy0aWCxiIcOmnv3z1nOQ7gghT/Y=; b=PLGzdaT8FJCpYTgNtPnq3BNNSLquImE3SlomL/YDQz8ydXPYERgWdNYbdpSo3dncqEDUMkZlWFAiWYc/PR92EUBrW8oLsLIPWKpJBGrJ66WjQZmr1MEdmSipPT6JaGid1W7YMX/hwpuCKGmgX3yE3+EgYIimyI03YUYfsSMYS48= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558608491020695.7257300041997; Thu, 23 May 2019 03:48:11 -0700 (PDT) Received: from localhost ([127.0.0.1]:33431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTlGW-0007La-4U for importer@patchew.org; Thu, 23 May 2019 06:48:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTkw0-0006V2-W2 for qemu-devel@nongnu.org; Thu, 23 May 2019 06:26:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTkw0-0002G7-0v for qemu-devel@nongnu.org; Thu, 23 May 2019 06:26:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48688) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTkvz-0002Fz-Sw for qemu-devel@nongnu.org; Thu, 23 May 2019 06:26:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1CF333087950; Thu, 23 May 2019 10:26:46 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (ovpn-116-162.sin2.redhat.com [10.67.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED83E69181; Thu, 23 May 2019 10:26:09 +0000 (UTC) From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 15:54:45 +0530 Message-Id: <20190523102449.2642-4-pagupta@redhat.com> In-Reply-To: <20190523102449.2642-1-pagupta@redhat.com> References: <20190523102449.2642-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 23 May 2019 10:26:51 +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 3/7] virtio-pmem: sync linux headers 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: kwolf@redhat.com, aarcange@redhat.com, cohuck@redhat.com, xiaoguangrong.eric@gmail.com, mst@redhat.com, pagupta@redhat.com, riel@surriel.com, david@redhat.com, armbru@redhat.com, ehabkost@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, dan.j.williams@intel.com, nilal@redhat.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Sync linux headers for virtio pmem. Signed-off-by: Pankaj Gupta --- include/standard-headers/linux/virtio_ids.h | 1 + include/standard-headers/linux/virtio_pmem.h | 35 ++++++++++++++++++++++++= ++++ 2 files changed, 36 insertions(+) create mode 100644 include/standard-headers/linux/virtio_pmem.h diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard= -headers/linux/virtio_ids.h index 6d5c3b2d4f..32b2f94d1f 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -43,5 +43,6 @@ #define VIRTIO_ID_INPUT 18 /* virtio input */ #define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */ #define VIRTIO_ID_CRYPTO 20 /* virtio crypto */ +#define VIRTIO_ID_PMEM 27 /* virtio pmem */ =20 #endif /* _LINUX_VIRTIO_IDS_H */ diff --git a/include/standard-headers/linux/virtio_pmem.h b/include/standar= d-headers/linux/virtio_pmem.h new file mode 100644 index 0000000000..7a3e2fe524 --- /dev/null +++ b/include/standard-headers/linux/virtio_pmem.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* + * Definitions for virtio-pmem devices. + * + * Copyright (C) 2019 Red Hat, Inc. + * + * Author(s): Pankaj Gupta + */ + +#ifndef _UAPI_LINUX_VIRTIO_PMEM_H +#define _UAPI_LINUX_VIRTIO_PMEM_H + +#include +#include +#include +#include + +struct virtio_pmem_config { + __le64 start; + __le64 size; +}; + +#define VIRTIO_PMEM_REQ_TYPE_FLUSH 0 + +struct virtio_pmem_resp { + /* Host return status corresponding to flush request */ + __virtio32 ret; +}; + +struct virtio_pmem_req { + /* command type */ + __virtio32 type; +}; + +#endif --=20 2.14.5 From nobody Sun Apr 28 23:05:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558608646; cv=none; d=zoho.com; s=zohoarc; b=R54prpN7bYZe0ryWqhpSRvR5KM+4/eHVFYi6jQthL3V8Iw8cE/HpHnlH+gOCpbXF3MUU8LCPr4YnTqlbodingDyYVHaQdSRs5dXBirxO+1Y4K2w+dwaEgkaiVvllGwd8xLrSATyhS1A+CbyvVWtUcLYdbS7C9d+KkIFxEoCNdyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558608646; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=t/r0EvkRyWx6Dn+uJ0CBEvhF7VL593R4jWX8dL/R1vA=; b=nB9SKVBqotEPVuCQ11JcYhgxmn6qnNpaoYGgrBAD/eqUGA161pQ+OBXfaD2HRRPw5gHRH2TBb59hfI5UsAjGjbN2NVASA1apKFMjZ3dWXqLG1spTKM6frBVFDKxy+hT6ILoEI4eDD/jAu0vAG9sKu34X4gBGIP8ZrViXKmqGccU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558608646853222.05864171765234; Thu, 23 May 2019 03:50:46 -0700 (PDT) Received: from localhost ([127.0.0.1]:33467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTlIP-0000cm-JZ for importer@patchew.org; Thu, 23 May 2019 06:50:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTkwI-0006ks-BP for qemu-devel@nongnu.org; Thu, 23 May 2019 06:27:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTkwG-0002Np-WB for qemu-devel@nongnu.org; Thu, 23 May 2019 06:27:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36350) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTkwG-0002Na-Pk for qemu-devel@nongnu.org; Thu, 23 May 2019 06:27:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0382B307D960; Thu, 23 May 2019 10:27:08 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (ovpn-116-162.sin2.redhat.com [10.67.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 241AC6606C; Thu, 23 May 2019 10:26:46 +0000 (UTC) From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 15:54:46 +0530 Message-Id: <20190523102449.2642-5-pagupta@redhat.com> In-Reply-To: <20190523102449.2642-1-pagupta@redhat.com> References: <20190523102449.2642-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 23 May 2019 10:27:08 +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 4/7] virtio-pci: Proxy for virtio-pmem 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: kwolf@redhat.com, aarcange@redhat.com, cohuck@redhat.com, xiaoguangrong.eric@gmail.com, mst@redhat.com, pagupta@redhat.com, riel@surriel.com, david@redhat.com, armbru@redhat.com, ehabkost@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, dan.j.williams@intel.com, nilal@redhat.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We need a proxy device for virtio-pmem, and this device has to be the actual memory device so we can cleanly hotplug it. Forward memory device class functions either to the actual device or use properties of the virtio-pmem device to implement these in the proxy. virtio-pmem will only be compiled for selected, supported architectures (that can deal with virtio/pci devices being memory devices). An architecture that is prepared for that can simply enable CONFIG_VIRTIO_PMEM to make it work. As not all architectures support memory devices (and CONFIG_VIRTIO_PMEM will be enabled per supported architecture), we have to move the PCI proxy to a separate file. Signed-off-by: Pankaj Gupta [ split up patches, memory-device changes, move pci proxy] Signed-off-by: David Hildenbrand --- hw/virtio/Makefile.objs | 1 + hw/virtio/virtio-pmem-pci.c | 131 ++++++++++++++++++++++++++++++++++++++++= ++++ hw/virtio/virtio-pmem-pci.h | 34 ++++++++++++ include/hw/pci/pci.h | 1 + 4 files changed, 167 insertions(+) create mode 100644 hw/virtio/virtio-pmem-pci.c create mode 100644 hw/virtio/virtio-pmem-pci.h diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 5857e3b8e1..964ce78607 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -13,6 +13,7 @@ obj-$(CONFIG_VIRTIO_BALLOON) +=3D virtio-balloon.o obj-$(CONFIG_VIRTIO_CRYPTO) +=3D virtio-crypto.o obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) +=3D virtio-= crypto-pci.o obj-$(CONFIG_VIRTIO_PMEM) +=3D virtio-pmem.o +common-obj-$(call land,$(CONFIG_VIRTIO_PMEM),$(CONFIG_VIRTIO_PCI)) +=3D vi= rtio-pmem-pci.o obj-$(CONFIG_VHOST_VSOCK) +=3D vhost-vsock.o =20 ifeq ($(CONFIG_VIRTIO_PCI),y) diff --git a/hw/virtio/virtio-pmem-pci.c b/hw/virtio/virtio-pmem-pci.c new file mode 100644 index 0000000000..8b2d0dbccc --- /dev/null +++ b/hw/virtio/virtio-pmem-pci.c @@ -0,0 +1,131 @@ +/* + * Virtio PMEM PCI device + * + * Copyright (C) 2018-2019 Red Hat, Inc. + * + * Authors: + * Pankaj Gupta + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "virtio-pmem-pci.h" +#include "hw/mem/memory-device.h" +#include "qapi/error.h" + +static void virtio_pmem_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VirtIOPMEMPCI *pmem_pci =3D VIRTIO_PMEM_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&pmem_pci->vdev); + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); +} + +static void virtio_pmem_pci_set_addr(MemoryDeviceState *md, uint64_t addr, + Error **errp) +{ + object_property_set_uint(OBJECT(md), addr, VIRTIO_PMEM_ADDR_PROP, errp= ); +} + +static uint64_t virtio_pmem_pci_get_addr(const MemoryDeviceState *md) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_PMEM_ADDR_PROP, + &error_abort); +} + +static MemoryRegion *virtio_pmem_pci_get_memory_region(MemoryDeviceState *= md, + Error **errp) +{ + VirtIOPMEMPCI *pci_pmem =3D VIRTIO_PMEM_PCI(md); + VirtIOPMEM *pmem =3D VIRTIO_PMEM(&pci_pmem->vdev); + VirtIOPMEMClass *vpc =3D VIRTIO_PMEM_GET_CLASS(pmem); + + return vpc->get_memory_region(pmem, errp); +} + +static uint64_t virtio_pmem_pci_get_plugged_size(const MemoryDeviceState *= md, + Error **errp) +{ + VirtIOPMEMPCI *pci_pmem =3D VIRTIO_PMEM_PCI(md); + VirtIOPMEM *pmem =3D VIRTIO_PMEM(&pci_pmem->vdev); + VirtIOPMEMClass *vpc =3D VIRTIO_PMEM_GET_CLASS(pmem); + MemoryRegion *mr =3D vpc->get_memory_region(pmem, errp); + + /* the plugged size corresponds to the region size */ + return mr ? 0 : memory_region_size(mr); +} + +static void virtio_pmem_pci_fill_device_info(const MemoryDeviceState *md, + MemoryDeviceInfo *info) +{ + VirtioPMEMDeviceInfo *vi =3D g_new0(VirtioPMEMDeviceInfo, 1); + VirtIOPMEMPCI *pci_pmem =3D VIRTIO_PMEM_PCI(md); + VirtIOPMEM *pmem =3D VIRTIO_PMEM(&pci_pmem->vdev); + VirtIOPMEMClass *vpc =3D VIRTIO_PMEM_GET_CLASS(pmem); + DeviceState *dev =3D DEVICE(md); + + if (dev->id) { + vi->has_id =3D true; + vi->id =3D g_strdup(dev->id); + } + + /* let the real device handle everything else */ + vpc->fill_device_info(pmem, vi); + + info->u.virtio_pmem.data =3D vi; + info->type =3D MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM; +} + +static void virtio_pmem_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(klass); + + k->realize =3D virtio_pmem_pci_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D PCI_DEVICE_ID_VIRTIO_PMEM; + pcidev_k->revision =3D VIRTIO_PCI_ABI_VERSION; + pcidev_k->class_id =3D PCI_CLASS_OTHERS; + + mdc->get_addr =3D virtio_pmem_pci_get_addr; + mdc->set_addr =3D virtio_pmem_pci_set_addr; + mdc->get_plugged_size =3D virtio_pmem_pci_get_plugged_size; + mdc->get_memory_region =3D virtio_pmem_pci_get_memory_region; + mdc->fill_device_info =3D virtio_pmem_pci_fill_device_info; +} + +static void virtio_pmem_pci_instance_init(Object *obj) +{ + VirtIOPMEMPCI *dev =3D VIRTIO_PMEM_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_PMEM); +} + +static const VirtioPCIDeviceTypeInfo virtio_pmem_pci_info =3D { + .base_name =3D TYPE_VIRTIO_PMEM_PCI, + .generic_name =3D "virtio-pmem-pci", + .transitional_name =3D "virtio-pmem-pci-transitional", + .non_transitional_name =3D "virtio-pmem-pci-non-transitional", + .instance_size =3D sizeof(VirtIOPMEMPCI), + .instance_init =3D virtio_pmem_pci_instance_init, + .class_init =3D virtio_pmem_pci_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_MEMORY_DEVICE }, + { } + }, +}; + +static void virtio_pmem_pci_register_types(void) +{ + virtio_pci_types_register(&virtio_pmem_pci_info); +} +type_init(virtio_pmem_pci_register_types) diff --git a/hw/virtio/virtio-pmem-pci.h b/hw/virtio/virtio-pmem-pci.h new file mode 100644 index 0000000000..616abef093 --- /dev/null +++ b/hw/virtio/virtio-pmem-pci.h @@ -0,0 +1,34 @@ +/* + * Virtio PMEM PCI device + * + * Copyright (C) 2018-2019 Red Hat, Inc. + * + * Authors: + * Pankaj Gupta + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_VIRTIO_PMEM_PCI_H +#define QEMU_VIRTIO_PMEM_PCI_H + +#include "hw/virtio/virtio-pci.h" +#include "hw/virtio/virtio-pmem.h" + +typedef struct VirtIOPMEMPCI VirtIOPMEMPCI; + +/* + * virtio-pmem-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VIRTIO_PMEM_PCI "virtio-pmem-pci-base" +#define VIRTIO_PMEM_PCI(obj) \ + OBJECT_CHECK(VirtIOPMEMPCI, (obj), TYPE_VIRTIO_PMEM_PCI) + +struct VirtIOPMEMPCI { + VirtIOPCIProxy parent_obj; + VirtIOPMEM vdev; +}; + +#endif /* QEMU_VIRTIO_PMEM_PCI_H */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index edf44de21d..097feb2cb7 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -85,6 +85,7 @@ extern bool pci_available; #define PCI_DEVICE_ID_VIRTIO_RNG 0x1005 #define PCI_DEVICE_ID_VIRTIO_9P 0x1009 #define PCI_DEVICE_ID_VIRTIO_VSOCK 0x1012 +#define PCI_DEVICE_ID_VIRTIO_PMEM 0x1013 =20 #define PCI_VENDOR_ID_REDHAT 0x1b36 #define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001 --=20 2.14.5 From nobody Sun Apr 28 23:05:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558608645; cv=none; d=zoho.com; s=zohoarc; b=XxWZ8AK69PCjdZepBmxl59zexWSOZRc43g7vcJL2Udl+uZACDrgRuzq9DAoEgmyjCRTFvtDkcmsI4T7Zp/Mg7ilZBQst8jihtXs9WG6KTT5/cjwHX9CHiXwzxfx8TTkvk4ap/YF9LFEv8DAg+YJ80Tj6yg4Xm7jO4YiPFk4X6r0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558608645; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=4aHDFuuOXVzqx1NqCPLmM7YdYXnok70R2e+pFoJ2XlE=; b=IjGQzLaCcyx7aRp3nMlJ/qqmgsd8vQ6PoUZVBZr2qXq/1mNafaiIlw8fvcfsae1uulpS1fU+Kh4T1NT5XR8f/DAiN1t2A7Ini1tNRIIXO3jC7YOui1rf+ufX4WAQsbfQ9V1fkdTwOU0nTHIpHL64weCuvL+JHy52xIIPAyeqFzE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558608645041660.8162077936805; Thu, 23 May 2019 03:50:45 -0700 (PDT) Received: from localhost ([127.0.0.1]:33485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTlIz-00017P-RA for importer@patchew.org; Thu, 23 May 2019 06:50:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTkwc-0006zR-Oo for qemu-devel@nongnu.org; Thu, 23 May 2019 06:27:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTkwb-0002Vv-Lt for qemu-devel@nongnu.org; Thu, 23 May 2019 06:27:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52682) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTkwb-0002Vd-HT for qemu-devel@nongnu.org; Thu, 23 May 2019 06:27:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF2D980C26; Thu, 23 May 2019 10:27:28 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (ovpn-116-162.sin2.redhat.com [10.67.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03D6269181; Thu, 23 May 2019 10:27:08 +0000 (UTC) From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 15:54:47 +0530 Message-Id: <20190523102449.2642-6-pagupta@redhat.com> In-Reply-To: <20190523102449.2642-1-pagupta@redhat.com> References: <20190523102449.2642-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 23 May 2019 10:27:28 +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 5/7] hmp: Handle virtio-pmem when printing memory device infos 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: kwolf@redhat.com, aarcange@redhat.com, cohuck@redhat.com, xiaoguangrong.eric@gmail.com, mst@redhat.com, pagupta@redhat.com, riel@surriel.com, david@redhat.com, armbru@redhat.com, ehabkost@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, dan.j.williams@intel.com, nilal@redhat.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Print the memory device info just like for PCDIMM/NVDIMM. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: David Hildenbrand --- hmp.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/hmp.c b/hmp.c index 92941142af..e1866bc7f1 100644 --- a/hmp.c +++ b/hmp.c @@ -2650,6 +2650,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDic= t *qdict) Error *err =3D NULL; MemoryDeviceInfoList *info_list =3D qmp_query_memory_devices(&err); MemoryDeviceInfoList *info; + VirtioPMEMDeviceInfo *vpi; MemoryDeviceInfo *value; PCDIMMDeviceInfo *di; =20 @@ -2659,19 +2660,9 @@ void hmp_info_memory_devices(Monitor *mon, const QDi= ct *qdict) if (value) { switch (value->type) { case MEMORY_DEVICE_INFO_KIND_DIMM: - di =3D value->u.dimm.data; - break; - case MEMORY_DEVICE_INFO_KIND_NVDIMM: - di =3D value->u.nvdimm.data; - break; - - default: - di =3D NULL; - break; - } - - if (di) { + di =3D value->type =3D=3D MEMORY_DEVICE_INFO_KIND_DIMM ? + value->u.dimm.data : value->u.nvdimm.data; monitor_printf(mon, "Memory device [%s]: \"%s\"\n", MemoryDeviceInfoKind_str(value->type), di->id ? di->id : ""); @@ -2684,6 +2675,18 @@ void hmp_info_memory_devices(Monitor *mon, const QDi= ct *qdict) di->hotplugged ? "true" : "false"); monitor_printf(mon, " hotpluggable: %s\n", di->hotpluggable ? "true" : "false"); + break; + case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: + vpi =3D value->u.virtio_pmem.data; + monitor_printf(mon, "Memory device [%s]: \"%s\"\n", + MemoryDeviceInfoKind_str(value->type), + vpi->id ? vpi->id : ""); + monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->mem= addr); + monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); + monitor_printf(mon, " memdev: %s\n", vpi->memdev); + break; + default: + g_assert_not_reached(); } } } --=20 2.14.5 From nobody Sun Apr 28 23:05:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558608294; cv=none; d=zoho.com; s=zohoarc; b=YFBCcId1yUseeECfAYTc9OfTPOOm/qTBLcIpBTXVsfdNzm8vpJ+WQQPVPfVA8EEfRN6q27Dbpcy7l0WfVPBxmtQSBNxgEmyrme5YxWXWILJiU4D6JfSuah2jXZf8T7mf4w0KRm9ZHitZ1enGW9k3AC5KtWCbKQcNK6iL92Ltteg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558608294; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=hH2eLz86P5RTdatRYT9b4SIdWhFWEAXI/NeKC6e03zY=; b=KML81aiac7cYvcjaGAE0eI9L/Igxw7g82QlDZefIEOgpNhk8Po4Vm4qMXi/BeccKnJLQKlq+xL3ldumH30yGgRmIgB3hd+RfVlmBIzp4jjwGEoCHScl8QopgGs7FUU5xMms806xlXGUjI3nZx66mjOT9C5C3XynDBEkLXa1NtD4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558608294224698.6615530634733; Thu, 23 May 2019 03:44:54 -0700 (PDT) Received: from localhost ([127.0.0.1]:33343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTlDJ-0004qS-7i for importer@patchew.org; Thu, 23 May 2019 06:44:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTkx0-0007IO-Rx for qemu-devel@nongnu.org; Thu, 23 May 2019 06:27:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTkwz-0002hJ-Vs for qemu-devel@nongnu.org; Thu, 23 May 2019 06:27:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTkwz-0002gl-RO for qemu-devel@nongnu.org; Thu, 23 May 2019 06:27:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 189133060485; Thu, 23 May 2019 10:27:51 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (ovpn-116-162.sin2.redhat.com [10.67.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2F4969181; Thu, 23 May 2019 10:27:29 +0000 (UTC) From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 15:54:48 +0530 Message-Id: <20190523102449.2642-7-pagupta@redhat.com> In-Reply-To: <20190523102449.2642-1-pagupta@redhat.com> References: <20190523102449.2642-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 23 May 2019 10:27:53 +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 6/7] numa: Handle virtio-pmem in NUMA stats 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: kwolf@redhat.com, aarcange@redhat.com, cohuck@redhat.com, xiaoguangrong.eric@gmail.com, mst@redhat.com, pagupta@redhat.com, riel@surriel.com, david@redhat.com, armbru@redhat.com, ehabkost@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, dan.j.williams@intel.com, nilal@redhat.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Account the memory to node 0 for now. Once (if ever) virtio-pmem supports NUMA, we can account it to the right node. Signed-off-by: David Hildenbrand --- numa.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/numa.c b/numa.c index 3875e1efda..42cca616e7 100644 --- a/numa.c +++ b/numa.c @@ -549,6 +549,7 @@ static void numa_stat_memory_devices(NumaNodeMem node_m= em[]) MemoryDeviceInfoList *info_list =3D qmp_memory_device_list(); MemoryDeviceInfoList *info; PCDIMMDeviceInfo *pcdimm_info; + VirtioPMEMDeviceInfo *vpi; =20 for (info =3D info_list; info; info =3D info->next) { MemoryDeviceInfo *value =3D info->value; @@ -556,22 +557,21 @@ static void numa_stat_memory_devices(NumaNodeMem node= _mem[]) if (value) { switch (value->type) { case MEMORY_DEVICE_INFO_KIND_DIMM: - pcdimm_info =3D value->u.dimm.data; - break; - case MEMORY_DEVICE_INFO_KIND_NVDIMM: - pcdimm_info =3D value->u.nvdimm.data; - break; - - default: - pcdimm_info =3D NULL; - break; - } - - if (pcdimm_info) { + pcdimm_info =3D value->type =3D=3D MEMORY_DEVICE_INFO_KIND= _DIMM ? + value->u.dimm.data : value->u.nvdimm.data; node_mem[pcdimm_info->node].node_mem +=3D pcdimm_info->siz= e; node_mem[pcdimm_info->node].node_plugged_mem +=3D pcdimm_info->size; + break; + case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: + vpi =3D value->u.virtio_pmem.data; + /* TODO: once we support numa, assign to right node */ + node_mem[0].node_mem +=3D vpi->size; + node_mem[0].node_plugged_mem +=3D vpi->size; + break; + default: + g_assert_not_reached(); } } } --=20 2.14.5 From nobody Sun Apr 28 23:05:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558608103; cv=none; d=zoho.com; s=zohoarc; b=VYTwmdh1wUk/gZzT3JYvDZ1vDJ32Oo+TKFCzVblv/5kBG4o0pAS2q4k4zkqKOWUh4EDWmZk+KmUcspDpX71iT/y2ZhAptOLdcDF/qvFARZPCnbETsNDtccSWZebAPFhc5GxQa6sJrG5M2T25RpmBjTH+FctsJl06nvIMyeNsfwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558608103; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Fd+Jkx5VKht0+P8sgxaxLhVdH248iiPjQDD6f8VwdlY=; b=MGaPSw0ebfSLn1cGbFc3WGLfWtbeGQ2twrTeI4Eo6C481N1h2VlkiZcKU1I2KZLIRBKdsPgGSJa2fa3SZ7aR1AJqL3KAFY+A1TCoA4RgYt0Pf64xrpNTtKwpQ+R0jx1RehaK4NXIYY/lPB6AKCpOSI4ioRoeJQlIkNV707gnjro= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558608103508889.3707460153156; Thu, 23 May 2019 03:41:43 -0700 (PDT) Received: from localhost ([127.0.0.1]:33311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTlAG-0002Bz-G6 for importer@patchew.org; Thu, 23 May 2019 06:41:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTkxP-0007eC-NG for qemu-devel@nongnu.org; Thu, 23 May 2019 06:28:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTkxO-0002rA-Ed for qemu-devel@nongnu.org; Thu, 23 May 2019 06:28:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60546) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTkxO-0002qm-6K for qemu-devel@nongnu.org; Thu, 23 May 2019 06:28:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C25FC05E76E; Thu, 23 May 2019 10:28:12 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (ovpn-116-162.sin2.redhat.com [10.67.116.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BD0469182; Thu, 23 May 2019 10:27:51 +0000 (UTC) From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 15:54:49 +0530 Message-Id: <20190523102449.2642-8-pagupta@redhat.com> In-Reply-To: <20190523102449.2642-1-pagupta@redhat.com> References: <20190523102449.2642-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 23 May 2019 10:28:12 +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 7/7] pc: Support for virtio-pmem-pci 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: kwolf@redhat.com, aarcange@redhat.com, cohuck@redhat.com, xiaoguangrong.eric@gmail.com, mst@redhat.com, pagupta@redhat.com, riel@surriel.com, david@redhat.com, armbru@redhat.com, ehabkost@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, dan.j.williams@intel.com, nilal@redhat.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Override the device hotplug handler to properly handle the memory device part via virtio-pmem-pci callbacks from the machine hotplug handler and forward to the actual PCI bus hotplug handler. As PCI hotplug has not been properly factored out into hotplug handlers, most magic is performed in the (un)realize functions. Also some PCI host buses don't have a PCI hotplug handler at all yet, just to be sure that we alway have a hotplug handler on x86, add a simple error check. Unlocking virtio-pmem will unlock virtio-pmem-pci. Signed-off-by: David Hildenbrand [ Disable virtio-pmem hotunplug ] Signed-off-by: Pankaj Gupta --- hw/i386/Kconfig | 1 + hw/i386/pc.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index 9817888216..4ddf2a9c55 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -30,6 +30,7 @@ config PC # For ACPI builder: select SERIAL_ISA select ACPI_VMGENID + select VIRTIO_PMEM_SUPPORTED =20 config PC_PCI bool diff --git a/hw/i386/pc.c b/hw/i386/pc.c index d98b737b8f..3b2ad42699 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -77,6 +77,8 @@ #include "hw/i386/intel_iommu.h" #include "hw/net/ne2000-isa.h" #include "standard-headers/asm-x86/bootparam.h" +#include "hw/virtio/virtio-pmem-pci.h" +#include "hw/mem/memory-device.h" =20 /* debug PC/ISA interrupts */ //#define DEBUG_IRQ @@ -2398,6 +2400,65 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_= dev, numa_cpu_pre_plug(cpu_slot, dev, errp); } =20 +static void pc_virtio_pmem_pci_pre_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + HotplugHandler *hotplug_dev2 =3D qdev_get_bus_hotplug_handler(dev); + Error *local_err =3D NULL; + + if (!hotplug_dev2) { + /* + * Without a bus hotplug handler, we cannot control the plug/unplug + * order. This should never be the case on x86, however better add + * a safety net. + */ + error_setg(errp, "virtio-pmem-pci not supported on this bus."); + return; + } + /* + * First, see if we can plug this memory device at all. If that + * succeeds, branch of to the actual hotplug handler. + */ + memory_device_pre_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev), NULL, + &local_err); + if (!local_err) { + hotplug_handler_pre_plug(hotplug_dev2, dev, &local_err); + } + error_propagate(errp, local_err); +} + +static void pc_virtio_pmem_pci_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + HotplugHandler *hotplug_dev2 =3D qdev_get_bus_hotplug_handler(dev); + Error *local_err =3D NULL; + + /* + * Plug the memory device first and then branch off to the actual + * hotplug handler. If that one fails, we can easily undo the memory + * device bits. + */ + memory_device_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev)); + hotplug_handler_plug(hotplug_dev2, dev, &local_err); + if (local_err) { + memory_device_unplug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev)); + } + error_propagate(errp, local_err); +} + +static void pc_virtio_pmem_pci_unplug_request(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **er= rp) +{ + /* We don't support virtio pmem hot unplug */ + error_setg(errp, "virtio pmem device unplug not supported."); +} + +static void pc_virtio_pmem_pci_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + /* We don't support virtio pmem hot unplug */ +} + static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -2405,6 +2466,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHand= ler *hotplug_dev, pc_memory_pre_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_pre_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { + pc_virtio_pmem_pci_pre_plug(hotplug_dev, dev, errp); } } =20 @@ -2415,6 +2478,8 @@ static void pc_machine_device_plug_cb(HotplugHandler = *hotplug_dev, pc_memory_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { + pc_virtio_pmem_pci_plug(hotplug_dev, dev, errp); } } =20 @@ -2425,6 +2490,8 @@ static void pc_machine_device_unplug_request_cb(Hotpl= ugHandler *hotplug_dev, pc_memory_unplug_request(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_unplug_request_cb(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { + pc_virtio_pmem_pci_unplug_request(hotplug_dev, dev, errp); } else { error_setg(errp, "acpi: device unplug request for not supported de= vice" " type: %s", object_get_typename(OBJECT(dev))); @@ -2438,6 +2505,8 @@ static void pc_machine_device_unplug_cb(HotplugHandle= r *hotplug_dev, pc_memory_unplug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_unplug_cb(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { + pc_virtio_pmem_pci_unplug(hotplug_dev, dev, errp); } else { error_setg(errp, "acpi: device unplug for not supported device" " type: %s", object_get_typename(OBJECT(dev))); @@ -2448,7 +2517,8 @@ static HotplugHandler *pc_get_hotplug_handler(Machine= State *machine, DeviceState *dev) { if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) || - object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + object_dynamic_cast(OBJECT(dev), TYPE_CPU) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) { return HOTPLUG_HANDLER(machine); } =20 --=20 2.14.5