In case of hugepages unmap has to be done with address aligned to
page size. Also unmap() has to be done for address returned by mmap(),
not for aligned address after that.

To reproduce original bug run:
echo 4096 >  /proc/sys/vm/nr_hugepages
make check

Signed-off-by: Maxim Uvarov <[email protected]>
---
 platform/linux-generic/odp_shared_memory.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/platform/linux-generic/odp_shared_memory.c 
b/platform/linux-generic/odp_shared_memory.c
index 99c5b40..51eba02 100644
--- a/platform/linux-generic/odp_shared_memory.c
+++ b/platform/linux-generic/odp_shared_memory.c
@@ -134,8 +134,14 @@ int odp_shm_free(odp_shm_t shm)
        odp_spinlock_lock(&odp_shm_tbl->lock);
        shm_block = &odp_shm_tbl->block[i];
 
+#ifdef MAP_HUGETLB
+       /* round up alloc size by page */
+       alloc_size = (shm_block->size + (shm_block->page_sz - 1))
+                     & (-shm_block->page_sz);
+#else
        alloc_size = shm_block->size + shm_block->align;
-       ret = munmap(shm_block->addr, alloc_size);
+#endif
+       ret = munmap(shm_block->addr_orig, alloc_size);
        if (0 != ret) {
                ODP_DBG("odp_shm_free: munmap failed\n");
                odp_spinlock_unlock(&odp_shm_tbl->lock);
-- 
1.8.5.1.163.gd7aced9


_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to