aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaiyang Tan <haiyangtan@tencent.com>2018-10-15 06:17:55 -0700
committerDamjan Marion <dmarion@me.com>2018-10-16 11:37:49 +0000
commita5ab5034f4b50fc5a19ccf8910c91613e6a52f5a (patch)
tree7ada95f1671e1f5b525355a6f90e6456813a012c
parente9239c978277d838c0c5ca0ad3076ef85d15138a (diff)
Fix coverity issue for potentially overflowing of page size
Change-Id: I2779626d745badb63386efcf729da7a094a4f297 Signed-off-by: Haiyang Tan <haiyangtan@tencent.com>
-rw-r--r--src/plugins/dpdk/buffer.c6
-rw-r--r--src/svm/ssvm.c2
-rw-r--r--src/vlib/buffer.c2
-rwxr-xr-xsrc/vlib/linux/physmem.c2
-rw-r--r--src/vlib/linux/vfio.c4
-rw-r--r--src/vppinfra/linux/mem.c5
6 files changed, 11 insertions, 10 deletions
diff --git a/src/plugins/dpdk/buffer.c b/src/plugins/dpdk/buffer.c
index edace2aaf61..bb177fc6772 100644
--- a/src/plugins/dpdk/buffer.c
+++ b/src/plugins/dpdk/buffer.c
@@ -465,7 +465,7 @@ dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, u32 elt_size,
for (i = 0; i < pr->n_pages; i++)
{
- size_t page_size = 1 << pr->log2_page_size;
+ size_t page_size = 1ull << pr->log2_page_size;
ret = rte_mempool_populate_iova (mp, ((char *) pr->mem) + i * page_size,
pr->page_table[i], page_size, 0, 0);
if (ret < 0)
@@ -493,8 +493,8 @@ dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, u32 elt_size,
/* *INDENT-OFF* */
vec_foreach_index (i, pr->page_table)
{
- dm.vaddr = pointer_to_uword (pr->mem) + (i << pr->log2_page_size);
- dm.size = 1 << pr->log2_page_size;
+ dm.vaddr = pointer_to_uword (pr->mem) + ((u64)i << pr->log2_page_size);
+ dm.size = 1ull << pr->log2_page_size;
dm.iova = pr->page_table[i];
if ((rv = ioctl (dbm->vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dm)))
break;
diff --git a/src/svm/ssvm.c b/src/svm/ssvm.c
index 03451e66d15..7fa9b258729 100644
--- a/src/svm/ssvm.c
+++ b/src/svm/ssvm.c
@@ -248,7 +248,7 @@ ssvm_master_init_memfd (ssvm_private_t * memfd)
memfd->my_pid = getpid ();
memfd->i_am_master = 1;
- page_size = 1 << alloc.log2_page_size;
+ page_size = 1ull << alloc.log2_page_size;
sh = memfd->sh;
sh->master_pid = memfd->my_pid;
sh->ssvm_size = memfd->ssvm_size;
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c
index a704efb40f4..785fa9b8aac 100644
--- a/src/vlib/buffer.c
+++ b/src/vlib/buffer.c
@@ -910,7 +910,7 @@ vlib_buffer_pool_create (vlib_main_t * vm, vlib_physmem_region_index_t pri,
p->log2_page_size = pr->log2_page_size;
p->buffer_size = buffer_size;
- p->buffers_per_page = (1 << pr->log2_page_size) / p->buffer_size;
+ p->buffers_per_page = (1ull << pr->log2_page_size) / p->buffer_size;
p->n_elts = p->buffers_per_page * pr->n_pages;
p->n_used = 0;
clib_spinlock_init (&p->lock);
diff --git a/src/vlib/linux/physmem.c b/src/vlib/linux/physmem.c
index 4d16486dea1..dbc4c549a99 100755
--- a/src/vlib/linux/physmem.c
+++ b/src/vlib/linux/physmem.c
@@ -179,7 +179,7 @@ unix_physmem_region_alloc (vlib_main_t * vm, char *name, u32 size,
pr->log2_page_size = alloc.log2_page_size;
pr->n_pages = alloc.n_pages;
pr->size = (u64) pr->n_pages << (u64) pr->log2_page_size;
- pr->page_mask = (1 << pr->log2_page_size) - 1;
+ pr->page_mask = (1ull << pr->log2_page_size) - 1;
pr->numa_node = numa_node;
pr->name = format (0, "%s%c", name, 0);
diff --git a/src/vlib/linux/vfio.c b/src/vlib/linux/vfio.c
index 02262719e82..ffc990a61d2 100644
--- a/src/vlib/linux/vfio.c
+++ b/src/vlib/linux/vfio.c
@@ -52,8 +52,8 @@ vfio_map_regions (vlib_main_t * vm, int fd)
vec_foreach_index (i, pr->page_table)
{
int rv;
- dm.vaddr = pointer_to_uword (pr->mem) + (i << pr->log2_page_size);
- dm.size = 1 << pr->log2_page_size;
+ dm.vaddr = pointer_to_uword (pr->mem) + ((u64)i << pr->log2_page_size);
+ dm.size = 1ull << pr->log2_page_size;
dm.iova = dm.vaddr;
vlib_log_debug (lvm->log_default, "map DMA va:0x%lx iova:%lx "
"size:0x%lx", dm.vaddr, dm.iova, dm.size);
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 2d968fae0ac..227e55b6d56 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -73,7 +73,8 @@ clib_mem_vm_randomize_va (uword * requested_va, u32 log2_page_size)
else
bit_mask = 0;
- *requested_va += (clib_cpu_time_now () & bit_mask) * (1 << log2_page_size);
+ *requested_va +=
+ (clib_cpu_time_now () & bit_mask) * (1ull << log2_page_size);
}
clib_error_t *
@@ -257,7 +258,7 @@ clib_mem_vm_ext_free (clib_mem_vm_alloc_t * a)
{
if (a != 0)
{
- clib_mem_vm_free (a->addr, 1 << a->log2_page_size);
+ clib_mem_vm_free (a->addr, 1ull << a->log2_page_size);
if (a->fd != -1)
close (a->fd);
}