get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 54970,
    "url": "http://patches.dpdk.org/api/patches/54970/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1560957293-17294-17-git-send-email-ndragazis@arrikto.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": "<1560957293-17294-17-git-send-email-ndragazis@arrikto.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1560957293-17294-17-git-send-email-ndragazis@arrikto.com",
    "date": "2019-06-19T15:14:41",
    "name": "[16/28] vhost: move postcopy live migration code",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": true,
    "hash": "b094d1357c91a00302607aa972cbb905227f42e0",
    "submitter": {
        "id": 1339,
        "url": "http://patches.dpdk.org/api/people/1339/?format=api",
        "name": "Nikos Dragazis",
        "email": "ndragazis@arrikto.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/1560957293-17294-17-git-send-email-ndragazis@arrikto.com/mbox/",
    "series": [
        {
            "id": 5082,
            "url": "http://patches.dpdk.org/api/series/5082/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=5082",
            "date": "2019-06-19T15:14:25",
            "name": "vhost: add virtio-vhost-user transport",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/5082/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/54970/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/54970/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 C537E1C407;\n\tWed, 19 Jun 2019 17:16:29 +0200 (CEST)",
            "from mx0.arrikto.com (mx0.arrikto.com [212.71.252.59])\n\tby dpdk.org (Postfix) with ESMTP id 40E591C393\n\tfor <dev@dpdk.org>; Wed, 19 Jun 2019 17:15:43 +0200 (CEST)",
            "from troi.prod.arr (mail.arr [10.99.0.5])\n\tby mx0.arrikto.com (Postfix) with ESMTP id 129AE182014;\n\tWed, 19 Jun 2019 18:15:43 +0300 (EEST)",
            "from localhost.localdomain (unknown [10.89.50.133])\n\tby troi.prod.arr (Postfix) with ESMTPSA id 5689F2B2;\n\tWed, 19 Jun 2019 18:15:42 +0300 (EEST)"
        ],
        "From": "Nikos Dragazis <ndragazis@arrikto.com>",
        "To": "dev@dpdk.org",
        "Cc": "Maxime Coquelin <maxime.coquelin@redhat.com>,\n\tTiwei Bie <tiwei.bie@intel.com>, Zhihong Wang <zhihong.wang@intel.com>,\n\tStefan Hajnoczi <stefanha@redhat.com>, Wei Wang <wei.w.wang@intel.com>,\n\tStojaczyk Dariusz <dariusz.stojaczyk@intel.com>,\n\tVangelis Koukis <vkoukis@arrikto.com>",
        "Date": "Wed, 19 Jun 2019 18:14:41 +0300",
        "Message-Id": "<1560957293-17294-17-git-send-email-ndragazis@arrikto.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1560957293-17294-1-git-send-email-ndragazis@arrikto.com>",
        "References": "<1560957293-17294-1-git-send-email-ndragazis@arrikto.com>",
        "Subject": "[dpdk-dev] [PATCH 16/28] vhost: move postcopy live migration code",
        "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": "Postcopy live migration is an AF_UNIX-bound feature due to the\nuserfaultfd mechanism. Therefore, this patch moves the relevant code from\nvhost_user.c to trans_af_unix.c and exposes this functionality via\ntransport-specific functions. Any other vhost-user transport\ncould potentially implement this feature by implementing these\ntransport-specific functions.\n\nSigned-off-by: Nikos Dragazis <ndragazis@arrikto.com>\n---\n lib/librte_vhost/trans_af_unix.c | 94 ++++++++++++++++++++++++++++++++++++++--\n lib/librte_vhost/vhost.c         |  1 -\n lib/librte_vhost/vhost.h         | 41 ++++++++++++++++--\n lib/librte_vhost/vhost_user.c    | 61 ++------------------------\n 4 files changed, 131 insertions(+), 66 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/trans_af_unix.c b/lib/librte_vhost/trans_af_unix.c\nindex a451880..4ccf9a7 100644\n--- a/lib/librte_vhost/trans_af_unix.c\n+++ b/lib/librte_vhost/trans_af_unix.c\n@@ -10,6 +10,7 @@\n #include <sys/un.h>\n #include <sys/types.h>\n #include <sys/ioctl.h>\n+#include <sys/syscall.h>\n #ifdef RTE_LIBRTE_VHOST_POSTCOPY\n #include <linux/userfaultfd.h>\n #endif\n@@ -39,6 +40,9 @@ struct vhost_user_connection {\n \tint slave_req_fd;\n \trte_spinlock_t slave_req_lock;\n \n+\tint postcopy_ufd;\n+\tint postcopy_listening;\n+\n \tTAILQ_ENTRY(vhost_user_connection) next;\n };\n \n@@ -261,6 +265,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)\n \tconn->slave_req_fd = -1;\n \tconn->vsocket = vsocket;\n \trte_spinlock_init(&conn->slave_req_lock);\n+\tconn->postcopy_ufd = -1;\n \n \tsize = strnlen(vsocket->path, PATH_MAX);\n \tvhost_set_ifname(dev->vid, vsocket->path, size);\n@@ -772,6 +777,13 @@ af_unix_cleanup_device(struct virtio_net *dev, int destroy __rte_unused)\n \t\tclose(conn->slave_req_fd);\n \t\tconn->slave_req_fd = -1;\n \t}\n+\n+\tif (conn->postcopy_ufd >= 0) {\n+\t\tclose(conn->postcopy_ufd);\n+\t\tconn->postcopy_ufd = -1;\n+\t}\n+\n+\tconn->postcopy_listening = 0;\n }\n \n static int\n@@ -866,7 +878,7 @@ af_unix_map_mem_regions(struct virtio_net *dev, struct VhostUserMsg *msg)\n \t\t\talignment,\n \t\t\tmmap_offset);\n \n-\t\tif (dev->postcopy_listening) {\n+\t\tif (conn->postcopy_listening) {\n \t\t\t/*\n \t\t\t * We haven't a better way right now than sharing\n \t\t\t * DPDK's virtual address with Qemu, so that Qemu can\n@@ -877,7 +889,7 @@ af_unix_map_mem_regions(struct virtio_net *dev, struct VhostUserMsg *msg)\n \t\t}\n \t}\n \n-\tif (dev->postcopy_listening) {\n+\tif (conn->postcopy_listening) {\n \t\t/* Send the addresses back to qemu */\n \t\tmsg->fd_num = 0;\n \t\t/* Send reply */\n@@ -918,11 +930,11 @@ af_unix_map_mem_regions(struct virtio_net *dev, struct VhostUserMsg *msg)\n \t\t\treg_struct.range.len = reg->mmap_size;\n \t\t\treg_struct.mode = UFFDIO_REGISTER_MODE_MISSING;\n \n-\t\t\tif (ioctl(dev->postcopy_ufd, UFFDIO_REGISTER,\n+\t\t\tif (ioctl(conn->postcopy_ufd, UFFDIO_REGISTER,\n \t\t\t\t\t\t&reg_struct)) {\n \t\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n \t\t\t\t\t\"Failed to register ufd for region %d: (ufd = %d) %s\\n\",\n-\t\t\t\t\ti, dev->postcopy_ufd,\n+\t\t\t\t\ti, conn->postcopy_ufd,\n \t\t\t\t\tstrerror(errno));\n \t\t\t\treturn -1;\n \t\t\t}\n@@ -990,6 +1002,77 @@ af_unix_set_log_base(struct virtio_net *dev, const struct VhostUserMsg *msg)\n \treturn 0;\n }\n \n+static int\n+af_unix_set_postcopy_advise(struct virtio_net *dev, struct VhostUserMsg *msg)\n+{\n+\tstruct vhost_user_connection *conn =\n+\t\tcontainer_of(dev, struct vhost_user_connection, device);\n+#ifdef RTE_LIBRTE_VHOST_POSTCOPY\n+\tstruct uffdio_api api_struct;\n+\n+\tconn->postcopy_ufd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);\n+\n+\tif (conn->postcopy_ufd == -1) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"Userfaultfd not available: %s\\n\",\n+\t\t\tstrerror(errno));\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t}\n+\tapi_struct.api = UFFD_API;\n+\tapi_struct.features = 0;\n+\tif (ioctl(conn->postcopy_ufd, UFFDIO_API, &api_struct)) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG, \"UFFDIO_API ioctl failure: %s\\n\",\n+\t\t\tstrerror(errno));\n+\t\tclose(conn->postcopy_ufd);\n+\t\tconn->postcopy_ufd = -1;\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t}\n+\tmsg->fds[0] = conn->postcopy_ufd;\n+\tmsg->fd_num = 1;\n+\n+\treturn RTE_VHOST_MSG_RESULT_REPLY;\n+#else\n+\tconn->postcopy_ufd = -1;\n+\tmsg->fd_num = 0;\n+\n+\treturn RTE_VHOST_MSG_RESULT_ERR;\n+#endif\n+}\n+\n+static int\n+af_unix_set_postcopy_listen(struct virtio_net *dev)\n+{\n+\tstruct vhost_user_connection *conn =\n+\t\tcontainer_of(dev, struct vhost_user_connection, device);\n+\n+\tif (dev->mem && dev->mem->nregions) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"Regions already registered at postcopy-listen\\n\");\n+\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n+\t}\n+\tconn->postcopy_listening = 1;\n+\n+\treturn RTE_VHOST_MSG_RESULT_OK;\n+}\n+\n+static int\n+af_unix_set_postcopy_end(struct virtio_net *dev, struct VhostUserMsg *msg)\n+{\n+\tstruct vhost_user_connection *conn =\n+\t\tcontainer_of(dev, struct vhost_user_connection, device);\n+\n+\tconn->postcopy_listening = 0;\n+\tif (conn->postcopy_ufd >= 0) {\n+\t\tclose(conn->postcopy_ufd);\n+\t\tconn->postcopy_ufd = -1;\n+\t}\n+\n+\tmsg->payload.u64 = 0;\n+\tmsg->size = sizeof(msg->payload.u64);\n+\tmsg->fd_num = 0;\n+\n+\treturn RTE_VHOST_MSG_RESULT_REPLY;\n+}\n+\n const struct vhost_transport_ops af_unix_trans_ops = {\n \t.socket_size = sizeof(struct af_unix_socket),\n \t.device_size = sizeof(struct vhost_user_connection),\n@@ -1005,4 +1088,7 @@ const struct vhost_transport_ops af_unix_trans_ops = {\n \t.map_mem_regions = af_unix_map_mem_regions,\n \t.unmap_mem_regions = af_unix_unmap_mem_regions,\n \t.set_log_base = af_unix_set_log_base,\n+\t.set_postcopy_advise = af_unix_set_postcopy_advise,\n+\t.set_postcopy_listen = af_unix_set_postcopy_listen,\n+\t.set_postcopy_end = af_unix_set_postcopy_end,\n };\ndiff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c\nindex 5b16390..91a286d 100644\n--- a/lib/librte_vhost/vhost.c\n+++ b/lib/librte_vhost/vhost.c\n@@ -512,7 +512,6 @@ vhost_new_device(const struct vhost_transport_ops *trans_ops)\n \tdev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET;\n \tdev->trans_ops = trans_ops;\n \tdev->vdpa_dev_id = -1;\n-\tdev->postcopy_ufd = -1;\n \n \treturn dev;\n }\ndiff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h\nindex b15d223..f5d6dc8 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -450,6 +450,44 @@ struct vhost_transport_ops {\n \t */\n \tint (*set_log_base)(struct virtio_net *dev,\n \t\t\t    const struct VhostUserMsg *msg);\n+\n+\t/**\n+\t * Register a userfault fd and send it to master.\n+\t *\n+\t * @param dev\n+\t *  vhost device\n+\t * @param msg\n+\t *  message\n+\t * @return\n+\t *  RTE_VHOST_MSG_RESULT_REPLY on success,\n+\t *  RTE_VHOST_MSG_RESULT_ERR on failure\n+\t */\n+\tint (*set_postcopy_advise)(struct virtio_net *dev,\n+\t\t\t\t   struct VhostUserMsg *msg);\n+\n+\t/**\n+\t * Change live migration mode (entering postcopy mode).\n+\t *\n+\t * @param dev\n+\t *  vhost device\n+\t * @return\n+\t *  RTE_VHOST_MSG_RESULT_OK on success,\n+\t *  RTE_VHOST_MSG_RESULT_ERR on failure\n+\t */\n+\tint (*set_postcopy_listen)(struct virtio_net *dev);\n+\n+\t/**\n+\t * Register completion of postcopy live migration.\n+\t *\n+\t * @param dev\n+\t *  vhost device\n+\t * @param msg\n+\t *  message\n+\t * @return\n+\t *  RTE_VHOST_MSG_RESULT_REPLY\n+\t */\n+\tint (*set_postcopy_end)(struct virtio_net *dev,\n+\t\t\t\tstruct VhostUserMsg *msg);\n };\n \n /** The traditional AF_UNIX vhost-user protocol transport. */\n@@ -492,9 +530,6 @@ struct virtio_net {\n \tuint32_t\t\tmax_guest_pages;\n \tstruct guest_page       *guest_pages;\n \n-\tint\t\t\tpostcopy_ufd;\n-\tint\t\t\tpostcopy_listening;\n-\n \t/*\n \t * Device id to identify a specific backend device.\n \t * It's set to -1 for the default software implementation.\ndiff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex d3c9c5f..29c99e7 100644\n--- a/lib/librte_vhost/vhost_user.c\n+++ b/lib/librte_vhost/vhost_user.c\n@@ -29,14 +29,10 @@\n #include <sys/mman.h>\n #include <sys/types.h>\n #include <sys/stat.h>\n-#include <sys/syscall.h>\n #include <assert.h>\n #ifdef RTE_LIBRTE_VHOST_NUMA\n #include <numaif.h>\n #endif\n-#ifdef RTE_LIBRTE_VHOST_POSTCOPY\n-#include <linux/userfaultfd.h>\n-#endif\n \n #include <rte_common.h>\n #include <rte_malloc.h>\n@@ -136,13 +132,6 @@ vhost_backend_cleanup(struct virtio_net *dev)\n \n \tfree(dev->guest_pages);\n \tdev->guest_pages = NULL;\n-\n-\tif (dev->postcopy_ufd >= 0) {\n-\t\tclose(dev->postcopy_ufd);\n-\t\tdev->postcopy_ufd = -1;\n-\t}\n-\n-\tdev->postcopy_listening = 0;\n }\n \n /*\n@@ -1471,35 +1460,8 @@ vhost_user_set_postcopy_advise(struct virtio_net **pdev,\n \t\t\tstruct VhostUserMsg *msg)\n {\n \tstruct virtio_net *dev = *pdev;\n-#ifdef RTE_LIBRTE_VHOST_POSTCOPY\n-\tstruct uffdio_api api_struct;\n-\n-\tdev->postcopy_ufd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);\n-\n-\tif (dev->postcopy_ufd == -1) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"Userfaultfd not available: %s\\n\",\n-\t\t\tstrerror(errno));\n-\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n-\t}\n-\tapi_struct.api = UFFD_API;\n-\tapi_struct.features = 0;\n-\tif (ioctl(dev->postcopy_ufd, UFFDIO_API, &api_struct)) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"UFFDIO_API ioctl failure: %s\\n\",\n-\t\t\tstrerror(errno));\n-\t\tclose(dev->postcopy_ufd);\n-\t\tdev->postcopy_ufd = -1;\n-\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n-\t}\n-\tmsg->fds[0] = dev->postcopy_ufd;\n-\tmsg->fd_num = 1;\n-\n-\treturn RTE_VHOST_MSG_RESULT_REPLY;\n-#else\n-\tdev->postcopy_ufd = -1;\n-\tmsg->fd_num = 0;\n \n-\treturn RTE_VHOST_MSG_RESULT_ERR;\n-#endif\n+\treturn dev->trans_ops->set_postcopy_advise(dev, msg);\n }\n \n static int\n@@ -1508,14 +1470,7 @@ vhost_user_set_postcopy_listen(struct virtio_net **pdev,\n {\n \tstruct virtio_net *dev = *pdev;\n \n-\tif (dev->mem && dev->mem->nregions) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"Regions already registered at postcopy-listen\\n\");\n-\t\treturn RTE_VHOST_MSG_RESULT_ERR;\n-\t}\n-\tdev->postcopy_listening = 1;\n-\n-\treturn RTE_VHOST_MSG_RESULT_OK;\n+\treturn dev->trans_ops->set_postcopy_listen(dev);\n }\n \n static int\n@@ -1523,17 +1478,7 @@ vhost_user_postcopy_end(struct virtio_net **pdev, struct VhostUserMsg *msg)\n {\n \tstruct virtio_net *dev = *pdev;\n \n-\tdev->postcopy_listening = 0;\n-\tif (dev->postcopy_ufd >= 0) {\n-\t\tclose(dev->postcopy_ufd);\n-\t\tdev->postcopy_ufd = -1;\n-\t}\n-\n-\tmsg->payload.u64 = 0;\n-\tmsg->size = sizeof(msg->payload.u64);\n-\tmsg->fd_num = 0;\n-\n-\treturn RTE_VHOST_MSG_RESULT_REPLY;\n+\treturn dev->trans_ops->set_postcopy_end(dev, msg);\n }\n \n typedef int (*vhost_message_handler_t)(struct virtio_net **pdev,\n",
    "prefixes": [
        "16/28"
    ]
}