With optimized vmemmap, we defer freeing surplus folios to a workqueue, which restores the vmemmap and frees the folio, or adds it back to the pool if restoring the vmemmap fails. However, until the worker has run, the memory is neither in the buddy nor in the pool. Consequently, a task that unmaps surplus folios and immediately faults in new ones can get SIGBUS. Reproduced by artificially delaying the worker, filling memory with surplus folios, unmapping one and touching a new one: the task gets SIGBUS. Let's fix it by waiting for deferred frees and retrying once if an allocation fails while frees are pending. This has low urgency, as it requires overcommitting surplus folios under memory pressure. No need to CC stable. Fixes: b65d4adbc0f0 ("mm: hugetlb: defer freeing of HugeTLB pages") Reported-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) --- mm/hugetlb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5984377160d37..d7ced61b4d2d4 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3218,6 +3218,9 @@ static struct folio *__alloc_hugetlb_folio(struct vm_area_struct *vma, }; folio = hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags); + /* Wait for deferred freeing and retry once before giving up. */ + if (IS_ERR(folio) && flush_work(&free_hpage_work)) + folio = hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags); mpol_cond_put(mpol); -- 2.56.1