linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Qi Zheng <zhengqi.arch@bytedance.com>
To: Jann Horn <jannh@google.com>
Cc: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org,
	willy@infradead.org, hughd@google.com,
	lorenzo.stoakes@oracle.com, joel@joelfernandes.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] mm/mremap: Fix move_normal_pmd/retract_page_tables race
Date: Tue, 8 Oct 2024 11:53:23 +0800	[thread overview]
Message-ID: <1c114925-9206-42b1-b24b-bb123853a359@bytedance.com> (raw)
In-Reply-To: <20241007-move_normal_pmd-vs-collapse-fix-2-v1-1-5ead9631f2ea@google.com>

Hi Jann,

On 2024/10/8 05:42, Jann Horn wrote:

[...]

> 
> diff --git a/mm/mremap.c b/mm/mremap.c
> index 24712f8dbb6b..dda09e957a5d 100644
> --- a/mm/mremap.c
> +++ b/mm/mremap.c
> @@ -238,6 +238,7 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr,
>   {
>   	spinlock_t *old_ptl, *new_ptl;
>   	struct mm_struct *mm = vma->vm_mm;
> +	bool res = false;
>   	pmd_t pmd;
>   
>   	if (!arch_supports_page_table_move())
> @@ -277,19 +278,25 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr,
>   	if (new_ptl != old_ptl)
>   		spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING);
>   
> -	/* Clear the pmd */
>   	pmd = *old_pmd;
> +
> +	/* Racing with collapse? */
> +	if (unlikely(!pmd_present(pmd) || pmd_leaf(pmd)))

Since we already hold the exclusive mmap lock, after a racing
with collapse occurs, the pmd entry cannot be refilled with
new content by page fault. So maybe we only need to recheck
pmd_none(pmd) here?

Thanks,
Qi

> +		goto out_unlock;
> +	/* Clear the pmd */
>   	pmd_clear(old_pmd);
> +	res = true;
>   
>   	VM_BUG_ON(!pmd_none(*new_pmd));
>   
>   	pmd_populate(mm, new_pmd, pmd_pgtable(pmd));
>   	flush_tlb_range(vma, old_addr, old_addr + PMD_SIZE);
> +out_unlock:
>   	if (new_ptl != old_ptl)
>   		spin_unlock(new_ptl);
>   	spin_unlock(old_ptl);
>   
> -	return true;
> +	return res;
>   }
>   #else
>   static inline bool move_normal_pmd(struct vm_area_struct *vma,
> 
> ---
> base-commit: 8cf0b93919e13d1e8d4466eb4080a4c4d9d66d7b
> change-id: 20241007-move_normal_pmd-vs-collapse-fix-2-387e9a68c7d6


  reply	other threads:[~2024-10-08  3:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-07 21:42 Jann Horn
2024-10-08  3:53 ` Qi Zheng [this message]
2024-10-08  7:52   ` David Hildenbrand
2024-10-08  7:58     ` Qi Zheng
2024-10-08  8:21       ` David Hildenbrand
2024-10-08  7:50 ` David Hildenbrand
2024-10-08 23:58 ` Joel Fernandes
2024-10-09  0:49   ` Jann Horn
2024-10-09  1:46     ` Joel Fernandes
2024-10-09 14:44 ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1c114925-9206-42b1-b24b-bb123853a359@bytedance.com \
    --to=zhengqi.arch@bytedance.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=jannh@google.com \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=stable@vger.kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox