From patchwork Thu Nov 10 02:47:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Wei W" X-Patchwork-Id: 9420515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A6CE0601C2 for ; Thu, 10 Nov 2016 02:48:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94ABD29483 for ; Thu, 10 Nov 2016 02:48:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8918629485; Thu, 10 Nov 2016 02:48:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E3C4129483 for ; Thu, 10 Nov 2016 02:48:20 +0000 (UTC) Received: from localhost ([::1]:43539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4fPY-0003fj-6G for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 Nov 2016 21:48:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4fP5-0003eY-TM for qemu-devel@nongnu.org; Wed, 09 Nov 2016 21:47:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4fP4-0006AB-Lt for qemu-devel@nongnu.org; Wed, 09 Nov 2016 21:47:51 -0500 Received: from mga05.intel.com ([192.55.52.43]:42985) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c4fP4-00069P-E5 for qemu-devel@nongnu.org; Wed, 09 Nov 2016 21:47:50 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP; 09 Nov 2016 18:47:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,616,1473145200"; d="scan'208"; a="1066457953" Received: from devel-ww.sh.intel.com ([10.239.48.106]) by fmsmga001.fm.intel.com with ESMTP; 09 Nov 2016 18:47:48 -0800 From: Wei Wang To: marcandre.lureau@gmail.com, mst@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org Date: Wed, 9 Nov 2016 21:47:49 -0500 Message-Id: <1478746069-79574-5-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478746069-79574-1-git-send-email-wei.w.wang@intel.com> References: <1478746069-79574-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.43 Subject: [Qemu-devel] [RFC PATCH 4/4] vhost-user: extend the vhost-user Master (client) part 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Wei Wang --- hw/net/vhost_net.c | 20 ++++++++++++ hw/virtio/vhost-user.c | 66 +++++++++++++++++++++++++++++++++++++++ include/hw/virtio/vhost-backend.h | 3 ++ include/net/vhost_net.h | 5 +++ 4 files changed, 94 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index f2d49ad..100349b 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -337,6 +337,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } } + vhost_set_peer_connection(ncs[i-1].peer, + VHOST_USER_SET_PEER_CONNECTION_INIT); + return 0; err_start: @@ -435,6 +438,18 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) return 0; } +int vhost_set_peer_connection(NetClientState *nc, uint64_t cmd) +{ + VHostNetState *net = get_vhost_net(nc); + const VhostOps *vhost_ops = net->dev.vhost_ops; + + if (vhost_ops && vhost_ops->vhost_set_peer_connection) { + return vhost_ops->vhost_set_peer_connection(&net->dev, cmd); + } + + return 0; +} + #else uint64_t vhost_net_get_max_queues(VHostNetState *net) { @@ -501,4 +516,9 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) { return 0; } + +int vhost_set_peer_connection(NetClientState *nc, uint64_t cmd) +{ + return 0; +} #endif diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index bce5181..6edf7f2 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -124,6 +124,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, return 0; } + msg->conn_id = chr->conn_id; + if (qemu_chr_fe_set_msgfds(chr, fds, fd_num) < 0) { error_report("Failed to set msg fds."); return -1; @@ -313,6 +315,22 @@ static int vhost_user_set_vring_enable(struct vhost_dev *dev, int enable) return 0; } +static int vhost_user_set_peer_connection(struct vhost_dev *dev, uint64_t cmd) +{ + VhostUserMsg msg = { + .request = VHOST_USER_SET_PEER_CONNECTION, + .flags = VHOST_USER_VERSION, + .payload.u64 = cmd, + .size = 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) { @@ -448,6 +466,28 @@ static int vhost_user_get_u64(struct vhost_dev *dev, int request, uint64_t *u64) return 0; } +static bool vhost_user_need_conn_id(struct vhost_dev *dev) +{ + CharDriverState *chr = dev->opaque; + + if(chr->conn_id == ANONYMOUS_CLIENT) + return 1; + else + return 0; +} + +static int vhost_user_get_conn_id(struct vhost_dev *dev) +{ + int ret; + uint64_t conn_id; + CharDriverState *chr = dev->opaque; + + ret = vhost_user_get_u64(dev, VHOST_USER_GET_CONN_ID, &conn_id); + if (!ret) + chr->conn_id = conn_id; + return ret; +} + static int vhost_user_get_features(struct vhost_dev *dev, uint64_t *features) { return vhost_user_get_u64(dev, VHOST_USER_GET_FEATURES, features); @@ -481,6 +521,18 @@ static int vhost_user_reset_device(struct vhost_dev *dev) return 0; } +static int vhost_user_set_dev_info(struct vhost_dev *dev, uint16_t virtio_id) +{ + VhostUserMsg msg = { + .request = VHOST_USER_SET_DEV_INFO, + .flags = VHOST_USER_VERSION, + .payload.dev_info.virtio_id = virtio_id, + .size = sizeof(msg.payload.dev_info), + }; + + return vhost_user_write(dev, &msg, NULL, 0); +} + static int vhost_user_init(struct vhost_dev *dev, void *opaque) { uint64_t features; @@ -489,6 +541,12 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque) assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER); dev->opaque = opaque; + if (vhost_user_need_conn_id(dev)) { + err = vhost_user_get_conn_id(dev); + if (err < 0) { + return err; + } + } err = vhost_user_get_features(dev, &features); if (err < 0) { @@ -510,6 +568,13 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque) return err; } + if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_VHOST_PCI)) { + err = vhost_user_set_dev_info(dev, VIRTIO_ID_NET); + if (err < 0) { + return err; + } + } + /* query the max queues we support if backend supports Multiple Queue */ if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) { err = vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, @@ -621,6 +686,7 @@ const VhostOps user_ops = { .vhost_reset_device = vhost_user_reset_device, .vhost_get_vq_index = vhost_user_get_vq_index, .vhost_set_vring_enable = vhost_user_set_vring_enable, + .vhost_set_peer_connection = vhost_user_set_peer_connection, .vhost_requires_shm_log = vhost_user_requires_shm_log, .vhost_migration_done = vhost_user_migration_done, .vhost_backend_can_merge = vhost_user_can_merge, diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index cf7f0b5..955dea6 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -67,6 +67,8 @@ typedef int (*vhost_reset_device_op)(struct vhost_dev *dev); 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_peer_connection_op)(struct vhost_dev *dev, + uint64_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); @@ -99,6 +101,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_peer_connection_op vhost_set_peer_connection; 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 5a08eff..baa5a34 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -33,6 +33,11 @@ VHostNetState *get_vhost_net(NetClientState *nc); int vhost_set_vring_enable(NetClientState * nc, int enable); +#define VHOST_USER_SET_PEER_CONNECTION_OFF 0 +#define VHOST_USER_SET_PEER_CONNECTION_ON 1 +#define VHOST_USER_SET_PEER_CONNECTION_INIT 2 +int vhost_set_peer_connection(NetClientState *nc, uint64_t cmd); + uint64_t vhost_net_get_acked_features(VHostNetState *net); #endif