get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 132421,
    "url": "http://patchwork.dpdk.org/api/patches/132421/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20231009110356.15382-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": "<20231009110356.15382-1-artur.paszkiewicz@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20231009110356.15382-1-artur.paszkiewicz@intel.com",
    "date": "2023-10-09T11:03:56",
    "name": "[v2] mem: allow using ASan in multi-process mode",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "e8407d0107b384418b0bb2d0ee2b4eb6bec91a00",
    "submitter": {
        "id": 3175,
        "url": "http://patchwork.dpdk.org/api/people/3175/?format=api",
        "name": "Artur Paszkiewicz",
        "email": "artur.paszkiewicz@intel.com"
    },
    "delegate": {
        "id": 24651,
        "url": "http://patchwork.dpdk.org/api/users/24651/?format=api",
        "username": "dmarchand",
        "first_name": "David",
        "last_name": "Marchand",
        "email": "david.marchand@redhat.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20231009110356.15382-1-artur.paszkiewicz@intel.com/mbox/",
    "series": [
        {
            "id": 29769,
            "url": "http://patchwork.dpdk.org/api/series/29769/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=29769",
            "date": "2023-10-09T11:03:56",
            "name": "[v2] mem: allow using ASan in multi-process mode",
            "version": 2,
            "mbox": "http://patchwork.dpdk.org/series/29769/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/132421/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/132421/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 31E884233B;\n\tMon,  9 Oct 2023 13:04:10 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 073A640282;\n\tMon,  9 Oct 2023 13:04:10 +0200 (CEST)",
            "from mgamail.intel.com (mgamail.intel.com [198.175.65.9])\n by mails.dpdk.org (Postfix) with ESMTP id E5C7F4026B\n for <dev@dpdk.org>; Mon,  9 Oct 2023 13:04:08 +0200 (CEST)",
            "from orsmga005.jf.intel.com ([10.7.209.41])\n by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 09 Oct 2023 04:04:09 -0700",
            "from apaszkie-mobl2.apaszkie-mobl2 (HELO apaszkie-mobl2.intel.com)\n ([10.213.16.91])\n by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 09 Oct 2023 04:04:01 -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=1696849450; x=1728385450;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=riD77xNq/eL7pQJiW/fOyNM0U5YQVdP51V+ZmCxmifY=;\n b=OL/ussMOD/96BH/Huyp7+/pZFf5zT0jHVWu7mRma0+171aeS7G2MGcGK\n GFKHhqnybgsWpSi+5ZBreVQoUYyrp/zMLCZQNJF0WXyl6FtY/m5/jiUfA\n Nohlt1BXYSM2N5shMVjleSqXLC5Jd5k5/wgRpxSfTWRxGTda9t7B69kjm\n dxssPmSdrhdIasYpJbVKSOxuDvDdAPFbR9DJhq+i7JgGJN8SJz/1wl8a3\n yBLnGo/L46EauEfTpc55z3ZanwONycr+l5McBcUG+oHJzj2EqM3a/GbUu\n WTXkg7Bo8mgU93zxW9QHnP+9vs9tj9MXwPb6Los5SVFbxoRr+/Q4NlpG7 A==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6600,9927,10857\"; a=\"2716273\"",
            "E=Sophos;i=\"6.03,210,1694761200\";\n   d=\"scan'208\";a=\"2716273\"",
            "E=McAfee;i=\"6600,9927,10857\"; a=\"926727441\"",
            "E=Sophos;i=\"6.03,210,1694761200\"; d=\"scan'208\";a=\"926727441\""
        ],
        "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 v2] mem: allow using ASan in multi-process mode",
        "Date": "Mon,  9 Oct 2023 13:03:56 +0200",
        "Message-Id": "<20231009110356.15382-1-artur.paszkiewicz@intel.com>",
        "X-Mailer": "git-send-email 2.35.3",
        "In-Reply-To": "<20231004142308.15395-1-artur.paszkiewicz@intel.com>",
        "References": "<20231004142308.15395-1-artur.paszkiewicz@intel.com>",
        "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---\nv2:\n- Added checks for config options disabling multi-process support.\n- Fixed missing unmap in legacy mode.\n\n lib/eal/common/eal_common_memory.c |  9 +++\n lib/eal/common/eal_private.h       | 22 +++++++\n lib/eal/linux/eal_memalloc.c       |  9 ++-\n lib/eal/linux/eal_memory.c         | 97 ++++++++++++++++++++++++++++++\n lib/eal/linux/meson.build          |  4 ++\n 5 files changed, 140 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c\nindex d9433db623..15f950810b 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,9 @@ 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 \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..3dca532874 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@@ -1469,6 +1470,9 @@ eal_legacy_hugepage_init(void)\n \t\tif (msl->memseg_arr.count > 0)\n \t\t\tcontinue;\n \t\t/* this is an unused list, deallocate it */\n+#ifdef RTE_MALLOC_ASAN\n+\t\teal_memseg_list_unmap_asan_shadow(msl);\n+#endif\n \t\tmem_sz = msl->len;\n \t\tmunmap(msl->base_va, mem_sz);\n \t\tmsl->base_va = NULL;\n@@ -1956,3 +1960,96 @@ 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;\n+\tvoid *shadow_addr;\n+\tsize_t shadow_sz;\n+\tint shm_oflag;\n+\tchar shm_path[PATH_MAX];\n+\tint shm_fd;\n+\tint ret = 0;\n+\n+\tif (!msl->heap || internal_conf->hugepage_file.unlink_before_mapping ||\n+\t    internal_conf->no_shconf || internal_conf->no_hugetlbfs)\n+\t\treturn 0;\n+\n+\tshadow_addr = ASAN_MEM_TO_SHADOW(msl->base_va);\n+\tshadow_sz = msl->len >> ASAN_SHADOW_SCALE;\n+\n+\tsnprintf(shm_path, sizeof(shm_path), \"/%s_%s_shadow\",\n+\t\teal_get_hugefile_prefix(), msl->memseg_arr.name);\n+\n+\tshm_oflag = O_RDWR;\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\tret = -1;\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 || internal_conf->hugepage_file.unlink_before_mapping ||\n+\t    internal_conf->no_shconf || internal_conf->no_hugetlbfs)\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": [
        "v2"
    ]
}