]> git.droids-corp.org - dpdk.git/commitdiff
mem: fix hugepage mapping error messages
authorJean Tourrilhes <jt@labs.hpe.com>
Tue, 4 Oct 2016 17:17:03 +0000 (10:17 -0700)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 5 Oct 2016 09:42:45 +0000 (11:42 +0200)
Running secondary is tricky due to the need to map the memory region
at the right place in VM, which is whatever primary has chosen. If the
base address for primary happens to by already mapped in the
secondary, we will hit precisely these error messages (depending if we
fail on the config region or the hugepages). This is why there is
already a comment about ASLR.

The issue is that in most cases, remapping does not happen and "errno"
is not changed and therefore stale. In our case, we got a "permission
denied", which sent us down the wrong track. It's such a common error
for secondary that I feel this error message should be unambiguous and
helpful.
The call to close was also moved because close() may override errno.

Signed-off-by: Jean Tourrilhes <jt@labs.hpe.com>
lib/librte_eal/linuxapp/eal/eal.c
lib/librte_eal/linuxapp/eal/eal_memory.c

index 3f4dff2a4c57d7e14f4d7323de9d75e7b4c0a6c3..81264a25f763e24f5f96bbd12074b2b8d806b738 100644 (file)
@@ -239,7 +239,8 @@ rte_eal_config_attach(void)
        mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),
                        PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
        if (mem_config == MAP_FAILED)
-               rte_panic("Cannot mmap memory for rte_config\n");
+               rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
+                         errno, strerror(errno));
 
        rte_config.mem_config = mem_config;
 }
@@ -264,9 +265,17 @@ rte_eal_config_reattach(void)
        mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
                        sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,
                        mem_cfg_fd, 0);
+       if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
+               if (mem_config != MAP_FAILED)
+                       /* errno is stale, don't use */
+                       rte_panic("Cannot mmap memory for rte_config at [%p], got [%p]"
+                                 " - please use '--base-virtaddr' option\n",
+                                 rte_mem_cfg_addr, mem_config);
+               else
+                       rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
+                                 errno, strerror(errno));
+       }
        close(mem_cfg_fd);
-       if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr)
-               rte_panic("Cannot mmap memory for rte_config\n");
 
        rte_config.mem_config = mem_config;
 }
index b0049e2e94010830a2d42475a907b1ca0165d3d6..bb7a5a76002422a0fbcc2914985d505232d0eb23 100644 (file)
@@ -1333,13 +1333,21 @@ rte_eal_hugepage_attach(void)
                                 PROT_READ, MAP_PRIVATE, fd_zero, 0);
                if (base_addr == MAP_FAILED ||
                    base_addr != mcfg->memseg[s].addr) {
-                       RTE_LOG(ERR, EAL, "Could not mmap %llu bytes "
-                               "in /dev/zero to requested address [%p]: '%s'\n",
-                               (unsigned long long)mcfg->memseg[s].len,
-                               mcfg->memseg[s].addr, strerror(errno));
                        max_seg = s;
-                       if (base_addr != MAP_FAILED)
+                       if (base_addr != MAP_FAILED) {
+                               /* errno is stale, don't use */
+                               RTE_LOG(ERR, EAL, "Could not mmap %llu bytes "
+                                       "in /dev/zero at [%p], got [%p] - "
+                                       "please use '--base-virtaddr' option\n",
+                                       (unsigned long long)mcfg->memseg[s].len,
+                                       mcfg->memseg[s].addr, base_addr);
                                munmap(base_addr, mcfg->memseg[s].len);
+                       } else {
+                               RTE_LOG(ERR, EAL, "Could not mmap %llu bytes "
+                                       "in /dev/zero at [%p]: '%s'\n",
+                                       (unsigned long long)mcfg->memseg[s].len,
+                                       mcfg->memseg[s].addr, strerror(errno));
+                       }
                        if (aslr_enabled() > 0) {
                                RTE_LOG(ERR, EAL, "It is recommended to "
                                        "disable ASLR in the kernel "