get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 95275,
    "url": "http://patchwork.dpdk.org/api/patches/95275/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20210705081928.98546-2-xuan.ding@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": "<20210705081928.98546-2-xuan.ding@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210705081928.98546-2-xuan.ding@intel.com",
    "date": "2021-07-05T08:19:27",
    "name": "[v4,1/2] vhost: enable IOMMU for async vhost",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "61b390808169a5905f311e6047395b1a17ac0df0",
    "submitter": {
        "id": 1401,
        "url": "http://patchwork.dpdk.org/api/people/1401/?format=api",
        "name": "Ding, Xuan",
        "email": "xuan.ding@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/20210705081928.98546-2-xuan.ding@intel.com/mbox/",
    "series": [
        {
            "id": 17624,
            "url": "http://patchwork.dpdk.org/api/series/17624/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=17624",
            "date": "2021-07-05T08:19:26",
            "name": "vhost: add IOMMU support in async data path",
            "version": 4,
            "mbox": "http://patchwork.dpdk.org/series/17624/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/95275/comments/",
    "check": "success",
    "checks": "http://patchwork.dpdk.org/api/patches/95275/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 10BDCA0A0C;\n\tMon,  5 Jul 2021 10:26:08 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id EAEF64068C;\n\tMon,  5 Jul 2021 10:26:07 +0200 (CEST)",
            "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n by mails.dpdk.org (Postfix) with ESMTP id 27DB64003C\n for <dev@dpdk.org>; Mon,  5 Jul 2021 10:26:04 +0200 (CEST)",
            "from orsmga008.jf.intel.com ([10.7.209.65])\n by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 05 Jul 2021 01:26:03 -0700",
            "from dpdk-xuanding-dev2.sh.intel.com ([10.67.119.115])\n by orsmga008.jf.intel.com with ESMTP; 05 Jul 2021 01:26:00 -0700"
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,10035\"; a=\"208984596\"",
            "E=Sophos;i=\"5.83,325,1616482800\"; d=\"scan'208\";a=\"208984596\"",
            "E=Sophos;i=\"5.83,325,1616482800\"; d=\"scan'208\";a=\"456642364\""
        ],
        "X-ExtLoop1": "1",
        "From": "Xuan Ding <xuan.ding@intel.com>",
        "To": "maxime.coquelin@redhat.com,\n\tchenbo.xia@intel.com",
        "Cc": "dev@dpdk.org, jiayu.hu@intel.com, sunil.pai.g@intel.com,\n bruce.richardson@intel.com, harry.van.haaren@intel.com, yong.liu@intel.com,\n wenwux.ma@intel.com, Xuan Ding <xuan.ding@intel.com>",
        "Date": "Mon,  5 Jul 2021 08:19:27 +0000",
        "Message-Id": "<20210705081928.98546-2-xuan.ding@intel.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20210705081928.98546-1-xuan.ding@intel.com>",
        "References": "<20210531150629.35020-1-xuan.ding@intel.com>\n <20210705081928.98546-1-xuan.ding@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v4 1/2] vhost: enable IOMMU for async vhost",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <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 <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "The use of IOMMU has many advantages, such as isolation and address\ntranslation. This patch extends the capbility of DMA engine to use\nIOMMU if the DMA device is bound to vfio.\n\nWhen set memory table, the guest memory will be mapped\ninto the default container of DPDK.\n\nSigned-off-by: Xuan Ding <xuan.ding@intel.com>\n---\n doc/guides/prog_guide/vhost_lib.rst |  9 ++++++\n lib/vhost/rte_vhost.h               |  1 +\n lib/vhost/socket.c                  |  9 ++++++\n lib/vhost/vhost.h                   |  1 +\n lib/vhost/vhost_user.c              | 46 ++++++++++++++++++++++++++++-\n 5 files changed, 65 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst\nindex 05c42c9b11..c3beda23d9 100644\n--- a/doc/guides/prog_guide/vhost_lib.rst\n+++ b/doc/guides/prog_guide/vhost_lib.rst\n@@ -118,6 +118,15 @@ The following is an overview of some key Vhost API functions:\n \n     It is disabled by default.\n \n+  - ``RTE_VHOST_USER_ASYNC_USE_VFIO``\n+\n+    In asynchronous data path, vhost liarary is not aware of which driver\n+    (igb_uio/vfio) the DMA device is bound to. Application should pass\n+    this flag to tell vhost library whether IOMMU should be programmed\n+    for guest memory.\n+\n+    It is disabled by default.\n+\n   - ``RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS``\n \n     Since v16.04, the vhost library forwards checksum and gso requests for\ndiff --git a/lib/vhost/rte_vhost.h b/lib/vhost/rte_vhost.h\nindex 8d875e9322..a766ea7b6b 100644\n--- a/lib/vhost/rte_vhost.h\n+++ b/lib/vhost/rte_vhost.h\n@@ -37,6 +37,7 @@ extern \"C\" {\n #define RTE_VHOST_USER_LINEARBUF_SUPPORT\t(1ULL << 6)\n #define RTE_VHOST_USER_ASYNC_COPY\t(1ULL << 7)\n #define RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS\t(1ULL << 8)\n+#define RTE_VHOST_USER_ASYNC_USE_VFIO\t(1ULL << 9)\n \n /* Features. */\n #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE\ndiff --git a/lib/vhost/socket.c b/lib/vhost/socket.c\nindex 5d0d728d52..77c722c86b 100644\n--- a/lib/vhost/socket.c\n+++ b/lib/vhost/socket.c\n@@ -42,6 +42,7 @@ struct vhost_user_socket {\n \tbool extbuf;\n \tbool linearbuf;\n \tbool async_copy;\n+\tbool async_use_vfio;\n \tbool net_compliant_ol_flags;\n \n \t/*\n@@ -243,6 +244,13 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)\n \t\t\tdev->async_copy = 1;\n \t}\n \n+\tif (vsocket->async_use_vfio) {\n+\t\tdev = get_device(vid);\n+\n+\t\tif (dev)\n+\t\t\tdev->async_use_vfio = 1;\n+\t}\n+\n \tVHOST_LOG_CONFIG(INFO, \"new device, handle is %d\\n\", vid);\n \n \tif (vsocket->notify_ops->new_connection) {\n@@ -879,6 +887,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)\n \tvsocket->extbuf = flags & RTE_VHOST_USER_EXTBUF_SUPPORT;\n \tvsocket->linearbuf = flags & RTE_VHOST_USER_LINEARBUF_SUPPORT;\n \tvsocket->async_copy = flags & RTE_VHOST_USER_ASYNC_COPY;\n+\tvsocket->async_use_vfio = flags & RTE_VHOST_USER_ASYNC_USE_VFIO;\n \tvsocket->net_compliant_ol_flags = flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS;\n \n \tif (vsocket->async_copy &&\ndiff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h\nindex 8078ddff79..fb775ce4ed 100644\n--- a/lib/vhost/vhost.h\n+++ b/lib/vhost/vhost.h\n@@ -370,6 +370,7 @@ struct virtio_net {\n \tint16_t\t\t\tbroadcast_rarp;\n \tuint32_t\t\tnr_vring;\n \tint\t\t\tasync_copy;\n+\tint\t\t\tasync_use_vfio;\n \tint\t\t\textbuf;\n \tint\t\t\tlinearbuf;\n \tstruct vhost_virtqueue\t*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];\ndiff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c\nindex 8f0eba6412..72459e192f 100644\n--- a/lib/vhost/vhost_user.c\n+++ b/lib/vhost/vhost_user.c\n@@ -45,6 +45,7 @@\n #include <rte_common.h>\n #include <rte_malloc.h>\n #include <rte_log.h>\n+#include <rte_vfio.h>\n \n #include \"iotlb.h\"\n #include \"vhost.h\"\n@@ -141,6 +142,36 @@ get_blk_size(int fd)\n \treturn ret == -1 ? (uint64_t)-1 : (uint64_t)stat.st_blksize;\n }\n \n+static int\n+async_dma_map(struct rte_vhost_mem_region *region, bool do_map)\n+{\n+\tint ret = 0;\n+\tuint64_t host_iova;\n+\thost_iova = rte_mem_virt2iova((void *)(uintptr_t)region->host_user_addr);\n+\tif (do_map) {\n+\t\t/* Add mapped region into the default container of DPDK. */\n+\t\tret = rte_vfio_container_dma_map(RTE_VFIO_DEFAULT_CONTAINER_FD,\n+\t\t\t\t\t\t region->host_user_addr,\n+\t\t\t\t\t\t host_iova,\n+\t\t\t\t\t\t region->size);\n+\t\tif (ret) {\n+\t\t\tVHOST_LOG_CONFIG(ERR, \"DMA engine map failed\\n\");\n+\t\t\treturn ret;\n+\t\t}\n+\t} else {\n+\t\t/* Remove mapped region from the default container of DPDK. */\n+\t\tret = rte_vfio_container_dma_unmap(RTE_VFIO_DEFAULT_CONTAINER_FD,\n+\t\t\t\t\t\t   region->host_user_addr,\n+\t\t\t\t\t\t   host_iova,\n+\t\t\t\t\t\t   region->size);\n+\t\tif (ret) {\n+\t\t\tVHOST_LOG_CONFIG(ERR, \"DMA engine unmap failed\\n\");\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+\n static void\n free_mem_region(struct virtio_net *dev)\n {\n@@ -155,6 +186,9 @@ free_mem_region(struct virtio_net *dev)\n \t\tif (reg->host_user_addr) {\n \t\t\tmunmap(reg->mmap_addr, reg->mmap_size);\n \t\t\tclose(reg->fd);\n+\n+\t\t\tif (dev->async_copy && dev->async_use_vfio)\n+\t\t\t\tasync_dma_map(reg, false);\n \t\t}\n \t}\n }\n@@ -1105,6 +1139,7 @@ vhost_user_mmap_region(struct virtio_net *dev,\n \tuint64_t mmap_size;\n \tuint64_t alignment;\n \tint populate;\n+\tint ret;\n \n \t/* Check for memory_size + mmap_offset overflow */\n \tif (mmap_offset >= -region->size) {\n@@ -1158,13 +1193,22 @@ vhost_user_mmap_region(struct virtio_net *dev,\n \tregion->mmap_size = mmap_size;\n \tregion->host_user_addr = (uint64_t)(uintptr_t)mmap_addr + mmap_offset;\n \n-\tif (dev->async_copy)\n+\tif (dev->async_copy) {\n \t\tif (add_guest_pages(dev, region, alignment) < 0) {\n \t\t\tVHOST_LOG_CONFIG(ERR,\n \t\t\t\t\t\"adding guest pages to region failed.\\n\");\n \t\t\treturn -1;\n \t\t}\n \n+\t\tif (dev->async_use_vfio) {\n+\t\t\tret = async_dma_map(region, true);\n+\t\t\tif (ret) {\n+\t\t\t\tVHOST_LOG_CONFIG(ERR, \"Configure IOMMU for DMA engine failed\\n\");\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n \tVHOST_LOG_CONFIG(INFO,\n \t\t\t\"guest memory region size: 0x%\" PRIx64 \"\\n\"\n \t\t\t\"\\t guest physical addr: 0x%\" PRIx64 \"\\n\"\n",
    "prefixes": [
        "v4",
        "1/2"
    ]
}