get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/35637/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 35637,
    "url": "http://patches.dpdk.org/api/patches/35637/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20180213092106.57996-5-zhihong.wang@intel.com/",
    "project": {
        "id": 1,
        "url": "http://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": "<20180213092106.57996-5-zhihong.wang@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20180213092106.57996-5-zhihong.wang@intel.com",
    "date": "2018-02-13T09:21:04",
    "name": "[dpdk-dev,v2,4/6] vhost: adapt vhost lib for selective datapath",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "bb7bc1e969d875df67c228692f8d7ea28a56a4ff",
    "submitter": {
        "id": 156,
        "url": "http://patches.dpdk.org/api/people/156/?format=api",
        "name": "Zhihong Wang",
        "email": "zhihong.wang@intel.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20180213092106.57996-5-zhihong.wang@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/35637/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/35637/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 [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 868995F14;\n\tMon,  5 Mar 2018 10:20:29 +0100 (CET)",
            "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n\tby dpdk.org (Postfix) with ESMTP id D73FB5F39\n\tfor <dev@dpdk.org>; Mon,  5 Mar 2018 10:20:26 +0100 (CET)",
            "from fmsmga001.fm.intel.com ([10.253.24.23])\n\tby orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t05 Mar 2018 01:20:26 -0800",
            "from unknown (HELO dpdk99.sh.intel.com) ([10.67.110.156])\n\tby fmsmga001.fm.intel.com with ESMTP; 05 Mar 2018 01:20:24 -0800"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.47,426,1515484800\"; d=\"scan'208\";a=\"35531749\"",
        "From": "Zhihong Wang <zhihong.wang@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "jianfeng.tan@intel.com, tiwei.bie@intel.com, maxime.coquelin@redhat.com, \n\tyliu@fridaylinux.org, cunming.liang@intel.com, xiao.w.wang@intel.com,\n\tdan.daly@intel.com, Zhihong Wang <zhihong.wang@intel.com>",
        "Date": "Tue, 13 Feb 2018 17:21:04 +0800",
        "Message-Id": "<20180213092106.57996-5-zhihong.wang@intel.com>",
        "X-Mailer": "git-send-email 2.13.6",
        "In-Reply-To": "<20180213092106.57996-1-zhihong.wang@intel.com>",
        "References": "<1517614137-62926-1-git-send-email-zhihong.wang@intel.com>\n\t<20180213092106.57996-1-zhihong.wang@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2 4/6] vhost: adapt vhost lib for selective\n\tdatapath",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://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": "<https://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": "This patch adapts vhost lib for selective datapath by calling device ops\nat the corresponding stage.\n\nSigned-off-by: Zhihong Wang <zhihong.wang@intel.com>\n---\nChanges in v2:\n\n 1. Ensure negotiated capabilities are supported in vhost-user lib.\n\n 2. Configure the data path at the right time.\n\n lib/librte_vhost/rte_vhost.h  | 25 ++++++++++++++\n lib/librte_vhost/socket.c     | 76 +++++++++++++++++++++++++++++++++++++++++--\n lib/librte_vhost/vhost.c      |  3 ++\n lib/librte_vhost/vhost.h      |  2 ++\n lib/librte_vhost/vhost_user.c | 56 +++++++++++++++++++++++++++----\n 5 files changed, 154 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h\nindex a76acea6b..9bec36756 100644\n--- a/lib/librte_vhost/rte_vhost.h\n+++ b/lib/librte_vhost/rte_vhost.h\n@@ -277,6 +277,31 @@ int rte_vhost_driver_disable_features(const char *path, uint64_t features);\n int rte_vhost_driver_get_features(const char *path, uint64_t *features);\n \n /**\n+ * Get the protocol feature bits before feature negotiation.\n+ *\n+ * @param path\n+ *  The vhost-user socket file path\n+ * @param protocol_features\n+ *  A pointer to store the queried protocol feature bits\n+ * @return\n+ *  0 on success, -1 on failure\n+ */\n+int rte_vhost_driver_get_protocol_features(const char *path,\n+\t\tuint64_t *protocol_features);\n+\n+/**\n+ * Get the queue number bits before feature negotiation.\n+ *\n+ * @param path\n+ *  The vhost-user socket file path\n+ * @param queue_num\n+ *  A pointer to store the queried queue number bits\n+ * @return\n+ *  0 on success, -1 on failure\n+ */\n+int rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num);\n+\n+/**\n  * Get the feature bits after negotiation\n  *\n  * @param vid\ndiff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c\nindex 5367ba771..0354740fa 100644\n--- a/lib/librte_vhost/socket.c\n+++ b/lib/librte_vhost/socket.c\n@@ -216,6 +216,9 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)\n \n \tvhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net);\n \n+\tvhost_set_vdpa_eid(vid, vsocket->eid);\n+\tvhost_set_vdpa_did(vid, vsocket->did);\n+\n \tif (vsocket->dequeue_zero_copy)\n \t\tvhost_enable_dequeue_zero_copy(vid);\n \n@@ -667,11 +670,80 @@ int\n rte_vhost_driver_get_features(const char *path, uint64_t *features)\n {\n \tstruct vhost_user_socket *vsocket;\n+\tstruct rte_vdpa_eng_attr attr;\n+\tint eid = -1;\n \n \tpthread_mutex_lock(&vhost_user.mutex);\n \tvsocket = find_vhost_user_socket(path);\n-\tif (vsocket)\n-\t\t*features = vsocket->features;\n+\tif (vsocket) {\n+\t\teid = vsocket->eid;\n+\t\tif (rte_vdpa_info_query(eid, &attr) < 0)\n+\t\t\t*features = vsocket->features;\n+\t\telse\n+\t\t\t*features = vsocket->features & attr.features;\n+\n+\t}\n+\tpthread_mutex_unlock(&vhost_user.mutex);\n+\n+\tif (!vsocket) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"socket file %s is not registered yet.\\n\", path);\n+\t\treturn -1;\n+\t} else {\n+\t\treturn 0;\n+\t}\n+}\n+\n+int\n+rte_vhost_driver_get_protocol_features(const char *path,\n+\t\tuint64_t *protocol_features)\n+{\n+\tstruct vhost_user_socket *vsocket;\n+\tstruct rte_vdpa_eng_attr attr;\n+\tint eid = -1;\n+\n+\tpthread_mutex_lock(&vhost_user.mutex);\n+\tvsocket = find_vhost_user_socket(path);\n+\tif (vsocket) {\n+\t\teid = vsocket->eid;\n+\t\tif (rte_vdpa_info_query(eid, &attr) < 0)\n+\t\t\t*protocol_features = VHOST_USER_PROTOCOL_FEATURES;\n+\t\telse\n+\t\t\t*protocol_features = VHOST_USER_PROTOCOL_FEATURES\n+\t\t\t\t& attr.protocol_features;\n+\n+\t}\n+\tpthread_mutex_unlock(&vhost_user.mutex);\n+\n+\tif (!vsocket) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"socket file %s is not registered yet.\\n\", path);\n+\t\treturn -1;\n+\t} else {\n+\t\treturn 0;\n+\t}\n+}\n+\n+int\n+rte_vhost_driver_get_queue_num(const char *path,\n+\t\tuint32_t *queue_num)\n+{\n+\tstruct vhost_user_socket *vsocket;\n+\tstruct rte_vdpa_eng_attr attr;\n+\tint eid = -1;\n+\n+\tpthread_mutex_lock(&vhost_user.mutex);\n+\tvsocket = find_vhost_user_socket(path);\n+\tif (vsocket) {\n+\t\teid = vsocket->eid;\n+\t\tif (rte_vdpa_info_query(eid, &attr) < 0)\n+\t\t\t*queue_num = VHOST_MAX_QUEUE_PAIRS;\n+\t\telse if (attr.queue_num > VHOST_MAX_QUEUE_PAIRS)\n+\t\t\t*queue_num = VHOST_MAX_QUEUE_PAIRS;\n+\t\telse\n+\t\t\t*queue_num = attr.queue_num;\n+\n+\t}\n \tpthread_mutex_unlock(&vhost_user.mutex);\n \n \tif (!vsocket) {\ndiff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c\nindex 45cf90f99..f8a5a1c42 100644\n--- a/lib/librte_vhost/vhost.c\n+++ b/lib/librte_vhost/vhost.c\n@@ -297,11 +297,14 @@ void\n vhost_destroy_device(int vid)\n {\n \tstruct virtio_net *dev = get_device(vid);\n+\tint eid = dev->eid;\n \n \tif (dev == NULL)\n \t\treturn;\n \n \tif (dev->flags & VIRTIO_DEV_RUNNING) {\n+\t\tif (eid >= 0 && vdpa_engines[eid]->eng_drv->dev_ops.dev_close)\n+\t\t\tvdpa_engines[eid]->eng_drv->dev_ops.dev_close(dev->vid);\n \t\tdev->flags &= ~VIRTIO_DEV_RUNNING;\n \t\tdev->notify_ops->destroy_device(vid);\n \t}\ndiff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h\nindex b3fa6da03..e11b27842 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -27,6 +27,8 @@\n #define VIRTIO_DEV_READY 2\n /* Used to indicate that the built-in vhost net device backend is enabled */\n #define VIRTIO_DEV_BUILTIN_VIRTIO_NET 4\n+/* Used to indicate that the device has its own data path and configured */\n+#define VIRTIO_DEV_VDPA_CONFIGURED 8\n \n /* Backend value set by guest. */\n #define VIRTIO_DEV_STOPPED -1\ndiff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex c93e48e4d..8b07b6c43 100644\n--- a/lib/librte_vhost/vhost_user.c\n+++ b/lib/librte_vhost/vhost_user.c\n@@ -133,7 +133,11 @@ vhost_user_set_owner(void)\n static int\n vhost_user_reset_owner(struct virtio_net *dev)\n {\n+\tint eid = dev->eid;\n+\n \tif (dev->flags & VIRTIO_DEV_RUNNING) {\n+\t\tif (eid >= 0 && vdpa_engines[eid]->eng_drv->dev_ops.dev_close)\n+\t\t\tvdpa_engines[eid]->eng_drv->dev_ops.dev_close(dev->vid);\n \t\tdev->flags &= ~VIRTIO_DEV_RUNNING;\n \t\tdev->notify_ops->destroy_device(dev->vid);\n \t}\n@@ -156,12 +160,25 @@ vhost_user_get_features(struct virtio_net *dev)\n }\n \n /*\n+ * The queue number that we support are requested.\n+ */\n+static uint32_t\n+vhost_user_get_queue_num(struct virtio_net *dev)\n+{\n+\tuint32_t queue_num = 0;\n+\n+\trte_vhost_driver_get_queue_num(dev->ifname, &queue_num);\n+\treturn (uint64_t)queue_num;\n+}\n+\n+/*\n  * We receive the negotiated features supported by us and the virtio device.\n  */\n static int\n vhost_user_set_features(struct virtio_net *dev, uint64_t features)\n {\n \tuint64_t vhost_features = 0;\n+\tint eid = dev->eid;\n \n \trte_vhost_driver_get_features(dev->ifname, &vhost_features);\n \tif (features & ~vhost_features) {\n@@ -191,6 +208,9 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features)\n \t\t\tdev->notify_ops->features_changed(dev->vid, features);\n \t}\n \n+\tif (eid >= 0 && vdpa_engines[eid]->eng_drv->dev_ops.feature_set)\n+\t\tvdpa_engines[eid]->eng_drv->dev_ops.feature_set(dev->vid);\n+\n \tdev->features = features;\n \tif (dev->features &\n \t\t((1 << VIRTIO_NET_F_MRG_RXBUF) | (1ULL << VIRTIO_F_VERSION_1))) {\n@@ -933,9 +953,12 @@ vhost_user_get_vring_base(struct virtio_net *dev,\n \t\t\t  VhostUserMsg *msg)\n {\n \tstruct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index];\n+\tint eid = dev->eid;\n \n \t/* We have to stop the queue (virtio) if it is running. */\n \tif (dev->flags & VIRTIO_DEV_RUNNING) {\n+\t\tif (eid >= 0 && vdpa_engines[eid]->eng_drv->dev_ops.dev_close)\n+\t\t\tvdpa_engines[eid]->eng_drv->dev_ops.dev_close(dev->vid);\n \t\tdev->flags &= ~VIRTIO_DEV_RUNNING;\n \t\tdev->notify_ops->destroy_device(dev->vid);\n \t}\n@@ -983,16 +1006,22 @@ vhost_user_set_vring_enable(struct virtio_net *dev,\n \t\t\t    VhostUserMsg *msg)\n {\n \tint enable = (int)msg->payload.state.num;\n+\tint index = (int)msg->payload.state.index;\n+\tint eid = dev->eid;\n \n \tRTE_LOG(INFO, VHOST_CONFIG,\n \t\t\"set queue enable: %d to qp idx: %d\\n\",\n-\t\tenable, msg->payload.state.index);\n+\t\tenable, index);\n+\n+\tif (eid >= 0 && vdpa_engines[eid]->eng_drv->dev_ops.vring_state_set)\n+\t\tvdpa_engines[eid]->eng_drv->dev_ops.vring_state_set(dev->vid,\n+\t\t\t\tindex, enable);\n \n \tif (dev->notify_ops->vring_state_changed)\n \t\tdev->notify_ops->vring_state_changed(dev->vid,\n-\t\t\t\tmsg->payload.state.index, enable);\n+\t\t\t\tindex, enable);\n \n-\tdev->virtqueue[msg->payload.state.index]->enabled = enable;\n+\tdev->virtqueue[index]->enabled = enable;\n \n \treturn 0;\n }\n@@ -1001,9 +1030,10 @@ static void\n vhost_user_get_protocol_features(struct virtio_net *dev,\n \t\t\t\t struct VhostUserMsg *msg)\n {\n-\tuint64_t features, protocol_features = VHOST_USER_PROTOCOL_FEATURES;\n+\tuint64_t features, protocol_features;\n \n \trte_vhost_driver_get_features(dev->ifname, &features);\n+\trte_vhost_driver_get_protocol_features(dev->ifname, &protocol_features);\n \n \t/*\n \t * REPLY_ACK protocol feature is only mandatory for now\n@@ -1015,7 +1045,6 @@ vhost_user_get_protocol_features(struct virtio_net *dev,\n \t\tprotocol_features &=\n \t\t\t~(1ULL << RTE_VHOST_USER_PROTOCOL_F_REPLY_ACK);\n \n-\tmsg->payload.u64 = protocol_features;\n \tmsg->size = sizeof(msg->payload.u64);\n }\n \n@@ -1100,6 +1129,7 @@ static int\n vhost_user_send_rarp(struct virtio_net *dev, struct VhostUserMsg *msg)\n {\n \tuint8_t *mac = (uint8_t *)&msg->payload.u64;\n+\tint eid = dev->eid;\n \n \tRTE_LOG(DEBUG, VHOST_CONFIG,\n \t\t\":: mac: %02x:%02x:%02x:%02x:%02x:%02x\\n\",\n@@ -1115,6 +1145,8 @@ vhost_user_send_rarp(struct virtio_net *dev, struct VhostUserMsg *msg)\n \t */\n \trte_smp_wmb();\n \trte_atomic16_set(&dev->broadcast_rarp, 1);\n+\tif (eid >= 0 && vdpa_engines[eid]->eng_drv->dev_ops.migration_done)\n+\t\tvdpa_engines[eid]->eng_drv->dev_ops.migration_done(dev->vid);\n \n \treturn 0;\n }\n@@ -1376,6 +1408,8 @@ vhost_user_msg_handler(int vid, int fd)\n {\n \tstruct virtio_net *dev;\n \tstruct VhostUserMsg msg;\n+\tstruct rte_vdpa_engine *eng;\n+\tint eid;\n \tint ret;\n \tint unlock_required = 0;\n \n@@ -1528,7 +1562,7 @@ vhost_user_msg_handler(int vid, int fd)\n \t\tbreak;\n \n \tcase VHOST_USER_GET_QUEUE_NUM:\n-\t\tmsg.payload.u64 = VHOST_MAX_QUEUE_PAIRS;\n+\t\tmsg.payload.u64 = (uint64_t)vhost_user_get_queue_num(dev);\n \t\tmsg.size = sizeof(msg.payload.u64);\n \t\tsend_vhost_reply(fd, &msg);\n \t\tbreak;\n@@ -1581,6 +1615,16 @@ vhost_user_msg_handler(int vid, int fd)\n \t\t}\n \t}\n \n+\teid = dev->eid;\n+\tif (eid >= 0 && virtio_is_ready(dev) &&\n+\t\t\t!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) &&\n+\t\t\tmsg.request.master == VHOST_USER_SET_VRING_ENABLE) {\n+\t\teng = vdpa_engines[eid];\n+\t\tif (eng->eng_drv->dev_ops.dev_conf)\n+\t\t\teng->eng_drv->dev_ops.dev_conf(vid);\n+\t\tdev->flags |= VIRTIO_DEV_VDPA_CONFIGURED;\n+\t}\n+\n \treturn 0;\n }\n \n",
    "prefixes": [
        "dpdk-dev",
        "v2",
        "4/6"
    ]
}