On ppc64 with the hash MMU, do_set_pmd() allocates the page table to deposit when the caller did not preallocate one. Both callers that let it allocate hold the folio lock: set_huge_pmd() in khugepaged never preallocates, and finish_fault() has no preallocated table when the page table was removed after __do_fault() checked the PMD. Allocating with __GFP_FS while holding a folio lock can deadlock in reclaim, for example the memcg reclaim deadlock on cgroup v1 described in commit 63f3655f9501 ("mm, memcg: fix reclaim deadlock with writeback"). pte_alloc_one() takes no gfp flags, so allocate the table in a NOFS scope. Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE") Fixes: 1d65b771bc08 ("mm/khugepaged: retract_page_tables() without mmap or vma lock") Cc: stable@vger.kernel.org Signed-off-by: Jose A. Perez de Azpillaga --- Changes in v2: - new, replaces v1 3/4 "mm/memory: never allocate a page table in do_set_pmd()" (David) v1: https://lore.kernel.org/20261125100058.15200-4-azpijr@gmail.com mm/memory.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index dfa307a9228c..05d03b32ce52 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5806,9 +5806,17 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct folio *folio, struct page *pa * related to pte entry. Use the preallocated table for that. */ if (arch_needs_pgtable_deposit() && !vmf->prealloc_pte) { + unsigned int nofs_flags; + if (!may_alloc) return VM_FAULT_FALLBACK; + /* + * The folio is locked, and reclaim or compaction with __GFP_FS + * could deadlock on it. pte_alloc_one() takes no gfp flags. + */ + nofs_flags = memalloc_nofs_save(); vmf->prealloc_pte = pte_alloc_one(vma->vm_mm); + memalloc_nofs_restore(nofs_flags); if (!vmf->prealloc_pte) return VM_FAULT_OOM; pgtable_allocated = true; -- 2.56.1