All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: fix align-error when get_addr in unmapped_area_topdown
@ 2022-04-12  8:10 lipeifeng
  2022-04-12 21:22 ` Andrew Morton
  0 siblings, 1 reply; 12+ messages in thread
From: lipeifeng @ 2022-04-12  8:10 UTC (permalink / raw)
  To: akpm, michel, hughd
  Cc: linux-mm, linux-kernel, 21cnbao, zhangshiming, lipeifeng

From: lipeifeng <lipeifeng@oppo.com>

when we found a suitable gap_end(> info->high_limit), gap_end
must be set to info->high_limit. And we will get the gap_end
after computing highest gap address at the desired alignment.

2096 found:
2097         if (gap_end > info->high_limit)
2098                 gap_end = info->high_limit;
2099
2100 found_highest:
2101         gap_end -= info->length;
2102         gap_end -= (gap_end - info->align_offset) & info->align_mask;
2103
2104         VM_BUG_ON(gap_end < info->low_limit);
2105         VM_BUG_ON(gap_end < gap_start);
2106         return gap_end;

so we must promise: info->high_limit - info->low_limit >=
info->length + info->align_mask.
Or in rare cases(info->high_limit - info->low_limit <
info->length + info->align_mask) we will get the addr in
align-error if found suitable gap_end(> info->high_limit).

Signed-off-by: lipeifeng <lipeifeng@oppo.com>
---
 mm/mmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 30e33d3..a28ea5c 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2009,7 +2009,6 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
 	if (length < info->length)
 		return -ENOMEM;
 
-	length = info->length;
 	/*
 	 * Adjust search limits by the desired length.
 	 * See implementation comment at top of unmapped_area().
@@ -2021,6 +2020,8 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
 
 	if (info->low_limit > high_limit)
 		return -ENOMEM;
+
+	length = info->length;
 	low_limit = info->low_limit + length;
 
 	/* Check highest gap, which does not precede any rbtree node */
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-05-17  8:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12  8:10 [PATCH] mm: fix align-error when get_addr in unmapped_area_topdown lipeifeng
2022-04-12 21:22 ` Andrew Morton
2022-04-13  3:28   ` lipeifeng
2022-05-01  2:26     ` lipeifeng
2022-05-02  1:10       ` Andrew Morton
2022-05-02  3:33         ` lipeifeng
2022-05-07 21:59           ` Andrew Morton
2022-05-09  9:23             ` lipeifeng
2022-05-09 11:45           ` Michel Lespinasse
2022-05-16  2:43             ` lipeifeng
2022-05-16  7:45               ` Michel Lespinasse
2022-05-17  8:04                 ` lipeifeng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.