All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pedro Falcato" <pfalcato@suse.de>,
	"David Hildenbrand" <david@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Zi Yan" <ziy@nvidia.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	"Jan Kara" <jack@suse.cz>, "Lorenzo Stoakes" <ljs@kernel.org>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>
Cc: linux-ext4@vger.kernel.org,
	"Liam R. Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Nico Pache" <nico.pache@linux.dev>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Dev Jain" <dev.jain@arm.com>, "Barry Song" <baohua@kernel.org>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Kiryl Shutsemau" <kas@kernel.org>,
	linux-mm@kvack.org, "Kairui Song" <kasong@tencent.com>,
	"Qi Zheng" <qi.zheng@linux.dev>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"Axel Rasmussen" <axelrasmussen@google.com>,
	"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
	"Baoquan He" <baoquan.he@linux.dev>,
	"Michal Hocko" <mhocko@kernel.org>,
	tytso@mit.edu, "Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Anna Schumaker" <anna@kernel.org>
Subject: Re: [PATCH RFC 5/5] mm/filemap: refuse releasing maybe_dma_pinned folios
Date: Fri, 20 Nov 2026 20:11:46 +0000	[thread overview]
Message-ID: <sashiko-outbox-226011@kernel.org> (raw)
In-Reply-To: <20261119-gup-dirty-what-v1-5-236d69f25c24@suse.de>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mm/filemap: filemap_release_folio() dma-pin check breaks
  folio_invalidate()
- [Medium] mm/filemap: VM_WARN_ON_FOLIO on mapped folio hit via
  mext_move_extent()
- [Medium] mm/filemap: VM_WARN_ON_FOLIO in filemap_release_folio()
  precedes needs_release
--

commit 38a290b76cc80ed81b7d5a26e8b50ef48dfba24c
Author: Pedro Falcato <pfalcato@suse.de>

mm/filemap: refuse releasing maybe_dma_pinned folios

This commit updates filemap_release_folio() to warn if the folio is mapped
and refuse to release filesystem metadata when folio_maybe_dma_pinned() is
true.

> diff --git a/mm/filemap.c b/mm/filemap.c
> index f9e34144c53c7..4fa75663b7f3e 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -4571,8 +4571,11 @@ bool filemap_release_folio(struct folio *folio, gfp_t gfp)
>  	struct address_space * const mapping = folio->mapping;
>  
>  	BUG_ON(!folio_test_locked(folio));
> +	VM_WARN_ON_FOLIO(folio_mapped(folio), folio);

[Severity: Medium]
Can EXT4_IOC_MOVE_EXT hit this VM_WARN_ON_FOLIO() on a memory-mapped file?

In fs/ext4/move_extent.c, mext_move_extent() locks the origin and donor
folios and calls filemap_release_folio() on them without unmapping them
from user page tables or checking folio_mapped() first:

fs/ext4/move_extent.c:mext_move_extent() {
	...
	if (!filemap_release_folio(folio[0], 0) ||
	    !filemap_release_folio(folio[1], 0)) {
		ret = -EBUSY;
		goto unlock;
	}
	...
}

If either file is memory-mapped with resident PTEs in the moved range, an
unprivileged EXT4_IOC_MOVE_EXT ioctl triggers this warning when
CONFIG_DEBUG_VM is enabled.

>  	if (!folio_needs_release(folio))
>  		return true;

[Severity: Medium]
Should VM_WARN_ON_FOLIO(folio_mapped(folio), folio) come after the
!folio_needs_release(folio) check to match filemap_may_release_folio()?

filemap_may_release_folio() returns true when !folio_needs_release(folio)
before checking folio_mapped(folio):

mm/internal.h:filemap_may_release_folio() {
	VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio);
	if (!folio_needs_release(folio))
		return true;

	/* There's no way to know whether these are write-mapped, so give up. */
	if (folio_mapped(folio))
		return false;
	...
}

Callers such as collapse_file() (which calls try_to_unmap() without
TTU_SYNC) and __folio_freeze_split_file() (which calls unmap_folio())
can leave a folio mapped if unmapping races with zap_pte_range(), then
rely on filemap_may_release_folio() to gate filemap_release_folio().
For a folio that does not need release, filemap_may_release_folio()
returns true and filemap_release_folio() then triggers
VM_WARN_ON_FOLIO(folio_mapped(folio), folio).

> +	if (folio_maybe_dma_pinned(folio))
> +		return false;
>  	if (folio_test_writeback(folio))
>  		return false;

[Severity: High]
Does refusing to release a DMA-pinned folio here break truncation via
folio_invalidate() and leak the folio and its buffer_heads?

During full-folio truncation, truncate_cleanup_folio() calls
folio_invalidate() before removing the folio from the page cache.
block_invalidate_folio() and gfs2_invalidate_folio() first discard all
buffers on the folio and then call filemap_release_folio(folio, 0) to
free the buffer_heads and clear PG_private.

If filemap_release_folio() returns false because the folio is DMA-pinned,
truncation still removes the folio from the page cache and sets
folio->mapping = NULL, leaving PG_private and the discarded buffer_heads
attached.  When the DMA pin holder later unpins the folio as dirty (for
example via unpin_user_pages_dirty_lock()), folio_mark_dirty() sees
folio_mapping(folio) == NULL and calls noop_dirty_folio(), setting
PG_dirty on the orphaned folio while PG_private holds a reference.  When
shrink_folio_list() later scans this folio on the file LRU, it sees
folio_test_dirty(folio) and jumps to activate_locked before reaching the
orphaned buffer release path, and because folio->mapping is NULL nothing
can ever write it back or clear PG_dirty, permanently leaking the folio
and its buffer_heads on the file LRU.

On GFS2, gfs2_invalidate_folio() -> gfs2_discard() also leaves struct
gfs2_bufdata attached at bh->b_private to be freed by gfs2_release_folio();
once truncation clears folio->mapping, any later filemap_release_folio()
call sees mapping == NULL and falls back to try_to_free_buffers() instead
of mapping->a_ops->release_folio, permanently leaking struct gfs2_bufdata
even if the folio was not dirtied.  In ext4's mpage_release_unused_pages(),
a failed delayed allocation calls block_invalidate_folio() and then
folio_clear_uptodate(folio), relying on filemap_release_folio() ->
try_to_free_buffers() -> folio_cancel_dirty() to clear PG_dirty, so
returning false leaves a pinned folio in the page cache with PG_dirty set
and PG_uptodate clear.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-gup-dirty-what-v1-0-236d69f25c24@suse.de?part=5

  reply	other threads:[~2026-11-20 20:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 20:10 [PATCH RFC 0/5] mm: GUP dirty + ->release_folio() fixes Pedro Falcato
2026-11-19 20:10 ` [PATCH RFC 1/5] mm/khugepaged: fix filemap_release_folio() interaction with GUP dirty Pedro Falcato
2026-11-19 20:10 ` [PATCH RFC 2/5] mm/huge_memory: " Pedro Falcato
2026-11-20 20:11   ` sashiko-bot
2026-11-19 20:10 ` [PATCH RFC 3/5] mm/vmscan: avoid releasing FS metadata for !FOLL_PIN gup folios Pedro Falcato
2026-11-19 20:10 ` [PATCH RFC 4/5] mm/vmscan: be more careful when releasing FS metadata if buffer_heads_over_limit Pedro Falcato
2026-11-19 20:10 ` [PATCH RFC 5/5] mm/filemap: refuse releasing maybe_dma_pinned folios Pedro Falcato
2026-11-20 20:11   ` sashiko-bot [this message]
2026-11-20  0:55 ` [PATCH RFC 0/5] mm: GUP dirty + ->release_folio() fixes John Hubbard
2026-11-20 11:57 ` Jan Kara
2026-11-20 17:39 ` Christoph Hellwig
2026-11-20 20:11 ` sashiko-bot

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=sashiko-outbox-226011@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=anna@kernel.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=baoquan.he@linux.dev \
    --cc=cel@kernel.org \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=jack@suse.cz \
    --cc=jhubbard@nvidia.com \
    --cc=jlayton@kernel.org \
    --cc=kas@kernel.org \
    --cc=kasong@tencent.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=mhocko@suse.com \
    --cc=nico.pache@linux.dev \
    --cc=peterx@redhat.com \
    --cc=pfalcato@suse.de \
    --cc=qi.zheng@linux.dev \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=tytso@mit.edu \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --cc=willy@infradead.org \
    --cc=yuanchu@google.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.