From: Zi Yan <ziy@nvidia.com>
To: Balbir Singh <balbirs@nvidia.com>
Cc: David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Miaohe Lin <linmiaohe@huawei.com>,
Naoya Horiguchi <nao.horiguchi@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/3] mm/huge_memory: prevent NULL pointer dereference in try_folio_split_to_order()
Date: Thu, 20 Nov 2025 09:45:16 -0500 [thread overview]
Message-ID: <D87B70D1-9A8C-48C4-8817-99F58F64F070@nvidia.com> (raw)
In-Reply-To: <010f0f19-8b87-4537-8c0b-bc8f9263aab4@nvidia.com>
On 19 Nov 2025, at 23:28, Balbir Singh wrote:
> On 11/20/25 14:59, Zi Yan wrote:
>> folio_split_supported() used in try_folio_split_to_order() requires
>> folio->mapping to be non NULL, but current try_folio_split_to_order() does
>> not check it. Add the check to prevent NULL pointer dereference.
>>
>> There is no issue in the current code, since try_folio_split_to_order() is
>> only used in truncate_inode_partial_folio(), where folio->mapping is not
>> NULL.
>>
>
> Just reading through the description does not clarify one thing
>
> What is the race between just truncated and trying to split them - is there a common lock
> that needs to be held? Is it the subsequent call in truncate_inode_partial_folio()
> that causes the race?
>
> IOW, if a folio is not anonymous and does not have a mapping, how is it
> being passed to this function?
Quote David’s explanation[1] (note: shmem is not anonymous):
vmscan triggers shmem_writeout() after unmapping the folio and after making
sure that there are no unexpected folio references.
shmem_writeout() will do the shmem_delete_from_page_cache() where we set
folio->mapping = NULL.
So anything walking the page tables (like s390x) could never find it.
Such shmem folios really cannot get split right now until we either
reclaimed them (-> freed) or until shmem_swapin_folio() re-obtained them
from the swapcache to re-add them to the swapcache through
shmem_add_to_page_cache().
[1] https://lore.kernel.org/all/14253d62-0a85-4f61-aed6-72da17bcef77@kernel.org/
>
>> Signed-off-by: Zi Yan <ziy@nvidia.com>
>> ---
>> include/linux/huge_mm.h | 7 +++++++
>> 1 file changed, 7 insertions(+)
>>
>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
>> index 1d439de1ca2c..0d55354e3a34 100644
>> --- a/include/linux/huge_mm.h
>> +++ b/include/linux/huge_mm.h
>> @@ -407,6 +407,13 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_o
>> static inline int try_folio_split_to_order(struct folio *folio,
>> struct page *page, unsigned int new_order)
>> {
>> + /*
>> + * Folios that just got truncated cannot get split. Signal to the
>> + * caller that there was a race.
>> + */
>> + if (!folio_test_anon(folio) && !folio->mapping)
>> + return -EBUSY;
>> +
>> if (!folio_split_supported(folio, new_order, SPLIT_TYPE_NON_UNIFORM, /* warns= */ false))
>> return split_huge_page_to_order(&folio->page, new_order);
>> return folio_split(folio, new_order, page, NULL);
Best Regards,
Yan, Zi
next prev parent reply other threads:[~2025-11-20 14:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 3:59 [RFC PATCH 0/3] folio->mapping == NULL check issue Zi Yan
2025-11-20 3:59 ` [RFC PATCH 1/3] mm/huge_memory: prevent NULL pointer dereference in try_folio_split_to_order() Zi Yan
2025-11-20 4:28 ` Balbir Singh
2025-11-20 14:45 ` Zi Yan [this message]
2025-11-20 9:25 ` David Hildenbrand (Red Hat)
2025-11-20 14:41 ` Zi Yan
2025-11-20 19:56 ` David Hildenbrand (Red Hat)
2025-11-21 16:41 ` Zi Yan
2025-11-21 17:09 ` David Hildenbrand (Red Hat)
2025-11-21 17:24 ` Zi Yan
2025-11-20 3:59 ` [RFC PATCH 2/3] mm/huge_memory: add kernel-doc for folio_split_supported() Zi Yan
2025-11-20 4:37 ` Balbir Singh
2025-11-20 9:27 ` David Hildenbrand (Red Hat)
2025-11-20 14:48 ` Zi Yan
2025-11-20 20:01 ` David Hildenbrand (Red Hat)
2025-11-20 3:59 ` [RFC PATCH 3/3] mm/memory-failure: handle min_order_for_split() error code properly Zi Yan
2025-11-20 4:45 ` Balbir Singh
2025-11-20 15:00 ` Zi Yan
2025-11-20 9:37 ` David Hildenbrand (Red Hat)
2025-11-20 14:59 ` Zi Yan
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=D87B70D1-9A8C-48C4-8817-99F58F64F070@nvidia.com \
--to=ziy@nvidia.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=balbirs@nvidia.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=nao.horiguchi@gmail.com \
--cc=npache@redhat.com \
--cc=ryan.roberts@arm.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