From nobody Sun May 5 10:51:37 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.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512445912160858.3185487170439; Mon, 4 Dec 2017 19:51:52 -0800 (PST) Received: from localhost ([::1]:46252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Gj-0002ZX-Ic for importer@patchew.org; Mon, 04 Dec 2017 22:51:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Ep-0001NZ-Qf for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM4Em-0007KJ-8c for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:43 -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 1eM4El-0007JF-Vu for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:40 -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:39 -0800 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga003.jf.intel.com with ESMTP; 04 Dec 2017 19:49:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,362,1508828400"; d="scan'208";a="9615335" 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:10 +0800 Message-Id: <1512444796-30615-2-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 1/7] vhost-user: share the vhost-user protocol related structures 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" Put the vhost-user protocol related data structures to vhost-user.h, so that they can be used in other implementations (e.g. a slave implementation). Signed-off-by: Wei Wang --- hw/virtio/vhost-user.c | 100 +------------------------------------- include/hw/virtio/vhost-user.h | 106 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 107 insertions(+), 99 deletions(-) create mode 100644 include/hw/virtio/vhost-user.h diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 093675e..e512f5a 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -12,6 +12,7 @@ #include "qapi/error.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-backend.h" +#include "hw/virtio/vhost-user.h" #include "hw/virtio/virtio-net.h" #include "chardev/char-fe.h" #include "sysemu/kvm.h" @@ -23,105 +24,6 @@ #include #include =20 -#define VHOST_MEMORY_MAX_NREGIONS 8 -#define VHOST_USER_F_PROTOCOL_FEATURES 30 - -enum VhostUserProtocolFeature { - VHOST_USER_PROTOCOL_F_MQ =3D 0, - VHOST_USER_PROTOCOL_F_LOG_SHMFD =3D 1, - VHOST_USER_PROTOCOL_F_RARP =3D 2, - VHOST_USER_PROTOCOL_F_REPLY_ACK =3D 3, - VHOST_USER_PROTOCOL_F_NET_MTU =3D 4, - VHOST_USER_PROTOCOL_F_SLAVE_REQ =3D 5, - VHOST_USER_PROTOCOL_F_CROSS_ENDIAN =3D 6, - - VHOST_USER_PROTOCOL_F_MAX -}; - -#define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX)= - 1) - -typedef enum VhostUserRequest { - VHOST_USER_NONE =3D 0, - VHOST_USER_GET_FEATURES =3D 1, - VHOST_USER_SET_FEATURES =3D 2, - VHOST_USER_SET_OWNER =3D 3, - VHOST_USER_RESET_OWNER =3D 4, - VHOST_USER_SET_MEM_TABLE =3D 5, - VHOST_USER_SET_LOG_BASE =3D 6, - VHOST_USER_SET_LOG_FD =3D 7, - VHOST_USER_SET_VRING_NUM =3D 8, - VHOST_USER_SET_VRING_ADDR =3D 9, - VHOST_USER_SET_VRING_BASE =3D 10, - VHOST_USER_GET_VRING_BASE =3D 11, - VHOST_USER_SET_VRING_KICK =3D 12, - VHOST_USER_SET_VRING_CALL =3D 13, - VHOST_USER_SET_VRING_ERR =3D 14, - VHOST_USER_GET_PROTOCOL_FEATURES =3D 15, - VHOST_USER_SET_PROTOCOL_FEATURES =3D 16, - VHOST_USER_GET_QUEUE_NUM =3D 17, - VHOST_USER_SET_VRING_ENABLE =3D 18, - VHOST_USER_SEND_RARP =3D 19, - VHOST_USER_NET_SET_MTU =3D 20, - VHOST_USER_SET_SLAVE_REQ_FD =3D 21, - VHOST_USER_IOTLB_MSG =3D 22, - VHOST_USER_SET_VRING_ENDIAN =3D 23, - VHOST_USER_MAX -} VhostUserRequest; - -typedef enum VhostUserSlaveRequest { - VHOST_USER_SLAVE_NONE =3D 0, - VHOST_USER_SLAVE_IOTLB_MSG =3D 1, - VHOST_USER_SLAVE_MAX -} VhostUserSlaveRequest; - -typedef struct VhostUserMemoryRegion { - uint64_t guest_phys_addr; - uint64_t memory_size; - uint64_t userspace_addr; - uint64_t mmap_offset; -} VhostUserMemoryRegion; - -typedef struct VhostUserMemory { - uint32_t nregions; - uint32_t padding; - VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS]; -} VhostUserMemory; - -typedef struct VhostUserLog { - uint64_t mmap_size; - uint64_t mmap_offset; -} VhostUserLog; - -typedef struct VhostUserMsg { - VhostUserRequest request; - -#define VHOST_USER_VERSION_MASK (0x3) -#define VHOST_USER_REPLY_MASK (0x1<<2) -#define VHOST_USER_NEED_REPLY_MASK (0x1 << 3) - uint32_t flags; - uint32_t size; /* the following payload size */ - union { -#define VHOST_USER_VRING_IDX_MASK (0xff) -#define VHOST_USER_VRING_NOFD_MASK (0x1<<8) - uint64_t u64; - struct vhost_vring_state state; - struct vhost_vring_addr addr; - VhostUserMemory memory; - VhostUserLog log; - struct vhost_iotlb_msg iotlb; - } payload; -} QEMU_PACKED VhostUserMsg; - -static VhostUserMsg m __attribute__ ((unused)); -#define VHOST_USER_HDR_SIZE (sizeof(m.request) \ - + sizeof(m.flags) \ - + sizeof(m.size)) - -#define VHOST_USER_PAYLOAD_SIZE (sizeof(m) - VHOST_USER_HDR_SIZE) - -/* The version of the protocol we support */ -#define VHOST_USER_VERSION (0x1) - struct vhost_user { CharBackend *chr; int slave_fd; diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h new file mode 100644 index 0000000..d76e9ad --- /dev/null +++ b/include/hw/virtio/vhost-user.h @@ -0,0 +1,106 @@ +#ifndef VHOST_USER_H +#define VHOST_USER_H + +#include + +#define VHOST_MEMORY_MAX_NREGIONS 8 +#define VHOST_USER_F_PROTOCOL_FEATURES 30 + +enum VhostUserProtocolFeature { + VHOST_USER_PROTOCOL_F_MQ =3D 0, + VHOST_USER_PROTOCOL_F_LOG_SHMFD =3D 1, + VHOST_USER_PROTOCOL_F_RARP =3D 2, + VHOST_USER_PROTOCOL_F_REPLY_ACK =3D 3, + VHOST_USER_PROTOCOL_F_NET_MTU =3D 4, + VHOST_USER_PROTOCOL_F_SLAVE_REQ =3D 5, + VHOST_USER_PROTOCOL_F_CROSS_ENDIAN =3D 6, + + VHOST_USER_PROTOCOL_F_MAX +}; + +#define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX)= - 1) + +typedef enum VhostUserRequest { + VHOST_USER_NONE =3D 0, + VHOST_USER_GET_FEATURES =3D 1, + VHOST_USER_SET_FEATURES =3D 2, + VHOST_USER_SET_OWNER =3D 3, + VHOST_USER_RESET_OWNER =3D 4, + VHOST_USER_SET_MEM_TABLE =3D 5, + VHOST_USER_SET_LOG_BASE =3D 6, + VHOST_USER_SET_LOG_FD =3D 7, + VHOST_USER_SET_VRING_NUM =3D 8, + VHOST_USER_SET_VRING_ADDR =3D 9, + VHOST_USER_SET_VRING_BASE =3D 10, + VHOST_USER_GET_VRING_BASE =3D 11, + VHOST_USER_SET_VRING_KICK =3D 12, + VHOST_USER_SET_VRING_CALL =3D 13, + VHOST_USER_SET_VRING_ERR =3D 14, + VHOST_USER_GET_PROTOCOL_FEATURES =3D 15, + VHOST_USER_SET_PROTOCOL_FEATURES =3D 16, + VHOST_USER_GET_QUEUE_NUM =3D 17, + VHOST_USER_SET_VRING_ENABLE =3D 18, + VHOST_USER_SEND_RARP =3D 19, + VHOST_USER_NET_SET_MTU =3D 20, + VHOST_USER_SET_SLAVE_REQ_FD =3D 21, + VHOST_USER_IOTLB_MSG =3D 22, + VHOST_USER_SET_VRING_ENDIAN =3D 23, + VHOST_USER_MAX +} VhostUserRequest; + +typedef enum VhostUserSlaveRequest { + VHOST_USER_SLAVE_NONE =3D 0, + VHOST_USER_SLAVE_IOTLB_MSG =3D 1, + VHOST_USER_SLAVE_MAX +} VhostUserSlaveRequest; + +typedef struct VhostUserMemoryRegion { + uint64_t guest_phys_addr; + uint64_t memory_size; + uint64_t userspace_addr; + uint64_t mmap_offset; +} VhostUserMemoryRegion; + +typedef struct VhostUserMemory { + uint32_t nregions; + uint32_t padding; + VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS]; +} VhostUserMemory; + +typedef struct VhostUserLog { + uint64_t mmap_size; + uint64_t mmap_offset; +} VhostUserLog; + +typedef struct VhostUserMsg { + VhostUserRequest request; + +#define VHOST_USER_VERSION_MASK (0x3) +#define VHOST_USER_REPLY_MASK (0x1 << 2) +#define VHOST_USER_NEED_REPLY_MASK (0x1 << 3) + uint32_t flags; + /* The following payload size */ + uint32_t size; + union { +#define VHOST_USER_VRING_IDX_MASK (0xff) +#define VHOST_USER_VRING_NOFD_MASK (0x1 << 8) + uint64_t u64; + struct vhost_vring_state state; + struct vhost_vring_addr addr; + VhostUserMemory memory; + VhostUserLog log; + struct vhost_iotlb_msg iotlb; + } payload; +} QEMU_PACKED VhostUserMsg; + +static VhostUserMsg m __attribute__ ((unused)); +#define VHOST_USER_HDR_SIZE (sizeof(m.request) \ + + sizeof(m.flags) \ + + sizeof(m.size)) + +#define VHOST_USER_PAYLOAD_SIZE (sizeof(m) - VHOST_USER_HDR_SIZE) + +/* The version of the protocol we support */ +#define VHOST_USER_VERSION (0x1) + +#endif --=20 2.7.4 From nobody Sun May 5 10:51:37 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.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151244605196519.0511345137038; Mon, 4 Dec 2017 19:54:11 -0800 (PST) Received: from localhost ([::1]:46266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4J4-0005oy-4v for importer@patchew.org; Mon, 04 Dec 2017 22:54:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Ep-0001NY-QR for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM4Eo-0007LT-HS for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:43 -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 1eM4Eo-0007JF-4v for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:42 -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:41 -0800 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga003.jf.intel.com with ESMTP; 04 Dec 2017 19:49:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,362,1508828400"; d="scan'208";a="9615345" 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:11 +0800 Message-Id: <1512444796-30615-3-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 2/7] vhost-pci-net: add vhost-pci-net 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 vhost-pci-net device emulation. The device uses bar 2 to expose the remote VM's memory to the guest. The first 4KB of the the bar area stores the metadata which describes the remote memory and vring info. Signed-off-by: Wei Wang --- hw/net/Makefile.objs | 2 +- hw/net/vhost_pci_net.c | 106 +++++++++++++++++++++= ++++ include/hw/virtio/vhost-pci-net.h | 37 +++++++++ include/standard-headers/linux/vhost_pci_net.h | 60 ++++++++++++++ include/standard-headers/linux/virtio_ids.h | 1 + 5 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 hw/net/vhost_pci_net.c create mode 100644 include/hw/virtio/vhost-pci-net.h create mode 100644 include/standard-headers/linux/vhost_pci_net.h diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs index 4171af0..8b392fb 100644 --- a/hw/net/Makefile.objs +++ b/hw/net/Makefile.objs @@ -36,7 +36,7 @@ obj-$(CONFIG_MILKYMIST) +=3D milkymist-minimac2.o obj-$(CONFIG_PSERIES) +=3D spapr_llan.o obj-$(CONFIG_XILINX_ETHLITE) +=3D xilinx_ethlite.o =20 -obj-$(CONFIG_VIRTIO) +=3D virtio-net.o +obj-$(CONFIG_VIRTIO) +=3D virtio-net.o vhost_pci_net.o obj-y +=3D vhost_net.o =20 obj-$(CONFIG_ETSEC) +=3D fsl_etsec/etsec.o fsl_etsec/registers.o \ diff --git a/hw/net/vhost_pci_net.c b/hw/net/vhost_pci_net.c new file mode 100644 index 0000000..db8f954 --- /dev/null +++ b/hw/net/vhost_pci_net.c @@ -0,0 +1,106 @@ +/* + * vhost-pci-net support + * + * Copyright Intel, Inc. 2017 + * + * Authors: + * Wei Wang + * Zhiyong Yang + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#include "qemu/osdep.h" +#include "qemu/iov.h" +#include "qemu/error-report.h" +#include "hw/pci/pci.h" +#include "hw/virtio/virtio-access.h" +#include "hw/virtio/vhost-pci-net.h" +#include "hw/virtio/virtio-net.h" + +static uint64_t vpnet_get_features(VirtIODevice *vdev, uint64_t features, + Error **errp) +{ + VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + features |=3D vpnet->host_features; + + return features; +} + +static void vpnet_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + struct vpnet_config netcfg; + + virtio_stw_p(vdev, &netcfg.status, vpnet->status); + memcpy(config, &netcfg, vpnet->config_size); +} + +static void vpnet_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + + virtio_init(vdev, "vhost-pci-net", VIRTIO_ID_VHOST_PCI_NET, + vpnet->config_size); + + memory_region_init_ram(&vpnet->metadata_region, NULL, + "Metadata", METADATA_SIZE, NULL); + memory_region_add_subregion(&vpnet->bar_region, 0, + &vpnet->metadata_region); + vpnet->metadata =3D memory_region_get_ram_ptr(&vpnet->metadata_region); + memset(vpnet->metadata, 0, METADATA_SIZE); +} + +static void vpnet_device_unrealize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + + virtio_cleanup(vdev); +} + +static Property vpnet_properties[] =3D { + DEFINE_PROP_BIT("mrg_rxbuf", VhostPCINet, host_features, + VIRTIO_NET_F_MRG_RXBUF, true), + DEFINE_PROP_CHR("chardev", VhostPCINet, chr_be), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vpnet_instance_init(Object *obj) +{ + VhostPCINet *vpnet =3D VHOST_PCI_NET(obj); + + vpnet->config_size =3D sizeof(struct vpnet_config); +} + +static void vpnet_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + dc->props =3D vpnet_properties; + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); + vdc->realize =3D vpnet_device_realize; + vdc->unrealize =3D vpnet_device_unrealize; + vdc->get_config =3D vpnet_get_config; + vdc->get_features =3D vpnet_get_features; +} + +static const TypeInfo vpnet_info =3D { + .name =3D TYPE_VHOST_PCI_NET, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VhostPCINet), + .instance_init =3D vpnet_instance_init, + .class_init =3D vpnet_class_init, +}; + +static void virtio_register_types(void) +{ + type_register_static(&vpnet_info); +} + +type_init(virtio_register_types) diff --git a/include/hw/virtio/vhost-pci-net.h b/include/hw/virtio/vhost-pc= i-net.h new file mode 100644 index 0000000..0c6886d --- /dev/null +++ b/include/hw/virtio/vhost-pci-net.h @@ -0,0 +1,37 @@ +/* + * Virtio Network Device + * + * Copyright Intel, Corp. 2017 + * + * Authors: + * Wei Wang + * Zhiyong Yang + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#ifndef _QEMU_VHOST_PCI_NET_H +#define _QEMU_VHOST_PCI_NET_H + +#include "standard-headers/linux/vhost_pci_net.h" +#include "hw/virtio/virtio.h" +#include "chardev/char-fe.h" + +#define TYPE_VHOST_PCI_NET "vhost-pci-net-device" +#define VHOST_PCI_NET(obj) \ + OBJECT_CHECK(VhostPCINet, (obj), TYPE_VHOST_PCI_NET) + +typedef struct VhostPCINet { + VirtIODevice parent_obj; + MemoryRegion bar_region; + MemoryRegion metadata_region; + struct vpnet_metadata *metadata; + uint32_t host_features; + size_t config_size; + uint16_t status; + CharBackend chr_be; +} VhostPCINet; + +#endif diff --git a/include/standard-headers/linux/vhost_pci_net.h b/include/stand= ard-headers/linux/vhost_pci_net.h new file mode 100644 index 0000000..cfb2413 --- /dev/null +++ b/include/standard-headers/linux/vhost_pci_net.h @@ -0,0 +1,60 @@ +#ifndef _LINUX_VHOST_PCI_NET_H +#define _LINUX_VHOST_PCI_NET_H + +/* This header is BSD licensed so anyone can use the definitions to implem= ent + * compatible drivers/servers. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Intel nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``A= S IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL Intel OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ + +#include "standard-headers/linux/virtio_ids.h" + +#define METADATA_SIZE 4096 +#define MAX_REMOTE_REGION 8 + +struct vpnet_config { + uint16_t status; +}; + +struct vpnet_remote_mem { + uint64_t gpa; + uint64_t size; +}; + +struct vpnet_remote_vq { + uint16_t last_avail_idx; + int32_t vring_enabled; + uint32_t vring_num; + uint64_t desc_gpa; + uint64_t avail_gpa; + uint64_t used_gpa; +}; + +struct vpnet_metadata { + uint32_t nregions; + uint32_t nvqs; + struct vpnet_remote_mem mem[MAX_REMOTE_REGION]; + struct vpnet_remote_vq vq[0]; +}; + +#endif diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard= -headers/linux/virtio_ids.h index 6d5c3b2..333bbd1 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_VHOST_PCI_NET 21 /* vhost-pci-net */ =20 #endif /* _LINUX_VIRTIO_IDS_H */ --=20 2.7.4 From nobody Sun May 5 10:51:37 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.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 From nobody Sun May 5 10:51:37 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.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 1512445918841899.8720887013677; Mon, 4 Dec 2017 19:51:58 -0800 (PST) Received: from localhost ([::1]:46254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Gu-0002i7-9q for importer@patchew.org; Mon, 04 Dec 2017 22:51:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Ev-0001QK-1b for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM4Et-0007Oc-6N for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:49 -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 1eM4Es-0007JF-Mn for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:47 -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:46 -0800 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga003.jf.intel.com with ESMTP; 04 Dec 2017 19:49:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,362,1508828400"; d="scan'208";a="9615367" 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:13 +0800 Message-Id: <1512444796-30615-5-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 4/7] vhost-pci-slave: add vhost-pci slave implementation 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" The vhost-pci slave implementation is added to support the creation of the vhost-pci-net device. It follows the vhost-user protocol to get the master VM's info (e.g. memory regions, vring address). Signed-off-by: Wei Wang --- hw/net/vhost_pci_net.c | 20 ++- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-pci-slave.c | 307 ++++++++++++++++++++++++++++++++= ++++ include/hw/virtio/vhost-pci-net.h | 3 + include/hw/virtio/vhost-pci-slave.h | 12 ++ 5 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 hw/virtio/vhost-pci-slave.c create mode 100644 include/hw/virtio/vhost-pci-slave.h diff --git a/hw/net/vhost_pci_net.c b/hw/net/vhost_pci_net.c index db8f954..11184c3 100644 --- a/hw/net/vhost_pci_net.c +++ b/hw/net/vhost_pci_net.c @@ -21,6 +21,7 @@ #include "hw/virtio/virtio-access.h" #include "hw/virtio/vhost-pci-net.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/vhost-pci-slave.h" =20 static uint64_t vpnet_get_features(VirtIODevice *vdev, uint64_t features, Error **errp) @@ -45,6 +46,10 @@ static void vpnet_device_realize(DeviceState *dev, Error= **errp) VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); =20 + qemu_chr_fe_set_handlers(&vpnet->chr_be, vp_slave_can_read, + vp_slave_read, vp_slave_event, NULL, + vpnet, NULL, true); + virtio_init(vdev, "vhost-pci-net", VIRTIO_ID_VHOST_PCI_NET, vpnet->config_size); =20 @@ -59,7 +64,20 @@ static void vpnet_device_realize(DeviceState *dev, Error= **errp) static void vpnet_device_unrealize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); - + VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + int i, ret, nregions =3D vpnet->metadata->nregions; + + for (i =3D 0; i < nregions; i++) { + ret =3D munmap(vpnet->remote_mem_base[i], vpnet->remote_mem_map_si= ze[i]); + if (ret < 0) { + error_report("%s: failed to unmap mr[%d]", __func__, i); + continue; + } + memory_region_del_subregion(&vpnet->bar_region, + &vpnet->remote_mem_region[i]); + } + + qemu_chr_fe_deinit(&vpnet->chr_be, true); virtio_cleanup(vdev); } =20 diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 765d363..5e81f2f 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -3,6 +3,7 @@ common-obj-y +=3D virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) +=3D virtio-pci.o common-obj-y +=3D virtio-bus.o common-obj-y +=3D virtio-mmio.o +common-obj-y +=3D vhost-pci-slave.o =20 obj-y +=3D virtio.o virtio-balloon.o=20 obj-$(CONFIG_LINUX) +=3D vhost.o vhost-backend.o vhost-user.o diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c new file mode 100644 index 0000000..b1a8620 --- /dev/null +++ b/hw/virtio/vhost-pci-slave.c @@ -0,0 +1,307 @@ +/* + * Vhost-pci Slave + * + * Copyright Intel Corp. 2017 + * + * Authors: + * Wei Wang + * Zhiyong Yang + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include +#include + +#include "monitor/qdev.h" +#include "qapi/error.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "hw/virtio/virtio-pci.h" +#include "hw/virtio/vhost-pci-slave.h" +#include "hw/virtio/vhost-user.h" +#include "hw/virtio/vhost-pci-net.h" + +#define VHOST_USER_PROTOCOL_FEATURES 0 + +static int vp_slave_write(CharBackend *chr_be, VhostUserMsg *msg) +{ + int size; + + if (!msg) { + return 0; + } + + /* The payload size has been assigned, plus the header size here */ + size =3D msg->size + VHOST_USER_HDR_SIZE; + msg->flags &=3D ~VHOST_USER_VERSION_MASK; + msg->flags |=3D VHOST_USER_VERSION; + + return qemu_chr_fe_write_all(chr_be, (const uint8_t *)msg, size) + =3D=3D size ? 0 : -1; +} + +static int vp_slave_get_features(VhostPCINet *vpnet, CharBackend *chr_be, + VhostUserMsg *msg) +{ + /* Offer the initial features, which have the protocol feature bit set= */ + msg->payload.u64 =3D (uint64_t)vpnet->host_features | + (1 << VHOST_USER_F_PROTOCOL_FEATURES); + msg->size =3D sizeof(msg->payload.u64); + msg->flags |=3D VHOST_USER_REPLY_MASK; + + return vp_slave_write(chr_be, msg); +} + +static void vp_slave_set_features(VhostPCINet *vpnet, VhostUserMsg *msg) +{ + vpnet->host_features =3D msg->payload.u64 & + ~(1 << VHOST_USER_F_PROTOCOL_FEATURES); +} + +void vp_slave_event(void *opaque, int event) +{ + switch (event) { + case CHR_EVENT_OPENED: + break; + case CHR_EVENT_CLOSED: + break; + } +} + +static int vp_slave_get_protocol_features(CharBackend *chr_be, + VhostUserMsg *msg) +{ + msg->payload.u64 =3D VHOST_USER_PROTOCOL_FEATURES; + msg->size =3D sizeof(msg->payload.u64); + msg->flags |=3D VHOST_USER_REPLY_MASK; + + return vp_slave_write(chr_be, msg); +} + +static int vp_slave_get_queue_num(CharBackend *chr_be, VhostUserMsg *msg) +{ + msg->payload.u64 =3D VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX; + msg->size =3D sizeof(msg->payload.u64); + msg->flags |=3D VHOST_USER_REPLY_MASK; + + return vp_slave_write(chr_be, msg); +} + +/* Set up the vhost-pci-net device bar to map the remote memory */ +static int vp_slave_set_mem_table(VhostPCINet *vpnet, VhostUserMsg *msg, + int *fds, int fd_num) +{ + VhostUserMemory *mem =3D &msg->payload.memory; + VhostUserMemoryRegion *region =3D mem->regions; + uint32_t i, nregions =3D mem->nregions; + uint64_t bar_map_offset =3D METADATA_SIZE; + void *remote_mem_ptr; + + /* Sanity Check */ + if (fd_num !=3D nregions) { + error_report("%s: fd num doesn't match region num", __func__); + return -1; + } + + vpnet->metadata->nregions =3D nregions; + vpnet->remote_mem_region =3D g_malloc(nregions * sizeof(MemoryRegion)); + + for (i =3D 0; i < nregions; i++) { + vpnet->remote_mem_map_size[i] =3D region[i].memory_size + + region[i].mmap_offset; + /* + * Map the remote memory by QEMU. They will then be exposed to the + * guest via a vhost-pci device BAR. The mapped base addr and size + * are recorded and will be used when cleaning up the device. + */ + vpnet->remote_mem_base[i] =3D mmap(NULL, vpnet->remote_mem_map_siz= e[i], + PROT_READ | PROT_WRITE, MAP_SHARE= D, + fds[i], 0); + if (vpnet->remote_mem_base[i] =3D=3D MAP_FAILED) { + error_report("%s: map peer memory region %d failed", __func__,= i); + return -1; + } + + remote_mem_ptr =3D vpnet->remote_mem_base[i] + region[i].mmap_offs= et; + /* + * The BAR MMIO is different from the traditional one, because the + * it is set up as a regular RAM. Guest will be able to directly + * access it without VMExits, just like accessing its RAM memory. + */ + memory_region_init_ram_ptr(&vpnet->remote_mem_region[i], NULL, + "RemoteMemory", region[i].memory_size, + remote_mem_ptr); + /* + * The remote memory regions, which are scattered in the remote VM= 's + * address space, are put continuous in the BAR. + */ + memory_region_add_subregion(&vpnet->bar_region, bar_map_offset, + &vpnet->remote_mem_region[i]); + bar_map_offset +=3D region[i].memory_size; + + vpnet->metadata->mem[i].gpa =3D region[i].guest_phys_addr; + vpnet->metadata->mem[i].size =3D region[i].memory_size; + } + + return 0; +} + +static void vp_slave_set_vring_num(VhostPCINet *vpnet, VhostUserMsg *msg) +{ + struct vhost_vring_state *state =3D &msg->payload.state; + + vpnet->metadata->vq[state->index].vring_num =3D state->num; +} + +static void vp_slave_set_vring_base(VhostPCINet *vpnet, VhostUserMsg *msg) +{ + struct vhost_vring_state *state =3D &msg->payload.state; + + vpnet->metadata->vq[state->index].last_avail_idx =3D state->num; +} + +static int vp_slave_get_vring_base(CharBackend *chr_be, VhostUserMsg *msg) +{ + msg->flags |=3D VHOST_USER_REPLY_MASK; + msg->size =3D sizeof(m.payload.state); + /* Send back the last_avail_idx, which is 0 here */ + msg->payload.state.num =3D 0; + + return vp_slave_write(chr_be, msg); +} + +static void vp_slave_set_vring_addr(VhostPCINet *vpnet, VhostUserMsg *msg) +{ + uint32_t index =3D msg->payload.addr.index; + + vpnet->metadata->vq[index].desc_gpa =3D msg->payload.addr.desc_user_ad= dr; + vpnet->metadata->vq[index].avail_gpa =3D msg->payload.addr.avail_user_= addr; + vpnet->metadata->vq[index].used_gpa =3D msg->payload.addr.used_user_ad= dr; + vpnet->metadata->nvqs =3D msg->payload.addr.index + 1; +} + +static void vp_slave_set_vring_enable(VhostPCINet *vpnet, VhostUserMsg *ms= g) +{ + struct vhost_vring_state *state =3D &msg->payload.state; + + vpnet->metadata->vq[state->index].vring_enabled =3D (int)state->num; +} + +int vp_slave_can_read(void *opaque) +{ + return VHOST_USER_HDR_SIZE; +} + +void vp_slave_read(void *opaque, const uint8_t *buf, int size) +{ + int ret, fd_num, fds[VHOST_MEMORY_MAX_NREGIONS]; + VhostUserMsg msg; + uint8_t *p =3D (uint8_t *) &msg; + VhostPCINet *vpnet =3D (VhostPCINet *)opaque; + CharBackend *chr_be =3D &vpnet->chr_be; + + if (size !=3D VHOST_USER_HDR_SIZE) { + error_report("%s: wrong message size received %d", __func__, size); + return; + } + + memcpy(p, buf, VHOST_USER_HDR_SIZE); + + if (msg.size) { + p +=3D VHOST_USER_HDR_SIZE; + size =3D qemu_chr_fe_read_all(chr_be, p, msg.size); + if (size !=3D msg.size) { + error_report("%s: wrong message size received %d !=3D %d", __f= unc__, + size, msg.size); + return; + } + } + + if (msg.request > VHOST_USER_MAX) { + error_report("%s: read an incorrect msg %d", __func__, msg.request= ); + return; + } + + switch (msg.request) { + case VHOST_USER_GET_FEATURES: + ret =3D vp_slave_get_features(vpnet, chr_be, &msg); + if (ret < 0) { + goto err_handling; + } + break; + case VHOST_USER_SET_FEATURES: + vp_slave_set_features(vpnet, &msg); + break; + case VHOST_USER_GET_PROTOCOL_FEATURES: + ret =3D vp_slave_get_protocol_features(chr_be, &msg); + if (ret < 0) { + goto err_handling; + } + break; + case VHOST_USER_SET_PROTOCOL_FEATURES: + break; + case VHOST_USER_GET_QUEUE_NUM: + ret =3D vp_slave_get_queue_num(chr_be, &msg); + if (ret < 0) { + goto err_handling; + } + break; + case VHOST_USER_SET_OWNER: + break; + case VHOST_USER_SET_MEM_TABLE: + fd_num =3D qemu_chr_fe_get_msgfds(chr_be, fds, sizeof(fds) / sizeo= f(int)); + vp_slave_set_mem_table(vpnet, &msg, fds, fd_num); + break; + case VHOST_USER_SET_VRING_NUM: + vp_slave_set_vring_num(vpnet, &msg); + break; + case VHOST_USER_SET_VRING_BASE: + vp_slave_set_vring_base(vpnet, &msg); + break; + case VHOST_USER_GET_VRING_BASE: + ret =3D vp_slave_get_vring_base(chr_be, &msg); + if (ret < 0) { + goto err_handling; + } + break; + case VHOST_USER_SET_VRING_ADDR: + vp_slave_set_vring_addr(vpnet, &msg); + break; + case VHOST_USER_SET_VRING_KICK: + /* Consume the fd */ + qemu_chr_fe_get_msgfds(chr_be, fds, 1); + /* + * This is a non-blocking eventfd. + * The receive function forces it to be blocking, + * so revert it back to non-blocking. + */ + qemu_set_nonblock(fds[0]); + break; + case VHOST_USER_SET_VRING_CALL: + /* Consume the fd, and revert it to non-blocking. */ + qemu_chr_fe_get_msgfds(chr_be, fds, 1); + qemu_set_nonblock(fds[0]); + break; + case VHOST_USER_SET_VRING_ENABLE: + vp_slave_set_vring_enable(vpnet, &msg); + break; + case VHOST_USER_SET_LOG_BASE: + break; + case VHOST_USER_SET_LOG_FD: + qemu_chr_fe_get_msgfds(chr_be, fds, 1); + close(fds[0]); + break; + case VHOST_USER_SEND_RARP: + break; + default: + error_report("vhost-pci-slave does not support msg request =3D %d", + msg.request); + break; + } + return; + +err_handling: + error_report("%s: handle request %d failed", __func__, msg.request); +} diff --git a/include/hw/virtio/vhost-pci-net.h b/include/hw/virtio/vhost-pc= i-net.h index 0c6886d..6f4ab6a 100644 --- a/include/hw/virtio/vhost-pci-net.h +++ b/include/hw/virtio/vhost-pci-net.h @@ -27,7 +27,10 @@ typedef struct VhostPCINet { VirtIODevice parent_obj; MemoryRegion bar_region; MemoryRegion metadata_region; + MemoryRegion *remote_mem_region; struct vpnet_metadata *metadata; + void *remote_mem_base[MAX_REMOTE_REGION]; + uint64_t remote_mem_map_size[MAX_REMOTE_REGION]; uint32_t host_features; size_t config_size; uint16_t status; diff --git a/include/hw/virtio/vhost-pci-slave.h b/include/hw/virtio/vhost-= pci-slave.h new file mode 100644 index 0000000..1be6a87 --- /dev/null +++ b/include/hw/virtio/vhost-pci-slave.h @@ -0,0 +1,12 @@ +#ifndef QEMU_VHOST_PCI_SLAVE_H +#define QEMU_VHOST_PCI_SLAVE_H + +#include "linux-headers/linux/vhost.h" + +extern int vp_slave_can_read(void *opaque); + +extern void vp_slave_read(void *opaque, const uint8_t *buf, int size); + +extern void vp_slave_event(void *opaque, int event); + +#endif --=20 2.7.4 From nobody Sun May 5 10:51:37 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.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512446050684673.7202574004131; Mon, 4 Dec 2017 19:54:10 -0800 (PST) Received: from localhost ([::1]:46265 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4J1-0005mN-QJ for importer@patchew.org; Mon, 04 Dec 2017 22:54:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Ez-0001Ti-6a for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM4Ev-0007PS-5x for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:53 -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 1eM4Eu-0007JF-Sb for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:49 -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:48 -0800 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga003.jf.intel.com with ESMTP; 04 Dec 2017 19:49:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,362,1508828400"; d="scan'208";a="9615378" 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:14 +0800 Message-Id: <1512444796-30615-6-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 5/7] vhost-user: VHOST_USER_SET_VHOST_PCI msg 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 a new vhost-uer protocol msg, VHOST_USER_SET_VHOST_PCI. This msg is used to signal the vhost-pci device to start/stop working. Signed-off-by: Wei Wang --- hw/net/vhost_net.c | 37 +++++++++++++++++++++++++++++++++++= ++ hw/virtio/vhost-pci-slave.c | 2 +- hw/virtio/vhost-user.c | 17 +++++++++++++++++ hw/virtio/vhost.c | 7 +++++++ include/hw/virtio/vhost-backend.h | 2 ++ include/hw/virtio/vhost-user.h | 2 ++ include/hw/virtio/vhost.h | 2 ++ include/net/vhost_net.h | 2 ++ 8 files changed, 70 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index e037db6..107aa13 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -296,6 +296,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + struct vhost_net *last_net; int r, e, i; =20 if (!k->set_guest_notifiers) { @@ -341,6 +342,18 @@ int vhost_net_start(VirtIODevice *dev, NetClientState = *ncs, } } =20 + last_net =3D get_vhost_net(ncs[total_queues - 1].peer); + if (vhost_pci_enabled(&last_net->dev)) { + /* + * All the msgs have been sync-ed to the vhost-pci device. This is= the + * last one to signal the vhost-pci device to link up. + */ + r =3D vhost_set_vhost_pci(ncs[total_queues - 1].peer, true); + if (r < 0) { + goto err_start; + } + } + return 0; =20 err_start: @@ -362,8 +375,15 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState = *ncs, BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + struct vhost_net *last_net; int i, r; =20 + last_net =3D get_vhost_net(ncs[total_queues - 1].peer); + if (vhost_pci_enabled(&last_net->dev)) { + /* Signal the vhost-pci device to stop. */ + vhost_set_vhost_pci(ncs[total_queues - 1].peer, false); + } + for (i =3D 0; i < total_queues; i++) { vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); } @@ -450,6 +470,18 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t = mtu) return vhost_ops->vhost_net_set_mtu(&net->dev, mtu); } =20 +int vhost_set_vhost_pci(NetClientState *nc, bool up) +{ + VHostNetState *net =3D get_vhost_net(nc); + const VhostOps *vhost_ops =3D net->dev.vhost_ops; + + if (vhost_ops && vhost_ops->vhost_set_vhost_pci) { + return vhost_ops->vhost_set_vhost_pci(&net->dev, up); + } + + return 0; +} + #else uint64_t vhost_net_get_max_queues(VHostNetState *net) { @@ -521,4 +553,9 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t m= tu) { return 0; } + +int vhost_set_vhost_pci(NetClientState *nc, bool up) +{ + return 0; +} #endif diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c index b1a8620..8052884 100644 --- a/hw/virtio/vhost-pci-slave.c +++ b/hw/virtio/vhost-pci-slave.c @@ -23,7 +23,7 @@ #include "hw/virtio/vhost-user.h" #include "hw/virtio/vhost-pci-net.h" =20 -#define VHOST_USER_PROTOCOL_FEATURES 0 +#define VHOST_USER_PROTOCOL_FEATURES (1UL << VHOST_USER_PROTOCOL_F_VHOST_P= CI) =20 static int vp_slave_write(CharBackend *chr_be, VhostUserMsg *msg) { diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index e512f5a..a48003a 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -342,6 +342,22 @@ static int vhost_user_set_vring_enable(struct vhost_de= v *dev, int enable) return 0; } =20 +static int vhost_user_set_vhost_pci(struct vhost_dev *dev, bool up) +{ + VhostUserMsg msg =3D { + .request =3D VHOST_USER_SET_VHOST_PCI, + .flags =3D VHOST_USER_VERSION, + .payload.u64 =3D (uint64_t)up, + .size =3D sizeof(msg.payload.u64), + }; + + if (vhost_user_write(dev, &msg, NULL, 0) < 0) { + return -1; + } + + return 0; +} + static int vhost_user_get_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { @@ -844,6 +860,7 @@ const VhostOps user_ops =3D { .vhost_reset_device =3D vhost_user_reset_device, .vhost_get_vq_index =3D vhost_user_get_vq_index, .vhost_set_vring_enable =3D vhost_user_set_vring_enable, + .vhost_set_vhost_pci =3D vhost_user_set_vhost_pci, .vhost_requires_shm_log =3D vhost_user_requires_shm_log, .vhost_migration_done =3D vhost_user_migration_done, .vhost_backend_can_merge =3D vhost_user_can_merge, diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e4290ce..dda7b8f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -25,6 +25,7 @@ #include "exec/address-spaces.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#include "hw/virtio/vhost-user.h" #include "migration/blocker.h" #include "sysemu/dma.h" =20 @@ -1007,6 +1008,12 @@ out: return ret; } =20 +bool vhost_pci_enabled(struct vhost_dev *dev) +{ + return ((dev->protocol_features & + (1ULL << VHOST_USER_PROTOCOL_F_VHOST_PCI)) !=3D 0); +} + static int vhost_virtqueue_start(struct vhost_dev *dev, struct VirtIODevice *vdev, struct vhost_virtqueue *vq, diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index a7a5f22..e9d23dd 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -71,6 +71,7 @@ typedef int (*vhost_reset_device_op)(struct vhost_dev *de= v); typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx); typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev, int enable); +typedef int (*vhost_set_vhost_pci_op)(struct vhost_dev *dev, bool up); typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev); typedef int (*vhost_migration_done_op)(struct vhost_dev *dev, char *mac_addr); @@ -111,6 +112,7 @@ typedef struct VhostOps { vhost_reset_device_op vhost_reset_device; vhost_get_vq_index_op vhost_get_vq_index; vhost_set_vring_enable_op vhost_set_vring_enable; + vhost_set_vhost_pci_op vhost_set_vhost_pci; vhost_requires_shm_log_op vhost_requires_shm_log; vhost_migration_done_op vhost_migration_done; vhost_backend_can_merge_op vhost_backend_can_merge; diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index d76e9ad..d5bcee7 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -14,6 +14,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_NET_MTU =3D 4, VHOST_USER_PROTOCOL_F_SLAVE_REQ =3D 5, VHOST_USER_PROTOCOL_F_CROSS_ENDIAN =3D 6, + VHOST_USER_PROTOCOL_F_VHOST_PCI =3D 7, =20 VHOST_USER_PROTOCOL_F_MAX }; @@ -45,6 +46,7 @@ typedef enum VhostUserRequest { VHOST_USER_SET_SLAVE_REQ_FD =3D 21, VHOST_USER_IOTLB_MSG =3D 22, VHOST_USER_SET_VRING_ENDIAN =3D 23, + VHOST_USER_SET_VHOST_PCI =3D 24, VHOST_USER_MAX } VhostUserRequest; =20 diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 467dc77..f173e81 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -106,4 +106,6 @@ int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file); =20 int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int writ= e); + +bool vhost_pci_enabled(struct vhost_dev *dev); #endif diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index afc1499..257e8cc 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -37,4 +37,6 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net); =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); =20 +int vhost_set_vhost_pci(NetClientState *nc, bool up); + #endif --=20 2.7.4 From nobody Sun May 5 10:51:37 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.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512446054644742.2637052571863; Mon, 4 Dec 2017 19:54:14 -0800 (PST) Received: from localhost ([::1]:46267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4JB-0005vI-TH for importer@patchew.org; Mon, 04 Dec 2017 22:54:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Ez-0001Th-65 for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM4Ex-0007QB-9n for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:53 -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 1eM4Ex-0007JF-0Q for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:51 -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:50 -0800 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga003.jf.intel.com with ESMTP; 04 Dec 2017 19:49:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,362,1508828400"; d="scan'208";a="9615383" 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:15 +0800 Message-Id: <1512444796-30615-7-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 6/7] vhost-pci-slave: handle VHOST_USER_SET_VHOST_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" This patch implements the slave part handling of the VHOST_USER_SET_VHOST_PCI msg. Receiving a "true" from the master will set the LINK_UP status of the vhost-pci device config status, and a config interrupt will be injected to the guest to notify that the device is ready to use. The driver is expected to start reading the metadata for remote memory and vring setup after this LINK_UP interrupt is received. Receiving a "false" from the master will clear the LINK_UP status and inject a config interrupt to the guest to notify the driver to stop sending and receiving packets. Signed-off-by: Wei Wang --- hw/net/vhost_pci_net.c | 13 +++++++++++++ hw/virtio/vhost-pci-slave.c | 3 +++ include/hw/virtio/vhost-pci-net.h | 2 ++ include/standard-headers/linux/vhost_pci_net.h | 2 ++ 4 files changed, 20 insertions(+) diff --git a/hw/net/vhost_pci_net.c b/hw/net/vhost_pci_net.c index 11184c3..39eb28d 100644 --- a/hw/net/vhost_pci_net.c +++ b/hw/net/vhost_pci_net.c @@ -32,6 +32,19 @@ static uint64_t vpnet_get_features(VirtIODevice *vdev, u= int64_t features, return features; } =20 +void vpnet_set_link_up(VhostPCINet *vpnet, bool up) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(vpnet); + + if (up) { + vpnet->status |=3D VPNET_S_LINK_UP; + } else { + vpnet->status &=3D ~VPNET_S_LINK_UP; + } + + virtio_notify_config(vdev); +} + static void vpnet_get_config(VirtIODevice *vdev, uint8_t *config) { VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c index 8052884..6554efb 100644 --- a/hw/virtio/vhost-pci-slave.c +++ b/hw/virtio/vhost-pci-slave.c @@ -287,6 +287,9 @@ void vp_slave_read(void *opaque, const uint8_t *buf, in= t size) case VHOST_USER_SET_VRING_ENABLE: vp_slave_set_vring_enable(vpnet, &msg); break; + case VHOST_USER_SET_VHOST_PCI: + vpnet_set_link_up(vpnet, (bool)msg.payload.u64); + break; case VHOST_USER_SET_LOG_BASE: break; case VHOST_USER_SET_LOG_FD: diff --git a/include/hw/virtio/vhost-pci-net.h b/include/hw/virtio/vhost-pc= i-net.h index 6f4ab6a..2d0e94c 100644 --- a/include/hw/virtio/vhost-pci-net.h +++ b/include/hw/virtio/vhost-pci-net.h @@ -37,4 +37,6 @@ typedef struct VhostPCINet { CharBackend chr_be; } VhostPCINet; =20 +void vpnet_set_link_up(VhostPCINet *vpnet, bool up); + #endif diff --git a/include/standard-headers/linux/vhost_pci_net.h b/include/stand= ard-headers/linux/vhost_pci_net.h index 792261e..ab91989 100644 --- a/include/standard-headers/linux/vhost_pci_net.h +++ b/include/standard-headers/linux/vhost_pci_net.h @@ -35,6 +35,8 @@ =20 #define MAX_REMOTE_REGION 8 =20 +/* Set by the device to indicate that the device (e.g. metadata) is ready = */ +#define VPNET_S_LINK_UP 1 struct vpnet_config { uint16_t status; }; --=20 2.7.4 From nobody Sun May 5 10:51:37 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.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512446160675408.12045649462425; Mon, 4 Dec 2017 19:56:00 -0800 (PST) Received: from localhost ([::1]:46281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4Ku-0007NP-0Z for importer@patchew.org; Mon, 04 Dec 2017 22:56:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM4F0-0001Uk-Ey for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM4Ez-0007R5-Go for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:54 -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 1eM4Ez-0007JF-6T for qemu-devel@nongnu.org; Mon, 04 Dec 2017 22:49:53 -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:52 -0800 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga003.jf.intel.com with ESMTP; 04 Dec 2017 19:49:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,362,1508828400"; d="scan'208";a="9615401" 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:16 +0800 Message-Id: <1512444796-30615-8-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 7/7] virtio/vhost.c: vhost-pci needs remote gpa 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" The vhost-pci driver uses the remote guest physical address to send/receive packets from the remote guest, so when sending the ving info to the vhost-p= ci device, send the guest physical adress directly. Signed-off-by: Wei Wang --- hw/virtio/vhost.c | 56 +++++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index dda7b8f..ffbda6c 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1057,26 +1057,38 @@ static int vhost_virtqueue_start(struct vhost_dev *= dev, } } =20 - vq->desc_size =3D s =3D l =3D virtio_queue_get_desc_size(vdev, idx); vq->desc_phys =3D a =3D virtio_queue_get_desc_addr(vdev, idx); - vq->desc =3D vhost_memory_map(dev, a, &l, 0); - if (!vq->desc || l !=3D s) { - r =3D -ENOMEM; - goto fail_alloc_desc; + if (vhost_pci_enabled(dev)) { + vq->desc =3D (void *)a; + } else { + vq->desc_size =3D s =3D l =3D virtio_queue_get_desc_size(vdev, idx= ); + vq->desc =3D vhost_memory_map(dev, a, &l, 0); + if (!vq->desc || l !=3D s) { + r =3D -ENOMEM; + goto fail_alloc_desc; + } } vq->avail_size =3D s =3D l =3D virtio_queue_get_avail_size(vdev, idx); vq->avail_phys =3D a =3D virtio_queue_get_avail_addr(vdev, idx); - vq->avail =3D vhost_memory_map(dev, a, &l, 0); - if (!vq->avail || l !=3D s) { - r =3D -ENOMEM; - goto fail_alloc_avail; + if (vhost_pci_enabled(dev)) { + vq->avail =3D (void *)a; + } else { + vq->avail =3D vhost_memory_map(dev, a, &l, 0); + if (!vq->avail || l !=3D s) { + r =3D -ENOMEM; + goto fail_alloc_avail; + } } vq->used_size =3D s =3D l =3D virtio_queue_get_used_size(vdev, idx); vq->used_phys =3D a =3D virtio_queue_get_used_addr(vdev, idx); - vq->used =3D vhost_memory_map(dev, a, &l, 1); - if (!vq->used || l !=3D s) { - r =3D -ENOMEM; - goto fail_alloc_used; + if (vhost_pci_enabled(dev)) { + vq->used =3D (void *)a; + } else { + vq->used =3D vhost_memory_map(dev, a, &l, 1); + if (!vq->used || l !=3D s) { + r =3D -ENOMEM; + goto fail_alloc_used; + } } =20 r =3D vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabl= ed); @@ -1163,13 +1175,17 @@ static void vhost_virtqueue_stop(struct vhost_dev *= dev, !virtio_is_big_endian(vdev= ), vhost_vq_index); } - - vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx= ), - 1, virtio_queue_get_used_size(vdev, idx)); - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), - 0, virtio_queue_get_avail_size(vdev, idx)); - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), - 0, virtio_queue_get_desc_size(vdev, idx)); + if (!vhost_pci_enabled(dev)) { + vhost_memory_unmap(dev, vq->used, + virtio_queue_get_used_size(vdev, idx), + 1, virtio_queue_get_used_size(vdev, idx)); + vhost_memory_unmap(dev, vq->avail, + virtio_queue_get_avail_size(vdev, idx), + 0, virtio_queue_get_avail_size(vdev, idx)); + vhost_memory_unmap(dev, vq->desc, + virtio_queue_get_desc_size(vdev, idx), + 0, virtio_queue_get_desc_size(vdev, idx)); + } } =20 static void vhost_eventfd_add(MemoryListener *listener, --=20 2.7.4