Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/zswap: publish the initial pool with list_add_rcu()" failed to apply to 6.12-stable tree

PATCH New Sasha Levin 1 participant 2 messages Nov 7 – Nov 11

Subsystems (3)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

The patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x c1dd5e24a82d19bff8eef50ba8205d4776584aff
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'

Thanks,
Sasha

------------------ original commit in Linus's tree ------------------

From c1dd5e24a82d19bff8eef50ba8205d4776584aff Mon Sep 17 00:00:00 2001
From: Longlong Xia <[email protected]>
Date: Tue, 8 Sep 2026 09:28:01 +0800
Subject: [PATCH] mm/zswap: publish the initial pool with list_add_rcu()

zswap_setup() publishes the pool on the zswap_pools list with a plain list_add(), but the list is walked by concurrent RCU readers holding nothing but rcu_read_lock() through zswap_total_pages(), e.g. /proc/meminfo and the shrinker count path.

    CPU 0 (writer)                          CPU 1 (reader)
    --------------                          --------------
    zswap_pool_create():
      pool->zs_pool = zs_create_pool(); (1)
    list_add() -> __list_add():
      WRITE_ONCE(zswap_pools.next,
          &pool->list);                (2)   zswap_total_pages():
                                                pool = READ_ONCE(     (a)
                                                    zswap_pools.next);
                                                zs_get_total_pages(   (b)
                                                    pool->zs_pool);

If (2) becomes visible to CPU 1 before (1), CPU 1 finds the pool at (a) but dereferences a wild pointer at (b). Publish the node with list_add_rcu().

---
 mm/zswap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/zswap.c +1 -1
index b5411ab164809..2a95aedc08fcc 100644
@@ -1815,7 +1815,7 @@ static int zswap_setup(void)
 	pool = __zswap_pool_create_fallback();
 	if (pool) {
 		pr_info("loaded using pool %s\n", pool->tfm_name);
-		list_add(&pool->list, &zswap_pools);
+		list_add_rcu(&pool->list, &zswap_pools);
 		zswap_has_pool = true;
 		static_branch_enable(&zswap_ever_enabled);
 	} else {
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 1/1 mm/zswap: publish the initial pool with list_add_rcu()

From: Longlong Xia <[email protected]>

[ Upstream commit c1dd5e24a82d19bff8eef50ba8205d4776584aff ]

zswap_setup() publishes the pool on the zswap_pools list with a plain list_add(), but the list is walked by concurrent RCU readers holding nothing but rcu_read_lock() through zswap_total_pages(), e.g. /proc/meminfo and the shrinker count path.

    CPU 0 (writer)                          CPU 1 (reader)
    --------------                          --------------
    zswap_pool_create():
      pool->zs_pool = zs_create_pool(); (1)
    list_add() -> __list_add():
      WRITE_ONCE(zswap_pools.next,
          &pool->list);                (2)   zswap_total_pages():
                                                pool = READ_ONCE(     (a)
                                                    zswap_pools.next);
                                                zs_get_total_pages(   (b)
                                                    pool->zs_pool);

If (2) becomes visible to CPU 1 before (1), CPU 1 finds the pool at (a) but dereferences a wild pointer at (b). Publish the node with list_add_rcu().

Fixes 91cdcd8d624b ("mm: zswap: optimize zswap pool size tracking")
Assisted-by Zcode:GLM-5.3
Cc Chengming Zhou <[email protected]>
Cc Johannes Weiner <[email protected]>
[ sashal: Adjusted context to preserve existing logging of both the compressor and the zpool backend. ]
---
 mm/zswap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/zswap.c +1 -1
index 6c50249d5398f..61311c92bd6f6 100644
@@ -1778,7 +1778,7 @@ static int zswap_setup(void)
 	if (pool) {
 		pr_info("loaded using pool %s/%s\n", pool->tfm_name,
 			zpool_get_type(pool->zpool));
-		list_add(&pool->list, &zswap_pools);
+		list_add_rcu(&pool->list, &zswap_pools);
 		zswap_has_pool = true;
 	} else {
 		pr_err("pool creation failed\n");
Signature · 1 line
2.53.0