get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 97660,
    "url": "http://patchwork.dpdk.org/api/patches/97660/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20210901053044.109901-3-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": "<20210901053044.109901-3-xuan.ding@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210901053044.109901-3-xuan.ding@intel.com",
    "date": "2021-09-01T05:30:44",
    "name": "[2/2] vhost: enable IOMMU for async vhost",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "b9497681e50ccbfd297f6d9f15bed1624917029b",
    "submitter": {
        "id": 1401,
        "url": "http://patchwork.dpdk.org/api/people/1401/?format=api",
        "name": "Ding, Xuan",
        "email": "xuan.ding@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20210901053044.109901-3-xuan.ding@intel.com/mbox/",
    "series": [
        {
            "id": 18590,
            "url": "http://patchwork.dpdk.org/api/series/18590/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=18590",
            "date": "2021-09-01T05:30:42",
            "name": "*** support IOMMU for DMA device ***",
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/18590/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/97660/comments/",
    "check": "success",
    "checks": "http://patchwork.dpdk.org/api/patches/97660/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 BBD0FA0C53;\n\tWed,  1 Sep 2021 07:42:47 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id ABFDC40698;\n\tWed,  1 Sep 2021 07:42:45 +0200 (CEST)",
            "from mga11.intel.com (mga11.intel.com [192.55.52.93])\n by mails.dpdk.org (Postfix) with ESMTP id 21E7C40041\n for <dev@dpdk.org>; Wed,  1 Sep 2021 07:42:42 +0200 (CEST)",
            "from fmsmga008.fm.intel.com ([10.253.24.58])\n by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 31 Aug 2021 22:42:28 -0700",
            "from dpdk-xuanding-dev2.sh.intel.com ([10.67.119.115])\n by fmsmga008.fm.intel.com with ESMTP; 31 Aug 2021 22:42:19 -0700"
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,10093\"; a=\"215504646\"",
            "E=Sophos;i=\"5.84,368,1620716400\"; d=\"scan'208\";a=\"215504646\"",
            "E=Sophos;i=\"5.84,368,1620716400\"; d=\"scan'208\";a=\"498578398\""
        ],
        "X-ExtLoop1": "1",
        "From": "Xuan Ding <xuan.ding@intel.com>",
        "To": "dev@dpdk.org, anatoly.burakov@intel.com, maxime.coquelin@redhat.com,\n chenbo.xia@intel.com",
        "Cc": "jiayu.hu@intel.com, bruce.richardson@intel.com, sunil.pai.g@intel.com,\n Xuan Ding <xuan.ding@intel.com>",
        "Date": "Wed,  1 Sep 2021 05:30:44 +0000",
        "Message-Id": "<20210901053044.109901-3-xuan.ding@intel.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20210901053044.109901-1-xuan.ding@intel.com>",
        "References": "<20210901053044.109901-1-xuan.ding@intel.com>",
        "Subject": "[dpdk-dev] [PATCH 2/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 lib/vhost/vhost_user.c | 46 +++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 45 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c\nindex 031c578e54..48617fc708 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@@ -153,6 +184,9 @@ free_mem_region(struct virtio_net *dev)\n \tfor (i = 0; i < dev->mem->nregions; i++) {\n \t\treg = &dev->mem->regions[i];\n \t\tif (reg->host_user_addr) {\n+\t\t\tif (dev->async_copy && rte_vfio_is_enabled(\"vfio\"))\n+\t\t\t\tasync_dma_map(reg, false);\n+\n \t\t\tmunmap(reg->mmap_addr, reg->mmap_size);\n \t\t\tclose(reg->fd);\n \t\t}\n@@ -1157,6 +1191,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@@ -1210,13 +1245,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 (rte_vfio_is_enabled(\"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": [
        "2/2"
    ]
}