blob: ce07c37b24ed895066de11893a9bab83ab5105d0 [file] [log] [blame]
Klement Sekera58eb8662017-06-09 06:06:49 +02001/*
2 *------------------------------------------------------------------
3 * Copyright (c) 2009 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
16 */
17
18#ifndef __included_svm_common_h__
19#define __included_svm_common_h__
20
21#include <stdarg.h>
22#include <pthread.h>
23#include <vppinfra/types.h>
24
25#define SVM_VERSION ((1<<16) | 1) /* set to declare region ready. */
26
27#define SVM_FLAGS_MHEAP (1<<0) /* region contains an mheap */
28#define SVM_FLAGS_FILE (1<<1) /* region backed by one or more files */
29#define SVM_FLAGS_NODATA (1<<2) /* region will be further subdivided */
30#define SVM_FLAGS_NEED_DATA_INIT (1<<3)
31
32#define SVM_PVT_MHEAP_SIZE (128<<10) /* region's private mheap (128k) */
33
34typedef struct svm_region_
35{
36 volatile uword version;
37 pthread_mutex_t mutex;
38 pthread_cond_t condvar;
39 int mutex_owner_pid; /* in case of trouble */
40 int mutex_owner_tag;
41 uword flags;
42 uword virtual_base; /* base of the region object */
43 uword virtual_size;
44 void *region_heap;
45 void *data_base; /* data portion base address */
46 void *data_heap; /* data heap, if any */
47 volatile void *user_ctx; /* user context pointer */
48 /* stuff allocated in the region's heap */
49 uword bitmap_size; /* nbits in virtual alloc bitmap */
50 uword *bitmap; /* the bitmap */
51 char *region_name;
52 char *backing_file;
53 char **filenames;
54 uword *client_pids;
55 /* pad */
56
57 /* next page:
58 * (64K) clib heap for the region itself
59 *
60 * data_base -> whatever is in this region
61 */
62
63} svm_region_t;
64
65typedef struct svm_map_region_args_
66{
67 const char *root_path; /* NULL means use the truly global arena */
68 const char *name;
David Johnsond9818dd2018-12-14 14:53:41 -050069 uword baseva;
Klement Sekera58eb8662017-06-09 06:06:49 +020070 u64 size;
71 u64 pvt_heap_size;
72 uword flags;
73 char *backing_file;
74 uword backing_mmap_size;
75 /* uid, gid to own the svm region(s) */
76 int uid;
77 int gid;
78} svm_map_region_args_t;
79
David Johnsond9818dd2018-12-14 14:53:41 -050080/*
81 * Memory mapped to high addresses for session/vppcom/vcl/etc...
82 */
83#if __WORDSIZE == 64
84#define HIGH_SEGMENT_BASEVA (8ULL << 30) /* 8GB */
85#elif __WORDSIZE == 32
86#define HIGH_SEGMENT_BASEVA (3584UL << 20) /* 3.5GB */
87#else
88#error "unknown __WORDSIZE"
89#endif
Klement Sekera58eb8662017-06-09 06:06:49 +020090
91/*
92 * Memory shared across all router instances. Packet buffers, etc
93 * Base should be "out of the way," and size should be big enough to
94 * cover everything we plan to put here.
95 */
Klement Sekera58eb8662017-06-09 06:06:49 +020096#define SVM_GLOBAL_REGION_SIZE (64<<20)
97#define SVM_GLOBAL_REGION_NAME "/global_vm"
Damjan Marionaec8f892018-01-08 16:35:35 +010098u64 svm_get_global_region_base_va ();
Klement Sekera58eb8662017-06-09 06:06:49 +020099
100/*
101 * Memory shared across individual router instances.
102 */
103#define SVM_OVERLAY_REGION_BASEVA \
104 (SVM_GLOBAL_REGION_BASEVA + SVM_GLOBAL_REGION_SIZE)
105#define SVM_OVERLAY_REGION_SIZE (1<<20)
106#define SVM_OVERLAY_REGION_BASENAME "/overlay_vm"
107
108typedef struct
109{
110 u8 *subregion_name;
111} svm_subregion_t;
112
113typedef struct
114{
115 svm_subregion_t *subregions; /* subregion pool */
116 uword *name_hash;
117 u8 *root_path;
Dave Wallace19296112017-08-31 15:54:11 -0400118 int uid;
119 int gid;
Klement Sekera58eb8662017-06-09 06:06:49 +0200120} svm_main_region_t;
121
122
123void *svm_region_find_or_create (svm_map_region_args_t * a);
124void svm_region_init (void);
Dave Barach59b25652017-09-10 15:04:27 -0400125void svm_region_init_mapped_region (svm_map_region_args_t * a,
126 svm_region_t * rp);
Ole Troan3cdc25f2017-08-17 11:07:33 +0200127int svm_region_init_chroot (const char *root_path);
Klement Sekera58eb8662017-06-09 06:06:49 +0200128void svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid);
129void svm_region_init_args (svm_map_region_args_t * a);
130void svm_region_exit (void);
Florin Corasd6c30d92018-01-29 05:11:24 -0800131void svm_region_exit_client (void);
Klement Sekera58eb8662017-06-09 06:06:49 +0200132void svm_region_unmap (void *rp_arg);
Florin Corasd6c30d92018-01-29 05:11:24 -0800133void svm_region_unmap_client (void *rp_arg);
Klement Sekera58eb8662017-06-09 06:06:49 +0200134void svm_client_scan (const char *root_path);
135void svm_client_scan_this_region_nolock (svm_region_t * rp);
136u8 *shm_name_from_svm_map_region_args (svm_map_region_args_t * a);
137u8 *format_svm_region (u8 * s, va_list * args);
138
139svm_region_t *svm_get_root_rp (void);
140
141#endif /* __included_svm_common_h__ */
142
143/*
144 * fd.io coding-style-patch-verification: ON
145 *
146 * Local Variables:
147 * eval: (c-set-style "gnu")
148 * End:
149 */