From: Kairui Song <ryncsn@gmail.com>
To: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com,
nphamcs@gmail.com, baoquan.he@linux.dev, youngjun.park@lge.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/4] mm, swap: Fix potential NULL dereference when trying a sleep table allocation
Date: Thu, 27 Aug 2026 17:10:54 +0800 [thread overview]
Message-ID: <ao_ybL9yRO_pHphW@KASONG-MC4> (raw)
In-Reply-To: <20260820115505.20027-2-shikemeng@huaweicloud.com>
On Thu, Aug 20, 2026 at 07:55:02PM +0800, Kemeng Shi wrote:
> The root cause of this issue is because multi-tables are updated in non
> atomic context. To be more specific, the issue could be triggerred as
> following:
>
> swap_alloc_fast swap_cluster_populate()
> /* Try a sleep allocation */
> spin_unlock(&ci->lock);
> swap_cluster_alloc_table()
> rcu_assign_pointer(ci->table, table);
>
> ci = swap_cluster_lock(si, offset)
> cluster_is_usable(ci, order)
> if (!cluster_table_is_alloced(ci)) // ok
> alloc_swap_scan_cluster()
> cluster_scan_range()
> __swap_table_get()
>
> /* free table when more table allocation fails */
> ci->memcg_table = kzalloc_obj(*ci->memcg_table,
> gfp);
> if (!ci->memcg_table)
> swap_cluster_free_table()
> rcu_assign_pointer(ci->table, NULL);
>
> table = rcu_dereference_check(ci->table, lockdep_is_held(&ci->lock));
> atomic_long_read(&table[off]); // NULL dereference
>
> Fix the issue by making tables visible at end of swap_cluster_populate().
I think you mean "end of swap_cluster_alloc_table".
>
> Fixes: 2fe7a6f5024b8 ("mm/memcg, swap: store cgroup id in cluster table directly")
Hmm, wrong commit id again, should be
Fixes: b197d41462c2 ("mm/memcg, swap: store cgroup id in cluster table directly")
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
> mm/swapfile.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 615d90867111..4561c864f806 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -466,8 +466,6 @@ static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp)
> if (!table)
> return -ENOMEM;
>
> - rcu_assign_pointer(ci->table, table);
> -
> #ifdef CONFIG_MEMCG
> if (!mem_cgroup_disabled()) {
> VM_WARN_ON_ONCE(ci->memcg_table);
> @@ -487,6 +485,12 @@ static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp)
> return -ENOMEM;
> }
> #endif
> +
> + /*
> + * Make tables visible to cluster_is_usable() after everything is
> + * ready.
> + */
> + rcu_assign_pointer(ci->table, table);
Hmm, but for the error paths above, they will leak the new allocated table?
next prev parent reply other threads:[~2026-08-27 9:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 11:55 [PATCH v2 0/4] mm, swap: some random fixes and cleanups Kemeng Shi
2026-08-20 11:55 ` [PATCH v2 1/4] mm, swap: Fix potential NULL dereference when trying a sleep table allocation Kemeng Shi
2026-08-27 9:10 ` Kairui Song [this message]
2026-08-29 1:03 ` Andrew Morton
2026-09-05 4:03 ` Kemeng Shi
2026-08-20 11:55 ` [PATCH v2 2/4] mm, swap: Move setup_swap_clusters_info() after SWP_SOLIDSTATE initialization Kemeng Shi
2026-08-27 9:43 ` Kairui Song
2026-08-20 11:55 ` [PATCH v2 3/4] mm, swap: return early from swap_extend_table_try_free() on first non-zero entry Kemeng Shi
2026-08-27 13:54 ` Kairui Song
2026-08-20 11:55 ` [PATCH v2 4/4] mm, swap: Remove unneeded swap_extend_table_try_free() in swap_dup_entries_cluster() Kemeng Shi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ao_ybL9yRO_pHphW@KASONG-MC4 \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baoquan.he@linux.dev \
--cc=chrisl@kernel.org \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=shikemeng@huaweicloud.com \
--cc=youngjun.park@lge.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.