From e3d2be9764500dff20adec673547ff4d5235a41d Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 24 Oct 2024 10:43:00 +0200 Subject: [PATCH] mm/filemap: return early if failed to allocate memory for split BugLink: https://bugs.launchpad.net/bugs/2085495 commit de60fd8ddeda2b41fbe11df11733838c5f684616 upstream. xas_split_alloc could fail with NOMEM, and in such case, it should abort early instead of keep going and fail the xas_split below. Link: https://lkml.kernel.org/r/20240416071722.45997-1-ryncsn@gmail.com Link: https://lkml.kernel.org/r/20240415171857.19244-1-ryncsn@gmail.com Link: https://lkml.kernel.org/r/20240415171857.19244-2-ryncsn@gmail.com Signed-off-by: Kairui Song Acked-by: Matthew Wilcox (Oracle) Signed-off-by: Andrew Morton Stable-dep-of: 6758c1128ceb ("mm/filemap: optimize filemap folio adding") Signed-off-by: Greg Kroah-Hartman (cherry picked from commit ff3c557fa93e7fcf5891e38fa7285b3c44e994b3 6.6.y) Signed-off-by: Matthew Ruffell Signed-off-by: Chengen Du Acked-by: Stefan Bader Acked-by: Manuel Diewald Signed-off-by: Stefan Bader --- mm/filemap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 605a779e23ca..33ad16c126c0 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -871,9 +871,12 @@ noinline int __filemap_add_folio(struct address_space *mapping, unsigned int order = xa_get_order(xas.xa, xas.xa_index); void *entry, *old = NULL; - if (order > folio_order(folio)) + if (order > folio_order(folio)) { xas_split_alloc(&xas, xa_load(xas.xa, xas.xa_index), order, gfp); + if (xas_error(&xas)) + goto error; + } xas_lock_irq(&xas); xas_for_each_conflict(&xas, entry) { old = entry;