From 0ca43e9e68dd5c593c1ec041f35fd91868408852 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Thu, 7 May 2020 16:07:49 -0400 Subject: [PATCH] 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 --- mm/mmap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index c37e74bbb95c..942b9b12a29a 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); -- 2.50.1