public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Jinjiang Tu <tujinjiang@huawei.com>
Cc: muchun.song@linux.dev, osalvador@suse.de, david@redhat.com,
	akpm@linux-foundation.org, mike.kravetz@oracle.com,
	linux-mm@kvack.org, wangkefeng.wang@huawei.com
Subject: Re: [PATCH] mm/hugetlb: fix folio is still mapped when deleted
Date: Thu, 11 Sep 2025 19:13:44 +0100	[thread overview]
Message-ID: <aMMRWMpTx6jjZunV@casper.infradead.org> (raw)
In-Reply-To: <20250911130848.4087211-1-tujinjiang@huawei.com>

On Thu, Sep 11, 2025 at 09:08:48PM +0800, Jinjiang Tu wrote:
> Migration may be raced with fallocating hole. remove_inode_single_folio
> will unmap the folio if the folio is still mapped. However, it's called
> without folio lock. If the folio is migrated and the mapped pte has been
> converted to migration entry, folio_mapped() returns false, and won't
> unmap it. Due to extra refcount held by remove_inode_single_folio,
> migration fails, restores migration entry to normal pte, and the folio
> is mapped again. As a result, we triggered BUG in filemap_unaccount_folio.

> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 09d4baef29cf..d21865d0178a 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -521,10 +521,10 @@ static bool remove_inode_single_folio(struct hstate *h, struct inode *inode,
>  	 * the fault mutex.  The mutex will prevent faults
>  	 * until we finish removing the folio.
>  	 */
> +	folio_lock(folio);

The comment above is now nonsensical.  Can you correct it, please?

>  	if (unlikely(folio_mapped(folio)))
>  		hugetlb_unmap_file_folio(h, mapping, folio, index);
>  
> -	folio_lock(folio);
>  	/*
>  	 * We must remove the folio from page cache before removing
>  	 * the region/ reserve map (hugetlb_unreserve_pages).  In
> -- 
> 2.43.0
> 
> 


  reply	other threads:[~2025-09-11 18:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11 13:08 [PATCH] mm/hugetlb: fix folio is still mapped when deleted Jinjiang Tu
2025-09-11 18:13 ` Matthew Wilcox [this message]
2025-09-12  0:30   ` Jinjiang Tu

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=aMMRWMpTx6jjZunV@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=tujinjiang@huawei.com \
    --cc=wangkefeng.wang@huawei.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