linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Qi Zheng <zhengqi.arch@bytedance.com>
To: Muchun Song <muchun.song@linux.dev>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-arm-kernel@lists.infradead.org,
	linuxppc-dev@lists.ozlabs.org, david@redhat.com,
	hughd@google.com, willy@infradead.org, vbabka@kernel.org,
	akpm@linux-foundation.org, rppt@kernel.org,
	vishal.moola@gmail.com, peterx@redhat.com, ryan.roberts@arm.com,
	christophe.leroy2@cs-soprasteria.com
Subject: Re: [PATCH v3 09/14] mm: mremap: move_ptes() use pte_offset_map_rw_nolock()
Date: Thu, 5 Sep 2024 18:56:14 +0800	[thread overview]
Message-ID: <cccc16ad-21fb-4c99-8c49-91ee15c202cc@bytedance.com> (raw)
In-Reply-To: <1b03a7de-1278-4e36-8068-885dd1c29742@linux.dev>



On 2024/9/5 17:25, Muchun Song wrote:
> 
> 
> On 2024/9/4 16:40, Qi Zheng wrote:
>> In move_ptes(), we may modify the new_pte after acquiring the new_ptl, so
>> convert it to using pte_offset_map_rw_nolock(). Since we may free the PTE
>> page in retract_page_tables() without holding the read lock of mmap_lock,
>> so we still need to do a pmd_same() check after holding the PTL.
> 
> retract_page_tables() and move_ptes() are synchronized with
> i_mmap_lock, right?

Right, will remove the pmd_same() check in v4. Thanks!

> 
> Muchun,
> Thanks.
> 
>>
>> Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
>> ---
>>   mm/mremap.c | 20 ++++++++++++++++++--
>>   1 file changed, 18 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/mremap.c b/mm/mremap.c
>> index 24712f8dbb6b5..16e54151395ad 100644
>> --- a/mm/mremap.c
>> +++ b/mm/mremap.c
>> @@ -143,6 +143,7 @@ static int move_ptes(struct vm_area_struct *vma, 
>> pmd_t *old_pmd,
>>       spinlock_t *old_ptl, *new_ptl;
>>       bool force_flush = false;
>>       unsigned long len = old_end - old_addr;
>> +    pmd_t pmdval;
>>       int err = 0;
>>       /*
>> @@ -175,14 +176,29 @@ static int move_ptes(struct vm_area_struct *vma, 
>> pmd_t *old_pmd,
>>           err = -EAGAIN;
>>           goto out;
>>       }
>> -    new_pte = pte_offset_map_nolock(mm, new_pmd, new_addr, &new_ptl);
>> +    /*
>> +     * Since we may free the PTE page in retract_page_tables() without
>> +     * holding the read lock of mmap_lock, so we still need to do a
>> +     * pmd_same() check after holding the PTL.
>> +     */
>> +    new_pte = pte_offset_map_rw_nolock(mm, new_pmd, new_addr, &pmdval,
>> +                       &new_ptl);
>>       if (!new_pte) {
>>           pte_unmap_unlock(old_pte, old_ptl);
>>           err = -EAGAIN;
>>           goto out;
>>       }
>> -    if (new_ptl != old_ptl)
>> +    if (new_ptl != old_ptl) {
>>           spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING);
>> +
>> +        if (unlikely(!pmd_same(pmdval, pmdp_get_lockless(new_pmd)))) {
>> +            pte_unmap_unlock(new_pte, new_ptl);
>> +            pte_unmap_unlock(old_pte, old_ptl);
>> +            err = -EAGAIN;
>> +            goto out;
>> +        }
>> +    }
>> +
>>       flush_tlb_batched_pending(vma->vm_mm);
>>       arch_enter_lazy_mmu_mode();
> 


  reply	other threads:[~2024-09-05 10:56 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-04  8:40 [PATCH v3 00/14] introduce pte_offset_map_{ro|rw}_nolock() Qi Zheng
2024-09-04  8:40 ` [PATCH v3 01/14] mm: pgtable: " Qi Zheng
2024-09-06  7:20   ` Muchun Song
2024-09-12  9:28     ` Qi Zheng
2024-09-04  8:40 ` [PATCH v3 02/14] arm: adjust_pte() use pte_offset_map_rw_nolock() Qi Zheng
2024-09-04  8:40 ` [PATCH v3 03/14] powerpc: assert_pte_locked() use pte_offset_map_ro_nolock() Qi Zheng
2024-09-04  8:40 ` [PATCH v3 04/14] mm: filemap: filemap_fault_recheck_pte_none() " Qi Zheng
2024-09-04  8:40 ` [PATCH v3 05/14] mm: khugepaged: __collapse_huge_page_swapin() " Qi Zheng
2024-09-04  8:40 ` [PATCH v3 06/14] mm: handle_pte_fault() use pte_offset_map_rw_nolock() Qi Zheng
2024-09-04  8:40 ` [PATCH v3 07/14] mm: khugepaged: collapse_pte_mapped_thp() " Qi Zheng
2024-09-04  8:40 ` [PATCH v3 08/14] mm: copy_pte_range() " Qi Zheng
2024-09-05  8:57   ` Muchun Song
2024-09-05 10:55     ` Qi Zheng
2024-09-04  8:40 ` [PATCH v3 09/14] mm: mremap: move_ptes() " Qi Zheng
2024-09-05  9:25   ` Muchun Song
2024-09-05 10:56     ` Qi Zheng [this message]
2024-09-04  8:40 ` [PATCH v3 10/14] mm: page_vma_mapped_walk: map_pte() " Qi Zheng
2024-09-05 12:07   ` Muchun Song
2024-09-12  9:30     ` Qi Zheng
2024-09-04  8:40 ` [PATCH v3 11/14] mm: userfaultfd: move_pages_pte() " Qi Zheng
2024-09-05 12:20   ` Muchun Song
2024-09-04  8:40 ` [PATCH v3 12/14] mm: multi-gen LRU: walk_pte_range() " Qi Zheng
2024-09-05 12:23   ` Muchun Song
2024-09-04  8:40 ` [PATCH v3 13/14] mm: pgtable: remove pte_offset_map_nolock() Qi Zheng
2024-09-05 12:23   ` Muchun Song
2024-09-04  8:40 ` [PATCH v3 14/14] mm: khugepaged: retract_page_tables() use pte_offset_map_rw_nolock() Qi Zheng

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=cccc16ad-21fb-4c99-8c49-91ee15c202cc@bytedance.com \
    --to=zhengqi.arch@bytedance.com \
    --cc=akpm@linux-foundation.org \
    --cc=christophe.leroy2@cs-soprasteria.com \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=muchun.song@linux.dev \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=vbabka@kernel.org \
    --cc=vishal.moola@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).