aboutsummaryrefslogtreecommitdiffstats
path: root/vnet
diff options
context:
space:
mode:
authorJianfeng Tan <jianfeng.tan@intel.com>2016-08-11 02:17:30 +0000
committerDave Barach <openvpp@barachs.net>2016-08-15 21:52:12 +0000
commit8d98684a60dc641b457922c1529a1d5d6479c94d (patch)
tree211cb41ad29c2e9d28ad3d6fc131882f15b13c85 /vnet
parent161b2c6a833f2b53d684ae4a18119c26b825fe73 (diff)
Vhost-User: Fix calculate memory region size
The memory region size calculation is wrong. For example, a region with size of 1G (hugepage size is also 1G), and offset is zero, use the previous way to calculate, the ultimate size to mmap and munmap is 2G, which could lead to segment fault when munmap is executed. This patch refers the way in DPDK to calculate the region size. Change-Id: I6f35cde15e2402be0025c556c192b87a46bbf978 Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
Diffstat (limited to 'vnet')
-rw-r--r--vnet/vnet/devices/dpdk/vhost_user.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/vnet/vnet/devices/dpdk/vhost_user.c b/vnet/vnet/devices/dpdk/vhost_user.c
index f1c50019625..8335963d22b 100644
--- a/vnet/vnet/devices/dpdk/vhost_user.c
+++ b/vnet/vnet/devices/dpdk/vhost_user.c
@@ -883,8 +883,8 @@ static void dpdk_unmap_all_mem_regions(dpdk_device_t * xd)
long page_sz = get_huge_page_size(vui->region_fd[i]);
- ssize_t map_sz = (mem->regions[i].memory_size +
- vui->region_offset[i] + page_sz) & ~(page_sz - 1);
+ ssize_t map_sz = RTE_ALIGN_CEIL(mem->regions[i].memory_size +
+ vui->region_offset[i], page_sz);
r = munmap((void *)(vui->region_addr[i] - vui->region_offset[i]), map_sz);
@@ -1188,7 +1188,7 @@ static clib_error_t * dpdk_vhost_user_socket_read (unix_file_t * uf)
fd = fds[0];
/* align size to 2M page */
long page_sz = get_huge_page_size(fd);
- ssize_t map_sz = (msg.log.size + msg.log.offset + page_sz) & ~(page_sz - 1);
+ ssize_t map_sz = RTE_ALIGN_CEIL(msg.log.size + msg.log.offset, page_sz);
void *addr = mmap(0, map_sz, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);