Subject: cleanup of uvm_fault*() interfaces
To: None <tech-kern@netbsd.org>
From: Matthias Drochner <M.Drochner@fz-juelich.de>
List: tech-kern
Date: 03/02/2006 14:42:32
This is a multipart MIME message.

--==_Exmh_195201686240
Content-Type: text/plain; charset=us-ascii


Now that the fault_type argument to uvm_fault() is
a dummy everywhere and vm_fault_t has no meaning
anymore outside uvm's internal use, we could clean
up the interface a bit. Opinions?
(and all calls from md trap.c would get the "0"
stripped out)

best regards
Matthias



--==_Exmh_195201686240
Content-Type: text/plain ; name="fault.txt"; charset=us-ascii
Content-Description: fault.txt
Content-Disposition: attachment; filename="fault.txt"

Index: uvm_extern.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_extern.h,v
retrieving revision 1.111
diff -u -p -r1.111 uvm_extern.h
--- uvm_extern.h	1 Mar 2006 12:38:44 -0000	1.111
+++ uvm_extern.h	2 Mar 2006 13:19:39 -0000
@@ -84,7 +84,6 @@
  */
 
 typedef unsigned int uvm_flag_t;
-typedef int vm_fault_t;
 
 typedef int vm_inherit_t;	/* XXX: inheritance codes */
 typedef off_t voff_t;		/* XXX: offset within a uvm_object */
@@ -575,8 +574,7 @@ void			ubc_release(void *, int);
 void			ubc_flush(struct uvm_object *, voff_t, voff_t);
 
 /* uvm_fault.c */
-int			uvm_fault(struct vm_map *, vaddr_t, vm_fault_t,
-			    vm_prot_t);
+int			uvm_fault(struct vm_map *, vaddr_t, vm_prot_t);
 				/* handle a page fault */
 
 /* uvm_glue.c */
Index: uvm_fault.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_fault.c,v
retrieving revision 1.109
diff -u -p -r1.109 uvm_fault.c
--- uvm_fault.c	22 Feb 2006 22:28:18 -0000	1.109
+++ uvm_fault.c	2 Mar 2006 13:19:39 -0000
@@ -690,9 +690,12 @@ done:
 #define MASK(entry)     (UVM_ET_ISCOPYONWRITE(entry) ? \
 			 ~VM_PROT_WRITE : VM_PROT_ALL)
 
-int
-uvm_fault(struct vm_map *orig_map, vaddr_t vaddr, vm_fault_t fault_type,
-    vm_prot_t access_type)
+#define UVM_FAULT_WIRE 1
+#define UVM_FAULT_WIREMAX 2
+
+static int
+uvm_fault_internal(struct vm_map *orig_map, vaddr_t vaddr,
+    vm_prot_t access_type, int fault_flag)
 {
 	struct uvm_faultinfo ufi;
 	vm_prot_t enter_prot, check_prot;
@@ -707,8 +710,8 @@ uvm_fault(struct vm_map *orig_map, vaddr
 	struct vm_page *pages[UVM_MAXRANGE], *pg, *uobjpage;
 	UVMHIST_FUNC("uvm_fault"); UVMHIST_CALLED(maphist);
 
-	UVMHIST_LOG(maphist, "(map=0x%x, vaddr=0x%x, ft=%d, at=%d)",
-	      orig_map, vaddr, fault_type, access_type);
+	UVMHIST_LOG(maphist, "(map=0x%x, vaddr=0x%x, at=%d, ff=%d)",
+	      orig_map, vaddr, access_type, fault_flag);
 
 	anon = anon_spare = NULL;
 	pg = NULL;
@@ -722,8 +725,7 @@ uvm_fault(struct vm_map *orig_map, vaddr
 	ufi.orig_map = orig_map;
 	ufi.orig_rvaddr = trunc_page(vaddr);
 	ufi.orig_size = PAGE_SIZE;	/* can't get any smaller than this */
-	wire_fault = fault_type == VM_FAULT_WIRE ||
-	    fault_type == VM_FAULT_WIREMAX;
+	wire_fault = (fault_flag > 0);
 	if (wire_fault)
 		narrow = TRUE;		/* don't look for neighborhood
 					 * pages on wire */
@@ -760,7 +762,7 @@ ReFault:
 	 * check protection
 	 */
 
-	check_prot = fault_type == VM_FAULT_WIREMAX ?
+	check_prot = fault_flag == UVM_FAULT_WIREMAX ?
 	    ufi.entry->max_protection : ufi.entry->protection;
 	if ((check_prot & access_type) != access_type) {
 		UVMHIST_LOG(maphist,
@@ -795,7 +797,7 @@ ReFault:
 	 */
 
 	if (UVM_ET_ISNEEDSCOPY(ufi.entry)) {
-		KASSERT(fault_type != VM_FAULT_WIREMAX);
+		KASSERT(fault_flag != UVM_FAULT_WIREMAX);
 		if (cow_now || (ufi.entry->object.uvm_obj == NULL)) {
 			/* need to clear */
 			UVMHIST_LOG(maphist,
@@ -1807,6 +1809,13 @@ done:
 	return error;
 }
 
+int
+uvm_fault(struct vm_map *orig_map, vaddr_t vaddr, vm_prot_t access_type)
+{
+
+	return uvm_fault_internal(orig_map, vaddr, access_type, 0);
+}
+
 /*
  * uvm_fault_wire: wire down a range of virtual addresses in a map.
  *
@@ -1818,7 +1827,7 @@ done:
 
 int
 uvm_fault_wire(struct vm_map *map, vaddr_t start, vaddr_t end,
-    vm_fault_t fault_type, vm_prot_t access_type)
+    vm_prot_t access_type, int wiremax)
 {
 	vaddr_t va;
 	int error;
@@ -1838,7 +1847,8 @@ uvm_fault_wire(struct vm_map *map, vaddr
 	}
 
 	for (va = start ; va < end ; va += PAGE_SIZE) {
-		error = uvm_fault(map, va, fault_type, access_type);
+		error = uvm_fault_internal(map, va, access_type,
+				wiremax ? UVM_FAULT_WIREMAX : UVM_FAULT_WIRE);
 		if (error) {
 			if (va != start) {
 				uvm_fault_unwire(map, start, va);
Index: uvm_fault.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_fault.h,v
retrieving revision 1.18
diff -u -p -r1.18 uvm_fault.h
--- uvm_fault.h	11 Dec 2005 12:25:29 -0000	1.18
+++ uvm_fault.h	2 Mar 2006 13:19:39 -0000
@@ -38,15 +38,6 @@
 #define _UVM_UVM_FAULT_H_
 
 /*
- * fault types
- */
-
-#define VM_FAULT_INVALID ((vm_fault_t) 0x0)	/* invalid mapping */
-#define VM_FAULT_PROTECT ((vm_fault_t) 0x1)	/* protection */
-#define VM_FAULT_WIRE	 ((vm_fault_t) 0x2)	/* wire mapping */
-#define VM_FAULT_WIREMAX ((vm_fault_t) 0x3)	/* wire, allow maxprot */
-
-/*
  * fault data structures
  */
 
@@ -75,8 +66,7 @@ struct uvm_faultinfo {
 int uvmfault_anonget(struct uvm_faultinfo *, struct vm_amap *,
 		     struct vm_anon *);
 
-int uvm_fault_wire(struct vm_map *, vaddr_t, vaddr_t, vm_fault_t,
-		   vm_prot_t);
+int uvm_fault_wire(struct vm_map *, vaddr_t, vaddr_t, vm_prot_t, int);
 void uvm_fault_unwire(struct vm_map *, vaddr_t, vaddr_t);
 void uvm_fault_unwire_locked(struct vm_map *, vaddr_t, vaddr_t);
 
Index: uvm_glue.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_glue.c,v
retrieving revision 1.92
diff -u -p -r1.92 uvm_glue.c
--- uvm_glue.c	24 Dec 2005 23:41:34 -0000	1.92
+++ uvm_glue.c	2 Mar 2006 13:19:39 -0000
@@ -178,7 +178,7 @@ uvm_vslock(struct proc *p, caddr_t addr,
 	map = &p->p_vmspace->vm_map;
 	start = trunc_page((vaddr_t)addr);
 	end = round_page((vaddr_t)addr + len);
-	error = uvm_fault_wire(map, start, end, VM_FAULT_WIRE, access_type);
+	error = uvm_fault_wire(map, start, end, access_type, 0);
 	return error;
 }
 
@@ -249,8 +249,7 @@ uvm_lwp_fork(struct lwp *l1, struct lwp 
 
 	if ((l2->l_flag & L_INMEM) == 0) {
 		error = uvm_fault_wire(kernel_map, (vaddr_t)up,
-		    (vaddr_t)up + USPACE, VM_FAULT_WIRE,
-		    VM_PROT_READ | VM_PROT_WRITE);
+		    (vaddr_t)up + USPACE, VM_PROT_READ | VM_PROT_WRITE, 0);
 		if (error)
 			panic("uvm_lwp_fork: uvm_fault_wire failed: %d", error);
 #ifdef PMAP_UAREA
@@ -428,8 +427,8 @@ uvm_swapin(struct lwp *l)
 
 	addr = (vaddr_t)l->l_addr;
 	/* make L_INMEM true */
-	error = uvm_fault_wire(kernel_map, addr, addr + USPACE, VM_FAULT_WIRE,
-	    VM_PROT_READ | VM_PROT_WRITE);
+	error = uvm_fault_wire(kernel_map, addr, addr + USPACE,
+	    VM_PROT_READ | VM_PROT_WRITE, 0);
 	if (error) {
 		panic("uvm_swapin: rewiring stack failed: %d", error);
 	}
Index: uvm_map.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_map.c,v
retrieving revision 1.215
diff -u -p -r1.215 uvm_map.c
--- uvm_map.c	1 Mar 2006 12:38:44 -0000	1.215
+++ uvm_map.c	2 Mar 2006 13:19:39 -0000
@@ -2902,7 +2902,7 @@ uvm_map_advice(struct vm_map *map, vaddr
  *
  * => wires map entries.  should not be used for transient page locking.
  *	for that, use uvm_fault_wire()/uvm_fault_unwire() (see uvm_vslock()).
- * => regions sepcified as not pageable require lock-down (wired) memory
+ * => regions specified as not pageable require lock-down (wired) memory
  *	and page tables.
  * => map must never be read-locked
  * => if islocked is TRUE, map is already write-locked
@@ -3076,7 +3076,7 @@ uvm_map_pageable(struct vm_map *map, vad
 	while (entry != &map->header && entry->start < end) {
 		if (entry->wired_count == 1) {
 			rv = uvm_fault_wire(map, entry->start, entry->end,
-			    VM_FAULT_WIREMAX, entry->max_protection);
+			    entry->max_protection, 1);
 			if (rv) {
 
 				/*
@@ -3307,7 +3307,7 @@ uvm_map_pageable_all(struct vm_map *map,
 	     entry = entry->next) {
 		if (entry->wired_count == 1) {
 			rv = uvm_fault_wire(map, entry->start, entry->end,
-			    VM_FAULT_WIREMAX, entry->max_protection);
+			    entry->max_protection, 1);
 			if (rv) {
 
 				/*

--==_Exmh_195201686240--