DPDK patches and discussions
 help / color / mirror / Atom feed
From: Li Han <han.li1@zte.com.cn>
To: thomas@monjalon.net
Cc: dev@dpdk.org, Li Han <han.li1@zte.com.cn>
Subject: [dpdk-dev] [PATCH v2] lib/librte_eal/linuxapp: fix runtime config mmap issue
Date: Wed, 23 Oct 2019 18:31:54 +0800	[thread overview]
Message-ID: <1571826714-28661-1-git-send-email-han.li1@zte.com.cn> (raw)

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:
-fix code style issues

Signed-off-by: Li Han <han.li1@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..d4cd5bb 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


                 reply	other threads:[~2019-10-23 11:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1571826714-28661-1-git-send-email-han.li1@zte.com.cn \
    --to=han.li1@zte.com.cn \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).