From: Olivier Matz <olivier.matz@6wind.com>
To: dev@dpdk.org
Cc: matvejchikov@gmail.com, adrien.mazarguil@6wind.com,
jblunck@infradead.org, sergio.gonzalez.monroy@intel.com,
santosh.shukla@caviumnetworks.com, stable@dpdk.org
Subject: [dpdk-dev] [PATCH v2] eal: don't advertise a physical address when no hugepages
Date: Mon, 3 Jul 2017 12:04:07 +0200 [thread overview]
Message-ID: <20170703100407.21790-1-olivier.matz@6wind.com> (raw)
In-Reply-To: <20170609082937.21294-1-olivier.matz@6wind.com>
When populating a mempool with a virtual memory area, the mempool
library expects to be able to get the physical address of each page.
When started with --no-huge, the physical addresses may not be available
because the pages are not locked in memory. It sometimes returns
RTE_BAD_PHYS_ADDR, which makes the mempool_populate() function to fail.
This was working before the commit cdc242f260e7 ("eal/linux: support
running as unprivileged user"), because rte_mem_virt2phy() was returning
0 instead of RTE_BAD_PHYS_ADDR, which was seen as a valid physical
address.
Since --no-huge is a debug function that breaks the support of physical
drivers, always set physical addresses to RTE_BAD_PHYS_ADDR in memzones
or in rte_mem_virt2phy(), and ensure that mempool won't complain in that
case.
Fixes: cdc242f260e7 ("eal/linux: support running as unprivileged user")
CC: stable@dpdk.org
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
v1 -> v2:
- initialize memory segments (rte_memseg) with RTE_BAD_PHYS_ADDR
if started with --no-huge
- return RTE_BAD_PHYS_ADDR when rte_malloc_virt2phy() if the
memory segment has no physical address
- drop change in eal_common_memzone.c: the physical address is
now set to RTE_BAD_PHYS_ADDR as per return value of
rte_malloc_virt2phy()
lib/librte_eal/common/include/rte_malloc.h | 2 +-
lib/librte_eal/common/rte_malloc.c | 4 +++-
lib/librte_eal/linuxapp/eal/eal_memory.c | 9 ++++++++-
lib/librte_mempool/rte_mempool.c | 2 +-
4 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/lib/librte_eal/common/include/rte_malloc.h b/lib/librte_eal/common/include/rte_malloc.h
index 61aac322b..3d37f79b8 100644
--- a/lib/librte_eal/common/include/rte_malloc.h
+++ b/lib/librte_eal/common/include/rte_malloc.h
@@ -329,7 +329,7 @@ rte_malloc_set_limit(const char *type, size_t max);
* @param addr
* Address obtained from a previous rte_malloc call
* @return
- * NULL on error
+ * RTE_BAD_PHYS_ADDR on error
* otherwise return physical address of the buffer
*/
phys_addr_t
diff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c
index f4a883529..5c0627bf4 100644
--- a/lib/librte_eal/common/rte_malloc.c
+++ b/lib/librte_eal/common/rte_malloc.c
@@ -253,6 +253,8 @@ rte_malloc_virt2phy(const void *addr)
{
const struct malloc_elem *elem = malloc_elem_from_data(addr);
if (elem == NULL)
- return 0;
+ return RTE_BAD_PHYS_ADDR;
+ if (elem->ms->phys_addr == RTE_BAD_PHYS_ADDR)
+ return RTE_BAD_PHYS_ADDR;
return elem->ms->phys_addr + ((uintptr_t)addr - (uintptr_t)elem->ms->addr);
}
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 647d89c58..040f24a43 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -112,6 +112,13 @@ test_phys_addrs_available(void)
if (rte_xen_dom0_supported())
return;
+ if (!rte_eal_has_hugepages()) {
+ RTE_LOG(ERR, EAL,
+ "Started without hugepages support, physical addresses not available\n");
+ phys_addrs_available = false;
+ return;
+ }
+
physaddr = rte_mem_virt2phy(&tmp);
if (physaddr == RTE_BAD_PHYS_ADDR) {
RTE_LOG(ERR, EAL,
@@ -1054,7 +1061,7 @@ rte_eal_hugepage_init(void)
strerror(errno));
return -1;
}
- mcfg->memseg[0].phys_addr = (phys_addr_t)(uintptr_t)addr;
+ mcfg->memseg[0].phys_addr = RTE_BAD_PHYS_ADDR;
mcfg->memseg[0].addr = addr;
mcfg->memseg[0].hugepage_sz = RTE_PGSIZE_4K;
mcfg->memseg[0].len = internal_config.memory;
diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index f65310f60..6fc3c9c7c 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -476,7 +476,7 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
/* required for xen_dom0 to get the machine address */
paddr = rte_mem_phy2mch(-1, paddr);
- if (paddr == RTE_BAD_PHYS_ADDR) {
+ if (paddr == RTE_BAD_PHYS_ADDR && rte_eal_has_hugepages()) {
ret = -EINVAL;
goto fail;
}
--
2.11.0
next prev parent reply other threads:[~2017-07-03 10:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-14 10:34 [dpdk-dev] A (possible) problem with `--no-huge` option Ilya Matveychikov
2017-06-09 8:27 ` Olivier Matz
2017-06-09 8:29 ` [dpdk-dev] [PATCH] eal: don't advertise a physical address when no hugepages Olivier Matz
2017-06-10 8:31 ` Jan Blunck
2017-06-23 8:11 ` Olivier Matz
2017-06-23 17:08 ` Jan Blunck
2017-06-26 7:11 ` santosh
2017-06-12 13:58 ` Adrien Mazarguil
2017-07-03 10:04 ` Olivier Matz [this message]
2017-07-03 10:17 ` [dpdk-dev] [PATCH v2] " Jan Blunck
2017-07-04 15:53 ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2017-06-09 12:08 ` [dpdk-dev] A (possible) problem with `--no-huge` option Ilya Matveychikov
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=20170703100407.21790-1-olivier.matz@6wind.com \
--to=olivier.matz@6wind.com \
--cc=adrien.mazarguil@6wind.com \
--cc=dev@dpdk.org \
--cc=jblunck@infradead.org \
--cc=matvejchikov@gmail.com \
--cc=santosh.shukla@caviumnetworks.com \
--cc=sergio.gonzalez.monroy@intel.com \
--cc=stable@dpdk.org \
/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).