From b39e2b5e89fd1d4737cd6fc9bca9c54a0090f052 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 2 Feb 2021 09:14:41 -0500 Subject: [PATCH] mm/mmap: Change gap calculations When calculating the gaps, make sure the alignment is okay. This needs further analysis. Signed-off-by: Liam R. Howlett --- mm/mmap.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 30c68d02aba9..d4b199d0db5b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1622,8 +1622,9 @@ static unsigned long unmapped_area(struct vm_unmapped_area_info *info) rcu_read_unlock(); return -ENOMEM; } - gap = mas.index + gap_start_offset(info, mas.index); - } while (gap > mas.last + 1 - info->length); + gap = mas.index & ~(info->align_mask); + gap += info->align_offset; + } while ((gap < mas.index) && (gap > mas.last - info->length + 1)); rcu_read_unlock(); return gap; @@ -1652,8 +1653,10 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) rcu_read_unlock(); return -ENOMEM; } - gap = mas.last + gap_end_offset(info, mas.last) - - info->length + 1; + + gap = mas.last - info->length + 1; + gap &= ~(info->align_mask); + gap += info->align_offset; } while (mas.index > gap); rcu_read_unlock(); -- 2.50.1