get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 132306,
    "url": "http://patchwork.dpdk.org/api/patches/132306/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20231004142308.15395-1-artur.paszkiewicz@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": "<20231004142308.15395-1-artur.paszkiewicz@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20231004142308.15395-1-artur.paszkiewicz@intel.com",
    "date": "2023-10-04T14:23:08",
    "name": "mem: allow using ASan in multi-process mode",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "fcde88d768c9480b6adfd41e77517bf1b04de0df",
    "submitter": {
        "id": 3175,
        "url": "http://patchwork.dpdk.org/api/people/3175/?format=api",
        "name": "Artur Paszkiewicz",
        "email": "artur.paszkiewicz@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/20231004142308.15395-1-artur.paszkiewicz@intel.com/mbox/",
    "series": [
        {
            "id": 29736,
            "url": "http://patchwork.dpdk.org/api/series/29736/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=29736",
            "date": "2023-10-04T14:23:08",
            "name": "mem: allow using ASan in multi-process mode",
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/29736/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/132306/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/132306/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 8A5EF426B7;\n\tWed,  4 Oct 2023 16:23:32 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 5981D402A9;\n\tWed,  4 Oct 2023 16:23:32 +0200 (CEST)",
            "from mgamail.intel.com (mgamail.intel.com [134.134.136.126])\n by mails.dpdk.org (Postfix) with ESMTP id 94705402A9\n for <dev@dpdk.org>; Wed,  4 Oct 2023 16:23:30 +0200 (CEST)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 04 Oct 2023 07:23:19 -0700",
            "from apaszkie-mobl2.igk.intel.com ([10.237.141.77])\n by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 04 Oct 2023 07:23:18 -0700"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1696429410; x=1727965410;\n h=from:to:cc:subject:date:message-id:mime-version:\n content-transfer-encoding;\n bh=CflvDlrwz0ACZtbH54pLXbmEB2vuq/6vQs08NPZlM4M=;\n b=IvzW7e/G0ubLgwuujCL6XBdDs06C27xXu7woh+5DLW0KdYz1gg/ZXVDM\n 58v0wtH/o65O/x9VPw+O7zs2Q7zQLTr6Z/oVOmseCxChRb2kx6VM7CoDn\n b8KHf6TEYD2SokFG/LCPHL1Ty47O/fHa9JZdNbtQkwEhuS2wThubhLa56\n 6DEDpStOZ8G0bOUcXqE0ihPEFlxPeMDslGR8tCDu4BpeI+61Drl10jUcx\n 0ts4Zs4jL98hQd4spxf40i3YoatxTysvayQv3dNuC2qZ+tBVlMzZ5rA1Q\n tojQqGecwPrlyGduhNOzSE/dBDzFx3pwlYYK6WLNxwp7iQYiPN2G+ptGX A==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6600,9927,10853\"; a=\"368238498\"",
            "E=Sophos;i=\"6.03,200,1694761200\"; d=\"scan'208\";a=\"368238498\"",
            "E=McAfee;i=\"6600,9927,10853\"; a=\"751299252\"",
            "E=Sophos;i=\"6.03,200,1694761200\"; d=\"scan'208\";a=\"751299252\""
        ],
        "X-ExtLoop1": "1",
        "From": "Artur Paszkiewicz <artur.paszkiewicz@intel.com>",
        "To": "anatoly.burakov@intel.com",
        "Cc": "dev@dpdk.org,\n\tArtur Paszkiewicz <artur.paszkiewicz@intel.com>",
        "Subject": "[PATCH] mem: allow using ASan in multi-process mode",
        "Date": "Wed,  4 Oct 2023 16:23:08 +0200",
        "Message-Id": "<20231004142308.15395-1-artur.paszkiewicz@intel.com>",
        "X-Mailer": "git-send-email 2.35.3",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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"
    },
    "content": "Multi-process applications operate on shared hugepage memory but each\nprocess has its own ASan shadow region which is not synchronized with\nthe other processes. This causes issues when different processes try to\nuse the same memory because they have their own view of which addresses\nare valid.\n\nFix it by mapping the shadow regions for memseg lists as shared memory.\nThe primary process is responsible for creating and removing the shared\nmemory objects.\n\nDisable ASan instrumentation for triggering the page fault in\nalloc_seg() because if the segment is already allocated by another\nprocess and is marked as free in the shadow, accessing this address will\ncause an ASan error.\n\nSigned-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>\n---\n lib/eal/common/eal_common_memory.c | 10 ++++\n lib/eal/common/eal_private.h       | 22 ++++++++\n lib/eal/linux/eal_memalloc.c       |  9 +++-\n lib/eal/linux/eal_memory.c         | 87 ++++++++++++++++++++++++++++++\n lib/eal/linux/meson.build          |  4 ++\n 5 files changed, 131 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c\nindex d9433db623..2c15d5fc90 100644\n--- a/lib/eal/common/eal_common_memory.c\n+++ b/lib/eal/common/eal_common_memory.c\n@@ -263,6 +263,12 @@ eal_memseg_list_alloc(struct rte_memseg_list *msl, int reserve_flags)\n \tRTE_LOG(DEBUG, EAL, \"VA reserved for memseg list at %p, size %zx\\n\",\n \t\t\taddr, mem_sz);\n \n+#ifdef RTE_MALLOC_ASAN\n+\tif (eal_memseg_list_map_asan_shadow(msl) != 0) {\n+\t\tRTE_LOG(ERR, EAL, \"Failed to map ASan shadow region for memseg list\");\n+\t\treturn -1;\n+\t}\n+#endif\n \treturn 0;\n }\n \n@@ -1050,6 +1056,10 @@ rte_eal_memory_detach(void)\n \t\t\t\tRTE_LOG(ERR, EAL, \"Could not unmap memory: %s\\n\",\n \t\t\t\t\t\trte_strerror(rte_errno));\n \n+#ifdef RTE_MALLOC_ASAN\n+\t\teal_memseg_list_unmap_asan_shadow(msl);\n+#endif\n+\n \t\t/*\n \t\t * we are detaching the fbarray rather than destroying because\n \t\t * other processes might still reference this fbarray, and we\ndiff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h\nindex 5eadba4902..48df338cf9 100644\n--- a/lib/eal/common/eal_private.h\n+++ b/lib/eal/common/eal_private.h\n@@ -300,6 +300,28 @@ eal_memseg_list_alloc(struct rte_memseg_list *msl, int reserve_flags);\n void\n eal_memseg_list_populate(struct rte_memseg_list *msl, void *addr, int n_segs);\n \n+#ifdef RTE_MALLOC_ASAN\n+/**\n+ * Map shared memory for MSL ASan shadow region.\n+ *\n+ * @param msl\n+ *  Memory segment list.\n+ * @return\n+ *  0 on success, (-1) on failure.\n+ */\n+int\n+eal_memseg_list_map_asan_shadow(struct rte_memseg_list *msl);\n+\n+/**\n+ * Unmap the MSL ASan shadow region.\n+ *\n+ * @param msl\n+ *  Memory segment list.\n+ */\n+void\n+eal_memseg_list_unmap_asan_shadow(struct rte_memseg_list *msl);\n+#endif\n+\n /**\n  * Distribute available memory between MSLs.\n  *\ndiff --git a/lib/eal/linux/eal_memalloc.c b/lib/eal/linux/eal_memalloc.c\nindex f8b1588cae..5212ae6b56 100644\n--- a/lib/eal/linux/eal_memalloc.c\n+++ b/lib/eal/linux/eal_memalloc.c\n@@ -511,6 +511,13 @@ resize_hugefile(int fd, uint64_t fa_offset, uint64_t page_sz, bool grow,\n \t\t\tgrow, dirty);\n }\n \n+__rte_no_asan\n+static inline void\n+page_fault(void *addr)\n+{\n+\t*(volatile int *)addr = *(volatile int *)addr;\n+}\n+\n static int\n alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,\n \t\tstruct hugepage_info *hi, unsigned int list_idx,\n@@ -641,7 +648,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,\n \t * that is already there, so read the old value, and write itback.\n \t * kernel populates the page with zeroes initially.\n \t */\n-\t*(volatile int *)addr = *(volatile int *)addr;\n+\tpage_fault(addr);\n \n \tiova = rte_mem_virt2iova(addr);\n \tif (iova == RTE_BAD_PHYS_ADDR) {\ndiff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c\nindex 9b6f08fba8..aabc5a68b3 100644\n--- a/lib/eal/linux/eal_memory.c\n+++ b/lib/eal/linux/eal_memory.c\n@@ -41,6 +41,7 @@\n #include \"eal_filesystem.h\"\n #include \"eal_hugepages.h\"\n #include \"eal_options.h\"\n+#include \"malloc_elem.h\"\n \n #define PFN_MASK_SIZE\t8\n \n@@ -1956,3 +1957,89 @@ rte_eal_memseg_init(void)\n #endif\n \t\t\tmemseg_secondary_init();\n }\n+\n+#ifdef RTE_MALLOC_ASAN\n+int\n+eal_memseg_list_map_asan_shadow(struct rte_memseg_list *msl)\n+{\n+\tconst struct internal_config *internal_conf =\n+\t\t\teal_get_internal_configuration();\n+\tvoid *addr = msl->base_va;\n+\tvoid *shadow_addr = ASAN_MEM_TO_SHADOW(addr);\n+\tsize_t shadow_sz = msl->len >> ASAN_SHADOW_SCALE;\n+\tint shm_oflag = O_RDWR;\n+\tchar shm_path[PATH_MAX];\n+\tint shm_fd;\n+\tint ret = 0;\n+\n+\tif (!msl->heap)\n+\t\treturn 0;\n+\n+\tsnprintf(shm_path, sizeof(shm_path), \"/%s_%s_shadow\",\n+\t\teal_get_hugefile_prefix(), msl->memseg_arr.name);\n+\n+\tif (internal_conf->process_type == RTE_PROC_PRIMARY)\n+\t\tshm_oflag |= O_CREAT | O_TRUNC;\n+\n+\tshm_fd = shm_open(shm_path, shm_oflag, 0600);\n+\tif (shm_fd == -1) {\n+\t\tRTE_LOG(DEBUG, EAL, \"shadow shm_open() failed: %s\\n\",\n+\t\t\tstrerror(errno));\n+\t\treturn -1;\n+\t}\n+\n+\tif (internal_conf->process_type == RTE_PROC_PRIMARY) {\n+\t\tret = ftruncate(shm_fd, shadow_sz);\n+\t\tif (ret == -1) {\n+\t\t\tRTE_LOG(DEBUG, EAL, \"shadow ftruncate() failed: %s\\n\",\n+\t\t\t\tstrerror(errno));\n+\t\t\tgoto out;\n+\t\t}\n+\t}\n+\n+\taddr = mmap(shadow_addr, shadow_sz, PROT_READ | PROT_WRITE,\n+\t\t    MAP_SHARED | MAP_FIXED, shm_fd, 0);\n+\tif (addr == MAP_FAILED) {\n+\t\tRTE_LOG(DEBUG, EAL, \"shadow mmap() failed: %s\\n\",\n+\t\t\tstrerror(errno));\n+\t\tgoto out;\n+\t}\n+\n+\tif (addr != shadow_addr) {\n+\t\tRTE_LOG(DEBUG, EAL, \"wrong shadow mmap() address\\n\");\n+\t\tmunmap(addr, shadow_sz);\n+\t\tret = -1;\n+\t}\n+out:\n+\tclose(shm_fd);\n+\tif (ret != 0) {\n+\t\tif (internal_conf->process_type == RTE_PROC_PRIMARY)\n+\t\t\tshm_unlink(shm_path);\n+\t}\n+\n+\treturn ret;\n+}\n+\n+void\n+eal_memseg_list_unmap_asan_shadow(struct rte_memseg_list *msl)\n+{\n+\tconst struct internal_config *internal_conf =\n+\t\t\teal_get_internal_configuration();\n+\n+\tif (!msl->heap)\n+\t\treturn;\n+\n+\tif (munmap(ASAN_MEM_TO_SHADOW(msl->base_va),\n+\t\t   msl->len >> ASAN_SHADOW_SCALE) != 0)\n+\t\tRTE_LOG(ERR, EAL, \"Could not unmap asan shadow memory: %s\\n\",\n+\t\t\tstrerror(errno));\n+\tif (internal_conf->process_type == RTE_PROC_PRIMARY) {\n+\t\tchar shm_path[PATH_MAX];\n+\n+\t\tsnprintf(shm_path, sizeof(shm_path), \"/%s_%s_shadow\",\n+\t\t\t eal_get_hugefile_prefix(),\n+\t\t\t msl->memseg_arr.name);\n+\t\tshm_unlink(shm_path);\n+\t}\n+}\n+#endif\ndiff --git a/lib/eal/linux/meson.build b/lib/eal/linux/meson.build\nindex e99ebed256..1e8a48c8d3 100644\n--- a/lib/eal/linux/meson.build\n+++ b/lib/eal/linux/meson.build\n@@ -23,3 +23,7 @@ deps += ['kvargs', 'telemetry']\n if has_libnuma\n     dpdk_conf.set10('RTE_EAL_NUMA_AWARE_HUGEPAGES', true)\n endif\n+\n+if dpdk_conf.has('RTE_MALLOC_ASAN')\n+    ext_deps += cc.find_library('rt')\n+endif\n",
    "prefixes": []
}