mem: fix alignment requested with --base-virtaddr
authorDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Fri, 15 Jun 2018 15:13:04 +0000 (17:13 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 12 Jul 2018 22:25:10 +0000 (00:25 +0200)
Whenever a calculated base-virtaddr offset had to be
manually aligned to requested page_sz, we did not take
account of that alignment in incrementing the base-virtaddr
offset further. The next requested virtual area could print
a warning "hint [...] not respected!" and let the system
pick an address instead. As a result, this breaks secondary
process support on many system configurations.

Fixes: b7cc54187ea4 ("mem: move virtual area function in common directory")
Cc: stable@dpdk.org
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
lib/librte_eal/common/eal_common_memory.c

index 261fd77..9adbf41 100644 (file)
@@ -34,7 +34,7 @@
 
 #define MEMSEG_LIST_FMT "memseg-%" PRIu64 "k-%i-%i"
 
-static uint64_t baseaddr_offset;
+static void *next_baseaddr;
 static uint64_t system_page_sz;
 
 void *
@@ -56,9 +56,11 @@ eal_get_virtual_area(void *requested_addr, size_t *size,
        allow_shrink = (flags & EAL_VIRTUAL_AREA_ALLOW_SHRINK) > 0;
        unmap = (flags & EAL_VIRTUAL_AREA_UNMAP) > 0;
 
-       if (requested_addr == NULL && internal_config.base_virtaddr != 0) {
-               requested_addr = (void *) (internal_config.base_virtaddr +
-                               (size_t)baseaddr_offset);
+       if (next_baseaddr == NULL && internal_config.base_virtaddr != 0)
+               next_baseaddr = (void *) internal_config.base_virtaddr;
+
+       if (requested_addr == NULL && next_baseaddr != NULL) {
+               requested_addr = next_baseaddr;
                requested_addr = RTE_PTR_ALIGN(requested_addr, page_sz);
                addr_is_hint = true;
        }
@@ -116,6 +118,8 @@ eal_get_virtual_area(void *requested_addr, size_t *size,
                RTE_LOG(WARNING, EAL, "WARNING! Base virtual address hint (%p != %p) not respected!\n",
                        requested_addr, aligned_addr);
                RTE_LOG(WARNING, EAL, "   This may cause issues with mapping memory into secondary processes\n");
+       } else if (next_baseaddr != NULL) {
+               next_baseaddr = RTE_PTR_ADD(aligned_addr, *size);
        }
 
        RTE_LOG(DEBUG, EAL, "Virtual area found at %p (size = 0x%zx)\n",
@@ -148,8 +152,6 @@ eal_get_virtual_area(void *requested_addr, size_t *size,
                        munmap(aligned_end, after_len);
        }
 
-       baseaddr_offset += *size;
-
        return aligned_addr;
 }