Skip to contentSkip to conversation

mm/rmap: Fix potential pte_unmap on an not mapped pte

PATCH Applied Miaohe Lin 2 participants 3 messages Jan 27, 2021 – Jan 28, 2021

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 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().

Fixes commit ("ace71a19cec5 mm: introduce page_vma_mapped_walk()")
---
 include/linux/rmap.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/rmap.h +2 -1
index 70085ca1a3fc..def5c62c93b3 100644
@@ -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);
Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 6 lines · On Wed, 27 Jan 2021 04:33:49 -0500 Miaohe Lin <[email protected]> wrote:

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().

What are the runtime consequences of this? Is there a workload which is known to trigger it?

IOW, how do we justify a -stable backport of this fix?

Quoted 15 lines
include/linux/rmap.h +2 -1
@@ -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);
Signature · 1 line
2.19.1
author
#2 lore raw

Hi:

Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Wed, 27 Jan 2021 04:33:49 -0500 Miaohe Lin <[email protected]> wrote:

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().

Quoted 3 lines

What are the runtime consequences of this? Is there a workload which is known to trigger it?

Not yet. This should not be backported. My bad. Sorry about it.

Quoted 18 lines

IOW, how do we justify a -stable backport of this fix?

Quoted 15 lines
Quoted 1 line
include/linux/rmap.h +2 -1
@@ -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);
Signature · 1 line
2.19.1

.