get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 55295,
    "url": "https://patches.dpdk.org/api/patches/55295/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20190625161850.35292-1-jin.yu@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": "<20190625161850.35292-1-jin.yu@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20190625161850.35292-1-jin.yu@intel.com",
    "date": "2019-06-25T16:18:50",
    "name": "vhost: support inflight share memory protocol feature",
    "commit_ref": null,
    "pull_url": null,
    "state": "changes-requested",
    "archived": true,
    "hash": "355f2e345f1b42fb5f8944485de5023cd11194b1",
    "submitter": {
        "id": 1265,
        "url": "https://patches.dpdk.org/api/people/1265/?format=api",
        "name": "Jin Yu",
        "email": "jin.yu@intel.com"
    },
    "delegate": {
        "id": 2642,
        "url": "https://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20190625161850.35292-1-jin.yu@intel.com/mbox/",
    "series": [
        {
            "id": 5149,
            "url": "https://patches.dpdk.org/api/series/5149/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=5149",
            "date": "2019-06-25T16:18:50",
            "name": "vhost: support inflight share memory protocol feature",
            "version": 1,
            "mbox": "https://patches.dpdk.org/series/5149/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/55295/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/55295/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 22F0D1BBDA;\n\tTue, 25 Jun 2019 10:32:22 +0200 (CEST)",
            "from mga07.intel.com (mga07.intel.com [134.134.136.100])\n\tby dpdk.org (Postfix) with ESMTP id 402D41BB83\n\tfor <dev@dpdk.org>; Tue, 25 Jun 2019 10:32:19 +0200 (CEST)",
            "from orsmga007.jf.intel.com ([10.7.209.58])\n\tby orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t25 Jun 2019 01:32:18 -0700",
            "from storage36.sh.intel.com ([10.67.111.92])\n\tby orsmga007.jf.intel.com with ESMTP; 25 Jun 2019 01:32:16 -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,415,1557212400\"; d=\"scan'208\";a=\"152227790\"",
        "From": "JinYu <jin.yu@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "JinYu <jin.yu@intel.com>, lilin <lilin24@baidu.com>,\n\tNi Xun <nixun@baidu.com>, Zhang Yu <zhangyu31@baidu.com>",
        "Date": "Wed, 26 Jun 2019 00:18:50 +0800",
        "Message-Id": "<20190625161850.35292-1-jin.yu@intel.com>",
        "X-Mailer": "git-send-email 2.17.2",
        "Subject": "[dpdk-dev] [PATCH] vhost: support inflight share memory protocol\n\tfeature",
        "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: lilin <lilin24@baidu.com>\nSigned-off-by: Ni Xun <nixun@baidu.com>\nSigned-off-by: Zhang Yu <zhangyu31@baidu.com>\nSigned-off-by: JinYu <jin.yu@intel.com>\n---\n lib/librte_vhost/rte_vhost.h           |  96 ++++++++++\n lib/librte_vhost/rte_vhost_version.map |   4 +\n lib/librte_vhost/vhost.c               |  72 ++++++++\n lib/librte_vhost/vhost.h               |  11 ++\n lib/librte_vhost/vhost_user.c          | 237 +++++++++++++++++++++++++\n lib/librte_vhost/vhost_user.h          |  17 +-\n 6 files changed, 434 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h\nindex 0226b3eff..57cb1abaa 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,12 +102,53 @@ struct rte_vhost_memory {\n \tstruct rte_vhost_mem_region regions[];\n };\n \n+typedef struct VhostUserInflightEntry {\n+\t/* Indicate whether this descriptor is inflight or not.\n+    \t * Only available for head-descriptor. */\n+\tuint8_t\t\tinflight;\n+\n+\tuint8_t\t\tpadding[5];\n+\n+\t/* Maintain a list for the last batch of used descriptors.\n+    \t * Only available when batching is used for submitting */\n+\tuint16_t\tnext;\n+\n+\t/* Used to preserve the order of fetching available descriptors.\n+     \t * Only available for head-descriptor. */\n+\tuint64_t\tcounter;\n+} VhostUserInflightEntry;\n+\n+typedef struct VhostInflightInfo {\n+\t/* The feature flags of this region. Now it's initialized to 0. */\n+\tuint64_t\t\tfeature;\n+\n+\t/* The version of this region. It's 1 currently.\n+    \t * Zero value indicates an uninitialized buffer */\n+\tuint16_t \t\tversion;\n+\n+\t/* The size of DescStateSplit array. It's equal to the virtqueue\n+     \t * size. Slave could get it from queue size field of VhostUserInflight. */\n+\tuint16_t\t\tdesc_num;\n+\n+\t/* The head of list that track the last batch of used descriptors. */\n+\tuint16_t\t\tlast_batch_head;\n+\n+\t/* Store the idx value of used ring */\n+\tuint16_t \t\tused_idx;\n+\n+\t/* Used to track the state of each descriptor in descriptor table */\n+\tVhostUserInflightEntry\tdesc[0];\n+} VhostInflightInfo;\n+\n struct rte_vhost_vring {\n \tstruct vring_desc\t*desc;\n \tstruct vring_avail\t*avail;\n \tstruct vring_used\t*used;\n \tuint64_t\t\tlog_guest_addr;\n \n+\tVhostInflightInfo       *inflight;\n+\tint                \tinflight_flag;\n+\n \t/** Deprecated, use rte_vhost_vring_call() instead. */\n \tint\t\t\tcallfd;\n \n@@ -603,6 +648,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 vring info including the vring address, vring size, inflight, etc.\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 vring info\n+ * @return\n+ *  0 on success, -1 on failure\n+ */\n+int __rte_experimental \n+rte_vhost_get_vhost_vring_with_inflight(int vid, uint16_t vring_idx,\n+\t\t\t\tstruct rte_vhost_vring *vring);\n+\n /**\n  * Get guest vring info, including the vring address, vring size, etc.\n  *\n@@ -631,6 +692,41 @@ 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 entry.\n+ *\n+ * @param vring\n+ *  the structure to hold the requested vring info\n+ * @param idx\n+ *  inflight entry index\n+ */\n+void __rte_experimental rte_vhost_set_inflight(struct rte_vhost_vring *vring,\n+\t\tuint16_t idx);\n+\n+/**\n+ * clear inflight flag for a entry.\n+ *\n+ * @param vring\n+ *  the structure to hold the requested vring info\n+ * @param last_used_idx\n+ *  next free used_idx\n+ * @param idx\n+ *  inflight entry index\n+ */\n+void __rte_experimental rte_vhost_clr_inflight(struct rte_vhost_vring *vring,\n+\t\tuint16_t last_used_idx, uint16_t idx);\n+\n+/**\n+ * set last inflight io index.\n+ *\n+ * @param vring\n+ *  the structure to hold the requested vring info\n+ * @param idx\n+ *  inflight entry index\n+ */\n+void __rte_experimental rte_vhost_set_last_inflight_io(struct rte_vhost_vring *vring,\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..bea1e9ab6 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;\n+\trte_vhost_clr_inflight;\n+\trte_vhost_set_last_inflight_io;\n+\trte_vhost_get_vhost_with_inflight;\n };\ndiff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c\nindex 981837b5d..a2604a5d4 100644\n--- a/lib/librte_vhost/vhost.c\n+++ b/lib/librte_vhost/vhost.c\n@@ -240,6 +240,8 @@ cleanup_vq(struct vhost_virtqueue *vq, int destroy)\n \t\tclose(vq->callfd);\n \tif (vq->kickfd >= 0)\n \t\tclose(vq->kickfd);\n+\tif (vq->inflight)\n+\t\tvq->inflight = NULL;\n }\n \n /*\n@@ -726,6 +728,41 @@ 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_vring_with_inflight(int vid, uint16_t vring_idx,\n+\t\t\t  struct rte_vhost_vring *vring)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct vhost_virtqueue *vq;\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+\tvq = dev->virtqueue[vring_idx];\n+\tif (!vq)\n+\t\treturn -1;\n+\n+\tvring->desc  = vq->desc;\n+\tvring->avail = vq->avail;\n+\tvring->used  = vq->used;\n+\tvring->log_guest_addr  = vq->log_guest_addr;\n+\n+\tvring->callfd  = vq->callfd;\n+\tvring->kickfd  = vq->kickfd;\n+\tvring->size    = vq->size;\n+\n+\tvring->inflight = vq->inflight;\n+\n+\tvring->inflight_flag = vq->inflight_flag;\n+\tvq->inflight_flag = 0;\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 +818,41 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)\n \treturn 0;\n }\n \n+void __rte_experimental\n+rte_vhost_set_inflight(struct rte_vhost_vring *vring, uint16_t idx)\n+{\n+\tVhostInflightInfo *inflight = vring->inflight;\n+\tif (unlikely(!inflight))\n+\t\treturn;\n+\tinflight->desc[idx].inflight = 1;\n+}\n+\n+void __rte_experimental\n+rte_vhost_clr_inflight(struct rte_vhost_vring *vring,\n+\tuint16_t last_used_idx, uint16_t idx)\n+{\n+\tVhostInflightInfo *inflight = vring->inflight;\n+\n+\tif (unlikely(!inflight))\n+\t\treturn;\n+\n+\trte_compiler_barrier();\n+\tinflight->desc[idx].inflight = 0;\n+\trte_compiler_barrier();\n+\tinflight->used_idx = last_used_idx;\n+}\n+\n+void __rte_experimental\n+rte_vhost_set_last_inflight_io(struct rte_vhost_vring *vring, uint16_t idx)\n+{\n+\tVhostInflightInfo *inflight = vring->inflight;\n+\n+\tif (unlikely(!inflight))\n+\t\treturn;\n+\n+\tinflight->last_batch_head = idx;\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..c4790f1ce 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -128,6 +128,10 @@ 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+\tVhostInflightInfo       *inflight;\n+\tbool                \tinflight_flag;\n+\n \tuint16_t\t\tnr_zmbuf;\n \tuint16_t\t\tzmbuf_size;\n \tuint16_t\t\tlast_zmbuf_idx;\n@@ -286,6 +290,12 @@ struct guest_page {\n \tuint64_t size;\n };\n \n+typedef struct VuDevInflightInfo {\n+\tint \t\tfd;\n+\tvoid \t\t*addr;\n+\tuint64_t \tsize;\n+} VuDevInflightInfo;\n+\n /**\n  * Device structure contains all configuration information relating\n  * to the device.\n@@ -303,6 +313,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+\tVuDevInflightInfo \tinflight_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;\ndiff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex c9e29ece8..d7293250d 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,14 @@\n #define VIRTIO_MIN_MTU 68\n #define VIRTIO_MAX_MTU 65535\n \n+#define INFLIGHT_ALIGNMENT 64\n+#define INFLIGHT_VERSION 0xabcd\n+\n+#define CLOEXEC 0x0001U\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 +88,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 +172,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@@ -1165,6 +1187,184 @@ 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(uint16_t queue_size)\n+{\n+\treturn ALIGN_UP(sizeof(VhostUserInflightEntry) * queue_size +\n+\t\tsizeof(uint16_t) * 4 + sizeof(uint64_t), 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\tmsg->payload.inflight.mmap_size = 0;\n+\t\treturn RTE_VHOST_MSG_RESULT_OK;\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+\tmmap_size = num_queues * get_pervq_shm_size(queue_size);\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_OK;\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+\tpervq_inflight_size = get_pervq_shm_size(queue_size);\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\tvq->inflight = (VhostInflightInfo *)addr;\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 +1401,35 @@ 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+vhost_check_queue_inflights(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+{\n+\tuint16_t i = 0;\n+\n+\tif (!(dev->protocol_features & VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD))\n+\t\treturn RTE_VHOST_MSG_RESULT_OK;\n+\n+\tif ((!vq->inflight))\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\n+\t/* TODO */\n+\t/* should check whether the feature is negotiated first. */\n+\n+\tif (!vq->inflight->version) {\n+\t\tvq->inflight->version = INFLIGHT_VERSION;\n+\t\treturn RTE_VHOST_MSG_RESULT_OK;\n+\t}\n+\n+\tfor (i = 0; i < vq->size; i++) {\n+\t\tif (vq->inflight->desc[i].inflight == 1) {\n+\t\t\tvq->inflight_flag = 1;\n+\t\t\tbreak;\n+\t\t}\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 +1471,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(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 +1997,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..837ee6c5d 100644\n--- a/lib/librte_vhost/vhost_user.h\n+++ b/lib/librte_vhost/vhost_user.h\n@@ -22,8 +22,8 @@\n \t\t\t\t\t (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \\\n \t\t\t\t\t (1ULL << VHOST_USER_PROTOCOL_F_CRYPTO_SESSION) | \\\n \t\t\t\t\t (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) | \\\n-\t\t\t\t\t (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) | \\\n-\t\t\t\t\t (1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT))\n+\t\t\t\t\t (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER))\n+\t\n \n typedef enum VhostUserRequest {\n \tVHOST_USER_NONE = 0,\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": []
}