CVS commit: src/external/gpl3/gcc/dist/gcc/config/i386

2012-09-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Sep 14 13:00:01 UTC 2012

Modified Files:
src/external/gpl3/gcc/dist/gcc/config/i386: i386.c netbsd-elf.h
netbsd64.h

Log Message:
Fix GCC to correctly implement the i386 psABI on NetBSD.
This consists of two parts:
- for NetBSD/i386 and NetBSD/AMD64 with -m32, use a default stack
  alignment of 23bit as specified by the ABI
- ensure that double and long long variables on the stack are by default
  only aligned to 32bit, if there is nothing else in the function
  needing a larger stack alignment

The combination ensures that SSE variables on the stack trigger the
realignment logic, but just using double or long long doesn't.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 \
src/external/gpl3/gcc/dist/gcc/config/i386/i386.c \
src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h
cvs rdiff -u -r1.2 -r1.3 \
src/external/gpl3/gcc/dist/gcc/config/i386/netbsd-elf.h

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

Modified files:

Index: src/external/gpl3/gcc/dist/gcc/config/i386/i386.c
diff -u src/external/gpl3/gcc/dist/gcc/config/i386/i386.c:1.1.1.1 src/external/gpl3/gcc/dist/gcc/config/i386/i386.c:1.2
--- src/external/gpl3/gcc/dist/gcc/config/i386/i386.c:1.1.1.1	Tue Jun 21 01:22:07 2011
+++ src/external/gpl3/gcc/dist/gcc/config/i386/i386.c	Fri Sep 14 13:00:01 2012
@@ -20104,7 +20104,9 @@ ix86_local_alignment (tree exp, enum mac
   if (!TARGET_64BIT
align == 64
ix86_preferred_stack_boundary  64
-   (mode == DImode || (type  TYPE_MODE (type) == DImode))
+   (mode == DImode || (type  TYPE_MODE (type) == DImode)
+  || mode == DFmode || (type  TYPE_MODE (type) == DFmode)
+  || mode == DCmode || (type  TYPE_MODE (type) == DCmode))
(!type || !TYPE_USER_ALIGN (type))
(!decl || !DECL_USER_ALIGN (decl)))
 align = 32;
@@ -20150,7 +20152,8 @@ ix86_local_alignment (tree exp, enum mac
 	|| TREE_CODE (type) == QUAL_UNION_TYPE)
 	TYPE_FIELDS (type))
 {
-  if (DECL_MODE (TYPE_FIELDS (type)) == DFmode  align  64)
+  if (DECL_MODE (TYPE_FIELDS (type)) == DFmode  align  64
+   (TARGET_64BIT || ix86_preferred_stack_boundary = 64))
 	return 64;
   if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type)))  align  128)
 	return 128;
@@ -20159,7 +20162,8 @@ ix86_local_alignment (tree exp, enum mac
 	   || TREE_CODE (type) == INTEGER_TYPE)
 {
 
-  if (TYPE_MODE (type) == DFmode  align  64)
+  if (TYPE_MODE (type) == DFmode  align  64
+   (TARGET_64BIT || ix86_preferred_stack_boundary = 64))
 	return 64;
   if (ALIGN_MODE_128 (TYPE_MODE (type))  align  128)
 	return 128;
Index: src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h
diff -u src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h:1.1.1.1 src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h:1.2
--- src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h:1.1.1.1	Tue Jun 21 01:22:04 2011
+++ src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h	Fri Sep 14 13:00:01 2012
@@ -70,3 +70,7 @@ along with GCC; see the file COPYING3.  
 #define ENABLE_EXECUTE_STACK NETBSD_ENABLE_EXECUTE_STACK
 
 #define TARGET_VERSION fprintf (stderr,  (NetBSD/x86_64 ELF));
+
+/* Preserve i386 psABI  */
+#undef PREFERRED_STACK_BOUNDARY_DEFAULT
+#define PREFERRED_STACK_BOUNDARY_DEFAULT MIN_STACK_BOUNDARY

Index: src/external/gpl3/gcc/dist/gcc/config/i386/netbsd-elf.h
diff -u src/external/gpl3/gcc/dist/gcc/config/i386/netbsd-elf.h:1.2 src/external/gpl3/gcc/dist/gcc/config/i386/netbsd-elf.h:1.3
--- src/external/gpl3/gcc/dist/gcc/config/i386/netbsd-elf.h:1.2	Thu Feb  2 13:07:33 2012
+++ src/external/gpl3/gcc/dist/gcc/config/i386/netbsd-elf.h	Fri Sep 14 13:00:01 2012
@@ -126,3 +126,7 @@ along with GCC; see the file COPYING3.  
 #undef X87_ENABLE_ARITH
 #define X87_ENABLE_ARITH(MODE) \
   (flag_excess_precision == EXCESS_PRECISION_FAST || (MODE) == DFmode)
+
+/* Preserve i386 psABI  */
+#undef PREFERRED_STACK_BOUNDARY_DEFAULT
+#define PREFERRED_STACK_BOUNDARY_DEFAULT MIN_STACK_BOUNDARY



CVS commit: src/usr.sbin/npf/npftest

2012-09-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Sep 14 15:37:03 UTC 2012

Modified Files:
src/usr.sbin/npf/npftest: npftest.c

Log Message:
More __dead


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/npf/npftest/npftest.c

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

Modified files:

Index: src/usr.sbin/npf/npftest/npftest.c
diff -u src/usr.sbin/npf/npftest/npftest.c:1.7 src/usr.sbin/npf/npftest/npftest.c:1.8
--- src/usr.sbin/npf/npftest/npftest.c:1.7	Wed Sep 12 08:47:14 2012
+++ src/usr.sbin/npf/npftest/npftest.c	Fri Sep 14 15:37:03 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: npftest.c,v 1.7 2012/09/12 08:47:14 martin Exp $	*/
+/*	$NetBSD: npftest.c,v 1.8 2012/09/14 15:37:03 joerg Exp $	*/
 
 /*
  * NPF testing framework.
@@ -26,7 +26,7 @@
 
 static bool verbose, quiet;
 
-static void
+__dead static void
 usage(void)
 {
 	printf(usage:\n
@@ -48,7 +48,7 @@ usage(void)
 	exit(EXIT_FAILURE);
 }
 
-static void
+__dead static void
 describe_tests(void)
 {
 	printf(	nbuf\tbasic npf mbuf handling\n



CVS commit: src

2012-09-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Sep 14 16:29:22 UTC 2012

Modified Files:
src/lib/librumpuser: rumpuser.c
src/sys/rump/dev/lib/libscsitest: scsitest.c
src/sys/rump/dev/lib/libugenhc: ugenhc.c
src/sys/rump/include/rump: rumpuser.h
src/sys/rump/librump/rumpvfs: rumpblk.c rumpfs.c
src/sys/rump/net/lib/libshmif: if_shmem.c
src/sys/rump/net/lib/libvirtif: if_virt.c

Log Message:
Do not assume that O_FOO flags have matching values in the rump kernel
and hypervisor.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/librumpuser/rumpuser.c
cvs rdiff -u -r1.3 -r1.4 src/sys/rump/dev/lib/libscsitest/scsitest.c
cvs rdiff -u -r1.10 -r1.11 src/sys/rump/dev/lib/libugenhc/ugenhc.c
cvs rdiff -u -r1.72 -r1.73 src/sys/rump/include/rump/rumpuser.h
cvs rdiff -u -r1.47 -r1.48 src/sys/rump/librump/rumpvfs/rumpblk.c
cvs rdiff -u -r1.110 -r1.111 src/sys/rump/librump/rumpvfs/rumpfs.c
cvs rdiff -u -r1.44 -r1.45 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.26 -r1.27 src/sys/rump/net/lib/libvirtif/if_virt.c

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

Modified files:

Index: src/lib/librumpuser/rumpuser.c
diff -u src/lib/librumpuser/rumpuser.c:1.19 src/lib/librumpuser/rumpuser.c:1.20
--- src/lib/librumpuser/rumpuser.c:1.19	Sat Aug 25 18:00:06 2012
+++ src/lib/librumpuser/rumpuser.c	Fri Sep 14 16:29:22 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser.c,v 1.19 2012/08/25 18:00:06 pooka Exp $	*/
+/*	$NetBSD: rumpuser.c,v 1.20 2012/09/14 16:29:22 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include rumpuser_port.h
 
 #if !defined(lint)
-__RCSID($NetBSD: rumpuser.c,v 1.19 2012/08/25 18:00:06 pooka Exp $);
+__RCSID($NetBSD: rumpuser.c,v 1.20 2012/09/14 16:29:22 pooka Exp $);
 #endif /* !lint */
 
 #include sys/ioctl.h
@@ -317,10 +317,32 @@ rumpuser_memsync(void *addr, size_t len,
 }
 
 int
-rumpuser_open(const char *path, int flags, int *error)
+rumpuser_open(const char *path, int ruflags, int *error)
 {
+	int flags;
 
-	DOCALL(int, (open(path, flags, 0644)));
+	switch (ruflags  RUMPUSER_OPEN_ACCMODE) {
+	case RUMPUSER_OPEN_RDONLY:
+		flags = O_RDONLY;
+		break;
+	case RUMPUSER_OPEN_WRONLY:
+		flags = O_WRONLY;
+		break;
+	case RUMPUSER_OPEN_RDWR:
+		flags = O_RDWR;
+		break;
+	default:
+		*error = EINVAL;
+		return -1;
+	}
+
+#define TESTSET(_ru_, _h_) if (ruflags  _ru_) flags |= _h_;
+	TESTSET(RUMPUSER_OPEN_CREATE, O_CREAT);
+	TESTSET(RUMPUSER_OPEN_EXCL, O_EXCL);
+	TESTSET(RUMPUSER_OPEN_DIRECT, O_DIRECT);
+#undef TESTSET
+
+	DOCALL_KLOCK(int, (open(path, flags, 0644)));
 }
 
 int

Index: src/sys/rump/dev/lib/libscsitest/scsitest.c
diff -u src/sys/rump/dev/lib/libscsitest/scsitest.c:1.3 src/sys/rump/dev/lib/libscsitest/scsitest.c:1.4
--- src/sys/rump/dev/lib/libscsitest/scsitest.c:1.3	Sun May  6 16:58:31 2012
+++ src/sys/rump/dev/lib/libscsitest/scsitest.c	Fri Sep 14 16:29:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsitest.c,v 1.3 2012/05/06 16:58:31 martin Exp $	*/
+/*	$NetBSD: scsitest.c,v 1.4 2012/09/14 16:29:21 pooka Exp $	*/
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -35,7 +35,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: scsitest.c,v 1.3 2012/05/06 16:58:31 martin Exp $);
+__KERNEL_RCSID(0, $NetBSD: scsitest.c,v 1.4 2012/09/14 16:29:21 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -218,7 +218,7 @@ scsitest_match(struct device *parent, st
 		return 0;
 	mycdsize = fsize / CDBLOCKSIZE;
 
-	if ((isofd = rumpuser_open(MYCDISO, O_RDWR, error)) == -1)
+	if ((isofd = rumpuser_open(MYCDISO, RUMPUSER_OPEN_RDWR, error)) == -1)
 		return 0;
 #else
 	/*

Index: src/sys/rump/dev/lib/libugenhc/ugenhc.c
diff -u src/sys/rump/dev/lib/libugenhc/ugenhc.c:1.10 src/sys/rump/dev/lib/libugenhc/ugenhc.c:1.11
--- src/sys/rump/dev/lib/libugenhc/ugenhc.c:1.10	Sun Jun 10 06:15:55 2012
+++ src/sys/rump/dev/lib/libugenhc/ugenhc.c	Fri Sep 14 16:29:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugenhc.c,v 1.10 2012/06/10 06:15:55 mrg Exp $	*/
+/*	$NetBSD: ugenhc.c,v 1.11 2012/09/14 16:29:21 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ugenhc.c,v 1.10 2012/06/10 06:15:55 mrg Exp $);
+__KERNEL_RCSID(0, $NetBSD: ugenhc.c,v 1.11 2012/09/14 16:29:21 pooka Exp $);
 
 #include sys/param.h
 #include sys/bus.h
@@ -602,7 +602,7 @@ rhscintr(void *arg)
 		 */
 
 		for (;;) {
-			fd = rumpuser_open(buf, O_RDWR, error);
+			fd = rumpuser_open(buf, RUMPUSER_OPEN_RDWR, error);
 			if (fd != -1)
 break;
 			kpause(ugwait, false, hz/4, NULL);
@@ -627,7 +627,7 @@ rhscintr(void *arg)
 		 */
 
 		for (;;) {
-			fd = rumpuser_open(buf, O_RDWR, error);
+			fd = rumpuser_open(buf, RUMPUSER_OPEN_RDWR, error);
 			if (fd == -1)
 break;
 
@@ -971,6 +971,7 @@ ugenhc_open(struct usbd_pipe 

CVS commit: src/sys/uvm

2012-09-14 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Fri Sep 14 18:56:15 UTC 2012

Modified Files:
src/sys/uvm: uvm_aobj.c uvm_aobj.h

Log Message:
- Describe uvm_aobj and the lock order.
- Remove unnecessary uao_dropswap_range1() wrapper.
- KNF.  Sprinkle some __cacheline_aligned.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/uvm/uvm_aobj.c
cvs rdiff -u -r1.21 -r1.22 src/sys/uvm/uvm_aobj.h

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_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.116 src/sys/uvm/uvm_aobj.c:1.117
--- src/sys/uvm/uvm_aobj.c:1.116	Tue Sep  6 16:41:55 2011
+++ src/sys/uvm/uvm_aobj.c	Fri Sep 14 18:56:15 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.116 2011/09/06 16:41:55 matt Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.117 2012/09/14 18:56:15 rmind Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: uvm_aobj.c,v 1.116 2011/09/06 16:41:55 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: uvm_aobj.c,v 1.117 2012/09/14 18:56:15 rmind Exp $);
 
 #include opt_uvmhist.h
 
@@ -52,66 +52,55 @@ __KERNEL_RCSID(0, $NetBSD: uvm_aobj.c,v
 #include uvm/uvm.h
 
 /*
- * an aobj manages anonymous-memory backed uvm_objects.   in addition
- * to keeping the list of resident pages, it also keeps a list of
- * allocated swap blocks.  depending on the size of the aobj this list
- * of allocated swap blocks is either stored in an array (small objects)
- * or in a hash table (large objects).
- */
-
-/*
- * local structures
+ * An anonymous UVM object (aobj) manages anonymous-memory.  In addition to
+ * keeping the list of resident pages, it may also keep a list of allocated
+ * swap blocks.  Depending on the size of the object, this list is either
+ * stored in an array (small objects) or in a hash table (large objects).
+ *
+ * Lock order
+ *
+ *	uvm_object::vmobjlock -
+ *		uao_list_lock
  */
 
 /*
- * for hash tables, we break the address space of the aobj into blocks
- * of UAO_SWHASH_CLUSTER_SIZE pages.   we require the cluster size to
- * be a power of two.
+ * Note: for hash tables, we break the address space of the aobj into blocks
+ * of UAO_SWHASH_CLUSTER_SIZE pages, which shall be a power of two.
  */
 
-#define UAO_SWHASH_CLUSTER_SHIFT 4
-#define UAO_SWHASH_CLUSTER_SIZE (1  UAO_SWHASH_CLUSTER_SHIFT)
+#define	UAO_SWHASH_CLUSTER_SHIFT	4
+#define	UAO_SWHASH_CLUSTER_SIZE		(1  UAO_SWHASH_CLUSTER_SHIFT)
 
-/* get the tag for this page index */
-#define UAO_SWHASH_ELT_TAG(PAGEIDX) \
-	((PAGEIDX)  UAO_SWHASH_CLUSTER_SHIFT)
+/* Get the tag for this page index. */
+#define	UAO_SWHASH_ELT_TAG(idx)		((idx)  UAO_SWHASH_CLUSTER_SHIFT)
+#define UAO_SWHASH_ELT_PAGESLOT_IDX(idx) \
+((idx)  (UAO_SWHASH_CLUSTER_SIZE - 1))
 
-#define UAO_SWHASH_ELT_PAGESLOT_IDX(PAGEIDX) \
-	((PAGEIDX)  (UAO_SWHASH_CLUSTER_SIZE - 1))
+/* Given an ELT and a page index, find the swap slot. */
+#define	UAO_SWHASH_ELT_PAGESLOT(elt, idx) \
+((elt)-slots[UAO_SWHASH_ELT_PAGESLOT_IDX(idx)])
 
-/* given an ELT and a page index, find the swap slot */
-#define UAO_SWHASH_ELT_PAGESLOT(ELT, PAGEIDX) \
-	((ELT)-slots[UAO_SWHASH_ELT_PAGESLOT_IDX(PAGEIDX)])
+/* Given an ELT, return its pageidx base. */
+#define	UAO_SWHASH_ELT_PAGEIDX_BASE(ELT) \
+((elt)-tag  UAO_SWHASH_CLUSTER_SHIFT)
 
-/* given an ELT, return its pageidx base */
-#define UAO_SWHASH_ELT_PAGEIDX_BASE(ELT) \
-	((ELT)-tag  UAO_SWHASH_CLUSTER_SHIFT)
+/* The hash function. */
+#define	UAO_SWHASH_HASH(aobj, idx) \
+((aobj)-u_swhash[(((idx)  UAO_SWHASH_CLUSTER_SHIFT) \
+ (aobj)-u_swhashmask)])
 
 /*
- * the swhash hash function
- */
-
-#define UAO_SWHASH_HASH(AOBJ, PAGEIDX) \
-	((AOBJ)-u_swhash[(((PAGEIDX)  UAO_SWHASH_CLUSTER_SHIFT) \
-			 (AOBJ)-u_swhashmask)])
-
-/*
- * the swhash threshhold determines if we will use an array or a
+ * The threshold which determines whether we will use an array or a
  * hash table to store the list of allocated swap blocks.
  */
-
-#define UAO_SWHASH_THRESHOLD (UAO_SWHASH_CLUSTER_SIZE * 4)
-#define UAO_USES_SWHASH(AOBJ) \
-	((AOBJ)-u_pages  UAO_SWHASH_THRESHOLD)	/* use hash? */
-
-/*
- * the number of buckets in a swhash, with an upper bound
- */
-
-#define UAO_SWHASH_MAXBUCKETS 256
-#define UAO_SWHASH_BUCKETS(AOBJ) \
-	(MIN((AOBJ)-u_pages  UAO_SWHASH_CLUSTER_SHIFT, \
-	 UAO_SWHASH_MAXBUCKETS))
+#define	UAO_SWHASH_THRESHOLD		(UAO_SWHASH_CLUSTER_SIZE * 4)
+#define	UAO_USES_SWHASH(aobj) \
+((aobj)-u_pages  UAO_SWHASH_THRESHOLD)
+
+/* The number of buckets in a hash, with an upper bound. */
+#define	UAO_SWHASH_MAXBUCKETS		256
+#define	UAO_SWHASH_BUCKETS(aobj) \
+(MIN((aobj)-u_pages  UAO_SWHASH_CLUSTER_SHIFT, UAO_SWHASH_MAXBUCKETS))
 
 /*
  * uao_swhash_elt: when a hash table is being used, this structure defines
@@ -135,7 +124,7 @@ LIST_HEAD(uao_swhash, uao_swhash_elt);
  * uao_swhash_elt_pool: pool of 

CVS commit: src/sys/uvm

2012-09-14 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Fri Sep 14 22:20:50 UTC 2012

Modified Files:
src/sys/uvm: uvm_aobj.c uvm_object.h

Log Message:
- Manage anonymous UVM object reference count with atomic ops.
- Fix an old bug of possible lock against oneself (uao_detach_locked() is
  called from uao_swap_off() with uao_list_lock acquired).  Also removes
  the try-lock dance in uao_swap_off(), since the lock order changes.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/uvm/uvm_aobj.c
cvs rdiff -u -r1.32 -r1.33 src/sys/uvm/uvm_object.h

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_aobj.c
diff -u src/sys/uvm/uvm_aobj.c:1.117 src/sys/uvm/uvm_aobj.c:1.118
--- src/sys/uvm/uvm_aobj.c:1.117	Fri Sep 14 18:56:15 2012
+++ src/sys/uvm/uvm_aobj.c	Fri Sep 14 22:20:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_aobj.c,v 1.117 2012/09/14 18:56:15 rmind Exp $	*/
+/*	$NetBSD: uvm_aobj.c,v 1.118 2012/09/14 22:20:50 rmind Exp $	*/
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,13 +38,12 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: uvm_aobj.c,v 1.117 2012/09/14 18:56:15 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: uvm_aobj.c,v 1.118 2012/09/14 22:20:50 rmind Exp $);
 
 #include opt_uvmhist.h
 
 #include sys/param.h
 #include sys/systm.h
-#include sys/proc.h
 #include sys/kernel.h
 #include sys/kmem.h
 #include sys/pool.h
@@ -59,8 +58,8 @@ __KERNEL_RCSID(0, $NetBSD: uvm_aobj.c,v
  *
  * Lock order
  *
- *	uvm_object::vmobjlock -
- *		uao_list_lock
+ *	uao_list_lock -
+ *		uvm_object::vmobjlock
  */
 
 /*
@@ -153,9 +152,6 @@ static int	uao_get(struct uvm_object *, 
 		int *, int, vm_prot_t, int, int);
 static int	uao_put(struct uvm_object *, voff_t, voff_t, int);
 
-static void uao_detach_locked(struct uvm_object *);
-static void uao_reference_locked(struct uvm_object *);
-
 #if defined(VMSWAP)
 static struct uao_swhash_elt *uao_find_swhash_elt
 (struct uvm_aobj *, int, bool);
@@ -362,7 +358,8 @@ uao_free(struct uvm_aobj *aobj)
 {
 	struct uvm_object *uobj = aobj-u_obj;
 
-	uao_dropswap_range(aobj, 0, 0);
+	KASSERT(mutex_owned(uobj-vmobjlock));
+	uao_dropswap_range(uobj, 0, 0);
 	mutex_exit(uobj-vmobjlock);
 
 #if defined(VMSWAP)
@@ -512,124 +509,62 @@ uao_init(void)
 }
 
 /*
- * uao_reference: add a ref to an aobj
- *
- * = aobj must be unlocked
- * = just lock it and call the locked version
+ * uao_reference: hold a reference to an anonymous UVM object.
  */
-
 void
 uao_reference(struct uvm_object *uobj)
 {
-
-	/*
- 	 * kernel_object already has plenty of references, leave it alone.
- 	 */
-
-	if (UVM_OBJ_IS_KERN_OBJECT(uobj))
-		return;
-
-	mutex_enter(uobj-vmobjlock);
-	uao_reference_locked(uobj);
-	mutex_exit(uobj-vmobjlock);
-}
-
-/*
- * uao_reference_locked: add a ref to an aobj that is already locked
- *
- * = aobj must be locked
- * this needs to be separate from the normal routine
- * since sometimes we need to add a reference to an aobj when
- * it's already locked.
- */
-
-static void
-uao_reference_locked(struct uvm_object *uobj)
-{
-	UVMHIST_FUNC(uao_reference); UVMHIST_CALLED(maphist);
-
-	/*
- 	 * kernel_object already has plenty of references, leave it alone.
- 	 */
-
-	if (UVM_OBJ_IS_KERN_OBJECT(uobj))
+	/* Kernel object is persistent. */
+	if (UVM_OBJ_IS_KERN_OBJECT(uobj)) {
 		return;
-
-	uobj-uo_refs++;
-	UVMHIST_LOG(maphist, - done (uobj=0x%x, ref = %d),
-		uobj, uobj-uo_refs,0,0);
+	}
+	atomic_inc_uint(uobj-uo_refs);
 }
 
 /*
- * uao_detach: drop a reference to an aobj
- *
- * = aobj must be unlocked
- * = just lock it and call the locked version
+ * uao_detach: drop a reference to an anonymous UVM object.
  */
-
 void
 uao_detach(struct uvm_object *uobj)
 {
-
-	/*
- 	 * detaching from kernel_object is a noop.
- 	 */
-
-	if (UVM_OBJ_IS_KERN_OBJECT(uobj))
-		return;
-
-	mutex_enter(uobj-vmobjlock);
-	uao_detach_locked(uobj);
-}
-
-/*
- * uao_detach_locked: drop a reference to an aobj
- *
- * = aobj must be locked, and is unlocked (or freed) upon return.
- * this needs to be separate from the normal routine
- * since sometimes we need to detach from an aobj when
- * it's already locked.
- */
-
-static void
-uao_detach_locked(struct uvm_object *uobj)
-{
 	struct uvm_aobj *aobj = (struct uvm_aobj *)uobj;
 	struct vm_page *pg;
+
 	UVMHIST_FUNC(uao_detach); UVMHIST_CALLED(maphist);
 
 	/*
- 	 * detaching from kernel_object is a noop.
- 	 */
+	 * Detaching from kernel object is a NOP.
+	 */
 
-	if (UVM_OBJ_IS_KERN_OBJECT(uobj)) {
-		mutex_exit(uobj-vmobjlock);
+	if (UVM_OBJ_IS_KERN_OBJECT(uobj))
 		return;
-	}
+
+	/*
+	 * Drop the reference.  If it was the last one, destroy the object.
+	 */
 
 	UVMHIST_LOG(maphist,  (uobj=0x%x)  ref=%d, uobj,uobj-uo_refs,0,0);
-	uobj-uo_refs--;
-	if (uobj-uo_refs) {
-		mutex_exit(uobj-vmobjlock);
+	if (atomic_dec_uint_nv(uobj-uo_refs)  0) {
 		UVMHIST_LOG(maphist, - done (rc0),