Hi Kirill,

On Tue, Jul 14, 2020 at 10:33:06AM +0300, Kirill A. Shutemov wrote:
> On Sun, Jul 12, 2020 at 03:58:06PM -0700, Linus Torvalds wrote:
> > Anybody else have any opinions?
> 
> Maybe we just shouldn't allow move_normal_pmd() if ranges overlap?
> 
> Other option: pass 'overlaps' down to move_normal_pmd() and only WARN() if
> see establised PMD without overlaps being true.

I was thinking we should not call move_page_tables() with overlapping ranges
at all, just to keep things simple. I am concerned about other issues such as
if you move a range forward, you will end up overwriting part of the source
range.

Allow me some time to develop a proper patch, I have it on my list. I will
try to get to it this week.

I think we can also add a patch to detect the overlap as you did and warn in
such situation.

Thoughts?

thanks,

 - Joel


> Untested patch:
> 
> diff --git a/mm/mremap.c b/mm/mremap.c
> index 5dd572d57ca9..e33fcee541fe 100644
> --- a/mm/mremap.c
> +++ b/mm/mremap.c
> @@ -245,6 +245,18 @@ unsigned long move_page_tables(struct vm_area_struct 
> *vma,
>       unsigned long extent, next, old_end;
>       struct mmu_notifier_range range;
>       pmd_t *old_pmd, *new_pmd;
> +     bool overlaps;
> +
> +     /*
> +      * shift_arg_pages() can call move_page_tables() on overlapping ranges.
> +      * In this case we cannot use move_normal_pmd() because destination pmd
> +      * might be established page table: move_ptes() doesn't free page
> +      * table.
> +      */
> +     if (old_addr > new_addr)
> +             overlaps = old_addr - new_addr < len;
> +     else
> +             overlaps = new_addr - old_addr < len;
>  
>       old_end = old_addr + len;
>       flush_cache_range(vma, old_addr, old_end);
> @@ -282,7 +294,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
>                       split_huge_pmd(vma, old_pmd, old_addr);
>                       if (pmd_trans_unstable(old_pmd))
>                               continue;
> -             } else if (extent == PMD_SIZE) {
> +             } else if (!overlaps && extent == PMD_SIZE) {
>  #ifdef CONFIG_HAVE_MOVE_PMD
>                       /*
>                        * If the extent is PMD-sized, try to speed the move by
> -- 
>  Kirill A. Shutemov

Reply via email to