From: David Hildenbrand <david@redhat.com>
To: Miaohe Lin <linmiaohe@huawei.com>, akpm@linux-foundation.org
Cc: mike.kravetz@oracle.com, shy828301@gmail.com,
willy@infradead.org, ying.huang@intel.com, ziy@nvidia.com,
minchan@kernel.org, apopple@nvidia.com,
dave.hansen@linux.intel.com, o451686892@gmail.com,
jhubbard@nvidia.com, peterx@redhat.com, naoya.horiguchi@nec.com,
mhocko@suse.com, riel@redhat.com, osalvador@suse.de,
sfr@canb.auug.org.au, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] mm/migration: fix potential pte_unmap on an not mapped pte
Date: Mon, 11 Apr 2022 13:41:58 +0200 [thread overview]
Message-ID: <a190e78f-d833-780b-6fbe-b129c2505deb@redhat.com> (raw)
In-Reply-To: <20220409073846.22286-5-linmiaohe@huawei.com>
On 09.04.22 09:38, Miaohe Lin wrote:
> __migration_entry_wait and migration_entry_wait_on_locked assume pte is
> always mapped from caller. But this is not the case when it's called from
> migration_entry_wait_huge and follow_huge_pmd. And a parameter unmap to
> indicate whether pte needs to be unmapped to fix this issue.
Hm.
migration_entry_wait_on_locked documents
"@ptep: mapped pte pointer. Will return with the ptep unmapped. Only
required for pte entries, pass NULL for pmd entries."
Setting ptep implies that we have a *mapped pte* pointer that requires unmap.
If some code sets that although that's not guaranteed, that calling code
is wrong and needs to be fixed to not pass a ptep.
hugetlbfs never requires a map/unmap. I really don't see we there is need to
adjust migration_entry_wait_on_locked(): just don't pass a ptep as documented.
What's really nasty here is that hugetlbfs actually mostly works on PMD/PUD,
but we call it PTEs. One corner case might be CONT PTEs, but they are also
accessed without a map+unmap.
Regarding __migration_entry_wait(), I think we should just stop using it for
hugetlbfs and have a proper hugetlbfs variant that calls
hugetlb_migration_entry_wait(ptep == NULL), and knows that although we're
handling ptes, we're usually not actually holding ptes in our hands
that need a map+unmap.
Something like (including some cleanups mm parameter):
diff --git a/include/linux/swapops.h b/include/linux/swapops.h
index 32d517a28969..898c407ad8f7 100644
--- a/include/linux/swapops.h
+++ b/include/linux/swapops.h
@@ -234,8 +234,8 @@ extern void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep,
spinlock_t *ptl);
extern void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd,
unsigned long address);
-extern void migration_entry_wait_huge(struct vm_area_struct *vma,
- struct mm_struct *mm, pte_t *pte);
+extern void __migration_entry_wait_huge(pte_t *ptep, spinlock_t *ptl);
+extern void migration_entry_wait_huge(struct vm_area_struct *vma, pte_t *pte);
#else
static inline swp_entry_t make_readable_migration_entry(pgoff_t offset)
{
@@ -261,8 +261,9 @@ static inline void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep,
spinlock_t *ptl) { }
static inline void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd,
unsigned long address) { }
+static inline void __migration_entry_wait_huge(pte_t *ptep, spinlock_t *ptl) { }
static inline void migration_entry_wait_huge(struct vm_area_struct *vma,
- struct mm_struct *mm, pte_t *pte) { }
+ pte_t *pte) { }
static inline int is_writable_migration_entry(swp_entry_t entry)
{
return 0;
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 48740e6c3476..2b38eaaa2e60 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5622,7 +5622,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
*/
entry = huge_ptep_get(ptep);
if (unlikely(is_hugetlb_entry_migration(entry))) {
- migration_entry_wait_huge(vma, mm, ptep);
+ migration_entry_wait_huge(vma, ptep);
return 0;
} else if (unlikely(is_hugetlb_entry_hwpoisoned(entry)))
return VM_FAULT_HWPOISON_LARGE |
@@ -6770,7 +6770,7 @@ follow_huge_pmd(struct mm_struct *mm, unsigned long address,
} else {
if (is_hugetlb_entry_migration(pte)) {
spin_unlock(ptl);
- __migration_entry_wait(mm, (pte_t *)pmd, ptl);
+ __migration_entry_wait_huge((pte_t *)pmd, ptl);
goto retry;
}
/*
diff --git a/mm/migrate.c b/mm/migrate.c
index 231907e89b93..84b685a235fe 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -315,11 +315,26 @@ void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd,
__migration_entry_wait(mm, ptep, ptl);
}
+void __migration_entry_wait_huge(pte_t *ptep, spinlock_t *ptl)
+{
+ swp_entry_t entry;
+ pte_t pte;
+
+ spin_lock(ptl);
+ pte = huge_ptep_get(ptep);
+
+ if (unlikely(!is_hugetlb_entry_migration(pte)))
+ spin_unlock(ptl);
+ else
+ migration_entry_wait_on_locked(pte_to_swp_entry(pte), NULL, ptl);
+}
+
void migration_entry_wait_huge(struct vm_area_struct *vma,
struct mm_struct *mm, pte_t *pte)
{
- spinlock_t *ptl = huge_pte_lockptr(hstate_vma(vma), mm, pte);
- __migration_entry_wait(mm, pte, ptl);
+ spinlock_t *ptl = huge_pte_lockptr(hstate_vma(vma), vma->mm, pte);
+
+ __migration_entry_wait_huge(pte, ptl);
}
#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2022-04-11 11:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-09 7:38 [PATCH 0/4] A few cleanup and fixup patches for migration Miaohe Lin
2022-04-09 7:38 ` [PATCH 1/4] mm/migration: reduce the rcu lock duration Miaohe Lin
2022-04-11 14:09 ` Christoph Hellwig
2022-04-12 2:07 ` ying.huang
2022-04-12 3:21 ` Miaohe Lin
2022-04-09 7:38 ` [PATCH 2/4] mm/migration: remove unneeded lock page and PageMovable check Miaohe Lin
2022-04-11 14:09 ` Christoph Hellwig
2022-04-09 7:38 ` [PATCH 3/4] mm/migration: return errno when isolate_huge_page failed Miaohe Lin
2022-04-11 14:10 ` Christoph Hellwig
2022-04-12 3:13 ` Miaohe Lin
2022-04-09 7:38 ` [PATCH 4/4] mm/migration: fix potential pte_unmap on an not mapped pte Miaohe Lin
2022-04-09 11:38 ` kernel test robot
2022-04-11 1:54 ` Miaohe Lin
2022-04-11 11:41 ` David Hildenbrand [this message]
2022-04-12 2:55 ` Miaohe Lin
2022-04-12 2:25 ` [PATCH 0/4] A few cleanup and fixup patches for migration ying.huang
2022-04-12 3:29 ` Miaohe Lin
2022-04-12 6:33 ` ying.huang
2022-04-12 8:59 ` Miaohe Lin
2022-04-12 7:00 ` ying.huang
2022-04-12 9:06 ` Miaohe Lin
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=a190e78f-d833-780b-6fbe-b129c2505deb@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=dave.hansen@linux.intel.com \
--cc=jhubbard@nvidia.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=mike.kravetz@oracle.com \
--cc=minchan@kernel.org \
--cc=naoya.horiguchi@nec.com \
--cc=o451686892@gmail.com \
--cc=osalvador@suse.de \
--cc=peterx@redhat.com \
--cc=riel@redhat.com \
--cc=sfr@canb.auug.org.au \
--cc=shy828301@gmail.com \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
--cc=ziy@nvidia.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