1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2018 Joyent, Inc.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/errno.h>
#include <sys/cred.h>
#include <sys/kmem.h>
#include <sys/lgrp.h>
#include <sys/mman.h>
#include <vm/hat.h>
#include <vm/as.h>
#include <vm/seg.h>
#include <vm/seg_hole.h>
static int seghole_dup(struct seg *, struct seg *);
static int seghole_unmap(struct seg *, caddr_t, size_t);
static void seghole_free(struct seg *);
static faultcode_t seghole_fault(struct hat *, struct seg *, caddr_t, size_t,
enum fault_type, enum seg_rw);
static faultcode_t seghole_faulta(struct seg *, caddr_t);
static int seghole_setprot(struct seg *, caddr_t, size_t, uint_t);
static int seghole_checkprot(struct seg *, caddr_t, size_t, uint_t);
static int seghole_sync(struct seg *, caddr_t, size_t, int, uint_t);
static size_t seghole_incore(struct seg *, caddr_t, size_t, char *);
static int seghole_lockop(struct seg *, caddr_t, size_t, int, int, ulong_t *,
size_t);
static int seghole_getprot(struct seg *, caddr_t, size_t, uint_t *);
static u_offset_t seghole_getoffset(struct seg *, caddr_t);
static int seghole_gettype(struct seg *, caddr_t);
static int seghole_getvp(struct seg *, caddr_t, struct vnode **);
static int seghole_advise(struct seg *, caddr_t, size_t, uint_t);
static void seghole_dump(struct seg *);
static int seghole_pagelock(struct seg *, caddr_t, size_t, struct page ***,
enum lock_type, enum seg_rw);
static int seghole_setpagesize(struct seg *, caddr_t, size_t, uint_t);
static int seghole_capable(struct seg *, segcapability_t);
static struct seg_ops seghole_ops = {
seghole_dup,
seghole_unmap,
seghole_free,
seghole_fault,
seghole_faulta,
seghole_setprot,
seghole_checkprot,
NULL, /* kluster: disabled */
NULL, /* swapout: disabled */
seghole_sync,
seghole_incore,
seghole_lockop,
seghole_getprot,
seghole_getoffset,
seghole_gettype,
seghole_getvp,
seghole_advise,
seghole_dump,
seghole_pagelock,
seghole_setpagesize,
NULL, /* getmemid: disabled */
NULL, /* getpolicy: disabled */
seghole_capable,
seg_inherit_notsup
};
/*
* Create a hole in the AS.
*/
int
seghole_create(struct seg **segpp, void *argsp)
{
struct seg *seg = *segpp;
seghole_crargs_t *crargs = argsp;
seghole_data_t *data;
data = kmem_alloc(sizeof (seghole_data_t), KM_SLEEP);
data->shd_name = crargs->name;
seg->s_ops = &seghole_ops;
seg->s_data = data;
seg->s_flags = S_HOLE;
return (0);
}
static int
seghole_dup(struct seg *seg, struct seg *newseg)
{
seghole_data_t *shd = (seghole_data_t *)seg->s_data;
seghole_data_t *newshd;
ASSERT(seg->s_as && AS_WRITE_HELD(seg->s_as));
newshd = kmem_zalloc(sizeof (seghole_data_t), KM_SLEEP);
newshd->shd_name = shd->shd_name;
newseg->s_ops = seg->s_ops;
newseg->s_data = newshd;
newseg->s_flags = S_HOLE;
return (0);
}
static int
seghole_unmap(struct seg *seg, caddr_t addr, size_t len)
{
ASSERT(seg->s_as && AS_WRITE_HELD(seg->s_as));
/* Entire segment is being unmapped */
if (addr == seg->s_base && len == seg->s_size) {
seg_free(seg);
return (0);
}
/* Shrinking from low address side */
if (addr == seg->s_base) {
seg->s_base += len;
seg->s_size -= len;
return (0);
}
/* Shrinking from high address side */
if ((addr + len) == (seg->s_base + seg->s_size)) {
seg->s_size -= len;
return (0);
}
/* Do not tolerate splitting the segment */
return (EINVAL);
}
static void
seghole_free(struct seg *seg)
{
seghole_data_t *data = (seghole_data_t *)seg->s_data;
ASSERT(data != NULL);
kmem_free(data, sizeof (*data));
seg->s_data = NULL;
}
/* ARGSUSED */
static faultcode_t
seghole_fault(struct hat *hat, struct seg *seg, caddr_t addr, size_t len,
enum fault_type type, enum seg_rw tw)
{
ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as));
return (FC_NOMAP);
}
/* ARGSUSED */
static faultcode_t
seghole_faulta(struct seg *seg, caddr_t addr)
{
return (FC_NOMAP);
}
/* ARGSUSED */
static int
seghole_setprot(struct seg *seg, caddr_t addr, size_t len, uint_t prot)
{
ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as));
return (ENOMEM);
}
/* ARGSUSED */
static int
seghole_checkprot(struct seg *seg, caddr_t addr, size_t len, uint_t prot)
{
ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as));
return (ENOMEM);
}
/* ARGSUSED */
static int
seghole_sync(struct seg *seg, caddr_t addr, size_t len, int attr, uint_t flags)
{
/* Always succeed since there are no backing store to sync */
return (0);
}
/* ARGSUSED */
static size_t
seghole_incore(struct seg *seg, caddr_t addr, size_t len, char *vec)
{
ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as));
return (0);
}
/* ARGSUSED */
static int
seghole_lockop(struct seg *seg, caddr_t addr, size_t len, int attr, int op,
ulong_t *lockmap, size_t pos)
{
/*
* Emit an error consistent with there being no segment in this hole in
* the AS. The MC_LOCKAS and MC_UNLOCKAS commands will explicitly skip
* hole segments, allowing such operations to proceed as expected.
*/
return (ENOMEM);
}
static int
seghole_getprot(struct seg *seg, caddr_t addr, size_t len, uint_t *protv)
{
size_t pgno;
ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as));
/*
* Few SEGOP_GETPROT callers actually check for an error, so it's
* necessary to report zeroed protection for the length of the request.
*/
pgno = seg_page(seg, addr + len) - seg_page(seg, addr) + 1;
while (pgno > 0) {
protv[--pgno] = 0;
}
return (ENOMEM);
}
/* ARGSUSED */
static u_offset_t
seghole_getoffset(struct seg *seg, caddr_t addr)
{
/*
* To avoid leaking information about the layout of the kernel address
* space, always report '0' as the offset.
*/
return (0);
}
/* ARGSUSED */
static int
seghole_gettype(struct seg *seg, caddr_t addr)
{
return (MAP_PRIVATE);
}
/* ARGSUSED */
static int
seghole_getvp(struct seg *seg, caddr_t addr, struct vnode **vpp)
{
ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as));
return (ENOMEM);
}
/* ARGSUSED */
static int
seghole_advise(struct seg *seg, caddr_t addr, size_t len, uint_t behav)
{
return (ENOMEM);
}
/* ARGSUSED */
static void
seghole_dump(struct seg *seg)
{
/* There's nothing to dump from a hole in the AS */
}
/* ARGSUSED */
static int
seghole_pagelock(struct seg *seg, caddr_t addr, size_t len, struct page ***ppp,
enum lock_type type, enum seg_rw rw)
{
return (EFAULT);
}
/* ARGSUSED */
static int
seghole_setpagesize(struct seg *seg, caddr_t addr, size_t len, uint_t szc)
{
return (ENOMEM);
}
/* ARGSUSED */
static int
seghole_capable(struct seg *seg, segcapability_t capability)
{
/* no special capablities */
return (0);
}
|