From: Peter Xu <peterx@redhat.com>
To: linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org
Cc: Hugh Dickins <hughd@google.com>,
David Hildenbrand <david@redhat.com>,
Liam Howlett <liam.howlett@oracle.com>,
Mike Rapoport <rppt@linux.vnet.ibm.com>,
Alistair Popple <apopple@nvidia.com>,
Matthew Wilcox <willy@infradead.org>,
peterx@redhat.com, Yang Shi <shy828301@gmail.com>,
"Kirill A . Shutemov" <kirill@shutemov.name>,
Jerome Glisse <jglisse@redhat.com>,
Miaohe Lin <linmiaohe@huawei.com>,
Andrea Arcangeli <aarcange@redhat.com>
Subject: [PATCH v4 2/4] mm: Clear vmf->pte after pte_unmap_same() returns
Date: Wed, 15 Sep 2021 14:15:33 -0400 [thread overview]
Message-ID: <20210915181533.11188-1-peterx@redhat.com> (raw)
In-Reply-To: <20210915181456.10739-1-peterx@redhat.com>
pte_unmap_same() will always unmap the pte pointer. After the unmap, vmf->pte
will not be valid any more, we should clear it.
It was safe only because no one is accessing vmf->pte after pte_unmap_same()
returns, since the only caller of pte_unmap_same() (so far) is do_swap_page(),
where vmf->pte will in most cases be overwritten very soon.
Directly pass in vmf into pte_unmap_same() and then we can also avoid the long
parameter list too, which should be a nice cleanup.
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Liam Howlett <liam.howlett@oracle.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
mm/memory.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 25fc46e87214..7b095f07c4ef 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2724,19 +2724,19 @@ EXPORT_SYMBOL_GPL(apply_to_existing_page_range);
* proceeding (but do_wp_page is only called after already making such a check;
* and do_anonymous_page can safely check later on).
*/
-static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd,
- pte_t *page_table, pte_t orig_pte)
+static inline int pte_unmap_same(struct vm_fault *vmf)
{
int same = 1;
#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPTION)
if (sizeof(pte_t) > sizeof(unsigned long)) {
- spinlock_t *ptl = pte_lockptr(mm, pmd);
+ spinlock_t *ptl = pte_lockptr(vmf->vma->vm_mm, vmf->pmd);
spin_lock(ptl);
- same = pte_same(*page_table, orig_pte);
+ same = pte_same(*vmf->pte, vmf->orig_pte);
spin_unlock(ptl);
}
#endif
- pte_unmap(page_table);
+ pte_unmap(vmf->pte);
+ vmf->pte = NULL;
return same;
}
@@ -3487,7 +3487,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
vm_fault_t ret = 0;
void *shadow = NULL;
- if (!pte_unmap_same(vma->vm_mm, vmf->pmd, vmf->pte, vmf->orig_pte))
+ if (!pte_unmap_same(vmf))
goto out;
entry = pte_to_swp_entry(vmf->orig_pte);
--
2.31.1
next prev parent reply other threads:[~2021-09-15 18:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-15 18:14 [PATCH v4 0/4] mm: A few cleanup patches around zap, shmem and uffd Peter Xu
2021-09-15 18:14 ` [PATCH v4 1/4] mm/shmem: Unconditionally set pte dirty in mfill_atomic_install_pte Peter Xu
2021-09-24 3:56 ` Hugh Dickins
2021-09-27 21:21 ` Peter Xu
2021-09-28 19:28 ` Hugh Dickins
2021-09-28 21:37 ` Peter Xu
2021-11-04 21:34 ` Andrew Morton
2021-11-05 1:01 ` Peter Xu
2021-09-15 18:15 ` Peter Xu [this message]
2021-09-24 3:59 ` [PATCH v4 2/4] mm: Clear vmf->pte after pte_unmap_same() returns Hugh Dickins
2021-09-15 18:15 ` [PATCH v4 3/4] mm: Drop first_index/last_index in zap_details Peter Xu
2021-09-24 4:14 ` Hugh Dickins
2021-09-15 18:15 ` [PATCH v4 4/4] mm: Add zap_skip_check_mapping() helper Peter Xu
2021-09-24 4:44 ` Hugh Dickins
2021-09-24 10:11 ` David Hildenbrand
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=20210915181533.11188-1-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=jglisse@redhat.com \
--cc=kirill@shutemov.name \
--cc=liam.howlett@oracle.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rppt@linux.vnet.ibm.com \
--cc=shy828301@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).