svn commit: r317054 - stable/11/sys/vm
Mark Johnston
markj at FreeBSD.org
Mon Apr 17 16:59:20 UTC 2017
Author: markj
Date: Mon Apr 17 16:59:18 2017
New Revision: 317054
URL: https://svnweb.freebsd.org/changeset/base/317054
Log:
MFC r316686, r316687, r316689
Fix a race between vm_map_wire() and vm_map_protect().
Modified:
stable/11/sys/vm/vm_map.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/sys/vm/vm_map.c
==============================================================================
--- stable/11/sys/vm/vm_map.c Mon Apr 17 16:51:04 2017 (r317053)
+++ stable/11/sys/vm/vm_map.c Mon Apr 17 16:59:18 2017 (r317054)
@@ -1655,6 +1655,8 @@ _vm_map_clip_start(vm_map_t map, vm_map_
vm_map_entry_t new_entry;
VM_MAP_ASSERT_LOCKED(map);
+ KASSERT(entry->end > start && entry->start < start,
+ ("_vm_map_clip_start: invalid clip of entry %p", entry));
/*
* Split off the front portion -- note that we must insert the new
@@ -1739,6 +1741,8 @@ _vm_map_clip_end(vm_map_t map, vm_map_en
vm_map_entry_t new_entry;
VM_MAP_ASSERT_LOCKED(map);
+ KASSERT(entry->start < end && entry->end > end,
+ ("_vm_map_clip_end: invalid clip of entry %p", entry));
/*
* If there is no object backing this entry, we might as well create
@@ -1963,6 +1967,14 @@ vm_map_protect(vm_map_t map, vm_offset_t
vm_map_lock(map);
+ /*
+ * Ensure that we are not concurrently wiring pages. vm_map_wire() may
+ * need to fault pages into the map and will drop the map lock while
+ * doing so, and the VM object may end up in an inconsistent state if we
+ * update the protection on the map entry in between faults.
+ */
+ vm_map_wait_busy(map);
+
VM_MAP_RANGE_CHECK(map, start, end);
if (vm_map_lookup_entry(map, start, &entry)) {
@@ -1974,8 +1986,8 @@ vm_map_protect(vm_map_t map, vm_offset_t
/*
* Make a first pass to check for protection violations.
*/
- current = entry;
- while ((current != &map->header) && (current->start < end)) {
+ for (current = entry; current != &map->header && current->start < end;
+ current = current->next) {
if (current->eflags & MAP_ENTRY_IS_SUB_MAP) {
vm_map_unlock(map);
return (KERN_INVALID_ARGUMENT);
@@ -1984,17 +1996,15 @@ vm_map_protect(vm_map_t map, vm_offset_t
vm_map_unlock(map);
return (KERN_PROTECTION_FAILURE);
}
- current = current->next;
}
-
/*
* Do an accounting pass for private read-only mappings that
* now will do cow due to allowed write (e.g. debugger sets
* breakpoint on text segment)
*/
- for (current = entry; (current != &map->header) &&
- (current->start < end); current = current->next) {
+ for (current = entry; current != &map->header && current->start < end;
+ current = current->next) {
vm_map_clip_end(map, current, end);
@@ -2047,8 +2057,8 @@ vm_map_protect(vm_map_t map, vm_offset_t
* Go back and fix up protections. [Note that clipping is not
* necessary the second time.]
*/
- current = entry;
- while ((current != &map->header) && (current->start < end)) {
+ for (current = entry; current != &map->header && current->start < end;
+ current = current->next) {
old_prot = current->protection;
if (set_max)
@@ -2082,7 +2092,6 @@ vm_map_protect(vm_map_t map, vm_offset_t
#undef MASK
}
vm_map_simplify_entry(map, current);
- current = current->next;
}
vm_map_unlock(map);
return (KERN_SUCCESS);
More information about the svn-src-stable-11
mailing list