From f6defa113e2e10a70c5a92ce7e14b7a532154409 Mon Sep 17 00:00:00 2001 From: Artem Belov Date: Tue, 26 Feb 2019 01:47:34 +0000 Subject: Fix vpp crashing when attempting to run in kubernetes Pod mmap does not fail but writing to mapped memory is causing sigbus. Change-Id: I5135f32eede67fccb4aaa07a501cd262d254ed8d Signed-off-by: Artem Belov --- src/vppinfra/pmalloc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/vppinfra') diff --git a/src/vppinfra/pmalloc.c b/src/vppinfra/pmalloc.c index dd772f34381..f421665e934 100644 --- a/src/vppinfra/pmalloc.c +++ b/src/vppinfra/pmalloc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -263,6 +264,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); @@ -335,6 +337,25 @@ 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 */ + if (a->log2_subpage_sz != pm->sys_log2_page_sz) + { + 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); -- cgit 1.2.3-korg