diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 60d3def1342d19fcf5ebfcb62fbe45fb605c9902..3e62bae06d7a0cc04d92a5f9bfb9cb47fb891f71 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3035,12 +3035,20 @@ int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long end_pfn) while (start_pfn < end_pfn) { folio = pfn_folio(start_pfn); + + /* + * The folio might have been dissolved from under our feet, so make sure + * to carefully check the state under the lock. + */ + spin_lock_irq(&hugetlb_lock); if (folio_test_hugetlb(folio)) { h = folio_hstate(folio); } else { + spin_unlock_irq(&hugetlb_lock); start_pfn++; continue; } + spin_unlock_irq(&hugetlb_lock); if (!folio_ref_count(folio)) { ret = alloc_and_dissolve_hugetlb_folio(h, folio,