From: Miaohe Lin <linmia...@huawei.com> [ Upstream commit 5d5d19eda6b0ee790af89c45e3f678345be6f50f ]
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-linmia...@huawei.com Fixes: ace71a19cec5 ("mm: introduce page_vma_mapped_walk()") Signed-off-by: Hongxiang Lou <louhongxi...@huawei.com> Signed-off-by: Miaohe Lin <linmia...@huawei.com> Tested-by: Sedat Dilek <sedat.di...@gmail.com> Cc: Kees Cook <keesc...@chromium.org> Cc: Nathan Chancellor <natechancel...@gmail.com> Cc: Mike Kravetz <mike.krav...@oracle.com> Cc: Shakeel Butt <shake...@google.com> Cc: Johannes Weiner <han...@cmpxchg.org> Cc: Vlastimil Babka <vba...@suse.cz> Cc: Michel Lespinasse <wal...@google.com> Cc: Nick Desaulniers <ndesaulni...@google.com> Cc: "Kirill A. Shutemov" <kirill.shute...@linux.intel.com> Cc: Wei Yang <richard.weiy...@linux.alibaba.com> Cc: Dmitry Safonov <0x7f454...@gmail.com> Cc: Brian Geffon <bgef...@google.com> Signed-off-by: Andrew Morton <a...@linux-foundation.org> Signed-off-by: Linus Torvalds <torva...@linux-foundation.org> Signed-off-by: Sasha Levin <sas...@kernel.org> --- include/linux/rmap.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 70085ca1a3fc9..def5c62c93b3b 100644 --- a/include/linux/rmap.h +++ b/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); -- 2.27.0