get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2508,
    "url": "https://patches.dpdk.org/api/patches/2508/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1422242440-28948-9-git-send-email-huawei.xie@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": "<1422242440-28948-9-git-send-email-huawei.xie@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1422242440-28948-9-git-send-email-huawei.xie@intel.com",
    "date": "2015-01-26T03:20:34",
    "name": "[dpdk-dev,RFC,v2,08/14] split set_memory_table into two parts",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "b0d6f088222c9ffb7c6ebc3ad53b57449d2a8e64",
    "submitter": {
        "id": 16,
        "url": "https://patches.dpdk.org/api/people/16/?format=api",
        "name": "Huawei Xie",
        "email": "huawei.xie@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1422242440-28948-9-git-send-email-huawei.xie@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/2508/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/2508/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 [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id EA7DF5AAC;\n\tMon, 26 Jan 2015 04:21:35 +0100 (CET)",
            "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n\tby dpdk.org (Postfix) with ESMTP id 0E22D5A6D\n\tfor <dev@dpdk.org>; Mon, 26 Jan 2015 04:21:25 +0100 (CET)",
            "from fmsmga001.fm.intel.com ([10.253.24.23])\n\tby orsmga101.jf.intel.com with ESMTP; 25 Jan 2015 19:21:24 -0800",
            "from shvmail01.sh.intel.com ([10.239.29.42])\n\tby fmsmga001.fm.intel.com with ESMTP; 25 Jan 2015 19:21:22 -0800",
            "from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com\n\t[10.239.29.90])\n\tby shvmail01.sh.intel.com with ESMTP id t0Q3LKcg014762;\n\tMon, 26 Jan 2015 11:21:21 +0800",
            "from shecgisg003.sh.intel.com (localhost [127.0.0.1])\n\tby shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP\n\tid t0Q3LIxa029039; Mon, 26 Jan 2015 11:21:20 +0800",
            "(from hxie5@localhost)\n\tby shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t0Q3LIEN029035; \n\tMon, 26 Jan 2015 11:21:18 +0800"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.09,466,1418112000\"; d=\"scan'208\";a=\"656346882\"",
        "From": "Huawei Xie <huawei.xie@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Mon, 26 Jan 2015 11:20:34 +0800",
        "Message-Id": "<1422242440-28948-9-git-send-email-huawei.xie@intel.com>",
        "X-Mailer": "git-send-email 1.7.4.1",
        "In-Reply-To": "<1422242440-28948-1-git-send-email-huawei.xie@intel.com>",
        "References": "<1422242440-28948-1-git-send-email-huawei.xie@intel.com>",
        "Subject": "[dpdk-dev] [RFC PATCH v2 08/14] split set_memory_table into two\n\tparts",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Signed-off-by: Huawei Xie <huawei.xie@intel.com>\n---\n lib/librte_vhost/Makefile                     |   2 +-\n lib/librte_vhost/vhost-net.h                  |   5 +-\n lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  |   7 +-\n lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  85 +++++++\n lib/librte_vhost/vhost_cuse/virtio-net-cdev.h |  45 ++++\n lib/librte_vhost/virtio-net.c                 | 306 +-------------------------\n 6 files changed, 145 insertions(+), 305 deletions(-)\n create mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h",
    "diff": "diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile\nindex 0b2f08f..e0d0ef6 100644\n--- a/lib/librte_vhost/Makefile\n+++ b/lib/librte_vhost/Makefile\n@@ -37,7 +37,7 @@ LIB = librte_vhost.a\n CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -I vhost_cuse -O3 -D_FILE_OFFSET_BITS=64 -lfuse\n LDFLAGS += -lfuse\n # all source are stored in SRCS-y\n-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := vhost_cuse/vhost-net-cdev.c virtio-net.c vhost_rxtx.c\n+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := vhost_cuse/vhost-net-cdev.c vhost_cuse/virtio-net-cdev.c virtio-net.c vhost_rxtx.c\n \n # install includes\n SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_virtio_net.h\ndiff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h\nindex 03a5c57..11737cc 100644\n--- a/lib/librte_vhost/vhost-net.h\n+++ b/lib/librte_vhost/vhost-net.h\n@@ -41,6 +41,8 @@\n \n #include <rte_log.h>\n \n+#define VHOST_MEMORY_MAX_NREGIONS 8\n+\n /* Macros for printing using RTE_LOG */\n #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1\n #define RTE_LOGTYPE_VHOST_DATA   RTE_LOGTYPE_USER1\n@@ -92,7 +94,8 @@ struct vhost_net_device_ops {\n \tint (*get_features)(struct vhost_device_ctx, uint64_t *);\n \tint (*set_features)(struct vhost_device_ctx, uint64_t *);\n \n-\tint (*set_mem_table)(struct vhost_device_ctx, const void *, uint32_t);\n+\tint (*set_mem_table)(struct vhost_device_ctx,\n+\t\tconst struct virtio_memory_regions *, uint32_t nregions);\n \n \tint (*set_vring_num)(struct vhost_device_ctx, struct vhost_vring_state *);\n \tint (*set_vring_addr)(struct vhost_device_ctx, struct vhost_vring_addr *);\ndiff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c\nindex 802c7dc..2ddd6e0 100644\n--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c\n+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c\n@@ -46,6 +46,7 @@\n #include <rte_string_fns.h>\n #include <rte_virtio_net.h>\n \n+#include \"virtio-net-cdev.h\"\n #include \"vhost-net.h\"\n #include \"eventfd_link/eventfd_link.h\"\n \n@@ -60,7 +61,7 @@ static const char default_cdev[] = \"vhost-net\";\n static const char eventfd_cdev[] = \"/dev/eventfd-link\";\n \n static struct fuse_session *session;\n-static struct vhost_net_device_ops const *ops;\n+struct vhost_net_device_ops const *ops;\n \n /*\n  * Returns vhost_device_ctx from given fuse_req_t. The index is populated later\n@@ -291,8 +292,8 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,\n \t\t\tbreak;\n \n \t\tdefault:\n-\t\t\tresult = ops->set_mem_table(ctx,\n-\t\t\t\t\tin_buf, mem_temp.nregions);\n+\t\t\tresult = cuse_set_mem_table(ctx, in_buf,\n+\t\t\t\tmem_temp.nregions);\n \t\t\tif (result)\n \t\t\t\tfuse_reply_err(req, EINVAL);\n \t\t\telse\ndiff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c\nindex 58ac3dd..edcbc10 100644\n--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c\n+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c\n@@ -47,7 +47,11 @@\n \n #include <rte_log.h>\n \n+#include \"rte_virtio_net.h\"\n #include \"vhost-net.h\"\n+#include \"virtio-net-cdev.h\"\n+\n+extern struct vhost_net_device_ops const *ops;\n \n /* Line size for reading maps file. */\n static const uint32_t BUFSIZE = PATH_MAX;\n@@ -253,3 +257,84 @@ host_memory_map(pid_t pid, uint64_t addr,\n \n \treturn 0;\n }\n+\n+int\n+cuse_set_mem_table(struct vhost_device_ctx ctx,\n+\tconst struct vhost_memory *mem_regions_addr, uint32_t nregions)\n+{\n+\tuint64_t size = offsetof(struct vhost_memory, regions);\n+\tuint32_t idx, valid_regions;\n+\tstruct virtio_memory_regions regions[VHOST_MEMORY_MAX_NREGIONS];\n+\tstruct vhost_memory_region *mem_regions = (void *)(uintptr_t)\n+\t\t((uint64_t)(uintptr_t)mem_regions_addr + size);\n+\tuint64_t base_address = 0, mapped_address, mapped_size;\n+\n+\tfor (idx = 0; idx < nregions; idx++) {\n+\t\tregions[idx].guest_phys_address =\n+\t\t\tmem_regions[idx].guest_phys_addr;\n+\t\tregions[idx].guest_phys_address_end =\n+\t\t\tregions[idx].guest_phys_address +\n+\t\t\tmem_regions[idx].memory_size;\n+\t\tregions[idx].memory_size =\n+\t\t\tmem_regions[idx].memory_size;\n+\t\tregions[idx].userspace_address =\n+\t\t\tmem_regions[idx].userspace_addr;\n+\n+\t\tLOG_DEBUG(VHOST_CONFIG,\n+\t\t\t\"REGION: %u - GPA: %p - QVA: %p - SIZE (%\"PRIu64\")\\n\",\n+\t\t\tidx,\n+\t\t\t(void *)(uintptr_t)regions[idx].guest_phys_address,\n+\t\t\t(void *)(uintptr_t)regions[idx].userspace_address,\n+\t\t\tregions[idx].memory_size);\n+\n+\t\t/*set the base address mapping*/\n+\t\tif (regions[idx].guest_phys_address == 0x0) {\n+\t\t\tbase_address =\n+\t\t\t\tregions[idx].userspace_address;\n+\t\t\t/* Map VM memory file */\n+\t\t\tif (host_memory_map(ctx.pid, base_address,\n+\t\t\t\t&mapped_address, &mapped_size) != 0) {\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/* Check that we have a valid base address. */\n+\tif (base_address == 0) {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"Failed to find base address of qemu memory file.\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tvalid_regions = nregions;\n+\tfor (idx = 0; idx < nregions; idx++) {\n+\t\tif ((regions[idx].userspace_address < base_address) ||\n+\t\t\t(regions[idx].userspace_address >\n+\t\t\t(base_address + mapped_size)))\n+\t\t\tvalid_regions--;\n+\t}\n+\n+\tif (valid_regions != nregions) {\n+\t\tvalid_regions = 0;\n+\t\tfor (idx = nregions; 0 != idx--; ) {\n+\t\t\tif ((regions[idx].userspace_address < base_address) ||\n+\t\t\t(regions[idx].userspace_address >\n+\t\t\t(base_address + mapped_size))) {\n+\t\t\t\tmemmove(&regions[idx], &regions[idx + 1],\n+\t\t\t\t\tsizeof(struct virtio_memory_regions) *\n+\t\t\t\t\tvalid_regions);\n+\t\t\t} else\n+\t\t\t\tvalid_regions++;\n+\t\t}\n+\t}\n+\n+\tfor (idx = 0; idx < valid_regions; idx++) {\n+\t\tregions[idx].address_offset =\n+\t\t\tmapped_address - base_address +\n+\t\t\tregions[idx].userspace_address -\n+\t\t\tregions[idx].guest_phys_address;\n+\t}\n+\n+\tops->set_mem_table(ctx, &regions[0], valid_regions);\n+\treturn 0;\n+}\ndiff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h\nnew file mode 100644\nindex 0000000..5ee81b1\n--- /dev/null\n+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h\n@@ -0,0 +1,45 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#ifndef _VIRTIO_NET_CDEV_H\n+#define _VIRTIO_NET_CDEV_H\n+\n+#include <stdint.h>\n+#include <linux/vhost.h>\n+\n+#include \"vhost-net.h\"\n+\n+int\n+cuse_set_mem_table(struct vhost_device_ctx ctx,\n+\tconst struct vhost_memory *mem_regions_addr, uint32_t nregions);\n+\n+#endif\ndiff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c\nindex da9e3a6..57a5801 100644\n--- a/lib/librte_vhost/virtio-net.c\n+++ b/lib/librte_vhost/virtio-net.c\n@@ -31,8 +31,6 @@\n  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n  */\n \n-#include <dirent.h>\n-#include <fuse/cuse_lowlevel.h>\n #include <linux/vhost.h>\n #include <linux/virtio_net.h>\n #include <stddef.h>\n@@ -72,26 +70,6 @@ static struct virtio_net_config_ll *ll_root;\n \t\t\t\t(1ULL << VIRTIO_NET_F_CTRL_RX))\n static uint64_t VHOST_FEATURES = VHOST_SUPPORTED_FEATURES;\n \n-/* Line size for reading maps file. */\n-static const uint32_t BUFSIZE = PATH_MAX;\n-\n-/* Size of prot char array in procmap. */\n-#define PROT_SZ 5\n-\n-/* Number of elements in procmap struct. */\n-#define PROCMAP_SZ 8\n-\n-/* Structure containing information gathered from maps file. */\n-struct procmap {\n-\tuint64_t va_start;\t/* Start virtual address in file. */\n-\tuint64_t len;\t\t/* Size of file. */\n-\tuint64_t pgoff;\t\t/* Not used. */\n-\tuint32_t maj;\t\t/* Not used. */\n-\tuint32_t min;\t\t/* Not used. */\n-\tuint32_t ino;\t\t/* Not used. */\n-\tchar prot[PROT_SZ];\t/* Not used. */\n-\tchar fname[PATH_MAX];\t/* File name. */\n-};\n \n /*\n  * Converts QEMU virtual address to Vhost virtual address. This function is\n@@ -118,191 +96,6 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)\n \treturn vhost_va;\n }\n \n-/*\n- * Locate the file containing QEMU's memory space and\n- * map it to our address space.\n- */\n-static int\n-host_memory_map(struct virtio_net *dev, struct virtio_memory *mem,\n-\tpid_t pid, uint64_t addr)\n-{\n-\tstruct dirent *dptr = NULL;\n-\tstruct procmap procmap;\n-\tDIR *dp = NULL;\n-\tint fd;\n-\tint i;\n-\tchar memfile[PATH_MAX];\n-\tchar mapfile[PATH_MAX];\n-\tchar procdir[PATH_MAX];\n-\tchar resolved_path[PATH_MAX];\n-\tchar *path = NULL;\n-\tFILE *fmap;\n-\tvoid *map;\n-\tuint8_t found = 0;\n-\tchar line[BUFSIZE];\n-\tchar dlm[] = \"-   :   \";\n-\tchar *str, *sp, *in[PROCMAP_SZ];\n-\tchar *end = NULL;\n-\n-\t/* Path where mem files are located. */\n-\tsnprintf(procdir, PATH_MAX, \"/proc/%u/fd/\", pid);\n-\t/* Maps file used to locate mem file. */\n-\tsnprintf(mapfile, PATH_MAX, \"/proc/%u/maps\", pid);\n-\n-\tfmap = fopen(mapfile, \"r\");\n-\tif (fmap == NULL) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") Failed to open maps file for pid %d\\n\",\n-\t\t\tdev->device_fh, pid);\n-\t\treturn -1;\n-\t}\n-\n-\t/* Read through maps file until we find out base_address. */\n-\twhile (fgets(line, BUFSIZE, fmap) != 0) {\n-\t\tstr = line;\n-\t\terrno = 0;\n-\t\t/* Split line into fields. */\n-\t\tfor (i = 0; i < PROCMAP_SZ; i++) {\n-\t\t\tin[i] = strtok_r(str, &dlm[i], &sp);\n-\t\t\tif ((in[i] == NULL) || (errno != 0)) {\n-\t\t\t\tfclose(fmap);\n-\t\t\t\treturn -1;\n-\t\t\t}\n-\t\t\tstr = NULL;\n-\t\t}\n-\n-\t\t/* Convert/Copy each field as needed. */\n-\t\tprocmap.va_start = strtoull(in[0], &end, 16);\n-\t\tif ((in[0] == '\\0') || (end == NULL) || (*end != '\\0') ||\n-\t\t\t(errno != 0)) {\n-\t\t\tfclose(fmap);\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tprocmap.len = strtoull(in[1], &end, 16);\n-\t\tif ((in[1] == '\\0') || (end == NULL) || (*end != '\\0') ||\n-\t\t\t(errno != 0)) {\n-\t\t\tfclose(fmap);\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tprocmap.pgoff = strtoull(in[3], &end, 16);\n-\t\tif ((in[3] == '\\0') || (end == NULL) || (*end != '\\0') ||\n-\t\t\t(errno != 0)) {\n-\t\t\tfclose(fmap);\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tprocmap.maj = strtoul(in[4], &end, 16);\n-\t\tif ((in[4] == '\\0') || (end == NULL) || (*end != '\\0') ||\n-\t\t\t(errno != 0)) {\n-\t\t\tfclose(fmap);\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tprocmap.min = strtoul(in[5], &end, 16);\n-\t\tif ((in[5] == '\\0') || (end == NULL) || (*end != '\\0') ||\n-\t\t\t(errno != 0)) {\n-\t\t\tfclose(fmap);\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tprocmap.ino = strtoul(in[6], &end, 16);\n-\t\tif ((in[6] == '\\0') || (end == NULL) || (*end != '\\0') ||\n-\t\t\t(errno != 0)) {\n-\t\t\tfclose(fmap);\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tmemcpy(&procmap.prot, in[2], PROT_SZ);\n-\t\tmemcpy(&procmap.fname, in[7], PATH_MAX);\n-\n-\t\tif (procmap.va_start == addr) {\n-\t\t\tprocmap.len = procmap.len - procmap.va_start;\n-\t\t\tfound = 1;\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\tfclose(fmap);\n-\n-\tif (!found) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") Failed to find memory file in pid %d maps file\\n\",\n-\t\t\tdev->device_fh, pid);\n-\t\treturn -1;\n-\t}\n-\n-\t/* Find the guest memory file among the process fds. */\n-\tdp = opendir(procdir);\n-\tif (dp == NULL) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") Cannot open pid %d process directory\\n\",\n-\t\t\tdev->device_fh, pid);\n-\t\treturn -1;\n-\t}\n-\n-\tfound = 0;\n-\n-\t/* Read the fd directory contents. */\n-\twhile (NULL != (dptr = readdir(dp))) {\n-\t\tsnprintf(memfile, PATH_MAX, \"/proc/%u/fd/%s\",\n-\t\t\t\tpid, dptr->d_name);\n-\t\tpath = realpath(memfile, resolved_path);\n-\t\tif ((path == NULL) && (strlen(resolved_path) == 0)) {\n-\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\t\"(%\"PRIu64\") Failed to resolve fd directory\\n\",\n-\t\t\t\tdev->device_fh);\n-\t\t\tclosedir(dp);\n-\t\t\treturn -1;\n-\t\t}\n-\t\tif (strncmp(resolved_path, procmap.fname,\n-\t\t\tstrnlen(procmap.fname, PATH_MAX)) == 0) {\n-\t\t\tfound = 1;\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\n-\tclosedir(dp);\n-\n-\tif (found == 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") Failed to find memory file for pid %d\\n\",\n-\t\t\tdev->device_fh, pid);\n-\t\treturn -1;\n-\t}\n-\t/* Open the shared memory file and map the memory into this process. */\n-\tfd = open(memfile, O_RDWR);\n-\n-\tif (fd == -1) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") Failed to open %s for pid %d\\n\",\n-\t\t\tdev->device_fh, memfile, pid);\n-\t\treturn -1;\n-\t}\n-\n-\tmap = mmap(0, (size_t)procmap.len, PROT_READ|PROT_WRITE,\n-\t\tMAP_POPULATE|MAP_SHARED, fd, 0);\n-\tclose(fd);\n-\n-\tif (map == MAP_FAILED) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"(%\"PRIu64\") Error mapping the file %s for pid %d\\n\",\n-\t\t\tdev->device_fh, memfile, pid);\n-\t\treturn -1;\n-\t}\n-\n-\t/* Store the memory address and size in the device data structure */\n-\tmem->mapped_address = (uint64_t)(uintptr_t)map;\n-\tmem->mapped_size = procmap.len;\n-\n-\tLOG_DEBUG(VHOST_CONFIG,\n-\t\t\"(%\"PRIu64\") Mem File: %s->%s - Size: %llu - VA: %p\\n\",\n-\t\tdev->device_fh,\n-\t\tmemfile, resolved_path,\n-\t\t(unsigned long long)mem->mapped_size, map);\n-\n-\treturn 0;\n-}\n \n /*\n  * Retrieves an entry from the devices configuration linked list.\n@@ -651,14 +444,12 @@ set_features(struct vhost_device_ctx ctx, uint64_t *pu)\n  * This includes storing offsets used to translate buffer addresses.\n  */\n static int\n-set_mem_table(struct vhost_device_ctx ctx, const void *mem_regions_addr,\n-\tuint32_t nregions)\n+set_mem_table(struct vhost_device_ctx ctx,\n+\tconst struct virtio_memory_regions *regions, uint32_t nregions)\n {\n \tstruct virtio_net *dev;\n-\tstruct vhost_memory_region *mem_regions;\n \tstruct virtio_memory *mem;\n-\tuint64_t size = offsetof(struct vhost_memory, regions);\n-\tuint32_t regionidx, valid_regions;\n+\tuint32_t regionidx;\n \n \tdev = get_device(ctx);\n \tif (dev == NULL)\n@@ -682,104 +473,19 @@ set_mem_table(struct vhost_device_ctx ctx, const void *mem_regions_addr,\n \n \tmem->nregions = nregions;\n \n-\tmem_regions = (void *)(uintptr_t)\n-\t\t\t((uint64_t)(uintptr_t)mem_regions_addr + size);\n-\n \tfor (regionidx = 0; regionidx < mem->nregions; regionidx++) {\n \t\t/* Populate the region structure for each region. */\n-\t\tmem->regions[regionidx].guest_phys_address =\n-\t\t\tmem_regions[regionidx].guest_phys_addr;\n-\t\tmem->regions[regionidx].guest_phys_address_end =\n-\t\t\tmem->regions[regionidx].guest_phys_address +\n-\t\t\tmem_regions[regionidx].memory_size;\n-\t\tmem->regions[regionidx].memory_size =\n-\t\t\tmem_regions[regionidx].memory_size;\n-\t\tmem->regions[regionidx].userspace_address =\n-\t\t\tmem_regions[regionidx].userspace_addr;\n-\n-\t\tLOG_DEBUG(VHOST_CONFIG, \"(%\"PRIu64\") REGION: %u - GPA: %p - QEMU VA: %p - SIZE (%\"PRIu64\")\\n\", dev->device_fh,\n-\t\t\tregionidx,\n-\t\t\t(void *)(uintptr_t)mem->regions[regionidx].guest_phys_address,\n-\t\t\t(void *)(uintptr_t)mem->regions[regionidx].userspace_address,\n-\t\t\tmem->regions[regionidx].memory_size);\n-\n-\t\t/*set the base address mapping*/\n+\t\tmem->regions[regionidx] = regions[regionidx];\n \t\tif (mem->regions[regionidx].guest_phys_address == 0x0) {\n \t\t\tmem->base_address =\n \t\t\t\tmem->regions[regionidx].userspace_address;\n-\t\t\t/* Map VM memory file */\n-\t\t\tif (host_memory_map(dev, mem, ctx.pid,\n-\t\t\t\tmem->base_address) != 0) {\n-\t\t\t\tfree(mem);\n-\t\t\t\treturn -1;\n-\t\t\t}\n+\t\t\tmem->mapped_address =\n+\t\t\t\tmem->regions[regionidx].address_offset;\n \t\t}\n \t}\n \n-\t/* Check that we have a valid base address. */\n-\tif (mem->base_address == 0) {\n-\t\tRTE_LOG(ERR, VHOST_CONFIG, \"(%\"PRIu64\") Failed to find base address of qemu memory file.\\n\", dev->device_fh);\n-\t\tfree(mem);\n-\t\treturn -1;\n-\t}\n-\n-\t/*\n-\t * Check if all of our regions have valid mappings.\n-\t * Usually one does not exist in the QEMU memory file.\n-\t */\n-\tvalid_regions = mem->nregions;\n-\tfor (regionidx = 0; regionidx < mem->nregions; regionidx++) {\n-\t\tif ((mem->regions[regionidx].userspace_address <\n-\t\t\tmem->base_address) ||\n-\t\t\t(mem->regions[regionidx].userspace_address >\n-\t\t\t(mem->base_address + mem->mapped_size)))\n-\t\t\t\tvalid_regions--;\n-\t}\n-\n-\t/*\n-\t * If a region does not have a valid mapping,\n-\t * we rebuild our memory struct to contain only valid entries.\n-\t */\n-\tif (valid_regions != mem->nregions) {\n-\t\tLOG_DEBUG(VHOST_CONFIG, \"(%\"PRIu64\") Not all memory regions exist in the QEMU mem file. Re-populating mem structure\\n\",\n-\t\t\tdev->device_fh);\n-\n-\t\t/*\n-\t\t * Re-populate the memory structure with only valid regions.\n-\t\t * Invalid regions are over-written with memmove.\n-\t\t */\n-\t\tvalid_regions = 0;\n-\n-\t\tfor (regionidx = mem->nregions; 0 != regionidx--;) {\n-\t\t\tif ((mem->regions[regionidx].userspace_address <\n-\t\t\t\tmem->base_address) ||\n-\t\t\t\t(mem->regions[regionidx].userspace_address >\n-\t\t\t\t(mem->base_address + mem->mapped_size))) {\n-\t\t\t\tmemmove(&mem->regions[regionidx],\n-\t\t\t\t\t&mem->regions[regionidx + 1],\n-\t\t\t\t\tsizeof(struct virtio_memory_regions) *\n-\t\t\t\t\t\tvalid_regions);\n-\t\t\t} else {\n-\t\t\t\tvalid_regions++;\n-\t\t\t}\n-\t\t}\n-\t}\n-\tmem->nregions = valid_regions;\n \tdev->mem = mem;\n \n-\t/*\n-\t * Calculate the address offset for each region.\n-\t * This offset is used to identify the vhost virtual address\n-\t * corresponding to a QEMU guest physical address.\n-\t */\n-\tfor (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {\n-\t\tdev->mem->regions[regionidx].address_offset =\n-\t\t\tdev->mem->regions[regionidx].userspace_address -\n-\t\t\t\tdev->mem->base_address +\n-\t\t\t\tdev->mem->mapped_address -\n-\t\t\t\tdev->mem->regions[regionidx].guest_phys_address;\n-\n-\t}\n \treturn 0;\n }\n \n",
    "prefixes": [
        "dpdk-dev",
        "RFC",
        "v2",
        "08/14"
    ]
}