Module Name: src
Committed By: chs
Date: Sat May 20 07:27:15 UTC 2017
Modified Files:
src/share/man/man9: uvm_map.9
src/sys/uvm: uvm_extern.h uvm_map.c uvm_mmap.c
Log Message:
MAP_FIXED means something different for mremap() than it does for mmap(),
so we cannot use UVM_FLAG_FIXED to specify both behaviors.
keep UVM_FLAG_FIXED with its earlier meaning (prior to my previous change)
of whether to use uvm_map_findspace() to locate space for the new mapping or
to use the hint address that the caller passed in, and add a new flag
UVM_FLAG_UNMAP to indicate that any existing entries in the range should be
unmapped as part of creating the new mapping. the new UVM_FLAG_UNMAP flag
may only be used if UVM_FLAG_FIXED is also specified.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/share/man/man9/uvm_map.9
cvs rdiff -u -r1.205 -r1.206 src/sys/uvm/uvm_extern.h
cvs rdiff -u -r1.348 -r1.349 src/sys/uvm/uvm_map.c
cvs rdiff -u -r1.165 -r1.166 src/sys/uvm/uvm_mmap.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/share/man/man9/uvm_map.9
diff -u src/share/man/man9/uvm_map.9:1.8 src/share/man/man9/uvm_map.9:1.9
--- src/share/man/man9/uvm_map.9:1.8 Sun May 14 12:31:13 2017
+++ src/share/man/man9/uvm_map.9 Sat May 20 07:27:15 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: uvm_map.9,v 1.8 2017/05/14 12:31:13 wiz Exp $
+.\" $NetBSD: uvm_map.9,v 1.9 2017/05/20 07:27:15 chs Exp $
.\"
.\" Copyright (c) 1998 Matthew R. Green
.\" All rights reserved.
@@ -239,6 +239,12 @@ Sleep until VA space is available, if it
Unmap only VA space.
Used by
.Fn uvm_unmap .
+.It UVM_FLAG_UNMAP
+Any existing entires in the range for this mapping should be
+unmapped as part of creating the new mapping. Use of this flag
+without also specifying
+.Dv UVM_FLAG_FIXED
+is a bug.
.El
.Pp
The
Index: src/sys/uvm/uvm_extern.h
diff -u src/sys/uvm/uvm_extern.h:1.205 src/sys/uvm/uvm_extern.h:1.206
--- src/sys/uvm/uvm_extern.h:1.205 Wed May 17 22:43:12 2017
+++ src/sys/uvm/uvm_extern.h Sat May 20 07:27:15 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_extern.h,v 1.205 2017/05/17 22:43:12 christos Exp $ */
+/* $NetBSD: uvm_extern.h,v 1.206 2017/05/20 07:27:15 chs Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -121,16 +121,17 @@
#define UVM_ADV_MASK 0x7 /* mask */
/* bits 0xffff0000: mapping flags */
-#define UVM_FLAG_FIXED 0x010000 /* find space */
-#define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
-#define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
-#define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
-#define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce allocations */
-#define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
-#define UVM_FLAG_NOWAIT 0x400000 /* not allowed to sleep */
-#define UVM_FLAG_WAITVA 0x800000 /* wait for va */
-#define UVM_FLAG_VAONLY 0x2000000 /* unmap: no pages are mapped */
-#define UVM_FLAG_COLORMATCH 0x4000000 /* match color given in off */
+#define UVM_FLAG_FIXED 0x00010000 /* find space */
+#define UVM_FLAG_OVERLAY 0x00020000 /* establish overlay */
+#define UVM_FLAG_NOMERGE 0x00040000 /* don't merge map entries */
+#define UVM_FLAG_COPYONW 0x00080000 /* set copy_on_write flag */
+#define UVM_FLAG_AMAPPAD 0x00100000 /* for bss: pad amap */
+#define UVM_FLAG_TRYLOCK 0x00200000 /* fail if we can not lock map */
+#define UVM_FLAG_NOWAIT 0x00400000 /* not allowed to sleep */
+#define UVM_FLAG_WAITVA 0x00800000 /* wait for va */
+#define UVM_FLAG_VAONLY 0x02000000 /* unmap: no pages are mapped */
+#define UVM_FLAG_COLORMATCH 0x04000000 /* match color given in off */
+#define UVM_FLAG_UNMAP 0x08000000 /* unmap existing entries */
#define UVM_FLAG_BITS "\177\020\
F\0\3\
@@ -172,7 +173,9 @@ b\25TRYLOCK\0\
b\26NOWAIT\0\
b\27WAITVA\0\
b\30VAONLY\0\
-b\31COLORMATCH\0"
+b\31COLORMATCH\0\
+b\32UNMAP\0\
+"
/* macros to extract info */
#define UVM_PROTECTION(X) ((X) & UVM_PROT_MASK)
Index: src/sys/uvm/uvm_map.c
diff -u src/sys/uvm/uvm_map.c:1.348 src/sys/uvm/uvm_map.c:1.349
--- src/sys/uvm/uvm_map.c:1.348 Fri May 19 16:56:35 2017
+++ src/sys/uvm/uvm_map.c Sat May 20 07:27:15 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_map.c,v 1.348 2017/05/19 16:56:35 kamil Exp $ */
+/* $NetBSD: uvm_map.c,v 1.349 2017/05/20 07:27:15 chs Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.348 2017/05/19 16:56:35 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.349 2017/05/20 07:27:15 chs Exp $");
#include "opt_ddb.h"
#include "opt_pax.h"
@@ -1163,7 +1163,8 @@ retry:
}
vm_map_lock(map); /* could sleep here */
}
- if (flags & UVM_FLAG_FIXED) {
+ if (flags & UVM_FLAG_UNMAP) {
+ KASSERT(flags & UVM_FLAG_FIXED);
KASSERT((flags & UVM_FLAG_NOWAIT) == 0);
/*
@@ -1301,8 +1302,8 @@ uvm_map_enter(struct vm_map *map, const
KASSERT(map->hint == prev_entry); /* bimerge case assumes this */
KASSERT(vm_map_locked_p(map));
- KASSERT((flags & (UVM_FLAG_NOWAIT | UVM_FLAG_FIXED)) !=
- (UVM_FLAG_NOWAIT | UVM_FLAG_FIXED));
+ KASSERT((flags & (UVM_FLAG_NOWAIT | UVM_FLAG_UNMAP)) !=
+ (UVM_FLAG_NOWAIT | UVM_FLAG_UNMAP));
if (uobj)
newetype = UVM_ET_OBJ;
@@ -1316,12 +1317,13 @@ uvm_map_enter(struct vm_map *map, const
}
/*
- * For fixed mappings, remove any old entries now. Adding the new
+ * For mappings with unmap, remove any old entries now. Adding the new
* entry cannot fail because that can only happen if UVM_FLAG_NOWAIT
- * is set, and we do not support nowait and fixed together.
+ * is set, and we do not support nowait and unmap together.
*/
- if (flags & UVM_FLAG_FIXED) {
+ if (flags & UVM_FLAG_UNMAP) {
+ KASSERT(flags & UVM_FLAG_FIXED);
uvm_unmap_remove(map, start, start + size, &dead_entries, 0);
#ifdef DEBUG
struct vm_map_entry *tmp_entry;
Index: src/sys/uvm/uvm_mmap.c
diff -u src/sys/uvm/uvm_mmap.c:1.165 src/sys/uvm/uvm_mmap.c:1.166
--- src/sys/uvm/uvm_mmap.c:1.165 Fri May 19 15:30:19 2017
+++ src/sys/uvm/uvm_mmap.c Sat May 20 07:27:15 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_mmap.c,v 1.165 2017/05/19 15:30:19 chs Exp $ */
+/* $NetBSD: uvm_mmap.c,v 1.166 2017/05/20 07:27:15 chs Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.165 2017/05/19 15:30:19 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.166 2017/05/20 07:27:15 chs Exp $");
#include "opt_compat_netbsd.h"
#include "opt_pax.h"
@@ -932,7 +932,7 @@ uvm_mmap(struct vm_map *map, vaddr_t *ad
} else {
if (*addr & PAGE_MASK)
return EINVAL;
- uvmflag |= UVM_FLAG_FIXED;
+ uvmflag |= UVM_FLAG_FIXED | UVM_FLAG_UNMAP;
}
/*