From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: dayou5941@163.com
Cc: akpm@linux-foundation.org, david@kernel.org, ziy@nvidia.com,
linux-mm@kvack.org, Li Youhong <liyouhong@kylinos.cn>,
Sashiko <sashiko-bot@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH v3] mm/memory-failure: fix concurrent access issue in min_order_for_split()
Date: Wed, 5 Aug 2026 10:32:45 +0100 [thread overview]
Message-ID: <anMDGv1p05wKlMyq@lucifer> (raw)
In-Reply-To: <20260805084224.2597547-1-dayou5941@163.com>
Please stop sending series so quickly :)
Leave at least a day between new revisions.
There's review on the v2 that is outstanding.
So engage in discussions there and wait until tomorrow before sending v4.
Thanks!
On Wed, Aug 05, 2026 at 04:42:24PM +0800, dayou5941@163.com wrote:
> From: Li Youhong <liyouhong@kylinos.cn>
>
> min_order_for_split() accesses folio->mapping without proper
> synchronization. While the compiler typically caches the value
> in a register making a NULL deref unlikely in practice, the
> real issue is that the callers in memory-failure.c do not hold
> the folio lock at the time of the call:
>
> - memory_failure() explicitly drops the folio lock before calling
> min_order_for_split().
> - soft_offline_in_use_page() has not yet acquired the folio lock
> when calling min_order_for_split().
>
> This means the value of folio->mapping may be modified by a
> truncate or invalidate operation while min_order_for_split() is
> executing, leading to a torn read or use of a stale mapping value.
>
> Fixes: 689b8986776c ("mm/memory-failure: improve large block size folio handling")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20260803060001.800638-1-dayou5941@163.com
> Cc: stable@vger.kernel.org
> Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
> ---
> v2:
> - Dropped the approach of caching folio->mapping inside min_order_for_split() in favor of adding the folio lock at the callers.
> - Added VM_WARN_ON_ONCE_FOLIO() in min_order_for_split().
> - Updated the commit message to clarify that the real issue is the callers not holding the folio lock, rather than a TOCTOU race.
> v1: https://lore.kernel.org/all/20260804035828.2684059-1-dayou5941@163.com/
>
> v3:
> - Fix author name and Signed-off-by format as requested by Greg.
> v2: https://lore.kernel.org/all/20260805072625.2437636-1-dayou5941@163.com/
> ---
> mm/huge_memory.c | 2 ++
> mm/memory-failure.c | 12 ++++++++++--
> 2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 58cabe6af33d..e3f16dadc1d4 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -4300,6 +4300,8 @@ int folio_split(struct folio *folio, unsigned int new_order,
> */
> unsigned int min_order_for_split(struct folio *folio)
> {
> + VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio);
> +
> if (folio_test_anon(folio))
> return 0;
>
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index 3b1e6946821b..7391524b5046 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -2437,12 +2437,17 @@ int memory_failure(unsigned long pfn, int flags)
> res = -EOPNOTSUPP;
> goto unlock_mutex;
> }
> +
> folio_unlock(folio);
>
> if (folio_test_large(folio)) {
> - const int new_order = min_order_for_split(folio);
> + const int new_order;
> int err;
>
> + folio_lock(folio);
> + new_order = min_order_for_split(folio);
> + folio_unlock(folio);
> +
> /*
> * The flag must be set after the refcount is bumped
> * otherwise it may race with THP split.
> @@ -2796,8 +2801,11 @@ static int soft_offline_in_use_page(struct page *page)
> };
>
> if (!huge && folio_test_large(folio)) {
> - const int new_order = min_order_for_split(folio);
> + const int new_order;
>
> + folio_lock(folio);
> + new_order = min_order_for_split(folio);
> + folio_unlock(folio);
> /*
> * If new_order (target split order) is not 0, do not split the
> * folio at all to retain the still accessible large folio.
> --
> 2.25.1
>
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-08-05 9:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 8:42 [PATCH v3] mm/memory-failure: fix concurrent access issue in min_order_for_split() dayou5941
2026-08-05 9:32 ` Lorenzo Stoakes (ARM) [this message]
2026-08-19 19:14 ` kernel test robot
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=anMDGv1p05wKlMyq@lucifer \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=dayou5941@163.com \
--cc=linux-mm@kvack.org \
--cc=liyouhong@kylinos.cn \
--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