Index: alpha/alpha/machdep.c =================================================================== RCS file: /home/ncvs/src/sys/alpha/alpha/machdep.c,v retrieving revision 1.133 diff -u -r1.133 machdep.c --- alpha/alpha/machdep.c 2001/06/29 11:10:25 1.133 +++ alpha/alpha/machdep.c 2001/07/04 02:54:14 @@ -257,7 +257,6 @@ /* * Good {morning,afternoon,evening,night}. */ - mtx_lock(&vm_mtx); identifycpu(); /* startrtclock(); */ @@ -367,7 +366,6 @@ exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (16*(ARG_MAX+(PAGE_SIZE*3)))); - mtx_unlock(&vm_mtx); /* * XXX: Mbuf system machine-specific initializations should * go here, if anywhere. Index: alpha/alpha/mem.c =================================================================== RCS file: /home/ncvs/src/sys/alpha/alpha/mem.c,v retrieving revision 1.35 diff -u -r1.35 mem.c --- alpha/alpha/mem.c 2001/05/21 16:04:24 1.35 +++ alpha/alpha/mem.c 2001/07/04 02:54:14 @@ -145,6 +145,8 @@ int error = 0, rw; vm_offset_t addr, eaddr; + GIANT_REQUIRED; + while (uio->uio_resid > 0 && !error) { iov = uio->uio_iov; if (iov->iov_len == 0) { @@ -190,19 +192,15 @@ */ addr = trunc_page(v); eaddr = round_page(v + c); - mtx_lock(&vm_mtx); for (; addr < eaddr; addr += PAGE_SIZE) if (pmap_extract(kernel_pmap, addr) == 0) { - mtx_unlock(&vm_mtx); return EFAULT; } if (!kernacc((caddr_t)v, c, uio->uio_rw == UIO_READ ? VM_PROT_READ : VM_PROT_WRITE)) { - mtx_unlock(&vm_mtx); return (EFAULT); } - mtx_unlock(&vm_mtx); error = uiomove((caddr_t)v, c, uio); continue; } Index: alpha/alpha/trap.c =================================================================== RCS file: /home/ncvs/src/sys/alpha/alpha/trap.c,v retrieving revision 1.68 diff -u -r1.68 trap.c --- alpha/alpha/trap.c 2001/06/29 19:51:31 1.68 +++ alpha/alpha/trap.c 2001/07/04 02:54:14 @@ -278,6 +278,8 @@ critical_exit(s); #endif + GIANT_REQUIRED; + cnt.v_trap++; ucode = 0; user = (framep->tf_regs[FRAME_PS] & ALPHA_PSL_USERMODE) != 0; @@ -432,15 +434,8 @@ case ALPHA_MMCSR_FOE: case ALPHA_MMCSR_FOW: { - int hadvmlock; - - hadvmlock = mtx_owned(&vm_mtx); - if (hadvmlock == 0) - mtx_lock(&vm_mtx); pmap_emulate_reference(p, a0, user, a1 == ALPHA_MMCSR_FOW); - if (hadvmlock == 0) - mtx_unlock(&vm_mtx); goto out; } case ALPHA_MMCSR_INVALTRANS: Index: alpha/alpha/vm_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/alpha/alpha/vm_machdep.c,v retrieving revision 1.52 diff -u -r1.52 vm_machdep.c --- alpha/alpha/vm_machdep.c 2001/07/03 05:09:37 1.52 +++ alpha/alpha/vm_machdep.c 2001/07/04 02:54:14 @@ -274,14 +274,13 @@ cpu_wait(p) struct proc *p; { + GIANT_REQUIRED; - mtx_lock(&vm_mtx); /* drop per-process resources */ pmap_dispose_proc(p); /* and clean-out the vmspace */ vmspace_free(p->p_vmspace); - mtx_unlock(&vm_mtx); } /* @@ -330,10 +329,11 @@ register caddr_t addr, v, kva; vm_offset_t pa; + GIANT_REQUIRED; + if ((bp->b_flags & B_PHYS) == 0) panic("vmapbuf"); - mtx_lock(&vm_mtx); for (v = bp->b_saveaddr, addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE, v += PAGE_SIZE) { @@ -349,7 +349,6 @@ vm_page_hold(PHYS_TO_VM_PAGE(pa)); pmap_kenter((vm_offset_t) v, pa); } - mtx_unlock(&vm_mtx); kva = bp->b_saveaddr; bp->b_saveaddr = bp->b_data; @@ -367,10 +366,11 @@ register caddr_t addr; vm_offset_t pa; + GIANT_REQUIRED; + if ((bp->b_flags & B_PHYS) == 0) panic("vunmapbuf"); - mtx_lock(&vm_mtx); for (addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE) { @@ -378,7 +378,6 @@ pmap_kremove((vm_offset_t) addr); vm_page_unhold(PHYS_TO_VM_PAGE(pa)); } - mtx_unlock(&vm_mtx); bp->b_data = bp->b_saveaddr; } @@ -436,17 +435,13 @@ * pages because doing so may flush our L1 and L2 caches too much. */ - if (mtx_trylock(&vm_mtx) == 0) - return (0); if (zero_state && vm_page_zero_count >= ZIDLE_LO(cnt.v_free_count)) { - mtx_unlock(&vm_mtx); return(0); } if (vm_page_zero_count >= ZIDLE_HI(cnt.v_free_count)) { - mtx_unlock(&vm_mtx); return(0); } - + if (mtx_trylock(&Giant)) { s = splvm(); m = vm_page_list_find(PQ_FREE, free_rover, FALSE); zero_state = 0; @@ -469,8 +464,9 @@ } free_rover = (free_rover + PQ_PRIME2) & PQ_L2_MASK; splx(s); - mtx_unlock(&vm_mtx); return (1); + } + return(0); } /* Index: alpha/osf1/imgact_osf1.c =================================================================== RCS file: /home/ncvs/src/sys/alpha/osf1/imgact_osf1.c,v retrieving revision 1.6 diff -u -r1.6 imgact_osf1.c --- alpha/osf1/imgact_osf1.c 2001/06/06 13:46:16 1.6 +++ alpha/osf1/imgact_osf1.c 2001/07/04 02:54:14 @@ -97,6 +97,8 @@ struct nameidata *ndp; Osf_Auxargs *osf_auxargs; + GIANT_REQUIRED; + execp = (const struct ecoff_exechdr*)imgp->image_header; eap = &execp->a; ndp = NULL; @@ -175,14 +177,12 @@ /* * Destroy old process VM and create a new one (with a new stack). */ - mtx_lock(&vm_mtx); exec_new_vmspace(imgp); /* * The vm space can now be changed. */ vmspace = imgp->proc->p_vmspace; - mtx_unlock(&vm_mtx); imgp->interpreted = 0; imgp->proc->p_sysent = &osf1_sysvec; @@ -214,17 +214,14 @@ /* .. bss .. */ if (round_page(bsize)) { baddr = bss_start; - mtx_lock(&vm_mtx); if ((error = vm_map_find(&vmspace->vm_map, NULL, (vm_offset_t) 0, &baddr, round_page(bsize), FALSE, VM_PROT_ALL, VM_PROT_ALL, FALSE))) { - mtx_unlock(&vm_mtx); DPRINTF(("%s(%d): error = %d\n", __FILE__, __LINE__, error)); goto bail; } - mtx_unlock(&vm_mtx); } Index: alpha/osf1/osf1_misc.c =================================================================== RCS file: /home/ncvs/src/sys/alpha/osf1/osf1_misc.c,v retrieving revision 1.16 diff -u -r1.16 osf1_misc.c --- alpha/osf1/osf1_misc.c 2001/06/06 14:07:52 1.16 +++ alpha/osf1/osf1_misc.c 2001/07/04 02:54:14 @@ -472,6 +472,8 @@ vm_map_t map; vm_offset_t addr, len, newaddr; + GIANT_REQUIRED; + SCARG(&a, addr) = SCARG(uap, addr); SCARG(&a, len) = SCARG(uap, len); SCARG(&a, prot) = SCARG(uap, prot); @@ -500,7 +502,6 @@ addr = round_page((vm_offset_t)0x10000UL); len = (vm_offset_t)SCARG(&a, len); map = &p->p_vmspace->vm_map; - mtx_lock(&vm_mtx); if (!vm_map_findspace(map, addr, len, &newaddr)) { SCARG(&a,addr) = (caddr_t) newaddr; SCARG(&a, flags) |= (MAP_FIXED); @@ -510,7 +511,6 @@ uprintf("osf1_mmap:vm_map_findspace failed for: %p 0x%lx\n", (caddr_t)addr, len); #endif - mtx_unlock(&vm_mtx); if (SCARG(uap, flags) & OSF1_MAP_SHARED) SCARG(&a, flags) |= MAP_SHARED; if (SCARG(uap, flags) & OSF1_MAP_PRIVATE) @@ -1643,15 +1643,15 @@ vm_map_entry_t entry; vm_offset_t zero; + GIANT_REQUIRED; + zero = 0; if (uap->cmd == OSF1_USC_GET) { - mtx_lock(&vm_mtx); if (vm_map_lookup_entry(&(p->p_vmspace->vm_map),0, &entry)) p->p_retval[0] = OSF1_USW_NULLP; else p->p_retval[0] = 0; - mtx_unlock(&vm_mtx); return(KERN_SUCCESS); } else if (uap->cmd == OSF1_USC_SET) if (uap->mask & OSF1_USW_NULLP) { Index: dev/md/md.c =================================================================== RCS file: /home/ncvs/src/sys/dev/md/md.c,v retrieving revision 1.36 diff -u -r1.36 md.c --- dev/md/md.c 2001/06/25 18:24:52 1.36 +++ dev/md/md.c 2001/07/04 02:54:14 @@ -692,6 +692,8 @@ { unsigned u; + GIANT_REQUIRED; + if (sc->dev != NULL) { devstat_remove_entry(&sc->stats); disk_destroy(sc->dev); @@ -701,9 +703,7 @@ if (sc->cred != NULL) crfree(sc->cred); if (sc->object != NULL) { - mtx_lock(&vm_mtx); vm_pager_deallocate(sc->object); - mtx_unlock(&vm_mtx); } if (sc->secp != NULL) { for (u = 0; u < sc->nsect; u++) @@ -725,6 +725,8 @@ int error; struct md_s *sc; + GIANT_REQUIRED; + if (mdio->md_options & MD_AUTOUNIT) { sc = mdnew(-1); mdio->md_unit = sc->unit; @@ -757,18 +759,15 @@ sc->secsize = PAGE_SIZE; sc->nsect = mdio->md_size / (PAGE_SIZE / DEV_BSIZE); - mtx_lock(&vm_mtx); sc->object = vm_pager_allocate(OBJT_SWAP, NULL, sc->secsize * (vm_offset_t)sc->nsect, VM_PROT_DEFAULT, 0); if (mdio->md_options & MD_RESERVE) { if (swap_pager_reserve(sc->object, 0, sc->nsect) < 0) { vm_pager_deallocate(sc->object); - mtx_unlock(&vm_mtx); sc->object = NULL; mddestroy(sc, mdio, p); return(EDOM); } } - mtx_unlock(&vm_mtx); error = mdsetcred(sc, p->p_ucred); if (error) mddestroy(sc, mdio, p); Index: fs/procfs/procfs_map.c =================================================================== RCS file: /home/ncvs/src/sys/fs/procfs/procfs_map.c,v retrieving revision 1.28 diff -u -r1.28 procfs_map.c --- fs/procfs/procfs_map.c 2001/06/06 04:13:11 1.28 +++ fs/procfs/procfs_map.c 2001/07/04 02:54:14 @@ -81,14 +81,14 @@ vm_map_entry_t entry; char mebuffer[MEBUFFERSIZE]; + GIANT_REQUIRED; + if (uio->uio_rw != UIO_READ) return (EOPNOTSUPP); if (uio->uio_offset != 0) return (0); - mtx_lock(&vm_mtx); - error = 0; if (map != &curproc->p_vmspace->vm_map) vm_map_lock_read(map); @@ -171,17 +171,13 @@ error = EFBIG; break; } - mtx_unlock(&vm_mtx); error = uiomove(mebuffer, len, uio); - mtx_lock(&vm_mtx); if (error) break; } if (map != &curproc->p_vmspace->vm_map) vm_map_unlock_read(map); - mtx_unlock(&vm_mtx); - return error; } Index: fs/procfs/procfs_mem.c =================================================================== RCS file: /home/ncvs/src/sys/fs/procfs/procfs_mem.c,v retrieving revision 1.50 diff -u -r1.50 procfs_mem.c --- fs/procfs/procfs_mem.c 2001/05/23 09:42:11 1.50 +++ fs/procfs/procfs_mem.c 2001/07/04 02:54:14 @@ -83,6 +83,8 @@ vm_prot_t reqprot; vm_offset_t kva; + GIANT_REQUIRED; + /* * if the vmspace is in the midst of being deallocated or the * process is exiting, don't try to grab anything. The page table @@ -91,12 +93,8 @@ vm = p->p_vmspace; if ((p->p_flag & P_WEXIT)) return EFAULT; - - mtx_lock(&vm_mtx); - if (vm->vm_refcnt < 1) { - mtx_unlock(&vm_mtx); + if (vm->vm_refcnt < 1) return EFAULT; - } ++vm->vm_refcnt; /* * The map we want... @@ -214,9 +212,7 @@ /* * Now do the i/o move. */ - mtx_unlock(&vm_mtx); error = uiomove((caddr_t)(kva + page_offset), len, uio); - mtx_lock(&vm_mtx); pmap_kremove(kva); @@ -235,7 +231,6 @@ kmem_free(kernel_map, kva, PAGE_SIZE); vmspace_free(vm); - mtx_unlock(&vm_mtx); return (error); } Index: fs/specfs/spec_vnops.c =================================================================== RCS file: /home/ncvs/src/sys/fs/specfs/spec_vnops.c,v retrieving revision 1.159 diff -u -r1.159 spec_vnops.c --- fs/specfs/spec_vnops.c 2001/05/23 22:20:29 1.159 +++ fs/specfs/spec_vnops.c 2001/07/04 02:54:14 @@ -660,7 +660,8 @@ int blksiz; int gotreqpage; - mtx_assert(&Giant, MA_OWNED); + GIANT_REQUIRED; + error = 0; pcount = round_page(ap->a_count) / PAGE_SIZE; @@ -732,7 +733,6 @@ cnt.v_vnodein++; cnt.v_vnodepgsin += pcount; - mtx_unlock(&vm_mtx); /* Do the input. */ BUF_STRATEGY(bp); @@ -743,7 +743,6 @@ tsleep(bp, PVM, "spread", 0); splx(s); - mtx_lock(&vm_mtx); if ((bp->b_ioflags & BIO_ERROR) != 0) { if (bp->b_error) Index: i386/i386/busdma_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/busdma_machdep.c,v retrieving revision 1.22 diff -u -r1.22 busdma_machdep.c --- i386/i386/busdma_machdep.c 2001/05/19 01:28:01 1.22 +++ i386/i386/busdma_machdep.c 2001/07/04 02:54:14 @@ -32,6 +32,7 @@ #include #include #include +#include #include #include Index: i386/i386/machdep.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/machdep.c,v retrieving revision 1.459 diff -u -r1.459 machdep.c --- i386/i386/machdep.c 2001/06/29 18:13:30 1.459 +++ i386/i386/machdep.c 2001/07/04 02:54:14 @@ -260,7 +260,6 @@ /* * Good {morning,afternoon,evening,night}. */ - mtx_lock(&vm_mtx); earlysetcpuclass(); startrtclock(); printcpuinfo(); @@ -394,7 +393,6 @@ exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (16*(ARG_MAX+(PAGE_SIZE*3)))); - mtx_unlock(&vm_mtx); /* * XXX: Mbuf system machine-specific initializations should * go here, if anywhere. @@ -2049,6 +2047,8 @@ if (!has_f00f_bug) return; + GIANT_REQUIRED; + printf("Intel Pentium detected, installing workaround for F00F bug\n"); r_idt.rd_limit = sizeof(idt0) - 1; @@ -2064,11 +2064,9 @@ r_idt.rd_base = (int)new_idt; lidt(&r_idt); idt = new_idt; - mtx_lock(&vm_mtx); if (vm_map_protect(kernel_map, tmp, tmp + PAGE_SIZE, VM_PROT_READ, FALSE) != KERN_SUCCESS) panic("vm_map_protect failed"); - mtx_unlock(&vm_mtx); return; } #endif /* defined(I586_CPU) && !NO_F00F_HACK */ Index: i386/i386/mem.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/mem.c,v retrieving revision 1.91 diff -u -r1.91 mem.c --- i386/i386/mem.c 2001/06/29 11:10:28 1.91 +++ i386/i386/mem.c 2001/07/04 02:54:14 @@ -140,6 +140,8 @@ int error = 0; vm_offset_t addr, eaddr; + GIANT_REQUIRED; + while (uio->uio_resid > 0 && error == 0) { iov = uio->uio_iov; if (iov->iov_len == 0) { @@ -155,17 +157,13 @@ case 0: v = uio->uio_offset; v &= ~PAGE_MASK; - mtx_lock(&vm_mtx); pmap_kenter((vm_offset_t)ptvmmap, v); - mtx_unlock(&vm_mtx); o = (int)uio->uio_offset & PAGE_MASK; c = (u_int)(PAGE_SIZE - ((int)iov->iov_base & PAGE_MASK)); c = min(c, (u_int)(PAGE_SIZE - o)); c = min(c, (u_int)iov->iov_len); error = uiomove((caddr_t)&ptvmmap[o], (int)c, uio); - mtx_lock(&vm_mtx); pmap_kremove((vm_offset_t)ptvmmap); - mtx_unlock(&vm_mtx); continue; /* minor device 1 is kernel memory */ @@ -183,20 +181,16 @@ return EFAULT; if (eaddr >= (vm_offset_t)VADDR(APTDPTDI, 0)) return EFAULT; - mtx_lock(&vm_mtx); for (; addr < eaddr; addr += PAGE_SIZE) if (pmap_extract(kernel_pmap, addr) == 0) { - mtx_unlock(&vm_mtx); return EFAULT; } if (!kernacc((caddr_t)(int)uio->uio_offset, c, uio->uio_rw == UIO_READ ? VM_PROT_READ : VM_PROT_WRITE)) { - mtx_unlock(&vm_mtx); return (EFAULT); } - mtx_unlock(&vm_mtx); error = uiomove((caddr_t)(int)uio->uio_offset, (int)c, uio); continue; } Index: i386/i386/pmap.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/pmap.c,v retrieving revision 1.282 diff -u -r1.282 pmap.c --- i386/i386/pmap.c 2001/05/23 22:17:28 1.282 +++ i386/i386/pmap.c 2001/07/04 02:54:15 @@ -3135,14 +3135,11 @@ { vm_offset_t va, tmpva, offset; unsigned *pte; - int hadvmlock; offset = pa & PAGE_MASK; size = roundup(offset + size, PAGE_SIZE); - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); + GIANT_REQUIRED; va = kmem_alloc_pageable(kernel_map, size); if (!va) @@ -3157,9 +3154,6 @@ pa += PAGE_SIZE; } invltlb(); - - if (!hadvmlock) - mtx_unlock(&vm_mtx); return ((void *)(va + offset)); } Index: i386/i386/vm_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/vm_machdep.c,v retrieving revision 1.163 diff -u -r1.163 vm_machdep.c --- i386/i386/vm_machdep.c 2001/07/03 05:09:44 1.163 +++ i386/i386/vm_machdep.c 2001/07/04 02:54:15 @@ -292,14 +292,13 @@ cpu_wait(p) struct proc *p; { + GIANT_REQUIRED; - mtx_lock(&vm_mtx); /* drop per-process resources */ pmap_dispose_proc(p); /* and clean-out the vmspace */ vmspace_free(p->p_vmspace); - mtx_unlock(&vm_mtx); } /* @@ -378,10 +377,11 @@ register caddr_t addr, v, kva; vm_offset_t pa; + GIANT_REQUIRED; + if ((bp->b_flags & B_PHYS) == 0) panic("vmapbuf"); - mtx_lock(&vm_mtx); for (v = bp->b_saveaddr, addr = (caddr_t)trunc_page((vm_offset_t)bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE, v += PAGE_SIZE) { @@ -397,7 +397,6 @@ vm_page_hold(PHYS_TO_VM_PAGE(pa)); pmap_kenter((vm_offset_t) v, pa); } - mtx_unlock(&vm_mtx); kva = bp->b_saveaddr; bp->b_saveaddr = bp->b_data; @@ -415,10 +414,11 @@ register caddr_t addr; vm_offset_t pa; + GIANT_REQUIRED; + if ((bp->b_flags & B_PHYS) == 0) panic("vunmapbuf"); - mtx_lock(&vm_mtx); for (addr = (caddr_t)trunc_page((vm_offset_t)bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE) { @@ -426,7 +426,6 @@ pmap_kremove((vm_offset_t) addr); vm_page_unhold(PHYS_TO_VM_PAGE(pa)); } - mtx_unlock(&vm_mtx); bp->b_data = bp->b_saveaddr; } @@ -582,17 +581,12 @@ * pages because doing so may flush our L1 and L2 caches too much. */ - if (mtx_trylock(&vm_mtx) == 0) - return (0); - if (zero_state && vm_page_zero_count >= ZIDLE_LO(cnt.v_free_count)) { - mtx_unlock(&vm_mtx); + if (zero_state && vm_page_zero_count >= ZIDLE_LO(cnt.v_free_count)) return(0); - } - if (vm_page_zero_count >= ZIDLE_HI(cnt.v_free_count)) { - mtx_unlock(&vm_mtx); + if (vm_page_zero_count >= ZIDLE_HI(cnt.v_free_count)) return(0); - } + if (mtx_trylock(&Giant)) { zero_state = 0; m = vm_page_list_find(PQ_FREE, free_rover, FALSE); if (m != NULL && (m->flags & PG_ZERO) == 0) { @@ -611,8 +605,9 @@ zero_state = 1; } free_rover = (free_rover + PQ_PRIME2) & PQ_L2_MASK; - mtx_unlock(&vm_mtx); return (1); + } + return(0); } /* Index: i386/isa/isa_dma.c =================================================================== RCS file: /home/ncvs/src/sys/i386/isa/isa_dma.c,v retrieving revision 1.8 diff -u -r1.8 isa_dma.c --- i386/isa/isa_dma.c 2001/06/30 05:29:08 1.8 +++ i386/isa/isa_dma.c 2001/07/04 02:54:15 @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -216,6 +217,8 @@ int waport; caddr_t newaddr; + GIANT_REQUIRED; + #ifdef DIAGNOSTIC if (chan & ~VALID_DMA_MASK) panic("isa_dmastart: channel out of range"); @@ -254,12 +257,7 @@ } /* translate to physical */ - mtx_lock(&vm_mtx); /* - * XXX: need to hold for longer period to - * ensure that mappings don't change - */ phys = pmap_extract(pmap_kernel(), (vm_offset_t)addr); - mtx_unlock(&vm_mtx); if (flags & ISADMA_RAW) { dma_auto_mode |= (1 << chan); @@ -378,11 +376,11 @@ vm_offset_t phys, priorpage = 0, endva; u_int dma_pgmsk = (chan & 4) ? ~(128*1024-1) : ~(64*1024-1); + GIANT_REQUIRED; + endva = (vm_offset_t)round_page((vm_offset_t)va + length); for (; va < (caddr_t) endva ; va += PAGE_SIZE) { - mtx_lock(&vm_mtx); phys = trunc_page(pmap_extract(pmap_kernel(), (vm_offset_t)va)); - mtx_unlock(&vm_mtx); #define ISARAM_END RAM_END if (phys == 0) panic("isa_dmacheck: no physical page present"); Index: kern/imgact_aout.c =================================================================== RCS file: /home/ncvs/src/sys/kern/imgact_aout.c,v retrieving revision 1.68 diff -u -r1.68 imgact_aout.c --- kern/imgact_aout.c 2001/05/19 01:28:02 1.68 +++ kern/imgact_aout.c 2001/07/04 02:54:15 @@ -91,6 +91,8 @@ unsigned long bss_size; int error; + GIANT_REQUIRED; + /* * Linux and *BSD binaries look very much alike, * only the machine id is different: @@ -171,7 +173,6 @@ if (error) return (error); - mtx_lock(&vm_mtx); /* * Destroy old process VM and create a new one (with a new stack) */ @@ -185,9 +186,7 @@ vp = imgp->vp; map = &vmspace->vm_map; vm_map_lock(map); - mtx_unlock(&vm_mtx); VOP_GETVOBJECT(vp, &object); - mtx_lock(&vm_mtx); vm_object_reference(object); text_end = virtual_offset + a_out->a_text; @@ -198,7 +197,6 @@ MAP_COPY_ON_WRITE | MAP_PREFAULT); if (error) { vm_map_unlock(map); - mtx_unlock(&vm_mtx); return (error); } data_end = text_end + a_out->a_data; @@ -211,7 +209,6 @@ MAP_COPY_ON_WRITE | MAP_PREFAULT); if (error) { vm_map_unlock(map); - mtx_unlock(&vm_mtx); return (error); } } @@ -222,7 +219,6 @@ VM_PROT_ALL, VM_PROT_ALL, 0); if (error) { vm_map_unlock(map); - mtx_unlock(&vm_mtx); return (error); } } @@ -234,8 +230,6 @@ vmspace->vm_taddr = (caddr_t) (uintptr_t) virtual_offset; vmspace->vm_daddr = (caddr_t) (uintptr_t) (virtual_offset + a_out->a_text); - - mtx_unlock(&vm_mtx); /* Fill in image_params */ imgp->interpreted = 0; Index: kern/imgact_elf.c =================================================================== RCS file: /home/ncvs/src/sys/kern/imgact_elf.c,v retrieving revision 1.95 diff -u -r1.95 imgact_elf.c --- kern/imgact_elf.c 2001/05/23 22:05:08 1.95 +++ kern/imgact_elf.c 2001/07/04 02:54:15 @@ -198,6 +198,8 @@ vm_offset_t file_addr; vm_offset_t data_buf = 0; + GIANT_REQUIRED; + VOP_GETVOBJECT(vp, &object); error = 0; @@ -230,7 +232,6 @@ else map_len = round_page(offset+filsz) - file_addr; - mtx_lock(&vm_mtx); if (map_len != 0) { vm_object_reference(object); vm_map_lock(&vmspace->vm_map); @@ -245,13 +246,11 @@ vm_map_unlock(&vmspace->vm_map); if (rv != KERN_SUCCESS) { vm_object_deallocate(object); - mtx_unlock(&vm_mtx); return EINVAL; } /* we can stop now if we've covered it all */ if (memsz == filsz) { - mtx_unlock(&vm_mtx); return 0; } } @@ -275,7 +274,6 @@ VM_PROT_ALL, VM_PROT_ALL, 0); vm_map_unlock(&vmspace->vm_map); if (rv != KERN_SUCCESS) { - mtx_unlock(&vm_mtx); return EINVAL; } } @@ -293,17 +291,13 @@ MAP_COPY_ON_WRITE | MAP_PREFAULT_PARTIAL); if (rv != KERN_SUCCESS) { vm_object_deallocate(object); - mtx_unlock(&vm_mtx); return EINVAL; } /* send the page fragment to user space */ - mtx_unlock(&vm_mtx); error = copyout((caddr_t)data_buf, (caddr_t)map_addr, copy_len); - mtx_lock(&vm_mtx); vm_map_remove(exec_map, data_buf, data_buf + PAGE_SIZE); if (error) { - mtx_unlock(&vm_mtx); return (error); } } @@ -314,7 +308,6 @@ vm_map_protect(&vmspace->vm_map, map_addr, map_addr + map_len, prot, FALSE); - mtx_unlock(&vm_mtx); return error; } @@ -475,6 +468,8 @@ Elf_Brandinfo *brand_info; char path[MAXPATHLEN]; + GIANT_REQUIRED; + /* * Do we have a valid ELF header ? */ @@ -510,11 +505,9 @@ if ((error = exec_extract_strings(imgp)) != 0) goto fail; - mtx_lock(&vm_mtx); exec_new_vmspace(imgp); vmspace = imgp->proc->p_vmspace; - mtx_unlock(&vm_mtx); for (i = 0; i < hdr->e_phnum; i++) { switch(phdr[i].p_type) { @@ -571,12 +564,10 @@ } } - mtx_lock(&vm_mtx); vmspace->vm_tsize = text_size >> PAGE_SHIFT; vmspace->vm_taddr = (caddr_t)(uintptr_t)text_addr; vmspace->vm_dsize = data_size >> PAGE_SHIFT; vmspace->vm_daddr = (caddr_t)(uintptr_t)data_addr; - mtx_unlock(&vm_mtx); addr = ELF_RTLD_ADDR(vmspace); Index: kern/init_main.c =================================================================== RCS file: /home/ncvs/src/sys/kern/init_main.c,v retrieving revision 1.173 diff -u -r1.173 init_main.c --- kern/init_main.c 2001/06/13 10:58:36 1.173 +++ kern/init_main.c 2001/07/04 02:54:15 @@ -274,6 +274,8 @@ register struct filedesc0 *fdp; register unsigned i; + GIANT_REQUIRED; + p = &proc0; /* @@ -373,14 +375,12 @@ limit0.p_refcnt = 1; /* Allocate a prototype map so we have something to fork. */ - mtx_lock(&vm_mtx); pmap_pinit0(vmspace_pmap(&vmspace0)); p->p_vmspace = &vmspace0; vmspace0.vm_refcnt = 1; vm_map_init(&vmspace0.vm_map, round_page(VM_MIN_ADDRESS), trunc_page(VM_MAXUSER_ADDRESS)); vmspace0.vm_map.pmap = vmspace_pmap(&vmspace0); - mtx_unlock(&vm_mtx); p->p_addr = proc0paddr; /* XXX */ /* @@ -471,6 +471,8 @@ mtx_lock(&Giant); + GIANT_REQUIRED; + p = curproc; /* Get the vnode for '/'. Set p->p_fd->fd_cdir to reference it. */ @@ -486,13 +488,11 @@ * Need just enough stack to hold the faked-up "execve()" arguments. */ addr = trunc_page(USRSTACK - PAGE_SIZE); - mtx_lock(&vm_mtx); if (vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr, PAGE_SIZE, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0) != 0) panic("init: couldn't allocate argument space"); p->p_vmspace->vm_maxsaddr = (caddr_t)addr; p->p_vmspace->vm_ssize = 1; - mtx_unlock(&vm_mtx); if ((var = getenv("init_path")) != NULL) { strncpy(init_path, var, sizeof init_path); Index: kern/kern_exec.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_exec.c,v retrieving revision 1.132 diff -u -r1.132 kern_exec.c --- kern/kern_exec.c 2001/06/20 23:10:06 1.132 +++ kern/kern_exec.c 2001/07/04 02:54:15 @@ -445,13 +445,13 @@ vm_page_t ma[VM_INITIAL_PAGEIN]; vm_object_t object; + GIANT_REQUIRED; if (imgp->firstpage) { exec_unmap_first_page(imgp); } VOP_GETVOBJECT(imgp->vp, &object); - mtx_lock(&vm_mtx); ma[0] = vm_page_grab(object, 0, VM_ALLOC_NORMAL | VM_ALLOC_RETRY); @@ -482,7 +482,6 @@ vm_page_protect(ma[0], VM_PROT_NONE); vm_page_free(ma[0]); } - mtx_unlock(&vm_mtx); return EIO; } } @@ -493,7 +492,6 @@ pmap_kenter((vm_offset_t) imgp->image_header, VM_PAGE_TO_PHYS(ma[0])); imgp->firstpage = ma[0]; - mtx_unlock(&vm_mtx); return 0; } @@ -501,12 +499,11 @@ exec_unmap_first_page(imgp) struct image_params *imgp; { + GIANT_REQUIRED; if (imgp->firstpage) { - mtx_lock(&vm_mtx); pmap_kremove((vm_offset_t) imgp->image_header); vm_page_unwire(imgp->firstpage, 1); - mtx_unlock(&vm_mtx); imgp->firstpage = NULL; } } @@ -525,7 +522,8 @@ caddr_t stack_addr = (caddr_t) (USRSTACK - MAXSSIZ); vm_map_t map = &vmspace->vm_map; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + imgp->vmspace_destroyed = 1; /* Index: kern/kern_exit.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_exit.c,v retrieving revision 1.129 diff -u -r1.129 kern_exit.c --- kern/kern_exit.c 2001/06/27 06:15:44 1.129 +++ kern/kern_exit.c 2001/07/04 02:54:15 @@ -120,6 +120,8 @@ register struct vmspace *vm; struct exitlist *ep; + GIANT_REQUIRED; + if (p->p_pid == 1) { printf("init died (signal %d, exit %d)\n", WTERMSIG(rv), WEXITSTATUS(rv)); @@ -213,7 +215,6 @@ * Can't free the entire vmspace as the kernel stack * may be mapped within that space also. */ - mtx_lock(&vm_mtx); if (vm->vm_refcnt == 1) { if (vm->vm_shm) shmexit(p); @@ -222,7 +223,6 @@ (void) vm_map_remove(&vm->vm_map, VM_MIN_ADDRESS, VM_MAXUSER_ADDRESS); } - mtx_unlock(&vm_mtx); PROC_LOCK(p); if (SESS_LEADER(p)) { Index: kern/kern_fork.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_fork.c,v retrieving revision 1.115 diff -u -r1.115 kern_fork.c --- kern/kern_fork.c 2001/06/30 03:35:22 1.115 +++ kern/kern_fork.c 2001/07/04 02:54:15 @@ -209,6 +209,8 @@ struct forklist *ep; struct filedesc *fd; + GIANT_REQUIRED; + /* Can't copy and clear */ if ((flags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG)) return (EINVAL); @@ -218,9 +220,7 @@ * certain parts of a process from itself. */ if ((flags & RFPROC) == 0) { - vm_fork(p1, 0, flags); - mtx_assert(&vm_mtx, MA_NOTOWNED); /* * Close all file descriptors. @@ -561,7 +561,6 @@ * execution path later. (ie: directly into user mode) */ vm_fork(p1, p2, flags); - mtx_assert(&vm_mtx, MA_NOTOWNED); if (flags == (RFFDG | RFPROC)) { cnt.v_forks++; Index: kern/kern_resource.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_resource.c,v retrieving revision 1.83 diff -u -r1.83 kern_resource.c --- kern/kern_resource.c 2001/05/19 01:28:02 1.83 +++ kern/kern_resource.c 2001/07/04 02:54:15 @@ -431,6 +431,8 @@ register struct rlimit *alimp; int error; + GIANT_REQUIRED; + if (which >= RLIM_NLIMITS) return (EINVAL); alimp = &p->p_rlimit[which]; @@ -498,10 +500,8 @@ } addr = trunc_page(addr); size = round_page(size); - mtx_lock(&vm_mtx); (void) vm_map_protect(&p->p_vmspace->vm_map, addr, addr+size, prot, FALSE); - mtx_unlock(&vm_mtx); } break; Index: kern/link_elf.c =================================================================== RCS file: /home/ncvs/src/sys/kern/link_elf.c,v retrieving revision 1.38 diff -u -r1.38 link_elf.c --- kern/link_elf.c 2001/06/13 10:58:36 1.38 +++ kern/link_elf.c 2001/07/04 02:54:15 @@ -531,6 +531,8 @@ int symcnt; int strcnt; + GIANT_REQUIRED; + shdr = NULL; lf = NULL; @@ -657,10 +659,8 @@ ef = (elf_file_t) lf; #ifdef SPARSE_MAPPING - mtx_lock(&vm_mtx); ef->object = vm_object_allocate(OBJT_DEFAULT, mapsize >> PAGE_SHIFT); if (ef->object == NULL) { - mtx_unlock(&vm_mtx); free(ef, M_LINKER); error = ENOMEM; goto out; @@ -673,11 +673,9 @@ VM_PROT_ALL, VM_PROT_ALL, 0); if (error) { vm_object_deallocate(ef->object); - mtx_unlock(&vm_mtx); ef->object = 0; goto out; } - mtx_unlock(&vm_mtx); #else ef->address = malloc(mapsize, M_LINKER, M_WAITOK); if (!ef->address) { @@ -705,12 +703,10 @@ /* * Wire down the pages */ - mtx_lock(&vm_mtx); vm_map_pageable(kernel_map, (vm_offset_t) segbase, (vm_offset_t) segbase + segs[i]->p_memsz, FALSE); - mtx_unlock(&vm_mtx); #endif } @@ -834,12 +830,10 @@ } #ifdef SPARSE_MAPPING if (ef->object) { - mtx_lock(&vm_mtx); vm_map_remove(kernel_map, (vm_offset_t) ef->address, (vm_offset_t) ef->address + (ef->object->size << PAGE_SHIFT)); vm_object_deallocate(ef->object); - mtx_unlock(&vm_mtx); } #else if (ef->address) Index: kern/subr_blist.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_blist.c,v retrieving revision 1.8 diff -u -r1.8 subr_blist.c --- kern/subr_blist.c 2001/05/19 01:28:02 1.8 +++ kern/subr_blist.c 2001/07/04 02:54:15 @@ -71,6 +71,7 @@ #include #include #include +#include #include #include #include Index: kern/sys_pipe.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sys_pipe.c,v retrieving revision 1.82 diff -u -r1.82 sys_pipe.c --- kern/sys_pipe.c 2001/06/15 20:45:01 1.82 +++ kern/sys_pipe.c 2001/07/04 02:54:15 @@ -248,13 +248,14 @@ caddr_t buffer; int npages, error; + GIANT_REQUIRED; + npages = round_page(size)/PAGE_SIZE; /* * Create an object, I don't like the idea of paging to/from * kernel_object. * XXX -- minor change needed here for NetBSD/OpenBSD VM systems. */ - mtx_lock(&vm_mtx); object = vm_object_allocate(OBJT_DEFAULT, npages); buffer = (caddr_t) vm_map_min(kernel_map); @@ -269,13 +270,11 @@ if (error != KERN_SUCCESS) { vm_object_deallocate(object); - mtx_unlock(&vm_mtx); return (ENOMEM); } /* free old resources if we're resizing */ pipe_free_kmem(cpipe); - mtx_unlock(&vm_mtx); cpipe->pipe_buffer.object = object; cpipe->pipe_buffer.buffer = buffer; cpipe->pipe_buffer.size = size; @@ -551,12 +550,13 @@ int i; vm_offset_t addr, endaddr, paddr; + GIANT_REQUIRED; + size = (u_int) uio->uio_iov->iov_len; if (size > wpipe->pipe_buffer.size) size = wpipe->pipe_buffer.size; endaddr = round_page((vm_offset_t)uio->uio_iov->iov_base + size); - mtx_lock(&vm_mtx); addr = trunc_page((vm_offset_t)uio->uio_iov->iov_base); for (i = 0; addr < endaddr; addr += PAGE_SIZE, i++) { vm_page_t m; @@ -567,7 +567,6 @@ for (j = 0; j < i; j++) vm_page_unwire(wpipe->pipe_map.ms[j], 1); - mtx_unlock(&vm_mtx); return (EFAULT); } @@ -599,7 +598,6 @@ pmap_qenter(wpipe->pipe_map.kva, wpipe->pipe_map.ms, wpipe->pipe_map.npages); - mtx_unlock(&vm_mtx); /* * and update the uio data */ @@ -621,8 +619,9 @@ struct pipe *wpipe; { int i; + + GIANT_REQUIRED; - mtx_lock(&vm_mtx); if (wpipe->pipe_map.kva) { pmap_qremove(wpipe->pipe_map.kva, wpipe->pipe_map.npages); @@ -636,7 +635,6 @@ } for (i = 0; i < wpipe->pipe_map.npages; i++) vm_page_unwire(wpipe->pipe_map.ms[i], 1); - mtx_unlock(&vm_mtx); } /* @@ -1167,8 +1165,8 @@ pipe_free_kmem(cpipe) struct pipe *cpipe; { + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (cpipe->pipe_buffer.buffer != NULL) { if (cpipe->pipe_buffer.size > PIPE_SIZE) --nbigpipe; @@ -1228,13 +1226,11 @@ /* * free resources */ - mtx_lock(&vm_mtx); pipe_free_kmem(cpipe); /* XXX: erm, doesn't zalloc already have its own locks and * not need the giant vm lock? */ zfree(pipe_zone, cpipe); - mtx_unlock(&vm_mtx); } } Index: kern/sysv_shm.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sysv_shm.c,v retrieving revision 1.61 diff -u -r1.61 sysv_shm.c --- kern/sysv_shm.c 2001/05/30 03:28:59 1.61 +++ kern/sysv_shm.c 2001/07/04 02:54:15 @@ -187,7 +187,8 @@ struct shm_handle *shm_handle; size_t size; - mtx_assert(&vm_mtx, MA_OWNED); /* For vm_object_deallocate. */ + GIANT_REQUIRED; + shm_handle = shmseg->shm_internal; vm_object_deallocate(shm_handle->shm_object); free((caddr_t)shm_handle, M_SHM); @@ -207,8 +208,7 @@ int segnum, result; size_t size; - /* For vm_map_remove and shm_deallocate_segment. */ - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; segnum = IPCID_TO_IX(shmmap_s->shmid); shmseg = &shmsegs[segnum]; @@ -254,9 +254,7 @@ break; if (i == shminfo.shmseg) return EINVAL; - mtx_lock(&vm_mtx); error = shm_delete_mapping(p, shmmap_s); - mtx_unlock(&vm_mtx); return error; } @@ -282,6 +280,8 @@ vm_size_t size; int rv; + GIANT_REQUIRED; + if (!jail_sysvipc_allowed && jailed(p->p_ucred)) return (ENOSYS); @@ -334,17 +334,14 @@ } shm_handle = shmseg->shm_internal; - mtx_lock(&vm_mtx); vm_object_reference(shm_handle->shm_object); rv = vm_map_find(&p->p_vmspace->vm_map, shm_handle->shm_object, 0, &attach_va, size, (flags & MAP_FIXED)?0:1, prot, prot, 0); if (rv != KERN_SUCCESS) { - mtx_unlock(&vm_mtx); return ENOMEM; } vm_map_inherit(&p->p_vmspace->vm_map, attach_va, attach_va + size, VM_INHERIT_SHARE); - mtx_unlock(&vm_mtx); shmmap_s->va = attach_va; shmmap_s->shmid = uap->shmid; @@ -434,6 +431,8 @@ struct shmid_ds inbuf; struct shmid_ds *shmseg; + GIANT_REQUIRED; + if (!jail_sysvipc_allowed && jailed(p->p_ucred)) return (ENOSYS); @@ -470,9 +469,7 @@ shmseg->shm_perm.key = IPC_PRIVATE; shmseg->shm_perm.mode |= SHMSEG_REMOVED; if (shmseg->shm_nattch <= 0) { - mtx_lock(&vm_mtx); shm_deallocate_segment(shmseg); - mtx_unlock(&vm_mtx); shm_last_free = IPCID_TO_IX(uap->shmid); } break; @@ -539,6 +536,8 @@ struct shmid_ds *shmseg; struct shm_handle *shm_handle; + GIANT_REQUIRED; + if (uap->size < shminfo.shmmin || uap->size > shminfo.shmmax) return EINVAL; if (shm_nused >= shminfo.shmmni) /* Any shmids left? */ @@ -574,7 +573,6 @@ * We make sure that we have allocated a pager before we need * to. */ - mtx_lock(&vm_mtx); if (shm_use_phys) { shm_handle->shm_object = vm_pager_allocate(OBJT_PHYS, 0, size, VM_PROT_DEFAULT, 0); @@ -584,7 +582,6 @@ } vm_object_clear_flag(shm_handle->shm_object, OBJ_ONEMAPPING); vm_object_set_flag(shm_handle->shm_object, OBJ_NOSPLIT); - mtx_unlock(&vm_mtx); shmseg->shm_internal = shm_handle; shmseg->shm_perm.cuid = shmseg->shm_perm.uid = cred->cr_uid; @@ -679,8 +676,9 @@ { struct shmmap_state *shmmap_s; int i; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); /* For shm_delete_mapping. */ shmmap_s = (struct shmmap_state *)p->p_vmspace->vm_shm; for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) if (shmmap_s->shmid != -1) Index: kern/uipc_syscalls.c =================================================================== RCS file: /home/ncvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.94 diff -u -r1.94 uipc_syscalls.c --- kern/uipc_syscalls.c 2001/06/24 12:27:30 1.94 +++ kern/uipc_syscalls.c 2001/07/04 02:54:15 @@ -1489,8 +1489,9 @@ struct sf_buf *sf; struct vm_page *m; + GIANT_REQUIRED; + sf = dtosf(addr); - mtx_lock(&vm_mtx); pmap_qremove((vm_offset_t)addr, 1); m = sf->m; vm_page_unwire(m, 0); @@ -1501,7 +1502,6 @@ */ if (m->wire_count == 0 && m->object == NULL) vm_page_free(m); - mtx_unlock(&vm_mtx); sf->m = NULL; mtx_lock(&sf_freelist.sf_lock); SLIST_INSERT_HEAD(&sf_freelist.sf_head, sf, free_list); @@ -1536,6 +1536,8 @@ off_t off, xfsize, sbytes = 0; int error = 0, s; + GIANT_REQUIRED; + vp = NULL; /* * Do argument checking. Must be a regular file in, stream @@ -1646,19 +1648,16 @@ * * Wait and loop if busy. */ - mtx_lock(&vm_mtx); pg = vm_page_lookup(obj, pindex); if (pg == NULL) { pg = vm_page_alloc(obj, pindex, VM_ALLOC_NORMAL); if (pg == NULL) { VM_WAIT; - mtx_unlock(&vm_mtx); goto retry_lookup; } vm_page_wakeup(pg); } else if (vm_page_sleep_busy(pg, TRUE, "sfpbsy")) { - mtx_unlock(&vm_mtx); goto retry_lookup; } @@ -1683,7 +1682,6 @@ * completes. */ vm_page_io_start(pg); - mtx_unlock(&vm_mtx); /* * Get the page from backing store. @@ -1702,7 +1700,6 @@ error = VOP_READ(vp, &auio, IO_VMIO | ((MAXBSIZE / bsize) << 16), p->p_ucred); VOP_UNLOCK(vp, 0, p); - mtx_lock(&vm_mtx); vm_page_flag_clear(pg, PG_ZERO); vm_page_io_finish(pg); if (error) { @@ -1717,7 +1714,6 @@ vm_page_busy(pg); vm_page_free(pg); } - mtx_unlock(&vm_mtx); sbunlock(&so->so_snd); goto done; } @@ -1728,13 +1724,10 @@ * Get a sendfile buf. We usually wait as long as necessary, * but this wait can be interrupted. */ - mtx_unlock(&vm_mtx); if ((sf = sf_buf_alloc()) == NULL) { - mtx_lock(&vm_mtx); vm_page_unwire(pg, 0); if (pg->wire_count == 0 && pg->object == NULL) vm_page_free(pg); - mtx_unlock(&vm_mtx); sbunlock(&so->so_snd); error = EINTR; goto done; @@ -1744,10 +1737,8 @@ * Allocate a kernel virtual page and insert the physical page * into it. */ - mtx_lock(&vm_mtx); sf->m = pg; pmap_qenter(sf->kva, &pg, 1); - mtx_unlock(&vm_mtx); /* * Get an mbuf header and set it up as having external storage. */ Index: kern/vfs_bio.c =================================================================== RCS file: /home/ncvs/src/sys/kern/vfs_bio.c,v retrieving revision 1.282 diff -u -r1.282 vfs_bio.c --- kern/vfs_bio.c 2001/05/24 07:22:21 1.282 +++ kern/vfs_bio.c 2001/07/04 02:54:15 @@ -281,8 +281,6 @@ * Called when a buffer is extended. This function clears the B_CACHE * bit if the newly extended portion of the buffer does not contain * valid data. - * - * must be called with vm_mtx held */ static __inline__ void @@ -290,6 +288,8 @@ vm_ooffset_t foff, vm_offset_t off, vm_offset_t size, vm_page_t m) { + GIANT_REQUIRED; + if (bp->b_flags & B_CACHE) { int base = (foff + off) & PAGE_MASK; if (vm_page_is_valid(m, base, size) == 0) @@ -340,6 +340,8 @@ struct buf *bp; int i; + GIANT_REQUIRED; + TAILQ_INIT(&bswlist); LIST_INIT(&invalhash); mtx_init(&buftimelock, "buftime lock", MTX_DEF); @@ -428,14 +430,11 @@ * from buf_daemon. */ - mtx_lock(&vm_mtx); bogus_offset = kmem_alloc_pageable(kernel_map, PAGE_SIZE); bogus_page = vm_page_alloc(kernel_object, ((bogus_offset - VM_MIN_KERNEL_ADDRESS) >> PAGE_SHIFT), VM_ALLOC_NORMAL); cnt.v_wire_count++; - mtx_unlock(&vm_mtx); - } /* @@ -445,23 +444,19 @@ * buffer_map. * * Since this call frees up buffer space, we call bufspacewakeup(). - * - * Must be called without the vm_mtx. */ static void bfreekva(struct buf * bp) { + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_NOTOWNED); if (bp->b_kvasize) { ++buffreekvacnt; bufspace -= bp->b_kvasize; - mtx_lock(&vm_mtx); vm_map_delete(buffer_map, (vm_offset_t) bp->b_kvabase, (vm_offset_t) bp->b_kvabase + bp->b_kvasize ); - mtx_unlock(&vm_mtx); bp->b_kvasize = 0; bufspacewakeup(); } @@ -478,6 +473,8 @@ int s = splbio(); int old_qindex = bp->b_qindex; + GIANT_REQUIRED; + if (bp->b_qindex != QUEUE_NONE) { KASSERT(BUF_REFCNT(bp) == 1, ("bremfree: bp %p not locked",bp)); TAILQ_REMOVE(&bufqueues[bp->b_qindex], bp, b_freelist); @@ -789,6 +786,8 @@ void bdwrite(struct buf * bp) { + GIANT_REQUIRED; + if (BUF_REFCNT(bp) == 0) panic("bdwrite: buffer is not busy"); @@ -817,7 +816,6 @@ VOP_BMAP(bp->b_vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL, NULL); } - mtx_lock(&vm_mtx); /* * Set the *dirty* buffer range based upon the VM system dirty pages. */ @@ -831,7 +829,6 @@ * out on the next sync, or perhaps the cluster will be completed. */ vfs_clean_pages(bp); - mtx_unlock(&vm_mtx); bqrelse(bp); /* @@ -985,15 +982,14 @@ * Release a busy buffer and, if requested, free its resources. The * buffer will be stashed in the appropriate bufqueue[] allowing it * to be accessed later as a cache entity or reused for other purposes. - * - * vm_mtx must be not be held. */ void brelse(struct buf * bp) { int s; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_NOTOWNED); KASSERT(!(bp->b_flags & (B_CLUSTER|B_PAGING)), ("brelse: inappropriate B_PAGING or B_CLUSTER bp %p", bp)); s = splbio(); @@ -1103,7 +1099,6 @@ resid = bp->b_bufsize; foff = bp->b_offset; - mtx_lock(&vm_mtx); for (i = 0; i < bp->b_npages; i++) { int had_bogus = 0; @@ -1115,12 +1110,10 @@ * now. */ if (m == bogus_page) { - mtx_unlock(&vm_mtx); VOP_GETVOBJECT(vp, &obj); poff = OFF_TO_IDX(bp->b_offset); had_bogus = 1; - mtx_lock(&vm_mtx); for (j = i; j < bp->b_npages; j++) { vm_page_t mtmp; mtmp = bp->b_pages[j]; @@ -1154,14 +1147,11 @@ if (bp->b_flags & (B_INVAL | B_RELBUF)) vfs_vmio_release(bp); - mtx_unlock(&vm_mtx); } else if (bp->b_flags & B_VMIO) { if (bp->b_flags & (B_INVAL | B_RELBUF)) { - mtx_lock(&vm_mtx); vfs_vmio_release(bp); - mtx_unlock(&vm_mtx); } } @@ -1326,9 +1316,6 @@ splx(s); } -/* - * Must be called with vm_mtx held. - */ static void vfs_vmio_release(bp) struct buf *bp; @@ -1336,7 +1323,8 @@ int i; vm_page_t m; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + for (i = 0; i < bp->b_npages; i++) { m = bp->b_pages[i]; bp->b_pages[i] = NULL; @@ -1372,8 +1360,6 @@ } } pmap_qremove(trunc_page((vm_offset_t) bp->b_data), bp->b_npages); - - /* could drop vm_mtx here */ if (bp->b_bufsize) { bufspacewakeup(); @@ -1527,6 +1513,8 @@ int nqindex; static int flushingbufs; + GIANT_REQUIRED; + /* * We can't afford to block since we might be holding a vnode lock, * which may prevent system daemons from running. We deal with @@ -1646,9 +1634,7 @@ if (qindex == QUEUE_CLEAN) { if (bp->b_flags & B_VMIO) { bp->b_flags &= ~B_ASYNC; - mtx_lock(&vm_mtx); vfs_vmio_release(bp); - mtx_unlock(&vm_mtx); } if (bp->b_vp) brelvp(bp); @@ -1771,14 +1757,12 @@ bfreekva(bp); - mtx_lock(&vm_mtx); if (vm_map_findspace(buffer_map, vm_map_min(buffer_map), maxsize, &addr)) { /* * Uh oh. Buffer map is to fragmented. We * must defragment the map. */ - mtx_unlock(&vm_mtx); ++bufdefragcnt; defrag = 1; bp->b_flags |= B_INVAL; @@ -1795,7 +1779,6 @@ bufspace += bp->b_kvasize; ++bufreusecnt; } - mtx_unlock(&vm_mtx); } bp->b_data = bp->b_kvabase; } @@ -1961,6 +1944,8 @@ vm_page_t m; vm_ooffset_t off; + GIANT_REQUIRED; + if (incore(vp, blkno)) return 1; if (vp->v_mount == NULL) @@ -1973,7 +1958,6 @@ size = vp->v_mount->mnt_stat.f_iosize; off = (vm_ooffset_t)blkno * (vm_ooffset_t)vp->v_mount->mnt_stat.f_iosize; - mtx_lock(&vm_mtx); for (toff = 0; toff < vp->v_mount->mnt_stat.f_iosize; toff += tinc) { m = vm_page_lookup(obj, OFF_TO_IDX(off + toff)); if (!m) @@ -1985,11 +1969,9 @@ (vm_offset_t) ((toff + off) & PAGE_MASK), tinc) == 0) goto notinmem; } - mtx_unlock(&vm_mtx); return 1; notinmem: - mtx_unlock(&vm_mtx); return (0); } @@ -2003,8 +1985,6 @@ * * This routine is primarily used by NFS, but is generalized for the * B_VMIO case. - * - * Must be called with vm_mtx */ static void vfs_setdirty(struct buf *bp) @@ -2012,7 +1992,7 @@ int i; vm_object_t object; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; /* * Degenerate case - empty buffer */ @@ -2365,6 +2345,8 @@ int newbsize, mbsize; int i; + GIANT_REQUIRED; + if (BUF_REFCNT(bp) == 0) panic("allocbuf: buffer not busy"); @@ -2487,7 +2469,6 @@ * DEV_BSIZE aligned existing buffer size. Figure out * if we have to remove any pages. */ - mtx_lock(&vm_mtx); if (desiredpages < bp->b_npages) { for (i = desiredpages; i < bp->b_npages; i++) { /* @@ -2508,7 +2489,6 @@ (desiredpages << PAGE_SHIFT), (bp->b_npages - desiredpages)); bp->b_npages = desiredpages; } - mtx_unlock(&vm_mtx); } else if (size > bp->b_bcount) { /* * We are growing the buffer, possibly in a @@ -2529,7 +2509,6 @@ vp = bp->b_vp; VOP_GETVOBJECT(vp, &obj); - mtx_lock(&vm_mtx); while (bp->b_npages < desiredpages) { vm_page_t m; vm_pindex_t pi; @@ -2639,8 +2618,6 @@ bp->b_npages ); - mtx_unlock(&vm_mtx); - bp->b_data = (caddr_t)((vm_offset_t)bp->b_data | (vm_offset_t)(bp->b_offset & PAGE_MASK)); } @@ -2718,6 +2695,8 @@ int s, error; void (*biodone) __P((struct buf *)); + GIANT_REQUIRED; + s = splbio(); KASSERT(BUF_REFCNT(bp) > 0, ("biodone: bp %p not busy %d", bp, BUF_REFCNT(bp))); @@ -2778,7 +2757,6 @@ if (error) { panic("biodone: no object"); } - mtx_lock(&vm_mtx); #if defined(VFS_BIO_DEBUG) if (obj->paging_in_progress < bp->b_npages) { printf("biodone: paging in progress(%d) < bp->b_npages(%d)\n", @@ -2867,7 +2845,6 @@ } if (obj) vm_object_pip_wakeupn(obj, 0); - mtx_unlock(&vm_mtx); } /* @@ -2891,15 +2868,14 @@ * This routine is called in lieu of iodone in the case of * incomplete I/O. This keeps the busy status for pages * consistant. - * - * vm_mtx should not be held */ void vfs_unbusy_pages(struct buf * bp) { int i; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_NOTOWNED); runningbufwakeup(bp); if (bp->b_flags & B_VMIO) { struct vnode *vp = bp->b_vp; @@ -2907,7 +2883,6 @@ VOP_GETVOBJECT(vp, &obj); - mtx_lock(&vm_mtx); for (i = 0; i < bp->b_npages; i++) { vm_page_t m = bp->b_pages[i]; @@ -2924,7 +2899,6 @@ vm_page_io_finish(m); } vm_object_pip_wakeupn(obj, 0); - mtx_unlock(&vm_mtx); } } @@ -2935,15 +2909,13 @@ * range is restricted to the buffer's size. * * This routine is typically called after a read completes. - * - * vm_mtx should be held */ static void vfs_page_set_valid(struct buf *bp, vm_ooffset_t off, int pageno, vm_page_t m) { vm_ooffset_t soff, eoff; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; /* * Start and end offsets in buffer. eoff - soff may not cross a * page boundry or cross the end of the buffer. The end of the @@ -2979,15 +2951,14 @@ * Since I/O has not been initiated yet, certain buffer flags * such as BIO_ERROR or B_INVAL may be in an inconsistant state * and should be ignored. - * - * vm_mtx should not be held */ void vfs_busy_pages(struct buf * bp, int clear_modify) { int i, bogus; - mtx_assert(&vm_mtx, MA_NOTOWNED); + GIANT_REQUIRED; + if (bp->b_flags & B_VMIO) { struct vnode *vp = bp->b_vp; vm_object_t obj; @@ -2997,7 +2968,6 @@ foff = bp->b_offset; KASSERT(bp->b_offset != NOOFFSET, ("vfs_busy_pages: no buffer offset")); - mtx_lock(&vm_mtx); vfs_setdirty(bp); retry: @@ -3045,7 +3015,6 @@ } if (bogus) pmap_qenter(trunc_page((vm_offset_t)bp->b_data), bp->b_pages, bp->b_npages); - mtx_unlock(&vm_mtx); } } @@ -3056,15 +3025,14 @@ * * Note that while we only really need to clean through to b_bcount, we * just go ahead and clean through to b_bufsize. - * - * should be called with vm_mtx held */ static void vfs_clean_pages(struct buf * bp) { int i; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + if (bp->b_flags & B_VMIO) { vm_ooffset_t foff; @@ -3132,9 +3100,6 @@ * * Note that while we only theoretically need to clear through b_bcount, * we go ahead and clear through b_bufsize. - * - * We'll get vm_mtx here for safety if processing a VMIO buffer. - * I don't think vm_mtx is needed, but we're twiddling vm_page flags. */ void @@ -3142,8 +3107,9 @@ int i, mask = 0; caddr_t sa, ea; + GIANT_REQUIRED; + if ((bp->b_flags & (B_VMIO | B_MALLOC)) == B_VMIO) { - mtx_lock(&vm_mtx); bp->b_flags &= ~B_INVAL; bp->b_ioflags &= ~BIO_ERROR; if( (bp->b_npages == 1) && (bp->b_bufsize < PAGE_SIZE) && @@ -3155,7 +3121,6 @@ } bp->b_pages[0]->valid |= mask; bp->b_resid = 0; - mtx_unlock(&vm_mtx); return; } ea = sa = bp->b_data; @@ -3183,7 +3148,6 @@ vm_page_flag_clear(bp->b_pages[i], PG_ZERO); } bp->b_resid = 0; - mtx_unlock(&vm_mtx); } else { clrbuf(bp); } @@ -3193,8 +3157,6 @@ * vm_hold_load_pages and vm_hold_free_pages get pages into * a buffers address space. The pages are anonymous and are * not associated with a file object. - * - * vm_mtx should not be held */ static void vm_hold_load_pages(struct buf * bp, vm_offset_t from, vm_offset_t to) @@ -3203,16 +3165,14 @@ vm_page_t p; int index; - mtx_assert(&vm_mtx, MA_NOTOWNED); + GIANT_REQUIRED; + to = round_page(to); from = round_page(from); index = (from - trunc_page((vm_offset_t)bp->b_data)) >> PAGE_SHIFT; - mtx_lock(&vm_mtx); for (pg = from; pg < to; pg += PAGE_SIZE, index++) { - tryagain: - /* * note: must allocate system pages since blocking here * could intefere with paging I/O, no matter which @@ -3234,7 +3194,6 @@ vm_page_wakeup(p); } bp->b_npages = index; - mtx_unlock(&vm_mtx); } void @@ -3243,13 +3202,13 @@ vm_offset_t pg; vm_page_t p; int index, newnpages; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_NOTOWNED); from = round_page(from); to = round_page(to); newnpages = index = (from - trunc_page((vm_offset_t)bp->b_data)) >> PAGE_SHIFT; - mtx_lock(&vm_mtx); for (pg = from; pg < to; pg += PAGE_SIZE, index++) { p = bp->b_pages[index]; if (p && (index < bp->b_npages)) { @@ -3265,7 +3224,6 @@ } } bp->b_npages = newnpages; - mtx_unlock(&vm_mtx); } Index: kern/vfs_cluster.c =================================================================== RCS file: /home/ncvs/src/sys/kern/vfs_cluster.c,v retrieving revision 1.110 diff -u -r1.110 vfs_cluster.c --- kern/vfs_cluster.c 2001/05/24 07:22:23 1.110 +++ kern/vfs_cluster.c 2001/07/04 02:54:15 @@ -320,6 +320,8 @@ daddr_t bn; int i, inc, j; + GIANT_REQUIRED; + KASSERT(size == vp->v_mount->mnt_stat.f_iosize, ("cluster_rbuild: size %ld != filesize %ld\n", size, vp->v_mount->mnt_stat.f_iosize)); @@ -433,7 +435,6 @@ BUF_KERNPROC(tbp); TAILQ_INSERT_TAIL(&bp->b_cluster.cluster_head, tbp, b_cluster.cluster_entry); - mtx_lock(&vm_mtx); for (j = 0; j < tbp->b_npages; j += 1) { vm_page_t m; m = tbp->b_pages[j]; @@ -447,12 +448,10 @@ if ((m->valid & VM_PAGE_BITS_ALL) == VM_PAGE_BITS_ALL) tbp->b_pages[j] = bogus_page; } - mtx_unlock(&vm_mtx); bp->b_bcount += tbp->b_bcount; bp->b_bufsize += tbp->b_bufsize; } - mtx_lock(&vm_mtx); for(j=0;jb_npages;j++) { if ((bp->b_pages[j]->valid & VM_PAGE_BITS_ALL) == VM_PAGE_BITS_ALL) @@ -465,7 +464,6 @@ pmap_qenter(trunc_page((vm_offset_t) bp->b_data), (vm_page_t *)bp->b_pages, bp->b_npages); - mtx_unlock(&vm_mtx); return (bp); } @@ -482,15 +480,15 @@ struct buf *nbp, *tbp; int error = 0; + GIANT_REQUIRED; + /* * Must propogate errors to all the components. */ if (bp->b_ioflags & BIO_ERROR) error = bp->b_error; - mtx_lock(&vm_mtx); pmap_qremove(trunc_page((vm_offset_t) bp->b_data), bp->b_npages); - mtx_unlock(&vm_mtx); /* * Move memory from the large cluster buffer into the component * buffers and mark IO as done on these. @@ -724,6 +722,8 @@ int totalwritten = 0; int dbsize = btodb(size); + GIANT_REQUIRED; + while (len > 0) { s = splbio(); /* @@ -866,7 +866,6 @@ } } - mtx_lock(&vm_mtx); for (j = 0; j < tbp->b_npages; j += 1) { m = tbp->b_pages[j]; vm_page_io_start(m); @@ -877,7 +876,6 @@ bp->b_npages++; } } - mtx_unlock(&vm_mtx); } bp->b_bcount += size; bp->b_bufsize += size; @@ -896,10 +894,8 @@ tbp, b_cluster.cluster_entry); } finishcluster: - mtx_lock(&vm_mtx); pmap_qenter(trunc_page((vm_offset_t) bp->b_data), (vm_page_t *) bp->b_pages, bp->b_npages); - mtx_unlock(&vm_mtx); if (bp->b_bufsize > bp->b_kvasize) panic( "cluster_wbuild: b_bufsize(%ld) > b_kvasize(%d)\n", Index: kern/vfs_default.c =================================================================== RCS file: /home/ncvs/src/sys/kern/vfs_default.c,v retrieving revision 1.53 diff -u -r1.53 vfs_default.c --- kern/vfs_default.c 2001/05/23 19:51:12 1.53 +++ kern/vfs_default.c 2001/07/04 02:54:15 @@ -527,6 +527,8 @@ vm_object_t object; int error = 0; + GIANT_REQUIRED; + if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE) return (0); @@ -535,7 +537,6 @@ if (vp->v_type == VREG || vp->v_type == VDIR) { if ((error = VOP_GETATTR(vp, &vat, cred, p)) != 0) goto retn; - mtx_lock(&vm_mtx); object = vnode_pager_alloc(vp, vat.va_size, 0, 0); } else if (devsw(vp->v_rdev) != NULL) { /* @@ -543,7 +544,6 @@ * for a disk vnode. This should be fixed, but doesn't * cause any problems (yet). */ - mtx_lock(&vm_mtx); object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0); } else { goto retn; @@ -553,21 +553,14 @@ * that the object is associated with the vp. */ object->ref_count--; - mtx_unlock(&vm_mtx); vp->v_usecount--; } else { - /* - * XXX: safe to hold vm mutex through VOP_UNLOCK? - */ - mtx_lock(&vm_mtx); if (object->flags & OBJ_DEAD) { VOP_UNLOCK(vp, 0, p); - msleep(object, VM_OBJECT_MTX(object), PVM, "vodead", 0); - mtx_unlock(&vm_mtx); + tsleep(object, PVM, "vodead", 0); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); goto retry; } - mtx_unlock(&vm_mtx); } KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object")); @@ -586,10 +579,11 @@ struct vnode *vp = ap->a_vp; vm_object_t obj = vp->v_object; + GIANT_REQUIRED; + if (vp->v_object == NULL) return (0); - mtx_lock(&vm_mtx); if (obj->ref_count == 0) { /* * vclean() may be called twice. The first time @@ -604,7 +598,6 @@ */ vm_pager_deallocate(obj); } - mtx_unlock(&vm_mtx); return (0); } Index: kern/vfs_subr.c =================================================================== RCS file: /home/ncvs/src/sys/kern/vfs_subr.c,v retrieving revision 1.314 diff -u -r1.314 vfs_subr.c --- kern/vfs_subr.c 2001/06/28 04:05:54 1.314 +++ kern/vfs_subr.c 2001/07/04 02:54:15 @@ -711,7 +711,7 @@ int s, error; vm_object_t object; - mtx_assert(&vm_mtx, MA_NOTOWNED); + GIANT_REQUIRED; if (flags & V_SAVE) { s = splbio(); @@ -799,10 +799,8 @@ */ mtx_lock(&vp->v_interlock); if (VOP_GETVOBJECT(vp, &object) == 0) { - mtx_lock(&vm_mtx); vm_object_page_remove(object, 0, 0, (flags & V_SAVE) ? TRUE : FALSE); - mtx_unlock(&vm_mtx); } mtx_unlock(&vp->v_interlock); @@ -1136,8 +1134,6 @@ * Also sets B_PAGING flag to indicate that vnode is not fully associated * with the buffer. i.e. the bp has not been linked into the vnode or * ref-counted. - * - * Doesn't block, only vnode seems to need a lock. */ void pbgetvp(vp, bp) @@ -1559,8 +1555,9 @@ struct vnode *vp; { struct proc *p = curproc; /* XXX */ + + GIANT_REQUIRED; - mtx_assert(&Giant, MA_OWNED); KASSERT(vp != NULL, ("vput: null vp")); mtx_lock(&vp->v_interlock); /* Skip this v_writecount check if we're going to panic below. */ @@ -2363,6 +2360,8 @@ struct vm_object *obj; int anyio, tries; + GIANT_REQUIRED; + tries = 5; loop: anyio = 0; @@ -2394,11 +2393,9 @@ if (!vget(vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) { if (VOP_GETVOBJECT(vp, &obj) == 0) { - mtx_lock(&vm_mtx); vm_object_page_clean(obj, 0, 0, flags == MNT_WAIT ? OBJPC_SYNC : OBJPC_NOSYNC); - mtx_unlock(&vm_mtx); anyio = 1; } vput(vp); @@ -2427,8 +2424,7 @@ struct proc *p; struct ucred *cred; { - - mtx_assert(&vm_mtx, MA_NOTOWNED); + GIANT_REQUIRED; return (VOP_CREATEVOBJECT(vp, cred, p)); } Index: kern/vfs_syscalls.c =================================================================== RCS file: /home/ncvs/src/sys/kern/vfs_syscalls.c,v retrieving revision 1.194 diff -u -r1.194 vfs_syscalls.c --- kern/vfs_syscalls.c 2001/06/06 23:34:38 1.194 +++ kern/vfs_syscalls.c 2001/07/04 02:54:15 @@ -2763,6 +2763,8 @@ vm_object_t obj; int error; + GIANT_REQUIRED; + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) return (error); vp = (struct vnode *)fp->f_data; @@ -2770,9 +2772,7 @@ return (error); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); if (VOP_GETVOBJECT(vp, &obj) == 0) { - mtx_lock(&vm_mtx); vm_object_page_clean(obj, 0, 0, 0); - mtx_unlock(&vm_mtx); } error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, p); #ifdef SOFTUPDATES Index: nfs/nfs_bio.c =================================================================== RCS file: /home/ncvs/src/sys/nfs/nfs_bio.c,v retrieving revision 1.95 diff -u -r1.95 nfs_bio.c --- nfs/nfs_bio.c 2001/05/23 22:26:05 1.95 +++ nfs/nfs_bio.c 2001/07/04 02:54:16 @@ -111,6 +111,8 @@ struct nfsmount *nmp; vm_page_t *pages; + GIANT_REQUIRED; + vp = ap->a_vp; p = curproc; /* XXX */ cred = curproc->p_ucred; /* XXX */ @@ -118,7 +120,6 @@ pages = ap->a_m; count = ap->a_count; - mtx_assert(&Giant, MA_OWNED); if (vp->v_object == NULL) { printf("nfs_getpages: called with non-merged cache vnode??\n"); return VM_PAGER_ERROR; @@ -126,9 +127,7 @@ if ((nmp->nm_flag & NFSMNT_NFSV3) != 0 && (nmp->nm_state & NFSSTA_GOTFSINFO) == 0) { - mtx_unlock(&vm_mtx); (void)nfs_fsinfo(nmp, vp, cred, p); - mtx_lock(&vm_mtx); } npages = btoc(count); @@ -172,9 +171,7 @@ uio.uio_rw = UIO_READ; uio.uio_procp = p; - mtx_unlock(&vm_mtx); error = nfs_readrpc(vp, &uio, cred); - mtx_lock(&vm_mtx); pmap_qremove(kva, npages); relpbuf(bp, &nfs_pbuf_freecnt); @@ -274,6 +271,8 @@ struct nfsnode *np; vm_page_t *pages; + GIANT_REQUIRED; + vp = ap->a_vp; np = VTONFS(vp); p = curproc; /* XXX */ @@ -285,12 +284,11 @@ npages = btoc(count); offset = IDX_TO_OFF(pages[0]->pindex); - mtx_assert(&Giant, MA_OWNED); + GIANT_REQUIRED; + if ((nmp->nm_flag & NFSMNT_NFSV3) != 0 && (nmp->nm_state & NFSSTA_GOTFSINFO) == 0) { - mtx_unlock(&vm_mtx); (void)nfs_fsinfo(nmp, vp, cred, p); - mtx_lock(&vm_mtx); } for (i = 0; i < npages; i++) { @@ -331,9 +329,7 @@ else iomode = NFSV3WRITE_FILESYNC; - mtx_unlock(&vm_mtx); error = nfs_writerpc(vp, &uio, cred, &iomode, &must_commit); - mtx_lock(&vm_mtx); pmap_qremove(kva, npages); relpbuf(bp, &nfs_pbuf_freecnt); @@ -345,9 +341,7 @@ vm_page_undirty(pages[i]); } if (must_commit) { - mtx_unlock(&vm_mtx); nfs_clearcommit(vp->v_mount); - mtx_lock(&vm_mtx); } } return rtvals[0]; @@ -770,6 +764,8 @@ int n, on, error = 0, iomode, must_commit; int haverslock = 0; + GIANT_REQUIRED; + #ifdef DIAGNOSTIC if (uio->uio_rw != UIO_WRITE) panic("nfs_write mode"); @@ -1091,9 +1087,7 @@ bp->b_dirtyoff = on; bp->b_dirtyend = on + n; } - mtx_lock(&vm_mtx); vfs_bio_set_validclean(bp, on, n); - mtx_unlock(&vm_mtx); } /* Index: nfs/nfs_subs.c =================================================================== RCS file: /home/ncvs/src/sys/nfs/nfs_subs.c,v retrieving revision 1.102 diff -u -r1.102 nfs_subs.c --- nfs/nfs_subs.c 2001/06/28 04:08:20 1.102 +++ nfs/nfs_subs.c 2001/07/04 02:54:16 @@ -2138,9 +2138,9 @@ register struct buf *bp, *nbp; int s; + GIANT_REQUIRED; + s = splbio(); - mtx_assert(&Giant, MA_OWNED); - mtx_assert(&vm_mtx, MA_NOTOWNED); mtx_lock(&mntvnode_mtx); loop: for (vp = LIST_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) { Index: pc98/i386/machdep.c =================================================================== RCS file: /home/ncvs/src/sys/pc98/i386/machdep.c,v retrieving revision 1.224 diff -u -r1.224 machdep.c --- pc98/i386/machdep.c 2001/06/29 11:10:37 1.224 +++ pc98/i386/machdep.c 2001/07/04 02:54:16 @@ -276,7 +276,6 @@ /* * Good {morning,afternoon,evening,night}. */ - mtx_lock(&vm_mtx); earlysetcpuclass(); startrtclock(); printcpuinfo(); @@ -410,7 +409,6 @@ exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (16*(ARG_MAX+(PAGE_SIZE*3)))); - mtx_unlock(&vm_mtx); /* * XXX: Mbuf system machine-specific initializations should * go here, if anywhere. @@ -2116,6 +2114,8 @@ if (!has_f00f_bug) return; + GIANT_REQUIRED; + printf("Intel Pentium detected, installing workaround for F00F bug\n"); r_idt.rd_limit = sizeof(idt0) - 1; @@ -2131,11 +2131,9 @@ r_idt.rd_base = (int)new_idt; lidt(&r_idt); idt = new_idt; - mtx_lock(&vm_mtx); if (vm_map_protect(kernel_map, tmp, tmp + PAGE_SIZE, VM_PROT_READ, FALSE) != KERN_SUCCESS) panic("vm_map_protect failed"); - mtx_unlock(&vm_mtx); return; } #endif /* defined(I586_CPU) && !NO_F00F_HACK */ Index: pc98/pc98/isa_dma.c =================================================================== RCS file: /home/ncvs/src/sys/pc98/pc98/isa_dma.c,v retrieving revision 1.10 diff -u -r1.10 isa_dma.c --- pc98/pc98/isa_dma.c 2001/06/30 05:29:09 1.10 +++ pc98/pc98/isa_dma.c 2001/07/04 02:54:16 @@ -249,6 +249,8 @@ int waport; caddr_t newaddr; + GIANT_REQUIRED; + #ifdef DIAGNOSTIC if (chan & ~VALID_DMA_MASK) panic("isa_dmastart: channel out of range"); @@ -287,12 +289,7 @@ } /* translate to physical */ - mtx_lock(&vm_mtx); /* - * XXX: need to hold for longer period to - * ensure that mappings don't change - */ phys = pmap_extract(pmap_kernel(), (vm_offset_t)addr); - mtx_unlock(&vm_mtx); if (flags & ISADMA_RAW) { dma_auto_mode |= (1 << chan); @@ -438,11 +435,11 @@ vm_offset_t phys, priorpage = 0, endva; u_int dma_pgmsk = (chan & 4) ? ~(128*1024-1) : ~(64*1024-1); + GIANT_REQUIRED; + endva = (vm_offset_t)round_page((vm_offset_t)va + length); for (; va < (caddr_t) endva ; va += PAGE_SIZE) { - mtx_lock(&vm_mtx); phys = trunc_page(pmap_extract(pmap_kernel(), (vm_offset_t)va)); - mtx_unlock(&vm_mtx); #ifdef EPSON_BOUNCEDMA #define ISARAM_END 0xf00000 #else Index: sys/mutex.h =================================================================== RCS file: /home/ncvs/src/sys/sys/mutex.h,v retrieving revision 1.31 diff -u -r1.31 mutex.h --- sys/mutex.h 2001/05/04 17:15:16 1.31 +++ sys/mutex.h 2001/07/04 02:54:16 @@ -372,8 +372,34 @@ #define mtx_assert(m, what) \ _mtx_assert((m), (what), __FILE__, __LINE__) +/* + * GIANT_REQUIRED; - place at the beginning of a procedure + * + * + */ + +#define GIANT_REQUIRED \ + do { \ + KASSERT(curproc->p_giant_optional == 0, ("Giant not optional at %s: %d", __FILE__, __LINE__)); \ + mtx_assert(&Giant, MA_OWNED); \ + } while(0) +#define START_GIANT_DEPRECIATED(sysctlvar) \ + int __gotgiant = (curproc->p_giant_optional == 0 && sysctlvar) ? \ + (mtx_lock(&Giant), 1) : 0 +#define END_GIANT_DEPRECIATED \ + if (__gotgiant) mtx_unlock(&Giant) +#define START_GIANT_OPTIONAL \ + ++curproc->p_giant_optional +#define END_GIANT_OPTIONAL \ + --curproc->p_giant_optional + #else /* INVARIANTS */ #define mtx_assert(m, what) +#define GIANT_REQUIRED +#define START_GIANT_DEPRECIATED(sysctl) +#define END_GIANT_DEPRECIATED +#define START_GIANT_OPTIONAL +#define END_GIANT_OPTIONAL #endif /* INVARIANTS */ #endif /* _KERNEL */ Index: sys/proc.h =================================================================== RCS file: /home/ncvs/src/sys/sys/proc.h,v retrieving revision 1.169 diff -u -r1.169 proc.h --- sys/proc.h 2001/06/30 03:35:22 1.169 +++ sys/proc.h 2001/07/04 02:54:16 @@ -276,6 +276,7 @@ struct pasleep p_asleep; /* (k) Used by asleep()/await(). */ void *p_emuldata; /* (c) Emulator state data. */ struct trapframe *p_frame; /* (k) */ + int p_giant_optional; /* (i) Giant Lock Sanity */ }; #define p_session p_pgrp->pg_session Index: ufs/ufs/ufs_readwrite.c =================================================================== RCS file: /home/ncvs/src/sys/ufs/ufs/ufs_readwrite.c,v retrieving revision 1.80 diff -u -r1.80 ufs_readwrite.c --- ufs/ufs/ufs_readwrite.c 2001/05/24 07:22:27 1.80 +++ ufs/ufs/ufs_readwrite.c 2001/07/04 02:54:16 @@ -80,6 +80,8 @@ int ioflag; vm_object_t object; + GIANT_REQUIRED; + vp = ap->a_vp; seqcount = ap->a_ioflag >> 16; ip = VTOI(vp); @@ -115,9 +117,7 @@ } if (object) { - mtx_lock(&vm_mtx); vm_object_reference(object); - mtx_unlock(&vm_mtx); } #ifdef ENABLE_VFS_IOOPT @@ -151,9 +151,7 @@ ip->i_flag |= IN_ACCESS; if (object) { - mtx_lock(&vm_mtx); vm_object_vndeallocate(object); - mtx_unlock(&vm_mtx); } return error; } @@ -199,9 +197,7 @@ MNT_NOATIME) == 0) ip->i_flag |= IN_ACCESS; if (object) { - mtx_lock(&vm_mtx); vm_object_vndeallocate(object); - mtx_unlock(&vm_mtx); } return error; } @@ -374,9 +370,7 @@ } if (object) { - mtx_lock(&vm_mtx); vm_object_vndeallocate(object); - mtx_unlock(&vm_mtx); } if ((error == 0 || uio->uio_resid != orig_resid) && (vp->v_mount->mnt_flag & MNT_NOATIME) == 0) @@ -408,6 +402,8 @@ int blkoffset, error, extended, flags, ioflag, resid, size, xfersize; vm_object_t object; + GIANT_REQUIRED; + extended = 0; seqcount = ap->a_ioflag >> 16; ioflag = ap->a_ioflag; @@ -417,9 +413,7 @@ object = vp->v_object; if (object) { - mtx_lock(&vm_mtx); vm_object_reference(object); - mtx_unlock(&vm_mtx); } #ifdef DIAGNOSTIC @@ -433,9 +427,7 @@ uio->uio_offset = ip->i_size; if ((ip->i_flags & APPEND) && uio->uio_offset != ip->i_size) { if (object) { - mtx_lock(&vm_mtx); vm_object_vndeallocate(object); - mtx_unlock(&vm_mtx); } return (EPERM); } @@ -456,9 +448,7 @@ if (uio->uio_offset < 0 || (u_int64_t)uio->uio_offset + uio->uio_resid > fs->fs_maxfilesize) { if (object) { - mtx_lock(&vm_mtx); vm_object_vndeallocate(object); - mtx_unlock(&vm_mtx); } return (EFBIG); } @@ -474,9 +464,7 @@ psignal(p, SIGXFSZ); PROC_UNLOCK(p); if (object) { - mtx_lock(&vm_mtx); vm_object_vndeallocate(object); - mtx_unlock(&vm_mtx); } return (EFBIG); } @@ -488,11 +476,9 @@ flags = B_SYNC; if (object && (object->flags & OBJ_OPT)) { - mtx_lock(&vm_mtx); vm_freeze_copyopts(object, OFF_TO_IDX(uio->uio_offset), OFF_TO_IDX(uio->uio_offset + uio->uio_resid + PAGE_MASK)); - mtx_unlock(&vm_mtx); } for (error = 0; uio->uio_resid > 0;) { @@ -595,9 +581,7 @@ error = UFS_UPDATE(vp, 1); if (object) { - mtx_lock(&vm_mtx); vm_object_vndeallocate(object); - mtx_unlock(&vm_mtx); } return (error); @@ -627,6 +611,7 @@ int rtval; int pagesperblock; + GIANT_REQUIRED; pcount = round_page(ap->a_count) / PAGE_SIZE; mreq = ap->a_m[ap->a_reqpage]; @@ -668,16 +653,9 @@ reqlblkno = foff / bsize; poff = (foff % bsize) / PAGE_SIZE; - mtx_unlock(&vm_mtx); - mtx_lock(&Giant); - dp = VTOI(vp)->i_devvp; if (ufs_bmaparray(vp, reqlblkno, &reqblkno, &bforwards, &bbackwards) || (reqblkno == -1)) { - - mtx_unlock(&Giant); - mtx_lock(&vm_mtx); - for(i = 0; i < pcount; i++) { if (i != ap->a_reqpage) vm_page_free(ap->a_m[i]); @@ -692,9 +670,6 @@ return VM_PAGER_ERROR; } } - - mtx_unlock(&Giant); - mtx_lock(&vm_mtx); physoffset = (off_t)reqblkno * DEV_BSIZE + poff * PAGE_SIZE; pagesperblock = bsize / PAGE_SIZE; Index: vm/default_pager.c =================================================================== RCS file: /home/ncvs/src/sys/vm/default_pager.c,v retrieving revision 1.27 diff -u -r1.27 default_pager.c --- vm/default_pager.c 2001/05/19 01:28:08 1.27 +++ vm/default_pager.c 2001/07/04 02:54:16 @@ -42,6 +42,7 @@ #include #include #include +#include #include #include Index: vm/device_pager.c =================================================================== RCS file: /home/ncvs/src/sys/vm/device_pager.c,v retrieving revision 1.51 diff -u -r1.51 device_pager.c --- vm/device_pager.c 2001/05/23 22:27:52 1.51 +++ vm/device_pager.c 2001/07/04 02:54:16 @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include Index: vm/phys_pager.c =================================================================== RCS file: /home/ncvs/src/sys/vm/phys_pager.c,v retrieving revision 1.9 diff -u -r1.9 phys_pager.c --- vm/phys_pager.c 2001/05/23 19:52:23 1.9 +++ vm/phys_pager.c 2001/07/04 02:54:16 @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,8 @@ { vm_object_t object; + GIANT_REQUIRED; + /* * Offset should be page aligned. */ @@ -76,7 +79,7 @@ */ while (phys_pager_alloc_lock) { phys_pager_alloc_lock = -1; - msleep(&phys_pager_alloc_lock, &vm_mtx, PVM, "swpalc", 0); + tsleep(&phys_pager_alloc_lock, PVM, "swpalc", 0); } phys_pager_alloc_lock = 1; Index: vm/swap_pager.c =================================================================== RCS file: /home/ncvs/src/sys/vm/swap_pager.c,v retrieving revision 1.159 diff -u -r1.159 swap_pager.c --- vm/swap_pager.c 2001/06/22 21:12:19 1.159 +++ vm/swap_pager.c 2001/07/04 02:54:17 @@ -80,6 +80,7 @@ #include #include #include +#include #include #ifndef MAX_PAGEOUT_CLUSTER @@ -118,12 +119,12 @@ static int nsw_wcount_async; /* limit write buffers / asynchronous */ static int nsw_wcount_async_max;/* assigned maximum */ static int nsw_cluster_max; /* maximum VOP I/O allowed */ -static int sw_alloc_interlock; /* swap pager allocation interlock */ struct blist *swapblist; static struct swblock **swhash; static int swhash_mask; static int swap_async_max = 4; /* maximum in-progress async I/O's */ +static struct sx sw_alloc_sx; /* from vm_swap.c */ extern struct vnode *swapdev_vp; @@ -232,8 +233,8 @@ static __inline void swp_sizecheck() { + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (vm_swap_size < nswap_lowat) { if (swap_pager_almost_full == 0) { printf("swap_pager: out of swap space\n"); @@ -383,7 +384,8 @@ { vm_object_t object; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + if (handle) { /* * Reference existing named region or allocate new one. There @@ -391,13 +393,7 @@ * as called from vm_page_remove() in regards to the lookup * of the handle. */ - - while (sw_alloc_interlock) { - sw_alloc_interlock = -1; - msleep(&sw_alloc_interlock, &vm_mtx, PVM, "swpalc", 0); - } - sw_alloc_interlock = 1; - + sx_xlock(&sw_alloc_sx); object = vm_pager_object_lookup(NOBJLIST(handle), handle); if (object != NULL) { @@ -409,10 +405,7 @@ swp_pager_meta_build(object, 0, SWAPBLK_NONE); } - - if (sw_alloc_interlock == -1) - wakeup(&sw_alloc_interlock); - sw_alloc_interlock = 0; + sx_xunlock(&sw_alloc_sx); } else { object = vm_object_allocate(OBJT_DEFAULT, OFF_TO_IDX(offset + PAGE_MASK + size)); @@ -441,13 +434,13 @@ vm_object_t object; { int s; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); /* * Remove from list right away so lookups will fail if we block for * pageout completion. */ - mtx_lock(&sw_alloc_mtx); if (object->handle == NULL) { TAILQ_REMOVE(&swap_pager_un_object_list, object, pager_object_list); @@ -488,7 +481,6 @@ * * This routine may not block * This routine must be called at splvm(). - * vm_mtx should be held */ static __inline daddr_t @@ -496,8 +488,9 @@ int npages; { daddr_t blk; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if ((blk = blist_alloc(swapblist, npages)) == SWAPBLK_NONE) { if (swap_pager_full != 2) { printf("swap_pager_getswapspace: failed\n"); @@ -526,7 +519,6 @@ * * This routine may not block * This routine must be called at splvm(). - * vm_mtx should be held */ static __inline void @@ -534,8 +526,8 @@ daddr_t blk; int npages; { + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); blist_free(swapblist, blk, npages); vm_swap_size += npages; /* per-swap area stats */ @@ -566,9 +558,8 @@ vm_size_t size; { int s = splvm(); - - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; swp_pager_meta_free(object, start, size); splx(s); } @@ -650,11 +641,10 @@ { vm_pindex_t i; int s; - - s = splvm(); - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + s = splvm(); /* * If destroysource is set, we remove the source object from the * swap_pager internal queue now. @@ -870,9 +860,9 @@ int s; char *data; struct buf *nbp = NULL; + + GIANT_REQUIRED; - mtx_assert(&Giant, MA_OWNED); - mtx_assert(&vm_mtx, MA_NOTOWNED); /* XXX: KASSERT instead ? */ if (bp->bio_bcount & PAGE_MASK) { biofinish(bp, NULL, EINVAL); @@ -903,9 +893,7 @@ * FREE PAGE(s) - destroy underlying swap that is no longer * needed. */ - mtx_lock(&vm_mtx); swp_pager_meta_free(object, start, count); - mtx_unlock(&vm_mtx); splx(s); bp->bio_resid = 0; biodone(bp); @@ -915,8 +903,6 @@ /* * Execute read or write */ - - mtx_lock(&vm_mtx); while (count > 0) { daddr_t blk; @@ -959,9 +945,7 @@ cnt.v_swappgsout += btoc(nbp->b_bcount); nbp->b_dirtyend = nbp->b_bcount; } - mtx_unlock(&vm_mtx); flushchainbuf(nbp); - mtx_lock(&vm_mtx); s = splvm(); nbp = NULL; } @@ -981,9 +965,7 @@ bp->bio_resid -= PAGE_SIZE; } else { if (nbp == NULL) { - mtx_unlock(&vm_mtx); nbp = getchainbuf(bp, swapdev_vp, B_ASYNC); - mtx_lock(&vm_mtx); nbp->b_blkno = blk; nbp->b_bcount = 0; nbp->b_data = data; @@ -1010,11 +992,9 @@ cnt.v_swappgsout += btoc(nbp->b_bcount); nbp->b_dirtyend = nbp->b_bcount; } - mtx_unlock(&vm_mtx); flushchainbuf(nbp); /* nbp = NULL; */ - } else - mtx_unlock(&vm_mtx); + } /* * Wait for completion. */ @@ -1056,8 +1036,9 @@ daddr_t blk; vm_offset_t kva; vm_pindex_t lastpindex; + + GIANT_REQUIRED; - mtx_assert(&Giant, MA_OWNED); mreq = m[reqpage]; if (mreq->object != object) { @@ -1185,10 +1166,8 @@ * * NOTE: b_blkno is destroyed by the call to VOP_STRATEGY */ - mtx_unlock(&vm_mtx); BUF_KERNPROC(bp); BUF_STRATEGY(bp); - mtx_lock(&vm_mtx); /* * wait for the page we want to complete. PG_SWAPINPROG is always @@ -1201,7 +1180,7 @@ while ((mreq->flags & PG_SWAPINPROG) != 0) { vm_page_flag_set(mreq, PG_WANTED | PG_REFERENCED); cnt.v_intrans++; - if (msleep(mreq, &vm_mtx, PSWP, "swread", hz*20)) { + if (tsleep(mreq, PSWP, "swread", hz*20)) { printf( "swap_pager: indefinite wait buffer: device:" " %s, blkno: %ld, size: %ld\n", @@ -1267,7 +1246,7 @@ int i; int n = 0; - mtx_assert(&Giant, MA_OWNED); + GIANT_REQUIRED; if (count && m[0]->object != object) { panic("swap_pager_getpages: object mismatch %p/%p", object, @@ -1432,7 +1411,6 @@ swapdev_vp->v_numoutput++; splx(s); - mtx_unlock(&vm_mtx); /* * asynchronous @@ -1444,7 +1422,6 @@ bp->b_iodone = swp_pager_async_iodone; BUF_KERNPROC(bp); BUF_STRATEGY(bp); - mtx_lock(&vm_mtx); for (j = 0; j < n; ++j) rtvals[i+j] = VM_PAGER_PEND; @@ -1482,8 +1459,6 @@ */ swp_pager_async_iodone(bp); - mtx_lock(&vm_mtx); - splx(s); } } @@ -1533,7 +1508,8 @@ int i; vm_object_t object = NULL; - mtx_assert(&vm_mtx, MA_NOTOWNED); + GIANT_REQUIRED; + bp->b_flags |= B_DONE; /* @@ -1562,7 +1538,6 @@ /* * remove the mapping for kernel virtual */ - mtx_lock(&vm_mtx); pmap_qremove((vm_offset_t)bp->b_data, bp->b_npages); /* @@ -1697,7 +1672,6 @@ if (object) vm_object_pip_wakeupn(object, bp->b_npages); - mtx_unlock(&vm_mtx); /* * release the physical I/O buffer */ @@ -1771,8 +1745,6 @@ * * This routine must be called at splvm(), except when used to convert * an OBJT_DEFAULT object into an OBJT_SWAP object. - * - * Requires vm_mtx. */ static void @@ -1784,7 +1756,7 @@ struct swblock *swap; struct swblock **pswap; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; /* * Convert default object to swap object if necessary */ @@ -1871,15 +1843,13 @@ * out. This routine does *NOT* operate on swap metadata associated * with resident pages. * - * vm_mtx must be held * This routine must be called at splvm() */ static void swp_pager_meta_free(vm_object_t object, vm_pindex_t index, daddr_t count) { - - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (object->type != OBJT_SWAP) return; @@ -1920,7 +1890,6 @@ * an object. * * This routine must be called at splvm() - * Requires vm_mtx. */ static void @@ -1928,7 +1897,7 @@ { daddr_t index = 0; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (object->type != OBJT_SWAP) return; @@ -1978,7 +1947,6 @@ * busy page. * * This routine must be called at splvm(). - * Requires vm_mtx. * * SWM_FREE remove and free swap block from metadata * SWM_POP remove from meta data but do not free.. pop it out @@ -1994,7 +1962,7 @@ struct swblock *swap; daddr_t r1; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; /* * The meta data only exists of the object is OBJT_SWAP * and even then might not be allocated yet. @@ -2082,8 +2050,6 @@ * Obtain a physical buffer and chain it to its parent buffer. When * I/O completes, the parent buffer will be B_SIGNAL'd. Errors are * automatically propagated to the parent - * - * vm_mtx can't be held */ struct buf * @@ -2092,8 +2058,7 @@ struct buf *nbp; u_int *count; - mtx_assert(&vm_mtx, MA_NOTOWNED); - mtx_assert(&Giant, MA_OWNED); + GIANT_REQUIRED; nbp = getpbuf(NULL); count = (u_int *)&(bp->bio_caller1); @@ -2120,9 +2085,7 @@ void flushchainbuf(struct buf *nbp) { - - mtx_assert(&vm_mtx, MA_NOTOWNED); - mtx_assert(&Giant, MA_OWNED); + GIANT_REQUIRED; if (nbp->b_bcount) { nbp->b_bufsize = nbp->b_bcount; if (nbp->b_iocmd == BIO_WRITE) @@ -2140,8 +2103,7 @@ int s; u_int *count; - mtx_assert(&vm_mtx, MA_NOTOWNED); - mtx_assert(&Giant, MA_OWNED); + GIANT_REQUIRED; count = (u_int *)&(bp->bio_caller1); s = splbio(); while (*count > limit) { Index: vm/vm.h =================================================================== RCS file: /home/ncvs/src/sys/vm/vm.h,v retrieving revision 1.17 diff -u -r1.17 vm.h --- vm/vm.h 2001/05/19 01:28:08 1.17 +++ vm/vm.h 2001/07/04 02:54:17 @@ -95,10 +95,6 @@ struct vm_object; typedef struct vm_object *vm_object_t; -#ifdef _KERNEL -extern struct mtx vm_mtx; -#endif - #ifndef _KERNEL /* * This is defined in for the kernel so that non-vm kernel Index: vm/vm_fault.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_fault.c,v retrieving revision 1.121 diff -u -r1.121 vm_fault.c --- vm/vm_fault.c 2001/05/23 22:09:18 1.121 +++ vm/vm_fault.c 2001/07/04 02:54:17 @@ -136,9 +136,7 @@ static void _unlock_things(struct faultstate *fs, int dealloc) { - - mtx_assert(&vm_mtx, MA_OWNED); - mtx_assert(&Giant, MA_OWNED); + GIANT_REQUIRED; vm_object_pip_wakeup(fs->object); if (fs->object != fs->first_object) { vm_page_free(fs->first_m); @@ -150,13 +148,8 @@ } unlock_map(fs); if (fs->vp != NULL) { - struct vnode *vp; - - vp = fs->vp; + vput(fs->vp); fs->vp = NULL; - mtx_unlock(&vm_mtx); - vput(vp); - mtx_lock(&vm_mtx); } } @@ -189,37 +182,20 @@ * * * The map in question must be referenced, and remains so. - * Caller may hold no locks except the vm_mtx which will be - * locked if needed. + * Caller may hold no locks. */ static int vm_fault1 __P((vm_map_t, vm_offset_t, vm_prot_t, int)); -static int vm_faults_no_vm_mtx; -SYSCTL_INT(_vm, OID_AUTO, vm_faults_no_vm_mtx, CTLFLAG_RW, - &vm_faults_no_vm_mtx, 0, ""); - -static int vm_faults_no_giant; -SYSCTL_INT(_vm, OID_AUTO, vm_faults_no_giant, CTLFLAG_RW, - &vm_faults_no_giant, 0, ""); - int vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, int fault_flags) { - int hadvmlock, hadgiant, ret; + int ret; - hadvmlock = mtx_owned(&vm_mtx); - hadgiant = mtx_owned(&Giant); mtx_lock(&Giant); - if (!hadvmlock) { - mtx_lock(&vm_mtx); - vm_faults_no_vm_mtx++; - if (hadgiant == 0) - vm_faults_no_giant++; - } + /* GIANT_REQUIRED */ + ret = vm_fault1(map, vaddr, fault_type, fault_flags); - if (!hadvmlock) - mtx_unlock(&vm_mtx); mtx_unlock(&Giant); return (ret); } @@ -237,8 +213,9 @@ int hardfault; int faultcount; struct faultstate fs; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); cnt.v_vm_faults++; hardfault = 0; @@ -296,9 +273,7 @@ vm_object_reference(fs.first_object); vm_object_pip_add(fs.first_object, 1); - mtx_unlock(&vm_mtx); fs.vp = vnode_pager_lock(fs.first_object); - mtx_lock(&vm_mtx); if ((fault_type & VM_PROT_WRITE) && (fs.first_object->type == OBJT_VNODE)) { vm_freeze_copyopts(fs.first_object, @@ -770,9 +745,7 @@ */ if (fs.vp != NULL) { - mtx_unlock(&vm_mtx); vput(fs.vp); - mtx_lock(&vm_mtx); fs.vp = NULL; } @@ -988,8 +961,9 @@ register vm_offset_t va; register pmap_t pmap; int rv; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); pmap = vm_map_pmap(map); /* @@ -1164,7 +1138,6 @@ * number of pages in marray * * This routine can't block. - * vm_mtx must be held. */ static int vm_fault_additional_pages(m, rbehind, rahead, marray, reqpage) @@ -1180,7 +1153,7 @@ vm_page_t rtm; int cbehind, cahead; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; object = m->object; pindex = m->pindex; Index: vm/vm_glue.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_glue.c,v retrieving revision 1.115 diff -u -r1.115 vm_glue.c --- vm/vm_glue.c 2001/06/20 00:48:20 1.115 +++ vm/vm_glue.c 2001/07/04 02:54:17 @@ -145,6 +145,8 @@ vm_map_t map; vm_map_entry_t save_hint; + GIANT_REQUIRED; + KASSERT((rw & (~VM_PROT_ALL)) == 0, ("illegal ``rw'' argument to useracc (%x)\n", rw)); prot = rw; @@ -161,7 +163,6 @@ || (vm_offset_t) addr + len < (vm_offset_t) addr) { return (FALSE); } - mtx_lock(&vm_mtx); map = &curproc->p_vmspace->vm_map; vm_map_lock_read(map); /* @@ -173,7 +174,6 @@ trunc_page((vm_offset_t)addr), round_page((vm_offset_t)addr + len), prot); map->hint = save_hint; vm_map_unlock_read(map); - mtx_unlock(&vm_mtx); return (rv == TRUE); } @@ -183,12 +183,10 @@ caddr_t addr; u_int len; { - - mtx_lock(&vm_mtx); + GIANT_REQUIRED; vm_map_pageable(&curproc->p_vmspace->vm_map, trunc_page((vm_offset_t)addr), round_page((vm_offset_t)addr + len), FALSE); - mtx_unlock(&vm_mtx); } void @@ -196,12 +194,10 @@ caddr_t addr; u_int len; { - - mtx_lock(&vm_mtx); + GIANT_REQUIRED; vm_map_pageable(&curproc->p_vmspace->vm_map, trunc_page((vm_offset_t)addr), round_page((vm_offset_t)addr + len), TRUE); - mtx_unlock(&vm_mtx); } /* @@ -211,8 +207,6 @@ * machine-dependent layer to fill those in and make the new process * ready to run. The new process is set up so that it returns directly * to user mode to avoid stack copying and relocation problems. - * - * Called without vm_mtx. */ void vm_fork(p1, p2, flags) @@ -221,7 +215,8 @@ { register struct user *up; - mtx_lock(&vm_mtx); + GIANT_REQUIRED; + if ((flags & RFPROC) == 0) { /* * Divorce the memory, if it is shared, essentially @@ -234,7 +229,6 @@ } } cpu_fork(p1, p2, flags); - mtx_unlock(&vm_mtx); return; } @@ -289,7 +283,6 @@ * and make the child ready to run. */ cpu_fork(p1, p2, flags); - mtx_unlock(&vm_mtx); } /* @@ -329,18 +322,16 @@ faultin(p) struct proc *p; { + GIANT_REQUIRED; PROC_LOCK_ASSERT(p, MA_OWNED); mtx_lock_spin(&sched_lock); if ((p->p_sflag & PS_INMEM) == 0) { - ++p->p_lock; mtx_unlock_spin(&sched_lock); PROC_UNLOCK(p); - mtx_lock(&vm_mtx); pmap_swapin_proc(p); - mtx_unlock(&vm_mtx); PROC_LOCK(p); mtx_lock_spin(&sched_lock); @@ -374,15 +365,13 @@ int ppri; mtx_assert(&Giant, MA_OWNED | MA_NOTRECURSED); + /* GIANT_REQUIRED */ loop: - mtx_lock(&vm_mtx); if (vm_page_count_min()) { VM_WAIT; - mtx_unlock(&vm_mtx); goto loop; } - mtx_unlock(&vm_mtx); pp = NULL; ppri = INT_MIN; @@ -458,9 +447,6 @@ * If any procs have been sleeping/stopped for at least maxslp seconds, * they are swapped. Else, we swap the longest-sleeping or stopped process, * if any, otherwise the longest-resident process. - * - * Can block - * must be called with vm_mtx */ void swapout_procs(action) @@ -470,9 +456,9 @@ struct proc *outp, *outp2; int outpri, outpri2; int didswap = 0; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); - mtx_unlock(&vm_mtx); outp = outp2 = NULL; outpri = outpri2 = INT_MIN; retry: @@ -480,12 +466,10 @@ LIST_FOREACH(p, &allproc, p_list) { struct vmspace *vm; - mtx_lock(&vm_mtx); PROC_LOCK(p); if (p->p_lock != 0 || (p->p_flag & (P_TRACED|P_SYSTEM|P_WEXIT)) != 0) { PROC_UNLOCK(p); - mtx_unlock(&vm_mtx); continue; } /* @@ -498,7 +482,6 @@ if ((p->p_sflag & (PS_INMEM|PS_SWAPPING)) != PS_INMEM) { mtx_unlock_spin(&sched_lock); PROC_UNLOCK(p); - mtx_unlock(&vm_mtx); continue; } @@ -506,7 +489,6 @@ default: mtx_unlock_spin(&sched_lock); PROC_UNLOCK(p); - mtx_unlock(&vm_mtx); continue; case SSLEEP: @@ -517,7 +499,6 @@ if (PRI_IS_REALTIME(p->p_pri.pri_class)) { mtx_unlock_spin(&sched_lock); PROC_UNLOCK(p); - mtx_unlock(&vm_mtx); continue; } @@ -530,7 +511,6 @@ (p->p_slptime < swap_idle_threshold1)) { mtx_unlock_spin(&sched_lock); PROC_UNLOCK(p); - mtx_unlock(&vm_mtx); continue; } @@ -544,7 +524,6 @@ (p->p_slptime < swap_idle_threshold2))) { mtx_unlock_spin(&sched_lock); PROC_UNLOCK(p); - mtx_unlock(&vm_mtx); continue; } mtx_unlock_spin(&sched_lock); @@ -559,7 +538,6 @@ NULL, curproc)) { vmspace_free(vm); PROC_UNLOCK(p); - mtx_unlock(&vm_mtx); continue; } vm_map_unlock(&vm->vm_map); @@ -574,12 +552,10 @@ swapout(p); vmspace_free(vm); didswap++; - mtx_unlock(&vm_mtx); goto retry; } PROC_UNLOCK(p); vmspace_free(vm); - mtx_unlock(&vm_mtx); } } sx_sunlock(&allproc_lock); @@ -587,7 +563,6 @@ * If we swapped something out, and another process needed memory, * then wakeup the sched process. */ - mtx_lock(&vm_mtx); if (didswap) wakeup(&proc0); } Index: vm/vm_init.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_init.c,v retrieving revision 1.27 diff -u -r1.27 vm_init.c --- vm/vm_init.c 2001/05/22 05:35:45 1.27 +++ vm/vm_init.c 2001/07/04 02:54:17 @@ -97,20 +97,15 @@ * The start and end address of physical memory is passed in. */ -struct mtx vm_mtx; - /* ARGSUSED*/ static void vm_mem_init(dummy) void *dummy; { - /* * Initializes resident memory structures. From here on, all physical * memory is accounted for, and we use only virtual addresses. */ - mtx_init(&vm_mtx, "vm", MTX_DEF); - mtx_lock(&vm_mtx); vm_set_page_size(); virtual_avail = vm_page_startup(avail_start, avail_end, virtual_avail); @@ -123,5 +118,4 @@ kmem_init(virtual_avail, virtual_end); pmap_init(avail_start, avail_end); vm_pager_init(); - mtx_unlock(&vm_mtx); } Index: vm/vm_kern.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_kern.c,v retrieving revision 1.71 diff -u -r1.71 vm_kern.c --- vm/vm_kern.c 2001/06/22 06:35:22 1.71 +++ vm/vm_kern.c 2001/07/04 02:54:17 @@ -104,17 +104,13 @@ { vm_offset_t addr; int result; - int hadvmlock; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); + GIANT_REQUIRED; + size = round_page(size); addr = vm_map_min(map); result = vm_map_find(map, NULL, (vm_offset_t) 0, &addr, size, TRUE, VM_PROT_ALL, VM_PROT_ALL, 0); - if (!hadvmlock) - mtx_unlock(&vm_mtx); if (result != KERN_SUCCESS) { return (0); } @@ -135,17 +131,12 @@ vm_offset_t addr; int result; - int hadvmlock; + GIANT_REQUIRED; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); size = round_page(size); addr = vm_map_min(map); result = vm_map_find(map, NULL, (vm_offset_t) 0, &addr, size, TRUE, VM_PROT_ALL, VM_PROT_ALL, MAP_NOFAULT); - if (!hadvmlock) - mtx_unlock(&vm_mtx); if (result != KERN_SUCCESS) { return (0); } @@ -164,11 +155,9 @@ vm_offset_t addr; vm_offset_t offset; vm_offset_t i; - int hadvmlock; + + GIANT_REQUIRED; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); size = round_page(size); /* @@ -184,8 +173,6 @@ vm_map_lock(map); if (vm_map_findspace(map, vm_map_min(map), size, &addr)) { vm_map_unlock(map); - if (!hadvmlock) - mtx_unlock(&vm_mtx); return (0); } offset = addr - VM_MIN_KERNEL_ADDRESS; @@ -230,8 +217,6 @@ (void) vm_map_pageable(map, (vm_offset_t) addr, addr + size, FALSE); - if (!hadvmlock) - mtx_unlock(&vm_mtx); return (addr); } @@ -250,16 +235,9 @@ vm_offset_t addr; vm_size_t size; { - int hadvmlock; - - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); + GIANT_REQUIRED; (void) vm_map_remove(map, trunc_page(addr), round_page(addr + size)); - - if (!hadvmlock) - mtx_unlock(&vm_mtx); } /* @@ -282,11 +260,8 @@ { int ret; vm_map_t result; - int hadvmlock; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); + GIANT_REQUIRED; size = round_page(size); @@ -304,8 +279,6 @@ panic("kmem_suballoc: cannot create submap"); if (vm_map_submap(parent, *min, *max, result) != KERN_SUCCESS) panic("kmem_suballoc: unable to change range to submap"); - if (!hadvmlock) - mtx_unlock(&vm_mtx); return (result); } @@ -343,12 +316,9 @@ vm_map_entry_t entry; vm_offset_t addr; vm_page_t m; - int hadvmlock; + + GIANT_REQUIRED; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); - size = round_page(size); addr = vm_map_min(map); @@ -444,13 +414,9 @@ } vm_map_unlock(map); - if (!hadvmlock) - mtx_unlock(&vm_mtx); return (addr); bad: - if (!hadvmlock) - mtx_unlock(&vm_mtx); return (0); } @@ -469,11 +435,8 @@ vm_size_t size; { vm_offset_t addr; - int hadvmlock; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); + GIANT_REQUIRED; size = round_page(size); @@ -488,17 +451,13 @@ /* no space now; see if we can ever get space */ if (vm_map_max(map) - vm_map_min(map) < size) { vm_map_unlock(map); - if (!hadvmlock) - mtx_unlock(&vm_mtx); return (0); } vm_map_unlock(map); - msleep(map, &vm_mtx, PVM, "kmaw", 0); + tsleep(map, PVM, "kmaw", 0); } vm_map_insert(map, NULL, (vm_offset_t) 0, addr, addr + size, VM_PROT_ALL, VM_PROT_ALL, 0); vm_map_unlock(map); - if (!hadvmlock) - mtx_unlock(&vm_mtx); return (addr); } @@ -514,17 +473,12 @@ vm_offset_t addr; vm_size_t size; { - int hadvmlock; + GIANT_REQUIRED; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); vm_map_lock(map); (void) vm_map_delete(map, trunc_page(addr), round_page(addr + size)); wakeup(map); vm_map_unlock(map); - if (!hadvmlock) - mtx_unlock(&vm_mtx); } /* Index: vm/vm_map.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_map.c,v retrieving revision 1.204 diff -u -r1.204 vm_map.c --- vm/vm_map.c 2001/06/22 06:35:22 1.204 +++ vm/vm_map.c 2001/07/04 02:54:17 @@ -173,7 +173,7 @@ { struct vmspace *vm; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; vm = zalloc(vmspace_zone); CTR1(KTR_VM, "vmspace_alloc: %p", vm); vm_map_init(&vm->vm_map, min, max); @@ -201,8 +201,8 @@ vmspace_free(vm) struct vmspace *vm; { + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (vm->vm_refcnt == 0) panic("vmspace_free: attempt to free already freed vmspace"); @@ -273,7 +273,8 @@ { vm_map_t result; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + result = zalloc(mapzone); CTR1(KTR_VM, "vm_map_create: %p", result); vm_map_init(result, min, max); @@ -291,8 +292,8 @@ struct vm_map *map; vm_offset_t min, max; { + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); map->header.next = map->header.prev = &map->header; map->nentries = 0; map->size = 0; @@ -310,8 +311,7 @@ vm_map_destroy(map) struct vm_map *map; { - - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; lockdestroy(&map->lock); } @@ -400,8 +400,6 @@ * in the "entry" parameter. The boolean * result indicates whether the address is * actually contained in the map. - * - * Doesn't block. */ boolean_t vm_map_lookup_entry(map, address, entry) @@ -412,7 +410,7 @@ vm_map_entry_t cur; vm_map_entry_t last; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; /* * Start looking either from the head of the list, or from the hint. */ @@ -491,8 +489,9 @@ vm_map_entry_t prev_entry; vm_map_entry_t temp_entry; vm_eflags_t protoeflags; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); /* * Check that the start and end points are not bogus. */ @@ -654,7 +653,7 @@ vm_map_entry_t entry, next; vm_offset_t end; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (start < map->min_offset) start = map->min_offset; if (start > map->max_offset) @@ -723,7 +722,8 @@ vm_offset_t start; int result, s = 0; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + start = *addr; if (map == kmem_map) @@ -768,8 +768,9 @@ { vm_map_entry_t next, prev; vm_size_t prevsize, esize; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) return; @@ -987,8 +988,9 @@ { vm_map_entry_t entry; int result = KERN_INVALID_ARGUMENT; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); vm_map_lock(map); VM_MAP_RANGE_CHECK(map, start, end); @@ -1027,7 +1029,7 @@ vm_map_entry_t current; vm_map_entry_t entry; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; vm_map_lock(map); VM_MAP_RANGE_CHECK(map, start, end); @@ -1117,7 +1119,8 @@ vm_map_entry_t current, entry; int modify_map = 0; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + /* * Some madvise calls directly modify the vm_map_entry, in which case * we need to use an exclusive lock on the map and we need to perform @@ -1270,8 +1273,9 @@ { vm_map_entry_t entry; vm_map_entry_t temp_entry; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); switch (new_inheritance) { case VM_INHERIT_NONE: case VM_INHERIT_COPY: @@ -1457,8 +1461,9 @@ vm_map_entry_t start_entry; vm_offset_t failed = 0; int rv; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); vm_map_lock(map); VM_MAP_RANGE_CHECK(map, start, end); @@ -1689,8 +1694,8 @@ vm_object_t object; vm_ooffset_t offset; - mtx_assert(&Giant, MA_OWNED); - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + vm_map_lock_read(map); VM_MAP_RANGE_CHECK(map, start, end); if (!vm_map_lookup_entry(map, start, &entry)) { @@ -1769,9 +1774,7 @@ int flags; vm_object_reference(object); - mtx_unlock(&vm_mtx); vn_lock(object->handle, LK_EXCLUSIVE | LK_RETRY, curproc); - mtx_lock(&vm_mtx); flags = (syncio || invalidate) ? OBJPC_SYNC : 0; flags |= invalidate ? OBJPC_INVAL : 0; vm_object_page_clean(object, @@ -1847,8 +1850,9 @@ vm_object_t object; vm_map_entry_t entry; vm_map_entry_t first_entry; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); /* * Find the start of the region, and clip it */ @@ -1949,8 +1953,9 @@ vm_offset_t end; { int result, s = 0; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (map == kmem_map) s = splvm(); @@ -1979,7 +1984,8 @@ vm_map_entry_t entry; vm_map_entry_t tmp_entry; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + if (!vm_map_lookup_entry(map, start, &tmp_entry)) { return (FALSE); } @@ -2026,8 +2032,9 @@ vm_pindex_t offidxstart, offidxend, idx; vm_size_t size; vm_ooffset_t offset; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); orig_object = entry->object.vm_object; if (orig_object->type != OBJT_DEFAULT && orig_object->type != OBJT_SWAP) return; @@ -2194,7 +2201,8 @@ vm_map_entry_t new_entry; vm_object_t object; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + vm_map_lock(old_map); old_map->infork = 1; @@ -2303,8 +2311,9 @@ vm_map_entry_t new_stack_entry; vm_size_t init_ssize; int rv; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (VM_MIN_ADDRESS > 0 && addrbos < VM_MIN_ADDRESS) return (KERN_NO_SPACE); @@ -2368,8 +2377,6 @@ * the stack. Also returns KERN_SUCCESS if addr is outside the * stack range (this is strange, but preserves compatibility with * the grow function in vm_machdep.c). - * - * Will grab vm_mtx if needed */ int vm_map_growstack (struct proc *p, vm_offset_t addr) @@ -2383,16 +2390,8 @@ int grow_amount; int rv; int is_procstack; - int hadvmlock; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); -#define myreturn(rval) do { \ - if (!hadvmlock) \ - mtx_unlock(&vm_mtx); \ - return (rval); \ -} while (0) + GIANT_REQUIRED; Retry: vm_map_lock_read(map); @@ -2400,12 +2399,12 @@ /* If addr is already in the entry range, no need to grow.*/ if (vm_map_lookup_entry(map, addr, &prev_entry)) { vm_map_unlock_read(map); - myreturn (KERN_SUCCESS); + return (KERN_SUCCESS); } if ((stack_entry = prev_entry->next) == &map->header) { vm_map_unlock_read(map); - myreturn (KERN_SUCCESS); + return (KERN_SUCCESS); } if (prev_entry == &map->header) end = stack_entry->start - stack_entry->avail_ssize; @@ -2423,14 +2422,14 @@ addr >= stack_entry->start || addr < stack_entry->start - stack_entry->avail_ssize) { vm_map_unlock_read(map); - myreturn (KERN_SUCCESS); + return (KERN_SUCCESS); } /* Find the minimum grow amount */ grow_amount = roundup (stack_entry->start - addr, PAGE_SIZE); if (grow_amount > stack_entry->avail_ssize) { vm_map_unlock_read(map); - myreturn (KERN_NO_SPACE); + return (KERN_NO_SPACE); } /* If there is no longer enough space between the entries @@ -2449,7 +2448,7 @@ stack_entry->avail_ssize = stack_entry->start - end; vm_map_unlock(map); - myreturn (KERN_NO_SPACE); + return (KERN_NO_SPACE); } is_procstack = addr >= (vm_offset_t)vm->vm_maxsaddr; @@ -2460,7 +2459,7 @@ if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > p->p_rlimit[RLIMIT_STACK].rlim_cur)) { vm_map_unlock_read(map); - myreturn (KERN_NO_SPACE); + return (KERN_NO_SPACE); } /* Round up the grow amount modulo SGROWSIZ */ @@ -2512,8 +2511,7 @@ } vm_map_unlock(map); - myreturn (rv); -#undef myreturn + return (rv); } /* @@ -2527,7 +2525,7 @@ struct vmspace *newvmspace; vm_map_t map = &p->p_vmspace->vm_map; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; newvmspace = vmspace_alloc(map->min_offset, map->max_offset); bcopy(&oldvmspace->vm_startcopy, &newvmspace->vm_startcopy, (caddr_t) (newvmspace + 1) - (caddr_t) &newvmspace->vm_startcopy); @@ -2555,7 +2553,7 @@ struct vmspace *oldvmspace = p->p_vmspace; struct vmspace *newvmspace; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (oldvmspace->vm_refcnt == 1) return; newvmspace = vmspace_fork(oldvmspace); @@ -2588,9 +2586,6 @@ * specified, the map may be changed to perform virtual * copying operations, although the data referenced will * remain the same. - * - * Can block locking maps and while calling vm_object_shadow(). - * Will drop/reaquire the vm_mtx. */ int vm_map_lookup(vm_map_t *var_map, /* IN/OUT */ @@ -2607,7 +2602,7 @@ vm_prot_t prot; vm_prot_t fault_type = fault_typea; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; RetryLookup:; /* @@ -2779,8 +2774,7 @@ /* * Unlock the main-level map */ - - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; vm_map_unlock_read(map); } @@ -2808,8 +2802,9 @@ vm_pindex_t first_pindex, osize, oindex; off_t ooffset; int cnt; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (npages) *npages = 0; @@ -3021,8 +3016,6 @@ * Performs the copy_on_write operations necessary to allow the virtual copies * into user space to work. This has to be called for write(2) system calls * from other processes, file unlinking, and file size shrinkage. - * - * Requires that the vm_mtx is held */ void vm_freeze_copyopts(object, froma, toa) @@ -3033,7 +3026,7 @@ vm_object_t robject; vm_pindex_t idx; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if ((object == NULL) || ((object->flags & OBJ_OPT) == 0)) return; Index: vm/vm_map.h =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_map.h,v retrieving revision 1.64 diff -u -r1.64 vm_map.h --- vm/vm_map.h 2001/06/09 18:06:57 1.64 +++ vm/vm_map.h 2001/07/04 03:12:33 @@ -212,7 +212,6 @@ do { \ lockmgr(&(map)->lock, LK_DRAIN|LK_INTERLOCK, \ &(map)->ref_lock, curproc); \ - mtx_lock(&vm_mtx); \ (map)->timestamp++; \ } while(0) @@ -227,11 +226,9 @@ #define vm_map_lock(map) \ do { \ vm_map_printf("locking map LK_EXCLUSIVE: %p\n", map); \ - mtx_assert(&vm_mtx, MA_OWNED); \ - if (lockmgr(&(map)->lock, LK_EXCLUSIVE | LK_INTERLOCK, \ - &vm_mtx, curproc) != 0) \ + if (lockmgr(&(map)->lock, LK_EXCLUSIVE, \ + NULL, curproc) != 0) \ panic("vm_map_lock: failed to get lock"); \ - mtx_lock(&vm_mtx); \ (map)->timestamp++; \ } while(0) @@ -244,10 +241,8 @@ #define vm_map_lock_read(map) \ do { \ vm_map_printf("locking map LK_SHARED: %p\n", map); \ - mtx_assert(&vm_mtx, MA_OWNED); \ - lockmgr(&(map)->lock, LK_SHARED | LK_INTERLOCK, \ - &vm_mtx, curproc); \ - mtx_lock(&vm_mtx); \ + lockmgr(&(map)->lock, LK_SHARED, \ + NULL, curproc); \ } while (0) #define vm_map_unlock_read(map) \ @@ -261,8 +256,7 @@ int error; vm_map_printf("locking map LK_EXCLUPGRADE: %p\n", map); - error = lockmgr(&map->lock, LK_EXCLUPGRADE | LK_INTERLOCK, &vm_mtx, p); - mtx_lock(&vm_mtx); + error = lockmgr(&map->lock, LK_EXCLUPGRADE, NULL, p); if (error == 0) map->timestamp++; return error; Index: vm/vm_meter.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_meter.c,v retrieving revision 1.55 diff -u -r1.55 vm_meter.c --- vm/vm_meter.c 2001/06/01 13:23:28 1.55 +++ vm/vm_meter.c 2001/07/04 02:54:17 @@ -145,10 +145,9 @@ /* * Mark all objects as inactive. */ - mtx_lock(&vm_mtx); + GIANT_REQUIRED; TAILQ_FOREACH(object, &vm_object_list, object_list) vm_object_clear_flag(object, OBJ_ACTIVE); - mtx_unlock(&vm_mtx); /* * Calculate process statistics. */ @@ -199,7 +198,6 @@ * Note active objects. */ paging = 0; - mtx_lock(&vm_mtx); for (map = &p->p_vmspace->vm_map, entry = map->header.next; entry != &map->header; entry = entry->next) { if ((entry->eflags & MAP_ENTRY_IS_SUB_MAP) || @@ -208,7 +206,6 @@ vm_object_set_flag(entry->object.vm_object, OBJ_ACTIVE); paging |= entry->object.vm_object->paging_in_progress; } - mtx_unlock(&vm_mtx); if (paging) totalp->t_pw++; } @@ -216,7 +213,6 @@ /* * Calculate object memory usage statistics. */ - mtx_lock(&vm_mtx); TAILQ_FOREACH(object, &vm_object_list, object_list) { /* * devices, like /dev/mem, will badly skew our totals @@ -240,7 +236,6 @@ } } totalp->t_free = cnt.v_free_count + cnt.v_cache_count; - mtx_unlock(&vm_mtx); return (sysctl_handle_opaque(oidp, totalp, sizeof total, req)); } Index: vm/vm_mmap.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_mmap.c,v retrieving revision 1.122 diff -u -r1.122 vm_mmap.c --- vm/vm_mmap.c 2001/05/24 18:04:29 1.122 +++ vm/vm_mmap.c 2001/07/04 02:54:17 @@ -113,8 +113,9 @@ struct proc *p; struct sbrk_args *uap; { - /* Not yet implemented */ + /* mtx_lock(&Giant); */ + /* mtx_unlock(&Giant); */ return (EOPNOTSUPP); } @@ -130,8 +131,9 @@ struct proc *p; struct sstk_args *uap; { - /* Not yet implemented */ + /* mtx_lock(&Giant); */ + /* mtx_unlock(&Giant); */ return (EOPNOTSUPP); } @@ -148,7 +150,7 @@ struct proc *p; struct getpagesize_args *uap; { - + /* MP SAFE */ p->p_retval[0] = PAGE_SIZE; return (0); } @@ -268,7 +270,7 @@ addr < round_page((vm_offset_t)vms->vm_daddr + MAXDSIZ))) addr = round_page((vm_offset_t)vms->vm_daddr + MAXDSIZ); - mtx_lock(&Giant); + mtx_lock(&Giant); /* syscall marked mp-safe but isn't */ if (flags & MAP_ANON) { /* * Mapping blank space is trivial. @@ -315,8 +317,10 @@ /* * Get the proper underlying object */ - if (VOP_GETVOBJECT(vp, &obj) != 0) - return (EINVAL); + if (VOP_GETVOBJECT(vp, &obj) != 0) { + error = EINVAL; + goto done; + } vp = (struct vnode*)obj->handle; } /* @@ -518,6 +522,8 @@ if ((flags & (MS_ASYNC|MS_INVALIDATE)) == (MS_ASYNC|MS_INVALIDATE)) return (EINVAL); + mtx_lock(&Giant); + map = &p->p_vmspace->vm_map; /* @@ -527,10 +533,6 @@ * the range of the map entry containing addr. This can be incorrect * if the region splits or is coalesced with a neighbor. */ -#ifndef BLEED - mtx_lock(&Giant); -#endif - mtx_lock(&vm_mtx); if (size == 0) { vm_map_entry_t entry; @@ -538,10 +540,7 @@ rv = vm_map_lookup_entry(map, addr, &entry); vm_map_unlock_read(map); if (rv == FALSE) { - mtx_unlock(&vm_mtx); -#ifndef BLEED mtx_unlock(&Giant); -#endif return (EINVAL); } addr = entry->start; @@ -554,10 +553,8 @@ rv = vm_map_clean(map, addr, addr + size, (flags & MS_ASYNC) == 0, (flags & MS_INVALIDATE) != 0); - mtx_unlock(&vm_mtx); -#ifndef BLEED mtx_unlock(&Giant); -#endif + switch (rv) { case KERN_SUCCESS: break; @@ -610,20 +607,17 @@ if (VM_MIN_ADDRESS > 0 && addr < VM_MIN_ADDRESS) return (EINVAL); #endif + mtx_lock(&Giant); map = &p->p_vmspace->vm_map; /* * Make sure entire range is allocated. */ - mtx_lock(&Giant); - mtx_lock(&vm_mtx); if (!vm_map_check_protection(map, addr, addr + size, VM_PROT_NONE)) { - mtx_unlock(&vm_mtx); mtx_unlock(&Giant); return (EINVAL); } /* returns nothing but KERN_SUCCESS anyway */ (void) vm_map_remove(map, addr, addr + size); - mtx_unlock(&vm_mtx); mtx_unlock(&Giant); return (0); } @@ -674,10 +668,8 @@ return(EINVAL); mtx_lock(&Giant); - mtx_lock(&vm_mtx); ret = vm_map_protect(&p->p_vmspace->vm_map, addr, addr + size, prot, FALSE); - mtx_unlock(&vm_mtx); mtx_unlock(&Giant); switch (ret) { case KERN_SUCCESS: @@ -716,16 +708,10 @@ if (addr + size < addr) return(EINVAL); -#ifndef BLEED mtx_lock(&Giant); -#endif - mtx_lock(&vm_mtx); ret = vm_map_inherit(&p->p_vmspace->vm_map, addr, addr+size, inherit); - mtx_unlock(&vm_mtx); -#ifndef BLEED mtx_unlock(&Giant); -#endif switch (ret) { case KERN_SUCCESS: @@ -779,15 +765,9 @@ start = trunc_page((vm_offset_t) uap->addr); end = round_page((vm_offset_t) uap->addr + uap->len); -#ifndef BLEED mtx_lock(&Giant); -#endif - mtx_lock(&vm_mtx); ret = vm_map_madvise(&p->p_vmspace->vm_map, start, end, uap->behav); - mtx_unlock(&vm_mtx); -#ifndef BLEED mtx_unlock(&Giant); -#endif return (ret ? EINVAL : 0); } @@ -833,11 +813,8 @@ */ vec = uap->vec; - map = &p->p_vmspace->vm_map; -#ifndef BLEED mtx_lock(&Giant); -#endif - mtx_lock(&vm_mtx); + map = &p->p_vmspace->vm_map; pmap = vmspace_pmap(p->p_vmspace); vm_map_lock_read(map); @@ -917,7 +894,6 @@ * the map, we release the lock. */ vm_map_unlock_read(map); - mtx_unlock(&vm_mtx); /* * calculate index into user supplied byte vector @@ -931,9 +907,7 @@ while((lastvecindex + 1) < vecindex) { error = subyte( vec + lastvecindex, 0); if (error) { -#ifndef BLEED mtx_unlock(&Giant); -#endif return (EFAULT); } ++lastvecindex; @@ -944,9 +918,7 @@ */ error = subyte( vec + vecindex, mincoreinfo); if (error) { -#ifndef BLEED mtx_unlock(&Giant); -#endif return (EFAULT); } @@ -954,7 +926,6 @@ * If the map has changed, due to the subyte, the previous * output may be invalid. */ - mtx_lock(&vm_mtx); vm_map_lock_read(map); if (timestamp != map->timestamp) goto RestartScan; @@ -969,7 +940,6 @@ * the map, we release the lock. */ vm_map_unlock_read(map); - mtx_unlock(&vm_mtx); /* * Zero the last entries in the byte vector. @@ -978,9 +948,7 @@ while((lastvecindex + 1) < vecindex) { error = subyte( vec + lastvecindex, 0); if (error) { -#ifndef BLEED mtx_unlock(&Giant); -#endif return (EFAULT); } ++lastvecindex; @@ -990,15 +958,11 @@ * If the map has changed, due to the subyte, the previous * output may be invalid. */ - mtx_lock(&vm_mtx); vm_map_lock_read(map); if (timestamp != map->timestamp) goto RestartScan; vm_map_unlock_read(map); - mtx_unlock(&vm_mtx); -#ifndef BLEED mtx_unlock(&Giant); -#endif return (0); } @@ -1043,16 +1007,10 @@ return (error); #endif -#ifndef BLEED mtx_lock(&Giant); -#endif - mtx_lock(&vm_mtx); error = vm_map_user_pageable(&p->p_vmspace->vm_map, addr, addr + size, FALSE); - mtx_unlock(&vm_mtx); -#ifndef BLEED mtx_unlock(&Giant); -#endif return (error == KERN_SUCCESS ? 0 : ENOMEM); } @@ -1067,6 +1025,8 @@ struct proc *p; struct mlockall_args *uap; { + /* mtx_lock(&Giant); */ + /* mtx_unlock(&Giant); */ return 0; } @@ -1081,6 +1041,8 @@ struct proc *p; struct munlockall_args *uap; { + /* mtx_lock(&Giant); */ + /* mtx_unlock(&Giant); */ return 0; } @@ -1117,16 +1079,10 @@ return (error); #endif -#ifndef BLEED mtx_lock(&Giant); -#endif - mtx_lock(&vm_mtx); error = vm_map_user_pageable(&p->p_vmspace->vm_map, addr, addr + size, TRUE); - mtx_unlock(&vm_mtx); -#ifndef BLEED mtx_unlock(&Giant); -#endif return (error == KERN_SUCCESS ? 0 : ENOMEM); } @@ -1175,9 +1131,7 @@ return (EINVAL); fitit = FALSE; mtx_lock(&Giant); - mtx_lock(&vm_mtx); (void) vm_map_remove(map, *addr, *addr + size); - mtx_unlock(&vm_mtx); } /* @@ -1252,7 +1206,6 @@ maxprot |= VM_PROT_EXECUTE; #endif - mtx_lock(&vm_mtx); if (fitit) *addr = pmap_addr_hint(object, *addr, size); @@ -1279,7 +1232,6 @@ if (rv != KERN_SUCCESS) (void) vm_map_remove(map, *addr, *addr + size); } - mtx_unlock(&vm_mtx); mtx_unlock(&Giant); switch (rv) { case KERN_SUCCESS: Index: vm/vm_object.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_object.c,v retrieving revision 1.193 diff -u -r1.193 vm_object.c --- vm/vm_object.c 2001/06/22 06:35:23 1.193 +++ vm/vm_object.c 2001/07/04 02:54:17 @@ -147,7 +147,8 @@ { int incr; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + TAILQ_INIT(&object->memq); TAILQ_INIT(&object->shadow_head); @@ -192,8 +193,8 @@ void vm_object_init() { + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); TAILQ_INIT(&vm_object_list); mtx_init(&vm_object_list_mtx, "vm object_list", MTX_DEF); vm_object_count = 0; @@ -229,8 +230,9 @@ vm_size_t size; { vm_object_t result; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); result = (vm_object_t) zalloc(obj_zone); _vm_object_allocate(type, size, result); @@ -247,8 +249,8 @@ vm_object_reference(object) vm_object_t object; { + GIANT_REQUIRED; - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); if (object == NULL) return; @@ -257,20 +259,14 @@ object->ref_count++; if (object->type == OBJT_VNODE) { - mtx_unlock(VM_OBJECT_MTX(object)); - mtx_assert(&Giant, MA_OWNED); while (vget((struct vnode *) object->handle, LK_RETRY|LK_NOOBJ, curproc)) { printf("vm_object_reference: delay in getting object\n"); } - mtx_lock(VM_OBJECT_MTX(object)); } } /* * handle deallocating a object of type OBJT_VNODE - * - * requires vm_mtx - * may block */ void vm_object_vndeallocate(object) @@ -278,7 +274,7 @@ { struct vnode *vp = (struct vnode *) object->handle; - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); + GIANT_REQUIRED; KASSERT(object->type == OBJT_VNODE, ("vm_object_vndeallocate: not a vnode object")); KASSERT(vp != NULL, ("vm_object_vndeallocate: missing vp")); @@ -297,10 +293,7 @@ /* * vrele may need a vop lock */ - mtx_unlock(VM_OBJECT_MTX(object)); - mtx_assert(&Giant, MA_OWNED); vrele(vp); - mtx_lock(VM_OBJECT_MTX(object)); } /* @@ -313,15 +306,15 @@ * may be relinquished. * * No object may be locked. - * vm_mtx must be held */ void vm_object_deallocate(object) vm_object_t object; { vm_object_t temp; + + GIANT_REQUIRED; - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); while (object != NULL) { if (object->type == OBJT_VNODE) { @@ -355,9 +348,6 @@ ("vm_object_deallocate: ref_count: %d, shadow_count: %d", object->ref_count, object->shadow_count)); -#ifdef objlocks - mtx_lock(VM_OBJECT_MTX(robject)); -#endif if ((robject->handle == NULL) && (robject->type == OBJT_DEFAULT || robject->type == OBJT_SWAP)) { @@ -368,32 +358,16 @@ robject->paging_in_progress || object->paging_in_progress ) { -#ifdef objlocks - mtx_unlock(VM_OBJECT_MTX(object)); -#endif vm_object_pip_sleep(robject, "objde1"); -#ifdef objlocks - mtx_unlock(VM_OBJECT_MTX(robject)); - mtx_lock(VM_OBJECT_MTX(object)); -#endif vm_object_pip_sleep(object, "objde2"); -#ifdef objlocks - mtx_lock(VM_OBJECT_MTX(robject)); -#endif } if (robject->ref_count == 1) { robject->ref_count--; -#ifdef objlocks - mtx_unlock(VM_OBJECT_MTX(object)); -#endif object = robject; goto doterm; } -#ifdef objlocks - mtx_unlock(VM_OBJECT_MTX(object)); -#endif object = robject; vm_object_collapse(object); continue; @@ -434,9 +408,9 @@ { vm_page_t p; int s; + + GIANT_REQUIRED; - mtx_assert(&Giant, MA_OWNED); - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); /* * Make sure no one uses us. */ @@ -468,9 +442,7 @@ vm_object_page_clean(object, 0, 0, OBJPC_SYNC); vp = (struct vnode *) object->handle; - mtx_unlock(VM_OBJECT_MTX(object)); vinvalbuf(vp, V_SAVE, NOCRED, NULL, 0, 0); - mtx_lock(VM_OBJECT_MTX(object)); } KASSERT(object->ref_count == 0, @@ -555,7 +527,8 @@ vm_page_t ma[vm_pageout_page_count]; int curgeneration; - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); + GIANT_REQUIRED; + if (object->type != OBJT_VNODE || (object->flags & OBJ_MIGHTBEDIRTY) == 0) return; @@ -762,8 +735,9 @@ { vm_pindex_t idx; vm_page_t p; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (object == NULL || (object->flags & OBJ_WRITEABLE) == 0) return; @@ -791,7 +765,7 @@ { vm_page_t p; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (object == NULL) return; TAILQ_FOREACH(p, &object->memq, listq) { @@ -834,7 +808,7 @@ vm_object_t tobject; vm_page_t m; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (object == NULL) return; @@ -948,7 +922,7 @@ vm_object_t source; vm_object_t result; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; source = *object; /* @@ -1015,7 +989,7 @@ vm_pindex_t backing_offset_index; s = splvm(); - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; backing_object = object->backing_object; backing_offset_index = OFF_TO_IDX(object->backing_object_offset); @@ -1229,8 +1203,7 @@ vm_object_collapse(object) vm_object_t object; { - - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; while (TRUE) { vm_object_t backing_object; @@ -1443,7 +1416,7 @@ unsigned int size; int all; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (object == NULL || object->resident_page_count == 0) @@ -1561,7 +1534,7 @@ { vm_pindex_t next_pindex; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (prev_object == NULL) { return (TRUE); Index: vm/vm_object.h =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_object.h,v retrieving revision 1.71 diff -u -r1.71 vm_object.h --- vm/vm_object.h 2001/05/19 01:28:09 1.71 +++ vm/vm_object.h 2001/07/04 02:54:17 @@ -169,49 +169,44 @@ #ifdef _KERNEL -/* - * For now a global vm lock. - */ -#define VM_OBJECT_MTX(object) (&vm_mtx) - static __inline void vm_object_set_flag(vm_object_t object, u_short bits) { - - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); - object->flags |= bits; + GIANT_REQUIRED; + atomic_set_short(&object->flags, bits); + /* object->flags |= bits; */ } static __inline void vm_object_clear_flag(vm_object_t object, u_short bits) { - - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); - object->flags &= ~bits; + GIANT_REQUIRED; + atomic_clear_short(&object->flags, bits); + /* object->flags &= ~bits; */ } static __inline void vm_object_pip_add(vm_object_t object, short i) { - - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); - object->paging_in_progress += i; + GIANT_REQUIRED; + atomic_add_short(&object->paging_in_progress, i); + /* object->paging_in_progress += i; */ } static __inline void vm_object_pip_subtract(vm_object_t object, short i) { - - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); - object->paging_in_progress -= i; + GIANT_REQUIRED; + atomic_subtract_short(&object->paging_in_progress, i); + /* object->paging_in_progress -= i; */ } static __inline void vm_object_pip_wakeup(vm_object_t object) { - - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); - object->paging_in_progress--; + GIANT_REQUIRED; + atomic_subtract_short(&object->paging_in_progress, 1); + /* object->paging_in_progress--; */ if ((object->flags & OBJ_PIPWNT) && object->paging_in_progress == 0) { vm_object_clear_flag(object, OBJ_PIPWNT); wakeup(object); @@ -221,10 +216,9 @@ static __inline void vm_object_pip_wakeupn(vm_object_t object, short i) { - - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); + GIANT_REQUIRED; if (i) - object->paging_in_progress -= i; + atomic_subtract_short(&object->paging_in_progress, i); if ((object->flags & OBJ_PIPWNT) && object->paging_in_progress == 0) { vm_object_clear_flag(object, OBJ_PIPWNT); wakeup(object); @@ -234,13 +228,12 @@ static __inline void vm_object_pip_sleep(vm_object_t object, char *waitid) { - - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); + GIANT_REQUIRED; if (object->paging_in_progress) { int s = splvm(); if (object->paging_in_progress) { vm_object_set_flag(object, OBJ_PIPWNT); - msleep(object, VM_OBJECT_MTX(object), PVM, waitid, 0); + tsleep(object, PVM, waitid, 0); } splx(s); } @@ -249,8 +242,7 @@ static __inline void vm_object_pip_wait(vm_object_t object, char *waitid) { - - mtx_assert(VM_OBJECT_MTX(object), MA_OWNED); + GIANT_REQUIRED; while (object->paging_in_progress) vm_object_pip_sleep(object, waitid); } Index: vm/vm_page.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_page.c,v retrieving revision 1.164 diff -u -r1.164 vm_page.c --- vm/vm_page.c 2001/05/24 07:22:26 1.164 +++ vm/vm_page.c 2001/07/04 02:54:17 @@ -148,7 +148,6 @@ * * Add a new page to the freelist for use by the system. * Must be called at splhigh(). - * Must be called with the vm_mtx held. */ vm_page_t vm_add_new_page(pa) @@ -156,7 +155,8 @@ { vm_page_t m; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + ++cnt.v_page_count; ++cnt.v_free_count; m = PHYS_TO_VM_PAGE(pa); @@ -362,8 +362,9 @@ register vm_pindex_t pindex; { register struct vm_page **bucket; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (m->object != NULL) panic("vm_page_insert: already inserted"); @@ -422,8 +423,9 @@ vm_page_t m; { vm_object_t object; + + GIANT_REQUIRED; - mtx_assert(&vm_mtx, MA_OWNED); if (m->object == NULL) return; @@ -487,8 +489,6 @@ * an interrupt makes a change, but the generation algorithm will not * operate properly in an SMP environment where both cpu's are able to run * kernel code simultaneously. - * NOTE: under the giant vm lock we should be ok, there should be - * no reason to check vm_page_bucket_generation * * The object must be locked. No side effects. * This routine may not block. @@ -604,7 +604,7 @@ int queue = m->queue; struct vpgqueues *pq; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (queue != PQ_NONE) { m->queue = PQ_NONE; pq = &vm_page_queues[queue]; @@ -645,7 +645,7 @@ vm_page_t m = NULL; struct vpgqueues *pq; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; pq = &vm_page_queues[basequeue]; /* @@ -683,7 +683,7 @@ { vm_page_t m; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; while (TRUE) { m = vm_page_list_find( PQ_CACHE, @@ -735,7 +735,6 @@ * VM_ALLOC_INTERRUPT interrupt time request * VM_ALLOC_ZERO zero page * - * vm_mtx must be locked. * This routine may not block. * * Additional special handling is required when called from an @@ -752,7 +751,8 @@ register vm_page_t m = NULL; int s; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + KASSERT(!vm_page_lookup(object, pindex), ("vm_page_alloc: page already allocated")); @@ -885,13 +885,13 @@ s = splvm(); if (curproc == pageproc) { vm_pageout_pages_needed = 1; - msleep(&vm_pageout_pages_needed, &vm_mtx, PSWP, "VMWait", 0); + tsleep(&vm_pageout_pages_needed, PSWP, "VMWait", 0); } else { if (!vm_pages_needed) { vm_pages_needed = 1; wakeup(&vm_pages_needed); } - msleep(&cnt.v_free_count, &vm_mtx, PVM, "vmwait", 0); + tsleep(&cnt.v_free_count, PVM, "vmwait", 0); } splx(s); } @@ -938,8 +938,9 @@ { int s; + GIANT_REQUIRED; s = splvm(); - mtx_assert(&vm_mtx, MA_OWNED); + if (m->queue != PQ_ACTIVE) { if ((m->queue - m->pc) == PQ_CACHE) cnt.v_reactivated++; @@ -1012,9 +1013,8 @@ struct vpgqueues *pq; vm_object_t object = m->object; + GIANT_REQUIRED; s = splvm(); - - mtx_assert(&vm_mtx, MA_OWNED); cnt.v_tfree++; if (m->busy || ((m->queue - m->pc) == PQ_FREE) || @@ -1252,7 +1252,7 @@ { int s; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; /* * Ignore if already inactive. */ @@ -1290,8 +1290,8 @@ int vm_page_try_to_cache(vm_page_t m) { + GIANT_REQUIRED; - mtx_assert(VM_PAGE_MTX(m), MA_OWNED); if (m->dirty || m->hold_count || m->busy || m->wire_count || (m->flags & (PG_BUSY|PG_UNMANAGED))) { return(0); @@ -1339,7 +1339,7 @@ { int s; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if ((m->flags & (PG_BUSY|PG_UNMANAGED)) || m->busy || m->wire_count) { printf("vm_page_cache: attempting to cache busy page\n"); return; @@ -1397,7 +1397,7 @@ int dnw; int head; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; dnw = ++dnweight; /* @@ -1438,7 +1438,6 @@ * to be in the object. If the page doesn't exist, allocate it. * * This routine may block. - * Requires vm_mtx. */ vm_page_t vm_page_grab(object, pindex, allocflags) @@ -1449,7 +1448,7 @@ vm_page_t m; int s, generation; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; retrylookup: if ((m = vm_page_lookup(object, pindex)) != NULL) { if (m->busy || (m->flags & PG_BUSY)) { @@ -1459,7 +1458,7 @@ while ((object->generation == generation) && (m->busy || (m->flags & PG_BUSY))) { vm_page_flag_set(m, PG_WANTED | PG_REFERENCED); - msleep(m, &vm_mtx, PVM, "pgrbwt", 0); + tsleep(m, PVM, "pgrbwt", 0); if ((allocflags & VM_ALLOC_RETRY) == 0) { splx(s); return NULL; @@ -1522,8 +1521,6 @@ * This routine may not block. * * (base + size) must be less then or equal to PAGE_SIZE. - * - * vm_mtx needs to be held */ void vm_page_set_validclean(m, base, size) @@ -1535,7 +1532,7 @@ int frag; int endoff; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (size == 0) /* handle degenerate case */ return; @@ -1609,8 +1606,7 @@ int base; int size; { - - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; m->dirty &= ~vm_page_bits(base, size); } @@ -1630,7 +1626,7 @@ { int bits; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; bits = vm_page_bits(base, size); m->valid &= ~bits; m->dirty &= ~bits; @@ -1918,16 +1914,10 @@ unsigned long boundary; { void * ret; - int hadvmlock; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); + GIANT_REQUIRED; ret = contigmalloc1(size, type, flags, low, high, alignment, boundary, kernel_map); - if (!hadvmlock) - mtx_unlock(&vm_mtx); - return (ret); } @@ -1938,14 +1928,8 @@ unsigned long size; struct malloc_type *type; { - int hadvmlock; - - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); + GIANT_REQUIRED; kmem_free(kernel_map, (vm_offset_t)addr, size); - if (!hadvmlock) - mtx_unlock(&vm_mtx); } vm_offset_t @@ -1956,15 +1940,10 @@ vm_offset_t alignment; { vm_offset_t ret; - int hadvmlock; - hadvmlock = mtx_owned(&vm_mtx); - if (!hadvmlock) - mtx_lock(&vm_mtx); + GIANT_REQUIRED; ret = ((vm_offset_t)contigmalloc1(size, M_DEVBUF, M_NOWAIT, low, high, alignment, 0ul, kernel_map)); - if (!hadvmlock) - mtx_unlock(&vm_mtx); return (ret); } Index: vm/vm_page.h =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_page.h,v retrieving revision 1.86 diff -u -r1.86 vm_page.h --- vm/vm_page.h 2001/05/24 07:22:26 1.86 +++ vm/vm_page.h 2001/07/04 02:54:17 @@ -305,28 +305,23 @@ (&vm_page_array[atop(pa) - first_page ]) /* - * For now, a global vm lock - */ -#define VM_PAGE_MTX(m) (&vm_mtx) - -/* * Functions implemented as macros */ static __inline void vm_page_flag_set(vm_page_t m, unsigned short bits) { - - mtx_assert(VM_PAGE_MTX(m), MA_OWNED); - m->flags |= bits; + GIANT_REQUIRED; + atomic_set_short(&(m)->flags, bits); + /* m->flags |= bits; */ } static __inline void vm_page_flag_clear(vm_page_t m, unsigned short bits) { - - mtx_assert(VM_PAGE_MTX(m), MA_OWNED); - m->flags &= ~bits; + GIANT_REQUIRED; + atomic_clear_short(&(m)->flags, bits); + /* m->flags &= ~bits; */ } #if 0 @@ -386,17 +381,15 @@ static __inline void vm_page_io_start(vm_page_t m) { - - mtx_assert(VM_PAGE_MTX(m), MA_OWNED); - m->busy++; + GIANT_REQUIRED; + atomic_add_char(&(m)->busy, 1); } static __inline void vm_page_io_finish(vm_page_t m) { - - mtx_assert(VM_PAGE_MTX(m), MA_OWNED); - m->busy--; + GIANT_REQUIRED; + atomic_subtract_char(&(m)->busy, 1); if (m->busy == 0) vm_page_flash(m); } @@ -463,16 +456,14 @@ static __inline void vm_page_hold(vm_page_t mem) { - - mtx_assert(VM_PAGE_MTX(m), MA_OWNED); + GIANT_REQUIRED; mem->hold_count++; } static __inline void vm_page_unhold(vm_page_t mem) { - - mtx_assert(VM_PAGE_MTX(m), MA_OWNED); + GIANT_REQUIRED; --mem->hold_count; KASSERT(mem->hold_count >= 0, ("vm_page_unhold: hold count < 0!!!")); } @@ -578,6 +569,7 @@ static __inline int vm_page_sleep_busy(vm_page_t m, int also_m_busy, const char *msg) { + GIANT_REQUIRED; if ((m->flags & PG_BUSY) || (also_m_busy && m->busy)) { int s = splvm(); if ((m->flags & PG_BUSY) || (also_m_busy && m->busy)) { @@ -585,7 +577,7 @@ * Page is busy. Wait and retry. */ vm_page_flag_set(m, PG_WANTED | PG_REFERENCED); - msleep(m, VM_PAGE_MTX(m), PVM, msg, 0); + tsleep(m, PVM, msg, 0); } splx(s); return(TRUE); Index: vm/vm_pageout.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_pageout.c,v retrieving revision 1.179 diff -u -r1.179 vm_pageout.c --- vm/vm_pageout.c 2001/06/20 23:34:06 1.179 +++ vm/vm_pageout.c 2001/07/04 02:54:17 @@ -226,7 +226,8 @@ int ib, is, page_base; vm_pindex_t pindex = m->pindex; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; + object = m->object; /* @@ -366,7 +367,7 @@ int numpagedout = 0; int i; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; /* * Initiate I/O. Bump the vm_page_t->busy counter and * mark the pages read-only. @@ -449,8 +450,6 @@ * backing_objects. * * The object and map must be locked. - * - * Requires the vm_mtx */ static void vm_pageout_object_deactivate_pages(map, object, desired, map_remove_only) @@ -464,7 +463,7 @@ int remove_mode; int s; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQUIRED; if (object->type == OBJT_DEVICE || object->type == OBJT_PHYS) return; @@ -553,7 +552,7 @@ vm_map_entry_t tmpe; vm_object_t obj, bigobj; - mtx_assert(&vm_mtx, MA_OWNED); + GIANT_REQ