aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArtem Belov <artem.belov@xored.com>2019-02-26 01:47:34 +0000
committerDamjan Marion <dmarion@me.com>2019-03-02 09:20:05 +0000
commitd302022440a3698c7ec81340bfb67cab2a5b71ea (patch)
treeec072492bebacea14e57cc0c4310fa145c94ca12 /src
parent6342e48dc1aa5a083b34ca6cae26bf3672cd800b (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> Signed-off-by: Ed Warnicke <hagbard@gmail.com> (cherry picked from commit f6defa113e2e10a70c5a92ce7e14b7a532154409)
Diffstat (limited to 'src')
-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 9c5f475e8dd..365ee044392 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>
@@ -260,6 +261,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);
@@ -332,6 +334,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);