From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>, dayou5941@163.com
Cc: linmiaohe@huawei.com, ljs@kernel.org, nao.horiguchi@gmail.com,
linux-mm@kvack.org, ziy@nvidia.com,
Li Youhong <liyouhong@kylinos.cn>,
Sashiko <sashiko-bot@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH v4] mm/memory-failure: fix folio refcount leak and locking in soft/hard offline
Date: Thu, 6 Aug 2026 12:50:23 +0200 [thread overview]
Message-ID: <0726ba54-a500-46a4-b42f-3e581da0f070@kernel.org> (raw)
In-Reply-To: <20260805213415.002dc67766271d21c232910b@linux-foundation.org>
On 8/6/26 06:34, Andrew Morton wrote:
> On Thu, 6 Aug 2026 11:19:58 +0800 dayou5941@163.com wrote:
>
>> From: Li Youhong <liyouhong@kylinos.cn>
>>
>> The min_order_for_split() function accesses folio->mapping without proper
>> synchronization. In memory_failure(), the folio lock is dropped before the
>> call, and in soft_offline_in_use_page(), the lock is not held at all. This
>> means that while min_order_for_split() is executing, the value of
>> folio->mapping may be modified by a truncate or invalidate operation,
>> leading to a torn read or use of a stale mapping value.
>>
>> Additionally, the soft_offline_in_use_page() path fails to release the
>> folio reference taken by get_hwpoison_page() when new_order != 0, causing a
>> reference leak.
>>
>> Fix these issues by:
>> - Moving the split operation logic into the callers and holding the folio
>> lock around min_order_for_split() and split_huge_page_to_order().
>> - Removing the try_to_split_thp_page() helper to simplify refcount
>> handling.
>> - Ensuring the folio reference is always dropped before returning on the
>> soft-offline error path.
>>
>> This refactors the code to be more maintainable, fixes the locking issue
>> reported by Sashiko, and also addresses the folio reference leak on the
>> soft-offline error path.
>>
>> ...
>>
>> --- a/mm/memory-failure.c
>> +++ b/mm/memory-failure.c
>> static void unmap_and_kill(struct list_head *to_kill, unsigned long pfn,
>> struct address_space *mapping, pgoff_t index, int flags)
>> {
>> @@ -2440,7 +2420,6 @@ int memory_failure(unsigned long pfn, int flags)
>> folio_unlock(folio);
>>
>> if (folio_test_large(folio)) {
>> - const int new_order = min_order_for_split(folio);
>> int err;
>>
>> /*
>> @@ -2457,24 +2436,24 @@ int memory_failure(unsigned long pfn, int flags)
>> * page is a valid handlable page.
>> */
>> folio_set_has_hwpoisoned(folio);
>> - err = try_to_split_thp_page(p, new_order, /* release= */ false);
>
> AI review asks (effectively) why the try_to_split_thp_page() return value
> never gets used
>
> https://sashiko.dev/#/patchset/20260806031958.677935-1-dayou5941@163.com
>
No need for AI. Just from compiling:
└ mm/memory-failure.c: In function ‘memory_failure’:
mm/memory-failure.c:2492:21: warning: variable ‘err’ set but not used
[-Wunused-but-set-variable]
2492 | int err;
I'll send out a patch myself that already addresses everything raised in here
without even me reading any of it.
--
Cheers,
David
prev parent reply other threads:[~2026-08-06 10:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 3:19 [PATCH v4] mm/memory-failure: fix folio refcount leak and locking in soft/hard offline dayou5941
2026-08-06 4:34 ` Andrew Morton
2026-08-06 10:50 ` David Hildenbrand (Arm) [this message]
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=0726ba54-a500-46a4-b42f-3e581da0f070@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dayou5941@163.com \
--cc=linmiaohe@huawei.com \
--cc=linux-mm@kvack.org \
--cc=liyouhong@kylinos.cn \
--cc=ljs@kernel.org \
--cc=nao.horiguchi@gmail.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
--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