From 52ace503ecf894ec2f63b8137f181868ea61d95a Mon Sep 17 00:00:00 2001 From: Alistair Delva Date: Mon, 8 May 2023 12:58:07 -0700 Subject: [PATCH] Revert "mm/mmap: regression fix for unmapped_area{_topdown}" This reverts commit 58c5d0d6d522112577c7eeb71d382ea642ed7be4. Breaks ldt_gdt kselftest. The same breakage has been reported upstream in https://lore.kernel.org/linux-mm/32f156ba80010fd97dbaf0a0cdfc84366608624d.camel@intel.com/ Bug: 281094761 Signed-off-by: Alistair Delva Change-Id: Ie8481abc4a23678e6d55128fffd7dd15c7ff2161 --- mm/mmap.c | 48 +++++------------------------------------------- 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 155eddaa9414..b8d161c87e46 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1518,8 +1518,7 @@ static inline int accountable_mapping(struct file *file, vm_flags_t vm_flags) */ static unsigned long unmapped_area(struct vm_unmapped_area_info *info) { - unsigned long length, gap, low_limit; - struct vm_area_struct *tmp; + unsigned long length, gap; MA_STATE(mas, ¤t->mm->mm_mt, 0, 0); @@ -1528,29 +1527,12 @@ static unsigned long unmapped_area(struct vm_unmapped_area_info *info) if (length < info->length) return -ENOMEM; - low_limit = info->low_limit; -retry: - if (mas_empty_area(&mas, low_limit, info->high_limit - 1, length)) + if (mas_empty_area(&mas, info->low_limit, info->high_limit - 1, + length)) return -ENOMEM; gap = mas.index; gap += (info->align_offset - gap) & info->align_mask; - tmp = mas_next(&mas, ULONG_MAX); - if (tmp && (tmp->vm_flags & VM_GROWSDOWN)) { /* Avoid prev check if possible */ - if (vm_start_gap(tmp) < gap + length - 1) { - low_limit = tmp->vm_end; - mas_reset(&mas); - goto retry; - } - } else { - tmp = mas_prev(&mas, 0); - if (tmp && vm_end_gap(tmp) > gap) { - low_limit = vm_end_gap(tmp); - mas_reset(&mas); - goto retry; - } - } - return gap; } @@ -1566,8 +1548,7 @@ retry: */ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) { - unsigned long length, gap, high_limit, gap_end; - struct vm_area_struct *tmp; + unsigned long length, gap; MA_STATE(mas, ¤t->mm->mm_mt, 0, 0); /* Adjust search length to account for worst case alignment overhead */ @@ -1575,31 +1556,12 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) if (length < info->length) return -ENOMEM; - high_limit = info->high_limit; -retry: - if (mas_empty_area_rev(&mas, info->low_limit, high_limit - 1, + if (mas_empty_area_rev(&mas, info->low_limit, info->high_limit - 1, length)) return -ENOMEM; gap = mas.last + 1 - info->length; gap -= (gap - info->align_offset) & info->align_mask; - gap_end = mas.last; - tmp = mas_next(&mas, ULONG_MAX); - if (tmp && (tmp->vm_flags & VM_GROWSDOWN)) { /* Avoid prev check if possible */ - if (vm_start_gap(tmp) <= gap_end) { - high_limit = vm_start_gap(tmp); - mas_reset(&mas); - goto retry; - } - } else { - tmp = mas_prev(&mas, 0); - if (tmp && vm_end_gap(tmp) > gap) { - high_limit = tmp->vm_start; - mas_reset(&mas); - goto retry; - } - } - return gap; }