linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Qi Zheng <zhengqi.arch@bytedance.com>, Jann Horn <jannh@google.com>
Cc: akpm@linux-foundation.org, 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 09:52:37 +0200	[thread overview]
Message-ID: <75fac79a-0ff2-4ba0-bdd7-954efe2d9f41@redhat.com> (raw)
In-Reply-To: <1c114925-9206-42b1-b24b-bb123853a359@bytedance.com>

On 08.10.24 05:53, Qi Zheng wrote:
> 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?

My thinking was that it is cheap and more future proof to check that we 
really still have a page table here. For example, what if collapse code 
is ever changed to replace the page table by the collapsed PMD?

So unless there is a good reason not to have this check here, I would 
keep it like that.

Thanks!

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2024-10-08  7:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-07 21:42 [PATCH] mm/mremap: Fix move_normal_pmd/retract_page_tables race Jann Horn
2024-10-08  3:53 ` Qi Zheng
2024-10-08  7:52   ` David Hildenbrand [this message]
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=75fac79a-0ff2-4ba0-bdd7-954efe2d9f41@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --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 \
    --cc=zhengqi.arch@bytedance.com \
    /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;
as well as URLs for NNTP newsgroup(s).