Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Kiryl Shutsemau <kirill@shutemov.name>
To: Hao Zhang <hao_zhang_kdev@163.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	 David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	linux-mm@kvack.org
Subject: Re: [PATCH] mm: thp: unlock i_mmap before releasing split folios
Date: Fri, 10 Jul 2026 12:16:32 +0100	[thread overview]
Message-ID: <alDSekC_5t-29vJS@thinkstation> (raw)
In-Reply-To: <20260710071344.GA106129@zh-pc>

On Fri, Jul 10, 2026 at 03:13:44PM +0800, Hao Zhang wrote:
> From: Hao Zhang <zhanghao1@kylinos.cn>
> Date: Thu, 9 Jul 2026 16:30:00 +0800
> 
> __folio_split() takes mapping->i_mmap_rwsem while unmapping and
> splitting a file-backed large folio. The lock is currently released
> only after the split folios that are not returned locked to the caller
> have been unlocked and put.
> 
> That leaves a lifetime hole. Once the split folios are unlocked and
> their references are dropped, inode eviction can make progress through
> the final page-cache truncation path. After the folios are removed from
> the page cache and the last inode reference is dropped, the inode that
> embeds the address_space can be freed after an RCU grace period. A later
> i_mmap_unlock_read(mapping) then dereferences mapping->i_mmap_rwsem
> from freed memory.
> 
> A possible race is:
> 
>   CPU0                                    CPU1
>   __folio_split()
>     i_mmap_lock_read(mapping)
>     ...
>     remap_page()
>     folio_unlock(new_folio)
>     free_folio_and_swap_cache(new_folio)
>                                           evict inode
>                                           truncate_inode_pages_final()
>                                           destroy_inode()
>                                           call_rcu()
>                                           RCU callback frees inode
>     i_mmap_unlock_read(mapping)
> 
> Release mapping->i_mmap_rwsem after the page-cache and reverse-mapping
> work has completed, but before unlocking and putting any of the split
> folios. Clear the local mapping pointer after the early unlock so the
> common exit path does not unlock it a second time.

I don't buy this analysis. We still have the lock_at page which is locked
and still in the page cache. Inode eviction cannot complete past
truncate_inode_pages_final() until it is unlocked, which only happens
after __folio_split() has released i_mmap_rwsem.

One possible path how this can be hit is if lock_at ends up in an
after-split folio beyond EOF and __folio_freeze_and_split_unmapped()
removes it from the page cache. Note the drop loop starts at
folio_next(folio), so this requires splitting at a tail page (e.g.
memory-failure) racing with truncate.

But that's not what your analysis claims. Please share the actual crash
reports. Let's get to the bottom of the situation before changing the
code.

-- 
  Kiryl Shutsemau / Kirill A. Shutemov


  reply	other threads:[~2026-07-10 11:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10  7:13 [PATCH] mm: thp: unlock i_mmap before releasing split folios Hao Zhang
2026-07-10 11:16 ` Kiryl Shutsemau [this message]
2026-07-10 15:56   ` Hao Zhang
2026-07-10 17:04     ` Lorenzo Stoakes
2026-07-10 17:17     ` Kiryl Shutsemau

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=alDSekC_5t-29vJS@thinkstation \
    --to=kirill@shutemov.name \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=hao_zhang_kdev@163.com \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    /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