From: Liam R. Howlett Date: Thu, 7 May 2020 20:07:49 +0000 (-0400) Subject: mm/mmap: Fix maple tree calculation for topdown with alignment mask. X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=0ca43e9e68dd5c593c1ec041f35fd91868408852;p=users%2Fjedix%2Flinux-maple.git mm/mmap: Fix maple tree calculation for topdown with alignment mask. When using alignment mask, calculate the address correctly. Found by LTP futex_wake04 Signed-off-by: Liam R. Howlett --- diff --git a/mm/mmap.c b/mm/mmap.c index c37e74bbb95c1..942b9b12a29a4 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2278,11 +2278,10 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) if (mas_get_unmapped_area_rev(&mas, info->low_limit, info->high_limit, length)) return -ENOMEM; + rcu_read_unlock(); - gap = mas.index; - // Not sure why this is needed.. - if (mas.max > info->high_limit) - gap = ((gap) & ~info->align_mask) + info->align_offset; + gap = (mas.index + info->align_mask - info->align_offset) & + (~info->align_mask); /* * Adjust search limits by the desired length. * See implementation comment at top of unmapped_area(). @@ -2377,8 +2376,8 @@ found_highest: info->low_limit, length); pr_err("mas.min %lu max %lu mas.last %lu\n", mas.min, mas.max, mas.last); - pr_err("mas.index %lu align %lu offset %lu\n", mas.index, - info->align_offset, info->align_mask); + pr_err("mas.index %lu align mask %lu offset %lu\n", mas.index, + info->align_mask, info->align_offset); pr_err("rb_find_vma find on %lu => %px (%px)\n", mas.index, rb_find_vma(mm, mas.index), vma); mt_dump(&mm->mm_mt);