* [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
` (2 more replies)
0 siblings, 3 replies; 4+ 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] 4+ 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
2026-11-22 13:05 ` Jose A. Perez de Azpillaga
2026-11-22 23:00 ` + mm-list_lru-fix-potential-infinite-loop-on-xa-node-allocation-failure.patch added to mm-new branch Andrew Morton
2 siblings, 0 replies; 4+ 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] 4+ 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
@ 2026-11-22 13:05 ` Jose A. Perez de Azpillaga
2026-11-22 23:00 ` + mm-list_lru-fix-potential-infinite-loop-on-xa-node-allocation-failure.patch added to mm-new branch Andrew Morton
2 siblings, 0 replies; 4+ messages in thread
From: Jose A. Perez de Azpillaga @ 2026-11-22 13:05 UTC (permalink / raw)
To: Muchun Song, Andrew Morton, Dave Chinner
Cc: Qi Zheng, Roman Gushchin, Muchun Song, Kairui Song, linux-mm,
stable, Sashiko
On 11/22/26 4: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>
LGTM:
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
--
cheers,
jose a. p-a
^ permalink raw reply [flat|nested] 4+ messages in thread
* + mm-list_lru-fix-potential-infinite-loop-on-xa-node-allocation-failure.patch added to mm-new branch
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
2026-11-22 13:05 ` Jose A. Perez de Azpillaga
@ 2026-11-22 23:00 ` Andrew Morton
2 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-11-22 23:00 UTC (permalink / raw)
To: mm-commits, stable, shakeel.butt, roman.gushchin, qi.zheng,
kasong, david, azpijr, songmuchun, akpm
The patch titled
Subject: mm/list_lru: fix potential infinite loop on xa node allocation failure
has been added to the -mm mm-new branch. Its filename is
mm-list_lru-fix-potential-infinite-loop-on-xa-node-allocation-failure.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-list_lru-fix-potential-infinite-loop-on-xa-node-allocation-failure.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Muchun Song <songmuchun@bytedance.com>
Subject: mm/list_lru: fix potential infinite loop on xa node allocation failure
Date: Sun, 22 Nov 2026 11:11:43 +0800
__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.
Link: https://patch.msgid.link/20261122031143.3639941-1-songmuchun@bytedance.com
Fixes: 28e98022b31e ("mm/list_lru: simplify reparenting and initial allocation")
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-21c1dba9-8d6f-4368-b38b-9a57cacb056f
Acked-by: Qi Zheng <qi.zheng@linux.dev>
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Kairui Song <kasong@tencent.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: <stable@vger.kernel.org>
mm/list_lru.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/mm/list_lru.c~mm-list_lru-fix-potential-infinite-loop-on-xa-node-allocation-failure
+++ a/mm/list_lru.c
@@ -626,7 +626,7 @@ static int __memcg_list_lru_alloc(struct
}
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);
_
Patches currently in -mm which might be from songmuchun@bytedance.com are
powerpc-mm-make-vmemmap_populate_compound_pages-static.patch
powerpc-mm-drop-powerpc-vmemmap_can_optimize.patch
mm-sparse-vmemmap-drop-vmemmap_can_optimize.patch
mm-sparse-vmemmap-drop-pgmap-from-vmemmap-population-apis.patch
mm-hugetlb_vmemmap-fix-hwpoison-state-races-during-optimization.patch
mm-hugetlb_vmemmap-fix-pmd-split-tlb-flush-race.patch
mm-hugetlb_vmemmap-fix-deadlock-during-pmd-split.patch
mm-list_lru-fix-potential-infinite-loop-on-xa-node-allocation-failure.patch
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-22 23:00 UTC | newest]
Thread overview: 4+ 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
2026-11-22 13:05 ` Jose A. Perez de Azpillaga
2026-11-22 23:00 ` + mm-list_lru-fix-potential-infinite-loop-on-xa-node-allocation-failure.patch added to mm-new branch Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox