* [PATCH] mm/list_lru: fix potential infinite loop on xa node allocation failure
@ 2026-11-22 3:11 Muchun Song
2026-11-22 7:08 ` Qi Zheng
0 siblings, 1 reply; 2+ messages in thread
From: Muchun Song @ 2026-11-22 3:11 UTC (permalink / raw)
To: Andrew Morton, Dave Chinner
Cc: Qi Zheng, Roman Gushchin, Muchun Song, Kairui Song, linux-mm,
Muchun Song, stable, Sashiko
__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 <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-21c1dba9-8d6f-4368-b38b-9a57cacb056f
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] mm/list_lru: fix potential infinite loop on xa node allocation failure
2026-11-22 3:11 [PATCH] mm/list_lru: fix potential infinite loop on xa node allocation failure Muchun Song
@ 2026-11-22 7:08 ` Qi Zheng
0 siblings, 0 replies; 2+ messages in thread
From: Qi Zheng @ 2026-11-22 7:08 UTC (permalink / raw)
To: Muchun Song, Andrew Morton, Dave Chinner
Cc: Roman Gushchin, Muchun Song, Kairui Song, linux-mm, stable,
Sashiko
On 11/22/26 11:11 AM, Muchun Song wrote:
> __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 <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-21c1dba9-8d6f-4368-b38b-9a57cacb056f
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> ---
> mm/list_lru.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Acked-by: Qi Zheng <qi.zheng@linux.dev>
Thanks,
Qi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-22 7:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 3:11 [PATCH] mm/list_lru: fix potential infinite loop on xa node allocation failure Muchun Song
2026-11-22 7:08 ` Qi Zheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox