summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/pmalloc.c
diff options
context:
space:
mode:
authorArtem Belov <artem.belov@xored.com>2019-02-26 01:47:34 +0000
committerDamjan Marion <dmarion@me.com>2019-02-26 11:26:03 +0000
commitf6defa113e2e10a70c5a92ce7e14b7a532154409 (patch)
treef470b8c408e7b9adcbc9bec070d03884b28e325c /src/vppinfra/pmalloc.c
parentd73dbd2d3a2437c1bb687d70a5872065a67fbb6c (diff)
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 <artem.belov@xored.com>
Diffstat (limited to 'src/vppinfra/pmalloc.c')
-rw-r--r--src/vppinfra/pmalloc.c21
1 files changed, 21 insertions, 0 deletions
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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <unistd.h>
#include <linux/mempolicy.h>
#include <linux/memfd.h>
@@ -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);