get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 37724,
    "url": "http://patches.dpdk.org/api/patches/37724/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/e786eaec63c0204b0bd6c28985904e644b35e4de.1523296701.git.anatoly.burakov@intel.com/",
    "project": {
        "id": 1,
        "url": "http://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": "<e786eaec63c0204b0bd6c28985904e644b35e4de.1523296701.git.anatoly.burakov@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/e786eaec63c0204b0bd6c28985904e644b35e4de.1523296701.git.anatoly.burakov@intel.com",
    "date": "2018-04-09T18:01:01",
    "name": "[dpdk-dev,v5,58/70] eal: share hugepage info primary and secondary",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "a145c91f62bfeef0eeb67519b1a6a7922499ebb3",
    "submitter": {
        "id": 4,
        "url": "http://patches.dpdk.org/api/people/4/?format=api",
        "name": "Anatoly Burakov",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/e786eaec63c0204b0bd6c28985904e644b35e4de.1523296701.git.anatoly.burakov@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/37724/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/37724/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 [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 87E2A1BA83;\n\tMon,  9 Apr 2018 20:03:34 +0200 (CEST)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id 6CF641B8E3\n\tfor <dev@dpdk.org>; Mon,  9 Apr 2018 20:02:07 +0200 (CEST)",
            "from orsmga004.jf.intel.com ([10.7.209.38])\n\tby orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t09 Apr 2018 11:02:06 -0700",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby orsmga004.jf.intel.com with ESMTP; 09 Apr 2018 11:02:02 -0700",
            "from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com\n\t[10.237.217.45])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tw39I22uL031378; Mon, 9 Apr 2018 19:02:02 +0100",
            "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id w39I21e0028470;\n\tMon, 9 Apr 2018 19:02:01 +0100",
            "(from aburakov@localhost)\n\tby sivswdev01.ir.intel.com with LOCAL id w39I21Zb028465;\n\tMon, 9 Apr 2018 19:02:01 +0100"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.48,427,1517904000\"; d=\"scan'208\";a=\"190066652\"",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "Bruce Richardson <bruce.richardson@intel.com>, keith.wiles@intel.com,\n\tjianfeng.tan@intel.com, andras.kovacs@ericsson.com,\n\tlaszlo.vadkeri@ericsson.com, benjamin.walker@intel.com,\n\tthomas@monjalon.net, konstantin.ananyev@intel.com,\n\tkuralamudhan.ramakrishnan@intel.com, louise.m.daly@intel.com,\n\tnelio.laranjeiro@6wind.com, yskoh@mellanox.com, pepperjo@japf.ch,\n\tjerin.jacob@caviumnetworks.com, hemant.agrawal@nxp.com,\n\tolivier.matz@6wind.com, shreyansh.jain@nxp.com,\n\tgowrishankar.m@linux.vnet.ibm.com",
        "Date": "Mon,  9 Apr 2018 19:01:01 +0100",
        "Message-Id": "<e786eaec63c0204b0bd6c28985904e644b35e4de.1523296701.git.anatoly.burakov@intel.com>",
        "X-Mailer": "git-send-email 1.7.0.7",
        "In-Reply-To": [
            "<cover.1523296700.git.anatoly.burakov@intel.com>",
            "<cover.1523296700.git.anatoly.burakov@intel.com>"
        ],
        "References": [
            "<cover.1523296700.git.anatoly.burakov@intel.com>",
            "<cover.1523218215.git.anatoly.burakov@intel.com>\n\t<cover.1523296700.git.anatoly.burakov@intel.com>"
        ],
        "Subject": "[dpdk-dev] [PATCH v5 58/70] eal: share hugepage info primary and\n\tsecondary",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://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": "<https://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": "Since we are going to need to map hugepages in both primary and\nsecondary processes, we need to know where we should look for\nhugetlbfs mountpoints. So, share those with secondary processes,\nand map them on init.\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\nTested-by: Santosh Shukla <Santosh.Shukla@caviumnetworks.com>\nTested-by: Hemant Agrawal <hemant.agrawal@nxp.com>\n---\n lib/librte_eal/bsdapp/eal/eal.c                 |  19 ++--\n lib/librte_eal/bsdapp/eal/eal_hugepage_info.c   |  56 +++++++++--\n lib/librte_eal/bsdapp/eal/eal_memory.c          |  21 +---\n lib/librte_eal/common/eal_common_options.c      |   5 +-\n lib/librte_eal/common/eal_filesystem.h          |  17 ++++\n lib/librte_eal/common/eal_hugepages.h           |  10 +-\n lib/librte_eal/common/eal_internal_cfg.h        |   2 +-\n lib/librte_eal/linuxapp/eal/eal.c               |  18 ++--\n lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 121 ++++++++++++++++++++----\n lib/librte_eal/linuxapp/eal/eal_memory.c        |  15 +--\n 10 files changed, 217 insertions(+), 67 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c\nindex 54330e1..727adc5 100644\n--- a/lib/librte_eal/bsdapp/eal/eal.c\n+++ b/lib/librte_eal/bsdapp/eal/eal.c\n@@ -289,7 +289,7 @@ eal_get_hugepage_mem_size(void)\n \n \tfor (i = 0; i < internal_config.num_hugepage_sizes; i++) {\n \t\tstruct hugepage_info *hpi = &internal_config.hugepage_info[i];\n-\t\tif (hpi->hugedir != NULL) {\n+\t\tif (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0) {\n \t\t\tfor (j = 0; j < RTE_MAX_NUMA_NODES; j++) {\n \t\t\t\tsize += hpi->hugepage_sz * hpi->num_pages[j];\n \t\t\t}\n@@ -561,12 +561,17 @@ rte_eal_init(int argc, char **argv)\n \t/* autodetect the iova mapping mode (default is iova_pa) */\n \trte_eal_get_configuration()->iova_mode = rte_bus_get_iommu_class();\n \n-\tif (internal_config.no_hugetlbfs == 0 &&\n-\t\t\teal_hugepage_info_init() < 0) {\n-\t\trte_eal_init_alert(\"Cannot get hugepage information.\");\n-\t\trte_errno = EACCES;\n-\t\trte_atomic32_clear(&run_once);\n-\t\treturn -1;\n+\tif (internal_config.no_hugetlbfs == 0) {\n+\t\t/* rte_config isn't initialized yet */\n+\t\tret = internal_config.process_type == RTE_PROC_PRIMARY ?\n+\t\t\teal_hugepage_info_init() :\n+\t\t\teal_hugepage_info_read();\n+\t\tif (ret < 0) {\n+\t\t\trte_eal_init_alert(\"Cannot get hugepage information.\");\n+\t\t\trte_errno = EACCES;\n+\t\t\trte_atomic32_clear(&run_once);\n+\t\t\treturn -1;\n+\t\t}\n \t}\n \n \tif (internal_config.memory == 0 && internal_config.force_sockets == 0) {\ndiff --git a/lib/librte_eal/bsdapp/eal/eal_hugepage_info.c b/lib/librte_eal/bsdapp/eal/eal_hugepage_info.c\nindex ba44da0..38d143c 100644\n--- a/lib/librte_eal/bsdapp/eal/eal_hugepage_info.c\n+++ b/lib/librte_eal/bsdapp/eal/eal_hugepage_info.c\n@@ -19,10 +19,10 @@\n  * Used in this file to store the hugepage file map on disk\n  */\n static void *\n-create_shared_memory(const char *filename, const size_t mem_size)\n+map_shared_memory(const char *filename, const size_t mem_size, int flags)\n {\n \tvoid *retval;\n-\tint fd = open(filename, O_CREAT | O_RDWR, 0666);\n+\tint fd = open(filename, flags, 0666);\n \tif (fd < 0)\n \t\treturn NULL;\n \tif (ftruncate(fd, mem_size) < 0) {\n@@ -34,6 +34,18 @@ create_shared_memory(const char *filename, const size_t mem_size)\n \treturn retval;\n }\n \n+static void *\n+open_shared_memory(const char *filename, const size_t mem_size)\n+{\n+\treturn map_shared_memory(filename, mem_size, O_RDWR);\n+}\n+\n+static void *\n+create_shared_memory(const char *filename, const size_t mem_size)\n+{\n+\treturn map_shared_memory(filename, mem_size, O_RDWR | O_CREAT);\n+}\n+\n /*\n  * No hugepage support on freebsd, but we dummy it, using contigmem driver\n  */\n@@ -46,13 +58,10 @@ eal_hugepage_info_init(void)\n \t/* re-use the linux \"internal config\" structure for our memory data */\n \tstruct hugepage_info *hpi = &internal_config.hugepage_info[0];\n \tstruct hugepage_info *tmp_hpi;\n+\tunsigned int i;\n \n \tinternal_config.num_hugepage_sizes = 1;\n \n-\t/* nothing more to be done for secondary */\n-\tif (rte_eal_process_type() == RTE_PROC_SECONDARY)\n-\t\treturn 0;\n-\n \tsysctl_size = sizeof(num_buffers);\n \terror = sysctlbyname(\"hw.contigmem.num_buffers\", &num_buffers,\n \t\t\t&sysctl_size, NULL, 0);\n@@ -87,7 +96,7 @@ eal_hugepage_info_init(void)\n \t\tRTE_LOG(INFO, EAL, \"Contigmem driver has %d buffers, each of size %dKB\\n\",\n \t\t\t\tnum_buffers, (int)(buffer_size>>10));\n \n-\thpi->hugedir = CONTIGMEM_DEV;\n+\tsnprintf(hpi->hugedir, sizeof(hpi->hugedir), \"%s\", CONTIGMEM_DEV);\n \thpi->hugepage_sz = buffer_size;\n \thpi->num_pages[0] = num_buffers;\n \thpi->lock_descriptor = fd;\n@@ -101,6 +110,14 @@ eal_hugepage_info_init(void)\n \n \tmemcpy(tmp_hpi, hpi, sizeof(internal_config.hugepage_info));\n \n+\t/* we've copied file descriptors along with everything else, but they\n+\t * will be invalid in secondary process, so overwrite them\n+\t */\n+\tfor (i = 0; i < RTE_DIM(internal_config.hugepage_info); i++) {\n+\t\tstruct hugepage_info *tmp = &tmp_hpi[i];\n+\t\ttmp->lock_descriptor = -1;\n+\t}\n+\n \tif (munmap(tmp_hpi, sizeof(internal_config.hugepage_info)) < 0) {\n \t\tRTE_LOG(ERR, EAL, \"Failed to unmap shared memory!\\n\");\n \t\treturn -1;\n@@ -108,3 +125,28 @@ eal_hugepage_info_init(void)\n \n \treturn 0;\n }\n+\n+/* copy stuff from shared info into internal config */\n+int\n+eal_hugepage_info_read(void)\n+{\n+\tstruct hugepage_info *hpi = &internal_config.hugepage_info[0];\n+\tstruct hugepage_info *tmp_hpi;\n+\n+\tinternal_config.num_hugepage_sizes = 1;\n+\n+\ttmp_hpi = open_shared_memory(eal_hugepage_info_path(),\n+\t\t\t\t  sizeof(internal_config.hugepage_info));\n+\tif (tmp_hpi == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"Failed to open shared memory!\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tmemcpy(hpi, tmp_hpi, sizeof(internal_config.hugepage_info));\n+\n+\tif (munmap(tmp_hpi, sizeof(internal_config.hugepage_info)) < 0) {\n+\t\tRTE_LOG(ERR, EAL, \"Failed to unmap shared memory!\\n\");\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\ndiff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c b/lib/librte_eal/bsdapp/eal/eal_memory.c\nindex 8a8c44e..6566360 100644\n--- a/lib/librte_eal/bsdapp/eal/eal_memory.c\n+++ b/lib/librte_eal/bsdapp/eal/eal_memory.c\n@@ -242,23 +242,10 @@ int\n rte_eal_hugepage_attach(void)\n {\n \tconst struct hugepage_info *hpi;\n-\tint fd_hugepage_info, fd_hugepage = -1;\n+\tint fd_hugepage = -1;\n \tunsigned int i;\n \n-\t/* Obtain a file descriptor for hugepage_info */\n-\tfd_hugepage_info = open(eal_hugepage_info_path(), O_RDONLY);\n-\tif (fd_hugepage_info < 0) {\n-\t\tRTE_LOG(ERR, EAL, \"Could not open %s\\n\", eal_hugepage_info_path());\n-\t\treturn -1;\n-\t}\n-\n-\t/* Map the shared hugepage_info into the process address spaces */\n-\thpi = mmap(NULL, sizeof(internal_config.hugepage_info),\n-\t\t\tPROT_READ, MAP_PRIVATE, fd_hugepage_info, 0);\n-\tif (hpi == MAP_FAILED) {\n-\t\tRTE_LOG(ERR, EAL, \"Could not mmap %s\\n\", eal_hugepage_info_path());\n-\t\tgoto error;\n-\t}\n+\thpi = &internal_config.hugepage_info[0];\n \n \tfor (i = 0; i < internal_config.num_hugepage_sizes; i++) {\n \t\tconst struct hugepage_info *cur_hpi = &hpi[i];\n@@ -288,13 +275,9 @@ rte_eal_hugepage_attach(void)\n \t}\n \n \t/* hugepage_info is no longer required */\n-\tmunmap((void *)(uintptr_t)hpi, sizeof(internal_config.hugepage_info));\n-\tclose(fd_hugepage_info);\n \treturn 0;\n \n error:\n-\tif (fd_hugepage_info >= 0)\n-\t\tclose(fd_hugepage_info);\n \tif (fd_hugepage >= 0)\n \t\tclose(fd_hugepage);\n \treturn -1;\ndiff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c\nindex 5b5da5f..04a4476 100644\n--- a/lib/librte_eal/common/eal_common_options.c\n+++ b/lib/librte_eal/common/eal_common_options.c\n@@ -179,8 +179,11 @@ eal_reset_internal_config(struct internal_config *internal_cfg)\n \tfor (i = 0; i < RTE_MAX_NUMA_NODES; i++)\n \t\tinternal_cfg->socket_mem[i] = 0;\n \t/* zero out hugedir descriptors */\n-\tfor (i = 0; i < MAX_HUGEPAGE_SIZES; i++)\n+\tfor (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {\n+\t\tmemset(&internal_cfg->hugepage_info[i], 0,\n+\t\t\t\tsizeof(internal_cfg->hugepage_info[0]));\n \t\tinternal_cfg->hugepage_info[i].lock_descriptor = -1;\n+\t}\n \tinternal_cfg->base_virtaddr = 0;\n \n \tinternal_cfg->syslog_facility = LOG_DAEMON;\ndiff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h\nindex 1c6048b..ad059ef 100644\n--- a/lib/librte_eal/common/eal_filesystem.h\n+++ b/lib/librte_eal/common/eal_filesystem.h\n@@ -85,6 +85,23 @@ eal_hugepage_info_path(void)\n \treturn buffer;\n }\n \n+/** Path of hugepage info file. */\n+#define HUGEPAGE_FILE_FMT \"%s/.%s_hugepage_file\"\n+\n+static inline const char *\n+eal_hugepage_file_path(void)\n+{\n+\tstatic char buffer[PATH_MAX]; /* static so auto-zeroed */\n+\tconst char *directory = default_config_dir;\n+\tconst char *home_dir = getenv(\"HOME\");\n+\n+\tif (getuid() != 0 && home_dir != NULL)\n+\t\tdirectory = home_dir;\n+\tsnprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_FILE_FMT, directory,\n+\t\t\tinternal_config.hugefile_prefix);\n+\treturn buffer;\n+}\n+\n /** String format for hugepage map files. */\n #define HUGEFILE_FMT \"%s/%smap_%d\"\n #define TEMP_HUGEFILE_FMT \"%s/%smap_temp_%d\"\ndiff --git a/lib/librte_eal/common/eal_hugepages.h b/lib/librte_eal/common/eal_hugepages.h\nindex ad1b0b6..4582f19 100644\n--- a/lib/librte_eal/common/eal_hugepages.h\n+++ b/lib/librte_eal/common/eal_hugepages.h\n@@ -26,9 +26,15 @@ struct hugepage_file {\n };\n \n /**\n- * Read the information from linux on what hugepages are available\n- * for the EAL to use\n+ * Read the information on what hugepages are available for the EAL to use,\n+ * clearing out any unused ones.\n  */\n int eal_hugepage_info_init(void);\n \n+/**\n+ * Read whatever information primary process has shared about hugepages into\n+ * secondary process.\n+ */\n+int eal_hugepage_info_read(void);\n+\n #endif /* EAL_HUGEPAGES_H */\ndiff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h\nindex 9d33cf4..c4cbf3a 100644\n--- a/lib/librte_eal/common/eal_internal_cfg.h\n+++ b/lib/librte_eal/common/eal_internal_cfg.h\n@@ -21,7 +21,7 @@\n  */\n struct hugepage_info {\n \tuint64_t hugepage_sz;   /**< size of a huge page */\n-\tconst char *hugedir;    /**< dir where hugetlbfs is mounted */\n+\tchar hugedir[PATH_MAX];    /**< dir where hugetlbfs is mounted */\n \tuint32_t num_pages[RTE_MAX_NUMA_NODES];\n \t/**< number of hugepages of that size on each socket */\n \tint lock_descriptor;    /**< file descriptor for hugepage dir */\ndiff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c\nindex 2c12811..e7c6dcf 100644\n--- a/lib/librte_eal/linuxapp/eal/eal.c\n+++ b/lib/librte_eal/linuxapp/eal/eal.c\n@@ -807,13 +807,17 @@ rte_eal_init(int argc, char **argv)\n \t\t\t\"KNI module inserted\\n\");\n \t}\n \n-\tif (internal_config.no_hugetlbfs == 0 &&\n-\t\t\tinternal_config.process_type != RTE_PROC_SECONDARY &&\n-\t\t\teal_hugepage_info_init() < 0) {\n-\t\trte_eal_init_alert(\"Cannot get hugepage information.\");\n-\t\trte_errno = EACCES;\n-\t\trte_atomic32_clear(&run_once);\n-\t\treturn -1;\n+\tif (internal_config.no_hugetlbfs == 0) {\n+\t\t/* rte_config isn't initialized yet */\n+\t\tret = internal_config.process_type == RTE_PROC_PRIMARY ?\n+\t\t\t\teal_hugepage_info_init() :\n+\t\t\t\teal_hugepage_info_read();\n+\t\tif (ret < 0) {\n+\t\t\trte_eal_init_alert(\"Cannot get hugepage information.\");\n+\t\t\trte_errno = EACCES;\n+\t\t\trte_atomic32_clear(&run_once);\n+\t\t\treturn -1;\n+\t\t}\n \t}\n \n \tif (internal_config.memory == 0 && internal_config.force_sockets == 0) {\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c\nindex 2e0819f..fb4b667 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c\n@@ -14,6 +14,7 @@\n #include <stdarg.h>\n #include <unistd.h>\n #include <errno.h>\n+#include <sys/mman.h>\n #include <sys/queue.h>\n #include <sys/stat.h>\n \n@@ -33,6 +34,39 @@\n static const char sys_dir_path[] = \"/sys/kernel/mm/hugepages\";\n static const char sys_pages_numa_dir_path[] = \"/sys/devices/system/node\";\n \n+/*\n+ * Uses mmap to create a shared memory area for storage of data\n+ * Used in this file to store the hugepage file map on disk\n+ */\n+static void *\n+map_shared_memory(const char *filename, const size_t mem_size, int flags)\n+{\n+\tvoid *retval;\n+\tint fd = open(filename, flags, 0666);\n+\tif (fd < 0)\n+\t\treturn NULL;\n+\tif (ftruncate(fd, mem_size) < 0) {\n+\t\tclose(fd);\n+\t\treturn NULL;\n+\t}\n+\tretval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE,\n+\t\t\tMAP_SHARED, fd, 0);\n+\tclose(fd);\n+\treturn retval;\n+}\n+\n+static void *\n+open_shared_memory(const char *filename, const size_t mem_size)\n+{\n+\treturn map_shared_memory(filename, mem_size, O_RDWR);\n+}\n+\n+static void *\n+create_shared_memory(const char *filename, const size_t mem_size)\n+{\n+\treturn map_shared_memory(filename, mem_size, O_RDWR | O_CREAT);\n+}\n+\n /* this function is only called from eal_hugepage_info_init which itself\n  * is only called from a primary process */\n static uint32_t\n@@ -299,15 +333,9 @@ compare_hpi(const void *a, const void *b)\n \treturn hpi_b->hugepage_sz - hpi_a->hugepage_sz;\n }\n \n-/*\n- * when we initialize the hugepage info, everything goes\n- * to socket 0 by default. it will later get sorted by memory\n- * initialization procedure.\n- */\n-int\n-eal_hugepage_info_init(void)\n-{\n-\tconst char dirent_start_text[] = \"hugepages-\";\n+static int\n+hugepage_info_init(void)\n+{\tconst char dirent_start_text[] = \"hugepages-\";\n \tconst size_t dirent_start_len = sizeof(dirent_start_text) - 1;\n \tunsigned int i, total_pages, num_sizes = 0;\n \tDIR *dir;\n@@ -323,6 +351,7 @@ eal_hugepage_info_init(void)\n \n \tfor (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir)) {\n \t\tstruct hugepage_info *hpi;\n+\t\tconst char *hugedir;\n \n \t\tif (strncmp(dirent->d_name, dirent_start_text,\n \t\t\t    dirent_start_len) != 0)\n@@ -334,10 +363,10 @@ eal_hugepage_info_init(void)\n \t\thpi = &internal_config.hugepage_info[num_sizes];\n \t\thpi->hugepage_sz =\n \t\t\trte_str_to_size(&dirent->d_name[dirent_start_len]);\n-\t\thpi->hugedir = get_hugepage_dir(hpi->hugepage_sz);\n+\t\thugedir = get_hugepage_dir(hpi->hugepage_sz);\n \n \t\t/* first, check if we have a mountpoint */\n-\t\tif (hpi->hugedir == NULL) {\n+\t\tif (hugedir == NULL) {\n \t\t\tuint32_t num_pages;\n \n \t\t\tnum_pages = get_num_hugepages(dirent->d_name);\n@@ -349,6 +378,7 @@ eal_hugepage_info_init(void)\n \t\t\t\t\tnum_pages, hpi->hugepage_sz);\n \t\t\tcontinue;\n \t\t}\n+\t\tsnprintf(hpi->hugedir, sizeof(hpi->hugedir), \"%s\", hugedir);\n \n \t\t/* try to obtain a writelock */\n \t\thpi->lock_descriptor = open(hpi->hugedir, O_RDONLY);\n@@ -411,13 +441,11 @@ eal_hugepage_info_init(void)\n \tfor (i = 0; i < num_sizes; i++) {\n \t\t/* pages may no longer all be on socket 0, so check all */\n \t\tunsigned int j, num_pages = 0;\n+\t\tstruct hugepage_info *hpi = &internal_config.hugepage_info[i];\n \n-\t\tfor (j = 0; j < RTE_MAX_NUMA_NODES; j++) {\n-\t\t\tstruct hugepage_info *hpi =\n-\t\t\t\t\t&internal_config.hugepage_info[i];\n+\t\tfor (j = 0; j < RTE_MAX_NUMA_NODES; j++)\n \t\t\tnum_pages += hpi->num_pages[j];\n-\t\t}\n-\t\tif (internal_config.hugepage_info[i].hugedir != NULL &&\n+\t\tif (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0 &&\n \t\t\t\tnum_pages > 0)\n \t\t\treturn 0;\n \t}\n@@ -425,3 +453,64 @@ eal_hugepage_info_init(void)\n \t/* no valid hugepage mounts available, return error */\n \treturn -1;\n }\n+\n+/*\n+ * when we initialize the hugepage info, everything goes\n+ * to socket 0 by default. it will later get sorted by memory\n+ * initialization procedure.\n+ */\n+int\n+eal_hugepage_info_init(void)\n+{\n+\tstruct hugepage_info *hpi, *tmp_hpi;\n+\tunsigned int i;\n+\n+\tif (hugepage_info_init() < 0)\n+\t\treturn -1;\n+\n+\thpi = &internal_config.hugepage_info[0];\n+\n+\ttmp_hpi = create_shared_memory(eal_hugepage_info_path(),\n+\t\t\tsizeof(internal_config.hugepage_info));\n+\tif (tmp_hpi == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"Failed to create shared memory!\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tmemcpy(tmp_hpi, hpi, sizeof(internal_config.hugepage_info));\n+\n+\t/* we've copied file descriptors along with everything else, but they\n+\t * will be invalid in secondary process, so overwrite them\n+\t */\n+\tfor (i = 0; i < RTE_DIM(internal_config.hugepage_info); i++) {\n+\t\tstruct hugepage_info *tmp = &tmp_hpi[i];\n+\t\ttmp->lock_descriptor = -1;\n+\t}\n+\n+\tif (munmap(tmp_hpi, sizeof(internal_config.hugepage_info)) < 0) {\n+\t\tRTE_LOG(ERR, EAL, \"Failed to unmap shared memory!\\n\");\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\n+\n+int eal_hugepage_info_read(void)\n+{\n+\tstruct hugepage_info *hpi = &internal_config.hugepage_info[0];\n+\tstruct hugepage_info *tmp_hpi;\n+\n+\ttmp_hpi = open_shared_memory(eal_hugepage_info_path(),\n+\t\t\t\t  sizeof(internal_config.hugepage_info));\n+\tif (tmp_hpi == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"Failed to open shared memory!\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tmemcpy(hpi, tmp_hpi, sizeof(internal_config.hugepage_info));\n+\n+\tif (munmap(tmp_hpi, sizeof(internal_config.hugepage_info)) < 0) {\n+\t\tRTE_LOG(ERR, EAL, \"Failed to unmap shared memory!\\n\");\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c\nindex c51d598..efa1202 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_memory.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c\n@@ -1060,7 +1060,7 @@ get_socket_mem_size(int socket)\n \n \tfor (i = 0; i < internal_config.num_hugepage_sizes; i++){\n \t\tstruct hugepage_info *hpi = &internal_config.hugepage_info[i];\n-\t\tif (hpi->hugedir != NULL)\n+\t\tif (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0)\n \t\t\tsize += hpi->hugepage_sz * hpi->num_pages[socket];\n \t}\n \n@@ -1160,7 +1160,8 @@ calc_num_pages_per_socket(uint64_t * memory,\n \tfor (socket = 0; socket < RTE_MAX_NUMA_NODES && total_mem != 0; socket++) {\n \t\t/* skips if the memory on specific socket wasn't requested */\n \t\tfor (i = 0; i < num_hp_info && memory[socket] != 0; i++){\n-\t\t\thp_used[i].hugedir = hp_info[i].hugedir;\n+\t\t\tsnprintf(hp_used[i].hugedir, sizeof(hp_used[i].hugedir),\n+\t\t\t\t\t\"%s\", hp_info[i].hugedir);\n \t\t\thp_used[i].num_pages[socket] = RTE_MIN(\n \t\t\t\t\tmemory[socket] / hp_info[i].hugepage_sz,\n \t\t\t\t\thp_info[i].num_pages[socket]);\n@@ -1235,7 +1236,7 @@ eal_get_hugepage_mem_size(void)\n \n \tfor (i = 0; i < internal_config.num_hugepage_sizes; i++) {\n \t\tstruct hugepage_info *hpi = &internal_config.hugepage_info[i];\n-\t\tif (hpi->hugedir != NULL) {\n+\t\tif (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0) {\n \t\t\tfor (j = 0; j < RTE_MAX_NUMA_NODES; j++) {\n \t\t\t\tsize += hpi->hugepage_sz * hpi->num_pages[j];\n \t\t\t}\n@@ -1508,7 +1509,7 @@ eal_legacy_hugepage_init(void)\n \t}\n \n \t/* create shared memory */\n-\thugepage = create_shared_memory(eal_hugepage_info_path(),\n+\thugepage = create_shared_memory(eal_hugepage_file_path(),\n \t\t\tnr_hugefiles * sizeof(struct hugepage_file));\n \n \tif (hugepage == NULL) {\n@@ -1693,16 +1694,16 @@ eal_legacy_hugepage_attach(void)\n \n \ttest_phys_addrs_available();\n \n-\tfd_hugepage = open(eal_hugepage_info_path(), O_RDONLY);\n+\tfd_hugepage = open(eal_hugepage_file_path(), O_RDONLY);\n \tif (fd_hugepage < 0) {\n-\t\tRTE_LOG(ERR, EAL, \"Could not open %s\\n\", eal_hugepage_info_path());\n+\t\tRTE_LOG(ERR, EAL, \"Could not open %s\\n\", eal_hugepage_file_path());\n \t\tgoto error;\n \t}\n \n \tsize = getFileSize(fd_hugepage);\n \thp = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd_hugepage, 0);\n \tif (hp == MAP_FAILED) {\n-\t\tRTE_LOG(ERR, EAL, \"Could not mmap %s\\n\", eal_hugepage_info_path());\n+\t\tRTE_LOG(ERR, EAL, \"Could not mmap %s\\n\", eal_hugepage_file_path());\n \t\tgoto error;\n \t}\n \n",
    "prefixes": [
        "dpdk-dev",
        "v5",
        "58/70"
    ]
}