get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 59360,
    "url": "http://patchwork.dpdk.org/api/patches/59360/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20190919150332.57009-1-jin.yu@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.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": "<20190919150332.57009-1-jin.yu@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20190919150332.57009-1-jin.yu@intel.com",
    "date": "2019-09-19T15:03:31",
    "name": "[04/10] vhost: add two new messages to support a shared buffer",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "dd9e9655f30853ec6bd64361810e359e06a36259",
    "submitter": {
        "id": 1265,
        "url": "http://patchwork.dpdk.org/api/people/1265/?format=api",
        "name": "Jin Yu",
        "email": "jin.yu@intel.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patchwork.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20190919150332.57009-1-jin.yu@intel.com/mbox/",
    "series": [
        {
            "id": 6441,
            "url": "http://patchwork.dpdk.org/api/series/6441/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=6441",
            "date": "2019-09-19T15:03:31",
            "name": null,
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/6441/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/59360/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/59360/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 2CD221D17B;\n\tThu, 19 Sep 2019 09:21:24 +0200 (CEST)",
            "from mga12.intel.com (mga12.intel.com [192.55.52.136])\n\tby dpdk.org (Postfix) with ESMTP id 94EEC1D168\n\tfor <dev@dpdk.org>; Thu, 19 Sep 2019 09:21:21 +0200 (CEST)",
            "from fmsmga002.fm.intel.com ([10.253.24.26])\n\tby fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t19 Sep 2019 00:21:19 -0700",
            "from storage36.sh.intel.com ([10.67.110.166])\n\tby fmsmga002.fm.intel.com with ESMTP; 19 Sep 2019 00:21:18 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.64,522,1559545200\"; d=\"scan'208\";a=\"217213732\"",
        "From": "JinYu <jin.yu@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "changpeng.liu@intel.com, maxime.coquelin@redhat.com, tiwei.bie@intel.com,\n\tzhihong.wang@intel.com, JinYu <jin.yu@intel.com>,\n\tLin Li <lilin24@baidu.com>, Xun Ni <nixun@baidu.com>,\n\tYu Zhang <zhangyu31@baidu.com>",
        "Date": "Thu, 19 Sep 2019 23:03:31 +0800",
        "Message-Id": "<20190919150332.57009-1-jin.yu@intel.com>",
        "X-Mailer": "git-send-email 2.17.2",
        "In-Reply-To": "<20190917145234.16951-5>",
        "References": "<20190917145234.16951-5>",
        "Subject": "[dpdk-dev] [PATCH 04/10] vhost: add two new messages to support a\n\tshared buffer",
        "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\nSigned-off-by: Lin Li <lilin24@baidu.com>\nSigned-off-by: Xun Ni <nixun@baidu.com>\nSigned-off-by: Yu Zhang <zhangyu31@baidu.com>\nSigned-off-by: Jin Yu <jin.yu@intel.com>\n---\n lib/librte_vhost/vhost.h      |   7 +\n lib/librte_vhost/vhost_user.c | 260 +++++++++++++++++++++++++++++++++-\n lib/librte_vhost/vhost_user.h |   4 +-\n 3 files changed, 269 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h\nindex 884befa85..d67ba849a 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -286,6 +286,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 +309,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;\ndiff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex c9e29ece8..66582a30f 100644\n--- a/lib/librte_vhost/vhost_user.c\n+++ b/lib/librte_vhost/vhost_user.c\n@@ -37,6 +37,10 @@\n #ifdef RTE_LIBRTE_VHOST_POSTCOPY\n #include <linux/userfaultfd.h>\n #endif\n+#ifdef F_ADD_SEALS /* if file sealing is supported, so is memfd */\n+#include <linux/memfd.h>\n+#define MEMFD_SUPPORTED\n+#endif\n \n #include <rte_common.h>\n #include <rte_malloc.h>\n@@ -49,6 +53,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\t\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 +91,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 +175,21 @@ 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->inflight_info) {\n+\t\tfree(dev->inflight_info);\n+\t\tdev->inflight_info = NULL;\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 +1195,233 @@ virtio_is_ready(struct virtio_net *dev)\n \treturn 1;\n }\n \n+static int\n+mem_create(const char *name, unsigned int flags)\n+{\n+#ifdef MEMFD_SUPPORTED\n+\treturn memfd_create(name, flags);\n+#else\n+\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\"doesn't support memfd--name:%s and flag:%x\\n\",\n+\t\tname, flags);\n+\treturn -1;\n+#endif\n+}\n+\n+static void *\n+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\"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\"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\"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\"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\n+get_pervq_shm_size_split(uint16_t queue_size)\n+{\n+\treturn ALIGN_UP(sizeof(struct rte_vhost_inflight_desc_split) *\n+\t\t\tqueue_size + sizeof(uint64_t) + sizeof(uint16_t) * 4,\n+\t\t\tINFLIGHT_ALIGNMENT);\n+}\n+\n+static uint32_t\n+get_pervq_shm_size_packed(uint16_t queue_size)\n+{\n+\treturn ALIGN_UP(sizeof(struct rte_vhost_inflight_desc_packed) *\n+\t\t\tqueue_size + sizeof(uint64_t) + sizeof(uint16_t) * 6 +\n+\t\t\tsizeof(uint8_t) * 9, INFLIGHT_ALIGNMENT);\n+}\n+\n+static int\n+vhost_user_get_inflight_fd(struct virtio_net **pdev,\n+\t\t\t\t     VhostUserMsg *msg,\n+\t\t\t\t     int main_fd __rte_unused)\n+{\n+\tint fd, i, j;\n+\tuint64_t pervq_inflight_size, mmap_size;\n+\tvoid *addr;\n+\tuint16_t num_queues, queue_size;\n+\tstruct virtio_net *dev = *pdev;\n+\tstruct rte_vhost_inflight_info_packed *inflight_packed = NULL;\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+\tdev->inflight_info = calloc(1, sizeof(struct inflight_mem_info));\n+\tif (!dev->inflight_info) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"Failed to alloc dev inflight area\");\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\tmsg->payload.inflight.num_queues);\n+\tRTE_LOG(INFO, VHOST_CONFIG, \"get_inflight_fd queue_size: %u\\n\",\n+\t\tmsg->payload.inflight.queue_size);\n+\n+\tif (vq_is_packed(dev))\n+\t\tpervq_inflight_size = get_pervq_shm_size_packed(queue_size);\n+\telse\n+\t\tpervq_inflight_size = get_pervq_shm_size_split(queue_size);\n+\n+\tmmap_size = num_queues * pervq_inflight_size;\n+\taddr = inflight_mem_alloc(\"vhost-inflight\", mmap_size, &fd);\n+\tif (!addr) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"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+\tif (vq_is_packed(dev)) {\n+\t\tfor (i = 0; i < num_queues; i++) {\n+\t\t\tinflight_packed =\n+\t\t\t\t(struct rte_vhost_inflight_info_packed *)addr;\n+\t\t\tinflight_packed->used_wrap_counter = 1;\n+\t\t\tinflight_packed->old_used_wrap_counter = 1;\n+\t\t\tfor (j = 0; j < queue_size; j++)\n+\t\t\t\tinflight_packed->desc[j].next = j + 1;\n+\t\t\taddr = (void *)((char *)addr + pervq_inflight_size);\n+\t\t}\n+\t}\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"send inflight mmap_size: %\"PRIu64\"\\n\",\n+\t\tmsg->payload.inflight.mmap_size);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"send inflight mmap_offset: %\"PRIu64\"\\n\",\n+\t\tmsg->payload.inflight.mmap_offset);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\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;\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 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,\n+\t\t\t\"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\tpervq_inflight_size = get_pervq_shm_size_packed(queue_size);\n+\telse\n+\t\tpervq_inflight_size = get_pervq_shm_size_split(queue_size);\n+\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"set_inflight_fd mmap_size: %\"PRIu64\"\\n\", mmap_size);\n+\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\"set_inflight_fd mmap_offset: %\"PRIu64\"\\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) {\n+\t\tdev->inflight_info = calloc(1,\n+\t\t\t\t\t    sizeof(struct inflight_mem_info));\n+\t\tif (dev->inflight_info == NULL) {\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\"Failed to alloc dev inflight area\");\n+\t\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t\t}\n+\t}\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+\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@@ -1762,9 +2019,10 @@ 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-\n /* return bytes# of read on success or negative val on failure. */\n static int\n read_vhost_message(int sockfd, struct VhostUserMsg *msg)\ndiff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h\nindex 17a1d7bca..6563f7315 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",
    "prefixes": [
        "04/10"
    ]
}