ipsec: Reference count the SAs
[vpp.git] / src / svm / ssvm.c
index 73517ae..605b692 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco and/or its affiliates.
+ * Copyright (c) 2015-2019 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
@@ -177,7 +177,7 @@ map_it:
   return SSVM_API_ERROR_SLAVE_TIMEOUT;
 
 re_map_it:
-  ssvm->requested_va = (u64) sh->ssvm_va;
+  ssvm->requested_va = sh->ssvm_va;
   ssvm->ssvm_size = sh->ssvm_size;
   munmap (sh, MMAP_PAGESIZE);
 
@@ -213,7 +213,7 @@ ssvm_delete_shm (ssvm_private_t * ssvm)
   vec_free (fn);
   vec_free (ssvm->name);
 
-  munmap ((void *) ssvm->requested_va, ssvm->ssvm_size);
+  munmap ((void *) ssvm->sh, ssvm->ssvm_size);
 }
 
 /**
@@ -352,8 +352,8 @@ ssvm_master_init_private (ssvm_private_t * ssvm)
   u32 rnd_size = 0;
   u8 *heap;
 
-  rnd_size = (ssvm->ssvm_size + (pagesize - 1)) & ~(pagesize - 1);
-  rnd_size = clib_min (rnd_size, ((u64) 1 << 32) - pagesize);
+  rnd_size = clib_max (ssvm->ssvm_size + (pagesize - 1), ssvm->ssvm_size);
+  rnd_size &= ~(pagesize - 1);
 
 #if USE_DLMALLOC == 0
   {
@@ -370,6 +370,7 @@ ssvm_master_init_private (ssvm_private_t * ssvm)
   }
 #else
   heap = create_mspace (rnd_size, 1 /* locked */ );
+  mspace_disable_expand (heap);
 #endif
 
   ssvm->ssvm_size = rnd_size;
@@ -383,7 +384,9 @@ ssvm_master_init_private (ssvm_private_t * ssvm)
 
   clib_memset (sh, 0, sizeof (*sh));
   sh->heap = heap;
+  sh->ssvm_va = pointer_to_uword (heap);
   sh->type = SSVM_SEGMENT_PRIVATE;
+  sh->name = ssvm->name;
 
   return 0;
 }