Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2 | *------------------------------------------------------------------ |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 3 | * svm.c - shared VM allocation, mmap(...MAP_FIXED...) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4 | * library |
| 5 | * |
| 6 | * Copyright (c) 2009 Cisco and/or its affiliates. |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at: |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | *------------------------------------------------------------------ |
| 19 | */ |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/mman.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <netinet/in.h> |
| 27 | #include <signal.h> |
| 28 | #include <pthread.h> |
| 29 | #include <unistd.h> |
| 30 | #include <time.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <string.h> |
| 33 | #include <vppinfra/clib.h> |
| 34 | #include <vppinfra/vec.h> |
| 35 | #include <vppinfra/hash.h> |
| 36 | #include <vppinfra/bitmap.h> |
| 37 | #include <vppinfra/fifo.h> |
| 38 | #include <vppinfra/time.h> |
| 39 | #include <vppinfra/mheap.h> |
| 40 | #include <vppinfra/heap.h> |
| 41 | #include <vppinfra/pool.h> |
| 42 | #include <vppinfra/format.h> |
| 43 | |
| 44 | #include "svm.h" |
| 45 | |
| 46 | static svm_region_t *root_rp; |
| 47 | static int root_rp_refcount; |
| 48 | |
| 49 | #define MAXLOCK 2 |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 50 | static pthread_mutex_t *mutexes_held[MAXLOCK]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | static int nheld; |
| 52 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 53 | svm_region_t * |
| 54 | svm_get_root_rp (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 56 | return root_rp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | #define MUTEX_DEBUG |
| 60 | |
Damjan Marion | aec8f89 | 2018-01-08 16:35:35 +0100 | [diff] [blame] | 61 | u64 |
| 62 | svm_get_global_region_base_va () |
| 63 | { |
| 64 | #if __aarch64__ |
| 65 | /* On AArch64 VA space can have different size, from 36 to 48 bits. |
| 66 | Here we are trying to detect VA bits by parsing /proc/self/maps |
| 67 | address ranges */ |
| 68 | int fd; |
| 69 | unformat_input_t input; |
| 70 | u64 start, end = 0; |
| 71 | u8 bits = 0; |
| 72 | |
| 73 | if ((fd = open ("/proc/self/maps", 0)) < 0) |
| 74 | clib_unix_error ("open '/proc/self/maps'"); |
| 75 | |
| 76 | unformat_init_clib_file (&input, fd); |
| 77 | while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT) |
| 78 | { |
Gabriel Ganne | c5239ad | 2018-01-11 15:04:19 +0100 | [diff] [blame] | 79 | if (unformat (&input, "%llx-%llx", &start, &end)) |
| 80 | end--; |
Damjan Marion | aec8f89 | 2018-01-08 16:35:35 +0100 | [diff] [blame] | 81 | unformat_skip_line (&input); |
| 82 | } |
Gabriel Ganne | 83d4743 | 2018-01-10 11:40:50 +0100 | [diff] [blame] | 83 | unformat_free (&input); |
| 84 | close (fd); |
Damjan Marion | aec8f89 | 2018-01-08 16:35:35 +0100 | [diff] [blame] | 85 | |
Damjan Marion | 1105600 | 2018-05-10 13:40:44 +0200 | [diff] [blame] | 86 | bits = count_leading_zeros (end); |
Gabriel Ganne | c5239ad | 2018-01-11 15:04:19 +0100 | [diff] [blame] | 87 | bits = 64 - bits; |
Damjan Marion | aec8f89 | 2018-01-08 16:35:35 +0100 | [diff] [blame] | 88 | if (bits >= 36 && bits <= 48) |
| 89 | return ((1ul << bits) / 4) - (2 * SVM_GLOBAL_REGION_SIZE); |
| 90 | else |
| 91 | clib_unix_error ("unexpected va bits '%u'", bits); |
Damjan Marion | aec8f89 | 2018-01-08 16:35:35 +0100 | [diff] [blame] | 92 | #endif |
| 93 | |
| 94 | /* default value */ |
Dave Barach | 9466c45 | 2018-08-24 17:21:14 -0400 | [diff] [blame] | 95 | return 0x130000000ULL; |
Damjan Marion | aec8f89 | 2018-01-08 16:35:35 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 98 | static void |
| 99 | region_lock (svm_region_t * rp, int tag) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 101 | pthread_mutex_lock (&rp->mutex); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | #ifdef MUTEX_DEBUG |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 103 | rp->mutex_owner_pid = getpid (); |
| 104 | rp->mutex_owner_tag = tag; |
| 105 | #endif |
| 106 | ASSERT (nheld < MAXLOCK); |
| 107 | /* |
| 108 | * Keep score of held mutexes so we can try to exit |
| 109 | * cleanly if the world comes to an end at the worst possible |
| 110 | * moment |
| 111 | */ |
| 112 | mutexes_held[nheld++] = &rp->mutex; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 115 | static void |
| 116 | region_unlock (svm_region_t * rp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 117 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 118 | int i, j; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | #ifdef MUTEX_DEBUG |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 120 | rp->mutex_owner_pid = 0; |
| 121 | rp->mutex_owner_tag = 0; |
| 122 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 124 | for (i = nheld - 1; i >= 0; i--) |
| 125 | { |
| 126 | if (mutexes_held[i] == &rp->mutex) |
| 127 | { |
| 128 | for (j = i; j < MAXLOCK - 1; j++) |
| 129 | mutexes_held[j] = mutexes_held[j + 1]; |
| 130 | nheld--; |
| 131 | goto found; |
| 132 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 133 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 134 | ASSERT (0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | |
| 136 | found: |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 137 | CLIB_MEMORY_BARRIER (); |
| 138 | pthread_mutex_unlock (&rp->mutex); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 142 | static u8 * |
| 143 | format_svm_flags (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 144 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 145 | uword f = va_arg (*args, uword); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 147 | if (f & SVM_FLAGS_MHEAP) |
| 148 | s = format (s, "MHEAP "); |
| 149 | if (f & SVM_FLAGS_FILE) |
| 150 | s = format (s, "FILE "); |
| 151 | if (f & SVM_FLAGS_NODATA) |
| 152 | s = format (s, "NODATA "); |
| 153 | if (f & SVM_FLAGS_NEED_DATA_INIT) |
| 154 | s = format (s, "INIT "); |
| 155 | |
| 156 | return (s); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 159 | static u8 * |
| 160 | format_svm_size (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 162 | uword size = va_arg (*args, uword); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 163 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 164 | if (size >= (1 << 20)) |
| 165 | { |
| 166 | s = format (s, "(%d mb)", size >> 20); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 167 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 168 | else if (size >= (1 << 10)) |
| 169 | { |
| 170 | s = format (s, "(%d kb)", size >> 10); |
| 171 | } |
| 172 | else |
| 173 | { |
| 174 | s = format (s, "(%d bytes)", size); |
| 175 | } |
| 176 | return (s); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 179 | u8 * |
| 180 | format_svm_region (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 182 | svm_region_t *rp = va_arg (*args, svm_region_t *); |
| 183 | int verbose = va_arg (*args, int); |
| 184 | int i; |
| 185 | uword lo, hi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 187 | s = format (s, "%s: base va 0x%x size 0x%x %U\n", |
| 188 | rp->region_name, rp->virtual_base, |
| 189 | rp->virtual_size, format_svm_size, rp->virtual_size); |
| 190 | s = format (s, " user_ctx 0x%x, bitmap_size %d\n", |
| 191 | rp->user_ctx, rp->bitmap_size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 192 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 193 | if (verbose) |
| 194 | { |
| 195 | s = format (s, " flags: 0x%x %U\n", rp->flags, |
| 196 | format_svm_flags, rp->flags); |
| 197 | s = format (s, |
| 198 | " region_heap 0x%x data_base 0x%x data_heap 0x%x\n", |
| 199 | rp->region_heap, rp->data_base, rp->data_heap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 202 | s = format (s, " %d clients, pids: ", vec_len (rp->client_pids)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 203 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 204 | for (i = 0; i < vec_len (rp->client_pids); i++) |
| 205 | s = format (s, "%d ", rp->client_pids[i]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 206 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 207 | s = format (s, "\n"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 208 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 209 | if (verbose) |
| 210 | { |
| 211 | lo = hi = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 212 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 213 | s = format (s, " VM in use: "); |
| 214 | |
| 215 | for (i = 0; i < rp->bitmap_size; i++) |
| 216 | { |
| 217 | if (clib_bitmap_get_no_check (rp->bitmap, i) != 0) |
| 218 | { |
| 219 | if (lo == ~0) |
| 220 | { |
| 221 | hi = lo = rp->virtual_base + i * MMAP_PAGESIZE; |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | hi = rp->virtual_base + i * MMAP_PAGESIZE; |
| 226 | } |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | if (lo != ~0) |
| 231 | { |
| 232 | hi = rp->virtual_base + i * MMAP_PAGESIZE - 1; |
| 233 | s = format (s, " 0x%x - 0x%x (%dk)\n", lo, hi, |
| 234 | (hi - lo) >> 10); |
| 235 | lo = hi = ~0; |
| 236 | } |
| 237 | } |
| 238 | } |
Dave Barach | 6a5adc3 | 2018-07-04 10:56:23 -0400 | [diff] [blame] | 239 | #if USE_DLMALLOC == 0 |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 240 | s = format (s, " rgn heap stats: %U", format_mheap, |
| 241 | rp->region_heap, 0); |
| 242 | if ((rp->flags & SVM_FLAGS_MHEAP) && rp->data_heap) |
| 243 | { |
| 244 | s = format (s, "\n data heap stats: %U", format_mheap, |
| 245 | rp->data_heap, 1); |
| 246 | } |
| 247 | s = format (s, "\n"); |
Dave Barach | 6a5adc3 | 2018-07-04 10:56:23 -0400 | [diff] [blame] | 248 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 251 | return (s); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* |
| 255 | * rnd_pagesize |
| 256 | * Round to a pagesize multiple, presumably 4k works |
| 257 | */ |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 258 | static u64 |
| 259 | rnd_pagesize (u64 size) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 260 | { |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 261 | u64 rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 262 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 263 | rv = (size + (MMAP_PAGESIZE - 1)) & ~(MMAP_PAGESIZE - 1); |
| 264 | return (rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 267 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 268 | * svm_data_region_setup |
| 269 | */ |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 270 | static int |
| 271 | svm_data_region_create (svm_map_region_args_t * a, svm_region_t * rp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 272 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 273 | int fd; |
| 274 | u8 junk = 0; |
| 275 | uword map_size; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 277 | map_size = rp->virtual_size - (MMAP_PAGESIZE + |
| 278 | (a->pvt_heap_size ? a->pvt_heap_size : |
| 279 | SVM_PVT_MHEAP_SIZE)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 280 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 281 | if (a->flags & SVM_FLAGS_FILE) |
| 282 | { |
| 283 | struct stat statb; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 284 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 285 | fd = open (a->backing_file, O_RDWR | O_CREAT, 0777); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 286 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 287 | if (fd < 0) |
| 288 | { |
| 289 | clib_unix_warning ("open"); |
| 290 | return -1; |
| 291 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 292 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 293 | if (fstat (fd, &statb) < 0) |
| 294 | { |
| 295 | clib_unix_warning ("fstat"); |
| 296 | close (fd); |
| 297 | return -2; |
| 298 | } |
| 299 | |
| 300 | if (statb.st_mode & S_IFREG) |
| 301 | { |
| 302 | if (statb.st_size == 0) |
| 303 | { |
| 304 | if (lseek (fd, map_size, SEEK_SET) == (off_t) - 1) |
| 305 | { |
| 306 | clib_unix_warning ("seek region size"); |
| 307 | close (fd); |
| 308 | return -3; |
| 309 | } |
| 310 | if (write (fd, &junk, 1) != 1) |
| 311 | { |
| 312 | clib_unix_warning ("set region size"); |
| 313 | close (fd); |
| 314 | return -3; |
| 315 | } |
| 316 | } |
| 317 | else |
| 318 | { |
| 319 | map_size = rnd_pagesize (statb.st_size); |
| 320 | } |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | map_size = a->backing_mmap_size; |
| 325 | } |
| 326 | |
| 327 | ASSERT (map_size <= rp->virtual_size - |
| 328 | (MMAP_PAGESIZE + SVM_PVT_MHEAP_SIZE)); |
| 329 | |
| 330 | if (mmap (rp->data_base, map_size, PROT_READ | PROT_WRITE, |
| 331 | MAP_SHARED | MAP_FIXED, fd, 0) == MAP_FAILED) |
| 332 | { |
| 333 | clib_unix_warning ("mmap"); |
| 334 | close (fd); |
| 335 | return -3; |
| 336 | } |
| 337 | close (fd); |
| 338 | rp->backing_file = (char *) format (0, "%s\0", a->backing_file); |
| 339 | rp->flags |= SVM_FLAGS_FILE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 340 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 341 | |
| 342 | if (a->flags & SVM_FLAGS_MHEAP) |
| 343 | { |
Dave Barach | 6a5adc3 | 2018-07-04 10:56:23 -0400 | [diff] [blame] | 344 | #if USE_DLMALLOC == 0 |
Ole Troan | 73710c7 | 2018-06-04 22:27:49 +0200 | [diff] [blame] | 345 | mheap_t *heap_header; |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 346 | rp->data_heap = |
| 347 | mheap_alloc_with_flags ((void *) (rp->data_base), map_size, |
| 348 | MHEAP_FLAG_DISABLE_VM); |
Ole Troan | 73710c7 | 2018-06-04 22:27:49 +0200 | [diff] [blame] | 349 | heap_header = mheap_header (rp->data_heap); |
| 350 | heap_header->flags |= MHEAP_FLAG_THREAD_SAFE; |
Dave Barach | 6a5adc3 | 2018-07-04 10:56:23 -0400 | [diff] [blame] | 351 | #else |
| 352 | rp->data_heap = create_mspace_with_base (rp->data_base, |
| 353 | map_size, 1 /* locked */ ); |
| 354 | mspace_disable_expand (rp->data_heap); |
| 355 | #endif |
Ole Troan | 73710c7 | 2018-06-04 22:27:49 +0200 | [diff] [blame] | 356 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 357 | rp->flags |= SVM_FLAGS_MHEAP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 358 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 359 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 362 | static int |
| 363 | svm_data_region_map (svm_map_region_args_t * a, svm_region_t * rp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 364 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 365 | int fd; |
| 366 | u8 junk = 0; |
| 367 | uword map_size; |
| 368 | struct stat statb; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 369 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 370 | map_size = rp->virtual_size - |
| 371 | (MMAP_PAGESIZE |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 372 | + (a->pvt_heap_size ? a->pvt_heap_size : SVM_PVT_MHEAP_SIZE)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 373 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 374 | if (a->flags & SVM_FLAGS_FILE) |
| 375 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 376 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 377 | fd = open (a->backing_file, O_RDWR, 0777); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 378 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 379 | if (fd < 0) |
| 380 | { |
| 381 | clib_unix_warning ("open"); |
| 382 | return -1; |
| 383 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 384 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 385 | if (fstat (fd, &statb) < 0) |
| 386 | { |
| 387 | clib_unix_warning ("fstat"); |
| 388 | close (fd); |
| 389 | return -2; |
| 390 | } |
| 391 | |
| 392 | if (statb.st_mode & S_IFREG) |
| 393 | { |
| 394 | if (statb.st_size == 0) |
| 395 | { |
| 396 | if (lseek (fd, map_size, SEEK_SET) == (off_t) - 1) |
| 397 | { |
| 398 | clib_unix_warning ("seek region size"); |
| 399 | close (fd); |
| 400 | return -3; |
| 401 | } |
| 402 | if (write (fd, &junk, 1) != 1) |
| 403 | { |
| 404 | clib_unix_warning ("set region size"); |
| 405 | close (fd); |
| 406 | return -3; |
| 407 | } |
| 408 | } |
| 409 | else |
| 410 | { |
| 411 | map_size = rnd_pagesize (statb.st_size); |
| 412 | } |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | map_size = a->backing_mmap_size; |
| 417 | } |
| 418 | |
| 419 | ASSERT (map_size <= rp->virtual_size |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 420 | - (MMAP_PAGESIZE |
| 421 | + |
| 422 | (a->pvt_heap_size ? a->pvt_heap_size : SVM_PVT_MHEAP_SIZE))); |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 423 | |
| 424 | if (mmap (rp->data_base, map_size, PROT_READ | PROT_WRITE, |
| 425 | MAP_SHARED | MAP_FIXED, fd, 0) == MAP_FAILED) |
| 426 | { |
| 427 | clib_unix_warning ("mmap"); |
| 428 | close (fd); |
| 429 | return -3; |
| 430 | } |
| 431 | close (fd); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 432 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 433 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 436 | u8 * |
| 437 | shm_name_from_svm_map_region_args (svm_map_region_args_t * a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 438 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 439 | u8 *shm_name; |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 440 | int root_path_offset = 0; |
| 441 | int name_offset = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 442 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 443 | if (a->root_path) |
| 444 | { |
| 445 | /* Tolerate present or absent slashes */ |
| 446 | if (a->root_path[0] == '/') |
| 447 | root_path_offset++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 448 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 449 | if (a->name[0] == '/') |
| 450 | name_offset = 1; |
| 451 | |
Matej Perina | d135c19 | 2017-07-18 13:59:41 +0200 | [diff] [blame] | 452 | shm_name = format (0, "/%s-%s%c", &a->root_path[root_path_offset], |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 453 | &a->name[name_offset], 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 454 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 455 | else |
| 456 | shm_name = format (0, "%s%c", a->name, 0); |
| 457 | return (shm_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 460 | void |
| 461 | svm_region_init_mapped_region (svm_map_region_args_t * a, svm_region_t * rp) |
| 462 | { |
| 463 | pthread_mutexattr_t attr; |
| 464 | pthread_condattr_t cattr; |
| 465 | int nbits, words, bit; |
| 466 | int overhead_space; |
| 467 | void *oldheap; |
| 468 | uword data_base; |
| 469 | ASSERT (rp); |
| 470 | int rv; |
| 471 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 472 | clib_memset (rp, 0, sizeof (*rp)); |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 473 | |
| 474 | if (pthread_mutexattr_init (&attr)) |
| 475 | clib_unix_warning ("mutexattr_init"); |
| 476 | |
| 477 | if (pthread_mutexattr_setpshared (&attr, PTHREAD_PROCESS_SHARED)) |
| 478 | clib_unix_warning ("mutexattr_setpshared"); |
| 479 | |
| 480 | if (pthread_mutex_init (&rp->mutex, &attr)) |
| 481 | clib_unix_warning ("mutex_init"); |
| 482 | |
| 483 | if (pthread_mutexattr_destroy (&attr)) |
| 484 | clib_unix_warning ("mutexattr_destroy"); |
| 485 | |
| 486 | if (pthread_condattr_init (&cattr)) |
| 487 | clib_unix_warning ("condattr_init"); |
| 488 | |
| 489 | if (pthread_condattr_setpshared (&cattr, PTHREAD_PROCESS_SHARED)) |
| 490 | clib_unix_warning ("condattr_setpshared"); |
| 491 | |
| 492 | if (pthread_cond_init (&rp->condvar, &cattr)) |
| 493 | clib_unix_warning ("cond_init"); |
| 494 | |
| 495 | if (pthread_condattr_destroy (&cattr)) |
| 496 | clib_unix_warning ("condattr_destroy"); |
| 497 | |
| 498 | region_lock (rp, 1); |
| 499 | |
| 500 | rp->virtual_base = a->baseva; |
| 501 | rp->virtual_size = a->size; |
| 502 | |
Dave Barach | 6a5adc3 | 2018-07-04 10:56:23 -0400 | [diff] [blame] | 503 | #if USE_DLMALLOC == 0 |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 504 | rp->region_heap = |
| 505 | mheap_alloc_with_flags (uword_to_pointer |
| 506 | (a->baseva + MMAP_PAGESIZE, void *), |
| 507 | (a->pvt_heap_size != |
| 508 | 0) ? a->pvt_heap_size : SVM_PVT_MHEAP_SIZE, |
| 509 | MHEAP_FLAG_DISABLE_VM); |
Dave Barach | 6a5adc3 | 2018-07-04 10:56:23 -0400 | [diff] [blame] | 510 | #else |
| 511 | rp->region_heap = create_mspace_with_base |
| 512 | (uword_to_pointer (a->baseva + MMAP_PAGESIZE, void *), |
| 513 | (a->pvt_heap_size != |
| 514 | 0) ? a->pvt_heap_size : SVM_PVT_MHEAP_SIZE, 1 /* locked */ ); |
| 515 | |
| 516 | mspace_disable_expand (rp->region_heap); |
| 517 | #endif |
| 518 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 519 | oldheap = svm_push_pvt_heap (rp); |
| 520 | |
| 521 | rp->region_name = (char *) format (0, "%s%c", a->name, 0); |
| 522 | vec_add1 (rp->client_pids, getpid ()); |
| 523 | |
| 524 | nbits = rp->virtual_size / MMAP_PAGESIZE; |
| 525 | |
| 526 | ASSERT (nbits > 0); |
| 527 | rp->bitmap_size = nbits; |
| 528 | words = (nbits + BITS (uword) - 1) / BITS (uword); |
| 529 | vec_validate (rp->bitmap, words - 1); |
| 530 | |
| 531 | overhead_space = MMAP_PAGESIZE /* header */ + |
| 532 | ((a->pvt_heap_size != 0) ? a->pvt_heap_size : SVM_PVT_MHEAP_SIZE); |
| 533 | |
| 534 | bit = 0; |
| 535 | data_base = (uword) rp->virtual_base; |
| 536 | |
| 537 | if (a->flags & SVM_FLAGS_NODATA) |
| 538 | rp->flags |= SVM_FLAGS_NEED_DATA_INIT; |
| 539 | |
| 540 | do |
| 541 | { |
| 542 | clib_bitmap_set_no_check (rp->bitmap, bit, 1); |
| 543 | bit++; |
| 544 | overhead_space -= MMAP_PAGESIZE; |
| 545 | data_base += MMAP_PAGESIZE; |
| 546 | } |
| 547 | while (overhead_space > 0); |
| 548 | |
| 549 | rp->data_base = (void *) data_base; |
| 550 | |
| 551 | /* |
| 552 | * Note: although the POSIX spec guarantees that only one |
| 553 | * process enters this block, we have to play games |
| 554 | * to hold off clients until e.g. the mutex is ready |
| 555 | */ |
| 556 | rp->version = SVM_VERSION; |
| 557 | |
| 558 | /* setup the data portion of the region */ |
| 559 | |
| 560 | rv = svm_data_region_create (a, rp); |
| 561 | if (rv) |
| 562 | { |
| 563 | clib_warning ("data_region_create: %d", rv); |
| 564 | } |
| 565 | |
| 566 | region_unlock (rp); |
| 567 | |
| 568 | svm_pop_heap (oldheap); |
| 569 | } |
| 570 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 571 | /* |
| 572 | * svm_map_region |
| 573 | */ |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 574 | void * |
| 575 | svm_map_region (svm_map_region_args_t * a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 576 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 577 | int svm_fd; |
| 578 | svm_region_t *rp; |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 579 | int deadman = 0; |
| 580 | u8 junk = 0; |
| 581 | void *oldheap; |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 582 | int rv; |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 583 | int pid_holding_region_lock; |
| 584 | u8 *shm_name; |
| 585 | int dead_region_recovery = 0; |
| 586 | int time_left; |
| 587 | struct stat stat; |
| 588 | struct timespec ts, tsrem; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 589 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 590 | ASSERT ((a->size & ~(MMAP_PAGESIZE - 1)) == a->size); |
| 591 | ASSERT (a->name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 592 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 593 | shm_name = shm_name_from_svm_map_region_args (a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 594 | |
Dave Wallace | d756b35 | 2017-07-03 13:11:38 -0400 | [diff] [blame] | 595 | if (CLIB_DEBUG > 1) |
| 596 | clib_warning ("[%d] map region %s: shm_open (%s)", |
| 597 | getpid (), a->name, shm_name); |
| 598 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 599 | svm_fd = shm_open ((char *) shm_name, O_RDWR | O_CREAT | O_EXCL, 0777); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 600 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 601 | if (svm_fd >= 0) |
| 602 | { |
Dave Wallace | 1929611 | 2017-08-31 15:54:11 -0400 | [diff] [blame] | 603 | if (fchmod (svm_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0) |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 604 | clib_unix_warning ("segment chmod"); |
| 605 | /* This turns out to fail harmlessly if the client starts first */ |
| 606 | if (fchown (svm_fd, a->uid, a->gid) < 0) |
| 607 | clib_unix_warning ("segment chown [ok if client starts first]"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 608 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 609 | vec_free (shm_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 610 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 611 | if (lseek (svm_fd, a->size, SEEK_SET) == (off_t) - 1) |
| 612 | { |
| 613 | clib_warning ("seek region size"); |
| 614 | close (svm_fd); |
| 615 | return (0); |
| 616 | } |
| 617 | if (write (svm_fd, &junk, 1) != 1) |
| 618 | { |
| 619 | clib_warning ("set region size"); |
| 620 | close (svm_fd); |
| 621 | return (0); |
| 622 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 623 | |
Damjan Marion | 7bee80c | 2017-04-26 15:32:12 +0200 | [diff] [blame] | 624 | rp = mmap (uword_to_pointer (a->baseva, void *), a->size, |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 625 | PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, svm_fd, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 626 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 627 | if (rp == (svm_region_t *) MAP_FAILED) |
| 628 | { |
| 629 | clib_unix_warning ("mmap create"); |
| 630 | close (svm_fd); |
| 631 | return (0); |
| 632 | } |
| 633 | close (svm_fd); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 634 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 635 | svm_region_init_mapped_region (a, rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 636 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 637 | return ((void *) rp); |
| 638 | } |
| 639 | else |
| 640 | { |
| 641 | svm_fd = shm_open ((char *) shm_name, O_RDWR, 0777); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 642 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 643 | vec_free (shm_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 644 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 645 | if (svm_fd < 0) |
| 646 | { |
| 647 | perror ("svm_region_map(mmap open)"); |
| 648 | return (0); |
| 649 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 650 | |
Ole Troan | c4f2ef7 | 2018-05-30 22:43:25 +0200 | [diff] [blame] | 651 | /* Reset ownership in case the client started first */ |
| 652 | if (fchown (svm_fd, a->uid, a->gid) < 0) |
| 653 | clib_unix_warning ("segment chown [ok if client starts first]"); |
| 654 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 655 | time_left = 20; |
| 656 | while (1) |
| 657 | { |
| 658 | if (0 != fstat (svm_fd, &stat)) |
| 659 | { |
| 660 | clib_warning ("fstat failed: %d", errno); |
| 661 | close (svm_fd); |
| 662 | return (0); |
| 663 | } |
| 664 | if (stat.st_size > 0) |
| 665 | { |
| 666 | break; |
| 667 | } |
| 668 | if (0 == time_left) |
| 669 | { |
| 670 | clib_warning ("waiting for resize of shm file timed out"); |
| 671 | close (svm_fd); |
| 672 | return (0); |
| 673 | } |
| 674 | ts.tv_sec = 0; |
| 675 | ts.tv_nsec = 100000000; |
| 676 | while (nanosleep (&ts, &tsrem) < 0) |
| 677 | ts = tsrem; |
| 678 | time_left--; |
| 679 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 680 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 681 | rp = mmap (0, MMAP_PAGESIZE, |
| 682 | PROT_READ | PROT_WRITE, MAP_SHARED, svm_fd, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 683 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 684 | if (rp == (svm_region_t *) MAP_FAILED) |
| 685 | { |
| 686 | close (svm_fd); |
| 687 | clib_warning ("mmap"); |
| 688 | return (0); |
| 689 | } |
| 690 | /* |
| 691 | * We lost the footrace to create this region; make sure |
| 692 | * the winner has crossed the finish line. |
| 693 | */ |
| 694 | while (rp->version == 0 && deadman++ < 5) |
| 695 | { |
| 696 | sleep (1); |
| 697 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 698 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 699 | /* |
| 700 | * <bleep>-ed? |
| 701 | */ |
| 702 | if (rp->version == 0) |
| 703 | { |
| 704 | clib_warning ("rp->version %d not %d", rp->version, SVM_VERSION); |
| 705 | close (svm_fd); |
| 706 | munmap (rp, a->size); |
| 707 | return (0); |
| 708 | } |
| 709 | /* Remap now that the region has been placed */ |
| 710 | a->baseva = rp->virtual_base; |
| 711 | a->size = rp->virtual_size; |
| 712 | munmap (rp, MMAP_PAGESIZE); |
| 713 | |
Damjan Marion | 7bee80c | 2017-04-26 15:32:12 +0200 | [diff] [blame] | 714 | rp = (void *) mmap (uword_to_pointer (a->baseva, void *), a->size, |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 715 | PROT_READ | PROT_WRITE, |
| 716 | MAP_SHARED | MAP_FIXED, svm_fd, 0); |
| 717 | if ((uword) rp == (uword) MAP_FAILED) |
| 718 | { |
| 719 | clib_unix_warning ("mmap"); |
| 720 | close (svm_fd); |
| 721 | return (0); |
| 722 | } |
| 723 | |
Dave Barach | ada24ea | 2018-05-24 17:32:00 -0400 | [diff] [blame] | 724 | close (svm_fd); |
| 725 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 726 | if ((uword) rp != rp->virtual_base) |
| 727 | { |
| 728 | clib_warning ("mmap botch"); |
| 729 | } |
| 730 | |
| 731 | /* |
| 732 | * Try to fix the region mutex if it is held by |
| 733 | * a dead process |
| 734 | */ |
| 735 | pid_holding_region_lock = rp->mutex_owner_pid; |
| 736 | if (pid_holding_region_lock && kill (pid_holding_region_lock, 0) < 0) |
| 737 | { |
| 738 | clib_warning |
| 739 | ("region %s mutex held by dead pid %d, tag %d, force unlock", |
| 740 | rp->region_name, pid_holding_region_lock, rp->mutex_owner_tag); |
| 741 | /* owner pid is nonexistent */ |
| 742 | rp->mutex.__data.__owner = 0; |
| 743 | rp->mutex.__data.__lock = 0; |
| 744 | dead_region_recovery = 1; |
| 745 | } |
| 746 | |
| 747 | if (dead_region_recovery) |
| 748 | clib_warning ("recovery: attempt to re-lock region"); |
| 749 | |
| 750 | region_lock (rp, 2); |
| 751 | oldheap = svm_push_pvt_heap (rp); |
| 752 | vec_add1 (rp->client_pids, getpid ()); |
| 753 | |
| 754 | if (dead_region_recovery) |
| 755 | clib_warning ("recovery: attempt svm_data_region_map"); |
| 756 | |
| 757 | rv = svm_data_region_map (a, rp); |
| 758 | if (rv) |
| 759 | { |
| 760 | clib_warning ("data_region_map: %d", rv); |
| 761 | } |
| 762 | |
| 763 | if (dead_region_recovery) |
| 764 | clib_warning ("unlock and continue"); |
| 765 | |
| 766 | region_unlock (rp); |
| 767 | |
| 768 | svm_pop_heap (oldheap); |
| 769 | |
| 770 | return ((void *) rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 771 | |
| 772 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 773 | return 0; /* NOTREACHED */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 776 | static void |
| 777 | svm_mutex_cleanup (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 779 | int i; |
| 780 | for (i = 0; i < nheld; i++) |
| 781 | { |
| 782 | pthread_mutex_unlock (mutexes_held[i]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
Ole Troan | 3cdc25f | 2017-08-17 11:07:33 +0200 | [diff] [blame] | 786 | static int |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 787 | svm_region_init_internal (svm_map_region_args_t * a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 788 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 789 | svm_region_t *rp; |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 790 | u64 ticks = clib_cpu_time_now (); |
| 791 | uword randomize_baseva; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 792 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 793 | /* guard against klutz calls */ |
| 794 | if (root_rp) |
Ole Troan | 3cdc25f | 2017-08-17 11:07:33 +0200 | [diff] [blame] | 795 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 796 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 797 | root_rp_refcount++; |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 798 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 799 | atexit (svm_mutex_cleanup); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 800 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 801 | /* Randomize the shared-VM base at init time */ |
| 802 | if (MMAP_PAGESIZE <= (4 << 10)) |
| 803 | randomize_baseva = (ticks & 15) * MMAP_PAGESIZE; |
| 804 | else |
| 805 | randomize_baseva = (ticks & 3) * MMAP_PAGESIZE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 806 | |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 807 | a->baseva += randomize_baseva; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 808 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 809 | rp = svm_map_region (a); |
Ole Troan | 3cdc25f | 2017-08-17 11:07:33 +0200 | [diff] [blame] | 810 | if (!rp) |
| 811 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 812 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 813 | region_lock (rp, 3); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 814 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 815 | /* Set up the main region data structures */ |
| 816 | if (rp->flags & SVM_FLAGS_NEED_DATA_INIT) |
| 817 | { |
| 818 | svm_main_region_t *mp = 0; |
| 819 | void *oldheap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 820 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 821 | rp->flags &= ~(SVM_FLAGS_NEED_DATA_INIT); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 822 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 823 | oldheap = svm_push_pvt_heap (rp); |
| 824 | vec_validate (mp, 0); |
| 825 | mp->name_hash = hash_create_string (0, sizeof (uword)); |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 826 | mp->root_path = a->root_path ? format (0, "%s%c", a->root_path, 0) : 0; |
Dave Wallace | 1929611 | 2017-08-31 15:54:11 -0400 | [diff] [blame] | 827 | mp->uid = a->uid; |
| 828 | mp->gid = a->gid; |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 829 | rp->data_base = mp; |
| 830 | svm_pop_heap (oldheap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 831 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 832 | region_unlock (rp); |
| 833 | root_rp = rp; |
Ole Troan | 3cdc25f | 2017-08-17 11:07:33 +0200 | [diff] [blame] | 834 | |
| 835 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 838 | void |
| 839 | svm_region_init (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 840 | { |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 841 | svm_map_region_args_t _a, *a = &_a; |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 842 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 843 | clib_memset (a, 0, sizeof (*a)); |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 844 | a->root_path = 0; |
| 845 | a->name = SVM_GLOBAL_REGION_NAME; |
Damjan Marion | aec8f89 | 2018-01-08 16:35:35 +0100 | [diff] [blame] | 846 | a->baseva = svm_get_global_region_base_va (); |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 847 | a->size = SVM_GLOBAL_REGION_SIZE; |
| 848 | a->flags = SVM_FLAGS_NODATA; |
| 849 | a->uid = 0; |
| 850 | a->gid = 0; |
| 851 | |
| 852 | svm_region_init_internal (a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Ole Troan | 3cdc25f | 2017-08-17 11:07:33 +0200 | [diff] [blame] | 855 | int |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 856 | svm_region_init_chroot (const char *root_path) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 857 | { |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 858 | svm_map_region_args_t _a, *a = &_a; |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 859 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 860 | clib_memset (a, 0, sizeof (*a)); |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 861 | a->root_path = root_path; |
| 862 | a->name = SVM_GLOBAL_REGION_NAME; |
Damjan Marion | aec8f89 | 2018-01-08 16:35:35 +0100 | [diff] [blame] | 863 | a->baseva = svm_get_global_region_base_va (); |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 864 | a->size = SVM_GLOBAL_REGION_SIZE; |
| 865 | a->flags = SVM_FLAGS_NODATA; |
| 866 | a->uid = 0; |
| 867 | a->gid = 0; |
| 868 | |
Ole Troan | 3cdc25f | 2017-08-17 11:07:33 +0200 | [diff] [blame] | 869 | return svm_region_init_internal (a); |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 870 | } |
| 871 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 872 | void |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 873 | svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid) |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 874 | { |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 875 | svm_map_region_args_t _a, *a = &_a; |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 876 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 877 | clib_memset (a, 0, sizeof (*a)); |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 878 | a->root_path = root_path; |
| 879 | a->name = SVM_GLOBAL_REGION_NAME; |
Damjan Marion | aec8f89 | 2018-01-08 16:35:35 +0100 | [diff] [blame] | 880 | a->baseva = svm_get_global_region_base_va (); |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 881 | a->size = SVM_GLOBAL_REGION_SIZE; |
| 882 | a->flags = SVM_FLAGS_NODATA; |
| 883 | a->uid = uid; |
| 884 | a->gid = gid; |
| 885 | |
| 886 | svm_region_init_internal (a); |
| 887 | } |
| 888 | |
| 889 | void |
| 890 | svm_region_init_args (svm_map_region_args_t * a) |
| 891 | { |
| 892 | svm_region_init_internal (a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 895 | void * |
| 896 | svm_region_find_or_create (svm_map_region_args_t * a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 897 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 898 | svm_main_region_t *mp; |
| 899 | svm_region_t *rp; |
| 900 | uword need_nbits; |
| 901 | int index, i; |
| 902 | void *oldheap; |
| 903 | uword *p; |
| 904 | u8 *name; |
| 905 | svm_subregion_t *subp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 906 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 907 | ASSERT (root_rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 908 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 909 | a->size += MMAP_PAGESIZE + |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 910 | ((a->pvt_heap_size != 0) ? a->pvt_heap_size : SVM_PVT_MHEAP_SIZE); |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 911 | a->size = rnd_pagesize (a->size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 912 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 913 | region_lock (root_rp, 4); |
| 914 | oldheap = svm_push_pvt_heap (root_rp); |
| 915 | mp = root_rp->data_base; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 916 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 917 | ASSERT (mp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 918 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 919 | /* Map the named region from the correct chroot environment */ |
Jan Srnicek | 5beec81 | 2017-03-24 10:18:11 +0100 | [diff] [blame] | 920 | if (a->root_path == NULL) |
| 921 | a->root_path = (char *) mp->root_path; |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 922 | |
| 923 | /* |
| 924 | * See if this region is already known. If it is, we're |
| 925 | * almost done... |
| 926 | */ |
| 927 | p = hash_get_mem (mp->name_hash, a->name); |
| 928 | |
| 929 | if (p) |
| 930 | { |
| 931 | rp = svm_map_region (a); |
| 932 | region_unlock (root_rp); |
| 933 | svm_pop_heap (oldheap); |
| 934 | return rp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 935 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 936 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 937 | /* Create the region. */ |
| 938 | ASSERT ((a->size & ~(MMAP_PAGESIZE - 1)) == a->size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 939 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 940 | need_nbits = a->size / MMAP_PAGESIZE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 941 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 942 | index = 1; /* $$$ fixme, figure out how many bit to really skip */ |
| 943 | |
| 944 | /* |
| 945 | * Scan the virtual space allocation bitmap, looking for a large |
| 946 | * enough chunk |
| 947 | */ |
| 948 | do |
| 949 | { |
| 950 | if (clib_bitmap_get_no_check (root_rp->bitmap, index) == 0) |
| 951 | { |
| 952 | for (i = 0; i < (need_nbits - 1); i++) |
| 953 | { |
| 954 | if (clib_bitmap_get_no_check (root_rp->bitmap, index + i) == 1) |
| 955 | { |
| 956 | index = index + i; |
| 957 | goto next; |
| 958 | } |
| 959 | } |
| 960 | break; |
| 961 | } |
| 962 | index++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 963 | next:; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 964 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 965 | while (index < root_rp->bitmap_size); |
| 966 | |
| 967 | /* Completely out of VM? */ |
| 968 | if (index >= root_rp->bitmap_size) |
| 969 | { |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 970 | clib_warning ("region %s: not enough VM to allocate 0x%llx (%lld)", |
| 971 | root_rp->region_name, a->size, a->size); |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 972 | svm_pop_heap (oldheap); |
| 973 | region_unlock (root_rp); |
| 974 | return 0; |
| 975 | } |
| 976 | |
| 977 | /* |
| 978 | * Mark virtual space allocated |
| 979 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 980 | #if CLIB_DEBUG > 1 |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 981 | clib_warning ("set %d bits at index %d", need_nbits, index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 982 | #endif |
| 983 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 984 | for (i = 0; i < need_nbits; i++) |
| 985 | { |
| 986 | clib_bitmap_set_no_check (root_rp->bitmap, index + i, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 989 | /* Place this region where it goes... */ |
| 990 | a->baseva = root_rp->virtual_base + index * MMAP_PAGESIZE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 991 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 992 | rp = svm_map_region (a); |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 993 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 994 | pool_get (mp->subregions, subp); |
| 995 | name = format (0, "%s%c", a->name, 0); |
| 996 | subp->subregion_name = name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 997 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 998 | hash_set_mem (mp->name_hash, name, subp - mp->subregions); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 999 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1000 | svm_pop_heap (oldheap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1001 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1002 | region_unlock (root_rp); |
| 1003 | |
| 1004 | return (rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Dave Wallace | d756b35 | 2017-07-03 13:11:38 -0400 | [diff] [blame] | 1007 | void |
| 1008 | svm_region_unlink (svm_region_t * rp) |
| 1009 | { |
| 1010 | svm_map_region_args_t _a, *a = &_a; |
| 1011 | svm_main_region_t *mp; |
| 1012 | u8 *shm_name; |
| 1013 | |
| 1014 | ASSERT (root_rp); |
| 1015 | ASSERT (rp); |
| 1016 | ASSERT (vec_c_string_is_terminated (rp->region_name)); |
| 1017 | |
| 1018 | mp = root_rp->data_base; |
| 1019 | ASSERT (mp); |
| 1020 | |
| 1021 | a->root_path = (char *) mp->root_path; |
| 1022 | a->name = rp->region_name; |
| 1023 | shm_name = shm_name_from_svm_map_region_args (a); |
| 1024 | if (CLIB_DEBUG > 1) |
| 1025 | clib_warning ("[%d] shm_unlink (%s)", getpid (), shm_name); |
| 1026 | shm_unlink ((const char *) shm_name); |
| 1027 | vec_free (shm_name); |
| 1028 | } |
| 1029 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1030 | /* |
| 1031 | * svm_region_unmap |
| 1032 | * |
| 1033 | * Let go of the indicated region. If the calling process |
| 1034 | * is the last customer, throw it away completely. |
| 1035 | * The root region mutex guarantees atomicity with respect to |
| 1036 | * a new region client showing up at the wrong moment. |
| 1037 | */ |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1038 | void |
Florin Coras | d6c30d9 | 2018-01-29 05:11:24 -0800 | [diff] [blame] | 1039 | svm_region_unmap_internal (void *rp_arg, u8 is_client) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1040 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1041 | int i, mypid = getpid (); |
| 1042 | int nclients_left; |
| 1043 | void *oldheap; |
| 1044 | uword virtual_base, virtual_size; |
| 1045 | svm_region_t *rp = rp_arg; |
| 1046 | char *name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1047 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1048 | /* |
| 1049 | * If we take a signal while holding one or more shared-memory |
| 1050 | * mutexes, we may end up back here from an otherwise |
| 1051 | * benign exit handler. Bail out to avoid a recursive |
| 1052 | * mutex screw-up. |
| 1053 | */ |
| 1054 | if (nheld) |
| 1055 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1056 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1057 | ASSERT (rp); |
| 1058 | ASSERT (root_rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1059 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1060 | if (CLIB_DEBUG > 1) |
| 1061 | clib_warning ("[%d] unmap region %s", getpid (), rp->region_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1062 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1063 | region_lock (root_rp, 5); |
| 1064 | region_lock (rp, 6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1065 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1066 | oldheap = svm_push_pvt_heap (rp); /* nb vec_delete() in the loop */ |
| 1067 | |
| 1068 | /* Remove the caller from the list of mappers */ |
| 1069 | for (i = 0; i < vec_len (rp->client_pids); i++) |
| 1070 | { |
| 1071 | if (rp->client_pids[i] == mypid) |
| 1072 | { |
| 1073 | vec_delete (rp->client_pids, 1, i); |
| 1074 | goto found; |
| 1075 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1076 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1077 | clib_warning ("pid %d AWOL", mypid); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1078 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1079 | found: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1080 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1081 | svm_pop_heap (oldheap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1082 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1083 | nclients_left = vec_len (rp->client_pids); |
| 1084 | virtual_base = rp->virtual_base; |
| 1085 | virtual_size = rp->virtual_size; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1086 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1087 | if (nclients_left == 0) |
| 1088 | { |
| 1089 | int index, nbits, i; |
| 1090 | svm_main_region_t *mp; |
| 1091 | uword *p; |
| 1092 | svm_subregion_t *subp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1093 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1094 | /* Kill the region, last guy on his way out */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1095 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1096 | oldheap = svm_push_pvt_heap (root_rp); |
| 1097 | name = vec_dup (rp->region_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1098 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1099 | virtual_base = rp->virtual_base; |
| 1100 | virtual_size = rp->virtual_size; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1101 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1102 | /* Figure out which bits to clear in the root region bitmap */ |
| 1103 | index = (virtual_base - root_rp->virtual_base) / MMAP_PAGESIZE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1104 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1105 | nbits = (virtual_size + MMAP_PAGESIZE - 1) / MMAP_PAGESIZE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1106 | |
| 1107 | #if CLIB_DEBUG > 1 |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1108 | clib_warning ("clear %d bits at index %d", nbits, index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1109 | #endif |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1110 | /* Give back the allocated VM */ |
| 1111 | for (i = 0; i < nbits; i++) |
| 1112 | { |
| 1113 | clib_bitmap_set_no_check (root_rp->bitmap, index + i, 0); |
| 1114 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1115 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1116 | mp = root_rp->data_base; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1117 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1118 | p = hash_get_mem (mp->name_hash, name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1119 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1120 | /* Better never happen ... */ |
| 1121 | if (p == NULL) |
| 1122 | { |
| 1123 | region_unlock (rp); |
| 1124 | region_unlock (root_rp); |
| 1125 | svm_pop_heap (oldheap); |
| 1126 | clib_warning ("Region name '%s' not found?", name); |
| 1127 | return; |
| 1128 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1129 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1130 | /* Remove from the root region subregion pool */ |
| 1131 | subp = mp->subregions + p[0]; |
| 1132 | pool_put (mp->subregions, subp); |
| 1133 | |
| 1134 | hash_unset_mem (mp->name_hash, name); |
| 1135 | |
| 1136 | vec_free (name); |
| 1137 | |
| 1138 | region_unlock (rp); |
Florin Coras | d6c30d9 | 2018-01-29 05:11:24 -0800 | [diff] [blame] | 1139 | |
| 1140 | /* If a client asks for the cleanup, don't unlink the backing |
| 1141 | * file since we can't tell if it has been recreated. */ |
| 1142 | if (!is_client) |
| 1143 | svm_region_unlink (rp); |
| 1144 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1145 | munmap ((void *) virtual_base, virtual_size); |
| 1146 | region_unlock (root_rp); |
| 1147 | svm_pop_heap (oldheap); |
| 1148 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1151 | region_unlock (rp); |
| 1152 | region_unlock (root_rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1153 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1154 | munmap ((void *) virtual_base, virtual_size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
Florin Coras | d6c30d9 | 2018-01-29 05:11:24 -0800 | [diff] [blame] | 1157 | void |
| 1158 | svm_region_unmap (void *rp_arg) |
| 1159 | { |
| 1160 | svm_region_unmap_internal (rp_arg, 0 /* is_client */ ); |
| 1161 | } |
| 1162 | |
| 1163 | void |
| 1164 | svm_region_unmap_client (void *rp_arg) |
| 1165 | { |
| 1166 | svm_region_unmap_internal (rp_arg, 1 /* is_client */ ); |
| 1167 | } |
| 1168 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1169 | /* |
| 1170 | * svm_region_exit |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1171 | */ |
Florin Coras | d6c30d9 | 2018-01-29 05:11:24 -0800 | [diff] [blame] | 1172 | static void |
| 1173 | svm_region_exit_internal (u8 is_client) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1174 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1175 | void *oldheap; |
| 1176 | int i, mypid = getpid (); |
| 1177 | uword virtual_base, virtual_size; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1178 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1179 | /* It felt so nice we did it twice... */ |
| 1180 | if (root_rp == 0) |
| 1181 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1182 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1183 | if (--root_rp_refcount > 0) |
| 1184 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1185 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1186 | /* |
| 1187 | * If we take a signal while holding one or more shared-memory |
| 1188 | * mutexes, we may end up back here from an otherwise |
| 1189 | * benign exit handler. Bail out to avoid a recursive |
| 1190 | * mutex screw-up. |
| 1191 | */ |
| 1192 | if (nheld) |
| 1193 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1194 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1195 | region_lock (root_rp, 7); |
| 1196 | oldheap = svm_push_pvt_heap (root_rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1197 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1198 | virtual_base = root_rp->virtual_base; |
| 1199 | virtual_size = root_rp->virtual_size; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1200 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1201 | for (i = 0; i < vec_len (root_rp->client_pids); i++) |
| 1202 | { |
| 1203 | if (root_rp->client_pids[i] == mypid) |
| 1204 | { |
| 1205 | vec_delete (root_rp->client_pids, 1, i); |
| 1206 | goto found; |
| 1207 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1208 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1209 | clib_warning ("pid %d AWOL", mypid); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1210 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1211 | found: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1212 | |
Florin Coras | d6c30d9 | 2018-01-29 05:11:24 -0800 | [diff] [blame] | 1213 | if (!is_client && vec_len (root_rp->client_pids) == 0) |
Dave Wallace | d756b35 | 2017-07-03 13:11:38 -0400 | [diff] [blame] | 1214 | svm_region_unlink (root_rp); |
| 1215 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1216 | region_unlock (root_rp); |
| 1217 | svm_pop_heap (oldheap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1218 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1219 | root_rp = 0; |
| 1220 | munmap ((void *) virtual_base, virtual_size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1223 | void |
Florin Coras | d6c30d9 | 2018-01-29 05:11:24 -0800 | [diff] [blame] | 1224 | svm_region_exit (void) |
| 1225 | { |
| 1226 | svm_region_exit_internal (0 /* is_client */ ); |
| 1227 | } |
| 1228 | |
| 1229 | void |
| 1230 | svm_region_exit_client (void) |
| 1231 | { |
| 1232 | svm_region_exit_internal (1 /* is_client */ ); |
| 1233 | } |
| 1234 | |
| 1235 | void |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1236 | svm_client_scan_this_region_nolock (svm_region_t * rp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1237 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1238 | int j; |
| 1239 | int mypid = getpid (); |
| 1240 | void *oldheap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1241 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1242 | for (j = 0; j < vec_len (rp->client_pids); j++) |
| 1243 | { |
| 1244 | if (mypid == rp->client_pids[j]) |
| 1245 | continue; |
| 1246 | if (rp->client_pids[j] && (kill (rp->client_pids[j], 0) < 0)) |
| 1247 | { |
| 1248 | clib_warning ("%s: cleanup ghost pid %d", |
| 1249 | rp->region_name, rp->client_pids[j]); |
| 1250 | /* nb: client vec in rp->region_heap */ |
| 1251 | oldheap = svm_push_pvt_heap (rp); |
| 1252 | vec_delete (rp->client_pids, 1, j); |
| 1253 | j--; |
| 1254 | svm_pop_heap (oldheap); |
| 1255 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1260 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1261 | * Scan svm regions for dead clients |
| 1262 | */ |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1263 | void |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 1264 | svm_client_scan (const char *root_path) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1265 | { |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1266 | int i, j; |
| 1267 | svm_main_region_t *mp; |
| 1268 | svm_map_region_args_t *a = 0; |
| 1269 | svm_region_t *root_rp; |
| 1270 | svm_region_t *rp; |
| 1271 | svm_subregion_t *subp; |
| 1272 | u8 *name = 0; |
| 1273 | u8 **svm_names = 0; |
| 1274 | void *oldheap; |
| 1275 | int mypid = getpid (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1276 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1277 | vec_validate (a, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1278 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1279 | svm_region_init_chroot (root_path); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1280 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1281 | root_rp = svm_get_root_rp (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1282 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1283 | pthread_mutex_lock (&root_rp->mutex); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1284 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1285 | mp = root_rp->data_base; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1286 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1287 | for (j = 0; j < vec_len (root_rp->client_pids); j++) |
| 1288 | { |
| 1289 | if (mypid == root_rp->client_pids[j]) |
| 1290 | continue; |
| 1291 | if (root_rp->client_pids[j] && (kill (root_rp->client_pids[j], 0) < 0)) |
| 1292 | { |
| 1293 | clib_warning ("%s: cleanup ghost pid %d", |
| 1294 | root_rp->region_name, root_rp->client_pids[j]); |
| 1295 | /* nb: client vec in root_rp->region_heap */ |
| 1296 | oldheap = svm_push_pvt_heap (root_rp); |
| 1297 | vec_delete (root_rp->client_pids, 1, j); |
| 1298 | j--; |
| 1299 | svm_pop_heap (oldheap); |
| 1300 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1303 | /* |
| 1304 | * Snapshoot names, can't hold root rp mutex across |
| 1305 | * find_or_create. |
| 1306 | */ |
| 1307 | /* *INDENT-OFF* */ |
| 1308 | pool_foreach (subp, mp->subregions, ({ |
| 1309 | name = vec_dup (subp->subregion_name); |
| 1310 | vec_add1(svm_names, name); |
| 1311 | })); |
| 1312 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1313 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1314 | pthread_mutex_unlock (&root_rp->mutex); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1315 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1316 | for (i = 0; i < vec_len (svm_names); i++) |
| 1317 | { |
| 1318 | vec_validate (a, 0); |
| 1319 | a->root_path = root_path; |
| 1320 | a->name = (char *) svm_names[i]; |
| 1321 | rp = svm_region_find_or_create (a); |
| 1322 | if (rp) |
| 1323 | { |
| 1324 | pthread_mutex_lock (&rp->mutex); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1325 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1326 | svm_client_scan_this_region_nolock (rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1327 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1328 | pthread_mutex_unlock (&rp->mutex); |
| 1329 | svm_region_unmap (rp); |
| 1330 | vec_free (svm_names[i]); |
| 1331 | } |
| 1332 | vec_free (a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1333 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1334 | vec_free (svm_names); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1335 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1336 | svm_region_exit (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1337 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1338 | vec_free (a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1339 | } |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1340 | |
| 1341 | /* |
| 1342 | * fd.io coding-style-patch-verification: ON |
| 1343 | * |
| 1344 | * Local Variables: |
| 1345 | * eval: (c-set-style "gnu") |
| 1346 | * End: |
| 1347 | */ |