genfs_io.c revision 1.91 1 /* $NetBSD: genfs_io.c,v 1.91 2020/03/14 19:07:22 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.91 2020/03/14 19:07:22 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 mount *trans_mp;
888 int flags;
889 bool modified; /* if we write out any pages */
890 bool holds_wapbl;
891 bool cleanall; /* try to pull off from the syncer's list */
892 bool onworklst;
893 bool nodirty;
894 const bool dirtyonly = (origflags & (PGO_DEACTIVATE|PGO_FREE)) == 0;
895
896 UVMHIST_FUNC("genfs_putpages"); UVMHIST_CALLED(ubchist);
897
898 KASSERT(origflags & (PGO_CLEANIT|PGO_FREE|PGO_DEACTIVATE));
899 KASSERT((startoff & PAGE_MASK) == 0 && (endoff & PAGE_MASK) == 0);
900 KASSERT(startoff < endoff || endoff == 0);
901 KASSERT(rw_write_held(slock));
902
903 UVMHIST_LOG(ubchist, "vp %#jx pages %jd off 0x%jx len 0x%jx",
904 (uintptr_t)vp, uobj->uo_npages, startoff, endoff - startoff);
905
906 #ifdef DIAGNOSTIC
907 if ((origflags & PGO_JOURNALLOCKED) && vp->v_mount->mnt_wapbl)
908 WAPBL_JLOCK_ASSERT(vp->v_mount);
909 #endif
910
911 trans_mp = NULL;
912 holds_wapbl = false;
913
914 retry:
915 modified = false;
916 flags = origflags;
917 KASSERT((vp->v_iflag & VI_ONWORKLST) != 0 ||
918 (vp->v_iflag & VI_WRMAPDIRTY) == 0);
919
920 /*
921 * shortcut if we have no pages to process.
922 */
923
924 nodirty = radix_tree_empty_tagged_tree_p(&uobj->uo_pages,
925 UVM_PAGE_DIRTY_TAG);
926 if (uobj->uo_npages == 0 || (dirtyonly && nodirty)) {
927 mutex_enter(vp->v_interlock);
928 if (vp->v_iflag & VI_ONWORKLST) {
929 vp->v_iflag &= ~VI_WRMAPDIRTY;
930 if (LIST_FIRST(&vp->v_dirtyblkhd) == NULL)
931 vn_syncer_remove_from_worklist(vp);
932 }
933 mutex_exit(vp->v_interlock);
934 if (trans_mp) {
935 if (holds_wapbl)
936 WAPBL_END(trans_mp);
937 fstrans_done(trans_mp);
938 }
939 rw_exit(slock);
940 return (0);
941 }
942
943 /*
944 * the vnode has pages, set up to process the request.
945 */
946
947 if (trans_mp == NULL && (flags & PGO_CLEANIT) != 0) {
948 if (pagedaemon) {
949 /* Pagedaemon must not sleep here. */
950 trans_mp = vp->v_mount;
951 error = fstrans_start_nowait(trans_mp);
952 if (error) {
953 rw_exit(slock);
954 return error;
955 }
956 } else {
957 /*
958 * Cannot use vdeadcheck() here as this operation
959 * usually gets used from VOP_RECLAIM(). Test for
960 * change of v_mount instead and retry on change.
961 */
962 rw_exit(slock);
963 trans_mp = vp->v_mount;
964 fstrans_start(trans_mp);
965 if (vp->v_mount != trans_mp) {
966 fstrans_done(trans_mp);
967 trans_mp = NULL;
968 } else {
969 holds_wapbl = (trans_mp->mnt_wapbl &&
970 (origflags & PGO_JOURNALLOCKED) == 0);
971 if (holds_wapbl) {
972 error = WAPBL_BEGIN(trans_mp);
973 if (error) {
974 fstrans_done(trans_mp);
975 return error;
976 }
977 }
978 }
979 rw_enter(slock, RW_WRITER);
980 goto retry;
981 }
982 }
983
984 error = 0;
985 wasclean = radix_tree_empty_tagged_tree_p(&uobj->uo_pages,
986 UVM_PAGE_WRITEBACK_TAG);
987 nextoff = startoff;
988 if (endoff == 0 || flags & PGO_ALLPAGES) {
989 endoff = trunc_page(LLONG_MAX);
990 }
991
992 /*
993 * if this vnode is known not to have dirty pages,
994 * don't bother to clean it out.
995 */
996
997 if (nodirty) {
998 #if !defined(DEBUG)
999 if (dirtyonly) {
1000 goto skip_scan;
1001 }
1002 #endif /* !defined(DEBUG) */
1003 flags &= ~PGO_CLEANIT;
1004 }
1005
1006 /*
1007 * start the loop to scan pages.
1008 */
1009
1010 cleanall = true;
1011 freeflag = pagedaemon ? PG_PAGEOUT : PG_RELEASED;
1012 uvm_page_array_init(&a);
1013 for (;;) {
1014 bool pgprotected;
1015
1016 /*
1017 * if !dirtyonly, iterate over all resident pages in the range.
1018 *
1019 * if dirtyonly, only possibly dirty pages are interesting.
1020 * however, if we are asked to sync for integrity, we should
1021 * wait on pages being written back by other threads as well.
1022 */
1023
1024 pg = uvm_page_array_fill_and_peek(&a, uobj, nextoff, 0,
1025 dirtyonly ? (UVM_PAGE_ARRAY_FILL_DIRTY |
1026 (!async ? UVM_PAGE_ARRAY_FILL_WRITEBACK : 0)) : 0);
1027 if (pg == NULL) {
1028 break;
1029 }
1030
1031 KASSERT(pg->uobject == uobj);
1032 KASSERT((pg->flags & (PG_RELEASED|PG_PAGEOUT)) == 0 ||
1033 (pg->flags & (PG_BUSY)) != 0);
1034 KASSERT(pg->offset >= startoff);
1035 KASSERT(pg->offset >= nextoff);
1036 KASSERT(!dirtyonly ||
1037 uvm_pagegetdirty(pg) != UVM_PAGE_STATUS_CLEAN ||
1038 radix_tree_get_tag(&uobj->uo_pages,
1039 pg->offset >> PAGE_SHIFT, UVM_PAGE_WRITEBACK_TAG));
1040
1041 if (pg->offset >= endoff) {
1042 break;
1043 }
1044
1045 /*
1046 * a preempt point.
1047 */
1048
1049 if (preempt_needed()) {
1050 nextoff = pg->offset; /* visit this page again */
1051 rw_exit(slock);
1052 preempt();
1053 /*
1054 * as we dropped the object lock, our cached pages can
1055 * be stale.
1056 */
1057 uvm_page_array_clear(&a);
1058 rw_enter(slock, RW_WRITER);
1059 continue;
1060 }
1061
1062 /*
1063 * if the current page is busy, wait for it to become unbusy.
1064 */
1065
1066 if ((pg->flags & PG_BUSY) != 0) {
1067 UVMHIST_LOG(ubchist, "busy %#jx", (uintptr_t)pg,
1068 0, 0, 0);
1069 if ((pg->flags & (PG_RELEASED|PG_PAGEOUT)) != 0
1070 && (flags & PGO_BUSYFAIL) != 0) {
1071 UVMHIST_LOG(ubchist, "busyfail %#jx",
1072 (uintptr_t)pg, 0, 0, 0);
1073 error = EDEADLK;
1074 if (busypg != NULL)
1075 *busypg = pg;
1076 break;
1077 }
1078 if (pagedaemon) {
1079 /*
1080 * someone has taken the page while we
1081 * dropped the lock for fstrans_start.
1082 */
1083 break;
1084 }
1085 /*
1086 * don't bother to wait on other's activities
1087 * unless we are asked to sync for integrity.
1088 */
1089 if (!async && (flags & PGO_RECLAIM) == 0) {
1090 wasclean = false;
1091 nextoff = pg->offset + PAGE_SIZE;
1092 uvm_page_array_advance(&a);
1093 continue;
1094 }
1095 nextoff = pg->offset; /* visit this page again */
1096 pg->flags |= PG_WANTED;
1097 UVM_UNLOCK_AND_WAIT_RW(pg, slock, 0, "genput", 0);
1098 /*
1099 * as we dropped the object lock, our cached pages can
1100 * be stale.
1101 */
1102 uvm_page_array_clear(&a);
1103 rw_enter(slock, RW_WRITER);
1104 continue;
1105 }
1106
1107 nextoff = pg->offset + PAGE_SIZE;
1108 uvm_page_array_advance(&a);
1109
1110 /*
1111 * if we're freeing, remove all mappings of the page now.
1112 * if we're cleaning, check if the page is needs to be cleaned.
1113 */
1114
1115 pgprotected = false;
1116 if (flags & PGO_FREE) {
1117 pmap_page_protect(pg, VM_PROT_NONE);
1118 pgprotected = true;
1119 } else if (flags & PGO_CLEANIT) {
1120
1121 /*
1122 * if we still have some hope to pull this vnode off
1123 * from the syncer queue, write-protect the page.
1124 */
1125
1126 if (cleanall && wasclean) {
1127
1128 /*
1129 * uobj pages get wired only by uvm_fault
1130 * where uobj is locked.
1131 */
1132
1133 if (pg->wire_count == 0) {
1134 pmap_page_protect(pg,
1135 VM_PROT_READ|VM_PROT_EXECUTE);
1136 pgprotected = true;
1137 } else {
1138 cleanall = false;
1139 }
1140 }
1141 }
1142
1143 if (flags & PGO_CLEANIT) {
1144 needs_clean = uvm_pagecheckdirty(pg, pgprotected);
1145 } else {
1146 needs_clean = false;
1147 }
1148
1149 /*
1150 * if we're cleaning, build a cluster.
1151 * the cluster will consist of pages which are currently dirty.
1152 * if not cleaning, just operate on the one page.
1153 */
1154
1155 if (needs_clean) {
1156 KDASSERT((vp->v_iflag & VI_ONWORKLST));
1157 wasclean = false;
1158 memset(pgs, 0, sizeof(pgs));
1159 pg->flags |= PG_BUSY;
1160 UVM_PAGE_OWN(pg, "genfs_putpages");
1161
1162 /*
1163 * let the fs constrain the offset range of the cluster.
1164 * we additionally constrain the range here such that
1165 * it fits in the "pgs" pages array.
1166 */
1167
1168 off_t fslo, fshi, genlo, lo, off = pg->offset;
1169 GOP_PUTRANGE(vp, off, &fslo, &fshi);
1170 KASSERT(fslo == trunc_page(fslo));
1171 KASSERT(fslo <= off);
1172 KASSERT(fshi == trunc_page(fshi));
1173 KASSERT(fshi == 0 || off < fshi);
1174
1175 if (off > MAXPHYS / 2)
1176 genlo = trunc_page(off - (MAXPHYS / 2));
1177 else
1178 genlo = 0;
1179 lo = MAX(fslo, genlo);
1180
1181 /*
1182 * first look backward.
1183 */
1184
1185 npages = (off - lo) >> PAGE_SHIFT;
1186 nback = npages;
1187 uvn_findpages(uobj, off - PAGE_SIZE, &nback,
1188 &pgs[0], NULL,
1189 UFP_NOWAIT|UFP_NOALLOC|UFP_DIRTYONLY|UFP_BACKWARD);
1190 if (nback) {
1191 memmove(&pgs[0], &pgs[npages - nback],
1192 nback * sizeof(pgs[0]));
1193 if (npages - nback < nback)
1194 memset(&pgs[nback], 0,
1195 (npages - nback) * sizeof(pgs[0]));
1196 else
1197 memset(&pgs[npages - nback], 0,
1198 nback * sizeof(pgs[0]));
1199 }
1200
1201 /*
1202 * then plug in our page of interest.
1203 */
1204
1205 pgs[nback] = pg;
1206
1207 /*
1208 * then look forward to fill in the remaining space in
1209 * the array of pages.
1210 *
1211 * pass our cached array of pages so that hopefully
1212 * uvn_findpages can find some good pages in it.
1213 * the array a was filled above with the one of
1214 * following sets of flags:
1215 * 0
1216 * UVM_PAGE_ARRAY_FILL_DIRTY
1217 * UVM_PAGE_ARRAY_FILL_DIRTY|WRITEBACK
1218 */
1219
1220 npages = MAXPAGES - nback - 1;
1221 if (fshi)
1222 npages = MIN(npages,
1223 (fshi - off - 1) >> PAGE_SHIFT);
1224 uvn_findpages(uobj, off + PAGE_SIZE, &npages,
1225 &pgs[nback + 1], NULL,
1226 UFP_NOWAIT|UFP_NOALLOC|UFP_DIRTYONLY);
1227 npages += nback + 1;
1228 } else {
1229 pgs[0] = pg;
1230 npages = 1;
1231 nback = 0;
1232 }
1233
1234 /*
1235 * apply FREE or DEACTIVATE options if requested.
1236 */
1237
1238 for (i = 0; i < npages; i++) {
1239 tpg = pgs[i];
1240 KASSERT(tpg->uobject == uobj);
1241 KASSERT(i == 0 ||
1242 pgs[i-1]->offset + PAGE_SIZE == tpg->offset);
1243 KASSERT(!needs_clean || uvm_pagegetdirty(pgs[i]) !=
1244 UVM_PAGE_STATUS_DIRTY);
1245 if (needs_clean) {
1246 /*
1247 * mark pages as WRITEBACK so that concurrent
1248 * fsync can find and wait for our activities.
1249 */
1250 radix_tree_set_tag(&uobj->uo_pages,
1251 pgs[i]->offset >> PAGE_SHIFT,
1252 UVM_PAGE_WRITEBACK_TAG);
1253 }
1254 if (tpg->offset < startoff || tpg->offset >= endoff)
1255 continue;
1256 if (flags & PGO_DEACTIVATE && tpg->wire_count == 0) {
1257 uvm_pagelock(tpg);
1258 uvm_pagedeactivate(tpg);
1259 uvm_pageunlock(tpg);
1260 } else if (flags & PGO_FREE) {
1261 pmap_page_protect(tpg, VM_PROT_NONE);
1262 if (tpg->flags & PG_BUSY) {
1263 tpg->flags |= freeflag;
1264 if (pagedaemon) {
1265 uvm_pageout_start(1);
1266 uvm_pagelock(tpg);
1267 uvm_pagedequeue(tpg);
1268 uvm_pageunlock(tpg);
1269 }
1270 } else {
1271
1272 /*
1273 * ``page is not busy''
1274 * implies that npages is 1
1275 * and needs_clean is false.
1276 */
1277
1278 KASSERT(npages == 1);
1279 KASSERT(!needs_clean);
1280 KASSERT(pg == tpg);
1281 KASSERT(nextoff ==
1282 tpg->offset + PAGE_SIZE);
1283 uvm_pagefree(tpg);
1284 if (pagedaemon)
1285 uvmexp.pdfreed++;
1286 }
1287 }
1288 }
1289 if (needs_clean) {
1290 modified = true;
1291 KASSERT(nextoff == pg->offset + PAGE_SIZE);
1292 KASSERT(nback < npages);
1293 nextoff = pg->offset + ((npages - nback) << PAGE_SHIFT);
1294 KASSERT(pgs[nback] == pg);
1295 KASSERT(nextoff == pgs[npages - 1]->offset + PAGE_SIZE);
1296
1297 /*
1298 * start the i/o.
1299 */
1300 rw_exit(slock);
1301 error = GOP_WRITE(vp, pgs, npages, flags);
1302 /*
1303 * as we dropped the object lock, our cached pages can
1304 * be stale.
1305 */
1306 uvm_page_array_clear(&a);
1307 rw_enter(slock, RW_WRITER);
1308 if (error) {
1309 break;
1310 }
1311 }
1312 }
1313 uvm_page_array_fini(&a);
1314
1315 /*
1316 * update ctime/mtime if the modification we started writing out might
1317 * be from mmap'ed write.
1318 *
1319 * this is necessary when an application keeps a file mmaped and
1320 * repeatedly modifies it via the window. note that, because we
1321 * don't always write-protect pages when cleaning, such modifications
1322 * might not involve any page faults.
1323 */
1324
1325 mutex_enter(vp->v_interlock);
1326 if (modified && (vp->v_iflag & VI_WRMAPDIRTY) != 0 &&
1327 (vp->v_type != VBLK ||
1328 (vp->v_mount->mnt_flag & MNT_NODEVMTIME) == 0)) {
1329 GOP_MARKUPDATE(vp, GOP_UPDATE_MODIFIED);
1330 }
1331
1332 /*
1333 * if we no longer have any possibly dirty pages, take us off the
1334 * syncer list.
1335 */
1336
1337 if ((vp->v_iflag & VI_ONWORKLST) != 0 &&
1338 radix_tree_empty_tagged_tree_p(&uobj->uo_pages,
1339 UVM_PAGE_DIRTY_TAG)) {
1340 vp->v_iflag &= ~VI_WRMAPDIRTY;
1341 if (LIST_FIRST(&vp->v_dirtyblkhd) == NULL)
1342 vn_syncer_remove_from_worklist(vp);
1343 }
1344
1345 #if !defined(DEBUG)
1346 skip_scan:
1347 #endif /* !defined(DEBUG) */
1348
1349 /* Wait for output to complete. */
1350 rw_exit(slock);
1351 if (!wasclean && !async && vp->v_numoutput != 0) {
1352 while (vp->v_numoutput != 0)
1353 cv_wait(&vp->v_cv, vp->v_interlock);
1354 }
1355 onworklst = (vp->v_iflag & VI_ONWORKLST) != 0;
1356 mutex_exit(vp->v_interlock);
1357
1358 if ((flags & PGO_RECLAIM) != 0 && onworklst) {
1359 /*
1360 * in the case of PGO_RECLAIM, ensure to make the vnode clean.
1361 * retrying is not a big deal because, in many cases,
1362 * uobj->uo_npages is already 0 here.
1363 */
1364 rw_enter(slock, RW_WRITER);
1365 goto retry;
1366 }
1367
1368 if (trans_mp) {
1369 if (holds_wapbl)
1370 WAPBL_END(trans_mp);
1371 fstrans_done(trans_mp);
1372 }
1373
1374 return (error);
1375 }
1376
1377 /*
1378 * Default putrange method for file systems that do not care
1379 * how many pages are given to one GOP_WRITE() call.
1380 */
1381 void
1382 genfs_gop_putrange(struct vnode *vp, off_t off, off_t *lop, off_t *hip)
1383 {
1384
1385 *lop = 0;
1386 *hip = 0;
1387 }
1388
1389 int
1390 genfs_gop_write(struct vnode *vp, struct vm_page **pgs, int npages, int flags)
1391 {
1392 off_t off;
1393 vaddr_t kva;
1394 size_t len;
1395 int error;
1396 UVMHIST_FUNC(__func__); UVMHIST_CALLED(ubchist);
1397
1398 UVMHIST_LOG(ubchist, "vp %#jx pgs %#jx npages %jd flags 0x%jx",
1399 (uintptr_t)vp, (uintptr_t)pgs, npages, flags);
1400
1401 off = pgs[0]->offset;
1402 kva = uvm_pagermapin(pgs, npages,
1403 UVMPAGER_MAPIN_WRITE | UVMPAGER_MAPIN_WAITOK);
1404 len = npages << PAGE_SHIFT;
1405
1406 error = genfs_do_io(vp, off, kva, len, flags, UIO_WRITE,
1407 uvm_aio_aiodone);
1408
1409 return error;
1410 }
1411
1412 /*
1413 * genfs_gop_write_rwmap:
1414 *
1415 * a variant of genfs_gop_write. it's used by UDF for its directory buffers.
1416 * this maps pages with PROT_WRITE so that VOP_STRATEGY can modifies
1417 * the contents before writing it out to the underlying storage.
1418 */
1419
1420 int
1421 genfs_gop_write_rwmap(struct vnode *vp, struct vm_page **pgs, int npages,
1422 int flags)
1423 {
1424 off_t off;
1425 vaddr_t kva;
1426 size_t len;
1427 int error;
1428 UVMHIST_FUNC(__func__); UVMHIST_CALLED(ubchist);
1429
1430 UVMHIST_LOG(ubchist, "vp %#jx pgs %#jx npages %jd flags 0x%jx",
1431 (uintptr_t)vp, (uintptr_t)pgs, npages, flags);
1432
1433 off = pgs[0]->offset;
1434 kva = uvm_pagermapin(pgs, npages,
1435 UVMPAGER_MAPIN_READ | UVMPAGER_MAPIN_WAITOK);
1436 len = npages << PAGE_SHIFT;
1437
1438 error = genfs_do_io(vp, off, kva, len, flags, UIO_WRITE,
1439 uvm_aio_aiodone);
1440
1441 return error;
1442 }
1443
1444 /*
1445 * Backend routine for doing I/O to vnode pages. Pages are already locked
1446 * and mapped into kernel memory. Here we just look up the underlying
1447 * device block addresses and call the strategy routine.
1448 */
1449
1450 static int
1451 genfs_do_io(struct vnode *vp, off_t off, vaddr_t kva, size_t len, int flags,
1452 enum uio_rw rw, void (*iodone)(struct buf *))
1453 {
1454 int s, error;
1455 int fs_bshift, dev_bshift;
1456 off_t eof, offset, startoffset;
1457 size_t bytes, iobytes, skipbytes;
1458 struct buf *mbp, *bp;
1459 const bool async = (flags & PGO_SYNCIO) == 0;
1460 const bool lazy = (flags & PGO_LAZY) == 0;
1461 const bool iowrite = rw == UIO_WRITE;
1462 const int brw = iowrite ? B_WRITE : B_READ;
1463 UVMHIST_FUNC(__func__); UVMHIST_CALLED(ubchist);
1464
1465 UVMHIST_LOG(ubchist, "vp %#jx kva %#jx len 0x%jx flags 0x%jx",
1466 (uintptr_t)vp, (uintptr_t)kva, len, flags);
1467
1468 KASSERT(vp->v_size <= vp->v_writesize);
1469 GOP_SIZE(vp, vp->v_writesize, &eof, 0);
1470 if (vp->v_type != VBLK) {
1471 fs_bshift = vp->v_mount->mnt_fs_bshift;
1472 dev_bshift = vp->v_mount->mnt_dev_bshift;
1473 } else {
1474 fs_bshift = DEV_BSHIFT;
1475 dev_bshift = DEV_BSHIFT;
1476 }
1477 error = 0;
1478 startoffset = off;
1479 bytes = MIN(len, eof - startoffset);
1480 skipbytes = 0;
1481 KASSERT(bytes != 0);
1482
1483 if (iowrite) {
1484 /*
1485 * why += 2?
1486 * 1 for biodone, 1 for uvm_aio_aiodone.
1487 */
1488 mutex_enter(vp->v_interlock);
1489 vp->v_numoutput += 2;
1490 mutex_exit(vp->v_interlock);
1491 }
1492 mbp = getiobuf(vp, true);
1493 UVMHIST_LOG(ubchist, "vp %#jx mbp %#jx num now %jd bytes 0x%jx",
1494 (uintptr_t)vp, (uintptr_t)mbp, vp->v_numoutput, bytes);
1495 mbp->b_bufsize = len;
1496 mbp->b_data = (void *)kva;
1497 mbp->b_resid = mbp->b_bcount = bytes;
1498 mbp->b_cflags |= BC_BUSY | BC_AGE;
1499 if (async) {
1500 mbp->b_flags = brw | B_ASYNC;
1501 mbp->b_iodone = iodone;
1502 } else {
1503 mbp->b_flags = brw;
1504 mbp->b_iodone = NULL;
1505 }
1506 if (curlwp == uvm.pagedaemon_lwp)
1507 BIO_SETPRIO(mbp, BPRIO_TIMELIMITED);
1508 else if (async || lazy)
1509 BIO_SETPRIO(mbp, BPRIO_TIMENONCRITICAL);
1510 else
1511 BIO_SETPRIO(mbp, BPRIO_TIMECRITICAL);
1512
1513 bp = NULL;
1514 for (offset = startoffset;
1515 bytes > 0;
1516 offset += iobytes, bytes -= iobytes) {
1517 int run;
1518 daddr_t lbn, blkno;
1519 struct vnode *devvp;
1520
1521 /*
1522 * bmap the file to find out the blkno to read from and
1523 * how much we can read in one i/o. if bmap returns an error,
1524 * skip the rest of the top-level i/o.
1525 */
1526
1527 lbn = offset >> fs_bshift;
1528 error = VOP_BMAP(vp, lbn, &devvp, &blkno, &run);
1529 if (error) {
1530 UVMHIST_LOG(ubchist, "VOP_BMAP lbn 0x%jx -> %jd\n",
1531 lbn, error, 0, 0);
1532 skipbytes += bytes;
1533 bytes = 0;
1534 goto loopdone;
1535 }
1536
1537 /*
1538 * see how many pages can be read with this i/o.
1539 * reduce the i/o size if necessary to avoid
1540 * overwriting pages with valid data.
1541 */
1542
1543 iobytes = MIN((((off_t)lbn + 1 + run) << fs_bshift) - offset,
1544 bytes);
1545
1546 /*
1547 * if this block isn't allocated, zero it instead of
1548 * reading it. unless we are going to allocate blocks,
1549 * mark the pages we zeroed PG_RDONLY.
1550 */
1551
1552 if (blkno == (daddr_t)-1) {
1553 if (!iowrite) {
1554 memset((char *)kva + (offset - startoffset), 0,
1555 iobytes);
1556 }
1557 skipbytes += iobytes;
1558 continue;
1559 }
1560
1561 /*
1562 * allocate a sub-buf for this piece of the i/o
1563 * (or just use mbp if there's only 1 piece),
1564 * and start it going.
1565 */
1566
1567 if (offset == startoffset && iobytes == bytes) {
1568 bp = mbp;
1569 } else {
1570 UVMHIST_LOG(ubchist, "vp %#jx bp %#jx num now %jd",
1571 (uintptr_t)vp, (uintptr_t)bp, vp->v_numoutput, 0);
1572 bp = getiobuf(vp, true);
1573 nestiobuf_setup(mbp, bp, offset - startoffset, iobytes);
1574 }
1575 bp->b_lblkno = 0;
1576
1577 /* adjust physical blkno for partial blocks */
1578 bp->b_blkno = blkno + ((offset - ((off_t)lbn << fs_bshift)) >>
1579 dev_bshift);
1580
1581 UVMHIST_LOG(ubchist,
1582 "bp %#jx offset 0x%jx bcount 0x%jx blkno 0x%jx",
1583 (uintptr_t)bp, offset, bp->b_bcount, bp->b_blkno);
1584
1585 VOP_STRATEGY(devvp, bp);
1586 }
1587
1588 loopdone:
1589 if (skipbytes) {
1590 UVMHIST_LOG(ubchist, "skipbytes %jd", skipbytes, 0,0,0);
1591 }
1592 nestiobuf_done(mbp, skipbytes, error);
1593 if (async) {
1594 UVMHIST_LOG(ubchist, "returning 0 (async)", 0,0,0,0);
1595 return (0);
1596 }
1597 UVMHIST_LOG(ubchist, "waiting for mbp %#jx", (uintptr_t)mbp, 0, 0, 0);
1598 error = biowait(mbp);
1599 s = splbio();
1600 (*iodone)(mbp);
1601 splx(s);
1602 UVMHIST_LOG(ubchist, "returning, error %jd", error, 0, 0, 0);
1603 return (error);
1604 }
1605
1606 int
1607 genfs_compat_getpages(void *v)
1608 {
1609 struct vop_getpages_args /* {
1610 struct vnode *a_vp;
1611 voff_t a_offset;
1612 struct vm_page **a_m;
1613 int *a_count;
1614 int a_centeridx;
1615 vm_prot_t a_access_type;
1616 int a_advice;
1617 int a_flags;
1618 } */ *ap = v;
1619
1620 off_t origoffset;
1621 struct vnode *vp = ap->a_vp;
1622 struct uvm_object *uobj = &vp->v_uobj;
1623 struct vm_page *pg, **pgs;
1624 vaddr_t kva;
1625 int i, error, orignpages, npages;
1626 struct iovec iov;
1627 struct uio uio;
1628 kauth_cred_t cred = curlwp->l_cred;
1629 const bool memwrite = (ap->a_access_type & VM_PROT_WRITE) != 0;
1630
1631 error = 0;
1632 origoffset = ap->a_offset;
1633 orignpages = *ap->a_count;
1634 pgs = ap->a_m;
1635
1636 if (ap->a_flags & PGO_LOCKED) {
1637 uvn_findpages(uobj, origoffset, ap->a_count, ap->a_m, NULL,
1638 UFP_NOWAIT|UFP_NOALLOC| (memwrite ? UFP_NORDONLY : 0));
1639
1640 error = ap->a_m[ap->a_centeridx] == NULL ? EBUSY : 0;
1641 if (error == 0 && memwrite) {
1642 genfs_markdirty(vp);
1643 }
1644 return error;
1645 }
1646 if (origoffset + (ap->a_centeridx << PAGE_SHIFT) >= vp->v_size) {
1647 rw_exit(uobj->vmobjlock);
1648 return EINVAL;
1649 }
1650 if ((ap->a_flags & PGO_SYNCIO) == 0) {
1651 rw_exit(uobj->vmobjlock);
1652 return 0;
1653 }
1654 npages = orignpages;
1655 uvn_findpages(uobj, origoffset, &npages, pgs, NULL, UFP_ALL);
1656 rw_exit(uobj->vmobjlock);
1657 kva = uvm_pagermapin(pgs, npages,
1658 UVMPAGER_MAPIN_READ | UVMPAGER_MAPIN_WAITOK);
1659 for (i = 0; i < npages; i++) {
1660 pg = pgs[i];
1661 if ((pg->flags & PG_FAKE) == 0) {
1662 continue;
1663 }
1664 iov.iov_base = (char *)kva + (i << PAGE_SHIFT);
1665 iov.iov_len = PAGE_SIZE;
1666 uio.uio_iov = &iov;
1667 uio.uio_iovcnt = 1;
1668 uio.uio_offset = origoffset + (i << PAGE_SHIFT);
1669 uio.uio_rw = UIO_READ;
1670 uio.uio_resid = PAGE_SIZE;
1671 UIO_SETUP_SYSSPACE(&uio);
1672 /* XXX vn_lock */
1673 error = VOP_READ(vp, &uio, 0, cred);
1674 if (error) {
1675 break;
1676 }
1677 if (uio.uio_resid) {
1678 memset(iov.iov_base, 0, uio.uio_resid);
1679 }
1680 }
1681 uvm_pagermapout(kva, npages);
1682 rw_enter(uobj->vmobjlock, RW_WRITER);
1683 for (i = 0; i < npages; i++) {
1684 pg = pgs[i];
1685 if (error && (pg->flags & PG_FAKE) != 0) {
1686 pg->flags |= PG_RELEASED;
1687 } else {
1688 uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_UNKNOWN);
1689 uvm_pagelock(pg);
1690 uvm_pageactivate(pg);
1691 uvm_pageunlock(pg);
1692 }
1693 }
1694 if (error) {
1695 uvm_page_unbusy(pgs, npages);
1696 }
1697 if (error == 0 && memwrite) {
1698 genfs_markdirty(vp);
1699 }
1700 rw_exit(uobj->vmobjlock);
1701 return error;
1702 }
1703
1704 int
1705 genfs_compat_gop_write(struct vnode *vp, struct vm_page **pgs, int npages,
1706 int flags)
1707 {
1708 off_t offset;
1709 struct iovec iov;
1710 struct uio uio;
1711 kauth_cred_t cred = curlwp->l_cred;
1712 struct buf *bp;
1713 vaddr_t kva;
1714 int error;
1715
1716 offset = pgs[0]->offset;
1717 kva = uvm_pagermapin(pgs, npages,
1718 UVMPAGER_MAPIN_WRITE | UVMPAGER_MAPIN_WAITOK);
1719
1720 iov.iov_base = (void *)kva;
1721 iov.iov_len = npages << PAGE_SHIFT;
1722 uio.uio_iov = &iov;
1723 uio.uio_iovcnt = 1;
1724 uio.uio_offset = offset;
1725 uio.uio_rw = UIO_WRITE;
1726 uio.uio_resid = npages << PAGE_SHIFT;
1727 UIO_SETUP_SYSSPACE(&uio);
1728 /* XXX vn_lock */
1729 error = VOP_WRITE(vp, &uio, 0, cred);
1730
1731 mutex_enter(vp->v_interlock);
1732 vp->v_numoutput++;
1733 mutex_exit(vp->v_interlock);
1734
1735 bp = getiobuf(vp, true);
1736 bp->b_cflags |= BC_BUSY | BC_AGE;
1737 bp->b_lblkno = offset >> vp->v_mount->mnt_fs_bshift;
1738 bp->b_data = (char *)kva;
1739 bp->b_bcount = npages << PAGE_SHIFT;
1740 bp->b_bufsize = npages << PAGE_SHIFT;
1741 bp->b_resid = 0;
1742 bp->b_error = error;
1743 uvm_aio_aiodone(bp);
1744 return (error);
1745 }
1746
1747 /*
1748 * Process a uio using direct I/O. If we reach a part of the request
1749 * which cannot be processed in this fashion for some reason, just return.
1750 * The caller must handle some additional part of the request using
1751 * buffered I/O before trying direct I/O again.
1752 */
1753
1754 void
1755 genfs_directio(struct vnode *vp, struct uio *uio, int ioflag)
1756 {
1757 struct vmspace *vs;
1758 struct iovec *iov;
1759 vaddr_t va;
1760 size_t len;
1761 const int mask = DEV_BSIZE - 1;
1762 int error;
1763 bool need_wapbl = (vp->v_mount && vp->v_mount->mnt_wapbl &&
1764 (ioflag & IO_JOURNALLOCKED) == 0);
1765
1766 #ifdef DIAGNOSTIC
1767 if ((ioflag & IO_JOURNALLOCKED) && vp->v_mount->mnt_wapbl)
1768 WAPBL_JLOCK_ASSERT(vp->v_mount);
1769 #endif
1770
1771 /*
1772 * We only support direct I/O to user space for now.
1773 */
1774
1775 if (VMSPACE_IS_KERNEL_P(uio->uio_vmspace)) {
1776 return;
1777 }
1778
1779 /*
1780 * If the vnode is mapped, we would need to get the getpages lock
1781 * to stabilize the bmap, but then we would get into trouble while
1782 * locking the pages if the pages belong to this same vnode (or a
1783 * multi-vnode cascade to the same effect). Just fall back to
1784 * buffered I/O if the vnode is mapped to avoid this mess.
1785 */
1786
1787 if (vp->v_vflag & VV_MAPPED) {
1788 return;
1789 }
1790
1791 if (need_wapbl) {
1792 error = WAPBL_BEGIN(vp->v_mount);
1793 if (error)
1794 return;
1795 }
1796
1797 /*
1798 * Do as much of the uio as possible with direct I/O.
1799 */
1800
1801 vs = uio->uio_vmspace;
1802 while (uio->uio_resid) {
1803 iov = uio->uio_iov;
1804 if (iov->iov_len == 0) {
1805 uio->uio_iov++;
1806 uio->uio_iovcnt--;
1807 continue;
1808 }
1809 va = (vaddr_t)iov->iov_base;
1810 len = MIN(iov->iov_len, genfs_maxdio);
1811 len &= ~mask;
1812
1813 /*
1814 * If the next chunk is smaller than DEV_BSIZE or extends past
1815 * the current EOF, then fall back to buffered I/O.
1816 */
1817
1818 if (len == 0 || uio->uio_offset + len > vp->v_size) {
1819 break;
1820 }
1821
1822 /*
1823 * Check alignment. The file offset must be at least
1824 * sector-aligned. The exact constraint on memory alignment
1825 * is very hardware-dependent, but requiring sector-aligned
1826 * addresses there too is safe.
1827 */
1828
1829 if (uio->uio_offset & mask || va & mask) {
1830 break;
1831 }
1832 error = genfs_do_directio(vs, va, len, vp, uio->uio_offset,
1833 uio->uio_rw);
1834 if (error) {
1835 break;
1836 }
1837 iov->iov_base = (char *)iov->iov_base + len;
1838 iov->iov_len -= len;
1839 uio->uio_offset += len;
1840 uio->uio_resid -= len;
1841 }
1842
1843 if (need_wapbl)
1844 WAPBL_END(vp->v_mount);
1845 }
1846
1847 /*
1848 * Iodone routine for direct I/O. We don't do much here since the request is
1849 * always synchronous, so the caller will do most of the work after biowait().
1850 */
1851
1852 static void
1853 genfs_dio_iodone(struct buf *bp)
1854 {
1855
1856 KASSERT((bp->b_flags & B_ASYNC) == 0);
1857 if ((bp->b_flags & B_READ) == 0 && (bp->b_cflags & BC_AGE) != 0) {
1858 mutex_enter(bp->b_objlock);
1859 vwakeup(bp);
1860 mutex_exit(bp->b_objlock);
1861 }
1862 putiobuf(bp);
1863 }
1864
1865 /*
1866 * Process one chunk of a direct I/O request.
1867 */
1868
1869 static int
1870 genfs_do_directio(struct vmspace *vs, vaddr_t uva, size_t len, struct vnode *vp,
1871 off_t off, enum uio_rw rw)
1872 {
1873 struct vm_map *map;
1874 struct pmap *upm, *kpm __unused;
1875 size_t klen = round_page(uva + len) - trunc_page(uva);
1876 off_t spoff, epoff;
1877 vaddr_t kva, puva;
1878 paddr_t pa;
1879 vm_prot_t prot;
1880 int error, rv __diagused, poff, koff;
1881 const int pgoflags = PGO_CLEANIT | PGO_SYNCIO | PGO_JOURNALLOCKED |
1882 (rw == UIO_WRITE ? PGO_FREE : 0);
1883
1884 /*
1885 * For writes, verify that this range of the file already has fully
1886 * allocated backing store. If there are any holes, just punt and
1887 * make the caller take the buffered write path.
1888 */
1889
1890 if (rw == UIO_WRITE) {
1891 daddr_t lbn, elbn, blkno;
1892 int bsize, bshift, run;
1893
1894 bshift = vp->v_mount->mnt_fs_bshift;
1895 bsize = 1 << bshift;
1896 lbn = off >> bshift;
1897 elbn = (off + len + bsize - 1) >> bshift;
1898 while (lbn < elbn) {
1899 error = VOP_BMAP(vp, lbn, NULL, &blkno, &run);
1900 if (error) {
1901 return error;
1902 }
1903 if (blkno == (daddr_t)-1) {
1904 return ENOSPC;
1905 }
1906 lbn += 1 + run;
1907 }
1908 }
1909
1910 /*
1911 * Flush any cached pages for parts of the file that we're about to
1912 * access. If we're writing, invalidate pages as well.
1913 */
1914
1915 spoff = trunc_page(off);
1916 epoff = round_page(off + len);
1917 rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
1918 error = VOP_PUTPAGES(vp, spoff, epoff, pgoflags);
1919 if (error) {
1920 return error;
1921 }
1922
1923 /*
1924 * Wire the user pages and remap them into kernel memory.
1925 */
1926
1927 prot = rw == UIO_READ ? VM_PROT_READ | VM_PROT_WRITE : VM_PROT_READ;
1928 error = uvm_vslock(vs, (void *)uva, len, prot);
1929 if (error) {
1930 return error;
1931 }
1932
1933 map = &vs->vm_map;
1934 upm = vm_map_pmap(map);
1935 kpm = vm_map_pmap(kernel_map);
1936 puva = trunc_page(uva);
1937 kva = uvm_km_alloc(kernel_map, klen, atop(puva) & uvmexp.colormask,
1938 UVM_KMF_VAONLY | UVM_KMF_WAITVA | UVM_KMF_COLORMATCH);
1939 for (poff = 0; poff < klen; poff += PAGE_SIZE) {
1940 rv = pmap_extract(upm, puva + poff, &pa);
1941 KASSERT(rv);
1942 pmap_kenter_pa(kva + poff, pa, prot, PMAP_WIRED);
1943 }
1944 pmap_update(kpm);
1945
1946 /*
1947 * Do the I/O.
1948 */
1949
1950 koff = uva - trunc_page(uva);
1951 error = genfs_do_io(vp, off, kva + koff, len, PGO_SYNCIO, rw,
1952 genfs_dio_iodone);
1953
1954 /*
1955 * Tear down the kernel mapping.
1956 */
1957
1958 pmap_kremove(kva, klen);
1959 pmap_update(kpm);
1960 uvm_km_free(kernel_map, kva, klen, UVM_KMF_VAONLY);
1961
1962 /*
1963 * Unwire the user pages.
1964 */
1965
1966 uvm_vsunlock(vs, (void *)uva, len);
1967 return error;
1968 }
1969