DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2] mem: Warn once if /proc/self/pagemap is unreadable
@ 2015-06-24  8:33 Simon Kagstrom
  2015-07-10 21:43 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Kagstrom @ 2015-06-24  8:33 UTC (permalink / raw)
  To: dev

Newer kernels make this unreadable for security reasons for non-roots.
Running the application will then fill the logs with

  rte_mem_virt2phy: cannot open /proc/self/pagemap

messages.

However, there are cases when DPDK is and should be run as non-root,
without the need for virtual-to-physical address translations: a
typical example is when working with PCAP input/output. This patch
adds a start-time check for /proc/self/pagemap readability, and
directly returns an error code from rte_mem_virt2phy().

This way, there is only a one-time warning at startup instead of
constant warnings all the time.

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
Signed-off-by: Johan Faltstrom <johan.faltstrom@netinsight.net>
---
ChangeLog:

v2: Fix use with huge pages.

 lib/librte_eal/linuxapp/eal/eal_memory.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 9b8d946..f4a1936 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -111,6 +111,8 @@
 
 static uint64_t baseaddr_offset;
 
+static unsigned proc_pagemap_readable;
+
 #define RANDOMIZE_VA_SPACE_FILE "/proc/sys/kernel/randomize_va_space"
 
 /* Lock page in physical memory and prevent from swapping. */
@@ -135,6 +137,10 @@ rte_mem_virt2phy(const void *virtaddr)
 	int page_size;
 	off_t offset;
 
+	/* Cannot parse /proc/self/pagemap, no need to log errors everywhere */
+	if (!proc_pagemap_readable)
+		return RTE_BAD_PHYS_ADDR;
+
 	/* standard page size */
 	page_size = getpagesize();
 
@@ -1546,12 +1552,31 @@ rte_eal_memdevice_init(void)
 	return 0;
 }
 
+static int
+test_proc_pagemap_readable(void)
+{
+	int fd = open("/proc/self/pagemap", O_RDONLY);
+
+	if (fd < 0)
+		return 0;
+	/* Is readable */
+	close(fd);
+
+	return 1;
+}
 
 /* init memory subsystem */
 int
 rte_eal_memory_init(void)
 {
 	RTE_LOG(INFO, EAL, "Setting up memory...\n");
+
+	proc_pagemap_readable = test_proc_pagemap_readable();
+	if (!proc_pagemap_readable)
+		RTE_LOG(ERR, EAL,
+		        "Cannot open /proc/self/pagemap: %s. virt2phys address translation will not work\n",
+			strerror(errno));
+
 	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
 			rte_eal_hugepage_init() :
 			rte_eal_hugepage_attach();
-- 
1.9.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH v2] mem: Warn once if /proc/self/pagemap is unreadable
  2015-06-24  8:33 [dpdk-dev] [PATCH v2] mem: Warn once if /proc/self/pagemap is unreadable Simon Kagstrom
@ 2015-07-10 21:43 ` Thomas Monjalon
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Monjalon @ 2015-07-10 21:43 UTC (permalink / raw)
  To: Simon Kagstrom; +Cc: dev

2015-06-24 10:33, Simon Kagstrom:
> Newer kernels make this unreadable for security reasons for non-roots.
> Running the application will then fill the logs with
> 
>   rte_mem_virt2phy: cannot open /proc/self/pagemap
> 
> messages.
> 
> However, there are cases when DPDK is and should be run as non-root,
> without the need for virtual-to-physical address translations: a
> typical example is when working with PCAP input/output. This patch
> adds a start-time check for /proc/self/pagemap readability, and
> directly returns an error code from rte_mem_virt2phy().
> 
> This way, there is only a one-time warning at startup instead of
> constant warnings all the time.
> 
> Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
> Signed-off-by: Johan Faltstrom <johan.faltstrom@netinsight.net>

Applied, thanks

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-10 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-24  8:33 [dpdk-dev] [PATCH v2] mem: Warn once if /proc/self/pagemap is unreadable Simon Kagstrom
2015-07-10 21:43 ` Thomas Monjalon

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).