mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: Chi Zhiling <chizhiling@kylinos.cn>,
	Christian Brauner <brauner@kernel.org>,
	Joanne Koong <joannelkoong@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Next Mailing List <linux-next@vger.kernel.org>
Subject: linux-next: manual merge of the exfat tree with the origin tree
Date: Wed, 18 Nov 2026 13:06:16 +0000	[thread overview]
Message-ID: <av2iyFkAQ-mCpbZF@sirena.org.uk> (raw)

[-- Attachment #1: Type: text/plain, Size: 9792 bytes --]

Hi all,

Today's linux-next merge of the exfat tree got conflicts in:

  fs/exfat/iomap.h
  fs/exfat/iomap.c

between commit:

  9e8fc16dc6b47 ("iomap: pass iomap_iter_next_fn directly instead of struct iomap_ops")

from the origin tree and commits:

  cfdee4e5f5764 ("exfat: coordinate direct writes with mmap faults")
  e70ec3eaac957 ("exfat: increase VDL before unlocking initialized folios")

from the exfat tree.  This really needs double checking.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

diff --cc fs/exfat/iomap.c
index 4e6f3ed9dcc85,5e2c35954ecd3..0000000000000
--- a/fs/exfat/iomap.c
+++ b/fs/exfat/iomap.c
@@@ -151,40 -158,44 +158,40 @@@ out
  	return err;
  }
  
- static int exfat_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
- 		unsigned int flags, struct iomap *iomap, struct iomap *srcmap)
 -static int exfat_iomap_next(const struct iomap_iter *iter,
 -			   struct iomap *iomap, struct iomap *srcmap)
++int exfat_iomap_next(const struct iomap_iter *iter,
++		     struct iomap *iomap, struct iomap *srcmap)
  {
- 	return __exfat_iomap_begin(inode, offset, length, flags, iomap, false);
+ 	const loff_t *dio_valid_size = iter->private;
+ 	loff_t valid_size;
+ 	int ret;
+ 
+ 	if (iomap->length) {
+ 		ret = iomap_iter_continue(iter, iomap, srcmap, 0);
+ 		if (ret <= 0)
+ 			return ret;
+ 	}
+ 	if (iter->flags & IOMAP_DIRECT)
+ 		valid_size = *dio_valid_size;
+ 	else
+ 		valid_size = exfat_get_valid_size(EXFAT_I(iter->inode));
+ 	ret = __exfat_iomap_begin(iter->inode, iter->pos, iter->len,
 -				 iter->flags, iomap, false, valid_size);
++				  iter->flags, iomap, false, valid_size);
+ 	return ret ?: 1;
  }
  
  static int exfat_write_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
  		unsigned int flags, struct iomap *iomap, struct iomap *srcmap)
  {
- 	struct exfat_inode_info *ei = EXFAT_I(inode);
- 	loff_t valid_size = exfat_get_valid_size(ei);
- 	loff_t end;
- 	int err;
+ 	int ret;
  
- 	err = __exfat_iomap_begin(inode, offset, length, flags, iomap, true);
- 	if (err || flags & (IOMAP_DIRECT | IOMAP_FAULT) ||
- 	    iomap->flags & IOMAP_F_NEW)
- 		return err;
- 
- 	end = iomap->offset + iomap->length;
- 	if (end >= valid_size ||
- 	    round_up(end, i_blocksize(inode)) <= valid_size)
- 		return 0;
- 
- 	/*
- 	 * Zero the invalid bytes from valid_size to the end of the block
- 	 * to prevent stale data from being exposed through the page cache.
- 	 */
- 	return iomap_truncate_page(inode, valid_size, NULL, exfat_iomap_next,
- 				   NULL, NULL);
+ 	ret = __exfat_iomap_begin(inode, offset, length, flags, iomap, true,
+ 				  exfat_get_valid_size(EXFAT_I(inode)));
+ 	if (!ret && (flags & IOMAP_DIRECT) &&
+ 	    offset + iomap->length > iomap->validity_cookie)
+ 		iomap->flags |= IOMAP_F_DIRTY;
+ 	return ret;
  }
  
- DEFINE_IOMAP_ITER_NEXT(exfat_iomap_next, exfat_iomap_begin);
 -const struct iomap_ops exfat_iomap_ops = {
 -	.iomap_next = exfat_iomap_next,
 -};
--
  #ifdef CONFIG_SWAP
  static int exfat_swap_iomap_begin(struct inode *inode, loff_t offset,
  		loff_t length, unsigned int flags, struct iomap *iomap,
@@@ -214,31 -227,155 +219,150 @@@ static int exfat_write_iomap_end(struc
  	if (!written)
  		return 0;
  
- 	end = pos + written;
- 
- 	if (exfat_advance_valid_size(ei, end))
- 		dirtied = true;
- 
- 	/*
- 	 * IOMAP_F_ZERO_TAIL zeroes the remainder of the last block. Track that
- 	 * block as zeroed so later valid_size extensions do not zero it again.
- 	 */
- 	if (iomap->flags & IOMAP_F_ZERO_TAIL)
- 		end = round_up(end, i_blocksize(inode));
- 	exfat_advance_zeroed_size(ei, end);
- 
- 	if (dirtied || iomap->flags & IOMAP_F_SIZE_CHANGED)
+ 	if (iomap->flags & IOMAP_F_SIZE_CHANGED)
  		mark_inode_dirty(inode);
--
  	return written;
  }
  
- DEFINE_IOMAP_ITER_NEXT_END(exfat_write_iomap_next, exfat_write_iomap_begin,
- 		exfat_write_iomap_end);
 -static int exfat_write_iomap_next(const struct iomap_iter *iter,
 -				  struct iomap *iomap, struct iomap *srcmap)
++int exfat_write_iomap_next(const struct iomap_iter *iter,
++			   struct iomap *iomap, struct iomap *srcmap)
+ {
+ 	int ret;
+ 
+ 	ret = iomap_iter_next(iter, iomap, srcmap, exfat_write_iomap_begin,
+ 			      exfat_write_iomap_end);
+ 	if (ret == -ENOSPC && (iter->flags & IOMAP_DIRECT)) {
+ 		const struct exfat_dio *dio = iter->private;
+ 
+ 		/*
+ 		 * ENOTBLK makes iomap wait for the submitted bios and report
+ 		 * a short write only if they succeeded.
+ 		 */
+ 		if (iter->pos > dio->start)
+ 			return -ENOTBLK;
+ 	}
+ 
+ 	return ret;
+ }
+ 
 -const struct iomap_ops exfat_write_iomap_ops = {
 -	.iomap_next	= exfat_write_iomap_next,
 -};
 -
+ static void exfat_zero_invalid_range(struct folio *folio, loff_t pos,
+ 				     size_t len, loff_t valid_size)
+ {
+ 	loff_t start = max(pos, valid_size);
+ 
+ 	if (start < pos + len)
+ 		folio_zero_segment(folio, offset_in_folio(folio, start),
+ 				   offset_in_folio(folio, pos) + len);
+ }
+ 
+ static struct folio *exfat_iomap_get_folio(struct iomap_iter *iter, loff_t pos,
+ 					   unsigned int len)
+ {
+ 	struct folio *folio = iomap_get_folio(iter, pos, len);
+ 
+ 	if (!IS_ERR(folio))
+ 		iter->iomap.private = folio;
+ 	return folio;
+ }
+ 
+ static bool exfat_iomap_valid(struct inode *inode, const struct iomap *iomap)
+ {
+ 	struct folio *folio = iomap->private;
+ 	loff_t valid_size = exfat_get_valid_size(EXFAT_I(inode));
+ 	loff_t old_valid_size = iomap->validity_cookie;
+ 
+ 	if (valid_size == old_valid_size)
+ 		return true;
+ 	if (!folio)
+ 		return false;
+ 
+ 	return old_valid_size >= folio_next_pos(folio) ||
+ 		valid_size <= folio_pos(folio);
+ }
+ 
+ /* Called after iomap_valid(), with the destination folio still locked. */
+ static int exfat_iomap_read_folio_range(const struct iomap_iter *iter,
+ 					struct folio *folio, loff_t pos, size_t len)
+ {
+ 	loff_t valid_size = iter->iomap.validity_cookie;
+ 	int error = 0;
+ 
+ 	if (pos < valid_size)
+ 		error = iomap_bio_read_folio_range_sync(iter, folio, pos, len);
+ 
+ 	/*
+ 	 * Sanitize all invalid bytes before iomap marks this range uptodate,
+ 	 * including bytes that a short user copy may leave untouched.
+ 	 */
+ 	if (!error)
+ 		exfat_zero_invalid_range(folio, pos, len, valid_size);
+ 	return error;
+ }
+ 
+ static void exfat_iomap_put_folio(struct inode *inode, loff_t pos,
+ 				  unsigned int copied, struct folio *folio)
+ {
+ 	if (copied) {
+ 		struct exfat_inode_info *ei = EXFAT_I(inode);
+ 
+ 		if (exfat_advance_valid_size(ei, pos + copied))
+ 			mark_inode_dirty(inode);
+ 		exfat_advance_zeroed_size(ei,
+ 					  round_up(pos + copied, i_blocksize(inode)));
+ 	}
+ 
+ 	folio_unlock(folio);
+ 	folio_put(folio);
+ }
+ 
+ const struct iomap_write_ops exfat_iomap_write_ops = {
+ 	.get_folio	= exfat_iomap_get_folio,
+ 	.put_folio	= exfat_iomap_put_folio,
+ 	.iomap_valid	= exfat_iomap_valid,
+ 	.read_folio_range = exfat_iomap_read_folio_range,
+ };
+ 
+ /*
+  * Gap zeroing follows the direct write. Keep completed data intact when the
+  * gap and the write share a filesystem block.
+  */
+ static int exfat_dio_gap_read_folio_range(const struct iomap_iter *iter,
+ 		struct folio *folio, loff_t pos, size_t len)
+ {
+ 	const struct exfat_dio *dio = iter->private;
+ 	loff_t valid = iter->iomap.validity_cookie;
+ 	loff_t end = pos + len;
+ 	loff_t start, stop;
+ 	int error;
+ 
+ 	if (pos < valid || end > dio->start) {
+ 		error = iomap_bio_read_folio_range_sync(iter, folio, pos, len);
+ 		if (error)
+ 			return error;
+ 	} else {
+ 		folio_zero_range(folio, offset_in_folio(folio, pos), len);
+ 		return 0;
+ 	}
+ 
+ 	start = max(pos, valid);
+ 	stop = min(end, dio->start);
+ 	if (start < stop)
+ 		folio_zero_segment(folio, offset_in_folio(folio, start),
+ 				   offset_in_folio(folio, pos) + stop - pos);
+ 
+ 	start = max(pos, dio->start + dio->completed);
+ 	if (start < end)
+ 		folio_zero_segment(folio, offset_in_folio(folio, start),
+ 				   offset_in_folio(folio, pos) + len);
+ 	return 0;
+ }
+ 
+ const struct iomap_write_ops exfat_dio_gap_write_ops = {
+ 	.get_folio	= exfat_iomap_get_folio,
+ 	.put_folio	= exfat_iomap_put_folio,
+ 	.iomap_valid	= exfat_iomap_valid,
+ 	.read_folio_range = exfat_dio_gap_read_folio_range,
+ };
  
  /*
   * exfat_writeback_range - Map folio during writeback
diff --cc fs/exfat/iomap.h
index 519132367b65e,f8f018f87230a..0000000000000
--- a/fs/exfat/iomap.h
+++ b/fs/exfat/iomap.h
@@@ -6,11 -6,17 +6,19 @@@
  #ifndef _LINUX_EXFAT_IOMAP_H
  #define _LINUX_EXFAT_IOMAP_H
  
 +#include <linux/iomap.h>
 +
- extern const struct iomap_dio_ops exfat_write_dio_ops;
+ /* One synchronous attempt for a direct write extending valid_size. */
+ struct exfat_dio {
+ 	struct kiocb iocb;
+ 	loff_t start;
+ 	loff_t completed;
+ };
+ 
 -extern const struct iomap_ops exfat_iomap_ops;
 -extern const struct iomap_ops exfat_write_iomap_ops;
 +DECLARE_IOMAP_ITER_NEXT(exfat_iomap_next);
 +DECLARE_IOMAP_ITER_NEXT(exfat_write_iomap_next);
+ extern const struct iomap_write_ops exfat_iomap_write_ops;
+ extern const struct iomap_write_ops exfat_dio_gap_write_ops;
  extern const struct iomap_writeback_ops exfat_writeback_ops;
  extern const struct iomap_read_ops exfat_iomap_bio_read_ops;
  

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

             reply	other threads:[~2026-11-18 13:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 13:06 Mark Brown [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-11-18 13:29 Mark Brown
2026-11-09 12:15 Mark Brown

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=av2iyFkAQ-mCpbZF@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=brauner@kernel.org \
    --cc=chizhiling@kylinos.cn \
    --cc=joannelkoong@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    /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®