Re: [PATCH RFC 5/5] mm/filemap: refuse releasing maybe_dma_pinned folios
From: Jan Kara
Date: Wed Nov 25 2026 - 03:48:00 EST
On Thu 19-11-26 20:10:48, Pedro Falcato wrote:
> Some callers, like folio_unmap_invalidate(), call filemap_release_folio()
> without any care for folio refcounts. This is on purpose. As
> folio_unmap_invalidate() states, invalidate_inode_pages2() needs stronger
> guarantees, and "can't afford to leave folios behind because
> shrink_folio_list() has a temp ref on them". Ok.
>
> Use folio_maybe_dma_pinned() universally, in filemap_release_folio(). This
> has a much lower false positive rate, and should be ok enough for most
> serious cases.
>
> While here, properly assert that no folio passed to release_folio is
> mapped.
>
> Cc: stable@xxxxxxxxxxxxxxx
> Fixes: d824ec2a1546 ("mm: do not reclaim private data from pinned page")
> Signed-off-by: Pedro Falcato <pfalcato@xxxxxxx>
Looks good to me. Feel free to add:
Reviewed-by: Jan Kara <jack@xxxxxxx>
and we'll see whether there's some path which actually required private
data on pinned page to be freed in some cornercase :)
Honza
> ---
> mm/filemap.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index f9e34144c53c..4fa75663b7f3 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);
> if (!folio_needs_release(folio))
> return true;
> + if (folio_maybe_dma_pinned(folio))
> + return false;
> if (folio_test_writeback(folio))
> return false;
>
>
> --
> 2.56.1
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR