Source-Changes-HG archive

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

[src/netbsd-9]: src/sys/uvm Pull up following revision(s) (requested by rin i...



details:   https://anonhg.NetBSD.org/src/rev/e11da7d5f526
branches:  netbsd-9
changeset: 460714:e11da7d5f526
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Nov 01 09:36:32 2019 +0000

description:
Pull up following revision(s) (requested by rin in ticket #388):

        sys/uvm/uvm_map.c: revision 1.365

PR kern/54395

- Align hint for virtual address at the beginning of uvm_map() if
   required. Otherwise, it will be rounded up/down in an unexpected
   way by uvm_map_space_avail(), which results in assertion failure.
   Fix kernel panic when executing earm binary (8KB pages) on aarch64
   (4KB pages), which relies on mmap(2) with MAP_ALIGNED flag.
- Use inline functions/macros consistently.
- Add some more KASSERT's.

For more details, see the PR as well as discussion on port-kern:
http://mail-index.netbsd.org/tech-kern/2019/10/27/msg025629.html

diffstat:

 sys/uvm/uvm_map.c |  40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diffs (89 lines):

diff -r f783b4a9547e -r e11da7d5f526 sys/uvm/uvm_map.c
--- a/sys/uvm/uvm_map.c Fri Nov 01 09:34:27 2019 +0000
+++ b/sys/uvm/uvm_map.c Fri Nov 01 09:36:32 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_map.c,v 1.362 2019/07/12 06:27:13 mlelstv Exp $    */
+/*     $NetBSD: uvm_map.c,v 1.362.2.1 2019/11/01 09:36:32 martin 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.362 2019/07/12 06:27:13 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.362.2.1 2019/11/01 09:36:32 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pax.h"
@@ -187,6 +187,23 @@
  */
 
 /*
+ * uvm_map_align_va: round down or up virtual address
+ */
+static __inline void
+uvm_map_align_va(vaddr_t *vap, vsize_t align, int topdown)
+{
+
+       KASSERT(powerof2(align));
+
+       if (align != 0 && (*vap & (align - 1)) != 0) {
+               if (topdown)
+                       *vap = rounddown2(*vap, align);
+               else
+                       *vap = roundup2(*vap, align);
+       }
+}
+
+/*
  * UVM_ET_ISCOMPATIBLE: check some requirements for map entry merging
  */
 extern struct vm_map *pager_map;
@@ -1063,6 +1080,7 @@
        int error;
 
        KASSERT((size & PAGE_MASK) == 0);
+       KASSERT((flags & UVM_FLAG_FIXED) == 0 || align == 0);
 
        /*
         * for pager_map, allocate the new entry first to avoid sleeping
@@ -1805,13 +1823,9 @@
                                *start = ptoa(hint + align); /* adjust to color */
                        }
                }
-       } else if (align != 0) {
-               if ((*start & (align - 1)) != 0) {
-                       if (topdown)
-                               *start &= ~(align - 1);
-                       else
-                               *start = roundup(*start, align);
-               }
+       } else {
+               KASSERT(powerof2(align));
+               uvm_map_align_va(start, align, topdown);
                /*
                 * XXX Should we PMAP_PREFER() here again?
                 * eh...i think we're okay
@@ -1861,7 +1875,7 @@
 
        UVMHIST_LOG(maphist, "(map=%#jx, hint=%#jx, len=%ju, flags=%#jx)",
            (uintptr_t)map, hint, length, flags);
-       KASSERT((flags & UVM_FLAG_COLORMATCH) != 0 || (align & (align - 1)) == 0);
+       KASSERT((flags & UVM_FLAG_COLORMATCH) != 0 || powerof2(align));
        KASSERT((flags & UVM_FLAG_COLORMATCH) == 0 || align < uvmexp.ncolors);
        KASSERT((flags & UVM_FLAG_FIXED) == 0 || align == 0);
 
@@ -1888,6 +1902,12 @@
        }
 
        /*
+        * hint may not be aligned properly; we need round up or down it
+        * before proceeding further.
+        */
+       uvm_map_align_va(&hint, align, topdown);
+
+       /*
         * Look for the first possible address; if there's already
         * something at this address, we have to start after it.
         */



Home | Main Index | Thread Index | Old Index