CVS commit: [netbsd-5] src/sys/uvm

2012-08-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Aug 22 21:33:57 UTC 2012

Modified Files:
src/sys/uvm [netbsd-5]: uvm_map.c

Log Message:
Pull up following revision(s) (requested by chs in ticket #1790):
sys/uvm/uvm_map.c: revision 1.319
avoid leaking a uvm_object reference when merging a new map entry
with the entries on both sides.  fixes PR 46807.


To generate a diff of this commit:
cvs rdiff -u -r1.263.4.4 -r1.263.4.5 src/sys/uvm/uvm_map.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_map.c
diff -u src/sys/uvm/uvm_map.c:1.263.4.4 src/sys/uvm/uvm_map.c:1.263.4.5
--- src/sys/uvm/uvm_map.c:1.263.4.4	Sun Nov 21 18:09:00 2010
+++ src/sys/uvm/uvm_map.c	Wed Aug 22 21:33:56 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_map.c,v 1.263.4.4 2010/11/21 18:09:00 riz Exp $	*/
+/*	$NetBSD: uvm_map.c,v 1.263.4.5 2012/08/22 21:33:56 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.263.4.4 2010/11/21 18:09:00 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.263.4.5 2012/08/22 21:33:56 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvmhist.h"
@@ -1560,9 +1560,8 @@ forwardmerge:
 		/*
 		 * drop our reference to uobj since we are extending a reference
 		 * that we already have (the ref count can not drop to zero).
-		 * (if merged, we've already detached)
 		 */
-		if (uobj && uobj->pgops->pgo_detach && !merged)
+		if (uobj && uobj->pgops->pgo_detach)
 			uobj->pgops->pgo_detach(uobj);
 
 		if (merged) {



CVS commit: [netbsd-5] src/sys/uvm

2011-11-18 Thread Stephen Borrill
Module Name:src
Committed By:   sborrill
Date:   Fri Nov 18 22:42:47 UTC 2011

Modified Files:
src/sys/uvm [netbsd-5]: uvm_meter.c

Log Message:
Pull up the following revisions(s) (requested by christos in ticket #1691):
sys/uvm/uvm_meter.c:revision 1.57

Dereference correct variable and thus stop a sysctl crash.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.49.8.1 src/sys/uvm/uvm_meter.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_meter.c
diff -u src/sys/uvm/uvm_meter.c:1.49 src/sys/uvm/uvm_meter.c:1.49.8.1
--- src/sys/uvm/uvm_meter.c:1.49	Wed Jun  4 12:45:28 2008
+++ src/sys/uvm/uvm_meter.c	Fri Nov 18 22:42:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_meter.c,v 1.49 2008/06/04 12:45:28 ad Exp $	*/
+/*	$NetBSD: uvm_meter.c,v 1.49.8.1 2011/11/18 22:42:47 sborrill Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.49 2008/06/04 12:45:28 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.49.8.1 2011/11/18 22:42:47 sborrill Exp $");
 
 #include 
 #include 
@@ -152,7 +152,7 @@ sysctl_vm_uvmexp(SYSCTLFN_ARGS)
 	struct sysctlnode node;
 
 	node = *rnode;
-	if (oldp)
+	if (oldlenp)
 		node.sysctl_size = min(*oldlenp, node.sysctl_size);
 
 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));



CVS commit: [netbsd-5] src/sys/uvm

2010-11-21 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Sun Nov 21 18:09:00 UTC 2010

Modified Files:
src/sys/uvm [netbsd-5]: uvm_bio.c uvm_fault.c uvm_map.c uvm_pager.c

Log Message:
Pull up following revision(s) (requested by rmind in ticket #1421):
sys/uvm/uvm_bio.c: revision 1.70
sys/uvm/uvm_map.c: revision 1.292
sys/uvm/uvm_pager.c: revision 1.98
sys/uvm/uvm_fault.c: revision 1.175
sys/uvm/uvm_bio.c: revision 1.69
ubc_fault: split-off code part handling a single page into ubc_fault_page().
Keep the lock around pmap_update() where required.  While fixing this
in ubc_fault(), rework logic to "remember" the last object of page and
reduce locking overhead, since in common case pages belong to one and
the same UVM object (but not always, therefore add a comment).
Unlocks before pmap_update(), on removal of mappings, might cause TLB
coherency issues, since on architectures like x86 and mips64 invalidation
IPIs are deferred to pmap_update().  Hence, VA space might be globally
visible before IPIs are sent or while they are still in-flight.
OK a...@.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.65.10.1 src/sys/uvm/uvm_bio.c
cvs rdiff -u -r1.125.6.1 -r1.125.6.2 src/sys/uvm/uvm_fault.c
cvs rdiff -u -r1.263.4.3 -r1.263.4.4 src/sys/uvm/uvm_map.c
cvs rdiff -u -r1.92 -r1.92.14.1 src/sys/uvm/uvm_pager.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_bio.c
diff -u src/sys/uvm/uvm_bio.c:1.65 src/sys/uvm/uvm_bio.c:1.65.10.1
--- src/sys/uvm/uvm_bio.c:1.65	Mon May  5 17:11:17 2008
+++ src/sys/uvm/uvm_bio.c	Sun Nov 21 18:09:00 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_bio.c,v 1.65 2008/05/05 17:11:17 ad Exp $	*/
+/*	$NetBSD: uvm_bio.c,v 1.65.10.1 2010/11/21 18:09:00 riz Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.65 2008/05/05 17:11:17 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.65.10.1 2010/11/21 18:09:00 riz Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -215,6 +215,82 @@
 }
 
 /*
+ * ubc_fault_page: helper of ubc_fault to handle a single page.
+ *
+ * => Caller has UVM object locked.
+ */
+
+static inline int
+ubc_fault_page(const struct uvm_faultinfo *ufi, const struct ubc_map *umap,
+struct vm_page *pg, vm_prot_t prot, vm_prot_t access_type, vaddr_t va)
+{
+	struct uvm_object *uobj;
+	vm_prot_t mask;
+	int error;
+	bool rdonly;
+
+	uobj = pg->uobject;
+	KASSERT(mutex_owned(&uobj->vmobjlock));
+
+	if (pg->flags & PG_WANTED) {
+		wakeup(pg);
+	}
+	KASSERT((pg->flags & PG_FAKE) == 0);
+	if (pg->flags & PG_RELEASED) {
+		mutex_enter(&uvm_pageqlock);
+		uvm_pagefree(pg);
+		mutex_exit(&uvm_pageqlock);
+		return 0;
+	}
+	if (pg->loan_count != 0) {
+
+		/*
+		 * Avoid unneeded loan break, if possible.
+		 */
+
+		if ((access_type & VM_PROT_WRITE) == 0) {
+			prot &= ~VM_PROT_WRITE;
+		}
+		if (prot & VM_PROT_WRITE) {
+			struct vm_page *newpg;
+
+			newpg = uvm_loanbreak(pg);
+			if (newpg == NULL) {
+uvm_page_unbusy(&pg, 1);
+return ENOMEM;
+			}
+			pg = newpg;
+		}
+	}
+
+	/*
+	 * Note that a page whose backing store is partially allocated
+	 * is marked as PG_RDONLY.
+	 */
+
+	KASSERT((pg->flags & PG_RDONLY) == 0 ||
+	(access_type & VM_PROT_WRITE) == 0 ||
+	pg->offset < umap->writeoff ||
+	pg->offset + PAGE_SIZE > umap->writeoff + umap->writelen);
+
+	rdonly = ((access_type & VM_PROT_WRITE) == 0 &&
+	(pg->flags & PG_RDONLY) != 0) ||
+	UVM_OBJ_NEEDS_WRITEFAULT(uobj);
+	mask = rdonly ? ~VM_PROT_WRITE : VM_PROT_ALL;
+
+	error = pmap_enter(ufi->orig_map->pmap, va, VM_PAGE_TO_PHYS(pg),
+	prot & mask, PMAP_CANFAIL | (access_type & mask));
+
+	mutex_enter(&uvm_pageqlock);
+	uvm_pageactivate(pg);
+	mutex_exit(&uvm_pageqlock);
+	pg->flags &= ~(PG_BUSY|PG_WANTED);
+	UVM_PAGE_OWN(pg, NULL);
+
+	return error;
+}
+
+/*
  * ubc_fault: fault routine for ubc mapping
  */
 
@@ -225,10 +301,11 @@
 	struct uvm_object *uobj;
 	struct ubc_map *umap;
 	vaddr_t va, eva, ubc_offset, slot_offset;
+	struct vm_page *pgs[ubc_winsize >> PAGE_SHIFT];
 	int i, error, npages;
-	struct vm_page *pgs[ubc_winsize >> PAGE_SHIFT], *pg;
 	vm_prot_t prot;
-	UVMHIST_FUNC("ubc_fault");  UVMHIST_CALLED(ubchist);
+
+	UVMHIST_FUNC("ubc_fault"); UVMHIST_CALLED(ubchist);
 
 	/*
 	 * no need to try with PGO_LOCKED...
@@ -299,106 +376,75 @@
 	0);
 
 	if (error == EAGAIN) {
-		kpause("ubc_fault", false, hz, NULL);
+		kpause("ubc_fault", false, hz >> 2, NULL);
 		goto again;
 	}
 	if (error) {
 		return error;
 	}
 
+	/*
+	 * For virtually-indexed, virtually-tagged caches we should avoid
+	 * creating writable mappings when we do not absolutely need them,
+	 * since the "compatible alias" trick does not work on such caches.
+	 * Otherwise, we can always map the pages writable.
+	 */
+
+#ifdef PMAP_CACHE_VIVT
+	prot = VM_PROT_READ | access_type;
+#else
+	pro

CVS commit: [netbsd-5] src/sys/uvm

2009-04-19 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sun Apr 19 15:43:14 UTC 2009

Modified Files:
src/sys/uvm [netbsd-5]: uvm_km.c uvm_km.h uvm_map.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #708):
sys/uvm/uvm_km.c: revision 1.102
sys/uvm/uvm_km.h: revision 1.18
sys/uvm/uvm_map.c: revision 1.264
PR port-amd64/32816 amd64 can not load lkms
Change some assertions to partially allow for VM_MAP_IS_KERNEL(map) where
map is outside the range of kernel_map.


To generate a diff of this commit:
cvs rdiff -u -r1.101.4.1 -r1.101.4.2 src/sys/uvm/uvm_km.c
cvs rdiff -u -r1.17 -r1.17.54.1 src/sys/uvm/uvm_km.h
cvs rdiff -u -r1.263.4.2 -r1.263.4.3 src/sys/uvm/uvm_map.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_km.c
diff -u src/sys/uvm/uvm_km.c:1.101.4.1 src/sys/uvm/uvm_km.c:1.101.4.2
--- src/sys/uvm/uvm_km.c:1.101.4.1	Sat Dec 27 18:26:22 2008
+++ src/sys/uvm/uvm_km.c	Sun Apr 19 15:43:14 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_km.c,v 1.101.4.1 2008/12/27 18:26:22 snj Exp $	*/
+/*	$NetBSD: uvm_km.c,v 1.101.4.2 2009/04/19 15:43:14 snj Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.101.4.1 2008/12/27 18:26:22 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.101.4.2 2009/04/19 15:43:14 snj Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -462,15 +462,16 @@
  */
 
 void
-uvm_km_pgremove_intrsafe(vaddr_t start, vaddr_t end)
+uvm_km_pgremove_intrsafe(struct vm_map *map, vaddr_t start, vaddr_t end)
 {
 	struct vm_page *pg;
 	paddr_t pa;
 	UVMHIST_FUNC("uvm_km_pgremove_intrsafe"); UVMHIST_CALLED(maphist);
 
-	KASSERT(VM_MIN_KERNEL_ADDRESS <= start);
+	KASSERT(VM_MAP_IS_KERNEL(map));
+	KASSERT(vm_map_min(map) <= start);
 	KASSERT(start < end);
-	KASSERT(end <= VM_MAX_KERNEL_ADDRESS);
+	KASSERT(end <= vm_map_max(map));
 
 	for (; start < end; start += PAGE_SIZE) {
 		if (!pmap_extract(pmap_kernel(), start, &pa)) {
@@ -485,23 +486,23 @@
 
 #if defined(DEBUG)
 void
-uvm_km_check_empty(vaddr_t start, vaddr_t end, bool intrsafe)
+uvm_km_check_empty(struct vm_map *map, vaddr_t start, vaddr_t end)
 {
+	struct vm_page *pg;
 	vaddr_t va;
 	paddr_t pa;
 
-	KDASSERT(VM_MIN_KERNEL_ADDRESS <= start);
+	KDASSERT(VM_MAP_IS_KERNEL(map));
+	KDASSERT(vm_map_min(map) <= start);
 	KDASSERT(start < end);
-	KDASSERT(end <= VM_MAX_KERNEL_ADDRESS);
+	KDASSERT(end <= vm_map_max(map));
 
 	for (va = start; va < end; va += PAGE_SIZE) {
 		if (pmap_extract(pmap_kernel(), va, &pa)) {
 			panic("uvm_km_check_empty: va %p has pa 0x%llx",
 			(void *)va, (long long)pa);
 		}
-		if (!intrsafe) {
-			const struct vm_page *pg;
-
+		if ((map->flags & VM_MAP_INTRSAFE) == 0) {
 			mutex_enter(&uvm_kernel_object->vmobjlock);
 			pg = uvm_pagelookup(uvm_kernel_object,
 			va - vm_map_min(kernel_map));
@@ -657,7 +658,7 @@
 		uvm_km_pgremove(addr, addr + size);
 		pmap_remove(pmap_kernel(), addr, addr + size);
 	} else if (flags & UVM_KMF_WIRED) {
-		uvm_km_pgremove_intrsafe(addr, addr + size);
+		uvm_km_pgremove_intrsafe(map, addr, addr + size);
 		pmap_kremove(addr, size);
 	}
 
@@ -767,7 +768,7 @@
 	}
 
 	KASSERT(pmap_extract(pmap_kernel(), addr, NULL));
-	uvm_km_pgremove_intrsafe(addr, addr + PAGE_SIZE);
+	uvm_km_pgremove_intrsafe(map, addr, addr + PAGE_SIZE);
 	pmap_kremove(addr, PAGE_SIZE);
 #if defined(DEBUG)
 	pmap_update(pmap_kernel());

Index: src/sys/uvm/uvm_km.h
diff -u src/sys/uvm/uvm_km.h:1.17 src/sys/uvm/uvm_km.h:1.17.54.1
--- src/sys/uvm/uvm_km.h:1.17	Wed Feb 21 23:00:13 2007
+++ src/sys/uvm/uvm_km.h	Sun Apr 19 15:43:14 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_km.h,v 1.17 2007/02/21 23:00:13 thorpej Exp $	*/
+/*	$NetBSD: uvm_km.h,v 1.17.54.1 2009/04/19 15:43:14 snj Exp $	*/
 
 /*
  *
@@ -49,9 +49,9 @@
 
 void uvm_km_init(vaddr_t, vaddr_t);
 void uvm_km_pgremove(vaddr_t, vaddr_t);
-void uvm_km_pgremove_intrsafe(vaddr_t, vaddr_t);
+void uvm_km_pgremove_intrsafe(struct vm_map *, vaddr_t, vaddr_t);
 #if defined(DEBUG)
-void uvm_km_check_empty(vaddr_t, vaddr_t, bool);
+void uvm_km_check_empty(struct vm_map *, vaddr_t, vaddr_t);
 #else
 #define	uvm_km_check_empty(a, b, c)	/* nothing */
 #endif /* defined(DEBUG) */

Index: src/sys/uvm/uvm_map.c
diff -u src/sys/uvm/uvm_map.c:1.263.4.2 src/sys/uvm/uvm_map.c:1.263.4.3
--- src/sys/uvm/uvm_map.c:1.263.4.2	Mon Feb  2 18:31:37 2009
+++ src/sys/uvm/uvm_map.c	Sun Apr 19 15:43:14 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_map.c,v 1.263.4.2 2009/02/02 18:31:37 snj Exp $	*/
+/*	$NetBSD: uvm_map.c,v 1.263.4.3 2009/04/19 15:43:14 snj Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.263.4.2 2009/02/02 18:31:37 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.263.4.3 2009/04/19 15:43:14 snj Exp $");
 
 #include "opt_ddb.h"
 #in