get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 56221,
    "url": "http://patches.dpdk.org/api/patches/56221/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20190708175318.46667-1-jin.yu@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": "<20190708175318.46667-1-jin.yu@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20190708175318.46667-1-jin.yu@intel.com",
    "date": "2019-07-08T17:53:17",
    "name": "[v2,1/2] vhost: support inflight share memory protocol feature",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "28f6efef1f54545fc6a4a2bb6344b8bb775b9a82",
    "submitter": {
        "id": 1265,
        "url": "http://patches.dpdk.org/api/people/1265/?format=api",
        "name": "Jin Yu",
        "email": "jin.yu@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/20190708175318.46667-1-jin.yu@intel.com/mbox/",
    "series": [
        {
            "id": 5391,
            "url": "http://patches.dpdk.org/api/series/5391/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=5391",
            "date": "2019-07-08T17:53:17",
            "name": "[v2,1/2] vhost: support inflight share memory protocol feature",
            "version": 2,
            "mbox": "http://patches.dpdk.org/series/5391/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/56221/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/56221/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 40E26397D;\n\tMon,  8 Jul 2019 12:06:29 +0200 (CEST)",
            "from mga11.intel.com (mga11.intel.com [192.55.52.93])\n\tby dpdk.org (Postfix) with ESMTP id 7B94C37B0\n\tfor <dev@dpdk.org>; Mon,  8 Jul 2019 12:06:27 +0200 (CEST)",
            "from orsmga004.jf.intel.com ([10.7.209.38])\n\tby fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t08 Jul 2019 03:06:26 -0700",
            "from storage36.sh.intel.com ([10.67.110.166])\n\tby orsmga004.jf.intel.com with ESMTP; 08 Jul 2019 03:06:24 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.63,466,1557212400\"; d=\"scan'208\";a=\"316678398\"",
        "From": "JinYu <jin.yu@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "changpeng.liu@intel.com, JinYu <jin.yu@intel.com>,\n\tLinLi <lilin24@baidu.com>, XunNi <nixun@baidu.com>,\n\tYuZhang <zhangyu31@baidu.com>",
        "Date": "Tue,  9 Jul 2019 01:53:17 +0800",
        "Message-Id": "<20190708175318.46667-1-jin.yu@intel.com>",
        "X-Mailer": "git-send-email 2.17.2",
        "In-Reply-To": "<20190626163806.61624-1-jin.yu@intel.com>",
        "References": "<20190626163806.61624-1-jin.yu@intel.com>",
        "Subject": "[dpdk-dev] [PATCH] [v2,\n\t1/2]vhost: support inflight share memory protocol feature",
        "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://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/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 introduces two new messages VHOST_USER_GET_INFLIGHT_FD\nand VHOST_USER_SET_INFLIGHT_FD to support transferring a shared\nbuffer between qemu and backend.\n\nFirstly, qemu uses VHOST_USER_GET_INFLIGHT_FD to get the\nshared buffer from backend. Then qemu should send it back\nthrough VHOST_USER_SET_INFLIGHT_FD each time we start vhost-user.\n\nThis shared buffer is used to process inflight I/O when backend\nreconnect.\n\nSigned-off-by: LinLi <lilin24@baidu.com>\nSigned-off-by: XunNi <nixun@baidu.com>\nSigned-off-by: YuZhang <zhangyu31@baidu.com>\nSigned-off-by: JinYu <jin.yu@intel.com>\n---\nv1 - specify the APIs are split-ring only\nv2 - fix APIs and judge split or packed\n---\n lib/librte_vhost/rte_vhost.h           | 105 +++++++++\n lib/librte_vhost/rte_vhost_version.map |   4 +\n lib/librte_vhost/vhost.c               | 158 ++++++++++++-\n lib/librte_vhost/vhost.h               |  16 ++\n lib/librte_vhost/vhost_user.c          | 313 +++++++++++++++++++++++++\n lib/librte_vhost/vhost_user.h          |  13 +-\n 6 files changed, 607 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h\nindex 0226b3eff..a17aff876 100644\n--- a/lib/librte_vhost/rte_vhost.h\n+++ b/lib/librte_vhost/rte_vhost.h\n@@ -71,6 +71,10 @@ extern \"C\" {\n #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11\n #endif\n \n+#ifndef VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD\n+#define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12\n+#endif\n+\n /** Indicate whether protocol features negotiation is supported. */\n #ifndef VHOST_USER_F_PROTOCOL_FEATURES\n #define VHOST_USER_F_PROTOCOL_FEATURES\t30\n@@ -98,6 +102,41 @@ struct rte_vhost_memory {\n \tstruct rte_vhost_mem_region regions[];\n };\n \n+struct inflight_desc_split {\n+\tuint8_t\t\tinflight;\n+\tuint8_t\t\tpadding[5];\n+\tuint16_t\tnext;\n+\tuint64_t\tcounter;\n+};\n+\n+struct inflight_info_split {\n+\tuint64_t\t\tfeatures;\n+\tuint16_t\t\tversion;\n+\tuint16_t\t\tdesc_num;\n+\tuint16_t\t\tlast_inflight_io;\n+\tuint16_t\t\tused_idx;\n+\tstruct inflight_desc_split desc[0];\n+};\n+\n+struct resubmit_desc {\n+\tuint16_t index;\n+\tuint64_t counter;\n+};\n+\n+struct resubmit_info {\n+\tstruct resubmit_desc\t*resubmit_list;\n+\tuint16_t\t\tresubmit_num;\n+};\n+\n+struct rte_vhost_ring_inflight_split {\n+\tunion {\n+\t\tstruct inflight_info_split *inflight_split;\n+\t\t/* TODO */\n+\t};\n+\n+\tstruct resubmit_info *resubmit_inflight_split;\n+};\n+\n struct rte_vhost_vring {\n \tstruct vring_desc\t*desc;\n \tstruct vring_avail\t*avail;\n@@ -603,6 +642,22 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n  */\n int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem);\n \n+/**\n+ * Get guest inflight vring info, including inflight ring and resubmit list.\n+ *\n+ * @param vid\n+ *  vhost device ID\n+ * @param vring_idx\n+ *  vring index\n+ * @param vring\n+ *  the structure to hold the requested inflight vring info\n+ * @return\n+ *  0 on success, -1 on failure\n+ */\n+int __rte_experimental\n+rte_vhost_get_vhost_ring_inflight_split(int vid, uint16_t vring_idx,\n+\t\t\t      struct rte_vhost_ring_inflight_split *vring);\n+\n /**\n  * Get guest vring info, including the vring address, vring size, etc.\n  *\n@@ -631,6 +686,56 @@ int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,\n  */\n int rte_vhost_vring_call(int vid, uint16_t vring_idx);\n \n+/**\n+ * set inflight flag for a desc.\n+ *\n+ * @param vid\n+ *  vhost device ID\n+ * @param vring_idx\n+ *  vring index\n+ * @param idx\n+ *  inflight entry index\n+ * @return\n+ *  0 on success, -1 on failure\n+ */\n+int __rte_experimental\n+rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx,\n+\t\tuint16_t idx);\n+\n+/**\n+ * clear inflight flag for a desc.\n+ *\n+ * @param vid\n+ *  vhost device ID\n+ * @param vring_idx\n+ *  vring index\n+ * @param last_used_idx\n+ *  next free used_idx\n+ * @param idx\n+ *  inflight entry index\n+ * @return\n+ *  0 on success, -1 on failure\n+ */\n+int __rte_experimental\n+rte_vhost_clr_inflight_desc_split(int vid, uint16_t vring_idx,\n+\t\tuint16_t last_used_idx, uint16_t idx);\n+\n+/**\n+ * set last inflight io index.\n+ *\n+ * @param vid\n+ *  vhost device ID\n+ * @param vring_idx\n+ *  vring index\n+ * @param idx\n+ *  inflight entry index\n+ * @return\n+ *  0 on success, -1 on failure\n+ */\n+int __rte_experimental\n+rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx,\n+\t\tuint16_t idx);\n+\n /**\n  * Get vhost RX queue avail count.\n  *\ndiff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map\nindex 5f1d4a75c..709593701 100644\n--- a/lib/librte_vhost/rte_vhost_version.map\n+++ b/lib/librte_vhost/rte_vhost_version.map\n@@ -87,4 +87,8 @@ EXPERIMENTAL {\n \trte_vdpa_relay_vring_used;\n \trte_vhost_extern_callback_register;\n \trte_vhost_driver_set_protocol_features;\n+\trte_vhost_set_inflight_desc_split;\n+\trte_vhost_clr_inflight_desc_split;\n+\trte_vhost_set_last_inflight_io_split;\n+\trte_vhost_get_vhost_vring_with_inflight_split;\n };\ndiff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c\nindex 981837b5d..ecd580cc5 100644\n--- a/lib/librte_vhost/vhost.c\n+++ b/lib/librte_vhost/vhost.c\n@@ -242,6 +242,30 @@ cleanup_vq(struct vhost_virtqueue *vq, int destroy)\n \t\tclose(vq->kickfd);\n }\n \n+void\n+cleanup_vq_inflight_split(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+{\n+\tif (!(dev->protocol_features &\n+\t\t(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)))\n+\t\treturn;\n+\n+\tif (vq_is_packed(dev)) {\n+\t\t/* TODO */\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"function only be used for split inflight.\\n\");\n+\t} else {\n+\t\tif (vq->inflight_split)\n+\t\t\tvq->inflight_split = NULL;\n+\t\tif (vq->resubmit_inflight_split) {\n+\t\t\tif (vq->resubmit_inflight_split->resubmit_list) {\n+\t\t\t\tfree(vq->resubmit_inflight_split->resubmit_list);\n+\t\t\t\tvq->resubmit_inflight_split->resubmit_list = NULL;\n+\t\t\t}\n+\t\t\tfree(vq->resubmit_inflight_split);\n+\t\t\tvq->resubmit_inflight_split = NULL;\n+\t\t}\n+\t}\n+}\n+\n /*\n  * Unmap any memory, close any file descriptors and\n  * free any memory owned by a device.\n@@ -253,8 +277,10 @@ cleanup_device(struct virtio_net *dev, int destroy)\n \n \tvhost_backend_cleanup(dev);\n \n-\tfor (i = 0; i < dev->nr_vring; i++)\n+\tfor (i = 0; i < dev->nr_vring; i++) {\n \t\tcleanup_vq(dev->virtqueue[i], destroy);\n+\t\tcleanup_vq_inflight_split(dev, dev->virtqueue[i]);\n+\t}\n }\n \n void\n@@ -726,6 +752,35 @@ rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem)\n \treturn 0;\n }\n \n+int __rte_experimental\n+rte_vhost_get_vhost_ring_inflight_split(int vid, uint16_t vring_idx,\n+\t\t\t  struct rte_vhost_ring_inflight_split *vring)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct inflight_info_split *inflight_vring;\n+\n+\tdev = get_device(vid);\n+\tif (dev == NULL || vring == NULL)\n+\t\treturn -1;\n+\n+\tif (vring_idx >= VHOST_MAX_VRING)\n+\t\treturn -1;\n+\n+\tinflight_vring = dev->virtqueue[vring_idx]->inflight_split;\n+\tif (!inflight_vring)\n+\t\treturn -1;\n+\n+\tif (vq_is_packed(dev)) {\n+\t\t/* TODO */\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"Can't be packed inflight ring.\\n\");\n+\t} else {\n+\t\tvring->inflight_split = inflight_vring;\n+\t\tvring->resubmit_inflight_split = dev->virtqueue[vring_idx]->resubmit_inflight_split;\n+\t}\n+\n+\treturn 0;\n+}\n+\n int\n rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,\n \t\t\t  struct rte_vhost_vring *vring)\n@@ -781,6 +836,107 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)\n \treturn 0;\n }\n \n+int\n+rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx, uint16_t idx)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct vhost_virtqueue *vq;\n+\n+\tdev = get_device(vid);\n+\tif (unlikely(!dev))\n+\t\treturn -1;\n+\n+\tif (unlikely(!(dev->protocol_features &\n+\t\t(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD))))\n+\t\treturn 0;\n+\n+\tif (unlikely(vq_is_packed(dev)))\n+\t\treturn -1;\n+\n+\tif (unlikely(vring_idx >= VHOST_MAX_VRING))\n+\t\treturn -1;\n+\n+\tvq = dev->virtqueue[vring_idx];\n+\tif (unlikely(!vq))\n+\t\treturn -1;\n+\n+\tif (unlikely(!vq->inflight_split))\n+\t\treturn -1;\n+\n+\tvq->inflight_split->desc[idx].counter = vq->global_counter++;\n+\tvq->inflight_split->desc[idx].inflight = 1;\n+\treturn 0;\n+}\n+\n+int\n+rte_vhost_clr_inflight_desc_split(int vid, uint16_t vring_idx,\n+\tuint16_t last_used_idx, uint16_t idx)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct vhost_virtqueue *vq;\n+\n+\tdev = get_device(vid);\n+\tif (unlikely(!dev))\n+\t\treturn -1;\n+\n+\tif (unlikely(!(dev->protocol_features &\n+\t\t(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD))))\n+\t\treturn 0;\n+\n+\tif (unlikely(vq_is_packed(dev)))\n+\t\treturn -1;\n+\n+\tif (unlikely(vring_idx >= VHOST_MAX_VRING))\n+\t\treturn -1;\n+\n+\tvq = dev->virtqueue[vring_idx];\n+\tif (unlikely(!vq))\n+\t\treturn -1;\n+\n+\tif (unlikely(!vq->inflight_split))\n+\t\treturn -1;\n+\n+\trte_compiler_barrier();\n+\n+\tvq->inflight_split->desc[idx].inflight = 0;\n+\n+\trte_compiler_barrier();\n+\n+\tvq->inflight_split->used_idx = last_used_idx;\n+\treturn 0;\n+}\n+\n+int\n+rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx, uint16_t idx)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct vhost_virtqueue *vq;\n+\n+\tdev = get_device(vid);\n+\tif (unlikely(!dev))\n+\t\treturn -1;\n+\n+\tif (unlikely(!(dev->protocol_features &\n+\t\t(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD))))\n+\t\treturn 0;\n+\n+\tif (unlikely(vq_is_packed(dev)))\n+\t\treturn -1;\n+\n+\tif (unlikely(vring_idx >= VHOST_MAX_VRING))\n+\t\treturn -1;\n+\n+\tvq = dev->virtqueue[vring_idx];\n+\tif (!vq)\n+\t\treturn -1;\n+\n+\tif (unlikely(!vq->inflight_split))\n+\t\treturn -1;\n+\n+\tvq->inflight_split->last_inflight_io = idx;\n+\treturn 0;\n+}\n+\n uint16_t\n rte_vhost_avail_entries(int vid, uint16_t queue_id)\n {\ndiff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h\nindex 884befa85..22925586d 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -128,6 +128,14 @@ struct vhost_virtqueue {\n \t/* Physical address of used ring, for logging */\n \tuint64_t\t\tlog_guest_addr;\n \n+\t/* inflight share memory info */\n+\tunion {\n+\t\tstruct inflight_info_split *inflight_split;\n+\t\t/* TODO */\n+\t};\n+\tstruct resubmit_info *resubmit_inflight_split;\n+\tuint64_t\t\tglobal_counter;\n+\n \tuint16_t\t\tnr_zmbuf;\n \tuint16_t\t\tzmbuf_size;\n \tuint16_t\t\tlast_zmbuf_idx;\n@@ -286,6 +294,12 @@ struct guest_page {\n \tuint64_t size;\n };\n \n+struct inflight_mem_info {\n+\tint\t\tfd;\n+\tvoid\t\t*addr;\n+\tuint64_t\tsize;\n+};\n+\n /**\n  * Device structure contains all configuration information relating\n  * to the device.\n@@ -303,6 +317,7 @@ struct virtio_net {\n \tuint32_t\t\tnr_vring;\n \tint\t\t\tdequeue_zero_copy;\n \tstruct vhost_virtqueue\t*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];\n+\tstruct inflight_mem_info inflight_info;\n #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)\n \tchar\t\t\tifname[IF_NAME_SZ];\n \tuint64_t\t\tlog_size;\n@@ -467,6 +482,7 @@ void vhost_destroy_device(int);\n void vhost_destroy_device_notify(struct virtio_net *dev);\n \n void cleanup_vq(struct vhost_virtqueue *vq, int destroy);\n+void cleanup_vq_inflight_split(struct virtio_net *dev, struct vhost_virtqueue *vq);\n void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq);\n \n int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);\ndiff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex c9e29ece8..feb642ad7 100644\n--- a/lib/librte_vhost/vhost_user.c\n+++ b/lib/librte_vhost/vhost_user.c\n@@ -31,6 +31,8 @@\n #include <sys/stat.h>\n #include <sys/syscall.h>\n #include <assert.h>\n+#include <sys/syscall.h>\n+#include <asm/unistd.h>\n #ifdef RTE_LIBRTE_VHOST_NUMA\n #include <numaif.h>\n #endif\n@@ -49,6 +51,15 @@\n #define VIRTIO_MIN_MTU 68\n #define VIRTIO_MAX_MTU 65535\n \n+#define INFLIGHT_ALIGNMENT\t64\n+#define INFLIGHT_VERSION\t0xabcd\n+#define VIRTQUEUE_MAX_SIZE\t1024\n+\n+#define CLOEXEC\t0x0001U\n+\n+#define ALIGN_DOWN(n, m) ((n) / (m) * (m))\n+#define ALIGN_UP(n, m) ALIGN_DOWN((n) + (m) - 1, (m))\n+\n static const char *vhost_message_str[VHOST_USER_MAX] = {\n \t[VHOST_USER_NONE] = \"VHOST_USER_NONE\",\n \t[VHOST_USER_GET_FEATURES] = \"VHOST_USER_GET_FEATURES\",\n@@ -78,6 +89,8 @@ static const char *vhost_message_str[VHOST_USER_MAX] = {\n \t[VHOST_USER_POSTCOPY_ADVISE]  = \"VHOST_USER_POSTCOPY_ADVISE\",\n \t[VHOST_USER_POSTCOPY_LISTEN]  = \"VHOST_USER_POSTCOPY_LISTEN\",\n \t[VHOST_USER_POSTCOPY_END]  = \"VHOST_USER_POSTCOPY_END\",\n+\t[VHOST_USER_GET_INFLIGHT_FD] = \"VHOST_USER_GET_INFLIGHT_FD\",\n+\t[VHOST_USER_SET_INFLIGHT_FD] = \"VHOST_USER_SET_INFLIGHT_FD\",\n };\n \n static int send_vhost_reply(int sockfd, struct VhostUserMsg *msg);\n@@ -160,6 +173,16 @@ vhost_backend_cleanup(struct virtio_net *dev)\n \t\tdev->log_addr = 0;\n \t}\n \n+\tif (dev->inflight_info.addr) {\n+\t\tmunmap(dev->inflight_info.addr, dev->inflight_info.size);\n+\t\tdev->inflight_info.addr = NULL;\n+\t}\n+\n+\tif (dev->inflight_info.fd > 0) {\n+\t\tclose(dev->inflight_info.fd);\n+\t\tdev->inflight_info.fd = -1;\n+\t}\n+\n \tif (dev->slave_req_fd >= 0) {\n \t\tclose(dev->slave_req_fd);\n \t\tdev->slave_req_fd = -1;\n@@ -306,6 +329,7 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg,\n \n \t\t\tdev->virtqueue[dev->nr_vring] = NULL;\n \t\t\tcleanup_vq(vq, 1);\n+\t\t\tcleanup_vq_inflight_split(dev, vq);\n \t\t\tfree_vq(dev, vq);\n \t\t}\n \t}\n@@ -1165,6 +1189,204 @@ virtio_is_ready(struct virtio_net *dev)\n \treturn 1;\n }\n \n+static int mem_create(const char *name, unsigned int flags)\n+{\n+#ifdef __NR_memfd_create\n+\treturn syscall(__NR_memfd_create, name, flags);\n+#else\n+\treturn -1;\n+#endif\n+}\n+\n+void *inflight_mem_alloc(const char *name, size_t size, int *fd)\n+{\n+\tvoid *ptr;\n+\tint mfd = -1;\n+\tchar fname[20] = \"/tmp/memfd-XXXXXX\";\n+\n+\t*fd = -1;\n+\tmfd = mem_create(name, CLOEXEC);\n+\tif (mfd != -1) {\n+\t\tif (ftruncate(mfd, size) == -1) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\t\"ftruncate fail for alloc inflight buffer\\n\");\n+\t\t\tclose(mfd);\n+\t\t\treturn NULL;\n+\t\t}\n+\t} else {\n+\t\tmfd = mkstemp(fname);\n+\t\tunlink(fname);\n+\n+\t\tif (mfd == -1) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\t\"mkstemp fail for alloc inflight buffer\\n\");\n+\t\t\treturn NULL;\n+\t\t}\n+\n+\t\tif (ftruncate(mfd, size) == -1) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\t\"ftruncate fail for alloc inflight buffer\\n\");\n+\t\t\tclose(mfd);\n+\t\t\treturn NULL;\n+\t\t}\n+\t}\n+\n+\tptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0);\n+\tif (ptr == MAP_FAILED) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\"mmap fail for alloc inflight buffer\\n\");\n+\t\tclose(mfd);\n+\t\treturn NULL;\n+\t}\n+\n+\t*fd = mfd;\n+\treturn ptr;\n+}\n+\n+static uint32_t get_pervq_shm_size_split(uint16_t queue_size)\n+{\n+\treturn ALIGN_UP(sizeof(struct inflight_desc_split) * queue_size +\n+\t\tsizeof(uint64_t) * 1 + sizeof(uint16_t) * 4, INFLIGHT_ALIGNMENT);\n+}\n+\n+static int\n+vhost_user_get_inflight_fd(struct virtio_net **pdev, VhostUserMsg *msg,\n+\t\tint main_fd __rte_unused)\n+{\n+\tint fd;\n+\tuint64_t mmap_size;\n+\tvoid *addr;\n+\tuint16_t num_queues, queue_size;\n+\tstruct virtio_net *dev = *pdev;\n+\n+\tif (msg->size != sizeof(msg->payload.inflight)) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"Invalid get_inflight_fd message size is %d\",\n+\t\t\tmsg->size);\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t}\n+\n+\tnum_queues = msg->payload.inflight.num_queues;\n+\tqueue_size = msg->payload.inflight.queue_size;\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG, \"get_inflight_fd num_queues: %u\\n\",\n+\t\t\tmsg->payload.inflight.num_queues);\n+\tRTE_LOG(INFO, VHOST_CONFIG, \"get_inflight_fd queue_size: %u\\n\",\n+\t\t\tmsg->payload.inflight.queue_size);\n+\n+\tif (vq_is_packed(dev)) {\n+\t\t/* TODO */\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"Don't support the packed ring\\n\");\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t} else {\n+\t\tmmap_size = num_queues * get_pervq_shm_size_split(queue_size);\n+\t}\n+\n+\taddr = inflight_mem_alloc(\"vhost-inflight\", mmap_size, &fd);\n+\tif (!addr) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"Failed to alloc vhost inflight area\");\n+\t\t\tmsg->payload.inflight.mmap_size = 0;\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t}\n+\tmemset(addr, 0, mmap_size);\n+\n+\tdev->inflight_info.addr = addr;\n+\tdev->inflight_info.size = msg->payload.inflight.mmap_size = mmap_size;\n+\tdev->inflight_info.fd = msg->fds[0] = fd;\n+\tmsg->payload.inflight.mmap_offset = 0;\n+\tmsg->fd_num = 1;\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\t\"send inflight mmap_size: %lu\\n\",\n+\t\t\tmsg->payload.inflight.mmap_size);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\t\"send inflight mmap_offset: %lu\\n\",\n+\t\t\tmsg->payload.inflight.mmap_offset);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\t\"send inflight fd: %d\\n\", msg->fds[0]);\n+\n+\treturn RTE_VHOST_MSG_RESULT_REPLY;\n+}\n+\n+static int\n+vhost_user_set_inflight_fd(struct virtio_net **pdev, VhostUserMsg *msg,\n+\t\tint main_fd __rte_unused)\n+{\n+\tint fd, i;\n+\tuint64_t mmap_size, mmap_offset;\n+\tuint16_t num_queues, queue_size;\n+\tuint32_t pervq_inflight_size;\n+\tvoid *addr;\n+\tstruct vhost_virtqueue *vq;\n+\tstruct virtio_net *dev = *pdev;\n+\n+\tfd = msg->fds[0];\n+\tif (msg->size != sizeof(msg->payload.inflight) || fd < 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"Invalid set_inflight_fd message size is %d,fd is %d\\n\",\n+\t\t\tmsg->size, fd);\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t}\n+\n+\tmmap_size = msg->payload.inflight.mmap_size;\n+\tmmap_offset = msg->payload.inflight.mmap_offset;\n+\tnum_queues = msg->payload.inflight.num_queues;\n+\tqueue_size = msg->payload.inflight.queue_size;\n+\n+\tif (vq_is_packed(dev)) {\n+\t\t/* TODO */\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"Don't support the packed ring\\n\");\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t} else {\n+\t\tpervq_inflight_size = get_pervq_shm_size_split(queue_size);\n+\t}\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"set_inflight_fd mmap_size: %lu\\n\", mmap_size);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"set_inflight_fd mmap_offset: %lu\\n\", mmap_offset);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"set_inflight_fd num_queues: %u\\n\", num_queues);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"set_inflight_fd queue_size: %u\\n\", queue_size);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"set_inflight_fd fd: %d\\n\", fd);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"set_inflight_fd pervq_inflight_size: %d\\n\",\n+\t\tpervq_inflight_size);\n+\n+\tif (dev->inflight_info.addr)\n+\t\tmunmap(dev->inflight_info.addr, dev->inflight_info.size);\n+\n+\taddr = mmap(0, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,\n+\t\t\tfd, mmap_offset);\n+\tif (addr == MAP_FAILED) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"failed to mmap share memory.\\n\");\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t}\n+\n+\tif (dev->inflight_info.fd)\n+\t\tclose(dev->inflight_info.fd);\n+\n+\tdev->inflight_info.fd = fd;\n+\tdev->inflight_info.addr = addr;\n+\tdev->inflight_info.size = mmap_size;\n+\n+\tfor (i = 0; i < num_queues; i++) {\n+\t\tvq = dev->virtqueue[i];\n+\t\tif (vq_is_packed(dev)) {\n+\t\t\t/* TODO */\n+\t\t} else {\n+\t\t\tvq->inflight_split = (struct inflight_info_split *)addr;\n+\t\t\tvq->inflight_split->desc_num = queue_size;\n+\t\t}\n+\t\taddr = (void *)((char *)addr + pervq_inflight_size);\n+\t}\n+\n+\treturn RTE_VHOST_MSG_RESULT_OK;\n+}\n+\n static int\n vhost_user_set_vring_call(struct virtio_net **pdev, struct VhostUserMsg *msg,\n \t\t\tint main_fd __rte_unused)\n@@ -1201,6 +1423,89 @@ static int vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused,\n \treturn RTE_VHOST_MSG_RESULT_OK;\n }\n \n+static int\n+resubmit_desc_compare(const void *a, const void *b)\n+{\n+\tconst struct resubmit_desc *desc0 = (const struct resubmit_desc *)a;\n+\tconst struct resubmit_desc *desc1 = (const struct resubmit_desc *)b;\n+\n+\tif (desc1->counter > desc0->counter &&\n+\t\t(desc1->counter - desc0->counter) < VIRTQUEUE_MAX_SIZE * 2)\n+\t\treturn 1;\n+\n+\treturn -1;\n+}\n+\n+static int\n+vhost_check_queue_inflights_split(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+{\n+\tstruct vring_used *used = vq->used;\n+\tuint16_t i = 0;\n+\tuint16_t resubmit_num = 0;\n+\tstruct resubmit_info *resubmit = NULL;\n+\n+\tif (!(dev->features &\n+\t\t(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)))\n+\t\treturn RTE_VHOST_MSG_RESULT_OK;\n+\n+\tif ((!vq->inflight_split))\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\n+\tif (!vq->inflight_split->version) {\n+\t\tvq->inflight_split->version = INFLIGHT_VERSION;\n+\t\treturn RTE_VHOST_MSG_RESULT_OK;\n+\t}\n+\n+\tvq->resubmit_inflight_split = NULL;\n+\tvq->global_counter = 0;\n+\n+\tif (vq->inflight_split->used_idx != used->idx) {\n+\t\tvq->inflight_split->desc[vq->inflight_split->last_inflight_io].inflight = 0;\n+\t\trte_compiler_barrier();\n+\t\tvq->inflight_split->used_idx = used->idx;\n+\t}\n+\n+\tfor (i = 0; i < vq->inflight_split->desc_num; i++) {\n+\t\tif (vq->inflight_split->desc[i].inflight == 1)\n+\t\t\tresubmit_num++;\n+\t}\n+\n+\tvq->last_avail_idx += resubmit_num;\n+\n+\tif (resubmit_num) {\n+\t\tresubmit  = calloc(1, sizeof(struct resubmit_info));\n+\t\tif (!resubmit) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG, \"Failed to allocate memory for resubmit info.\\n\");\n+\t\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t\t}\n+\n+\t\tresubmit->resubmit_list = calloc(resubmit_num,\n+\t\t\tsizeof(struct resubmit_desc));\n+\t\tif (!resubmit->resubmit_list) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG, \"Failed to allocate memory for inflight desc.\\n\");\n+\t\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t\t}\n+\n+\t\tfor (i = 0; i < vq->inflight_split->desc_num; i++) {\n+\t\t\tif (vq->inflight_split->desc[i].inflight == 1) {\n+\t\t\t\tresubmit->resubmit_list[resubmit->resubmit_num].index = i;\n+\t\t\t\tresubmit->resubmit_list[resubmit->resubmit_num].counter =\n+\t\t\t\t\tvq->inflight_split->desc[i].counter;\n+\t\t\t\tresubmit->resubmit_num++;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (resubmit->resubmit_num > 1)\n+\t\t\tqsort(resubmit->resubmit_list, resubmit->resubmit_num,\n+\t\t\t\tsizeof(struct resubmit_desc), resubmit_desc_compare);\n+\n+\t\tvq->global_counter = resubmit->resubmit_list[0].counter + 1;\n+\t\tvq->resubmit_inflight_split = resubmit;\n+\t}\n+\n+\treturn RTE_VHOST_MSG_RESULT_OK;\n+}\n+\n static int\n vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *msg,\n \t\t\tint main_fd __rte_unused)\n@@ -1242,6 +1547,12 @@ vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *msg,\n \t\tclose(vq->kickfd);\n \tvq->kickfd = file.fd;\n \n+\tif (vhost_check_queue_inflights_split(dev, vq)) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"Failed to inflights for vq: %d\\n\", file.index);\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t}\n+\n \treturn RTE_VHOST_MSG_RESULT_OK;\n }\n \n@@ -1762,6 +2073,8 @@ static vhost_message_handler_t vhost_message_handlers[VHOST_USER_MAX] = {\n \t[VHOST_USER_POSTCOPY_ADVISE] = vhost_user_set_postcopy_advise,\n \t[VHOST_USER_POSTCOPY_LISTEN] = vhost_user_set_postcopy_listen,\n \t[VHOST_USER_POSTCOPY_END] = vhost_user_postcopy_end,\n+\t[VHOST_USER_GET_INFLIGHT_FD] = vhost_user_get_inflight_fd,\n+\t[VHOST_USER_SET_INFLIGHT_FD] = vhost_user_set_inflight_fd,\n };\n \n \ndiff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h\nindex 2a650fe4b..99a773910 100644\n--- a/lib/librte_vhost/vhost_user.h\n+++ b/lib/librte_vhost/vhost_user.h\n@@ -54,7 +54,9 @@ typedef enum VhostUserRequest {\n \tVHOST_USER_POSTCOPY_ADVISE = 28,\n \tVHOST_USER_POSTCOPY_LISTEN = 29,\n \tVHOST_USER_POSTCOPY_END = 30,\n-\tVHOST_USER_MAX = 31\n+\tVHOST_USER_GET_INFLIGHT_FD = 31,\n+\tVHOST_USER_SET_INFLIGHT_FD = 32,\n+\tVHOST_USER_MAX = 33\n } VhostUserRequest;\n \n typedef enum VhostUserSlaveRequest {\n@@ -112,6 +114,13 @@ typedef struct VhostUserVringArea {\n \tuint64_t offset;\n } VhostUserVringArea;\n \n+typedef struct VhostUserInflight {\n+\tuint64_t mmap_size;\n+\tuint64_t mmap_offset;\n+\tuint16_t num_queues;\n+\tuint16_t queue_size;\n+} VhostUserInflight;\n+\n typedef struct VhostUserMsg {\n \tunion {\n \t\tuint32_t master; /* a VhostUserRequest value */\n@@ -131,6 +140,7 @@ typedef struct VhostUserMsg {\n \t\tstruct vhost_vring_addr addr;\n \t\tVhostUserMemory memory;\n \t\tVhostUserLog    log;\n+\t\tVhostUserInflight inflight;\n \t\tstruct vhost_iotlb_msg iotlb;\n \t\tVhostUserCryptoSessionParam crypto_session;\n \t\tVhostUserVringArea area;\n@@ -148,6 +158,7 @@ typedef struct VhostUserMsg {\n /* vhost_user.c */\n int vhost_user_msg_handler(int vid, int fd);\n int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);\n+void *inflight_mem_alloc(const char *name, size_t size, int *fd);\n \n /* socket.c */\n int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,\n",
    "prefixes": [
        "v2",
        "1/2"
    ]
}