From: "David Hildenbrand (Red Hat)" <david@kernel.org>
To: Lance Yang <lance.yang@linux.dev>,
zenghongling <zenghongling@kylinos.cn>,
Qi Zheng <qi.zheng@linux.dev>,
Muchun Song <muchun.song@linux.dev>
Cc: linux-mm@kvack.org, dev.jain@arm.com, akpm@linux-foundation.org,
ryan.roberts@arm.com, baolin.wang@linux.alibaba.com,
npache@redhat.com, linux-kernel@vger.kernel.org,
baohua@kernel.org, Liam.Howlett@oracle.com,
zhongling0719@126.com, ziy@nvidia.com,
lorenzo.stoakes@oracle.com
Subject: Re: [PATCH] mm/huge_memory: Fix iterator variable usage after swap()
Date: Wed, 21 Jan 2026 13:28:46 +0100 [thread overview]
Message-ID: <f9bfaa03-bc02-4379-b542-457015053e5e@kernel.org> (raw)
In-Reply-To: <ada6d430-fe18-4db7-aa1b-96a03f7af37b@linux.dev>
On 1/21/26 10:25, Lance Yang wrote:
>
>
> On 2026/1/21 16:13, zenghongling wrote:
>> The iterator variable 'folio' is swapped with 'prev' in the else
>> branch. Using 'folio' after swap() checks the potentially NULL
>> 'prev' value, not the original iterator value.
>>
>> Fix by moving folio_put() call before the swap operation in the
>> path where swap() occurs.
>>
>> Found by:
>> ./huge_memory.c:4225:6-11: ERROR: iterator variable bound on line 4178 cannot be NULL
>
Which tool did find that? A compiler?
> Good catch!
>
> But which tree is your patch based on?
>
> Seems like that was already fixed in commit 776bde7caf80[1]. The
> whole thing deferred_split_scan() was refactored using folio_batch,
> so the buggy code with swap(folio, prev) is gone ...
>
> Ccing Muchun and Qi who fixed that.
>
> [1]
> https://lore.kernel.org/all/59cb6b6fb5ffcff9d23b81890b252960139ad8e7.1762762324.git.zhengqi.arch@bytedance.com/
Right, in
commit 776bde7caf80f6af72b087cafe7d9f607b14716d
Author: Muchun Song <muchun.song@linux.dev>
Date: Mon Nov 10 16:17:57 2025 +0800
mm: thp: use folio_batch to handle THP splitting in deferred_split_scan()
Which raises the question whether we would want to backport that patch to stable kernels
if there was indeed a problem?
But: I don't immediately see the problem.
If pref is NULL (and folio obviously !+NULL), we'll end up with
* pref != NULL
* folio == NULL
The "if (folio)" check will do nothing, because we defer the freeing to the
if (prev)
folio_put(prev);
later
If pref is != NULL (and folio obviously !+NULL), we'll end up with
* pref = NULL
* folio = NULL
The if (folio) and if (prev) handling will care of it all.
So ... this pretty much looks like working as expected?
--
Cheers
David
next prev parent reply other threads:[~2026-01-21 12:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 8:13 zenghongling
2026-01-21 9:25 ` Lance Yang
2026-01-21 12:28 ` David Hildenbrand (Red Hat) [this message]
2026-01-22 2:16 ` Lance Yang
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=f9bfaa03-bc02-4379-b542-457015053e5e@kernel.org \
--to=david@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=muchun.song@linux.dev \
--cc=npache@redhat.com \
--cc=qi.zheng@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=zenghongling@kylinos.cn \
--cc=zhongling0719@126.com \
--cc=ziy@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox