Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src MAP_FIXED means something different for mremap() than it doe...



details:   https://anonhg.NetBSD.org/src/rev/55ca9c52e1dd
branches:  trunk
changeset: 353746:55ca9c52e1dd
user:      chs <chs%NetBSD.org@localhost>
date:      Sat May 20 07:27:15 2017 +0000

description:
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.

diffstat:

 share/man/man9/uvm_map.9 |   8 +++++++-
 sys/uvm/uvm_extern.h     |  27 +++++++++++++++------------
 sys/uvm/uvm_map.c        |  18 ++++++++++--------
 sys/uvm/uvm_mmap.c       |   6 +++---
 4 files changed, 35 insertions(+), 24 deletions(-)

diffs (153 lines):

diff -r 9d1a149340cd -r 55ca9c52e1dd share/man/man9/uvm_map.9
--- a/share/man/man9/uvm_map.9  Sat May 20 00:56:32 2017 +0000
+++ b/share/man/man9/uvm_map.9  Sat May 20 07:27:15 2017 +0000
@@ -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 @@
 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
diff -r 9d1a149340cd -r 55ca9c52e1dd sys/uvm/uvm_extern.h
--- a/sys/uvm/uvm_extern.h      Sat May 20 00:56:32 2017 +0000
+++ b/sys/uvm/uvm_extern.h      Sat May 20 07:27:15 2017 +0000
@@ -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\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)
diff -r 9d1a149340cd -r 55ca9c52e1dd sys/uvm/uvm_map.c
--- a/sys/uvm/uvm_map.c Sat May 20 00:56:32 2017 +0000
+++ b/sys/uvm/uvm_map.c Sat May 20 07:27:15 2017 +0000
@@ -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 @@
                }
                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 @@
 
        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 @@
        }
 
        /*
-        * 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;
diff -r 9d1a149340cd -r 55ca9c52e1dd sys/uvm/uvm_mmap.c
--- a/sys/uvm/uvm_mmap.c        Sat May 20 00:56:32 2017 +0000
+++ b/sys/uvm/uvm_mmap.c        Sat May 20 07:27:15 2017 +0000
@@ -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 @@
        } else {
                if (*addr & PAGE_MASK)
                        return EINVAL;
-               uvmflag |= UVM_FLAG_FIXED;
+               uvmflag |= UVM_FLAG_FIXED | UVM_FLAG_UNMAP;
        }
 
        /*



Home | Main Index | Thread Index | Old Index