Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/6742/?format=api
https://patches.dpdk.org/api/patches/6742/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1439366567-3402-7-git-send-email-changchun.ouyang@intel.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1439366567-3402-7-git-send-email-changchun.ouyang@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1439366567-3402-7-git-send-email-changchun.ouyang@intel.com", "date": "2015-08-12T08:02:41", "name": "[dpdk-dev,v4,06/12] vhost: support protocol feature", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "93ef2aac59b7dd530abd3d8ebf2390a1da6986d6", "submitter": { "id": 31, "url": "https://patches.dpdk.org/api/people/31/?format=api", "name": "Ouyang Changchun", "email": "changchun.ouyang@intel.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1439366567-3402-7-git-send-email-changchun.ouyang@intel.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/6742/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/6742/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id A711E8D97;\n\tWed, 12 Aug 2015 10:03:17 +0200 (CEST)", "from mga01.intel.com (mga01.intel.com [192.55.52.88])\n\tby dpdk.org (Postfix) with ESMTP id 163C98D8C\n\tfor <dev@dpdk.org>; Wed, 12 Aug 2015 10:03:14 +0200 (CEST)", "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby fmsmga101.fm.intel.com with ESMTP; 12 Aug 2015 01:03:14 -0700", "from shvmail01.sh.intel.com ([10.239.29.42])\n\tby orsmga002.jf.intel.com with ESMTP; 12 Aug 2015 01:03:14 -0700", "from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com\n\t[10.239.29.89])\n\tby shvmail01.sh.intel.com with ESMTP id t7C83A38027083;\n\tWed, 12 Aug 2015 16:03:10 +0800", "from shecgisg004.sh.intel.com (localhost [127.0.0.1])\n\tby shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP\n\tid t7C838BP003668; Wed, 12 Aug 2015 16:03:10 +0800", "(from couyang@localhost)\n\tby shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t7C838Hh003664; \n\tWed, 12 Aug 2015 16:03:08 +0800" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.15,659,1432623600\"; d=\"scan'208\";a=\"782522634\"", "From": "Ouyang Changchun <changchun.ouyang@intel.com>", "To": "dev@dpdk.org", "Date": "Wed, 12 Aug 2015 16:02:41 +0800", "Message-Id": "<1439366567-3402-7-git-send-email-changchun.ouyang@intel.com>", "X-Mailer": "git-send-email 1.7.12.2", "In-Reply-To": "<1439366567-3402-1-git-send-email-changchun.ouyang@intel.com>", "References": "<1434355006-30583-1-git-send-email-changchun.ouyang@intel.com>\n\t<1439366567-3402-1-git-send-email-changchun.ouyang@intel.com>", "Subject": "[dpdk-dev] [PATCH v4 06/12] vhost: support protocol feature", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "patches and discussions about DPDK <dev.dpdk.org>", "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://dpdk.org/ml/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "Support new protocol feature to communicate with qemu:\nAdd set and get protocol feature bits;\nAdd VRING_FLAG for mq feature to set vring flag, which\nindicates the vq is enabled or disabled.\n\nReserve values as follows:\nVHOST_USER_SEND_RARP = 17 (merge from qemu community)\nVHOST_USER_SET_VRING_FLAG = 18 (reserve for vhost mq)\n\nThese reservation need sync up with qemu community before finalizing.\n\nSigned-off-by: Changchun Ouyang <changchun.ouyang@intel.com>\n---\nThis is added since v4.\n\n lib/librte_vhost/rte_virtio_net.h | 2 +\n lib/librte_vhost/vhost-net.h | 3 ++\n lib/librte_vhost/vhost_rxtx.c | 21 ++++++++++\n lib/librte_vhost/vhost_user/vhost-net-user.c | 21 +++++++++-\n lib/librte_vhost/vhost_user/vhost-net-user.h | 4 ++\n lib/librte_vhost/vhost_user/virtio-net-user.c | 29 ++++++++++++++\n lib/librte_vhost/vhost_user/virtio-net-user.h | 2 +\n lib/librte_vhost/virtio-net.c | 56 ++++++++++++++++++++++++++-\n lib/librte_vhost/virtio-net.h | 2 +\n 9 files changed, 138 insertions(+), 2 deletions(-)", "diff": "diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h\nindex 8520d96..e16ad3a 100644\n--- a/lib/librte_vhost/rte_virtio_net.h\n+++ b/lib/librte_vhost/rte_virtio_net.h\n@@ -88,6 +88,7 @@ struct vhost_virtqueue {\n \tvolatile uint16_t\tlast_used_idx_res;\t/**< Used for multiple devices reserving buffers. */\n \teventfd_t\t\tcallfd;\t\t\t/**< Used to notify the guest (trigger interrupt). */\n \teventfd_t\t\tkickfd;\t\t\t/**< Currently unused as polling mode is enabled. */\n+\tuint32_t\t\tenabled;\t\t/**< Indicate the queue is enabled or not. */\n \tstruct buf_vector\tbuf_vec[BUF_VECTOR_MAX];\t/**< for scatter RX. */\n } __rte_cache_aligned;\n \n@@ -98,6 +99,7 @@ struct virtio_net {\n \tstruct vhost_virtqueue\t**virtqueue; /**< Contains all virtqueue information. */\n \tstruct virtio_memory **mem_arr; /**< Array for QEMU memory and memory region information. */\n \tuint64_t\t\tfeatures;\t/**< Negotiated feature set. */\n+\tuint64_t\t\tprotocol_features;\t/**< Negotiated protocol feature set. */\n \tuint64_t\t\tdevice_fh;\t/**< device identifier. */\n \tuint32_t\t\tflags;\t\t/**< Device flags. Only used to check if device is running on data core. */\n #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)\ndiff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h\nindex 7dff14d..bc88bad 100644\n--- a/lib/librte_vhost/vhost-net.h\n+++ b/lib/librte_vhost/vhost-net.h\n@@ -99,6 +99,9 @@ struct vhost_net_device_ops {\n \tint (*get_features)(struct vhost_device_ctx, uint64_t *);\n \tint (*set_features)(struct vhost_device_ctx, uint64_t *);\n \n+\tint (*get_protocol_features)(struct vhost_device_ctx, uint64_t *);\n+\tint (*set_protocol_features)(struct vhost_device_ctx, uint64_t *);\n+\n \tint (*set_vring_num)(struct vhost_device_ctx, struct vhost_vring_state *);\n \tint (*set_vring_addr)(struct vhost_device_ctx, struct vhost_vring_addr *);\n \tint (*set_vring_base)(struct vhost_device_ctx, struct vhost_vring_state *);\ndiff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c\nindex a60b542..3af0326 100644\n--- a/lib/librte_vhost/vhost_rxtx.c\n+++ b/lib/librte_vhost/vhost_rxtx.c\n@@ -89,6 +89,14 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,\n \t}\n \n \tvq = dev->virtqueue[queue_id];\n+\n+\tif (unlikely(vq->enabled == 0)) {\n+\t\tRTE_LOG(ERR, VHOST_DATA,\n+\t\t\t\"%s (%\"PRIu64\"): virtqueue idx:%d not enabled.\\n\",\n+\t\t\t __func__, dev->device_fh, queue_id);\n+\t\treturn 0;\n+\t}\n+\n \tcount = (count > MAX_PKT_BURST) ? MAX_PKT_BURST : count;\n \n \t/*\n@@ -281,6 +289,7 @@ copy_from_mbuf_to_vring(struct virtio_net *dev, uint16_t queue_id,\n \t * (guest physical addr -> vhost virtual addr)\n \t */\n \tvq = dev->virtqueue[queue_id];\n+\n \tvb_addr = gpa_to_vva(dev, queue_id / VIRTIO_QNUM,\n \t\t\tvq->buf_vec[vec_idx].buf_addr);\n \tvb_hdr_addr = vb_addr;\n@@ -491,6 +500,14 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,\n \t}\n \n \tvq = dev->virtqueue[queue_id];\n+\n+\tif (unlikely(vq->enabled == 0)) {\n+\t\tRTE_LOG(ERR, VHOST_DATA,\n+\t\t\t\"%s (%\"PRIu64\"): virtqueue idx:%d not enabled.\\n\",\n+\t\t\t __func__, dev->device_fh, queue_id);\n+\t\treturn 0;\n+\t}\n+\n \tcount = RTE_MIN((uint32_t)MAX_PKT_BURST, count);\n \n \tif (count == 0)\n@@ -590,6 +607,10 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,\n \t}\n \n \tvq = dev->virtqueue[queue_id];\n+\n+\tif (unlikely(vq->enabled == 0))\n+\t\treturn 0;\n+\n \tavail_idx = *((volatile uint16_t *)&vq->avail->idx);\n \n \t/* If there are no available buffers then return. */\ndiff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c\nindex e926ed7..f7a24e9 100644\n--- a/lib/librte_vhost/vhost_user/vhost-net-user.c\n+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c\n@@ -95,7 +95,11 @@ static const char *vhost_message_str[VHOST_USER_MAX] = {\n \t[VHOST_USER_GET_VRING_BASE] = \"VHOST_USER_GET_VRING_BASE\",\n \t[VHOST_USER_SET_VRING_KICK] = \"VHOST_USER_SET_VRING_KICK\",\n \t[VHOST_USER_SET_VRING_CALL] = \"VHOST_USER_SET_VRING_CALL\",\n-\t[VHOST_USER_SET_VRING_ERR] = \"VHOST_USER_SET_VRING_ERR\"\n+\t[VHOST_USER_SET_VRING_ERR] = \"VHOST_USER_SET_VRING_ERR\",\n+\t[VHOST_USER_GET_PROTOCOL_FEATURES] = \"VHOST_USER_GET_PROTOCOL_FEATURES\",\n+\t[VHOST_USER_SET_PROTOCOL_FEATURES] = \"VHOST_USER_SET_PROTOCOL_FEATURES\",\n+\t[VHOST_USER_SEND_RARP] = \"VHOST_USER_SEND_RARP\",\n+\t[VHOST_USER_SET_VRING_FLAG] = \"VHOST_USER_SET_VRING_FLAG\"\n };\n \n /**\n@@ -379,6 +383,17 @@ vserver_message_handler(int connfd, void *dat, int *remove)\n \t\tops->set_features(ctx, &features);\n \t\tbreak;\n \n+\tcase VHOST_USER_GET_PROTOCOL_FEATURES:\n+\t\tret = ops->get_protocol_features(ctx, &features);\n+\t\tmsg.payload.u64 = features;\n+\t\tmsg.size = sizeof(msg.payload.u64);\n+\t\tsend_vhost_message(connfd, &msg);\n+\t\tbreak;\n+\tcase VHOST_USER_SET_PROTOCOL_FEATURES:\n+\t\tfeatures = msg.payload.u64;\n+\t\tops->set_protocol_features(ctx, &features);\n+\t\tbreak;\n+\n \tcase VHOST_USER_SET_OWNER:\n \t\tops->set_owner(ctx);\n \t\tbreak;\n@@ -424,6 +439,10 @@ vserver_message_handler(int connfd, void *dat, int *remove)\n \t\tuser_set_vring_call(ctx, &msg);\n \t\tbreak;\n \n+\tcase VHOST_USER_SET_VRING_FLAG:\n+\t\tuser_set_vring_flag(ctx, &msg.payload.state);\n+\t\tbreak;\n+\n \tcase VHOST_USER_SET_VRING_ERR:\n \t\tif (!(msg.payload.u64 & VHOST_USER_VRING_NOFD_MASK))\n \t\t\tclose(msg.fds[0]);\ndiff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h b/lib/librte_vhost/vhost_user/vhost-net-user.h\nindex 2e72f3c..54e95aa 100644\n--- a/lib/librte_vhost/vhost_user/vhost-net-user.h\n+++ b/lib/librte_vhost/vhost_user/vhost-net-user.h\n@@ -63,6 +63,10 @@ typedef enum VhostUserRequest {\n \tVHOST_USER_SET_VRING_KICK = 12,\n \tVHOST_USER_SET_VRING_CALL = 13,\n \tVHOST_USER_SET_VRING_ERR = 14,\n+\tVHOST_USER_GET_PROTOCOL_FEATURES = 15,\n+\tVHOST_USER_SET_PROTOCOL_FEATURES = 16,\n+\tVHOST_USER_SEND_RARP = 17,\n+\tVHOST_USER_SET_VRING_FLAG = 18,\n \tVHOST_USER_MAX\n } VhostUserRequest;\n \ndiff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c\nindex d749f27..6a12d96 100644\n--- a/lib/librte_vhost/vhost_user/virtio-net-user.c\n+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c\n@@ -229,6 +229,13 @@ virtio_is_ready(struct virtio_net *dev)\n \t\t\t\t\"virtio isn't ready for processing.\\n\");\n \t\t\treturn 0;\n \t\t}\n+\t\tif ((dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_VRING_FLAG)) == 0) {\n+\t\t\t/* Without VRING_FLAG feature, only 1 vq pair is supported */\n+\t\t\tif (q_idx == 0) {\n+\t\t\t\trvq->enabled = 1;\n+\t\t\t\ttvq->enabled = 1;\n+\t\t\t}\n+\t\t}\n \t}\n \tRTE_LOG(INFO, VHOST_CONFIG,\n \t\t\"virtio is now ready for processing.\\n\");\n@@ -343,6 +350,28 @@ user_reset_owner(struct vhost_device_ctx ctx,\n \treturn 0;\n }\n \n+/*\n+ * when virtio queues are ready to work, qemu will send us to enable the virtio queue pair.\n+ */\n+int\n+user_set_vring_flag(struct vhost_device_ctx ctx,\n+\tstruct vhost_vring_state *state)\n+{\n+\tstruct virtio_net *dev = get_device(ctx);\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"set queue enable --- state idx:%d state num:%d\\n\", state->index, state->num);\n+\n+\t/*\n+\t * The state->index indicate the qeueu pair index,\n+\t * need set for both Rx and Tx.\n+\t */\n+\tdev->virtqueue[state->index * VIRTIO_QNUM + VIRTIO_RXQ]->enabled = state->num;\n+\tdev->virtqueue[state->index * VIRTIO_QNUM + VIRTIO_TXQ]->enabled = state->num;\n+\n+\treturn 0;\n+}\n+\n void\n user_destroy_device(struct vhost_device_ctx ctx)\n {\ndiff --git a/lib/librte_vhost/vhost_user/virtio-net-user.h b/lib/librte_vhost/vhost_user/virtio-net-user.h\nindex 2429836..10a3fff 100644\n--- a/lib/librte_vhost/vhost_user/virtio-net-user.h\n+++ b/lib/librte_vhost/vhost_user/virtio-net-user.h\n@@ -45,6 +45,8 @@ void user_set_vring_kick(struct vhost_device_ctx, struct VhostUserMsg *);\n \n int user_get_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);\n \n+int user_set_vring_flag(struct vhost_device_ctx ctx, struct vhost_vring_state *state);\n+\n void user_destroy_device(struct vhost_device_ctx);\n \n int user_reset_owner(struct vhost_device_ctx ctx, struct vhost_vring_state *state);\ndiff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c\nindex 8901aa5..24d0c53 100644\n--- a/lib/librte_vhost/virtio-net.c\n+++ b/lib/librte_vhost/virtio-net.c\n@@ -67,15 +67,23 @@ struct virtio_net_device_ops const *notify_ops;\n /* root address of the linked list of managed virtio devices */\n static struct virtio_net_config_ll *ll_root;\n \n+#define VHOST_USER_F_PROTOCOL_FEATURES 30\n+\n /* Features supported by this lib. */\n #define VHOST_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \\\n \t\t\t\t(1ULL << VIRTIO_NET_F_CTRL_VQ) | \\\n \t\t\t\t(1ULL << VIRTIO_NET_F_CTRL_RX) | \\\n \t\t\t\t(1ULL << VHOST_F_LOG_ALL) | \\\n-\t\t\t\t(1ULL << VIRTIO_NET_F_MQ))\n+\t\t\t\t(1ULL << VIRTIO_NET_F_MQ) | \\\n+\t\t\t\t(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))\n \n static uint64_t VHOST_FEATURES = VHOST_SUPPORTED_FEATURES;\n \n+/* Protocol features supported by this lib. */\n+#define VHOST_SUPPORTED_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_VRING_FLAG))\n+\n+static uint64_t VHOST_PROTOCOL_FEATURES = VHOST_SUPPORTED_PROTOCOL_FEATURES;\n+\n /*\n * Converts QEMU virtual address to Vhost virtual address. This function is\n * used to convert the ring addresses to our address space.\n@@ -533,6 +541,45 @@ set_features(struct vhost_device_ctx ctx, uint64_t *pu)\n }\n \n /*\n+ * Called from VHOST-USER SOCKET: VHOST_GET_PROTOCOL_FEATURES\n+ * The features that we support are requested.\n+ */\n+static int\n+get_protocol_features(struct vhost_device_ctx ctx, uint64_t *pu)\n+{\n+\tstruct virtio_net *dev;\n+\n+\tdev = get_device(ctx);\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\n+\t/* Send our supported features. */\n+\t*pu = VHOST_PROTOCOL_FEATURES;\n+\treturn 0;\n+}\n+\n+/*\n+ * Called from VHOST-USER SOCKET: VHOST_SET_PROTOCOL_FEATURES\n+ * We receive the negotiated features supported by us and the virtio device.\n+ */\n+static int\n+set_protocol_features(struct vhost_device_ctx ctx, uint64_t *pu)\n+{\n+\tstruct virtio_net *dev;\n+\n+\tdev = get_device(ctx);\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\tif (*pu & ~VHOST_PROTOCOL_FEATURES)\n+\t\treturn -1;\n+\n+\t/* Store the negotiated feature list for the device. */\n+\tdev->protocol_features = *pu;\n+\n+\treturn 0;\n+}\n+\n+/*\n * Called from CUSE IOCTL: VHOST_SET_VRING_NUM\n * The virtio device sends us the size of the descriptor ring.\n */\n@@ -824,6 +871,10 @@ set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)\n \tif (!(dev->flags & VIRTIO_DEV_RUNNING)) {\n \t\tif (((int)dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED) &&\n \t\t\t((int)dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED)) {\n+\t\t\tif ((dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_VRING_FLAG)) == 0) {\n+\t\t\t\tdev->virtqueue[VIRTIO_RXQ]->enabled = 1;\n+\t\t\t\tdev->virtqueue[VIRTIO_TXQ]->enabled = 1;\n+\t\t\t}\n \t\t\treturn notify_ops->new_device(dev);\n \t\t}\n \t/* Otherwise we remove it. */\n@@ -846,6 +897,9 @@ static const struct vhost_net_device_ops vhost_device_ops = {\n \t.get_features = get_features,\n \t.set_features = set_features,\n \n+\t.get_protocol_features = get_protocol_features,\n+\t.set_protocol_features = set_protocol_features,\n+\n \t.set_vring_num = set_vring_num,\n \t.set_vring_addr = set_vring_addr,\n \t.set_vring_base = set_vring_base,\ndiff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h\nindex 75fb57e..ef6efae 100644\n--- a/lib/librte_vhost/virtio-net.h\n+++ b/lib/librte_vhost/virtio-net.h\n@@ -37,6 +37,8 @@\n #include \"vhost-net.h\"\n #include \"rte_virtio_net.h\"\n \n+#define VHOST_USER_PROTOCOL_F_VRING_FLAG 2\n+\n struct virtio_net_device_ops const *notify_ops;\n struct virtio_net *get_device(struct vhost_device_ctx ctx);\n \n", "prefixes": [ "dpdk-dev", "v4", "06/12" ] }{ "id": 6742, "url": "