Skip to content

Commit 37641ef

Browse files
VMoolaakpm00
authored andcommitted
hugetlb: check for anon_vma prior to folio allocation
Commit 9acad7b ("hugetlb: use vmf_anon_prepare() instead of anon_vma_prepare()") may bailout after allocating a folio if we do not hold the mmap lock. When this occurs, vmf_anon_prepare() will release the vma lock. Hugetlb then attempts to call restore_reserve_on_error(), which depends on the vma lock being held. We can move vmf_anon_prepare() prior to the folio allocation in order to avoid calling restore_reserve_on_error() without the vma lock. Link: https://lkml.kernel.org/r/ZiFqSrSRLhIV91og@fedora Fixes: 9acad7b ("hugetlb: use vmf_anon_prepare() instead of anon_vma_prepare()") Reported-by: [email protected] Signed-off-by: Vishal Moola (Oracle) <[email protected]> Cc: Muchun Song <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 682886e commit 37641ef

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

mm/hugetlb.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6261,6 +6261,12 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
62616261
VM_UFFD_MISSING);
62626262
}
62636263

6264+
if (!(vma->vm_flags & VM_MAYSHARE)) {
6265+
ret = vmf_anon_prepare(vmf);
6266+
if (unlikely(ret))
6267+
goto out;
6268+
}
6269+
62646270
folio = alloc_hugetlb_folio(vma, haddr, 0);
62656271
if (IS_ERR(folio)) {
62666272
/*
@@ -6297,15 +6303,12 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
62976303
*/
62986304
restore_reserve_on_error(h, vma, haddr, folio);
62996305
folio_put(folio);
6306+
ret = VM_FAULT_SIGBUS;
63006307
goto out;
63016308
}
63026309
new_pagecache_folio = true;
63036310
} else {
63046311
folio_lock(folio);
6305-
6306-
ret = vmf_anon_prepare(vmf);
6307-
if (unlikely(ret))
6308-
goto backout_unlocked;
63096312
anon_rmap = 1;
63106313
}
63116314
} else {

0 commit comments

Comments
 (0)