From 58dd2923a1ea19cd2d3d26ea51c40b261dc9202b Mon Sep 17 00:00:00 2001 From: Artem Belov Date: Tue, 26 Feb 2019 08:05:29 +0700 Subject: [PATCH 1/3] Add hugepage allocation check --- src/vppinfra/pmalloc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/vppinfra/pmalloc.c b/src/vppinfra/pmalloc.c index 41309dd1d99e..26b6d1df274d 100644 --- a/src/vppinfra/pmalloc.c +++ b/src/vppinfra/pmalloc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -254,6 +255,7 @@ pmalloc_map_pages (clib_pmalloc_main_t * pm, clib_pmalloc_arena_t * a, int old_mpol = -1; long unsigned int mask[16] = { 0 }; long unsigned int old_mask[16] = { 0 }; + uword page_size = 1 << a->log2_subpage_sz; uword size = (uword) n_pages << pm->def_log2_page_sz; clib_error_free (pm->error); @@ -326,6 +328,20 @@ pmalloc_map_pages (clib_pmalloc_main_t * pm, clib_pmalloc_arena_t * a, goto error; } + /* Check if huge page is not allocated, + wrong allocation will generate the SIGBUS */ + for (int i = 0; i < n_pages; i++) + { + unsigned char flag; + mincore(va + i * page_size, 1, &flag); + // flag is 1 if the page was successfully allocated and in memory + if (!flag) + { + pm->error = clib_error_return_unix (0, "Unable to fulfill huge page allocation request"); + goto error; + } + } + clib_memset (va, 0, size); rv = set_mempolicy (old_mpol, old_mask, sizeof (old_mask) * 8 + 1); From e0b910424659021dd8aaf1412e4858fcccf92fbe Mon Sep 17 00:00:00 2001 From: Artem Belov Date: Tue, 26 Feb 2019 13:40:05 +0700 Subject: [PATCH 2/3] Skip synchronizing worker threads if single thread Fix SIGSEGV --- src/vnet/devices/virtio/vhost_user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vnet/devices/virtio/vhost_user.c b/src/vnet/devices/virtio/vhost_user.c index d13ea3beab3b..84d49043003d 100644 --- a/src/vnet/devices/virtio/vhost_user.c +++ b/src/vnet/devices/virtio/vhost_user.c @@ -1277,7 +1277,9 @@ vhost_user_exit (vlib_main_t * vm) vhost_user_main_t *vum = &vhost_user_main; vhost_user_intf_t *vui; - vlib_worker_thread_barrier_sync (vlib_get_main ()); + if (vec_len (vlib_mains) > 1) + vlib_worker_thread_barrier_sync (vlib_get_main ()); + /* *INDENT-OFF* */ pool_foreach (vui, vum->vhost_user_interfaces, { vhost_user_delete_if (vnm, vm, vui->sw_if_index); From cd557712614f9b97b2c62e6e702cf84f66629ae0 Mon Sep 17 00:00:00 2001 From: Artem Belov Date: Tue, 26 Feb 2019 13:43:23 +0700 Subject: [PATCH 3/3] Check buffer mmap result only on hugepages --- src/vppinfra/pmalloc.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/vppinfra/pmalloc.c b/src/vppinfra/pmalloc.c index 26b6d1df274d..04856f04f9a5 100644 --- a/src/vppinfra/pmalloc.c +++ b/src/vppinfra/pmalloc.c @@ -330,16 +330,21 @@ pmalloc_map_pages (clib_pmalloc_main_t * pm, clib_pmalloc_arena_t * a, /* Check if huge page is not allocated, wrong allocation will generate the SIGBUS */ - for (int i = 0; i < n_pages; i++) + if (a->log2_subpage_sz != pm->sys_log2_page_sz) { - unsigned char flag; - mincore(va + i * page_size, 1, &flag); - // flag is 1 if the page was successfully allocated and in memory - if (!flag) - { - pm->error = clib_error_return_unix (0, "Unable to fulfill huge page allocation request"); - goto error; - } + for (int i = 0; i < n_pages; i++) + { + unsigned char flag; + mincore (va + i * page_size, 1, &flag); + // flag is 1 if the page was successfully allocated and in memory + if (!flag) + { + pm->error = + clib_error_return_unix (0, + "Unable to fulfill huge page allocation request"); + goto error; + } + } } clib_memset (va, 0, size);