From: David Hildenbrand <david@redhat.com>
To: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Jann Horn <jannh@google.com>,
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 10:21:10 +0200 [thread overview]
Message-ID: <7201c25f-0b6e-4a8b-b6a1-b09c6730fb32@redhat.com> (raw)
In-Reply-To: <b989a811-f764-4b3d-b536-be4e68c0638e@bytedance.com>
On 08.10.24 09:58, Qi Zheng wrote:
>
>
> On 2024/10/8 15:52, David Hildenbrand wrote:
>> 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?
>
> Ah, make sense.
>
> Acked-by: Qi Zheng <zhengqi.arch@bytedance.com>
Thanks a lot for your review!
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-10-08 8:21 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
2024-10-08 7:58 ` Qi Zheng
2024-10-08 8:21 ` David Hildenbrand [this message]
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=7201c25f-0b6e-4a8b-b6a1-b09c6730fb32@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).