Skip to content

Commit f02ab08

Browse files
punitagrawalwildea01
authored andcommitted
arm64: hugetlb: Fix huge_pte_offset to return poisoned page table entries
When memory failure is enabled, a poisoned hugepage pte is marked as a swap entry. huge_pte_offset() does not return the poisoned page table entries when it encounters PUD/PMD hugepages. This behaviour of huge_pte_offset() leads to 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 pte which is then appropriately handled by the generic layer code. Signed-off-by: Punit Agrawal <punit.agrawal@arm.com> Acked-by: Steve Capper <steve.capper@arm.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Cc: David Woods <dwoods@mellanox.com> Tested-by: Manoj Iyer <manoj.iyer@canonical.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 6876442 commit f02ab08

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

arch/arm64/include/asm/pgtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static inline phys_addr_t pmd_page_paddr(pmd_t pmd)
441441

442442
#define pud_none(pud) (!pud_val(pud))
443443
#define pud_bad(pud) (!(pud_val(pud) & PUD_TABLE_BIT))
444-
#define pud_present(pud) (pud_val(pud))
444+
#define pud_present(pud) pte_present(pud_pte(pud))
445445

446446
static inline void set_pud(pud_t *pudp, pud_t pud)
447447
{

arch/arm64/mm/hugetlbpage.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,36 +136,27 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
136136
{
137137
pgd_t *pgd;
138138
pud_t *pud;
139-
pmd_t *pmd = NULL;
140-
pte_t *pte = NULL;
139+
pmd_t *pmd;
141140

142141
pgd = pgd_offset(mm, addr);
143142
pr_debug("%s: addr:0x%lx pgd:%p\n", __func__, addr, pgd);
144143
if (!pgd_present(*pgd))
145144
return NULL;
145+
146146
pud = pud_offset(pgd, addr);
147-
if (!pud_present(*pud))
147+
if (pud_none(*pud))
148148
return NULL;
149-
150-
if (pud_huge(*pud))
149+
/* swap or huge page */
150+
if (!pud_present(*pud) || pud_huge(*pud))
151151
return (pte_t *)pud;
152+
/* table; check the next level */
153+
152154
pmd = pmd_offset(pud, addr);
153-
if (!pmd_present(*pmd))
155+
if (pmd_none(*pmd))
154156
return NULL;
155-
156-
if (pte_cont(pmd_pte(*pmd))) {
157-
pmd = pmd_offset(
158-
pud, (addr & CONT_PMD_MASK));
159-
return (pte_t *)pmd;
160-
}
161-
if (pmd_huge(*pmd))
157+
if (!pmd_present(*pmd) || pmd_huge(*pmd))
162158
return (pte_t *)pmd;
163-
pte = pte_offset_kernel(pmd, addr);
164-
if (pte_present(*pte) && pte_cont(*pte)) {
165-
pte = pte_offset_kernel(
166-
pmd, (addr & CONT_PTE_MASK));
167-
return pte;
168-
}
159+
169160
return NULL;
170161
}
171162

0 commit comments

Comments
 (0)