Index: sys/uvm/uvm_map.c =================================================================== RCS file: /home/netbsd/src/sys/uvm/uvm_map.c,v retrieving revision 1.360 diff -p -u -r1.360 uvm_map.c --- sys/uvm/uvm_map.c 8 Jun 2019 23:48:33 -0000 1.360 +++ sys/uvm/uvm_map.c 8 Jul 2019 11:14:54 -0000 @@ -186,6 +186,15 @@ int user_va0_disable = __USER_VA0_DISABL * macros */ +#define ALIGN_VA(va, align, topdown) do { \ + if ((align) != 0 && ((va) & ((align) - 1)) != 0) { \ + if (topdown) \ + (va) &= ~((align) - 1); \ + else \ + (va) = roundup(va, align); \ + } \ +} while (/*CONSTCOND*/ 0) + /* * UVM_ET_ISCOMPATIBLE: check some requirements for map entry merging */ @@ -1805,13 +1814,8 @@ 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 { + ALIGN_VA(*start, align, topdown); /* * XXX Should we PMAP_PREFER() here again? * eh...i think we're okay @@ -1888,6 +1899,12 @@ uvm_map_findspace(struct vm_map *map, va } /* + * hint may not be aligned properly; we need truncate or + * round it up before proceeding further. + */ + 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. */