Author: kib
Date: Wed Sep  9 21:34:31 2020
New Revision: 365513
URL: https://svnweb.freebsd.org/changeset/base/365513

Log:
  Prepare to handle non-trivial errors from vm_map_delete().
  
  Reviewed by:  markj
  Tested by:    pho
  Sponsored by: The FreeBSD Foundation
  MFC after:    1 week
  Differential revision:        https://reviews.freebsd.org/D24652

Modified:
  head/sys/vm/vm_map.c
  head/sys/vm/vm_mmap.c
  head/sys/vm/vm_unix.c

Modified: head/sys/vm/vm_map.c
==============================================================================
--- head/sys/vm/vm_map.c        Wed Sep  9 21:08:45 2020        (r365512)
+++ head/sys/vm/vm_map.c        Wed Sep  9 21:34:31 2020        (r365513)
@@ -1868,8 +1868,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);
@@ -1877,6 +1880,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);
 }
@@ -2115,7 +2119,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: head/sys/vm/vm_mmap.c
==============================================================================
--- head/sys/vm/vm_mmap.c       Wed Sep  9 21:08:45 2020        (r365512)
+++ head/sys/vm/vm_mmap.c       Wed Sep  9 21:34:31 2020        (r365513)
@@ -577,6 +577,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);
@@ -614,10 +615,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)
@@ -627,8 +628,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: head/sys/vm/vm_unix.c
==============================================================================
--- head/sys/vm/vm_unix.c       Wed Sep  9 21:08:45 2020        (r365512)
+++ head/sys/vm/vm_unix.c       Wed Sep  9 21:34:31 2020        (r365513)
@@ -188,7 +188,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
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to