get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 104090,
    "url": "https://patches.dpdk.org/api/patches/104090/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20211110054630.61524-1-xuan.ding@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": "<20211110054630.61524-1-xuan.ding@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20211110054630.61524-1-xuan.ding@intel.com",
    "date": "2021-11-10T05:46:30",
    "name": "vhost: fix physical address mapping",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "68c3c50d9e89a37d069d728da15b409aa822709b",
    "submitter": {
        "id": 1401,
        "url": "https://patches.dpdk.org/api/people/1401/?format=api",
        "name": "Ding, Xuan",
        "email": "xuan.ding@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20211110054630.61524-1-xuan.ding@intel.com/mbox/",
    "series": [
        {
            "id": 20439,
            "url": "https://patches.dpdk.org/api/series/20439/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=20439",
            "date": "2021-11-10T05:46:30",
            "name": "vhost: fix physical address mapping",
            "version": 1,
            "mbox": "https://patches.dpdk.org/series/20439/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/104090/comments/",
    "check": "warning",
    "checks": "https://patches.dpdk.org/api/patches/104090/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 A6F38A034F;\n\tWed, 10 Nov 2021 06:59:52 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 659E04014D;\n\tWed, 10 Nov 2021 06:59:52 +0100 (CET)",
            "from mga05.intel.com (mga05.intel.com [192.55.52.43])\n by mails.dpdk.org (Postfix) with ESMTP id 8E1AC40142\n for <dev@dpdk.org>; Wed, 10 Nov 2021 06:59:50 +0100 (CET)",
            "from orsmga001.jf.intel.com ([10.7.209.18])\n by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 09 Nov 2021 21:59:49 -0800",
            "from dpdk-xuanding-dev2.sh.intel.com ([10.67.119.250])\n by orsmga001.jf.intel.com with ESMTP; 09 Nov 2021 21:59:46 -0800"
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,10163\"; a=\"318811295\"",
            "E=Sophos;i=\"5.87,222,1631602800\"; d=\"scan'208\";a=\"318811295\"",
            "E=Sophos;i=\"5.87,222,1631602800\"; d=\"scan'208\";a=\"533939529\""
        ],
        "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, xingguang.he@intel.com,\n Xuan Ding <xuan.ding@intel.com>",
        "Date": "Wed, 10 Nov 2021 05:46:30 +0000",
        "Message-Id": "<20211110054630.61524-1-xuan.ding@intel.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "Subject": "[dpdk-dev] [PATCH] vhost: fix physical address mapping",
        "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": "When choosing IOVA as PA mode, IOVA is likely to be discontinuous,\nwhich requires page by page mapping for DMA devices. To be consistent,\nthis patch implements page by page mapping instead of mapping at the\nregion granularity for both IOVA as VA and PA mode.\n\nFixes: 7c61fa08b716 (\"vhost: enable IOMMU for async vhost\")\n\nSigned-off-by: Xuan Ding <xuan.ding@intel.com>\n---\n lib/vhost/vhost.h      |   1 +\n lib/vhost/vhost_user.c | 104 ++++++++++++++++++++---------------------\n 2 files changed, 52 insertions(+), 53 deletions(-)",
    "diff": "diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h\nindex 7085e0885c..d246538ca5 100644\n--- a/lib/vhost/vhost.h\n+++ b/lib/vhost/vhost.h\n@@ -355,6 +355,7 @@ struct vring_packed_desc_event {\n struct guest_page {\n \tuint64_t guest_phys_addr;\n \tuint64_t host_phys_addr;\n+\tuint64_t host_user_addr;\n \tuint64_t size;\n };\n \ndiff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c\nindex a781346c4d..560b7ab283 100644\n--- a/lib/vhost/vhost_user.c\n+++ b/lib/vhost/vhost_user.c\n@@ -144,52 +144,54 @@ get_blk_size(int fd)\n }\n \n static int\n-async_dma_map(struct rte_vhost_mem_region *region, bool do_map)\n+async_dma_map(struct virtio_net *dev, bool do_map)\n {\n-\tuint64_t host_iova;\n \tint ret = 0;\n-\n-\thost_iova = rte_mem_virt2iova((void *)(uintptr_t)region->host_user_addr);\n+\tstruct guest_page *page;\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\t/*\n-\t\t\t * DMA device may bind with kernel driver, in this case,\n-\t\t\t * we don't need to program IOMMU manually. However, if no\n-\t\t\t * device is bound with vfio/uio in DPDK, and vfio kernel\n-\t\t\t * module is loaded, the API will still be called and return\n-\t\t\t * with ENODEV/ENOSUP.\n-\t\t\t *\n-\t\t\t * DPDK vfio only returns ENODEV/ENOSUP in very similar\n-\t\t\t * situations(vfio either unsupported, or supported\n-\t\t\t * but no devices found). Either way, no mappings could be\n-\t\t\t * performed. We treat it as normal case in async path.\n-\t\t\t */\n-\t\t\tif (rte_errno == ENODEV || rte_errno == ENOTSUP)\n+\t\tfor (uint32_t i = 0; i < dev->nr_guest_pages; i++) {\n+\t\t\tpage = &dev->guest_pages[i];\n+\t\t\tret = rte_vfio_container_dma_map(RTE_VFIO_DEFAULT_CONTAINER_FD,\n+\t\t\t\t\t\t\t page->host_user_addr,\n+\t\t\t\t\t\t\t page->host_phys_addr,\n+\t\t\t\t\t\t\t page->size);\n+\t\t\tif (ret) {\n+\t\t\t\t/*\n+\t\t\t\t* DMA device may bind with kernel driver, in this case,\n+\t\t\t\t* we don't need to program IOMMU manually. However, if no\n+\t\t\t\t* device is bound with vfio/uio in DPDK, and vfio kernel\n+\t\t\t\t* module is loaded, the API will still be called and return\n+\t\t\t\t* with ENODEV/ENOSUP.\n+\t\t\t\t*\n+\t\t\t\t* DPDK vfio only returns ENODEV/ENOSUP in very similar\n+\t\t\t\t* situations(vfio either unsupported, or supported\n+\t\t\t\t* but no devices found). Either way, no mappings could be\n+\t\t\t\t* performed. We treat it as normal case in async path.\n+\t\t\t\t*/\n+\t\t\t\tif (rte_errno == ENODEV || rte_errno == ENOTSUP)\n+\t\t\t\t\treturn 0;\n+\n+\t\t\t\tVHOST_LOG_CONFIG(ERR, \"DMA engine map failed\\n\");\n+\t\t\t\t/* DMA mapping errors won't stop VHST_USER_SET_MEM_TABLE. */\n \t\t\t\treturn 0;\n-\n-\t\t\tVHOST_LOG_CONFIG(ERR, \"DMA engine map failed\\n\");\n-\t\t\t/* DMA mapping errors won't stop VHST_USER_SET_MEM_TABLE. */\n-\t\t\treturn 0;\n+\t\t\t}\n \t\t}\n \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\t/* like DMA map, ignore the kernel driver case when unmap. */\n-\t\t\tif (rte_errno == EINVAL)\n-\t\t\t\treturn 0;\n+\t\tfor (uint32_t i = 0; i < dev->nr_guest_pages; i++) {\n+\t\t\tpage = &dev->guest_pages[i];\n+\t\t\tret = rte_vfio_container_dma_unmap(RTE_VFIO_DEFAULT_CONTAINER_FD,\n+\t\t\t\t\t\t\t   page->host_user_addr,\n+\t\t\t\t\t\t\t   page->host_phys_addr,\n+\t\t\t\t\t\t\t   page->size);\n+\t\t\tif (ret) {\n+\t\t\t\t/* like DMA map, ignore the kernel driver case when unmap. */\n+\t\t\t\tif (rte_errno == EINVAL)\n+\t\t\t\t\treturn 0;\n \n-\t\t\tVHOST_LOG_CONFIG(ERR, \"DMA engine unmap failed\\n\");\n-\t\t\treturn ret;\n+\t\t\t\tVHOST_LOG_CONFIG(ERR, \"DMA engine unmap failed\\n\");\n+\t\t\t\treturn ret;\n+\t\t\t}\n \t\t}\n \t}\n \n@@ -205,12 +207,12 @@ free_mem_region(struct virtio_net *dev)\n \tif (!dev || !dev->mem)\n \t\treturn;\n \n+\tif (dev->async_copy && rte_vfio_is_enabled(\"vfio\"))\n+\t\tasync_dma_map(dev, false);\n+\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@@ -978,7 +980,7 @@ vhost_user_set_vring_base(struct virtio_net **pdev,\n \n static int\n add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr,\n-\t\t   uint64_t host_phys_addr, uint64_t size)\n+\t\t   uint64_t host_phys_addr, uint64_t host_user_addr, uint64_t size)\n {\n \tstruct guest_page *page, *last_page;\n \tstruct guest_page *old_pages;\n@@ -1009,6 +1011,7 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr,\n \tpage = &dev->guest_pages[dev->nr_guest_pages++];\n \tpage->guest_phys_addr = guest_phys_addr;\n \tpage->host_phys_addr  = host_phys_addr;\n+\tpage->host_user_addr = host_user_addr;\n \tpage->size = size;\n \n \treturn 0;\n@@ -1028,7 +1031,8 @@ add_guest_pages(struct virtio_net *dev, struct rte_vhost_mem_region *reg,\n \tsize = page_size - (guest_phys_addr & (page_size - 1));\n \tsize = RTE_MIN(size, reg_size);\n \n-\tif (add_one_guest_page(dev, guest_phys_addr, host_phys_addr, size) < 0)\n+\tif (add_one_guest_page(dev, guest_phys_addr, host_phys_addr,\n+\t\t\t       host_user_addr, size) < 0)\n \t\treturn -1;\n \n \thost_user_addr  += size;\n@@ -1040,7 +1044,7 @@ add_guest_pages(struct virtio_net *dev, struct rte_vhost_mem_region *reg,\n \t\thost_phys_addr = rte_mem_virt2iova((void *)(uintptr_t)\n \t\t\t\t\t\t  host_user_addr);\n \t\tif (add_one_guest_page(dev, guest_phys_addr, host_phys_addr,\n-\t\t\t\tsize) < 0)\n+\t\t\t\t       host_user_addr, size) < 0)\n \t\t\treturn -1;\n \n \t\thost_user_addr  += size;\n@@ -1215,7 +1219,6 @@ 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@@ -1274,14 +1277,6 @@ vhost_user_mmap_region(struct virtio_net *dev,\n \t\t\tVHOST_LOG_CONFIG(ERR, \"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@@ -1420,6 +1415,9 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,\n \t\tdev->mem->nregions++;\n \t}\n \n+\tif (dev->async_copy && rte_vfio_is_enabled(\"vfio\"))\n+\t\tasync_dma_map(dev, true);\n+\n \tif (vhost_user_postcopy_register(dev, main_fd, msg) < 0)\n \t\tgoto free_mem_table;\n \n",
    "prefixes": []
}