From nobody Tue Feb 10 00:22:11 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512445913188777.0809205109406; Mon, 4 Dec 2017 19:51:53 -0800 (PST) Received: from localhost ([::1]:46253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Gk-0002ad-Rd for importer@patchew.org; Mon, 04 Dec 2017 22:51:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Er-0001Np-Ot for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM4Eq-0007Mk-KP for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:45 -0500 Received: from mga01.intel.com ([192.55.52.88]:32277) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eM4Eq-0007JF-Al for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:44 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2017 19:49:43 -0800 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga003.jf.intel.com with ESMTP; 04 Dec 2017 19:49:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,362,1508828400"; d="scan'208";a="9615355" From: Wei Wang To: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org, mst@redhat.com, marcandre.lureau@redhat.com, jasowang@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Date: Tue, 5 Dec 2017 11:33:12 +0800 Message-Id: <1512444796-30615-4-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512444796-30615-1-git-send-email-wei.w.wang@intel.com> References: <1512444796-30615-1-git-send-email-wei.w.wang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Subject: [Qemu-devel] [PATCH v3 3/7] virtio/virtio-pci.c: add vhost-pci-net-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: zhiyong.yang@intel.com, jan.kiszka@siemens.com, Wei Wang , avi.cohen@huawei.com 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" Add the virtio-pci emulation part of the vhost-pci device. BAR2 is used to expose the remote VM's memory to the guest, and its default size is set to 64GB. Signed-off-by: Wei Wang --- hw/virtio/virtio-pci.c | 55 ++++++++++++++++++++++= ++++ hw/virtio/virtio-pci.h | 14 +++++++ include/hw/pci/pci.h | 1 + include/standard-headers/linux/vhost_pci_net.h | 3 ++ 4 files changed, 73 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index e92837c..2a614b8 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2386,6 +2386,60 @@ static const TypeInfo virtio_net_pci_info =3D { .class_init =3D virtio_net_pci_class_init, }; =20 +/* vhost-pci-net */ + +static Property vpnet_pci_properties[] =3D { + DEFINE_PROP_END_OF_LIST(), +}; + +static void vpnet_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VhostPCINetPCI *dev =3D VHOST_PCI_NET_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + memory_region_init(&dev->vdev.bar_region, NULL, "RemoteMemory", + REMOTE_MEM_BAR_SIZE); + pci_register_bar(&vpci_dev->pci_dev, REMOTE_MEM_BAR_ID, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &dev->vdev.bar_region); + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + virtio_pci_force_virtio_1(vpci_dev); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); +} + +static void vpnet_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + VirtioPCIClass *vpciklass =3D VIRTIO_PCI_CLASS(klass); + + k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + k->device_id =3D PCI_DEVICE_ID_VHOST_PCI_NET; + k->class_id =3D PCI_CLASS_NETWORK_ETHERNET; + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); + dc->props =3D vpnet_pci_properties; + vpciklass->realize =3D vpnet_pci_realize; +} + +static void vpnet_pci_instance_init(Object *obj) +{ + VhostPCINetPCI *dev =3D VHOST_PCI_NET_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_PCI_NET); +} + +static const TypeInfo vpnet_pci_info =3D { + .name =3D TYPE_VHOST_PCI_NET_PCI, + .parent =3D TYPE_VIRTIO_PCI, + .instance_size =3D sizeof(VhostPCINetPCI), + .instance_init =3D vpnet_pci_instance_init, + .class_init =3D vpnet_pci_class_init, +}; + /* virtio-rng-pci */ =20 static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) @@ -2626,6 +2680,7 @@ static void virtio_pci_register_types(void) type_register_static(&virtio_balloon_pci_info); type_register_static(&virtio_serial_pci_info); type_register_static(&virtio_net_pci_info); + type_register_static(&vpnet_pci_info); #ifdef CONFIG_VHOST_SCSI type_register_static(&vhost_scsi_pci_info); #endif diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 12d3a90..cc58c17 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -18,6 +18,7 @@ #include "hw/pci/msi.h" #include "hw/virtio/virtio-blk.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/vhost-pci-net.h" #include "hw/virtio/virtio-rng.h" #include "hw/virtio/virtio-serial.h" #include "hw/virtio/virtio-scsi.h" @@ -44,6 +45,7 @@ typedef struct VirtIOSCSIPCI VirtIOSCSIPCI; typedef struct VirtIOBalloonPCI VirtIOBalloonPCI; typedef struct VirtIOSerialPCI VirtIOSerialPCI; typedef struct VirtIONetPCI VirtIONetPCI; +typedef struct VhostPCINetPCI VhostPCINetPCI; typedef struct VHostSCSIPCI VHostSCSIPCI; typedef struct VHostUserSCSIPCI VHostUserSCSIPCI; typedef struct VirtIORngPCI VirtIORngPCI; @@ -293,6 +295,18 @@ struct VirtIONetPCI { }; =20 /* + * vhost-pci-net-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VHOST_PCI_NET_PCI "vhost-pci-net-pci" +#define VHOST_PCI_NET_PCI(obj) \ + OBJECT_CHECK(VhostPCINetPCI, (obj), TYPE_VHOST_PCI_NET_PCI) + +struct VhostPCINetPCI { + VirtIOPCIProxy parent_obj; + VhostPCINet vdev; +}; + +/* * virtio-9p-pci: This extends VirtioPCIProxy. */ =20 diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 8d02a0a..7911fa8 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_VHOST_PCI_NET 0x1014 =20 #define PCI_VENDOR_ID_REDHAT 0x1b36 #define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001 diff --git a/include/standard-headers/linux/vhost_pci_net.h b/include/stand= ard-headers/linux/vhost_pci_net.h index cfb2413..792261e 100644 --- a/include/standard-headers/linux/vhost_pci_net.h +++ b/include/standard-headers/linux/vhost_pci_net.h @@ -29,7 +29,10 @@ =20 #include "standard-headers/linux/virtio_ids.h" =20 +#define REMOTE_MEM_BAR_ID 2 +#define REMOTE_MEM_BAR_SIZE 0x1000000000 #define METADATA_SIZE 4096 + #define MAX_REMOTE_REGION 8 =20 struct vpnet_config { --=20 2.7.4