Skip to content

Commit 3a194f3

Browse files
nhoriguchiakpm00
authored andcommitted
mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry
follow_pud_mask() does not support non-present pud entry now. As long as I tested on x86_64 server, follow_pud_mask() still simply returns no_page_table() for non-present_pud_entry() due to pud_bad(), so no severe user-visible effect should happen. But generally we should call follow_huge_pud() for non-present pud entry for 1GB hugetlb page. Update pud_huge() and follow_huge_pud() to handle non-present pud entries. The changes are similar to previous works for pud entries commit e66f17f ("mm/hugetlb: take page table lock in follow_huge_pmd()") and commit cbef847 ("mm/hugetlb: pmd_huge() returns true for non-present hugepage"). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Naoya Horiguchi <[email protected]> Reviewed-by: Miaohe Lin <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: kernel test robot <[email protected]> Cc: Liu Shixin <[email protected]> Cc: Muchun Song <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Yang Shi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c053171 commit 3a194f3

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

arch/x86/mm/hugetlbpage.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ int pmd_huge(pmd_t pmd)
3030
(pmd_val(pmd) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT;
3131
}
3232

33+
/*
34+
* pud_huge() returns 1 if @pud is hugetlb related entry, that is normal
35+
* hugetlb entry or non-present (migration or hwpoisoned) hugetlb entry.
36+
* Otherwise, returns 0.
37+
*/
3338
int pud_huge(pud_t pud)
3439
{
35-
return !!(pud_val(pud) & _PAGE_PSE);
40+
return !pud_none(pud) &&
41+
(pud_val(pud) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT;
3642
}
3743

3844
#ifdef CONFIG_HUGETLB_PAGE

mm/hugetlb.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6985,10 +6985,38 @@ struct page * __weak
69856985
follow_huge_pud(struct mm_struct *mm, unsigned long address,
69866986
pud_t *pud, int flags)
69876987
{
6988-
if (flags & (FOLL_GET | FOLL_PIN))
6988+
struct page *page = NULL;
6989+
spinlock_t *ptl;
6990+
pte_t pte;
6991+
6992+
if (WARN_ON_ONCE(flags & FOLL_PIN))
69896993
return NULL;
69906994

6991-
return pte_page(*(pte_t *)pud) + ((address & ~PUD_MASK) >> PAGE_SHIFT);
6995+
retry:
6996+
ptl = huge_pte_lock(hstate_sizelog(PUD_SHIFT), mm, (pte_t *)pud);
6997+
if (!pud_huge(*pud))
6998+
goto out;
6999+
pte = huge_ptep_get((pte_t *)pud);
7000+
if (pte_present(pte)) {
7001+
page = pud_page(*pud) + ((address & ~PUD_MASK) >> PAGE_SHIFT);
7002+
if (WARN_ON_ONCE(!try_grab_page(page, flags))) {
7003+
page = NULL;
7004+
goto out;
7005+
}
7006+
} else {
7007+
if (is_hugetlb_entry_migration(pte)) {
7008+
spin_unlock(ptl);
7009+
__migration_entry_wait(mm, (pte_t *)pud, ptl);
7010+
goto retry;
7011+
}
7012+
/*
7013+
* hwpoisoned entry is treated as no_page_table in
7014+
* follow_page_mask().
7015+
*/
7016+
}
7017+
out:
7018+
spin_unlock(ptl);
7019+
return page;
69927020
}
69937021

69947022
struct page * __weak

0 commit comments

Comments
 (0)