From owner-p4-projects@FreeBSD.ORG Fri Nov 24 15:05:37 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 020C216A417; Fri, 24 Nov 2006 15:05:37 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CDE0916A415 for ; Fri, 24 Nov 2006 15:05:36 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.FreeBSD.org (Postfix) with ESMTP id D5B8043D55 for ; Fri, 24 Nov 2006 15:04:54 +0000 (GMT) (envelope-from gonzo@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id kAOF5aMm060667 for ; Fri, 24 Nov 2006 15:05:36 GMT (envelope-from gonzo@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id kAOF5a0S060664 for perforce@freebsd.org; Fri, 24 Nov 2006 15:05:36 GMT (envelope-from gonzo@FreeBSD.org) Date: Fri, 24 Nov 2006 15:05:36 GMT Message-Id: <200611241505.kAOF5a0S060664@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gonzo@FreeBSD.org using -f From: Oleksandr Tymoshenko To: Perforce Change Reviews Cc: Subject: PERFORCE change 110483 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Nov 2006 15:05:37 -0000 http://perforce.freebsd.org/chv.cgi?CH=110483 Change 110483 by gonzo@gonzo_hq on 2006/11/24 15:05:32 o Replace splvm/splx with proper locking Reported by: INVARIANTS Affected files ... .. //depot/projects/mips2/src/sys/mips/mips/pmap.c#15 edit Differences ... ==== //depot/projects/mips2/src/sys/mips/mips/pmap.c#15 (text+ko) ==== @@ -97,6 +97,7 @@ #include #include #include +#include #include #include @@ -325,6 +326,7 @@ kernel_pmap->pm_active = ~0; kernel_pmap->pm_asid = 0; kernel_pmap->pm_asidgen = 1; + PMAP_LOCK_INIT(kernel_pmap); TAILQ_INIT(&kernel_pmap->pm_pvlist); /* @@ -420,7 +422,7 @@ * Now it is safe to enable pv_table recording. */ pmap_initialized = TRUE; -} +} void pmap_init2(void); /* XXX */ @@ -698,6 +700,7 @@ struct pmap *pmap; { + PMAP_LOCK_INIT(pmap); pmap->pm_private.pm_direct_map = kptmap; pmap->pm_ptphint = NULL; pmap->pm_active = 0; @@ -746,6 +749,7 @@ /* XXXMIPS: put proper asid generation here */ pmap->pm_asid = 1; pmap->pm_asidgen = 1; + PMAP_LOCK_INIT(pmap); TAILQ_INIT(&pmap->pm_pvlist); bzero(&pmap->pm_stats, sizeof pmap->pm_stats); mtx_lock_spin(&allpmaps_lock); @@ -880,9 +884,7 @@ { pv_entry_t pv; int rtval; - int s; - s = splvm(); if (m->md.pv_list_count < pmap->pm_stats.resident_count) { TAILQ_FOREACH(pv, &m->md.pv_list, pv_list) { if (pmap == pv->pv_pmap && va == pv->pv_va) @@ -907,7 +909,6 @@ free_pv_entry(pv); } - splx(s); return rtval; } @@ -919,10 +920,10 @@ pmap_insert_entry(pmap_t pmap, vm_offset_t va, vm_page_t mpte, vm_page_t m) { - int s; pv_entry_t pv; - s = splvm(); + vm_page_lock_queues(); + PMAP_LOCK(pmap); pv = get_pv_entry(); pv->pv_va = va; pv->pv_pmap = pmap; @@ -933,7 +934,8 @@ TAILQ_INSERT_TAIL(&m->md.pv_list, pv, pv_list); m->md.pv_list_count++; vm_page_unlock_queues(); - splx(s); + PMAP_UNLOCK(pmap); + vm_page_unlock_queues(); } /* @@ -977,8 +979,15 @@ if (pmap == NULL) return; + vm_page_lock_queues(); + PMAP_LOCK(pmap); + if (pmap->pm_stats.resident_count == 0) + { + PMAP_UNLOCK(pmap); + vm_page_unlock_queues(); return; + } count = (eva - sva) >> PAGE_SHIFT; va = sva; @@ -988,6 +997,9 @@ tlb_remove(pmap, va); va += PAGE_SIZE; } + + PMAP_UNLOCK(pmap); + vm_page_unlock_queues(); } /* @@ -1008,7 +1020,6 @@ { register pv_entry_t pv; pt_entry_t *pte, tpte; - int s; #if defined(PMAP_DIAGNOSTIC) /* @@ -1020,14 +1031,18 @@ } #endif - s = splvm(); + vm_page_lock_queues(); while ((pv = TAILQ_FIRST(&m->md.pv_list)) != NULL) { + PMAP_LOCK(pv->pv_pmap); pte = pmap_pte(pv->pv_pmap, pv->pv_va); pv->pv_pmap->pm_stats.resident_count--; if (pmap_pte_pa(pte) != VM_PAGE_TO_PHYS(m)) + { + PMAP_UNLOCK(pv->pv_pmap); panic("pmap_remove_all: pv_table for %x is inconsistent", VM_PAGE_TO_PHYS(m)); + } tpte = *pte; @@ -1052,11 +1067,11 @@ m->md.pv_list_count--; /* pmap_unuse_pt(pv->pv_pmap, pv->pv_va, pv->pv_ptem); */ free_pv_entry(pv); + PMAP_UNLOCK(pv->pv_pmap); } vm_page_flag_clear(m, PG_WRITEABLE); - - splx(s); + vm_page_unlock_queues(); } /* @@ -1261,20 +1276,14 @@ { vm_page_t m; vm_pindex_t diff, psize; - int s; psize = atop(end - start); m = m_start; - /* - * XXXMIPS: check if locking required. - */ - s = splvm(); while (m != NULL && (diff = m->pindex - m_start->pindex) < psize) { pmap_enter(pmap, start + ptoa(diff), m, prot & (VM_PROT_READ | VM_PROT_EXECUTE), FALSE); m = TAILQ_NEXT(m, listq); } - splx(s); } void @@ -1422,26 +1431,28 @@ { pv_entry_t pv; int loops = 0; - int s; if (!pmap_initialized || (m->flags & PG_FICTITIOUS)) return FALSE; - s = splvm(); + vm_page_lock_queues(); + PMAP_LOCK(pmap); /* * Not found, check current mappings returning immediately if found. */ TAILQ_FOREACH(pv, &m->md.pv_list, pv_list) { if (pv->pv_pmap == pmap) { - splx(s); + PMAP_UNLOCK(pmap); + vm_page_unlock_queues(); return TRUE; } loops++; if (loops >= 16) break; } - splx(s); + PMAP_UNLOCK(pmap); + vm_page_unlock_queues(); return (FALSE); } @@ -1460,7 +1471,6 @@ pt_entry_t *pte, tpte; vm_page_t m; pv_entry_t pv, npv; - int s; #ifdef PMAP_REMOVE_PAGES_CURPROC_ONLY if (!curthread || (pmap != vmspace_pmap(curthread->td_proc->p_vmspace))) { @@ -1469,7 +1479,8 @@ } #endif - s = splvm(); + vm_page_lock_queues(); + PMAP_LOCK(pmap); for(pv = TAILQ_FIRST(&pmap->pm_pvlist); pv; pv = npv) { @@ -1505,7 +1516,8 @@ /* pmap_unuse_pt(pv->pv_pmap, pv->pv_va, pv->pv_ptem); */ free_pv_entry(pv); } - splx(s); + PMAP_UNLOCK(pmap); + vm_page_unlock_queues(); pmap_invalidate_all(pmap); }