From: Qi Zheng <zhengqi.arch@bytedance.com>
To: "Mika Penttilä" <mika.penttila@nextfour.com>,
akpm@linux-foundation.org, tglx@linutronix.de,
hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, songmuchun@bytedance.com
Subject: Re: [PATCH 5/7] mm: free user PTE page table pages
Date: Mon, 19 Jul 2021 20:56:01 +0800 [thread overview]
Message-ID: <80b7d7fc-9d6d-0d1b-a333-b0ccd856e7c1@bytedance.com> (raw)
In-Reply-To: <9c3c87d5-e64e-f13f-ef36-b438e4de1e66@nextfour.com>
On 7/18/21 2:19 PM, Mika Penttilä wrote:
>> +
>> +/*
>> + * returns true if the pmd has been populated with PTE page table,
>> + * or false for all other cases.
>> + */
>> +bool pte_install_try_get(struct mm_struct *mm, pmd_t *pmd, pgtable_t
>> *pte)
>> +{
>> + spinlock_t *ptl;
>> + bool retval = true;
>> +
>> +retry:
>> + ptl = pmd_lock(mm, pmd);
>> + if (likely(pmd_none(*pmd))) {
>> + __pte_install(mm, pmd, pte);
>> + } else if (pmd_leaf(*pmd) || !pmd_present(*pmd)) {
>> + retval = false;
>> + } else if (!pte_get_unless_zero(pmd)) {
>> + spin_unlock(ptl);
>> + goto retry;
>> + }
>> + spin_unlock(ptl);
>> + return retval;
>> +}
>> +
>
> Can pte_get_unless_zero() return true above? Can the pmd have been by
> populated by others? In that case the ref count is wrongly incremented.
>
Here we only have mmap_read_lock(mm), so the pmd can be populated with
other PTE page table page after a page fault in a different thread B of
this mm. In this case, thread B already hold a pte_refcount of the PTE
page table page populated in the pmd, so pte_get_unless_zero() can
return true above.
Similarly, if THP is enabled, the pmd also can be populated with a THP
page, we can see more detail in comment in handle_pte_fault(). The
pmd_leaf() above is to detect this situation.
next prev parent reply other threads:[~2021-07-19 12:56 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-18 4:30 [PATCH 0/7] Free user PTE page table pages Qi Zheng
2021-07-18 4:30 ` [PATCH 1/7] mm: fix the deadlock in finish_fault() Qi Zheng
2021-07-18 21:28 ` Kirill A. Shutemov
2021-07-19 9:53 ` Qi Zheng
2021-07-20 23:14 ` Andrew Morton
2021-07-21 2:21 ` Qi Zheng
2021-07-18 4:30 ` [PATCH 2/7] mm: introduce pte_install() helper Qi Zheng
2021-07-18 21:31 ` Kirill A. Shutemov
2021-07-19 10:20 ` Qi Zheng
2021-07-18 4:30 ` [PATCH 3/7] mm: remove redundant smp_wmb() Qi Zheng
2021-07-27 13:39 ` Muchun Song
2021-07-18 4:30 ` [PATCH 4/7] mm: rework the parameter of lock_page_or_retry() Qi Zheng
2021-07-18 4:30 ` [PATCH 5/7] mm: free user PTE page table pages Qi Zheng
2021-07-18 6:19 ` Mika Penttilä
2021-07-19 12:56 ` Qi Zheng [this message]
2021-07-19 13:55 ` Mika Penttilä
2021-07-19 14:12 ` Qi Zheng
2021-07-19 14:17 ` Mika Penttilä
2021-07-18 22:01 ` Kirill A. Shutemov
2021-07-19 13:55 ` Qi Zheng
2021-07-18 4:30 ` [PATCH 6/7] mm: defer freeing PTE page table for a grace period Qi Zheng
2021-07-18 4:30 ` [PATCH 7/7] mm: use mmu_gather to free PTE page table Qi Zheng
2021-07-19 7:34 ` [PATCH 0/7] Free user PTE page table pages David Hildenbrand
2021-07-19 11:28 ` David Hildenbrand
2021-07-19 12:42 ` Muchun Song
2021-07-19 13:30 ` Muchun Song
2021-07-20 4:00 ` 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=80b7d7fc-9d6d-0d1b-a333-b0ccd856e7c1@bytedance.com \
--to=zhengqi.arch@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mika.penttila@nextfour.com \
--cc=songmuchun@bytedance.com \
--cc=tglx@linutronix.de \
--cc=vdavydov.dev@gmail.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).