Summary of changes: - rename align_va() into uvm_map_align_va() - add KASSERT(powerof2(align)) in uvm_map_align_va() - add KASSERT((flags & UVM_FLAG_FIXED) == 0 || align == 0) in uvm_map() Index: sys/uvm/uvm_map.c =================================================================== RCS file: /home/netbsd/src/sys/uvm/uvm_map.c,v retrieving revision 1.364 diff -p -u -r1.364 uvm_map.c --- sys/uvm/uvm_map.c 10 Aug 2019 01:06:45 -0000 1.364 +++ sys/uvm/uvm_map.c 27 Oct 2019 08:22:25 -0000 @@ -187,6 +187,23 @@ int user_va0_disable = __USER_VA0_DISABL */ /* + * 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 @@ uvm_map(struct vm_map *map, vaddr_t *sta 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 @@ uvm_map_space_avail(vaddr_t *start, vsiz *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 @@ uvm_map_findspace(struct vm_map *map, va 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 @@ uvm_map_findspace(struct vm_map *map, va } /* + * 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. */