Linux filesystem development
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: sj1557.seo@samsung.com, yuezhang.mo@sony.com, brauner@kernel.org,
	djwong@kernel.org, hch@lst.de, linux-fsdevel@vger.kernel.org,
	anmuxixixi@gmail.com, dxdt@dev.snart.me, chizhiling@kylinos.cn,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 7/9] exfat: add iomap buffered I/O support
Date: Tue, 12 May 2026 08:34:16 +0200	[thread overview]
Message-ID: <20260512063416.GA30619@lst.de> (raw)
In-Reply-To: <20260507124238.7313-8-linkinjeon@kernel.org>

> diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
> index 415f987afa9a..448857d4b70f 100644
> --- a/fs/exfat/exfat_fs.h
> +++ b/fs/exfat/exfat_fs.h
> @@ -12,6 +12,7 @@
>  #include <linux/blkdev.h>
>  #include <linux/backing-dev.h>
>  #include <uapi/linux/exfat.h>
> +#include <linux/buffer_head.h>

This looks like a bug-fix for adding exfat_cluster_walk a while ago
and not really related to this patch.

>  static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
>  {
>  	struct exfat_inode_info *ei = EXFAT_I(inode);
> +	loff_t old_valid_size;
> +	int ret = 0;
>  
> +	mutex_lock(&sbi->s_lock);
> +	old_valid_size = ei->valid_size;
> +	mutex_unlock(&sbi->s_lock);
>  
> +	if (old_valid_size < new_valid_size) {

The old_valid_size value can be stale as soon the lock is dropped.
So the lock here is not useful, but unless something else protectes
the value the code might be racy.  Also why does this use a sb-wide
lock for a per-inode value?

> +	if (may_alloc)
> +		num_clusters = exfat_bytes_to_cluster_round_up(sbi,
> +				offset + length) - exfat_bytes_to_cluster(sbi, offset);
> +	else
> +		num_clusters = exfat_bytes_to_cluster_round_up(sbi, length);

Why is the num_clusters calculation different for the read vs write case
here?  Also shouldn't the may_alloc case also update length given that
it is used later?

> +	if (length > cluster_length - cluster_offset)
> +		iomap->length = cluster_length - cluster_offset;
> +	else
> +		iomap->length = length;

use min or min_t here?

> +	iomap->addr = exfat_cluster_to_phys(sbi, cluster) + cluster_offset;
> +	iomap->type = IOMAP_MAPPED;
> +	if (may_alloc) {
> +		if (balloc)
> +			iomap->flags = IOMAP_F_NEW;
> +		else if (iomap->offset + iomap->length >= ei->valid_size)
> +			iomap->flags = IOMAP_F_ZERO_TAIL;
> +	} else {
> +		if (offset >= ei->valid_size)
> +			iomap->type = IOMAP_UNWRITTEN;

This might be a good place to explain the valid_size scheme and
how it affects the iomap reported types/flags.

> +/*
> + * exfat_write_iomap_end - Update the state after write
> + *
> + * Extends ->valid_size to cover the newly written range.
> + * Marks the inode dirty if metadata was changed.
> + */
> +static int exfat_write_iomap_end(struct inode *inode, loff_t pos, loff_t length,
> +		ssize_t written, unsigned int flags, struct iomap *iomap)
> +{
> +	if (written) {

Return early on !written to reduce indentation a bit?

> +/**
> + * exfat_iomap_read_end_io - iomap read bio completion handler for exFAT
> + * @bio: bio that has completed reading
> + *
> + * exfat_iomap_begin() rounds up MAPPED extents to the block boundary of
> + * valid_size. This ensures that any subsequent blocks are treated as
> + * IOMAP_UNWRITTEN, but it also causes the "straddle block" containing
> + * valid_size to be read from disk. The disk data beyond valid_size in
> + * this block is stale and must be zeroed to prevent data leakage.

We've seen this in ntfs already.  It also seems like a generally
useful thing to do.  I wonder if we should just unconditionally
zero non-fsverity data beyond i_size or have a flag for this
(although that might be hard to communicate).  But let's revisit that
after the initial merge as there are too many different series in flight
in this area right now.


  reply	other threads:[~2026-05-12  6:34 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 12:42 [PATCH v2 0/9] exfat: convert to iomap Namjae Jeon
2026-05-07 12:42 ` [PATCH v2 1/9] exfat: replace unsafe macros with static inline functions Namjae Jeon
2026-05-07 13:41   ` CharSyam
2026-05-07 23:36     ` Namjae Jeon
2026-05-07 12:42 ` [PATCH v2 2/9] exfat: add balloc parameter to exfat_map_cluster() for iomap support Namjae Jeon
2026-05-07 12:42 ` [PATCH v2 3/9] exfat: add exfat_file_open() Namjae Jeon
2026-05-07 13:52   ` CharSyam
2026-05-07 23:37     ` Namjae Jeon
2026-05-07 12:42 ` [PATCH v2 4/9] exfat: add support for multi-cluster allocation Namjae Jeon
2026-05-07 14:09   ` CharSyam
2026-05-08  0:27     ` Namjae Jeon
2026-05-10 13:32   ` Chi Zhiling
2026-05-11  0:20     ` Namjae Jeon
2026-05-11  0:45       ` Chi Zhiling
2026-05-07 12:42 ` [PATCH v2 5/9] iomap: introduce IOMAP_F_ZERO_TAIL flag Namjae Jeon
2026-05-09  9:59   ` Chi Zhiling
2026-05-09 14:30     ` Namjae Jeon
2026-05-11 12:45   ` Christoph Hellwig
2026-05-11 13:46     ` Namjae Jeon
2026-05-07 12:42 ` [PATCH v2 6/9] exfat: add data_start_bytes and exfat_cluster_to_phys() helper Namjae Jeon
2026-05-07 12:42 ` [PATCH v2 7/9] exfat: add iomap buffered I/O support Namjae Jeon
2026-05-12  6:34   ` Christoph Hellwig [this message]
2026-05-12  7:40     ` Namjae Jeon
2026-05-07 12:42 ` [PATCH v2 8/9] exfat: add iomap direct " Namjae Jeon
2026-05-12  6:37   ` Christoph Hellwig
2026-05-12  7:47     ` Namjae Jeon
2026-05-07 12:42 ` [PATCH v2 9/9] exfat: add support for SEEK_HOLE and SEEK_DATA in llseek Namjae Jeon
2026-05-12  6:40   ` Christoph Hellwig
2026-05-12  7:50     ` Namjae Jeon

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=20260512063416.GA30619@lst.de \
    --to=hch@lst.de \
    --cc=anmuxixixi@gmail.com \
    --cc=brauner@kernel.org \
    --cc=chizhiling@kylinos.cn \
    --cc=djwong@kernel.org \
    --cc=dxdt@dev.snart.me \
    --cc=linkinjeon@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sj1557.seo@samsung.com \
    --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