From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Zhan Xusheng <zhanxusheng1024@gmail.com>, Gao Xiang <xiang@kernel.org>
Cc: "open list:EROFS FILE SYSTEM" <linux-erofs@lists.ozlabs.org>,
linux-kernel@vger.kernel.org,
Zhan Xusheng <zhanxusheng@xiaomi.com>
Subject: Re: [PATCH] erofs: fix missing folio_unlock causing lock imbalance
Date: Tue, 31 Mar 2026 10:50:54 +0800 [thread overview]
Message-ID: <669c3c5c-aece-42a6-907a-fdee99e9f1a8@linux.alibaba.com> (raw)
In-Reply-To: <20260331023306.18574-1-zhanxusheng@xiaomi.com>
Hi Zhan,
On 2026/3/31 10:33, Zhan Xusheng wrote:
> folio_trylock() in erofs_try_to_free_all_cached_folios() may
> successfully acquire the folio lock, but the subsequent check
> for erofs_folio_is_managed() can skip unlocking when the folio
> is not managed by EROFS.
Do you find some real timing?
I don't think it can really happen, because:
>
> This leads to a lock imbalance and leaves the folio permanently
> locked, which may cause reclaim stalls or interfere with memory
> management.
>
> Fix this by ensuring folio_unlock() is called before continuing.
If a folio links to a pcluster, folio->private will be non-NULL,
and pcl->compressed_bvecs[i] points to that folios.
And z_erofs_cache_release_folio() will be called with folio lock,
and pcl->compressed_bvecs[i] will be set NULL here.
So I don't think erofs_try_to_free_all_cached_folios() can find
!erofs_folio_is_managed(sbi, folio) in the real world.
>
> Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
> ---
> fs/erofs/zdata.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
> index fe8121df9ef2..9d7ff22f1622 100644
> --- a/fs/erofs/zdata.c
> +++ b/fs/erofs/zdata.c
> @@ -605,8 +605,10 @@ static int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi,
> if (!folio_trylock(folio))
> return -EBUSY;
>
> - if (!erofs_folio_is_managed(sbi, folio))
> + if (!erofs_folio_is_managed(sbi, folio)) {
> + folio_unlock(folio);
> continue;
> + }
> pcl->compressed_bvecs[i].page = NULL;
> folio_detach_private(folio);
But I admit that we should rewrite in function as:
if (!erofs_folio_is_managed(sbi, folio)) {
DBG_BUGON(1);
} else {
pcl->compressed_bvecs[i].page = NULL;
folio_detach_private(folio);
}
folio_unlock(folio);
Thanks,
Gao Xiang
> folio_unlock(folio);
next prev parent reply other threads:[~2026-03-31 2:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 2:33 [PATCH] erofs: fix missing folio_unlock causing lock imbalance Zhan Xusheng
2026-03-31 2:50 ` Gao Xiang [this message]
2026-03-31 2:58 ` Gao Xiang
2026-03-31 3:32 ` Zhan Xusheng
2026-03-31 3:46 ` [PATCH] [PATCH v2] " Zhan Xusheng
2026-03-31 3:55 ` Gao Xiang
2026-03-31 5:02 ` [PATCH] [PATCH v3] erofs: ensure all folios are managed in erofs_try_to_free_all_cached_folios() Zhan Xusheng
2026-03-31 5:28 ` Gao Xiang
2026-04-02 6:46 ` Chunhai Guo
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=669c3c5c-aece-42a6-907a-fdee99e9f1a8@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
--cc=zhanxusheng1024@gmail.com \
--cc=zhanxusheng@xiaomi.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