From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ernst.netinsight.se (ernst.netinsight.se [194.16.221.21]) by dpdk.org (Postfix) with SMTP id 060BCC5F2 for ; Tue, 23 Jun 2015 12:39:42 +0200 (CEST) Received: from miho (unverified [10.100.1.152]) by ernst.netinsight.se (EMWAC SMTPRS 0.83) with SMTP id ; Tue, 23 Jun 2015 12:39:40 +0200 Date: Tue, 23 Jun 2015 12:39:35 +0200 From: Simon Kagstrom To: dev@dpdk.org, david.marchand@6wind.com Message-ID: <20150623123935.39139301@miho> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.27; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [dpdk-dev] [PATCH] mem: Warn once if /proc/self/pagemap is unreadable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2015 10:39:43 -0000 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 Signed-off-by: Johan Faltstrom --- lib/librte_eal/linuxapp/eal/eal_memory.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 9b8d946..7274cb3 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,6 +1552,18 @@ 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 @@ -1561,5 +1579,11 @@ rte_eal_memory_init(void) if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0) return -1; + 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)); + return 0; } -- 1.9.1