svn commit: r365804 - stable/12/sys/vm

Konstantin Belousov kib at FreeBSD.org
Wed Sep 16 15:42:59 UTC 2020


Author: kib
Date: Wed Sep 16 15:42:58 2020
New Revision: 365804
URL: https://svnweb.freebsd.org/changeset/base/365804

Log:
  MFC r365513:
  Prepare to handle non-trivial errors from vm_map_delete().

Modified:
  stable/12/sys/vm/vm_map.c
  stable/12/sys/vm/vm_mmap.c
  stable/12/sys/vm/vm_unix.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/vm/vm_map.c
==============================================================================
--- stable/12/sys/vm/vm_map.c	Wed Sep 16 15:38:22 2020	(r365803)
+++ stable/12/sys/vm/vm_map.c	Wed Sep 16 15:42:58 2020	(r365804)
@@ -1742,8 +1742,11 @@ vm_map_fixed(vm_map_t map, vm_object_t object, vm_ooff
 	    ("vm_map_fixed: non-NULL backing object for stack"));
 	vm_map_lock(map);
 	VM_MAP_RANGE_CHECK(map, start, end);
-	if ((cow & MAP_CHECK_EXCL) == 0)
-		vm_map_delete(map, start, end);
+	if ((cow & MAP_CHECK_EXCL) == 0) {
+		result = vm_map_delete(map, start, end);
+		if (result != KERN_SUCCESS)
+			goto out;
+	}
 	if ((cow & (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP)) != 0) {
 		result = vm_map_stack_locked(map, start, length, sgrowsiz,
 		    prot, max, cow);
@@ -1751,6 +1754,7 @@ vm_map_fixed(vm_map_t map, vm_object_t object, vm_ooff
 		result = vm_map_insert(map, object, offset, start, end,
 		    prot, max, cow);
 	}
+out:
 	vm_map_unlock(map);
 	return (result);
 }
@@ -1989,7 +1993,9 @@ again:
 			rv = KERN_INVALID_ADDRESS;
 			goto done;
 		}
-		vm_map_delete(map, *addr, *addr + length);
+		rv = vm_map_delete(map, *addr, *addr + length);
+		if (rv != KERN_SUCCESS)
+			goto done;
 	}
 	if ((cow & (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP)) != 0) {
 		rv = vm_map_stack_locked(map, *addr, length, sgrowsiz, prot,

Modified: stable/12/sys/vm/vm_mmap.c
==============================================================================
--- stable/12/sys/vm/vm_mmap.c	Wed Sep 16 15:38:22 2020	(r365803)
+++ stable/12/sys/vm/vm_mmap.c	Wed Sep 16 15:42:58 2020	(r365804)
@@ -534,6 +534,7 @@ kern_munmap(struct thread *td, uintptr_t addr0, size_t
 	vm_offset_t addr, end;
 	vm_size_t pageoff;
 	vm_map_t map;
+	int rv;
 
 	if (size == 0)
 		return (EINVAL);
@@ -571,10 +572,10 @@ kern_munmap(struct thread *td, uintptr_t addr0, size_t
 		}
 	}
 #endif
-	vm_map_delete(map, addr, end);
+	rv = vm_map_delete(map, addr, end);
 
 #ifdef HWPMC_HOOKS
-	if (__predict_false(pmc_handled)) {
+	if (rv == KERN_SUCCESS && __predict_false(pmc_handled)) {
 		/* downgrade the lock to prevent a LOR with the pmc-sx lock */
 		vm_map_lock_downgrade(map);
 		if (pkm.pm_address != (uintptr_t) NULL)
@@ -584,8 +585,7 @@ kern_munmap(struct thread *td, uintptr_t addr0, size_t
 #endif
 		vm_map_unlock(map);
 
-	/* vm_map_delete returns nothing but KERN_SUCCESS anyway */
-	return (0);
+	return (vm_mmap_to_errno(rv));
 }
 
 #ifndef _SYS_SYSPROTO_H_

Modified: stable/12/sys/vm/vm_unix.c
==============================================================================
--- stable/12/sys/vm/vm_unix.c	Wed Sep 16 15:38:22 2020	(r365803)
+++ stable/12/sys/vm/vm_unix.c	Wed Sep 16 15:42:58 2020	(r365804)
@@ -187,7 +187,7 @@ kern_break(struct thread *td, uintptr_t *addr)
 			rv = vm_map_wire_locked(map, old, new,
 			    VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
 			if (rv != KERN_SUCCESS)
-				vm_map_delete(map, old, new);
+				(void)vm_map_delete(map, old, new);
 		}
 		if (rv != KERN_SUCCESS) {
 #ifdef RACCT


More information about the svn-src-all mailing list