Thread (123 messages) 123 messages, 4 authors, 2021-02-27
STALE1934d REVIEWED: 1 (0M)

[patch 045/118] mm/rmap: fix potential pte_unmap on an not mapped pte

From: Andrew Morton <akpm@linux-foundation.org>
Date: 2021-02-26 01:18:14
Also in: mm-commits

From: Miaohe Lin <linmiaohe@huawei.com>
Subject: mm/rmap: fix potential pte_unmap on an not mapped pte

For PMD-mapped page (usually THP), pvmw->pte is NULL.  For PTE-mapped THP,
pvmw->pte is mapped.  But for HugeTLB pages, pvmw->pte is not mapped and
set to the relevant page table entry.  So in page_vma_mapped_walk_done(),
we may do pte_unmap() for HugeTLB pte which is not mapped.  Fix this by
checking pvmw->page against PageHuge before trying to do pte_unmap().

Link: https://lkml.kernel.org/r/20210127093349.39081-1-linmiaohe@huawei.com
Fixes: ace71a19cec5 ("mm: introduce page_vma_mapped_walk()")
Signed-off-by: Hongxiang Lou <redacted>
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Tested-by: Sedat Dilek <redacted>
Cc: Kees Cook <redacted>
Cc: Nathan Chancellor <redacted>
Cc: Mike Kravetz <redacted>
Cc: Shakeel Butt <redacted>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vlastimil Babka <redacted>
Cc: Michel Lespinasse <redacted>
Cc: Nick Desaulniers <redacted>
Cc: "Kirill A. Shutemov" <redacted>
Cc: Wei Yang <redacted>
Cc: Dmitry Safonov <redacted>
Cc: Brian Geffon <redacted>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/rmap.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
--- a/include/linux/rmap.h~mm-rmap-fix-potential-pte_unmap-on-an-not-mapped-pte
+++ a/include/linux/rmap.h
@@ -213,7 +213,8 @@ struct page_vma_mapped_walk {
 
 static inline void page_vma_mapped_walk_done(struct page_vma_mapped_walk *pvmw)
 {
-	if (pvmw->pte)
+	/* HugeTLB pte is set to the relevant page table entry without pte_mapped. */
+	if (pvmw->pte && !PageHuge(pvmw->page))
 		pte_unmap(pvmw->pte);
 	if (pvmw->ptl)
 		spin_unlock(pvmw->ptl);
_
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help