Skip to content

Commit 8daf9c7

Browse files
osalvadorvilardagaakpm00
authored andcommitted
mm/hugetlb: do not call vma_add_reservation upon ENOMEM
sysbot reported a splat [1] on __unmap_hugepage_range(). This is because vma_needs_reservation() can return -ENOMEM if allocate_file_region_entries() fails to allocate the file_region struct for the reservation. Check for that and do not call vma_add_reservation() if that is the case, otherwise region_abort() and region_del() will see that we do not have any file_regions. If we detect that vma_needs_reservation() returned -ENOMEM, we clear the hugetlb_restore_reserve flag as if this reservation was still consumed, so free_huge_folio() will not increment the resv count. [1] https://lore.kernel.org/linux-mm/[email protected]/T/#ma5983bc1ab18a54910da83416b3f89f3c7ee43aa Link: https://lkml.kernel.org/r/[email protected] Fixes: df7a6d1 ("mm/hugetlb: restore the reservation if needed") Signed-off-by: Oscar Salvador <[email protected]> Reported-and-tested-by: [email protected] Closes: https://lore.kernel.org/linux-mm/[email protected]/ Cc: Breno Leitao <[email protected]> Cc: Muchun Song <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c2dc78b commit 8daf9c7

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

mm/hugetlb.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5768,8 +5768,20 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
57685768
* do_exit() will not see it, and will keep the reservation
57695769
* forever.
57705770
*/
5771-
if (adjust_reservation && vma_needs_reservation(h, vma, address))
5772-
vma_add_reservation(h, vma, address);
5771+
if (adjust_reservation) {
5772+
int rc = vma_needs_reservation(h, vma, address);
5773+
5774+
if (rc < 0)
5775+
/* Pressumably allocate_file_region_entries failed
5776+
* to allocate a file_region struct. Clear
5777+
* hugetlb_restore_reserve so that global reserve
5778+
* count will not be incremented by free_huge_folio.
5779+
* Act as if we consumed the reservation.
5780+
*/
5781+
folio_clear_hugetlb_restore_reserve(page_folio(page));
5782+
else if (rc)
5783+
vma_add_reservation(h, vma, address);
5784+
}
57735785

57745786
tlb_remove_page_size(tlb, page, huge_page_size(h));
57755787
/*

0 commit comments

Comments
 (0)