[PATCH] arm64: hugetlb: Fix huge_pte_offset to return poisoned pmd
From: Punit Agrawal
Date: Thu Mar 09 2017 - 11:16:29 EST
When memory failure is enabled, a poisoned hugepage PMD is marked as a
swap entry. As pmd_present() only checks for VALID and PROT_NONE
bits (turned off for swap entries), it causues huge_pte_offset() to
return NULL for poisoned PMDs.
This behaviour of huge_pte_offset() leads to the error such as below
when munmap is called on poisoned hugepages.
[ 344.165544] mm/pgtable-generic.c:33: bad pmd 000000083af00074.
Fix huge_pte_offset() to return the poisoned PMD which is then
appropriately handled by the generic layer code.
Signed-off-by: Punit Agrawal <punit.agrawal@xxxxxxx>
Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: Steve Capper <steve.capper@xxxxxxx>
---
arch/arm64/mm/hugetlbpage.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index e25584d72396..9263f206353c 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -150,8 +150,17 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
if (pud_huge(*pud))
return (pte_t *)pud;
pmd = pmd_offset(pud, addr);
+
+ /*
+ * In case of HW Poisoning, a hugepage pmd can contain
+ * poisoned entries. Poisoned entries are marked as swap
+ * entries.
+ *
+ * For pmds that are not present, check to see if it could be
+ * a swap entry (!present and !none) before giving up.
+ */
if (!pmd_present(*pmd))
- return NULL;
+ return !pmd_none(*pmd) ? (pte_t *)pmd : NULL;
if (pte_cont(pmd_pte(*pmd))) {
pmd = pmd_offset(
--
2.11.0