__memcg_list_lru_alloc() populates missing list_lru_memcg entries top-down, from the farthest unpopulated ancestor down to @memcg. When storing the entry for an ancestor (pos != memcg) needs a new xa_node, xas_store() sets XA_ERROR(-ENOMEM) and leaves @pos unpopulated. If the following xas_nomem() also fails to allocate, the inner loop exits with the error still set, but the outer loop ignores it and reruns on the same unpopulated ancestor: xas_set() then resets the state to XAS_RESTART and retries the store. A one-off failure is recovered on that retry, but as long as the allocation keeps failing, e.g. under sustained memory pressure, the loop makes no progress and, with no schedule point, becomes an RCU stall / hard lockup when the caller holds mapping->i_pages.xa_lock with IRQs disabled. Stop the outer walk when xas_error() is set so the existing cleanup frees @mlru and the error is propagated to the caller. Fixes: 28e98022b31e ("mm/list_lru: simplify reparenting and initial allocation") Cc: stable@vger.kernel.org Reported-by: Sashiko Closes: https://sashiko.dev/#/bug/linux-21c1dba9-8d6f-4368-b38b-9a57cacb056f Signed-off-by: Muchun Song --- mm/list_lru.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index 651983d0bf8b..1e0ea7975acb 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -626,7 +626,7 @@ static int __memcg_list_lru_alloc(struct mem_cgroup *memcg, } xas_unlock_irqrestore(&xas, flags); } while (xas_nomem(&xas, gfp)); - } while (pos != memcg && !css_is_dying(&pos->css)); + } while (pos != memcg && !css_is_dying(&pos->css) && !xas_error(&xas)); if (unlikely(mlru)) kfree(mlru); base-commit: 7d1a16abe4cc5dccd21e3d6262e44433a5885d27 -- 2.54.0