From: Chi Zhiling <chizhiling@163.com>
To: Youling Tang <youling.tang@linux.dev>,
Namjae Jeon <linkinjeon@kernel.org>,
Sungjong Seo <sj1557.seo@samsung.com>
Cc: Yuezhang Mo <yuezhang.mo@sony.com>,
exfat@lists.linux.dev, linux-kernel@vger.kernel.org,
Youling Tang <tangyouling@kylinos.cn>,
stable@vger.kernel.org
Subject: Re: [PATCH v2 2/2] exfat: don't map EXFAT_EOF_CLUSTER as a physical cluster
Date: Mon, 16 Nov 2026 17:39:52 +0800 [thread overview]
Message-ID: <fd9bc0a5-2bf7-4ab3-86ba-7267d99f74fd@163.com> (raw)
In-Reply-To: <20261116090720.3226446-3-youling.tang@linux.dev>
On 11/16/26 5:07 PM, Youling Tang wrote:
> From: Youling Tang <tangyouling@kylinos.cn>
>
> exfat_map_cluster() reports a hole by returning success with
> *clu == EXFAT_EOF_CLUSTER for !create. __exfat_iomap_begin() does not
> check that sentinel and converts it into a physical address far beyond
> the device. A writeback that races with the i_size/i_blocks window in
> exfat_cont_expand() can hit this: the writeback submits a bio past the
> end of the device, and fsync() or msync() returns -EIO. If the
> resulting iomap length is zero, iomap_add_to_ioend() can loop on a
> zero-length bio and hang a concurrent truncate.
>
> When a range starts before the end of the cluster chain but extends past
> it, exfat_map_cluster() returns the sentinel for the whole range. Make
> it map the valid prefix in that case, and return the sentinel only if
> the whole range is beyond the chain:
>
> offset chain end offset+len
> |--- prefix ----|--- tail ---|
> |== allocated ==|
> MAPPED HOLE
>
> Reporting the whole straddling range as a hole instead would skip
> valid dirty data.
>
> Report the remaining range as a hole instead of turning the sentinel
> into an address, matching the old exfat_get_block() behavior.
>
> Fixes: 82a81a7352bc ("exfat: add iomap buffered I/O support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
Looks good to me:
Reviewed-by: Chi Zhiling <chizhiling@kylinos.cn>
> ---
> v2: move the clamp into exfat_map_cluster().
>
> fs/exfat/inode.c | 15 ++++++++++++---
> fs/exfat/iomap.c | 12 ++++++++++++
> 2 files changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c
> index c1d15d4fc5e7..b175d2f3e459 100644
> --- a/fs/exfat/inode.c
> +++ b/fs/exfat/inode.c
> @@ -134,6 +134,9 @@ void exfat_sync_inode(struct inode *inode)
> * Input: inode, (logical) clu_offset, target allocation area
> * Output: errcode, cluster number
> * *clu = (~0), if it's unable to allocate a new cluster
> + *
> + * For !create, *count is limited to the part of the range backed by the
> + * cluster chain; the caller reports the remainder as a hole.
> */
> int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
> unsigned int *clu, unsigned int *count, int create,
> @@ -153,9 +156,15 @@ int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
> *count > num_clusters - clu_offset)
> num_to_be_allocated = clu_offset + *count - num_clusters;
>
> - if (!create && (num_to_be_allocated > 0)) {
> - *clu = EXFAT_EOF_CLUSTER;
> - return 0;
> + if (!create && num_to_be_allocated > 0) {
> + if (clu_offset >= num_clusters) {
> + *clu = EXFAT_EOF_CLUSTER;
> + return 0;
> + }
> +
> + /* Range straddles the chain end: map the valid prefix only. */
> + *count = num_clusters - clu_offset;
> + num_to_be_allocated = 0;
> }
>
> *clu = last_clu = ei->start_clu;
> diff --git a/fs/exfat/iomap.c b/fs/exfat/iomap.c
> index 11823591b3a8..ed17b367f820 100644
> --- a/fs/exfat/iomap.c
> +++ b/fs/exfat/iomap.c
> @@ -90,6 +90,18 @@ static int __exfat_iomap_begin(struct inode *inode, loff_t offset, loff_t length
> if (err)
> goto out;
>
> + /*
> + * exfat_map_cluster() can return EXFAT_EOF_CLUSTER when racing with
> + * exfat_cont_expand(). Report it as a hole.
> + */
> + if (!may_alloc && cluster == EXFAT_EOF_CLUSTER) {
> + iomap->type = IOMAP_HOLE;
> + iomap->addr = IOMAP_NULL_ADDR;
> + iomap->offset = offset;
> + iomap->length = length;
> + goto out;
> + }
> +
> cluster_offset = exfat_cluster_offset(sbi, offset);
> cluster_length = exfat_cluster_to_bytes(sbi, num_clusters);
>
prev parent reply other threads:[~2026-11-16 9:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 9:07 [PATCH v2 0/2] exfat: fix iomap mapping vs truncate race Youling Tang
2026-11-16 9:07 ` [PATCH v2 1/2] exfat: fix iomap mapping when writeback races with truncate Youling Tang
2026-11-16 9:07 ` [PATCH v2 2/2] exfat: don't map EXFAT_EOF_CLUSTER as a physical cluster Youling Tang
2026-11-16 9:39 ` Chi Zhiling [this message]
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=fd9bc0a5-2bf7-4ab3-86ba-7267d99f74fd@163.com \
--to=chizhiling@163.com \
--cc=exfat@lists.linux.dev \
--cc=linkinjeon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sj1557.seo@samsung.com \
--cc=stable@vger.kernel.org \
--cc=tangyouling@kylinos.cn \
--cc=youling.tang@linux.dev \
--cc=yuezhang.mo@sony.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
all inboxes | Powered by JetHome®