Re: [RFC v7 PATCH 1/4] mm: refactor do_munmap() to extract the common part
On 8/10/18 10:41 AM, Matthew Wilcox wrote: On Fri, Aug 10, 2018 at 07:36:00AM +0800, Yang Shi wrote: +static inline bool addr_ok(unsigned long start, size_t len) Maybe munmap_range_ok()? Otherwise some of the conditions here don't make sense for such a generic sounding function. I don't know. I think the argument is about munmap_ prefix should be used. { - unsigned long end; - struct vm_area_struct *vma, *prev, *last; - if ((offset_in_page(start)) || start > TASK_SIZE || len > TASK_SIZE-start) - return -EINVAL; + return false; - len = PAGE_ALIGN(len); - if (len == 0) - return -EINVAL; + if (PAGE_ALIGN(len) == 0) + return false; + + return true; +} + +/* + * munmap_lookup_vma: find the first overlap vma and split overlap vmas. + * @mm: mm_struct + * @start: start address + * @end: end address + * + * returns the pointer to vma, NULL or err ptr when spilt_vma returns error. kernel-doc prefers: * Return: %NULL if no VMA overlaps this range. An ERR_PTR if an * overlapping VMA could not be split. Otherwise a pointer to the first * VMA which overlaps the range. Ok, will fix it. + */ +static struct vm_area_struct *munmap_lookup_vma(struct mm_struct *mm, + unsigned long start, unsigned long end) +{ + struct vm_area_struct *vma, *prev, *last; /* Find the first overlapping VMA */ vma = find_vma(mm, start); if (!vma) - return 0; - prev = vma->vm_prev; - /* we have start < vma->vm_end */ + return NULL; + /* we have start < vma->vm_end */ Can you remove the duplicate spaces here? Sure Thanks, Yang
Re: [RFC v7 PATCH 1/4] mm: refactor do_munmap() to extract the common part
On Fri, Aug 10, 2018 at 07:36:00AM +0800, Yang Shi wrote: > +static inline bool addr_ok(unsigned long start, size_t len) Maybe munmap_range_ok()? Otherwise some of the conditions here don't make sense for such a generic sounding function. > { > - unsigned long end; > - struct vm_area_struct *vma, *prev, *last; > - > if ((offset_in_page(start)) || start > TASK_SIZE || len > > TASK_SIZE-start) > - return -EINVAL; > + return false; > > - len = PAGE_ALIGN(len); > - if (len == 0) > - return -EINVAL; > + if (PAGE_ALIGN(len) == 0) > + return false; > + > + return true; > +} > + > +/* > + * munmap_lookup_vma: find the first overlap vma and split overlap vmas. > + * @mm: mm_struct > + * @start: start address > + * @end: end address > + * > + * returns the pointer to vma, NULL or err ptr when spilt_vma returns error. kernel-doc prefers: * Return: %NULL if no VMA overlaps this range. An ERR_PTR if an * overlapping VMA could not be split. Otherwise a pointer to the first * VMA which overlaps the range. > + */ > +static struct vm_area_struct *munmap_lookup_vma(struct mm_struct *mm, > + unsigned long start, unsigned long end) > +{ > + struct vm_area_struct *vma, *prev, *last; > > /* Find the first overlapping VMA */ > vma = find_vma(mm, start); > if (!vma) > - return 0; > - prev = vma->vm_prev; > - /* we have start < vma->vm_end */ > + return NULL; > > + /* we have start < vma->vm_end */ Can you remove the duplicate spaces here?
Re: [RFC v7 PATCH 1/4] mm: refactor do_munmap() to extract the common part
On 08/10/2018 01:36 AM, Yang Shi wrote: > Introduces three new helper functions: > * addr_ok() > * munmap_lookup_vma() > * munlock_vmas() > > They will be used by do_munmap() and the new do_munmap with zapping > large mapping early in the later patch. > > There is no functional change, just code refactor. > > Reviewed-by: Laurent Dufour > Signed-off-by: Yang Shi Acked-by: Vlastimil Babka Small nit below. > @@ -2764,13 +2812,7 @@ int do_munmap(struct mm_struct *mm, unsigned long > start, size_t len, >*/ > if (mm->locked_vm) { > struct vm_area_struct *tmp = vma; > - while (tmp && tmp->vm_start < end) { > - if (tmp->vm_flags & VM_LOCKED) { > - mm->locked_vm -= vma_pages(tmp); > - munlock_vma_pages_all(tmp); > - } > - tmp = tmp->vm_next; > - } > + munlock_vmas(tmp, end); No need for 'tmp' here. > } > > /* >