From: Zi Yan <ziy@nvidia.com>
To: David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Zi Yan <ziy@nvidia.com>,
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: [RFC PATCH 0/3] folio->mapping == NULL check issue
Date: Wed, 19 Nov 2025 22:59:50 -0500 [thread overview]
Message-ID: <20251120035953.1115736-1-ziy@nvidia.com> (raw)
Hi all,
Based on Wei's observation[1], this patchset is trying to solve several
potential issues:
1. Patch 1, 2: dereferencing NULL folio->mapping in
try_folio_split_to_order() for future users,
2. Patch 3: improper handling of negative return value of
min_order_for_split() in mm/memory-failure.c
No bug is present for the existing code.
For 1, try_folio_split_to_order() is used in
truncate_inode_partial_folio() and it is fine since folio->mapping is
always not NULL there.
For 2, mm/memory-failure.c code does not check for -EBUSY return value of
min_order_for_split() and directly passes it to a folio split function.
The code works by accident but needs to be fixed.
folio_split_supported() does not check if folio->mapping is NULL, but
can dereference it in some cases. My current fix is adding a kernel-doc
to clarify this requirement. An alternative is to add folio->mapping
check and return -EBUSY and return -EINVAL for the other checks. But
folio_split_supported() will no longer checks for "supported",
folio_split_can_split() might be a better name. Then, the existing
can_split_folio() might better be renamed to
folio_split_refcount_check(). In addition, try_folio_split_to_order(),
which calls folio_split_supported(), might want to handle -EBUSY separately
to avoid calling split_huge_page_to_order() when the folio is truncated
for a known -EBUSY error.
Let me know your thoughts. Thanks.
Link: https://lore.kernel.org/all/20251120004735.52z7r4xmogw7mbsj@master/ [1]
Zi Yan (3):
mm/huge_memory: prevent NULL pointer dereference in
try_folio_split_to_order()
mm/huge_memory: add kernel-doc for folio_split_supported()
mm/memory-failure: handle min_order_for_split() error code properly
include/linux/huge_mm.h | 7 +++++++
mm/huge_memory.c | 17 +++++++++++++++++
mm/memory-failure.c | 8 ++++++--
3 files changed, 30 insertions(+), 2 deletions(-)
--
2.51.0
next reply other threads:[~2025-11-20 4:00 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 3:59 Zi Yan [this message]
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
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=20251120035953.1115736-1-ziy@nvidia.com \
--to=ziy@nvidia.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--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