From nobody Fri May 3 12:01:33 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.zoho.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 1494578630323126.30394783983593; Fri, 12 May 2017 01:43:50 -0700 (PDT) Received: from localhost ([::1]:52063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96Au-0007iM-Sa for importer@patchew.org; Fri, 12 May 2017 04:43:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968f-0005Yl-Jt for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968d-0001iG-1M for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:29 -0400 Received: from mga11.intel.com ([192.55.52.93]:10685) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968c-0001gq-NW for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:26 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:25 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616172" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:33 +0800 Message-Id: <1494578148-102868-2-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 01/16] 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: Wei Wang 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 | 89 +-------------------------------------= -- include/hw/virtio/vhost-user.h | 93 ++++++++++++++++++++++++++++++++++++++= ++++ include/net/vhost-user.h | 4 +- 3 files changed, 96 insertions(+), 90 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 9334a8a..d161884 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 "sysemu/char.h" #include "sysemu/kvm.h" @@ -22,94 +23,6 @@ #include #include #include -#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_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_MAX -} VhostUserRequest; - -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; - } 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) =20 static bool ioeventfd_enabled(void) { diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h new file mode 100644 index 0000000..766a950 --- /dev/null +++ b/include/hw/virtio/vhost-user.h @@ -0,0 +1,93 @@ +#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_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_MAX +} VhostUserRequest; + +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; + } 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 diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h index 5bcd8a6..d9e328d 100644 --- a/include/net/vhost-user.h +++ b/include/net/vhost-user.h @@ -8,8 +8,8 @@ * */ =20 -#ifndef VHOST_USER_H -#define VHOST_USER_H +#ifndef NET_VHOST_USER_H +#define NET_VHOST_USER_H =20 struct vhost_net; struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc); --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494578594213416.6255313714423; Fri, 12 May 2017 01:43:14 -0700 (PDT) Received: from localhost ([::1]:52061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96AJ-0007Ak-Tj for importer@patchew.org; Fri, 12 May 2017 04:43:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968f-0005Yp-NG for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968e-0001ks-Qj for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:29 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968e-0001je-Hr for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:28 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:27 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616186" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:34 +0800 Message-Id: <1494578148-102868-3-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 02/16] vl: add the vhost-pci-slave command line option 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: Wei Wang 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" An example of the QEMU command to create a vhost-pci-slave is: -chardev socket,id=3Dslave1,server,wait=3Doff,path=3D${PATH_SLAVE1} -vhost-pci-slave socket,chardev=3Dslave1 The master can connect to the slave as usual: -chardev socket,id=3Dsock2,path=3D${PATH_SLAVE1} -netdev type=3Dvhost-user,id=3Dnet2,chardev=3Dsock2,vhostforce -device virtio-net-pci,mac=3D52:54:00:00:00:02,netdev=3Dnet2 Signed-off-by: Wei Wang --- qemu-options.hx | 4 ++++ vl.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index 99af8ed..a795850 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4152,6 +4152,10 @@ contents of @code{iv.b64} to the second secret =20 ETEXI =20 +DEF("vhost-pci-slave", HAS_ARG, QEMU_OPTION_vhost_pci_slave, + "-vhost-pci-slave socket,chrdev=3D{id}\n" + " creates a vhost-pci-slave", + QEMU_ARCH_I386) =20 HXCOMM This is the last statement. Insert new options before this line! STEXI diff --git a/vl.c b/vl.c index 0b4ed52..2ee4713 100644 --- a/vl.c +++ b/vl.c @@ -540,6 +540,20 @@ static QemuOptsList qemu_fw_cfg_opts =3D { }, }; =20 +static QemuOptsList qemu_vhost_pci_slave_opts =3D { + .name =3D "vhost-pci-slave", + .implied_opt_name =3D "chardev", + .head =3D QTAILQ_HEAD_INITIALIZER(qemu_vhost_pci_slave_opts.head), + .desc =3D { + /* + * no elements =3D> accept any + * sanity checking will happen later + * when setting device properties + */ + { /* end of list */ } + }, +}; + /** * Get machine options * @@ -3027,6 +3041,7 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_icount_opts); qemu_add_opts(&qemu_semihosting_config_opts); qemu_add_opts(&qemu_fw_cfg_opts); + qemu_add_opts(&qemu_vhost_pci_slave_opts); module_call_init(MODULE_INIT_OPTS); =20 runstate_init(); @@ -4039,6 +4054,13 @@ int main(int argc, char **argv, char **envp) exit(1); } break; + case QEMU_OPTION_vhost_pci_slave: + opts =3D qemu_opts_parse_noisily( + qemu_find_opts("vhost-pci-slave"), optarg, fals= e); + if (!opts) { + exit(1); + } + break; default: os_parse_cmd_args(popt->index, optarg); } --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 149457860290893.80299187360231; Fri, 12 May 2017 01:43:22 -0700 (PDT) Received: from localhost ([::1]:52062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96AT-0007I3-CW for importer@patchew.org; Fri, 12 May 2017 04:43:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968i-0005as-PY for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968g-0001nu-CM for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:32 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968f-0001je-Sp for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:30 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:29 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616203" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:35 +0800 Message-Id: <1494578148-102868-4-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 03/16] vhost-pci-slave: create a vhost-user slave to support 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: Wei Wang 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" Signed-off-by: Wei Wang --- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-pci-slave.c | 597 ++++++++++++++++++++++++++++++++= ++++ include/hw/virtio/vhost-pci-slave.h | 61 ++++ include/hw/virtio/vhost-user.h | 13 + 4 files changed, 672 insertions(+) create mode 100644 hw/virtio/vhost-pci-slave.c create mode 100644 include/hw/virtio/vhost-pci-slave.h 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..464afa3 --- /dev/null +++ b/hw/virtio/vhost-pci-slave.c @@ -0,0 +1,597 @@ +/* + * Vhost-pci Slave + * + * Copyright Intel Corp. 2017 + * + * Authors: + * Wei Wang + * + * 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" + +/* + * The basic feature bits for all vhost-pci devices. It will be or-ed + * with a device specific features(e.g. VHOST_PCI_NET_FEATURE_BITS), + * defined below. + */ +#define VHOST_PCI_FEATURE_BITS (1ULL << VIRTIO_F_VERSION_1) + +/* + * The device features here are sent to the remote virtio-net device for + * a negotiation first. Then the remotely negotiated features are given + * to the vhost-pci-net device to negotiate with its driver. + */ +#define VHOST_PCI_NET_FEATURE_BITS ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \ + (1ULL << VIRTIO_NET_F_CTRL_VQ) | \ + (1ULL << VIRTIO_NET_F_MQ)) + +VhostPCISlave *vp_slave; + +/* Clean up VhostPCIDev */ +static void vp_dev_cleanup(void) +{ + int ret; + uint32_t i, nregions; + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + Remoteq *remoteq; + + /* + * Normally, the pointer shoud have pointed to the slave device's vdev. + * Otherwise, it means that no vhost-pci device has been created yet. + * In this case, just return. + */ + if (!vp_dev->vdev) { + return; + } + + nregions =3D vp_dev->remote_mem_num; + for (i =3D 0; i < nregions; i++) { + ret =3D munmap(vp_dev->mr_map_base[i], vp_dev->mr_map_size[i]); + if (ret < 0) { + error_report("%s: failed to unmap mr[%d]", __func__, i); + continue; + } + memory_region_del_subregion(vp_dev->bar_mr, vp_dev->sub_mr + i); + } + + if (!QLIST_EMPTY(&vp_dev->remoteq_list)) { + QLIST_FOREACH(remoteq, &vp_dev->remoteq_list, node) + g_free(remoteq); + } + QLIST_INIT(&vp_dev->remoteq_list); + vp_dev->remoteq_num =3D 0; + vp_dev->vdev =3D NULL; +} + +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(CharBackend *chr_be, VhostUserMsg *msg) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + + /* Offer the initial features, which have the protocol feature bit set= */ + msg->payload.u64 =3D vp_dev->feature_bits; + 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(VhostUserMsg *msg) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + + /* + * Get the remotely negotiated feature bits. They will be later taken = by + * the vhost-pci device to negotiate with its driver. Clear the protoc= ol + * feature bit, which is useless for the device and driver negotiation. + */ + vp_dev->feature_bits =3D msg->payload.u64 & + ~(1 << VHOST_USER_F_PROTOCOL_FEATURES); +} + +static 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 void vp_slave_set_device_type(VhostUserMsg *msg) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + vp_dev->dev_type =3D (uint16_t)msg->payload.u64; + + switch (vp_dev->dev_type) { + case VIRTIO_ID_NET: + vp_dev->feature_bits |=3D VHOST_PCI_FEATURE_BITS | + VHOST_PCI_NET_FEATURE_BITS; + break; + default: + error_report("%s: device type %d is not supported", + __func__, vp_dev->dev_type); + } +} + +static int vp_slave_get_queue_num(CharBackend *chr_be, VhostUserMsg *msg) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + + switch (vp_dev->dev_type) { + case VIRTIO_ID_NET: + msg->payload.u64 =3D VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX; + break; + default: + error_report("%s: device type %d is not supported", __func__, + vp_dev->dev_type); + return -1; + } + msg->size =3D sizeof(msg->payload.u64); + msg->flags |=3D VHOST_USER_REPLY_MASK; + + return vp_slave_write(chr_be, msg); +} + +/* Calculate the memory size of all the regions */ +static uint64_t vp_slave_peer_mem_size_get(VhostUserMemory *mem) +{ + int i; + uint64_t total_size =3D 0; + uint32_t nregions =3D mem->nregions; + VhostUserMemoryRegion *mem_regions =3D mem->regions; + + for (i =3D 0; i < nregions; i++) { + total_size +=3D mem_regions[i].memory_size; + } + + return total_size; +} + +/* Prepare the memory for the vhost-pci device bar */ +static int vp_slave_set_mem_table(VhostUserMsg *msg, int *fds, int fd_num) +{ + VhostUserMemory *mem =3D &msg->payload.memory; + VhostUserMemoryRegion *mem_region =3D mem->regions; + uint32_t i, nregions =3D mem->nregions; + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + vp_dev->remote_mem_num =3D nregions; + MemoryRegion *bar_mr, *sub_mr; + uint64_t bar_size, bar_map_offset =3D 0; + RemoteMem *rmem; + void *mr_qva; + + /* Sanity Check */ + if (fd_num !=3D nregions) { + error_report("%s: fd num doesn't match region num", __func__); + return -1; + } + + if (!vp_dev->bar_mr) { + vp_dev->bar_mr =3D g_malloc(sizeof(MemoryRegion)); + } + if (!vp_dev->sub_mr) { + vp_dev->sub_mr =3D g_malloc(nregions * sizeof(MemoryRegion)); + } + bar_mr =3D vp_dev->bar_mr; + sub_mr =3D vp_dev->sub_mr; + + bar_size =3D vp_slave_peer_mem_size_get(mem); + bar_size =3D pow2ceil(bar_size); + memory_region_init(bar_mr, NULL, "RemoteMemory", bar_size); + for (i =3D 0; i < nregions; i++) { + vp_dev->mr_map_size[i] =3D mem_region[i].memory_size + + mem_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 for cleanup() to use. + */ + vp_dev->mr_map_base[i] =3D mmap(NULL, vp_dev->mr_map_size[i], + PROT_READ | PROT_WRITE, MAP_SHARED, + fds[i], 0); + if (vp_dev->mr_map_base[i] =3D=3D MAP_FAILED) { + error_report("%s: map peer memory region %d failed", __func__,= i); + return -1; + } + + mr_qva =3D vp_dev->mr_map_base[i] + mem_region[i].mmap_offset; + /* + * The BAR MMIO is different from the traditional one, because the + * memory is set up as a regular RAM. Guest will be able to direct= ly + * access it, just like accessing its RAM memory. + */ + memory_region_init_ram_ptr(&sub_mr[i], NULL, "RemoteMemory", + mem_region[i].memory_size, mr_qva); + /* + * The remote memory regions, which are scattered in the remote VM= 's + * address space, are put continuous in the BAR. + */ + memory_region_add_subregion(bar_mr, bar_map_offset, &sub_mr[i]); + bar_map_offset +=3D mem_region[i].memory_size; + rmem =3D &vp_dev->remote_mem[i]; + rmem->gpa =3D mem_region[i].guest_phys_addr; + rmem->size =3D mem_region[i].memory_size; + } + vp_dev->bar_map_offset =3D bar_map_offset; + + return 0; +} + +static void vp_slave_alloc_remoteq(void) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + + Remoteq *remoteq =3D g_malloc0(sizeof(Remoteq)); + /* + * Put the new allocated remoteq to the list, because we don't know how + * many remoteq the remote device will send to us. So, when they sent = one, + * insert it to the list. + */ + QLIST_INSERT_HEAD(&vp_dev->remoteq_list, remoteq, node); + vp_dev->remoteq_num++; +} + +static void vp_slave_set_vring_num(VhostUserMsg *msg) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + /* + * The info (vring_num, base etc) is sent for last remoteq, which was = put + * on the first of the list and have not been filled with those info. + */ + Remoteq *remoteq =3D QLIST_FIRST(&vp_dev->remoteq_list); + + remoteq->vring_num =3D msg->payload.u64; +} + +static void vp_slave_set_vring_base(VhostUserMsg *msg) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + Remoteq *remoteq =3D QLIST_FIRST(&vp_dev->remoteq_list); + + remoteq->last_avail_idx =3D msg->payload.u64; +} + +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(VhostUserMsg *msg) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + Remoteq *remoteq =3D QLIST_FIRST(&vp_dev->remoteq_list); + memcpy(&remoteq->addr, &msg->payload.addr, + sizeof(struct vhost_vring_addr)); +} + +static void vp_slave_set_vring_kick(int fd) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + Remoteq *remoteq =3D QLIST_FIRST(&vp_dev->remoteq_list); + if (remoteq) { + remoteq->kickfd =3D fd; + } +} + +static void vp_slave_set_vring_call(int fd) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + Remoteq *remoteq =3D QLIST_FIRST(&vp_dev->remoteq_list); + if (remoteq) { + remoteq->callfd =3D fd; + } +} + +static void vp_slave_set_vring_enable(VhostUserMsg *msg) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + struct vhost_vring_state *state =3D &msg->payload.state; + Remoteq *remoteq; + QLIST_FOREACH(remoteq, &vp_dev->remoteq_list, node) { + if (remoteq->vring_num =3D=3D state->index) { + remoteq->enabled =3D (int)state->num; + break; + } + } +} + +static int vp_slave_device_create(uint16_t virtio_id) +{ + Error *local_err =3D NULL; + QemuOpts *opts; + DeviceState *dev; + char params[50]; + + switch (virtio_id) { + case VIRTIO_ID_NET: + strcpy(params, "driver=3Dvhost-pci-net-pci,id=3Dvhost-pci-0"); + break; + default: + error_report("%s: device type %d not supported", __func__, virtio_= id); + } + + opts =3D qemu_opts_parse_noisily(qemu_find_opts("device"), params, tru= e); + dev =3D qdev_device_add(opts, &local_err); + if (!dev) { + qemu_opts_del(opts); + return -1; + } + object_unref(OBJECT(dev)); + return 0; +} + +static int vp_slave_set_vhost_pci(VhostUserMsg *msg) +{ + int ret =3D 0; + uint8_t cmd =3D (uint8_t)msg->payload.u64; + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + + switch (cmd) { + case VHOST_USER_SET_VHOST_PCI_START: + ret =3D vp_slave_device_create(vp_dev->dev_type); + if (ret < 0) { + return ret; + } + break; + case VHOST_USER_SET_VHOST_PCI_STOP: + break; + default: + error_report("%s: cmd %d not supported", __func__, cmd); + return -1; + } + + return ret; +} + +static int vp_slave_can_read(void *opaque) +{ + return VHOST_USER_HDR_SIZE; +} + +static void vp_slave_read(void *opaque, const uint8_t *buf, int size) +{ + int ret, fd_num, fds[MAX_GUEST_REGION]; + VhostUserMsg msg; + uint8_t *p =3D (uint8_t *) &msg; + CharBackend *chr_be =3D (CharBackend *)opaque; + + 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(chr_be, &msg); + if (ret < 0) { + goto err_handling; + } + break; + case VHOST_USER_SET_FEATURES: + vp_slave_set_features(&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_SET_DEVICE_ID: + /* + * Now, we know the remote device type. Make the related device fe= ature + * bits ready. The remote device will ask for it soon. + */ + vp_slave_set_device_type(&msg); + 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: + /* + * Currently, we don't support adding more memory to the vhost-pci + * device after the device is realized in QEMU. So, just "break" h= ere + * in this case. + */ + if (vp_slave->vp_dev->vdev) { + break; + } + fd_num =3D qemu_chr_fe_get_msgfds(chr_be, fds, sizeof(fds) / sizeo= f(int)); + vp_slave_set_mem_table(&msg, fds, fd_num); + break; + case VHOST_USER_SET_VRING_NUM: + /* + * This is the first message about a remoteq. Other messages (e.g. = BASE, + * ADDR, KICK etc) will follow this message and come soon. So, allo= cate + * a Rqmotq structure here, and ready to record info about the remo= teq + * from the upcoming messages. + */ + vp_slave_alloc_remoteq(); + vp_slave_set_vring_num(&msg); + break; + case VHOST_USER_SET_VRING_BASE: + vp_slave_set_vring_base(&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(&msg); + break; + case VHOST_USER_SET_VRING_KICK: + /* Consume the fd */ + qemu_chr_fe_get_msgfds(chr_be, fds, 1); + vp_slave_set_vring_kick(fds[0]); + /* + * 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 */ + qemu_chr_fe_get_msgfds(chr_be, fds, 1); + vp_slave_set_vring_call(fds[0]); + /* + * 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_ENABLE: + vp_slave_set_vring_enable(&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; + case VHOST_USER_SET_VHOST_PCI: + ret =3D vp_slave_set_vhost_pci(&msg); + if (ret < 0) { + goto err_handling; + } + 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); +} + +static Chardev *vp_slave_parse_chardev(const char *id) +{ + Chardev *chr =3D qemu_chr_find(id); + if (!chr) { + error_report("chardev \"%s\" not found", id); + return NULL; + } + + return chr; +} + +static void vp_dev_init(VhostPCIDev *vp_dev) +{ + vp_dev->feature_bits =3D 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; + vp_dev->bar_mr =3D NULL; + vp_dev->sub_mr =3D NULL; + vp_dev->vdev =3D NULL; + QLIST_INIT(&vp_dev->remoteq_list); + vp_dev->remoteq_num =3D 0; +} + +int vhost_pci_slave_init(QemuOpts *opts) +{ + Chardev *chr; + VhostPCIDev *vp_dev; + const char *chardev_id =3D qemu_opt_get(opts, "chardev"); + + vp_slave =3D g_malloc(sizeof(VhostPCISlave)); + chr =3D vp_slave_parse_chardev(chardev_id); + if (!chr) { + return -1; + } + vp_dev =3D g_malloc(sizeof(VhostPCIDev)); + vp_dev_init(vp_dev); + vp_slave->vp_dev =3D vp_dev; + + qemu_chr_fe_init(&vp_slave->chr_be, chr, &error_abort); + qemu_chr_fe_set_handlers(&vp_slave->chr_be, vp_slave_can_read, + vp_slave_read, vp_slave_event, + &vp_slave->chr_be, NULL, true); + + return 0; +} + +int vhost_pci_slave_cleanup(void) +{ + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + + vp_dev_cleanup(); + qemu_chr_fe_deinit(&vp_slave->chr_be); + g_free(vp_dev->sub_mr); + g_free(vp_dev->bar_mr); + g_free(vp_dev); + + return 0; +} diff --git a/include/hw/virtio/vhost-pci-slave.h b/include/hw/virtio/vhost-= pci-slave.h new file mode 100644 index 0000000..b5bf02a --- /dev/null +++ b/include/hw/virtio/vhost-pci-slave.h @@ -0,0 +1,61 @@ +#ifndef QEMU_VHOST_PCI_SLAVE_H +#define QEMU_VHOST_PCI_SLAVE_H + +#include "linux-headers/linux/vhost.h" + +#include "sysemu/char.h" +#include "exec/memory.h" + +typedef struct Remoteq { + uint16_t last_avail_idx; + uint32_t vring_num; + int kickfd; + int callfd; + int enabled; + struct vhost_vring_addr addr; + QLIST_ENTRY(Remoteq) node; +} Remoteq; + +typedef struct RemoteMem { + uint64_t gpa; + uint64_t size; +} RemoteMem; + +#define MAX_GUEST_REGION 8 +/* + * The basic vhost-pci device struct. + * It is set up by vhost-pci-slave, and shared to the device emulation. + */ +typedef struct VhostPCIDev { + /* Ponnter to the slave device */ + VirtIODevice *vdev; + uint16_t dev_type; + uint64_t feature_bits; + /* Records the end (offset to the BAR) of the last mapped region */ + uint64_t bar_map_offset; + /* The MemoryRegion that will be registered with a vhost-pci device BA= R */ + MemoryRegion *bar_mr; + /* Add to the bar MemoryRegion */ + MemoryRegion *sub_mr; + void *mr_map_base[MAX_GUEST_REGION]; + uint64_t mr_map_size[MAX_GUEST_REGION]; + + uint16_t remote_mem_num; + RemoteMem remote_mem[MAX_GUEST_REGION]; + uint16_t remoteq_num; + QLIST_HEAD(, Remoteq) remoteq_list; +} VhostPCIDev; + +/* Currenltly, a slave supports the creation of only one vhost-pci device = */ +typedef struct VhostPCISlave { + VhostPCIDev *vp_dev; + CharBackend chr_be; +} VhostPCISlave; + +extern int vhost_pci_slave_init(QemuOpts *opts); + +extern int vhost_pci_slave_cleanup(void); + +VhostPCIDev *get_vhost_pci_dev(void); + +#endif diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index 766a950..1fccbe2 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -12,11 +12,22 @@ enum VhostUserProtocolFeature { 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_VHOST_PCI =3D 5, + VHOST_USER_PROTOCOL_F_SET_DEVICE_ID =3D 6, =20 VHOST_USER_PROTOCOL_F_MAX }; =20 #define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX)= - 1) +#define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) |= \ + (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |= \ + (1ULL << VHOST_USER_PROTOCOL_F_RARP) |= \ + (1ULL << VHOST_USER_PROTOCOL_F_VHOST_PCI) |= \ + (1ULL << VHOST_USER_PROTOCOL_F_SET_DEVICE_ID)) + +/* Commands sent to start or stop the vhost-pci device */ +#define VHOST_USER_SET_VHOST_PCI_START 0 +#define VHOST_USER_SET_VHOST_PCI_STOP 1 =20 typedef enum VhostUserRequest { VHOST_USER_NONE =3D 0, @@ -40,6 +51,8 @@ typedef enum VhostUserRequest { VHOST_USER_SET_VRING_ENABLE =3D 18, VHOST_USER_SEND_RARP =3D 19, VHOST_USER_NET_SET_MTU =3D 20, + VHOST_USER_SET_DEVICE_ID =3D 21, + VHOST_USER_SET_VHOST_PCI =3D 22, VHOST_USER_MAX } VhostUserRequest; =20 --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494578760889604.1674619912756; Fri, 12 May 2017 01:46:00 -0700 (PDT) Received: from localhost ([::1]:52076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96D1-0001AO-7k for importer@patchew.org; Fri, 12 May 2017 04:45:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968k-0005c1-00 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968i-0001q9-47 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:34 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968h-0001je-Ll for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:32 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:31 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616223" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:36 +0800 Message-Id: <1494578148-102868-5-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 04/16] 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: Wei Wang 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. Signed-off-by: Wei Wang --- hw/net/vhost-pci-net.c | 248 +++++++++++++++++++++= ++++ hw/virtio/vhost-pci-slave.c | 5 + include/hw/virtio/vhost-pci-net.h | 34 ++++ include/standard-headers/linux/vhost_pci_net.h | 74 ++++++++ 4 files changed, 361 insertions(+) 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/vhost-pci-net.c b/hw/net/vhost-pci-net.c new file mode 100644 index 0000000..8e194ba --- /dev/null +++ b/hw/net/vhost-pci-net.c @@ -0,0 +1,248 @@ +/* + * vhost-pci-net support + * + * Copyright Intel, Inc. 2016 + * + * Authors: + * Wei Wang + * + * 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/virtio/virtio-access.h" +#include "hw/virtio/vhost-pci-net.h" + +#define VPNET_CTRLQ_SIZE 32 +#define VPNET_VQ_SIZE 256 + +static void vpnet_handle_vq(VirtIODevice *vdev, VirtQueue *vq) +{ +} + +static void vpnet_handle_ctrlq(VirtIODevice *vdev, VirtQueue *vq) +{ +} + +/* Send a ctrlq message to the driver */ +static size_t vpnet_send_ctrlq_msg(VhostPCINet *vpnet, + struct vpnet_ctrlq_msg *msg) +{ + VirtQueueElement *elem; + VirtQueue *vq; + size_t msg_len =3D msg->size; + + vq =3D vpnet->ctrlq; + if (!virtio_queue_ready(vq)) { + return 0; + } + + elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); + if (!elem) { + return 0; + } + + iov_from_buf(elem->in_sg, elem->in_num, 0, msg, msg_len); + + virtqueue_push(vq, elem, msg_len); + virtio_notify(VIRTIO_DEVICE(vpnet), vq); + g_free(elem); + + return msg_len; +} + +/* Send a ctrlq message of the remote memory to the driver */ +static void vpnet_send_ctrlq_msg_remote_mem(VhostPCINet *vpnet) +{ + VhostPCIDev *vp_dev =3D get_vhost_pci_dev(); + struct vpnet_ctrlq_msg *msg; + uint16_t payload_size, msg_size; + + payload_size =3D vp_dev->remote_mem_num * + sizeof(struct ctrlq_msg_remote_mem); + msg_size =3D payload_size + VPNET_CTRLQ_MSG_HDR_SIZE; + msg =3D g_malloc(msg_size); + msg->class =3D VHOST_PCI_CTRLQ_MSG_REMOTE_MEM; + msg->size =3D msg_size; + memcpy(msg->payload.msg_remote_mem, vp_dev->remote_mem, payload_size); + vpnet_send_ctrlq_msg(vpnet, msg); + g_free(msg); +} + +static void vpnet_ctrlq_msg_remoteq_add_one(struct vpnet_ctrlq_msg *msg, + Remoteq *remoteq) +{ + uint32_t vring_num =3D remoteq->vring_num; + struct ctrlq_msg_remoteq *msg_remoteq; + + msg_remoteq =3D &msg->payload.msg_remoteq[vring_num]; + msg_remoteq->last_avail_idx =3D remoteq->last_avail_idx; + msg_remoteq->vring_num =3D vring_num; + msg_remoteq->vring_enable =3D remoteq->enabled; + msg_remoteq->desc_gpa =3D remoteq->addr.desc_user_addr; + msg_remoteq->avail_gpa =3D remoteq->addr.avail_user_addr; + msg_remoteq->used_gpa =3D remoteq->addr.used_user_addr; +} + +/* Send a ctrlq message of the remoteq info to the driver */ +static void vpnet_send_ctrlq_msg_remoteq(VhostPCINet *vpnet) +{ + Remoteq *remoteq; + struct vpnet_ctrlq_msg *msg; + uint16_t remoteq_num, msg_size; + VhostPCIDev *vp_dev =3D get_vhost_pci_dev(); + + remoteq_num =3D vp_dev->remoteq_num; + msg_size =3D sizeof(struct ctrlq_msg_remoteq) * remoteq_num + + VPNET_CTRLQ_MSG_HDR_SIZE; + msg =3D g_malloc(msg_size); + msg->class =3D VHOST_PCI_CTRLQ_MSG_REMOTEQ; + msg->size =3D msg_size; + + QLIST_FOREACH(remoteq, &vp_dev->remoteq_list, node) { + /* Get remoteqs from the list, and fill them into the ctrlq_msg */ + vpnet_ctrlq_msg_remoteq_add_one(msg, remoteq); + } + + vpnet_send_ctrlq_msg(vpnet, msg); + g_free(msg); +} + +static void vpnet_set_status(struct VirtIODevice *vdev, uint8_t status) +{ + VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + uint16_t vq_num =3D vpnet->vq_pairs * 2; + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusState *vbus =3D VIRTIO_BUS(qbus); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + VirtQueue *vq; + int r, i; + + /* Send the ctrlq messages to the driver when the ctrlq is ready */ + if (status & VIRTIO_CONFIG_S_DRIVER_OK) { + vpnet_send_ctrlq_msg_remote_mem(vpnet); + vpnet_send_ctrlq_msg_remoteq(vpnet); + } +} + +static uint64_t vpnet_get_features(VirtIODevice *vdev, uint64_t features, + Error **errp) +{ + VhostPCIDev *vp_dev =3D get_vhost_pci_dev(); + + /* + * Give the driver the feature bits that have been negotiated with the + * remote device. + */ + return vp_dev->feature_bits; +} + +static void vpnet_set_features(VirtIODevice *vdev, uint64_t features) +{ +} + +static void vpnet_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + struct vhost_pci_net_config netcfg; + + virtio_stw_p(vdev, &netcfg.status, vpnet->status); + virtio_stw_p(vdev, &netcfg.vq_pairs, vpnet->vq_pairs); + memcpy(config, &netcfg, vpnet->config_size); +} + +static void vpnet_set_config(VirtIODevice *vdev, const uint8_t *config) +{ +} + +static void vpnet_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + uint16_t i, vq_num; + VhostPCIDev *vp_dev =3D get_vhost_pci_dev(); + + vq_num =3D vp_dev->remoteq_num; + vpnet->vq_pairs =3D vq_num / 2; + virtio_init(vdev, "vhost-pci-net", VIRTIO_ID_VHOST_PCI_NET, + vpnet->config_size); + + /* Add local vqs */ + for (i =3D 0; i < vq_num; i++) { + virtio_add_queue(vdev, VPNET_VQ_SIZE, vpnet_handle_vq); + } + /* Add the ctrlq */ + vpnet->ctrlq =3D virtio_add_queue(vdev, VPNET_CTRLQ_SIZE, vpnet_handle= _ctrlq); + + vpnet->status =3D 0; + vp_dev->vdev =3D vdev; +} + +static void vpnet_device_unrealize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + uint16_t i, vq_num =3D vpnet->vq_pairs * 2; + + /* Delete the datapath vqs and the ctrlq */ + for (i =3D 0; i < vq_num + 1; i++) { + virtio_del_queue(vdev, i); + } +} + +static void vpnet_reset(VirtIODevice *vdev) +{ +} + +static Property vpnet_properties[] =3D { + DEFINE_PROP_END_OF_LIST(), +}; + +static void vpnet_instance_init(Object *obj) +{ + VhostPCINet *vpnet =3D VHOST_PCI_NET(obj); + + /* + * The default config_size is sizeof(struct vhost_pci_net_config). + * Can be overriden with vpnet_set_config_size. + */ + vpnet->config_size =3D sizeof(struct vhost_pci_net_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->set_config =3D vpnet_set_config; + vdc->get_features =3D vpnet_get_features; + vdc->set_features =3D vpnet_set_features; + vdc->set_status =3D vpnet_set_status; + vdc->reset =3D vpnet_reset; +} + +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/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c index 464afa3..ab1d06b 100644 --- a/hw/virtio/vhost-pci-slave.c +++ b/hw/virtio/vhost-pci-slave.c @@ -39,6 +39,11 @@ =20 VhostPCISlave *vp_slave; =20 +VhostPCIDev *get_vhost_pci_dev(void) +{ + return vp_slave->vp_dev; +} + /* Clean up VhostPCIDev */ static void vp_dev_cleanup(void) { 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..e3a1c8b --- /dev/null +++ b/include/hw/virtio/vhost-pci-net.h @@ -0,0 +1,34 @@ +/* + * Virtio Network Device + * + * Copyright Intel, Corp. 2016 + * + * Authors: + * Wei Wang + * + * 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 "hw/virtio/vhost-pci-slave.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; + VirtQueue *ctrlq; + uint16_t status; + uint16_t vq_pairs; + size_t config_size; + uint64_t device_features; +} 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..bd8e09f --- /dev/null +++ b/include/standard-headers/linux/vhost_pci_net.h @@ -0,0 +1,74 @@ +#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 VPNET_S_LINK_UP 1 /* Link is up */ + +struct vhost_pci_net_config { + /* + * Legal values are between 1 and 0x8000 + */ + uint16_t vq_pairs; + /* See VPNET_S_* above */ + uint16_t status; +} QEMU_PACKED; + +struct ctrlq_msg_remote_mem { + uint64_t gpa; + uint64_t size; +}; + +struct ctrlq_msg_remoteq { + uint16_t last_avail_idx; + int32_t vring_enable; + uint32_t vring_num; + uint64_t desc_gpa; + uint64_t avail_gpa; + uint64_t used_gpa; +}; + +#define VHOST_PCI_CTRLQ_MSG_REMOTE_MEM 0 +#define VHOST_PCI_CTRLQ_MSG_REMOTEQ 1 +struct vpnet_ctrlq_msg { + uint8_t class; + uint8_t cmd; + uint16_t size; + union { + struct ctrlq_msg_remote_mem msg_remote_mem[0]; + struct ctrlq_msg_remoteq msg_remoteq[0]; + } payload; +} __attribute__((packed)); + +static struct vpnet_ctrlq_msg vpnet_msg __attribute__ ((unused)); +#define VPNET_CTRLQ_MSG_HDR_SIZE (sizeof(vpnet_msg.class) \ + + sizeof(vpnet_msg.cmd) \ + + sizeof(vpnet_msg.size)) + +#endif --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494578925691677.3688538360375; Fri, 12 May 2017 01:48:45 -0700 (PDT) Received: from localhost ([::1]:52086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96Fg-0003dY-3V for importer@patchew.org; Fri, 12 May 2017 04:48:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968l-0005cx-6l for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968j-0001rT-Pv for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:35 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968j-0001je-H8 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:33 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:32 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616239" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:37 +0800 Message-Id: <1494578148-102868-6-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 05/16] vhost-pci-net-pci: 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: Wei Wang 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" Signed-off-by: Wei Wang --- hw/net/Makefile.objs | 2 +- hw/net/vhost-pci-net.c | 6 ---- hw/virtio/virtio-pci.c | 54 +++++++++++++++++++++++++= ++++ hw/virtio/virtio-pci.h | 14 ++++++++ include/hw/pci/pci.h | 1 + include/standard-headers/linux/virtio_ids.h | 1 + 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs index 6a95d92..3b218b0 100644 --- a/hw/net/Makefile.objs +++ b/hw/net/Makefile.objs @@ -33,7 +33,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 index 8e194ba..e36803a 100644 --- a/hw/net/vhost-pci-net.c +++ b/hw/net/vhost-pci-net.c @@ -117,12 +117,6 @@ static void vpnet_send_ctrlq_msg_remoteq(VhostPCINet *= vpnet) static void vpnet_set_status(struct VirtIODevice *vdev, uint8_t status) { VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); - uint16_t vq_num =3D vpnet->vq_pairs * 2; - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusState *vbus =3D VIRTIO_BUS(qbus); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); - VirtQueue *vq; - int r, i; =20 /* Send the ctrlq messages to the driver when the ctrlq is ready */ if (status & VIRTIO_CONFIG_S_DRIVER_OK) { diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index f9b7244..b60e683 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2367,6 +2367,59 @@ 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(), +}; + +#define REMOTE_MEM_BAR_ID 2 +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); + VhostPCIDev *vp_dev =3D get_vhost_pci_dev(); + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + + 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, + vp_dev->bar_mr); + 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) @@ -2596,6 +2649,7 @@ static void virtio_pci_register_types(void) type_register_static(&virtio_keyboard_pci_info); type_register_static(&virtio_mouse_pci_info); type_register_static(&virtio_tablet_pci_info); + type_register_static(&vpnet_pci_info); #ifdef CONFIG_LINUX type_register_static(&virtio_host_pci_info); #endif diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index b095dfc..6ffacd9 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" @@ -43,6 +44,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 VirtIORngPCI VirtIORngPCI; typedef struct VirtIOInputPCI VirtIOInputPCI; @@ -278,6 +280,18 @@ struct VirtIONetPCI { VirtIONet vdev; }; =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. */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index a37a2d5..63903d6 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -83,6 +83,7 @@ #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/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 Fri May 3 12:01:33 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.zoho.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 1494578729673653.179312558589; Fri, 12 May 2017 01:45:29 -0700 (PDT) Received: from localhost ([::1]:52075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96CW-0000jJ-BQ for importer@patchew.org; Fri, 12 May 2017 04:45:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968o-0005fy-Dc for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968l-0001tM-Ed for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:38 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968l-0001je-1D for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:35 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:34 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616253" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:38 +0800 Message-Id: <1494578148-102868-7-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 06/16] virtio: add inter-vm notification support 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: Wei Wang 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 enables the assign of an already allocated eventfd to a notifier. In this case, QEMU creates a new eventfd for the notifier only when the notifier's fd equals to -1. Otherwise, it means that the notifier has been assigned a vaild fd. Signed-off-by: Wei Wang --- hw/net/vhost-pci-net.c | 73 +++++++++++++++++++++++++++++++++++= ++++ hw/virtio/virtio-bus.c | 19 +++++++--- hw/virtio/virtio-pci.c | 22 ++++++++++-- hw/virtio/virtio.c | 32 ++++++++++++++--- include/hw/virtio/vhost-pci-net.h | 6 ++++ include/hw/virtio/virtio.h | 2 ++ 6 files changed, 141 insertions(+), 13 deletions(-) diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c index e36803a..0235511 100644 --- a/hw/net/vhost-pci-net.c +++ b/hw/net/vhost-pci-net.c @@ -18,6 +18,7 @@ #include "qemu/error-report.h" #include "hw/virtio/virtio-access.h" #include "hw/virtio/vhost-pci-net.h" +#include "hw/virtio/virtio-bus.h" =20 #define VPNET_CTRLQ_SIZE 32 #define VPNET_VQ_SIZE 256 @@ -114,12 +115,53 @@ static void vpnet_send_ctrlq_msg_remoteq(VhostPCINet = *vpnet) g_free(msg); } =20 +static inline bool vq_is_txq(uint16_t id) +{ + return (id % 2 =3D=3D 0); +} + +static inline uint16_t tx2rx(uint16_t id) +{ + return id + 1; +} + +static inline uint16_t rx2tx(uint16_t id) +{ + return id - 1; +} + static void vpnet_set_status(struct VirtIODevice *vdev, uint8_t status) { VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + uint16_t vq_num =3D vpnet->vq_pairs * 2; + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusState *vbus =3D VIRTIO_BUS(qbus); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + VirtQueue *vq; + int r, i; =20 /* Send the ctrlq messages to the driver when the ctrlq is ready */ if (status & VIRTIO_CONFIG_S_DRIVER_OK) { + /* + * Set up the callfd when the driver is ready. + * Crosse share the eventfds from the remoteq. + * Use the tx remoteq's kickfd as the rx localq's callfd. + * Use the rx remoteq's kickfd as the tx localq's callfd. + */ + for (i =3D 0; i < vq_num; i++) { + vq =3D virtio_get_queue(vdev, i); + if (vq_is_txq(i)) { + virtio_queue_set_guest_notifier(vq, + vpnet->remoteq_fds[tx2rx(i)].kic= kfd); + } else { + virtio_queue_set_guest_notifier(vq, + vpnet->remoteq_fds[rx2tx(i)].kic= kfd); + } + } + r =3D k->set_guest_notifiers(qbus->parent, vq_num, true); + if (r < 0) { + error_report("Error binding guest notifier: %d", -r); + } vpnet_send_ctrlq_msg_remote_mem(vpnet); vpnet_send_ctrlq_msg_remoteq(vpnet); } @@ -155,17 +197,29 @@ static void vpnet_set_config(VirtIODevice *vdev, cons= t uint8_t *config) { } =20 +static void vpnet_copy_fds_from_vhostdev(VirtqueueFD *fds, Remoteq *remote= q) +{ + fds[remoteq->vring_num].callfd =3D remoteq->callfd; + fds[remoteq->vring_num].kickfd =3D remoteq->kickfd; +} + static void vpnet_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); uint16_t i, vq_num; VhostPCIDev *vp_dev =3D get_vhost_pci_dev(); + Remoteq *remoteq; =20 vq_num =3D vp_dev->remoteq_num; vpnet->vq_pairs =3D vq_num / 2; virtio_init(vdev, "vhost-pci-net", VIRTIO_ID_VHOST_PCI_NET, vpnet->config_size); + vpnet->remoteq_fds =3D g_malloc(sizeof(struct VirtqueueFD) * + vq_num); + QLIST_FOREACH(remoteq, &vp_dev->remoteq_list, node) { + vpnet_copy_fds_from_vhostdev(vpnet->remoteq_fds, remoteq); + } =20 /* Add local vqs */ for (i =3D 0; i < vq_num; i++) { @@ -192,6 +246,25 @@ static void vpnet_device_unrealize(DeviceState *dev, E= rror **errp) =20 static void vpnet_reset(VirtIODevice *vdev) { + VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); + VirtQueue *vq; + uint16_t i, vq_num =3D vpnet->vq_pairs * 2; + + for (i =3D 0; i < vq_num; i++) { + vq =3D virtio_get_queue(vdev, i); + /* + * Cross share the eventfds. + * Use the tx remoteq's callfd as the rx localq's kickfd. + * Use the rx remoteq's callfd as the tx localq's kickfd. + */ + if (vq_is_txq(i)) { + virtio_queue_set_host_notifier(vq, + vpnet->remoteq_fds[tx2rx(i)].cal= lfd); + } else { + virtio_queue_set_host_notifier(vq, + vpnet->remoteq_fds[rx2tx(i)].cal= lfd); + } + } } =20 static Property vpnet_properties[] =3D { diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index 3042232..3cf0991 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -274,11 +274,20 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus,= int n, bool assign) } =20 if (assign) { - r =3D event_notifier_init(notifier, 1); - if (r < 0) { - error_report("%s: unable to init event notifier: %s (%d)", - __func__, strerror(-r), r); - return r; + if (notifier->wfd =3D=3D -1) { + r =3D event_notifier_init(notifier, 1); + if (r < 0) { + error_report("%s: unable to init event notifier: %s (%d)", + __func__, strerror(-r), r); + return r; + } + } else { + r =3D event_notifier_set(notifier); + if (r < 0) { + error_report("%s: unable to set event notifier: %s (%d)", + __func__, strerror(-r), r); + return r; + } } r =3D k->ioeventfd_assign(proxy, notifier, n, true); if (r < 0) { diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index b60e683..3f1a198 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -963,11 +963,24 @@ static int virtio_pci_set_guest_notifier(DeviceState = *d, int n, bool assign, VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); VirtQueue *vq =3D virtio_get_queue(vdev, n); EventNotifier *notifier =3D virtio_queue_get_guest_notifier(vq); + int r =3D 0; =20 if (assign) { - int r =3D event_notifier_init(notifier, 0); - if (r < 0) { - return r; + if (notifier->wfd =3D=3D -1) { + r =3D event_notifier_init(notifier, 0); + if (r < 0) { + error_report("%s: unable to init event notifier: %s (%d)", + __func__, strerror(-r), r); + return r; + + } + } else { + r =3D event_notifier_set(notifier); + if (r < 0) { + error_report("%s: unable to set event notifier: %s (%d)", + __func__, strerror(-r), r); + return r; + } } virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); } else { @@ -2370,6 +2383,9 @@ static const TypeInfo virtio_net_pci_info =3D { /* vhost-pci-net */ =20 static Property vpnet_pci_properties[] =3D { + DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 4), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 03592c5..43c7273 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1196,10 +1196,6 @@ void virtio_reset(void *opaque) vdev->device_endian =3D virtio_default_endian(); } =20 - if (k->reset) { - k->reset(vdev); - } - vdev->broken =3D false; vdev->guest_features =3D 0; vdev->queue_sel =3D 0; @@ -1222,6 +1218,14 @@ void virtio_reset(void *opaque) vdev->vq[i].vring.num =3D vdev->vq[i].vring.num_default; vdev->vq[i].inuse =3D 0; virtio_virtqueue_reset_region_cache(&vdev->vq[i]); + vdev->vq[i].host_notifier.rfd =3D -1; + vdev->vq[i].host_notifier.wfd =3D -1; + vdev->vq[i].guest_notifier.rfd =3D -1; + vdev->vq[i].guest_notifier.wfd =3D -1; + } + + if (k->reset) { + k->reset(vdev); } } =20 @@ -2253,7 +2257,11 @@ void virtio_init(VirtIODevice *vdev, const char *nam= e, vdev->vq[i].vector =3D VIRTIO_NO_VECTOR; vdev->vq[i].vdev =3D vdev; vdev->vq[i].queue_index =3D i; - } + vdev->vq[i].host_notifier.rfd =3D -1; + vdev->vq[i].host_notifier.wfd =3D -1; + vdev->vq[i].guest_notifier.rfd =3D -1; + vdev->vq[i].guest_notifier.wfd =3D -1; + } =20 vdev->name =3D name; vdev->config_len =3D config_size; @@ -2364,6 +2372,13 @@ EventNotifier *virtio_queue_get_guest_notifier(VirtQ= ueue *vq) return &vq->guest_notifier; } =20 +void virtio_queue_set_guest_notifier(VirtQueue *vq, int fd) +{ + EventNotifier *e =3D &vq->guest_notifier; + e->rfd =3D fd; + e->wfd =3D fd; +} + static void virtio_queue_host_notifier_aio_read(EventNotifier *n) { VirtQueue *vq =3D container_of(n, VirtQueue, host_notifier); @@ -2437,6 +2452,13 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQu= eue *vq) return &vq->host_notifier; } =20 +void virtio_queue_set_host_notifier(VirtQueue *vq, int fd) +{ + EventNotifier *e =3D &vq->host_notifier; + e->rfd =3D fd; + e->wfd =3D fd; +} + void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name) { g_free(vdev->bus_name); diff --git a/include/hw/virtio/vhost-pci-net.h b/include/hw/virtio/vhost-pc= i-net.h index e3a1c8b..9776260 100644 --- a/include/hw/virtio/vhost-pci-net.h +++ b/include/hw/virtio/vhost-pci-net.h @@ -22,6 +22,11 @@ #define VHOST_PCI_NET(obj) \ OBJECT_CHECK(VhostPCINet, (obj), TYPE_VHOST_PCI_NET) =20 +typedef struct VirtqueueFD { + int kickfd; + int callfd; +} VirtqueueFD; + typedef struct VhostPCINet { VirtIODevice parent_obj; VirtQueue *ctrlq; @@ -29,6 +34,7 @@ typedef struct VhostPCINet { uint16_t vq_pairs; size_t config_size; uint64_t device_features; + VirtqueueFD *remoteq_fds; } VhostPCINet; =20 #endif diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 7b6edba..423b466 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -276,6 +276,7 @@ void virtio_queue_update_used_idx(VirtIODevice *vdev, i= nt n); VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n); uint16_t virtio_get_queue_index(VirtQueue *vq); EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq); +void virtio_queue_set_guest_notifier(VirtQueue *vq, int fd); void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, bool with_irqfd); int virtio_device_start_ioeventfd(VirtIODevice *vdev); @@ -284,6 +285,7 @@ int virtio_device_grab_ioeventfd(VirtIODevice *vdev); void virtio_device_release_ioeventfd(VirtIODevice *vdev); bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev); EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq); +void virtio_queue_set_host_notifier(VirtQueue *vq, int fd); void virtio_queue_host_notifier_read(EventNotifier *n); void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext = *ctx, VirtIOHandleAIOOutput hand= le_output); --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494578776115327.4175448696875; Fri, 12 May 2017 01:46:16 -0700 (PDT) Received: from localhost ([::1]:52077 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96DG-0001MZ-Rw for importer@patchew.org; Fri, 12 May 2017 04:46:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968o-0005fz-Di for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968n-0001uT-3U for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:38 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968m-0001je-Q9 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:37 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:36 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616265" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:39 +0800 Message-Id: <1494578148-102868-8-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 07/16] vhost-user: send device id to the slave 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: Wei Wang 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" Send virtio device id to the slave to indicate the device type. Signed-off-by: Wei Wang --- hw/net/vhost_net.c | 1 + hw/virtio/vhost-user.c | 20 ++++++++++++++++++++ include/hw/virtio/vhost.h | 1 + 3 files changed, 22 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 22874a9..ea9879f 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -155,6 +155,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) net->dev.max_queues =3D 1; net->dev.nvqs =3D 2; net->dev.vqs =3D net->vqs; + net->dev.dev_type =3D VIRTIO_ID_NET; =20 if (backend_kernel) { r =3D vhost_net_get_fd(options->net_backend); diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index d161884..1eba5e5 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -453,6 +453,18 @@ static int vhost_user_get_features(struct vhost_dev *d= ev, uint64_t *features) return vhost_user_get_u64(dev, VHOST_USER_GET_FEATURES, features); } =20 +static int vhost_user_set_dev_id(struct vhost_dev *dev, uint16_t virtio_id) +{ + VhostUserMsg msg =3D { + .request =3D VHOST_USER_SET_DEVICE_ID, + .flags =3D VHOST_USER_VERSION, + .payload.u64 =3D virtio_id, + .size =3D sizeof(msg.payload.u64), + }; + + return vhost_user_write(dev, &msg, NULL, 0); +} + static int vhost_user_set_owner(struct vhost_dev *dev) { VhostUserMsg msg =3D { @@ -510,6 +522,14 @@ static int vhost_user_init(struct vhost_dev *dev, void= *opaque) return err; } =20 + if (dev->protocol_features & + (1ULL << VHOST_USER_PROTOCOL_F_SET_DEVICE_ID)) { + err =3D vhost_user_set_dev_id(dev, dev->dev_type); + if (err < 0) { + return err; + } + } + /* query the max queues we support if backend supports Multiple Qu= eue */ if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) { err =3D vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index a450321..40ba87e 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -55,6 +55,7 @@ struct vhost_dev { int n_mem_sections; MemoryRegionSection *mem_sections; struct vhost_virtqueue *vqs; + uint16_t dev_type; int nvqs; /* the first virtqueue which would be used by this vhost dev */ int vq_index; --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494578944476774.6847922659096; Fri, 12 May 2017 01:49:04 -0700 (PDT) Received: from localhost ([::1]:52087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96Fz-0003so-8W for importer@patchew.org; Fri, 12 May 2017 04:49:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968p-0005hD-SX for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968o-0001vR-P8 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:39 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968o-0001je-Gl for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:38 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:38 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616269" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:40 +0800 Message-Id: <1494578148-102868-9-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 08/16] vhost-user: send guest physical address of virtqueues to the slave 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: Wei Wang 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" In the vhost-pci case, the slave needs the master side guest physical address, rather than the qemu virtual address. Signed-off-by: Wei Wang --- hw/virtio/vhost.c | 63 ++++++++++++++++++++++++++++++++-----------= ---- include/hw/virtio/vhost.h | 2 ++ 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 613494d..1ce7b92 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/migration.h" #include "sysemu/dma.h" =20 @@ -994,6 +995,12 @@ out: rcu_read_unlock(); } =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, @@ -1037,26 +1044,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 cpu_physical_memory_map(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 cpu_physical_memory_map(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 cpu_physical_memory_map(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); @@ -1139,13 +1158,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)) { + cpu_physical_memory_unmap(vq->used, + virtio_queue_get_used_size(vdev, idx), + 1, virtio_queue_get_used_size(vdev, idx)= ); + cpu_physical_memory_unmap(vq->avail, + virtio_queue_get_avail_size(vdev, idx), + 0, virtio_queue_get_avail_size(vdev, idx= )); + cpu_physical_memory_unmap(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, diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 40ba87e..09e02d8 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -107,4 +107,6 @@ int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file); =20 void vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int wri= te); + +bool vhost_pci_enabled(struct vhost_dev *dev); #endif --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494579070267218.57447844509136; Fri, 12 May 2017 01:51:10 -0700 (PDT) Received: from localhost ([::1]:52109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96I0-0005Pc-F5 for importer@patchew.org; Fri, 12 May 2017 04:51:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968r-0005j5-N4 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968q-0001xK-Iu for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:41 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968q-0001je-83 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:40 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:39 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616276" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:41 +0800 Message-Id: <1494578148-102868-10-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 09/16] vhost-user: send VHOST_USER_SET_VHOST_PCI_START/STOP 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: Wei Wang 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 master requests the slave to create or destroy a vhost-pci device. Signed-off-by: Wei Wang --- hw/net/vhost_net.c | 36 ++++++++++++++++++++++++++++++++++++ hw/virtio/vhost-user.c | 17 +++++++++++++++++ include/hw/virtio/vhost-backend.h | 2 ++ include/net/vhost_net.h | 2 ++ 4 files changed, 57 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ea9879f..0a5278d 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -18,6 +18,7 @@ #include "net/tap.h" #include "net/vhost-user.h" =20 +#include "hw/virtio/vhost-user.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "qemu/error-report.h" @@ -296,6 +297,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 +343,15 @@ 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)) { + r =3D vhost_set_vhost_pci(ncs[total_queues - 1].peer, + VHOST_USER_SET_VHOST_PCI_START); + if (r < 0) { + goto err_start; + } + } + return 0; =20 err_start: @@ -362,8 +373,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)) { + vhost_set_vhost_pci(ncs[total_queues - 1].peer, + VHOST_USER_SET_VHOST_PCI_STOP); + } + for (i =3D 0; i < total_queues; i++) { vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); } @@ -450,6 +468,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, uint8_t cmd) +{ + 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, cmd); + } + + return 0; +} + #else uint64_t vhost_net_get_max_queues(VHostNetState *net) { @@ -521,4 +551,10 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t = mtu) { return 0; } + +int vhost_set_vhost_pci(NetClientState *nc, uint8_t cmd) +{ + return 0; +} + #endif diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 1eba5e5..ca8fe36 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -313,6 +313,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, uint8_t cmd) +{ + VhostUserMsg msg =3D { + .request =3D VHOST_USER_SET_VHOST_PCI, + .flags =3D VHOST_USER_VERSION, + .payload.u64 =3D (uint64_t)cmd, + .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) { @@ -671,6 +687,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/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index c3cf4a7..1c68f67 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -70,6 +70,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, uint8_t cmd); typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev); typedef int (*vhost_migration_done_op)(struct vhost_dev *dev, char *mac_addr); @@ -114,6 +115,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/net/vhost_net.h b/include/net/vhost_net.h index afc1499..3db5559 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, uint8_t cmd); + #endif --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494579085192772.5579515530187; Fri, 12 May 2017 01:51:25 -0700 (PDT) Received: from localhost ([::1]:52111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96IF-0005ak-PI for importer@patchew.org; Fri, 12 May 2017 04:51:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968t-0005k6-1H for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968s-0001yU-6g for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:43 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968r-0001je-UQ for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:42 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:41 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616279" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:42 +0800 Message-Id: <1494578148-102868-11-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 10/16] vhost-pci-net: send the negotiated feature bits to the master 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: Wei Wang 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 slave device actively sends the negotiated feature bits to the master. Signed-off-by: Wei Wang --- hw/net/vhost-pci-net.c | 18 ++++++++++++++++++ hw/virtio/vhost-pci-slave.c | 22 ++++++++++++++++++++++ include/hw/virtio/vhost-pci-slave.h | 2 ++ 3 files changed, 42 insertions(+) diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c index 0235511..1379204 100644 --- a/hw/net/vhost-pci-net.c +++ b/hw/net/vhost-pci-net.c @@ -181,6 +181,24 @@ static uint64_t vpnet_get_features(VirtIODevice *vdev,= uint64_t features, =20 static void vpnet_set_features(VirtIODevice *vdev, uint64_t features) { + /* + * The implementation split the write of the 64-bit "features" into 2 + * 32-bit writes, so the function is called twice. need_send is used to + * detect the second write which finishes the write of "features", and + * need to send to the remote device. + */ + static bool need_send; + int ret; + + if (need_send) { + need_send =3D 0; + ret =3D vp_slave_send_feature_bits(features); + if (ret < 0) { + error_report("%s failed to send feature bits", __func__); + } + } else { + need_send =3D 1; + } } =20 static void vpnet_get_config(VirtIODevice *vdev, uint8_t *config) diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c index ab1d06b..6cc9c21 100644 --- a/hw/virtio/vhost-pci-slave.c +++ b/hw/virtio/vhost-pci-slave.c @@ -122,6 +122,28 @@ static void vp_slave_set_features(VhostUserMsg *msg) ~(1 << VHOST_USER_F_PROTOCOL_FEATURES); } =20 +static int vp_slave_send_u64(int request, uint64_t u64) +{ + VhostUserMsg msg =3D { + .request =3D request, + .flags =3D VHOST_USER_VERSION, + .payload.u64 =3D u64, + .size =3D sizeof(msg.payload.u64), + }; + + if (vp_slave_write(&vp_slave->chr_be, &msg) < 0) { + error_report("%s: failed to send", __func__); + return -1; + } + + return 0; +} + +int vp_slave_send_feature_bits(uint64_t features) +{ + return vp_slave_send_u64(VHOST_USER_SET_FEATURES, features); +} + static void vp_slave_event(void *opaque, int event) { switch (event) { diff --git a/include/hw/virtio/vhost-pci-slave.h b/include/hw/virtio/vhost-= pci-slave.h index b5bf02a..ab21e70 100644 --- a/include/hw/virtio/vhost-pci-slave.h +++ b/include/hw/virtio/vhost-pci-slave.h @@ -56,6 +56,8 @@ extern int vhost_pci_slave_init(QemuOpts *opts); =20 extern int vhost_pci_slave_cleanup(void); =20 +extern int vp_slave_send_feature_bits(uint64_t features); + VhostPCIDev *get_vhost_pci_dev(void); =20 #endif --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494578881427924.9925071858611; Fri, 12 May 2017 01:48:01 -0700 (PDT) Received: from localhost ([::1]:52084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96Ex-0002zC-Ro for importer@patchew.org; Fri, 12 May 2017 04:47:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968x-0005oM-75 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968u-0001zG-0C for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:47 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968t-0001je-Lr for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:43 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:43 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616284" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:43 +0800 Message-Id: <1494578148-102868-12-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 11/16] vhost-user: add asynchronous read for the vhost-user master 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: Wei Wang 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" Enable the vhost-user master to asynchronously receive messages from the slave. The vhost_user_asyn_read and vhost_user_can_read stub functions are defined for platforms that do not support the use of virtio. Signed-off-by: Wei Wang --- hw/virtio/Makefile.objs | 6 +++--- hw/virtio/vhost-stub.c | 11 +++++++++++ hw/virtio/vhost-user.c | 42 ++++++++++++++++++++++++++++++++++++++= +++- include/hw/virtio/vhost-user.h | 4 ++++ include/net/vhost-user.h | 4 ++++ net/vhost-user.c | 23 ++++++++++++++++++++--- 6 files changed, 83 insertions(+), 7 deletions(-) diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 5e81f2f..59e826e 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -10,7 +10,7 @@ obj-$(CONFIG_LINUX) +=3D vhost.o vhost-backend.o vhost-us= er.o obj-$(CONFIG_VHOST_VSOCK) +=3D vhost-vsock.o obj-y +=3D virtio-crypto.o obj-$(CONFIG_VIRTIO_PCI) +=3D virtio-crypto-pci.o -endif - +else common-obj-$(call lnot,$(CONFIG_LINUX)) +=3D vhost-stub.o -common-obj-$(CONFIG_ALL) +=3D vhost-stub.o +common-obj-y +=3D vhost-stub.o +endif diff --git a/hw/virtio/vhost-stub.c b/hw/virtio/vhost-stub.c index 2d76cde..e130791 100644 --- a/hw/virtio/vhost-stub.c +++ b/hw/virtio/vhost-stub.c @@ -1,7 +1,18 @@ #include "qemu/osdep.h" #include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" =20 bool vhost_has_free_slot(void) { return true; } + +void vhost_user_asyn_read(void *opaque, const uint8_t *buf, int size) +{ + return; +} + +int vhost_user_can_read(void *opaque) +{ + return 0; +} diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index ca8fe36..5d55ea1 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -14,7 +14,7 @@ #include "hw/virtio/vhost-backend.h" #include "hw/virtio/vhost-user.h" #include "hw/virtio/virtio-net.h" -#include "sysemu/char.h" +#include "net/vhost-user.h" #include "sysemu/kvm.h" #include "qemu/error-report.h" #include "qemu/sockets.h" @@ -75,6 +75,46 @@ fail: return -1; } =20 +int vhost_user_can_read(void *opaque) +{ + return VHOST_USER_HDR_SIZE; +} + +void vhost_user_asyn_read(void *opaque, const uint8_t *buf, int size) +{ + const char *name =3D opaque; + VhostUserMsg msg; + uint8_t *p =3D (uint8_t *) &msg; + CharBackend *chr_be =3D net_name_to_chr_be(name); + + 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 %d !=3D %d", __func__, + size, msg.size); + return; + } + } + + if (msg.request > VHOST_USER_MAX) { + error_report("%s:incorrect msg %d", __func__, msg.request); + } + + switch (msg.request) { + default: + error_report("%s: does not support msg %d", __func__, msg.request); + break; + } +} + static int process_message_reply(struct vhost_dev *dev, VhostUserRequest request) { diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index 1fccbe2..eae5431 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -103,4 +103,8 @@ static VhostUserMsg m __attribute__ ((unused)); /* The version of the protocol we support */ #define VHOST_USER_VERSION (0x1) =20 +int vhost_user_can_read(void *opaque); + +void vhost_user_asyn_read(void *opaque, const uint8_t *buf, int size); + #endif diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h index d9e328d..1bb5f1a 100644 --- a/include/net/vhost-user.h +++ b/include/net/vhost-user.h @@ -11,8 +11,12 @@ #ifndef NET_VHOST_USER_H #define NET_VHOST_USER_H =20 +#include "sysemu/char.h" + struct vhost_net; struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc); uint64_t vhost_user_get_acked_features(NetClientState *nc); =20 +CharBackend *net_name_to_chr_be(const char *name); + #endif /* VHOST_USER_H */ diff --git a/net/vhost-user.c b/net/vhost-user.c index e7e6340..91ee146 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -12,7 +12,7 @@ #include "clients.h" #include "net/vhost_net.h" #include "net/vhost-user.h" -#include "sysemu/char.h" +#include "hw/virtio/vhost-user.h" #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qmp-commands.h" @@ -221,6 +221,22 @@ static void chr_closed_bh(void *opaque) } } =20 +CharBackend *net_name_to_chr_be(const char *name) +{ + NetClientState *ncs[MAX_QUEUE_NUM]; + VhostUserState *s; + int queues; + + queues =3D qemu_find_net_clients_except(name, ncs, + NET_CLIENT_DRIVER_NIC, + MAX_QUEUE_NUM); + assert(queues < MAX_QUEUE_NUM); + + s =3D DO_UPCAST(VhostUserState, nc, ncs[0]); + + return &s->chr; +} + static void net_vhost_user_event(void *opaque, int event) { const char *name =3D opaque; @@ -307,8 +323,9 @@ static int net_vhost_user_init(NetClientState *peer, co= nst char *device, error_report_err(err); return -1; } - qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, - net_vhost_user_event, nc0->name, NULL, tr= ue); + qemu_chr_fe_set_handlers(&s->chr, vhost_user_can_read, + vhost_user_asyn_read, net_vhost_user_even= t, + nc0->name, NULL, true); } while (!s->started); =20 assert(s->vhost_net); --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494579279163116.49337279846077; Fri, 12 May 2017 01:54:39 -0700 (PDT) Received: from localhost ([::1]:52126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96LN-0008W1-Ke for importer@patchew.org; Fri, 12 May 2017 04:54:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968x-0005oK-70 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968v-00020Q-OI for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:47 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968v-0001je-Cc for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:45 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:44 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616294" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:44 +0800 Message-Id: <1494578148-102868-13-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 12/16] vhost-user: handling VHOST_USER_SET_FEATURES 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: Wei Wang 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" If the featuer bits sent by the slave are not equal to the ones that were sent by the master, perform a reset of the master device. Signed-off-by: Wei Wang --- hw/net/vhost_net.c | 2 ++ hw/virtio/vhost-user.c | 24 ++++++++++++++++++++++++ hw/virtio/virtio-pci.c | 20 ++++++++++++++++++++ hw/virtio/virtio-pci.h | 2 ++ include/net/vhost-user.h | 14 ++++++++++++++ net/vhost-user.c | 14 +++++--------- 6 files changed, 67 insertions(+), 9 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 0a5278d..7609083 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -352,6 +352,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, } } =20 + vhost_user_set_master_dev(ncs[0].peer, dev); + return 0; =20 err_start: diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 5d55ea1..1a34048 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/virtio-pci.h" #include "hw/virtio/vhost-user.h" #include "hw/virtio/virtio-net.h" #include "net/vhost-user.h" @@ -75,6 +76,26 @@ fail: return -1; } =20 +static void handle_slave_acked_features(const char *name, VhostUserMsg *ms= g) +{ + CharBackend *chr_be =3D net_name_to_chr_be(name); + VhostUserState *s =3D container_of(chr_be, VhostUserState, chr); + VirtIODevice *vdev =3D s->vdev; + uint64_t master_features, slave_features; + + master_features =3D vhost_net_get_acked_features(s->vhost_net) & + ~(1 << VHOST_USER_F_PROTOCOL_FEATURES); + slave_features =3D msg->payload.u64; + + /* + * It is a rare case: vhost-pci driver only accepted a subset of the + * feature bits. In this case, reset the virtio device. + */ + if (master_features !=3D slave_features) { + master_reset_virtio_net(vdev); + } +} + int vhost_user_can_read(void *opaque) { return VHOST_USER_HDR_SIZE; @@ -109,6 +130,9 @@ void vhost_user_asyn_read(void *opaque, const uint8_t *= buf, int size) } =20 switch (msg.request) { + case VHOST_USER_SET_FEATURES: + handle_slave_acked_features(name, &msg); + break; default: error_report("%s: does not support msg %d", __func__, msg.request); break; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 3f1a198..0677496 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -37,6 +37,7 @@ #include "qemu/range.h" #include "hw/virtio/virtio-bus.h" #include "qapi/visitor.h" +#include "monitor/qdev.h" =20 #define VIRTIO_PCI_REGION_SIZE(dev) VIRTIO_PCI_CONFIG_OFF(msix_present= (dev)) =20 @@ -2327,6 +2328,25 @@ static const TypeInfo virtio_serial_pci_info =3D { =20 /* virtio-net-pci */ =20 +void master_reset_virtio_net(VirtIODevice *vdev) +{ + VirtIONet *net =3D VIRTIO_NET(vdev); + VirtIONetPCI *net_pci =3D container_of(net, VirtIONetPCI, vdev); + VirtIOPCIProxy *proxy =3D &net_pci->parent_obj; + DeviceState *qdev =3D DEVICE(proxy); + DeviceState *qdev_new; + Error *err =3D NULL; + + virtio_pci_reset(qdev); + qdev_unplug(qdev, &err); + qdev->realized =3D false; + qdev_new =3D qdev_device_add(qdev->opts, &err); + if (!qdev_new) { + qemu_opts_del(qdev->opts); + } + object_unref(OBJECT(qdev)); +} + static Property virtio_net_properties[] =3D { DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 6ffacd9..fa8a671 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -399,4 +399,6 @@ struct VirtIOCryptoPCI { /* Virtio ABI version, if we increment this, we break the guest driver. */ #define VIRTIO_PCI_ABI_VERSION 0 =20 +void master_reset_virtio_net(VirtIODevice *vdev); + #endif diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h index 1bb5f1a..4cd14c9 100644 --- a/include/net/vhost-user.h +++ b/include/net/vhost-user.h @@ -12,6 +12,18 @@ #define NET_VHOST_USER_H =20 #include "sysemu/char.h" +#include "net/vhost_net.h" + +typedef struct VhostUserState { + NetClientState nc; + CharBackend chr; /* only queue index 0 */ + VHostNetState *vhost_net; + guint watch; + uint64_t acked_features; + bool started; + /* Pointer to the master device */ + VirtIODevice *vdev; +} VhostUserState; =20 struct vhost_net; struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc); @@ -19,4 +31,6 @@ uint64_t vhost_user_get_acked_features(NetClientState *nc= ); =20 CharBackend *net_name_to_chr_be(const char *name); =20 +void vhost_user_set_master_dev(NetClientState *nc, VirtIODevice *vdev); + #endif /* VHOST_USER_H */ diff --git a/net/vhost-user.c b/net/vhost-user.c index 91ee146..7c7707a 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -10,7 +10,6 @@ =20 #include "qemu/osdep.h" #include "clients.h" -#include "net/vhost_net.h" #include "net/vhost-user.h" #include "hw/virtio/vhost-user.h" #include "qemu/config-file.h" @@ -18,14 +17,11 @@ #include "qmp-commands.h" #include "trace.h" =20 -typedef struct VhostUserState { - NetClientState nc; - CharBackend chr; /* only queue index 0 */ - VHostNetState *vhost_net; - guint watch; - uint64_t acked_features; - bool started; -} VhostUserState; +void vhost_user_set_master_dev(NetClientState *nc, VirtIODevice *vdev) +{ + VhostUserState *s =3D DO_UPCAST(VhostUserState, nc, nc); + s->vdev =3D vdev; +} =20 VHostNetState *vhost_user_get_vhost_net(NetClientState *nc) { --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494579405285667.7395841658121; Fri, 12 May 2017 01:56:45 -0700 (PDT) Received: from localhost ([::1]:52152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96NQ-0001ht-0R for importer@patchew.org; Fri, 12 May 2017 04:56:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44985) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d968y-0005pj-Qy for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d968x-00022D-Dm for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:48 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d968x-0001je-33 for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:47 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:46 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616299" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:45 +0800 Message-Id: <1494578148-102868-14-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 13/16] vhost-pci-slave: add "reset_virtio" 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: Wei Wang 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" After the vhost-pci-net device being hotplugged to the VM, the device uses the features bits that have been negotiated with the remote virtio device to negotiate with the driver. If the driver accepts a subset of the feature bits, it implies that the vhost-pci-net can only suppoort a subset of the features supported by the remote virtio device. In this case, the remote virtio_device will be reset, and re-start the vhost-user protocol. Add the "reset_virtio" field as an indicator to the slave in this case. Signed-off-by: Wei Wang --- hw/net/vhost-pci-net.c | 11 +++++++++++ hw/virtio/vhost-pci-slave.c | 15 +++++++++++++-- include/hw/virtio/vhost-pci-slave.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c index 1379204..a2dca50 100644 --- a/hw/net/vhost-pci-net.c +++ b/hw/net/vhost-pci-net.c @@ -189,8 +189,19 @@ static void vpnet_set_features(VirtIODevice *vdev, uin= t64_t features) */ static bool need_send; int ret; + VhostPCIDev *vp_dev =3D get_vhost_pci_dev(); =20 if (need_send) { + /* + * If the remote negotiated feature bits are not equal to the + * feature bits that have been negotiated between the device and + * driver, the remote virtio device needs a reset. Set reset_virtio + * to indicate to the slave about this case. + */ + if (vp_dev->feature_bits !=3D features) { + vp_dev->feature_bits =3D features; + vp_dev->reset_virtio =3D 1; + } need_send =3D 0; ret =3D vp_slave_send_feature_bits(features); if (ret < 0) { diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c index 6cc9c21..a7d3c8d 100644 --- a/hw/virtio/vhost-pci-slave.c +++ b/hw/virtio/vhost-pci-slave.c @@ -171,8 +171,15 @@ static void vp_slave_set_device_type(VhostUserMsg *msg) =20 switch (vp_dev->dev_type) { case VIRTIO_ID_NET: - vp_dev->feature_bits |=3D VHOST_PCI_FEATURE_BITS | - VHOST_PCI_NET_FEATURE_BITS; + /* + * The setting of reset_virtio implies that the feature_bits has b= een + * remotely negotiated. So, skip adding the supported features to + * feature_bits in this case. + */ + if (!vp_dev->reset_virtio) { + vp_dev->feature_bits |=3D VHOST_PCI_FEATURE_BITS | + VHOST_PCI_NET_FEATURE_BITS; + } break; default: error_report("%s: device type %d is not supported", @@ -400,6 +407,9 @@ static int vp_slave_set_vhost_pci(VhostUserMsg *msg) =20 switch (cmd) { case VHOST_USER_SET_VHOST_PCI_START: + if (vp_dev->reset_virtio) { + vp_dev->reset_virtio =3D 0; + } ret =3D vp_slave_device_create(vp_dev->dev_type); if (ret < 0) { return ret; @@ -585,6 +595,7 @@ static void vp_dev_init(VhostPCIDev *vp_dev) vp_dev->vdev =3D NULL; QLIST_INIT(&vp_dev->remoteq_list); vp_dev->remoteq_num =3D 0; + vp_dev->reset_virtio =3D 0; } =20 int vhost_pci_slave_init(QemuOpts *opts) diff --git a/include/hw/virtio/vhost-pci-slave.h b/include/hw/virtio/vhost-= pci-slave.h index ab21e70..594917f 100644 --- a/include/hw/virtio/vhost-pci-slave.h +++ b/include/hw/virtio/vhost-pci-slave.h @@ -29,6 +29,7 @@ typedef struct RemoteMem { typedef struct VhostPCIDev { /* Ponnter to the slave device */ VirtIODevice *vdev; + bool reset_virtio; uint16_t dev_type; uint64_t feature_bits; /* Records the end (offset to the BAR) of the last mapped region */ --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494579029046560.0286505884129; Fri, 12 May 2017 01:50:29 -0700 (PDT) Received: from localhost ([::1]:52108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96HL-0004ud-Hb for importer@patchew.org; Fri, 12 May 2017 04:50:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9691-0005sF-Dp for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9690-00025D-Ha for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:51 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d9690-0001je-8t for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:50 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:49 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616313" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:46 +0800 Message-Id: <1494578148-102868-15-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 14/16] vhost-pci-slave: add support to delete a vhost-pci 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: Wei Wang 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" Signed-off-by: Wei Wang --- hw/virtio/vhost-pci-slave.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/hw/virtio/vhost-pci-slave.c b/hw/virtio/vhost-pci-slave.c index a7d3c8d..cde122c 100644 --- a/hw/virtio/vhost-pci-slave.c +++ b/hw/virtio/vhost-pci-slave.c @@ -139,6 +139,42 @@ static int vp_slave_send_u64(int request, uint64_t u64) return 0; } =20 +static DeviceState *virtio_to_pci_dev(VirtIODevice *vdev, uint16_t virtio_= id) +{ + DeviceState *qdev =3D NULL; + VhostPCINet *vpnet; + VhostPCINetPCI *netpci; + + if (!vdev) { + return NULL; + } + + switch (virtio_id) { + case VIRTIO_ID_NET: + vpnet =3D VHOST_PCI_NET(vdev); + netpci =3D container_of(vpnet, VhostPCINetPCI, vdev); + qdev =3D &netpci->parent_obj.pci_dev.qdev; + break; + default: + error_report("virtio_to_pci_dev: device type %d not supported", + virtio_id); + } + + return qdev; +} + +static void vp_slave_device_del(VirtIODevice *vdev) +{ + Error *errp =3D NULL; + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + DeviceState *qdev =3D virtio_to_pci_dev(vdev, vp_dev->dev_type); + + if (qdev !=3D NULL) { + qdev_unplug(qdev, &errp); + vp_dev_cleanup(); + } +} + int vp_slave_send_feature_bits(uint64_t features) { return vp_slave_send_u64(VHOST_USER_SET_FEATURES, features); @@ -146,10 +182,13 @@ int vp_slave_send_feature_bits(uint64_t features) =20 static void vp_slave_event(void *opaque, int event) { + VhostPCIDev *vp_dev =3D vp_slave->vp_dev; + switch (event) { case CHR_EVENT_OPENED: break; case CHR_EVENT_CLOSED: + vp_slave_device_del(vp_dev->vdev); break; } } @@ -416,6 +455,8 @@ static int vp_slave_set_vhost_pci(VhostUserMsg *msg) } break; case VHOST_USER_SET_VHOST_PCI_STOP: + vp_slave_device_del(vp_dev->vdev); + ret =3D 0; break; default: error_report("%s: cmd %d not supported", __func__, cmd); --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 1494579167805986.2274925864928; Fri, 12 May 2017 01:52:47 -0700 (PDT) Received: from localhost ([::1]:52117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96Ja-0006ua-JN for importer@patchew.org; Fri, 12 May 2017 04:52:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9693-0005to-5a for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9692-00028D-6R for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:53 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d9691-0001je-UF for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:52 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:51 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616321" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:47 +0800 Message-Id: <1494578148-102868-16-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 15/16] vhost-pci-net: tell the driver that it is ready to send packets 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: Wei Wang 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" If the remote device on the other side doesn't need to be reset, set bit 0 of the device status register to allow the driver to send out the packets. Signed-off-by: Wei Wang --- hw/net/vhost-pci-net.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/net/vhost-pci-net.c b/hw/net/vhost-pci-net.c index a2dca50..513a7ff 100644 --- a/hw/net/vhost-pci-net.c +++ b/hw/net/vhost-pci-net.c @@ -130,6 +130,20 @@ static inline uint16_t rx2tx(uint16_t id) return id - 1; } =20 +static void vpnet_set_link_up(VhostPCINet *vpnet) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(vpnet); + uint16_t old_status =3D vpnet->status; + + /* + * Set the LINK_UP status bit and notify the driver that it can send + * packets. + */ + vpnet->status |=3D VPNET_S_LINK_UP; + if (vpnet->status !=3D old_status) + virtio_notify_config(vdev); +} + static void vpnet_set_status(struct VirtIODevice *vdev, uint8_t status) { VhostPCINet *vpnet =3D VHOST_PCI_NET(vdev); @@ -137,6 +151,7 @@ static void vpnet_set_status(struct VirtIODevice *vdev,= uint8_t status) BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + VhostPCIDev *vp_dev =3D get_vhost_pci_dev(); VirtQueue *vq; int r, i; =20 @@ -164,6 +179,11 @@ static void vpnet_set_status(struct VirtIODevice *vdev= , uint8_t status) } vpnet_send_ctrlq_msg_remote_mem(vpnet); vpnet_send_ctrlq_msg_remoteq(vpnet); + /* If the peer device is not reset, start the device now */ + if (!vp_dev->reset_virtio) { + vdev->status =3D status; + vpnet_set_link_up(vpnet); + } } } =20 --=20 2.7.4 From nobody Fri May 3 12:01:33 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.zoho.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 14945792143001016.9702267679049; Fri, 12 May 2017 01:53:34 -0700 (PDT) Received: from localhost ([::1]:52120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d96KL-0007bA-08 for importer@patchew.org; Fri, 12 May 2017 04:53:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9697-0005xh-Aw for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9693-0002BZ-UX for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:57 -0400 Received: from mga11.intel.com ([192.55.52.93]:62480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d9693-0001je-KI for qemu-devel@nongnu.org; Fri, 12 May 2017 04:41:53 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2017 01:41:53 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.105]) by orsmga003.jf.intel.com with ESMTP; 12 May 2017 01:41:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,328,1491289200"; d="scan'208";a="967616328" From: Wei Wang To: stefanha@gmail.com, marcandre.lureau@gmail.com, mst@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:35:48 +0800 Message-Id: <1494578148-102868-17-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494578148-102868-1-git-send-email-wei.w.wang@intel.com> References: <1494578148-102868-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.93 Subject: [Qemu-devel] [PATCH v2 16/16] vl: enable vhost-pci-slave 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: Wei Wang 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" Enable the use of vhost-pci. The init and cleanup stub functions are added for the platforms that do not support the use of virtio. Signed-off-by: Wei Wang --- hw/virtio/vhost-stub.c | 11 +++++++++++ vl.c | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/hw/virtio/vhost-stub.c b/hw/virtio/vhost-stub.c index e130791..bfb73df 100644 --- a/hw/virtio/vhost-stub.c +++ b/hw/virtio/vhost-stub.c @@ -1,6 +1,7 @@ #include "qemu/osdep.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" +#include "hw/virtio/vhost-pci-slave.h" =20 bool vhost_has_free_slot(void) { @@ -16,3 +17,13 @@ int vhost_user_can_read(void *opaque) { return 0; } + +int vhost_pci_slave_init(QemuOpts *opt) +{ + return -1; +} + +int vhost_pci_slave_cleanup(void) +{ + return -1; +} diff --git a/vl.c b/vl.c index 2ee4713..18102d7 100644 --- a/vl.c +++ b/vl.c @@ -129,6 +129,7 @@ int main(int argc, char **argv) #include "sysemu/replay.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" +#include "hw/virtio/vhost-pci-slave.h" =20 #define MAX_VIRTIO_CONSOLES 1 #define MAX_SCLP_CONSOLES 1 @@ -187,6 +188,7 @@ uint8_t *boot_splash_filedata; size_t boot_splash_filedata_size; uint8_t qemu_extra_params_fw[2]; int only_migratable; /* turn it off unless user states otherwise */ +bool vhost_pci_slave_enabled; =20 int icount_align_option; =20 @@ -4060,6 +4062,7 @@ int main(int argc, char **argv, char **envp) if (!opts) { exit(1); } + vhost_pci_slave_enabled =3D true; break; default: os_parse_cmd_args(popt->index, optarg); @@ -4591,6 +4594,18 @@ int main(int argc, char **argv, char **envp) exit(1); } =20 + /* check if the vhost-pci-server is enabled */ + if (vhost_pci_slave_enabled) { + int ret; + ret =3D vhost_pci_slave_init(qemu_opts_find( + qemu_find_opts("vhost-pci-slave"), + NULL)); + if (ret < 0) { + error_report("vhost-pci-slave init failed"); + exit(1); + } + } + /* init USB devices */ if (machine_usb(current_machine)) { if (foreach_device_config(DEV_USB, usb_parse) < 0) @@ -4736,6 +4751,15 @@ int main(int argc, char **argv, char **envp) pause_all_vcpus(); res_free(); =20 + if (vhost_pci_slave_enabled) { + int ret; + ret =3D vhost_pci_slave_cleanup(); + if (ret < 0) { + error_report("vhost-pci-slave init failed"); + exit(1); + } + } + /* vhost-user must be cleaned up before chardevs. */ net_cleanup(); audio_cleanup(); --=20 2.7.4