genfs_io.c revision 1.90 1 /* $NetBSD: genfs_io.c,v 1.90 2020/03/14 18:08:39 ad Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.90 2020/03/14 18:08:39 ad Exp $");
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/proc.h>
39 #include <sys/kernel.h>
40 #include <sys/mount.h>
41 #include <sys/vnode.h>
42 #include <sys/kmem.h>
43 #include <sys/kauth.h>
44 #include <sys/fstrans.h>
45 #include <sys/buf.h>
46
47 #include <miscfs/genfs/genfs.h>
48 #include <miscfs/genfs/genfs_node.h>
49 #include <miscfs/specfs/specdev.h>
50
51 #include <uvm/uvm.h>
52 #include <uvm/uvm_pager.h>
53 #include <uvm/uvm_page_array.h>
54
55 static int genfs_do_directio(struct vmspace *, vaddr_t, size_t, struct vnode *,
56 off_t, enum uio_rw);
57 static void genfs_dio_iodone(struct buf *);
58
59 static int genfs_getpages_read(struct vnode *, struct vm_page **, int, off_t,
60 off_t, bool, bool, bool, bool);
61 static int genfs_do_io(struct vnode *, off_t, vaddr_t, size_t, int, enum uio_rw,
62 void (*)(struct buf *));
63 static void genfs_rel_pages(struct vm_page **, unsigned int);
64 static void genfs_markdirty(struct vnode *);
65
66 int genfs_maxdio = MAXPHYS;
67
68 static void
69 genfs_rel_pages(struct vm_page **pgs, unsigned int npages)
70 {
71 unsigned int i;
72
73 for (i = 0; i < npages; i++) {
74 struct vm_page *pg = pgs[i];
75
76 if (pg == NULL || pg == PGO_DONTCARE)
77 continue;
78 KASSERT(uvm_page_owner_locked_p(pg, true));
79 if (pg->flags & PG_FAKE) {
80 pg->flags |= PG_RELEASED;
81 }
82 }
83 uvm_page_unbusy(pgs, npages);
84 }
85
86 static void
87 genfs_markdirty(struct vnode *vp)
88 {
89
90 KASSERT(rw_write_held(vp->v_uobj.vmobjlock));
91
92 mutex_enter(vp->v_interlock);
93 if ((vp->v_iflag & VI_ONWORKLST) == 0) {
94 vn_syncer_add_to_worklist(vp, filedelay);
95 }
96 if ((vp->v_iflag & (VI_WRMAP|VI_WRMAPDIRTY)) == VI_WRMAP) {
97 vp->v_iflag |= VI_WRMAPDIRTY;
98 }
99 mutex_exit(vp->v_interlock);
100 }
101
102 /*
103 * generic VM getpages routine.
104 * Return PG_BUSY pages for the given range,
105 * reading from backing store if necessary.
106 */
107
108 int
109 genfs_getpages(void *v)
110 {
111 struct vop_getpages_args /* {
112 struct vnode *a_vp;
113 voff_t a_offset;
114 struct vm_page **a_m;
115 int *a_count;
116 int a_centeridx;
117 vm_prot_t a_access_type;
118 int a_advice;
119 int a_flags;
120 } */ * const ap = v;
121
122 off_t diskeof, memeof;
123 int i, error, npages;
124 const int flags = ap->a_flags;
125 struct vnode * const vp = ap->a_vp;
126 struct uvm_object * const uobj = &vp->v_uobj;
127 const bool async = (flags & PGO_SYNCIO) == 0;
128 const bool memwrite = (ap->a_access_type & VM_PROT_WRITE) != 0;
129 const bool overwrite = (flags & PGO_OVERWRITE) != 0;
130 const bool blockalloc = memwrite && (flags & PGO_NOBLOCKALLOC) == 0;
131 const bool need_wapbl = (vp->v_mount->mnt_wapbl &&
132 (flags & PGO_JOURNALLOCKED) == 0);
133 const bool glocked = (flags & PGO_GLOCKHELD) != 0;
134 bool holds_wapbl = false;
135 struct mount *trans_mount = NULL;
136 UVMHIST_FUNC("genfs_getpages"); UVMHIST_CALLED(ubchist);
137
138 UVMHIST_LOG(ubchist, "vp %#jx off 0x%jx/%jx count %jd",
139 (uintptr_t)vp, ap->a_offset >> 32, ap->a_offset, *ap->a_count);
140
141 KASSERT(memwrite >= overwrite);
142 KASSERT(vp->v_type == VREG || vp->v_type == VDIR ||
143 vp->v_type == VLNK || vp->v_type == VBLK);
144
145 #ifdef DIAGNOSTIC
146 if ((flags & PGO_JOURNALLOCKED) && vp->v_mount->mnt_wapbl)
147 WAPBL_JLOCK_ASSERT(vp->v_mount);
148 #endif
149
150 mutex_enter(vp->v_interlock);
151 error = vdead_check(vp, VDEAD_NOWAIT);
152 mutex_exit(vp->v_interlock);
153 if (error) {
154 if ((flags & PGO_LOCKED) == 0)
155 rw_exit(uobj->vmobjlock);
156 return error;
157 }
158
159 startover:
160 error = 0;
161 const voff_t origvsize = vp->v_size;
162 const off_t origoffset = ap->a_offset;
163 const int orignpages = *ap->a_count;
164
165 GOP_SIZE(vp, origvsize, &diskeof, 0);
166 if (flags & PGO_PASTEOF) {
167 off_t newsize;
168 #if defined(DIAGNOSTIC)
169 off_t writeeof;
170 #endif /* defined(DIAGNOSTIC) */
171
172 newsize = MAX(origvsize,
173 origoffset + (orignpages << PAGE_SHIFT));
174 GOP_SIZE(vp, newsize, &memeof, GOP_SIZE_MEM);
175 #if defined(DIAGNOSTIC)
176 GOP_SIZE(vp, vp->v_writesize, &writeeof, GOP_SIZE_MEM);
177 if (newsize > round_page(writeeof)) {
178 panic("%s: past eof: %" PRId64 " vs. %" PRId64,
179 __func__, newsize, round_page(writeeof));
180 }
181 #endif /* defined(DIAGNOSTIC) */
182 } else {
183 GOP_SIZE(vp, origvsize, &memeof, GOP_SIZE_MEM);
184 }
185 KASSERT(ap->a_centeridx >= 0 || ap->a_centeridx <= orignpages);
186 KASSERT((origoffset & (PAGE_SIZE - 1)) == 0 && origoffset >= 0);
187 KASSERT(orignpages > 0);
188
189 /*
190 * Bounds-check the request.
191 */
192
193 if (origoffset + (ap->a_centeridx << PAGE_SHIFT) >= memeof) {
194 if ((flags & PGO_LOCKED) == 0) {
195 rw_exit(uobj->vmobjlock);
196 }
197 UVMHIST_LOG(ubchist, "off 0x%jx count %jd goes past EOF 0x%jx",
198 origoffset, *ap->a_count, memeof,0);
199 error = EINVAL;
200 goto out_err;
201 }
202
203 /* uobj is locked */
204
205 if ((flags & PGO_NOTIMESTAMP) == 0 &&
206 (vp->v_type != VBLK ||
207 (vp->v_mount->mnt_flag & MNT_NODEVMTIME) == 0)) {
208 int updflags = 0;
209
210 if ((vp->v_mount->mnt_flag & MNT_NOATIME) == 0) {
211 updflags = GOP_UPDATE_ACCESSED;
212 }
213 if (memwrite) {
214 updflags |= GOP_UPDATE_MODIFIED;
215 }
216 if (updflags != 0) {
217 GOP_MARKUPDATE(vp, updflags);
218 }
219 }
220
221 /*
222 * For PGO_LOCKED requests, just return whatever's in memory.
223 */
224
225 if (flags & PGO_LOCKED) {
226 int nfound;
227 struct vm_page *pg;
228
229 KASSERT(!glocked);
230 npages = *ap->a_count;
231 #if defined(DEBUG)
232 for (i = 0; i < npages; i++) {
233 pg = ap->a_m[i];
234 KASSERT(pg == NULL || pg == PGO_DONTCARE);
235 }
236 #endif /* defined(DEBUG) */
237 nfound = uvn_findpages(uobj, origoffset, &npages,
238 ap->a_m, NULL,
239 UFP_NOWAIT|UFP_NOALLOC|(memwrite ? UFP_NORDONLY : 0));
240 KASSERT(npages == *ap->a_count);
241 if (nfound == 0) {
242 error = EBUSY;
243 goto out_err;
244 }
245 /*
246 * lock and unlock g_glock to ensure that no one is truncating
247 * the file behind us.
248 */
249 if (!genfs_node_rdtrylock(vp)) {
250 genfs_rel_pages(ap->a_m, npages);
251
252 /*
253 * restore the array.
254 */
255
256 for (i = 0; i < npages; i++) {
257 pg = ap->a_m[i];
258
259 if (pg != NULL && pg != PGO_DONTCARE) {
260 ap->a_m[i] = NULL;
261 }
262 KASSERT(ap->a_m[i] == NULL ||
263 ap->a_m[i] == PGO_DONTCARE);
264 }
265 } else {
266 genfs_node_unlock(vp);
267 }
268 error = (ap->a_m[ap->a_centeridx] == NULL ? EBUSY : 0);
269 if (error == 0 && memwrite) {
270 for (i = 0; i < npages; i++) {
271 pg = ap->a_m[i];
272 if (pg == NULL || pg == PGO_DONTCARE) {
273 continue;
274 }
275 if (uvm_pagegetdirty(pg) ==
276 UVM_PAGE_STATUS_CLEAN) {
277 uvm_pagemarkdirty(pg,
278 UVM_PAGE_STATUS_UNKNOWN);
279 }
280 }
281 genfs_markdirty(vp);
282 }
283 goto out_err;
284 }
285 rw_exit(uobj->vmobjlock);
286
287 /*
288 * find the requested pages and make some simple checks.
289 * leave space in the page array for a whole block.
290 */
291
292 const int fs_bshift = (vp->v_type != VBLK) ?
293 vp->v_mount->mnt_fs_bshift : DEV_BSHIFT;
294 const int fs_bsize = 1 << fs_bshift;
295 #define blk_mask (fs_bsize - 1)
296 #define trunc_blk(x) ((x) & ~blk_mask)
297 #define round_blk(x) (((x) + blk_mask) & ~blk_mask)
298
299 const int orignmempages = MIN(orignpages,
300 round_page(memeof - origoffset) >> PAGE_SHIFT);
301 npages = orignmempages;
302 const off_t startoffset = trunc_blk(origoffset);
303 const off_t endoffset = MIN(
304 round_page(round_blk(origoffset + (npages << PAGE_SHIFT))),
305 round_page(memeof));
306 const int ridx = (origoffset - startoffset) >> PAGE_SHIFT;
307
308 const int pgs_size = sizeof(struct vm_page *) *
309 ((endoffset - startoffset) >> PAGE_SHIFT);
310 struct vm_page **pgs, *pgs_onstack[UBC_MAX_PAGES];
311
312 if (pgs_size > sizeof(pgs_onstack)) {
313 pgs = kmem_zalloc(pgs_size, async ? KM_NOSLEEP : KM_SLEEP);
314 if (pgs == NULL) {
315 pgs = pgs_onstack;
316 error = ENOMEM;
317 goto out_err;
318 }
319 } else {
320 pgs = pgs_onstack;
321 (void)memset(pgs, 0, pgs_size);
322 }
323
324 UVMHIST_LOG(ubchist, "ridx %jd npages %jd startoff %jd endoff %jd",
325 ridx, npages, startoffset, endoffset);
326
327 if (trans_mount == NULL) {
328 trans_mount = vp->v_mount;
329 fstrans_start(trans_mount);
330 /*
331 * check if this vnode is still valid.
332 */
333 mutex_enter(vp->v_interlock);
334 error = vdead_check(vp, 0);
335 mutex_exit(vp->v_interlock);
336 if (error)
337 goto out_err_free;
338 /*
339 * XXX: This assumes that we come here only via
340 * the mmio path
341 */
342 if (blockalloc && need_wapbl) {
343 error = WAPBL_BEGIN(trans_mount);
344 if (error)
345 goto out_err_free;
346 holds_wapbl = true;
347 }
348 }
349
350 /*
351 * hold g_glock to prevent a race with truncate.
352 *
353 * check if our idea of v_size is still valid.
354 */
355
356 KASSERT(!glocked || genfs_node_wrlocked(vp));
357 if (!glocked) {
358 if (blockalloc) {
359 genfs_node_wrlock(vp);
360 } else {
361 genfs_node_rdlock(vp);
362 }
363 }
364 rw_enter(uobj->vmobjlock, RW_WRITER);
365 if (vp->v_size < origvsize) {
366 if (!glocked) {
367 genfs_node_unlock(vp);
368 }
369 if (pgs != pgs_onstack)
370 kmem_free(pgs, pgs_size);
371 goto startover;
372 }
373
374 if (uvn_findpages(uobj, origoffset, &npages, &pgs[ridx], NULL,
375 async ? UFP_NOWAIT : UFP_ALL) != orignmempages) {
376 if (!glocked) {
377 genfs_node_unlock(vp);
378 }
379 KASSERT(async != 0);
380 genfs_rel_pages(&pgs[ridx], orignmempages);
381 rw_exit(uobj->vmobjlock);
382 error = EBUSY;
383 goto out_err_free;
384 }
385
386 /*
387 * if PGO_OVERWRITE is set, don't bother reading the pages.
388 */
389
390 if (overwrite) {
391 if (!glocked) {
392 genfs_node_unlock(vp);
393 }
394 UVMHIST_LOG(ubchist, "PGO_OVERWRITE",0,0,0,0);
395
396 for (i = 0; i < npages; i++) {
397 struct vm_page *pg = pgs[ridx + i];
398
399 /*
400 * it's caller's responsibility to allocate blocks
401 * beforehand for the overwrite case.
402 */
403
404 KASSERT((pg->flags & PG_RDONLY) == 0 || !blockalloc);
405 pg->flags &= ~PG_RDONLY;
406
407 /*
408 * mark the page DIRTY.
409 * otherwise another thread can do putpages and pull
410 * our vnode from syncer's queue before our caller does
411 * ubc_release. note that putpages won't see CLEAN
412 * pages even if they are BUSY.
413 */
414
415 uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_DIRTY);
416 }
417 npages += ridx;
418 goto out;
419 }
420
421 /*
422 * if the pages are already resident, just return them.
423 */
424
425 for (i = 0; i < npages; i++) {
426 struct vm_page *pg = pgs[ridx + i];
427
428 if ((pg->flags & PG_FAKE) ||
429 (blockalloc && (pg->flags & PG_RDONLY) != 0)) {
430 break;
431 }
432 }
433 if (i == npages) {
434 if (!glocked) {
435 genfs_node_unlock(vp);
436 }
437 UVMHIST_LOG(ubchist, "returning cached pages", 0,0,0,0);
438 npages += ridx;
439 goto out;
440 }
441
442 /*
443 * the page wasn't resident and we're not overwriting,
444 * so we're going to have to do some i/o.
445 * find any additional pages needed to cover the expanded range.
446 */
447
448 npages = (endoffset - startoffset) >> PAGE_SHIFT;
449 if (startoffset != origoffset || npages != orignmempages) {
450 int npgs;
451
452 /*
453 * we need to avoid deadlocks caused by locking
454 * additional pages at lower offsets than pages we
455 * already have locked. unlock them all and start over.
456 */
457
458 genfs_rel_pages(&pgs[ridx], orignmempages);
459 memset(pgs, 0, pgs_size);
460
461 UVMHIST_LOG(ubchist, "reset npages start 0x%jx end 0x%jx",
462 startoffset, endoffset, 0,0);
463 npgs = npages;
464 if (uvn_findpages(uobj, startoffset, &npgs, pgs, NULL,
465 async ? UFP_NOWAIT : UFP_ALL) != npages) {
466 if (!glocked) {
467 genfs_node_unlock(vp);
468 }
469 KASSERT(async != 0);
470 genfs_rel_pages(pgs, npages);
471 rw_exit(uobj->vmobjlock);
472 error = EBUSY;
473 goto out_err_free;
474 }
475 }
476
477 rw_exit(uobj->vmobjlock);
478 error = genfs_getpages_read(vp, pgs, npages, startoffset, diskeof,
479 async, memwrite, blockalloc, glocked);
480 if (!glocked) {
481 genfs_node_unlock(vp);
482 }
483 if (error == 0 && async)
484 goto out_err_free;
485 rw_enter(uobj->vmobjlock, RW_WRITER);
486
487 /*
488 * we're almost done! release the pages...
489 * for errors, we free the pages.
490 * otherwise we activate them and mark them as valid and clean.
491 * also, unbusy pages that were not actually requested.
492 */
493
494 if (error) {
495 genfs_rel_pages(pgs, npages);
496 rw_exit(uobj->vmobjlock);
497 UVMHIST_LOG(ubchist, "returning error %jd", error,0,0,0);
498 goto out_err_free;
499 }
500
501 out:
502 UVMHIST_LOG(ubchist, "succeeding, npages %jd", npages,0,0,0);
503 error = 0;
504 for (i = 0; i < npages; i++) {
505 struct vm_page *pg = pgs[i];
506 if (pg == NULL) {
507 continue;
508 }
509 UVMHIST_LOG(ubchist, "examining pg %#jx flags 0x%jx",
510 (uintptr_t)pg, pg->flags, 0,0);
511 if (pg->flags & PG_FAKE && !overwrite) {
512 /*
513 * we've read page's contents from the backing storage.
514 *
515 * for a read fault, we keep them CLEAN; if we
516 * encountered a hole while reading, the pages can
517 * already been dirtied with zeros.
518 */
519 KASSERTMSG(blockalloc || uvm_pagegetdirty(pg) ==
520 UVM_PAGE_STATUS_CLEAN, "page %p not clean", pg);
521 pg->flags &= ~PG_FAKE;
522 }
523 KASSERT(!memwrite || !blockalloc || (pg->flags & PG_RDONLY) == 0);
524 if (i < ridx || i >= ridx + orignmempages || async) {
525 UVMHIST_LOG(ubchist, "unbusy pg %#jx offset 0x%jx",
526 (uintptr_t)pg, pg->offset,0,0);
527 if (pg->flags & PG_WANTED) {
528 wakeup(pg);
529 }
530 if (pg->flags & PG_FAKE) {
531 KASSERT(overwrite);
532 uvm_pagezero(pg);
533 }
534 if (pg->flags & PG_RELEASED) {
535 uvm_pagefree(pg);
536 continue;
537 }
538 uvm_pagelock(pg);
539 uvm_pageenqueue(pg);
540 uvm_pageunlock(pg);
541 pg->flags &= ~(PG_WANTED|PG_BUSY|PG_FAKE);
542 UVM_PAGE_OWN(pg, NULL);
543 } else if (memwrite && !overwrite &&
544 uvm_pagegetdirty(pg) == UVM_PAGE_STATUS_CLEAN) {
545 /*
546 * for a write fault, start dirtiness tracking of
547 * requested pages.
548 */
549 uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_UNKNOWN);
550 }
551 }
552 if (memwrite) {
553 genfs_markdirty(vp);
554 }
555 rw_exit(uobj->vmobjlock);
556 if (ap->a_m != NULL) {
557 memcpy(ap->a_m, &pgs[ridx],
558 orignmempages * sizeof(struct vm_page *));
559 }
560
561 out_err_free:
562 if (pgs != NULL && pgs != pgs_onstack)
563 kmem_free(pgs, pgs_size);
564 out_err:
565 if (trans_mount != NULL) {
566 if (holds_wapbl)
567 WAPBL_END(trans_mount);
568 fstrans_done(trans_mount);
569 }
570 return error;
571 }
572
573 /*
574 * genfs_getpages_read: Read the pages in with VOP_BMAP/VOP_STRATEGY.
575 *
576 * "glocked" (which is currently not actually used) tells us not whether
577 * the genfs_node is locked on entry (it always is) but whether it was
578 * locked on entry to genfs_getpages.
579 */
580 static int
581 genfs_getpages_read(struct vnode *vp, struct vm_page **pgs, int npages,
582 off_t startoffset, off_t diskeof,
583 bool async, bool memwrite, bool blockalloc, bool glocked)
584 {
585 struct uvm_object * const uobj = &vp->v_uobj;
586 const int fs_bshift = (vp->v_type != VBLK) ?
587 vp->v_mount->mnt_fs_bshift : DEV_BSHIFT;
588 const int dev_bshift = (vp->v_type != VBLK) ?
589 vp->v_mount->mnt_dev_bshift : DEV_BSHIFT;
590 kauth_cred_t const cred = curlwp->l_cred; /* XXXUBC curlwp */
591 size_t bytes, iobytes, tailstart, tailbytes, totalbytes, skipbytes;
592 vaddr_t kva;
593 struct buf *bp, *mbp;
594 bool sawhole = false;
595 int i;
596 int error = 0;
597
598 UVMHIST_FUNC(__func__); UVMHIST_CALLED(ubchist);
599
600 /*
601 * read the desired page(s).
602 */
603
604 totalbytes = npages << PAGE_SHIFT;
605 bytes = MIN(totalbytes, MAX(diskeof - startoffset, 0));
606 tailbytes = totalbytes - bytes;
607 skipbytes = 0;
608
609 kva = uvm_pagermapin(pgs, npages,
610 UVMPAGER_MAPIN_READ | (async ? 0 : UVMPAGER_MAPIN_WAITOK));
611 if (kva == 0)
612 return EBUSY;
613
614 mbp = getiobuf(vp, true);
615 mbp->b_bufsize = totalbytes;
616 mbp->b_data = (void *)kva;
617 mbp->b_resid = mbp->b_bcount = bytes;
618 mbp->b_cflags |= BC_BUSY;
619 if (async) {
620 mbp->b_flags = B_READ | B_ASYNC;
621 mbp->b_iodone = uvm_aio_aiodone;
622 } else {
623 mbp->b_flags = B_READ;
624 mbp->b_iodone = NULL;
625 }
626 if (async)
627 BIO_SETPRIO(mbp, BPRIO_TIMELIMITED);
628 else
629 BIO_SETPRIO(mbp, BPRIO_TIMECRITICAL);
630
631 /*
632 * if EOF is in the middle of the range, zero the part past EOF.
633 * skip over pages which are not PG_FAKE since in that case they have
634 * valid data that we need to preserve.
635 */
636
637 tailstart = bytes;
638 while (tailbytes > 0) {
639 const int len = PAGE_SIZE - (tailstart & PAGE_MASK);
640
641 KASSERT(len <= tailbytes);
642 if ((pgs[tailstart >> PAGE_SHIFT]->flags & PG_FAKE) != 0) {
643 memset((void *)(kva + tailstart), 0, len);
644 UVMHIST_LOG(ubchist, "tailbytes %#jx 0x%jx 0x%jx",
645 (uintptr_t)kva, tailstart, len, 0);
646 }
647 tailstart += len;
648 tailbytes -= len;
649 }
650
651 /*
652 * now loop over the pages, reading as needed.
653 */
654
655 bp = NULL;
656 off_t offset;
657 for (offset = startoffset;
658 bytes > 0;
659 offset += iobytes, bytes -= iobytes) {
660 int run;
661 daddr_t lbn, blkno;
662 int pidx;
663 struct vnode *devvp;
664
665 /*
666 * skip pages which don't need to be read.
667 */
668
669 pidx = (offset - startoffset) >> PAGE_SHIFT;
670 while ((pgs[pidx]->flags & PG_FAKE) == 0) {
671 size_t b;
672
673 KASSERT((offset & (PAGE_SIZE - 1)) == 0);
674 if ((pgs[pidx]->flags & PG_RDONLY)) {
675 sawhole = true;
676 }
677 b = MIN(PAGE_SIZE, bytes);
678 offset += b;
679 bytes -= b;
680 skipbytes += b;
681 pidx++;
682 UVMHIST_LOG(ubchist, "skipping, new offset 0x%jx",
683 offset, 0,0,0);
684 if (bytes == 0) {
685 goto loopdone;
686 }
687 }
688
689 /*
690 * bmap the file to find out the blkno to read from and
691 * how much we can read in one i/o. if bmap returns an error,
692 * skip the rest of the top-level i/o.
693 */
694
695 lbn = offset >> fs_bshift;
696 error = VOP_BMAP(vp, lbn, &devvp, &blkno, &run);
697 if (error) {
698 UVMHIST_LOG(ubchist, "VOP_BMAP lbn 0x%jx -> %jd\n",
699 lbn,error,0,0);
700 skipbytes += bytes;
701 bytes = 0;
702 goto loopdone;
703 }
704
705 /*
706 * see how many pages can be read with this i/o.
707 * reduce the i/o size if necessary to avoid
708 * overwriting pages with valid data.
709 */
710
711 iobytes = MIN((((off_t)lbn + 1 + run) << fs_bshift) - offset,
712 bytes);
713 if (offset + iobytes > round_page(offset)) {
714 int pcount;
715
716 pcount = 1;
717 while (pidx + pcount < npages &&
718 pgs[pidx + pcount]->flags & PG_FAKE) {
719 pcount++;
720 }
721 iobytes = MIN(iobytes, (pcount << PAGE_SHIFT) -
722 (offset - trunc_page(offset)));
723 }
724
725 /*
726 * if this block isn't allocated, zero it instead of
727 * reading it. unless we are going to allocate blocks,
728 * mark the pages we zeroed PG_RDONLY.
729 */
730
731 if (blkno == (daddr_t)-1) {
732 int holepages = (round_page(offset + iobytes) -
733 trunc_page(offset)) >> PAGE_SHIFT;
734 UVMHIST_LOG(ubchist, "lbn 0x%jx -> HOLE", lbn,0,0,0);
735
736 sawhole = true;
737 memset((char *)kva + (offset - startoffset), 0,
738 iobytes);
739 skipbytes += iobytes;
740
741 if (!blockalloc) {
742 rw_enter(uobj->vmobjlock, RW_WRITER);
743 for (i = 0; i < holepages; i++) {
744 pgs[pidx + i]->flags |= PG_RDONLY;
745 }
746 rw_exit(uobj->vmobjlock);
747 }
748 continue;
749 }
750
751 /*
752 * allocate a sub-buf for this piece of the i/o
753 * (or just use mbp if there's only 1 piece),
754 * and start it going.
755 */
756
757 if (offset == startoffset && iobytes == bytes) {
758 bp = mbp;
759 } else {
760 UVMHIST_LOG(ubchist, "vp %#jx bp %#jx num now %jd",
761 (uintptr_t)vp, (uintptr_t)bp, vp->v_numoutput, 0);
762 bp = getiobuf(vp, true);
763 nestiobuf_setup(mbp, bp, offset - startoffset, iobytes);
764 }
765 bp->b_lblkno = 0;
766
767 /* adjust physical blkno for partial blocks */
768 bp->b_blkno = blkno + ((offset - ((off_t)lbn << fs_bshift)) >>
769 dev_bshift);
770
771 UVMHIST_LOG(ubchist,
772 "bp %#jx offset 0x%x bcount 0x%x blkno 0x%x",
773 (uintptr_t)bp, offset, bp->b_bcount, bp->b_blkno);
774
775 VOP_STRATEGY(devvp, bp);
776 }
777
778 loopdone:
779 nestiobuf_done(mbp, skipbytes, error);
780 if (async) {
781 UVMHIST_LOG(ubchist, "returning 0 (async)",0,0,0,0);
782 return 0;
783 }
784 if (bp != NULL) {
785 error = biowait(mbp);
786 }
787
788 /* Remove the mapping (make KVA available as soon as possible) */
789 uvm_pagermapout(kva, npages);
790
791 /*
792 * if this we encountered a hole then we have to do a little more work.
793 * for read faults, we marked the page PG_RDONLY so that future
794 * write accesses to the page will fault again.
795 * for write faults, we must make sure that the backing store for
796 * the page is completely allocated while the pages are locked.
797 */
798
799 if (!error && sawhole && blockalloc) {
800 error = GOP_ALLOC(vp, startoffset,
801 npages << PAGE_SHIFT, 0, cred);
802 UVMHIST_LOG(ubchist, "gop_alloc off 0x%jx/0x%jx -> %jd",
803 startoffset, npages << PAGE_SHIFT, error,0);
804 if (!error) {
805 rw_enter(uobj->vmobjlock, RW_WRITER);
806 for (i = 0; i < npages; i++) {
807 struct vm_page *pg = pgs[i];
808
809 if (pg == NULL) {
810 continue;
811 }
812 pg->flags &= ~PG_RDONLY;
813 uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_DIRTY);
814 UVMHIST_LOG(ubchist, "mark dirty pg %#jx",
815 (uintptr_t)pg, 0, 0, 0);
816 }
817 rw_exit(uobj->vmobjlock);
818 }
819 }
820
821 putiobuf(mbp);
822 return error;
823 }
824
825 /*
826 * generic VM putpages routine.
827 * Write the given range of pages to backing store.
828 *
829 * => "offhi == 0" means flush all pages at or after "offlo".
830 * => object should be locked by caller. we return with the
831 * object unlocked.
832 * => if PGO_CLEANIT or PGO_SYNCIO is set, we may block (due to I/O).
833 * thus, a caller might want to unlock higher level resources
834 * (e.g. vm_map) before calling flush.
835 * => if neither PGO_CLEANIT nor PGO_SYNCIO is set, we will not block
836 * => if PGO_ALLPAGES is set, then all pages in the object will be processed.
837 *
838 * note on "cleaning" object and PG_BUSY pages:
839 * this routine is holding the lock on the object. the only time
840 * that it can run into a PG_BUSY page that it does not own is if
841 * some other process has started I/O on the page (e.g. either
842 * a pagein, or a pageout). if the PG_BUSY page is being paged
843 * in, then it can not be dirty (!UVM_PAGE_STATUS_CLEAN) because no
844 * one has had a chance to modify it yet. if the PG_BUSY page is
845 * being paged out then it means that someone else has already started
846 * cleaning the page for us (how nice!). in this case, if we
847 * have syncio specified, then after we make our pass through the
848 * object we need to wait for the other PG_BUSY pages to clear
849 * off (i.e. we need to do an iosync). also note that once a
850 * page is PG_BUSY it must stay in its object until it is un-busyed.
851 */
852
853 int
854 genfs_putpages(void *v)
855 {
856 struct vop_putpages_args /* {
857 struct vnode *a_vp;
858 voff_t a_offlo;
859 voff_t a_offhi;
860 int a_flags;
861 } */ * const ap = v;
862
863 return genfs_do_putpages(ap->a_vp, ap->a_offlo, ap->a_offhi,
864 ap->a_flags, NULL);
865 }
866
867 int
868 genfs_do_putpages(struct vnode *vp, off_t startoff, off_t endoff,
869 int origflags, struct vm_page **busypg)
870 {
871 struct uvm_object * const uobj = &vp->v_uobj;
872 krwlock_t * const slock = uobj->vmobjlock;
873 off_t nextoff;
874 int i, error, npages, nback;
875 int freeflag;
876 /*
877 * This array is larger than it should so that it's size is constant.
878 * The right size is MAXPAGES.
879 */
880 struct vm_page *pgs[MAXPHYS / MIN_PAGE_SIZE];
881 #define MAXPAGES (MAXPHYS / PAGE_SIZE)
882 struct vm_page *pg, *tpg;
883 struct uvm_page_array a;
884 bool wasclean, needs_clean;
885 bool async = (origflags & PGO_SYNCIO) == 0;
886 bool pagedaemon = curlwp == uvm.pagedaemon_lwp;
887 struct lwp * const l = curlwp ? curlwp : &lwp0;
888 struct mount *trans_mp;
889 int flags;
890 bool modified; /* if we write out any pages */
891 bool holds_wapbl;
892 bool cleanall; /* try to pull off from the syncer's list */
893 bool onworklst;
894 bool nodirty;
895 const bool dirtyonly = (origflags & (PGO_DEACTIVATE|PGO_FREE)) == 0;
896
897 UVMHIST_FUNC("genfs_putpages"); UVMHIST_CALLED(ubchist);
898
899 KASSERT(origflags & (PGO_CLEANIT|PGO_FREE|PGO_DEACTIVATE));
900 KASSERT((startoff & PAGE_MASK) == 0 && (endoff & PAGE_MASK) == 0);
901 KASSERT(startoff < endoff || endoff == 0);
902 KASSERT(rw_write_held(slock));
903
904 UVMHIST_LOG(ubchist, "vp %#jx pages %jd off 0x%jx len 0x%jx",
905 (uintptr_t)vp, uobj->uo_npages, startoff, endoff - startoff);
906
907 #ifdef DIAGNOSTIC
908 if ((origflags & PGO_JOURNALLOCKED) && vp->v_mount->mnt_wapbl)
909 WAPBL_JLOCK_ASSERT(vp->v_mount);
910 #endif
911
912 trans_mp = NULL;
913 holds_wapbl = false;
914
915 retry:
916 modified = false;
917 flags = origflags;
918 KASSERT((vp->v_iflag & VI_ONWORKLST) != 0 ||
919 (vp->v_iflag & VI_WRMAPDIRTY) == 0);
920
921 /*
922 * shortcut if we have no pages to process.
923 */
924
925 nodirty = radix_tree_empty_tagged_tree_p(&uobj->uo_pages,
926 UVM_PAGE_DIRTY_TAG);
927 if (uobj->uo_npages == 0 || (dirtyonly && nodirty)) {
928 mutex_enter(vp->v_interlock);
929 if (vp->v_iflag & VI_ONWORKLST) {
930 vp->v_iflag &= ~VI_WRMAPDIRTY;
931 if (LIST_FIRST(&vp->v_dirtyblkhd) == NULL)
932 vn_syncer_remove_from_worklist(vp);
933 }
934 mutex_exit(vp->v_interlock);
935 if (trans_mp) {
936 if (holds_wapbl)
937 WAPBL_END(trans_mp);
938 fstrans_done(trans_mp);
939 }
940 rw_exit(slock);
941 return (0);
942 }
943
944 /*
945 * the vnode has pages, set up to process the request.
946 */
947
948 if (trans_mp == NULL && (flags & PGO_CLEANIT) != 0) {
949 if (pagedaemon) {
950 /* Pagedaemon must not sleep here. */
951 trans_mp = vp->v_mount;
952 error = fstrans_start_nowait(trans_mp);
953 if (error) {
954 rw_exit(slock);
955 return error;
956 }
957 } else {
958 /*
959 * Cannot use vdeadcheck() here as this operation
960 * usually gets used from VOP_RECLAIM(). Test for
961 * change of v_mount instead and retry on change.
962 */
963 rw_exit(slock);
964 trans_mp = vp->v_mount;
965 fstrans_start(trans_mp);
966 if (vp->v_mount != trans_mp) {
967 fstrans_done(trans_mp);
968 trans_mp = NULL;
969 } else {
970 holds_wapbl = (trans_mp->mnt_wapbl &&
971 (origflags & PGO_JOURNALLOCKED) == 0);
972 if (holds_wapbl) {
973 error = WAPBL_BEGIN(trans_mp);
974 if (error) {
975 fstrans_done(trans_mp);
976 return error;
977 }
978 }
979 }
980 rw_enter(slock, RW_WRITER);
981 goto retry;
982 }
983 }
984
985 error = 0;
986 wasclean = radix_tree_empty_tagged_tree_p(&uobj->uo_pages,
987 UVM_PAGE_WRITEBACK_TAG);
988 nextoff = startoff;
989 if (endoff == 0 || flags & PGO_ALLPAGES) {
990 endoff = trunc_page(LLONG_MAX);
991 }
992
993 /*
994 * if this vnode is known not to have dirty pages,
995 * don't bother to clean it out.
996 */
997
998 if (nodirty) {
999 #if !defined(DEBUG)
1000 if (dirtyonly) {
1001 goto skip_scan;
1002 }
1003 #endif /* !defined(DEBUG) */
1004 flags &= ~PGO_CLEANIT;
1005 }
1006
1007 /*
1008 * start the loop to scan pages.
1009 */
1010
1011 cleanall = true;
1012 freeflag = pagedaemon ? PG_PAGEOUT : PG_RELEASED;
1013 uvm_page_array_init(&a);
1014 for (;;) {
1015 bool pgprotected;
1016
1017 /*
1018 * if !dirtyonly, iterate over all resident pages in the range.
1019 *
1020 * if dirtyonly, only possibly dirty pages are interesting.
1021 * however, if we are asked to sync for integrity, we should
1022 * wait on pages being written back by other threads as well.
1023 */
1024
1025 pg = uvm_page_array_fill_and_peek(&a, uobj, nextoff, 0,
1026 dirtyonly ? (UVM_PAGE_ARRAY_FILL_DIRTY |
1027 (!async ? UVM_PAGE_ARRAY_FILL_WRITEBACK : 0)) : 0);
1028 if (pg == NULL) {
1029 break;
1030 }
1031
1032 KASSERT(pg->uobject == uobj);
1033 KASSERT((pg->flags & (PG_RELEASED|PG_PAGEOUT)) == 0 ||
1034 (pg->flags & (PG_BUSY)) != 0);
1035 KASSERT(pg->offset >= startoff);
1036 KASSERT(pg->offset >= nextoff);
1037 KASSERT(!dirtyonly ||
1038 uvm_pagegetdirty(pg) != UVM_PAGE_STATUS_CLEAN ||
1039 radix_tree_get_tag(&uobj->uo_pages,
1040 pg->offset >> PAGE_SHIFT, UVM_PAGE_WRITEBACK_TAG));
1041
1042 if (pg->offset >= endoff) {
1043 break;
1044 }
1045
1046 /*
1047 * a preempt point.
1048 */
1049
1050 if (preempt_needed()) {
1051 nextoff = pg->offset; /* visit this page again */
1052 rw_exit(slock);
1053 preempt();
1054 /*
1055 * as we dropped the object lock, our cached pages can
1056 * be stale.
1057 */
1058 uvm_page_array_clear(&a);
1059 rw_enter(slock, RW_WRITER);
1060 continue;
1061 }
1062
1063 /*
1064 * if the current page is busy, wait for it to become unbusy.
1065 */
1066
1067 if ((pg->flags & PG_BUSY) != 0) {
1068 UVMHIST_LOG(ubchist, "busy %#jx", (uintptr_t)pg,
1069 0, 0, 0);
1070 if ((pg->flags & (PG_RELEASED|PG_PAGEOUT)) != 0
1071 && (flags & PGO_BUSYFAIL) != 0) {
1072 UVMHIST_LOG(ubchist, "busyfail %#jx",
1073 (uintptr_t)pg, 0, 0, 0);
1074 error = EDEADLK;
1075 if (busypg != NULL)
1076 *busypg = pg;
1077 break;
1078 }
1079 if (pagedaemon) {
1080 /*
1081 * someone has taken the page while we
1082 * dropped the lock for fstrans_start.
1083 */
1084 break;
1085 }
1086 /*
1087 * don't bother to wait on other's activities
1088 * unless we are asked to sync for integrity.
1089 */
1090 if (!async && (flags & PGO_RECLAIM) == 0) {
1091 wasclean = false;
1092 nextoff = pg->offset + PAGE_SIZE;
1093 uvm_page_array_advance(&a);
1094 continue;
1095 }
1096 nextoff = pg->offset; /* visit this page again */
1097 pg->flags |= PG_WANTED;
1098 UVM_UNLOCK_AND_WAIT_RW(pg, slock, 0, "genput", 0);
1099 /*
1100 * as we dropped the object lock, our cached pages can
1101 * be stale.
1102 */
1103 uvm_page_array_clear(&a);
1104 rw_enter(slock, RW_WRITER);
1105 continue;
1106 }
1107
1108 nextoff = pg->offset + PAGE_SIZE;
1109 uvm_page_array_advance(&a);
1110
1111 /*
1112 * if we're freeing, remove all mappings of the page now.
1113 * if we're cleaning, check if the page is needs to be cleaned.
1114 */
1115
1116 pgprotected = false;
1117 if (flags & PGO_FREE) {
1118 pmap_page_protect(pg, VM_PROT_NONE);
1119 pgprotected = true;
1120 } else if (flags & PGO_CLEANIT) {
1121
1122 /*
1123 * if we still have some hope to pull this vnode off
1124 * from the syncer queue, write-protect the page.
1125 */
1126
1127 if (cleanall && wasclean) {
1128
1129 /*
1130 * uobj pages get wired only by uvm_fault
1131 * where uobj is locked.
1132 */
1133
1134 if (pg->wire_count == 0) {
1135 pmap_page_protect(pg,
1136 VM_PROT_READ|VM_PROT_EXECUTE);
1137 pgprotected = true;
1138 } else {
1139 cleanall = false;
1140 }
1141 }
1142 }
1143
1144 if (flags & PGO_CLEANIT) {
1145 needs_clean = uvm_pagecheckdirty(pg, pgprotected);
1146 } else {
1147 needs_clean = false;
1148 }
1149
1150 /*
1151 * if we're cleaning, build a cluster.
1152 * the cluster will consist of pages which are currently dirty.
1153 * if not cleaning, just operate on the one page.
1154 */
1155
1156 if (needs_clean) {
1157 KDASSERT((vp->v_iflag & VI_ONWORKLST));
1158 wasclean = false;
1159 memset(pgs, 0, sizeof(pgs));
1160 pg->flags |= PG_BUSY;
1161 UVM_PAGE_OWN(pg, "genfs_putpages");
1162
1163 /*
1164 * let the fs constrain the offset range of the cluster.
1165 * we additionally constrain the range here such that
1166 * it fits in the "pgs" pages array.
1167 */
1168
1169 off_t fslo, fshi, genlo, lo, off = pg->offset;
1170 GOP_PUTRANGE(vp, off, &fslo, &fshi);
1171 KASSERT(fslo == trunc_page(fslo));
1172 KASSERT(fslo <= off);
1173 KASSERT(fshi == trunc_page(fshi));
1174 KASSERT(fshi == 0 || off < fshi);
1175
1176 if (off > MAXPHYS / 2)
1177 genlo = trunc_page(off - (MAXPHYS / 2));
1178 else
1179 genlo = 0;
1180 lo = MAX(fslo, genlo);
1181
1182 /*
1183 * first look backward.
1184 */
1185
1186 npages = (off - lo) >> PAGE_SHIFT;
1187 nback = npages;
1188 uvn_findpages(uobj, off - PAGE_SIZE, &nback,
1189 &pgs[0], NULL,
1190 UFP_NOWAIT|UFP_NOALLOC|UFP_DIRTYONLY|UFP_BACKWARD);
1191 if (nback) {
1192 memmove(&pgs[0], &pgs[npages - nback],
1193 nback * sizeof(pgs[0]));
1194 if (npages - nback < nback)
1195 memset(&pgs[nback], 0,
1196 (npages - nback) * sizeof(pgs[0]));
1197 else
1198 memset(&pgs[npages - nback], 0,
1199 nback * sizeof(pgs[0]));
1200 }
1201
1202 /*
1203 * then plug in our page of interest.
1204 */
1205
1206 pgs[nback] = pg;
1207
1208 /*
1209 * then look forward to fill in the remaining space in
1210 * the array of pages.
1211 *
1212 * pass our cached array of pages so that hopefully
1213 * uvn_findpages can find some good pages in it.
1214 * the array a was filled above with the one of
1215 * following sets of flags:
1216 * 0
1217 * UVM_PAGE_ARRAY_FILL_DIRTY
1218 * UVM_PAGE_ARRAY_FILL_DIRTY|WRITEBACK
1219 */
1220
1221 npages = MAXPAGES - nback - 1;
1222 if (fshi)
1223 npages = MIN(npages,
1224 (fshi - off - 1) >> PAGE_SHIFT);
1225 uvn_findpages(uobj, off + PAGE_SIZE, &npages,
1226 &pgs[nback + 1], NULL,
1227 UFP_NOWAIT|UFP_NOALLOC|UFP_DIRTYONLY);
1228 npages += nback + 1;
1229 } else {
1230 pgs[0] = pg;
1231 npages = 1;
1232 nback = 0;
1233 }
1234
1235 /*
1236 * apply FREE or DEACTIVATE options if requested.
1237 */
1238
1239 for (i = 0; i < npages; i++) {
1240 tpg = pgs[i];
1241 KASSERT(tpg->uobject == uobj);
1242 KASSERT(i == 0 ||
1243 pgs[i-1]->offset + PAGE_SIZE == tpg->offset);
1244 KASSERT(!needs_clean || uvm_pagegetdirty(pgs[i]) !=
1245 UVM_PAGE_STATUS_DIRTY);
1246 if (needs_clean) {
1247 /*
1248 * mark pages as WRITEBACK so that concurrent
1249 * fsync can find and wait for our activities.
1250 */
1251 radix_tree_set_tag(&uobj->uo_pages,
1252 pgs[i]->offset >> PAGE_SHIFT,
1253 UVM_PAGE_WRITEBACK_TAG);
1254 }
1255 if (tpg->offset < startoff || tpg->offset >= endoff)
1256 continue;
1257 if (flags & PGO_DEACTIVATE && tpg->wire_count == 0) {
1258 uvm_pagelock(tpg);
1259 uvm_pagedeactivate(tpg);
1260 uvm_pageunlock(tpg);
1261 } else if (flags & PGO_FREE) {
1262 pmap_page_protect(tpg, VM_PROT_NONE);
1263 if (tpg->flags & PG_BUSY) {
1264 tpg->flags |= freeflag;
1265 if (pagedaemon) {
1266 uvm_pageout_start(1);
1267 uvm_pagelock(tpg);
1268 uvm_pagedequeue(tpg);
1269 uvm_pageunlock(tpg);
1270 }
1271 } else {
1272
1273 /*
1274 * ``page is not busy''
1275 * implies that npages is 1
1276 * and needs_clean is false.
1277 */
1278
1279 KASSERT(npages == 1);
1280 KASSERT(!needs_clean);
1281 KASSERT(pg == tpg);
1282 KASSERT(nextoff ==
1283 tpg->offset + PAGE_SIZE);
1284 uvm_pagefree(tpg);
1285 if (pagedaemon)
1286 uvmexp.pdfreed++;
1287 }
1288 }
1289 }
1290 if (needs_clean) {
1291 modified = true;
1292 KASSERT(nextoff == pg->offset + PAGE_SIZE);
1293 KASSERT(nback < npages);
1294 nextoff = pg->offset + ((npages - nback) << PAGE_SHIFT);
1295 KASSERT(pgs[nback] == pg);
1296 KASSERT(nextoff == pgs[npages - 1]->offset + PAGE_SIZE);
1297
1298 /*
1299 * start the i/o.
1300 */
1301 rw_exit(slock);
1302 error = GOP_WRITE(vp, pgs, npages, flags);
1303 /*
1304 * as we dropped the object lock, our cached pages can
1305 * be stale.
1306 */
1307 uvm_page_array_clear(&a);
1308 rw_enter(slock, RW_WRITER);
1309 if (error) {
1310 break;
1311 }
1312 }
1313 }
1314 uvm_page_array_fini(&a);
1315
1316 /*
1317 * update ctime/mtime if the modification we started writing out might
1318 * be from mmap'ed write.
1319 *
1320 * this is necessary when an application keeps a file mmaped and
1321 * repeatedly modifies it via the window. note that, because we
1322 * don't always write-protect pages when cleaning, such modifications
1323 * might not involve any page faults.
1324 */
1325
1326 mutex_enter(vp->v_interlock);
1327 if (modified && (vp->v_iflag & VI_WRMAPDIRTY) != 0 &&
1328 (vp->v_type != VBLK ||
1329 (vp->v_mount->mnt_flag & MNT_NODEVMTIME) == 0)) {
1330 GOP_MARKUPDATE(vp, GOP_UPDATE_MODIFIED);
1331 }
1332
1333 /*
1334 * if we no longer have any possibly dirty pages, take us off the
1335 * syncer list.
1336 */
1337
1338 if ((vp->v_iflag & VI_ONWORKLST) != 0 &&
1339 radix_tree_empty_tagged_tree_p(&uobj->uo_pages,
1340 UVM_PAGE_DIRTY_TAG)) {
1341 vp->v_iflag &= ~VI_WRMAPDIRTY;
1342 if (LIST_FIRST(&vp->v_dirtyblkhd) == NULL)
1343 vn_syncer_remove_from_worklist(vp);
1344 }
1345
1346 #if !defined(DEBUG)
1347 skip_scan:
1348 #endif /* !defined(DEBUG) */
1349
1350 /* Wait for output to complete. */
1351 rw_exit(slock);
1352 if (!wasclean && !async && vp->v_numoutput != 0) {
1353 while (vp->v_numoutput != 0)
1354 cv_wait(&vp->v_cv, vp->v_interlock);
1355 }
1356 onworklst = (vp->v_iflag & VI_ONWORKLST) != 0;
1357 mutex_exit(vp->v_interlock);
1358
1359 if ((flags & PGO_RECLAIM) != 0 && onworklst) {
1360 /*
1361 * in the case of PGO_RECLAIM, ensure to make the vnode clean.
1362 * retrying is not a big deal because, in many cases,
1363 * uobj->uo_npages is already 0 here.
1364 */
1365 rw_enter(slock, RW_WRITER);
1366 goto retry;
1367 }
1368
1369 if (trans_mp) {
1370 if (holds_wapbl)
1371 WAPBL_END(trans_mp);
1372 fstrans_done(trans_mp);
1373 }
1374
1375 return (error);
1376 }
1377
1378 /*
1379 * Default putrange method for file systems that do not care
1380 * how many pages are given to one GOP_WRITE() call.
1381 */
1382 void
1383 genfs_gop_putrange(struct vnode *vp, off_t off, off_t *lop, off_t *hip)
1384 {
1385
1386 *lop = 0;
1387 *hip = 0;
1388 }
1389
1390 int
1391 genfs_gop_write(struct vnode *vp, struct vm_page **pgs, int npages, int flags)
1392 {
1393 off_t off;
1394 vaddr_t kva;
1395 size_t len;
1396 int error;
1397 UVMHIST_FUNC(__func__); UVMHIST_CALLED(ubchist);
1398
1399 UVMHIST_LOG(ubchist, "vp %#jx pgs %#jx npages %jd flags 0x%jx",
1400 (uintptr_t)vp, (uintptr_t)pgs, npages, flags);
1401
1402 off = pgs[0]->offset;
1403 kva = uvm_pagermapin(pgs, npages,
1404 UVMPAGER_MAPIN_WRITE | UVMPAGER_MAPIN_WAITOK);
1405 len = npages << PAGE_SHIFT;
1406
1407 error = genfs_do_io(vp, off, kva, len, flags, UIO_WRITE,
1408 uvm_aio_aiodone);
1409
1410 return error;
1411 }
1412
1413 /*
1414 * genfs_gop_write_rwmap:
1415 *
1416 * a variant of genfs_gop_write. it's used by UDF for its directory buffers.
1417 * this maps pages with PROT_WRITE so that VOP_STRATEGY can modifies
1418 * the contents before writing it out to the underlying storage.
1419 */
1420
1421 int
1422 genfs_gop_write_rwmap(struct vnode *vp, struct vm_page **pgs, int npages,
1423 int flags)
1424 {
1425 off_t off;
1426 vaddr_t kva;
1427 size_t len;
1428 int error;
1429 UVMHIST_FUNC(__func__); UVMHIST_CALLED(ubchist);
1430
1431 UVMHIST_LOG(ubchist, "vp %#jx pgs %#jx npages %jd flags 0x%jx",
1432 (uintptr_t)vp, (uintptr_t)pgs, npages, flags);
1433
1434 off = pgs[0]->offset;
1435 kva = uvm_pagermapin(pgs, npages,
1436 UVMPAGER_MAPIN_READ | UVMPAGER_MAPIN_WAITOK);
1437 len = npages << PAGE_SHIFT;
1438
1439 error = genfs_do_io(vp, off, kva, len, flags, UIO_WRITE,
1440 uvm_aio_aiodone);
1441
1442 return error;
1443 }
1444
1445 /*
1446 * Backend routine for doing I/O to vnode pages. Pages are already locked
1447 * and mapped into kernel memory. Here we just look up the underlying
1448 * device block addresses and call the strategy routine.
1449 */
1450
1451 static int
1452 genfs_do_io(struct vnode *vp, off_t off, vaddr_t kva, size_t len, int flags,
1453 enum uio_rw rw, void (*iodone)(struct buf *))
1454 {
1455 int s, error;
1456 int fs_bshift, dev_bshift;
1457 off_t eof, offset, startoffset;
1458 size_t bytes, iobytes, skipbytes;
1459 struct buf *mbp, *bp;
1460 const bool async = (flags & PGO_SYNCIO) == 0;
1461 const bool lazy = (flags & PGO_LAZY) == 0;
1462 const bool iowrite = rw == UIO_WRITE;
1463 const int brw = iowrite ? B_WRITE : B_READ;
1464 UVMHIST_FUNC(__func__); UVMHIST_CALLED(ubchist);
1465
1466 UVMHIST_LOG(ubchist, "vp %#jx kva %#jx len 0x%jx flags 0x%jx",
1467 (uintptr_t)vp, (uintptr_t)kva, len, flags);
1468
1469 KASSERT(vp->v_size <= vp->v_writesize);
1470 GOP_SIZE(vp, vp->v_writesize, &eof, 0);
1471 if (vp->v_type != VBLK) {
1472 fs_bshift = vp->v_mount->mnt_fs_bshift;
1473 dev_bshift = vp->v_mount->mnt_dev_bshift;
1474 } else {
1475 fs_bshift = DEV_BSHIFT;
1476 dev_bshift = DEV_BSHIFT;
1477 }
1478 error = 0;
1479 startoffset = off;
1480 bytes = MIN(len, eof - startoffset);
1481 skipbytes = 0;
1482 KASSERT(bytes != 0);
1483
1484 if (iowrite) {
1485 /*
1486 * why += 2?
1487 * 1 for biodone, 1 for uvm_aio_aiodone.
1488 */
1489 mutex_enter(vp->v_interlock);
1490 vp->v_numoutput += 2;
1491 mutex_exit(vp->v_interlock);
1492 }
1493 mbp = getiobuf(vp, true);
1494 UVMHIST_LOG(ubchist, "vp %#jx mbp %#jx num now %jd bytes 0x%jx",
1495 (uintptr_t)vp, (uintptr_t)mbp, vp->v_numoutput, bytes);
1496 mbp->b_bufsize = len;
1497 mbp->b_data = (void *)kva;
1498 mbp->b_resid = mbp->b_bcount = bytes;
1499 mbp->b_cflags |= BC_BUSY | BC_AGE;
1500 if (async) {
1501 mbp->b_flags = brw | B_ASYNC;
1502 mbp->b_iodone = iodone;
1503 } else {
1504 mbp->b_flags = brw;
1505 mbp->b_iodone = NULL;
1506 }
1507 if (curlwp == uvm.pagedaemon_lwp)
1508 BIO_SETPRIO(mbp, BPRIO_TIMELIMITED);
1509 else if (async || lazy)
1510 BIO_SETPRIO(mbp, BPRIO_TIMENONCRITICAL);
1511 else
1512 BIO_SETPRIO(mbp, BPRIO_TIMECRITICAL);
1513
1514 bp = NULL;
1515 for (offset = startoffset;
1516 bytes > 0;
1517 offset += iobytes, bytes -= iobytes) {
1518 int run;
1519 daddr_t lbn, blkno;
1520 struct vnode *devvp;
1521
1522 /*
1523 * bmap the file to find out the blkno to read from and
1524 * how much we can read in one i/o. if bmap returns an error,
1525 * skip the rest of the top-level i/o.
1526 */
1527
1528 lbn = offset >> fs_bshift;
1529 error = VOP_BMAP(vp, lbn, &devvp, &blkno, &run);
1530 if (error) {
1531 UVMHIST_LOG(ubchist, "VOP_BMAP lbn 0x%jx -> %jd\n",
1532 lbn, error, 0, 0);
1533 skipbytes += bytes;
1534 bytes = 0;
1535 goto loopdone;
1536 }
1537
1538 /*
1539 * see how many pages can be read with this i/o.
1540 * reduce the i/o size if necessary to avoid
1541 * overwriting pages with valid data.
1542 */
1543
1544 iobytes = MIN((((off_t)lbn + 1 + run) << fs_bshift) - offset,
1545 bytes);
1546
1547 /*
1548 * if this block isn't allocated, zero it instead of
1549 * reading it. unless we are going to allocate blocks,
1550 * mark the pages we zeroed PG_RDONLY.
1551 */
1552
1553 if (blkno == (daddr_t)-1) {
1554 if (!iowrite) {
1555 memset((char *)kva + (offset - startoffset), 0,
1556 iobytes);
1557 }
1558 skipbytes += iobytes;
1559 continue;
1560 }
1561
1562 /*
1563 * allocate a sub-buf for this piece of the i/o
1564 * (or just use mbp if there's only 1 piece),
1565 * and start it going.
1566 */
1567
1568 if (offset == startoffset && iobytes == bytes) {
1569 bp = mbp;
1570 } else {
1571 UVMHIST_LOG(ubchist, "vp %#jx bp %#jx num now %jd",
1572 (uintptr_t)vp, (uintptr_t)bp, vp->v_numoutput, 0);
1573 bp = getiobuf(vp, true);
1574 nestiobuf_setup(mbp, bp, offset - startoffset, iobytes);
1575 }
1576 bp->b_lblkno = 0;
1577
1578 /* adjust physical blkno for partial blocks */
1579 bp->b_blkno = blkno + ((offset - ((off_t)lbn << fs_bshift)) >>
1580 dev_bshift);
1581
1582 UVMHIST_LOG(ubchist,
1583 "bp %#jx offset 0x%jx bcount 0x%jx blkno 0x%jx",
1584 (uintptr_t)bp, offset, bp->b_bcount, bp->b_blkno);
1585
1586 VOP_STRATEGY(devvp, bp);
1587 }
1588
1589 loopdone:
1590 if (skipbytes) {
1591 UVMHIST_LOG(ubchist, "skipbytes %jd", skipbytes, 0,0,0);
1592 }
1593 nestiobuf_done(mbp, skipbytes, error);
1594 if (async) {
1595 UVMHIST_LOG(ubchist, "returning 0 (async)", 0,0,0,0);
1596 return (0);
1597 }
1598 UVMHIST_LOG(ubchist, "waiting for mbp %#jx", (uintptr_t)mbp, 0, 0, 0);
1599 error = biowait(mbp);
1600 s = splbio();
1601 (*iodone)(mbp);
1602 splx(s);
1603 UVMHIST_LOG(ubchist, "returning, error %jd", error, 0, 0, 0);
1604 return (error);
1605 }
1606
1607 int
1608 genfs_compat_getpages(void *v)
1609 {
1610 struct vop_getpages_args /* {
1611 struct vnode *a_vp;
1612 voff_t a_offset;
1613 struct vm_page **a_m;
1614 int *a_count;
1615 int a_centeridx;
1616 vm_prot_t a_access_type;
1617 int a_advice;
1618 int a_flags;
1619 } */ *ap = v;
1620
1621 off_t origoffset;
1622 struct vnode *vp = ap->a_vp;
1623 struct uvm_object *uobj = &vp->v_uobj;
1624 struct vm_page *pg, **pgs;
1625 vaddr_t kva;
1626 int i, error, orignpages, npages;
1627 struct iovec iov;
1628 struct uio uio;
1629 kauth_cred_t cred = curlwp->l_cred;
1630 const bool memwrite = (ap->a_access_type & VM_PROT_WRITE) != 0;
1631
1632 error = 0;
1633 origoffset = ap->a_offset;
1634 orignpages = *ap->a_count;
1635 pgs = ap->a_m;
1636
1637 if (ap->a_flags & PGO_LOCKED) {
1638 uvn_findpages(uobj, origoffset, ap->a_count, ap->a_m, NULL,
1639 UFP_NOWAIT|UFP_NOALLOC| (memwrite ? UFP_NORDONLY : 0));
1640
1641 error = ap->a_m[ap->a_centeridx] == NULL ? EBUSY : 0;
1642 if (error == 0 && memwrite) {
1643 genfs_markdirty(vp);
1644 }
1645 return error;
1646 }
1647 if (origoffset + (ap->a_centeridx << PAGE_SHIFT) >= vp->v_size) {
1648 rw_exit(uobj->vmobjlock);
1649 return EINVAL;
1650 }
1651 if ((ap->a_flags & PGO_SYNCIO) == 0) {
1652 rw_exit(uobj->vmobjlock);
1653 return 0;
1654 }
1655 npages = orignpages;
1656 uvn_findpages(uobj, origoffset, &npages, pgs, NULL, UFP_ALL);
1657 rw_exit(uobj->vmobjlock);
1658 kva = uvm_pagermapin(pgs, npages,
1659 UVMPAGER_MAPIN_READ | UVMPAGER_MAPIN_WAITOK);
1660 for (i = 0; i < npages; i++) {
1661 pg = pgs[i];
1662 if ((pg->flags & PG_FAKE) == 0) {
1663 continue;
1664 }
1665 iov.iov_base = (char *)kva + (i << PAGE_SHIFT);
1666 iov.iov_len = PAGE_SIZE;
1667 uio.uio_iov = &iov;
1668 uio.uio_iovcnt = 1;
1669 uio.uio_offset = origoffset + (i << PAGE_SHIFT);
1670 uio.uio_rw = UIO_READ;
1671 uio.uio_resid = PAGE_SIZE;
1672 UIO_SETUP_SYSSPACE(&uio);
1673 /* XXX vn_lock */
1674 error = VOP_READ(vp, &uio, 0, cred);
1675 if (error) {
1676 break;
1677 }
1678 if (uio.uio_resid) {
1679 memset(iov.iov_base, 0, uio.uio_resid);
1680 }
1681 }
1682 uvm_pagermapout(kva, npages);
1683 rw_enter(uobj->vmobjlock, RW_WRITER);
1684 for (i = 0; i < npages; i++) {
1685 pg = pgs[i];
1686 if (error && (pg->flags & PG_FAKE) != 0) {
1687 pg->flags |= PG_RELEASED;
1688 } else {
1689 uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_UNKNOWN);
1690 uvm_pagelock(pg);
1691 uvm_pageactivate(pg);
1692 uvm_pageunlock(pg);
1693 }
1694 }
1695 if (error) {
1696 uvm_page_unbusy(pgs, npages);
1697 }
1698 if (error == 0 && memwrite) {
1699 genfs_markdirty(vp);
1700 }
1701 rw_exit(uobj->vmobjlock);
1702 return error;
1703 }
1704
1705 int
1706 genfs_compat_gop_write(struct vnode *vp, struct vm_page **pgs, int npages,
1707 int flags)
1708 {
1709 off_t offset;
1710 struct iovec iov;
1711 struct uio uio;
1712 kauth_cred_t cred = curlwp->l_cred;
1713 struct buf *bp;
1714 vaddr_t kva;
1715 int error;
1716
1717 offset = pgs[0]->offset;
1718 kva = uvm_pagermapin(pgs, npages,
1719 UVMPAGER_MAPIN_WRITE | UVMPAGER_MAPIN_WAITOK);
1720
1721 iov.iov_base = (void *)kva;
1722 iov.iov_len = npages << PAGE_SHIFT;
1723 uio.uio_iov = &iov;
1724 uio.uio_iovcnt = 1;
1725 uio.uio_offset = offset;
1726 uio.uio_rw = UIO_WRITE;
1727 uio.uio_resid = npages << PAGE_SHIFT;
1728 UIO_SETUP_SYSSPACE(&uio);
1729 /* XXX vn_lock */
1730 error = VOP_WRITE(vp, &uio, 0, cred);
1731
1732 mutex_enter(vp->v_interlock);
1733 vp->v_numoutput++;
1734 mutex_exit(vp->v_interlock);
1735
1736 bp = getiobuf(vp, true);
1737 bp->b_cflags |= BC_BUSY | BC_AGE;
1738 bp->b_lblkno = offset >> vp->v_mount->mnt_fs_bshift;
1739 bp->b_data = (char *)kva;
1740 bp->b_bcount = npages << PAGE_SHIFT;
1741 bp->b_bufsize = npages << PAGE_SHIFT;
1742 bp->b_resid = 0;
1743 bp->b_error = error;
1744 uvm_aio_aiodone(bp);
1745 return (error);
1746 }
1747
1748 /*
1749 * Process a uio using direct I/O. If we reach a part of the request
1750 * which cannot be processed in this fashion for some reason, just return.
1751 * The caller must handle some additional part of the request using
1752 * buffered I/O before trying direct I/O again.
1753 */
1754
1755 void
1756 genfs_directio(struct vnode *vp, struct uio *uio, int ioflag)
1757 {
1758 struct vmspace *vs;
1759 struct iovec *iov;
1760 vaddr_t va;
1761 size_t len;
1762 const int mask = DEV_BSIZE - 1;
1763 int error;
1764 bool need_wapbl = (vp->v_mount && vp->v_mount->mnt_wapbl &&
1765 (ioflag & IO_JOURNALLOCKED) == 0);
1766
1767 #ifdef DIAGNOSTIC
1768 if ((ioflag & IO_JOURNALLOCKED) && vp->v_mount->mnt_wapbl)
1769 WAPBL_JLOCK_ASSERT(vp->v_mount);
1770 #endif
1771
1772 /*
1773 * We only support direct I/O to user space for now.
1774 */
1775
1776 if (VMSPACE_IS_KERNEL_P(uio->uio_vmspace)) {
1777 return;
1778 }
1779
1780 /*
1781 * If the vnode is mapped, we would need to get the getpages lock
1782 * to stabilize the bmap, but then we would get into trouble while
1783 * locking the pages if the pages belong to this same vnode (or a
1784 * multi-vnode cascade to the same effect). Just fall back to
1785 * buffered I/O if the vnode is mapped to avoid this mess.
1786 */
1787
1788 if (vp->v_vflag & VV_MAPPED) {
1789 return;
1790 }
1791
1792 if (need_wapbl) {
1793 error = WAPBL_BEGIN(vp->v_mount);
1794 if (error)
1795 return;
1796 }
1797
1798 /*
1799 * Do as much of the uio as possible with direct I/O.
1800 */
1801
1802 vs = uio->uio_vmspace;
1803 while (uio->uio_resid) {
1804 iov = uio->uio_iov;
1805 if (iov->iov_len == 0) {
1806 uio->uio_iov++;
1807 uio->uio_iovcnt--;
1808 continue;
1809 }
1810 va = (vaddr_t)iov->iov_base;
1811 len = MIN(iov->iov_len, genfs_maxdio);
1812 len &= ~mask;
1813
1814 /*
1815 * If the next chunk is smaller than DEV_BSIZE or extends past
1816 * the current EOF, then fall back to buffered I/O.
1817 */
1818
1819 if (len == 0 || uio->uio_offset + len > vp->v_size) {
1820 break;
1821 }
1822
1823 /*
1824 * Check alignment. The file offset must be at least
1825 * sector-aligned. The exact constraint on memory alignment
1826 * is very hardware-dependent, but requiring sector-aligned
1827 * addresses there too is safe.
1828 */
1829
1830 if (uio->uio_offset & mask || va & mask) {
1831 break;
1832 }
1833 error = genfs_do_directio(vs, va, len, vp, uio->uio_offset,
1834 uio->uio_rw);
1835 if (error) {
1836 break;
1837 }
1838 iov->iov_base = (char *)iov->iov_base + len;
1839 iov->iov_len -= len;
1840 uio->uio_offset += len;
1841 uio->uio_resid -= len;
1842 }
1843
1844 if (need_wapbl)
1845 WAPBL_END(vp->v_mount);
1846 }
1847
1848 /*
1849 * Iodone routine for direct I/O. We don't do much here since the request is
1850 * always synchronous, so the caller will do most of the work after biowait().
1851 */
1852
1853 static void
1854 genfs_dio_iodone(struct buf *bp)
1855 {
1856
1857 KASSERT((bp->b_flags & B_ASYNC) == 0);
1858 if ((bp->b_flags & B_READ) == 0 && (bp->b_cflags & BC_AGE) != 0) {
1859 mutex_enter(bp->b_objlock);
1860 vwakeup(bp);
1861 mutex_exit(bp->b_objlock);
1862 }
1863 putiobuf(bp);
1864 }
1865
1866 /*
1867 * Process one chunk of a direct I/O request.
1868 */
1869
1870 static int
1871 genfs_do_directio(struct vmspace *vs, vaddr_t uva, size_t len, struct vnode *vp,
1872 off_t off, enum uio_rw rw)
1873 {
1874 struct vm_map *map;
1875 struct pmap *upm, *kpm __unused;
1876 size_t klen = round_page(uva + len) - trunc_page(uva);
1877 off_t spoff, epoff;
1878 vaddr_t kva, puva;
1879 paddr_t pa;
1880 vm_prot_t prot;
1881 int error, rv __diagused, poff, koff;
1882 const int pgoflags = PGO_CLEANIT | PGO_SYNCIO | PGO_JOURNALLOCKED |
1883 (rw == UIO_WRITE ? PGO_FREE : 0);
1884
1885 /*
1886 * For writes, verify that this range of the file already has fully
1887 * allocated backing store. If there are any holes, just punt and
1888 * make the caller take the buffered write path.
1889 */
1890
1891 if (rw == UIO_WRITE) {
1892 daddr_t lbn, elbn, blkno;
1893 int bsize, bshift, run;
1894
1895 bshift = vp->v_mount->mnt_fs_bshift;
1896 bsize = 1 << bshift;
1897 lbn = off >> bshift;
1898 elbn = (off + len + bsize - 1) >> bshift;
1899 while (lbn < elbn) {
1900 error = VOP_BMAP(vp, lbn, NULL, &blkno, &run);
1901 if (error) {
1902 return error;
1903 }
1904 if (blkno == (daddr_t)-1) {
1905 return ENOSPC;
1906 }
1907 lbn += 1 + run;
1908 }
1909 }
1910
1911 /*
1912 * Flush any cached pages for parts of the file that we're about to
1913 * access. If we're writing, invalidate pages as well.
1914 */
1915
1916 spoff = trunc_page(off);
1917 epoff = round_page(off + len);
1918 rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
1919 error = VOP_PUTPAGES(vp, spoff, epoff, pgoflags);
1920 if (error) {
1921 return error;
1922 }
1923
1924 /*
1925 * Wire the user pages and remap them into kernel memory.
1926 */
1927
1928 prot = rw == UIO_READ ? VM_PROT_READ | VM_PROT_WRITE : VM_PROT_READ;
1929 error = uvm_vslock(vs, (void *)uva, len, prot);
1930 if (error) {
1931 return error;
1932 }
1933
1934 map = &vs->vm_map;
1935 upm = vm_map_pmap(map);
1936 kpm = vm_map_pmap(kernel_map);
1937 puva = trunc_page(uva);
1938 kva = uvm_km_alloc(kernel_map, klen, atop(puva) & uvmexp.colormask,
1939 UVM_KMF_VAONLY | UVM_KMF_WAITVA | UVM_KMF_COLORMATCH);
1940 for (poff = 0; poff < klen; poff += PAGE_SIZE) {
1941 rv = pmap_extract(upm, puva + poff, &pa);
1942 KASSERT(rv);
1943 pmap_kenter_pa(kva + poff, pa, prot, PMAP_WIRED);
1944 }
1945 pmap_update(kpm);
1946
1947 /*
1948 * Do the I/O.
1949 */
1950
1951 koff = uva - trunc_page(uva);
1952 error = genfs_do_io(vp, off, kva + koff, len, PGO_SYNCIO, rw,
1953 genfs_dio_iodone);
1954
1955 /*
1956 * Tear down the kernel mapping.
1957 */
1958
1959 pmap_kremove(kva, klen);
1960 pmap_update(kpm);
1961 uvm_km_free(kernel_map, kva, klen, UVM_KMF_VAONLY);
1962
1963 /*
1964 * Unwire the user pages.
1965 */
1966
1967 uvm_vsunlock(vs, (void *)uva, len);
1968 return error;
1969 }
1970