[dpdk-dev] [PATCH v3] lib/librte_eal/linuxapp: fix runtime config mmap issue

Li Han han.li1 at zte.com.cn
Wed Oct 23 12:42:41 CEST 2019


In rte_eal_config_reattach(),the secondary mmap may fail
due to the rte_mem_cfg_addr already be used by others.do
the change just as the rte_fbarray_init() do.if no
base_virtaddr,use the default 0x100000000.

v2/v3:
-fix code style issues

Signed-off-by: Li Han <han.li1 at zte.com.cn>
---
 lib/librte_eal/linux/eal/eal.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/lib/librte_eal/linux/eal/eal.c b/lib/librte_eal/linux/eal/eal.c
index f397206..ab0b5a0 100644
--- a/lib/librte_eal/linux/eal/eal.c
+++ b/lib/librte_eal/linux/eal/eal.c
@@ -308,20 +308,32 @@ enum rte_iova_mode
 {
 	void *rte_mem_cfg_addr;
 	int retval;
+	size_t page_sz, mmap_len;
 
 	const char *pathname = eal_runtime_config_path();
 
 	if (internal_config.no_shconf)
 		return 0;
-
+	mmap_len = sizeof(*rte_config.mem_config);
 	/* map the config before hugepage address so that we don't waste a page */
 	if (internal_config.base_virtaddr != 0)
 		rte_mem_cfg_addr = (void *)
 			RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
 			sizeof(struct rte_mem_config), sysconf(_SC_PAGE_SIZE));
-	else
-		rte_mem_cfg_addr = NULL;
-
+	else {
+		page_sz = sysconf(_SC_PAGESIZE);
+		if (page_sz == (size_t)-1) {
+			RTE_LOG(ERR, EAL,
+				"Cannot get SC_PAGESIZE for rte_mem_config\n");
+			return -1;
+		}
+		rte_mem_cfg_addr = eal_get_virtual_area(NULL, &mmap_len, page_sz, 0, 0);
+		if (rte_mem_cfg_addr == NULL) {
+			RTE_LOG(ERR, EAL,
+				"Cannot get virtual addr for rte_mem_config\n");
+			return -1;
+		}
+	}
 	if (mem_cfg_fd < 0){
 		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
 		if (mem_cfg_fd < 0) {
@@ -349,8 +361,10 @@ enum rte_iova_mode
 		return -1;
 	}
 
-	rte_mem_cfg_addr = mmap(rte_mem_cfg_addr, sizeof(*rte_config.mem_config),
-				PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
+	rte_mem_cfg_addr = mmap(rte_mem_cfg_addr, mmap_len,
+				PROT_READ | PROT_WRITE,
+				MAP_FIXED | MAP_SHARED,
+				mem_cfg_fd, 0);
 
 	if (rte_mem_cfg_addr == MAP_FAILED){
 		close(mem_cfg_fd);
-- 
1.8.3.1



More information about the dev mailing list