All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer
  2025-09-16  0:18 [PATCHSET RFC v5 2/8] " Darrick J. Wong
@ 2025-09-16  0:26 ` Darrick J. Wong
  2025-09-16 13:50   ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Darrick J. Wong @ 2025-09-16  0:26 UTC (permalink / raw)
  To: djwong, miklos; +Cc: bernd, linux-xfs, John, linux-fsdevel, neal, joannelkoong

From: Darrick J. Wong <djwong@kernel.org>

Return IO errors if an ->iomap_begin implementation returns an
IOMAP_INLINE buffer but forgets to set the inline_data pointer.
Filesystems should never do this, but we could help fs developers (me)
fix their bugs by handling this more gracefully than crashing the
kernel.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/iomap/buffered-io.c |   15 ++++++++++-----
 fs/iomap/direct-io.c   |    3 +++
 2 files changed, 13 insertions(+), 5 deletions(-)


diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 741f1f6001e1ff..869f178aea28d3 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -312,6 +312,9 @@ static int iomap_read_inline_data(const struct iomap_iter *iter,
 	size_t size = i_size_read(iter->inode) - iomap->offset;
 	size_t offset = offset_in_folio(folio, iomap->offset);
 
+	if (WARN_ON_ONCE(iomap->inline_data == NULL))
+		return -EIO;
+
 	if (folio_test_uptodate(folio))
 		return 0;
 
@@ -913,7 +916,7 @@ static bool __iomap_write_end(struct inode *inode, loff_t pos, size_t len,
 	return true;
 }
 
-static void iomap_write_end_inline(const struct iomap_iter *iter,
+static bool iomap_write_end_inline(const struct iomap_iter *iter,
 		struct folio *folio, loff_t pos, size_t copied)
 {
 	const struct iomap *iomap = &iter->iomap;
@@ -922,12 +925,16 @@ static void iomap_write_end_inline(const struct iomap_iter *iter,
 	WARN_ON_ONCE(!folio_test_uptodate(folio));
 	BUG_ON(!iomap_inline_data_valid(iomap));
 
+	if (WARN_ON_ONCE(iomap->inline_data == NULL))
+		return false;
+
 	flush_dcache_folio(folio);
 	addr = kmap_local_folio(folio, pos);
 	memcpy(iomap_inline_data(iomap, pos), addr, copied);
 	kunmap_local(addr);
 
 	mark_inode_dirty(iter->inode);
+	return true;
 }
 
 /*
@@ -940,10 +947,8 @@ static bool iomap_write_end(struct iomap_iter *iter, size_t len, size_t copied,
 	const struct iomap *srcmap = iomap_iter_srcmap(iter);
 	loff_t pos = iter->pos;
 
-	if (srcmap->type == IOMAP_INLINE) {
-		iomap_write_end_inline(iter, folio, pos, copied);
-		return true;
-	}
+	if (srcmap->type == IOMAP_INLINE)
+		return iomap_write_end_inline(iter, folio, pos, copied);
 
 	if (srcmap->flags & IOMAP_F_BUFFER_HEAD) {
 		size_t bh_written;
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 6dc4e18f93a40a..a992130a1cb6dd 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -523,6 +523,9 @@ static int iomap_dio_inline_iter(struct iomap_iter *iomi, struct iomap_dio *dio)
 	loff_t pos = iomi->pos;
 	u64 copied;
 
+	if (WARN_ON_ONCE(inline_data == NULL))
+		return -EIO;
+
 	if (WARN_ON_ONCE(!iomap_inline_data_valid(iomap)))
 		return -EIO;
 


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer
  2025-09-16  0:26 ` [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer Darrick J. Wong
@ 2025-09-16 13:50   ` Christoph Hellwig
  2025-09-16 14:50     ` Darrick J. Wong
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2025-09-16 13:50 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: miklos, bernd, linux-xfs, John, linux-fsdevel, neal, joannelkoong

> +	if (WARN_ON_ONCE(iomap->inline_data == NULL))

Shorten this to just !iomap->inline_data instead of checking for NULL?

Same for the other two.

Otherwise this looks good, and I'd prefer to see it go upstream ASAP
instead of hiding it in your big patch pile if possible.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer
  2025-09-16 13:50   ` Christoph Hellwig
@ 2025-09-16 14:50     ` Darrick J. Wong
  0 siblings, 0 replies; 9+ messages in thread
From: Darrick J. Wong @ 2025-09-16 14:50 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: miklos, bernd, linux-xfs, John, linux-fsdevel, neal, joannelkoong

On Tue, Sep 16, 2025 at 06:50:27AM -0700, Christoph Hellwig wrote:
> > +	if (WARN_ON_ONCE(iomap->inline_data == NULL))
> 
> Shorten this to just !iomap->inline_data instead of checking for NULL?
> 
> Same for the other two.
> 
> Otherwise this looks good, and I'd prefer to see it go upstream ASAP
> instead of hiding it in your big patch pile if possible.

Ok.  Will fix and resend as an independent series.

--D

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support
@ 2025-09-16 15:00 Darrick J. Wong
  2025-09-16 15:00 ` [PATCH 1/2] iomap: trace iomap_zero_iter zeroing activities Darrick J. Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Darrick J. Wong @ 2025-09-16 15:00 UTC (permalink / raw)
  To: djwong, brauner; +Cc: hch, linux-fsdevel, hch

Hi all,

In preparation for making fuse use the fs/iomap code for regular file
data IO, fix a few bugs in fuse and apply a couple of tweaks to iomap.
These patches can go in immediately.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

This has been running on the djcloud for months with no problems.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=iomap-fuse-prep
---
Commits in this patchset:
 * iomap: trace iomap_zero_iter zeroing activities
 * iomap: error out on file IO when there is no inline_data buffer
---
 fs/iomap/trace.h       |    1 +
 fs/iomap/buffered-io.c |   18 +++++++++++++-----
 fs/iomap/direct-io.c   |    3 +++
 3 files changed, 17 insertions(+), 5 deletions(-)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] iomap: trace iomap_zero_iter zeroing activities
  2025-09-16 15:00 [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support Darrick J. Wong
@ 2025-09-16 15:00 ` Darrick J. Wong
  2025-09-16 15:00 ` [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer Darrick J. Wong
  2025-09-19 12:17 ` [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support Christian Brauner
  2 siblings, 0 replies; 9+ messages in thread
From: Darrick J. Wong @ 2025-09-16 15:00 UTC (permalink / raw)
  To: djwong, brauner; +Cc: hch, linux-fsdevel, hch

From: Darrick J. Wong <djwong@kernel.org>

Trace which bytes actually get zeroed.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 fs/iomap/trace.h       |    1 +
 fs/iomap/buffered-io.c |    3 +++
 2 files changed, 4 insertions(+)


diff --git a/fs/iomap/trace.h b/fs/iomap/trace.h
index 6ad66e6ba653e8..a61c1dae474270 100644
--- a/fs/iomap/trace.h
+++ b/fs/iomap/trace.h
@@ -84,6 +84,7 @@ DEFINE_RANGE_EVENT(iomap_release_folio);
 DEFINE_RANGE_EVENT(iomap_invalidate_folio);
 DEFINE_RANGE_EVENT(iomap_dio_invalidate_fail);
 DEFINE_RANGE_EVENT(iomap_dio_rw_queued);
+DEFINE_RANGE_EVENT(iomap_zero_iter);
 
 #define IOMAP_TYPE_STRINGS \
 	{ IOMAP_HOLE,		"HOLE" }, \
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 1e95a331a682e2..741f1f6001e1ff 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -1415,6 +1415,9 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,
 		/* warn about zeroing folios beyond eof that won't write back */
 		WARN_ON_ONCE(folio_pos(folio) > iter->inode->i_size);
 
+		trace_iomap_zero_iter(iter->inode, folio_pos(folio) + offset,
+				bytes);
+
 		folio_zero_range(folio, offset, bytes);
 		folio_mark_accessed(folio);
 


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer
  2025-09-16 15:00 [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support Darrick J. Wong
  2025-09-16 15:00 ` [PATCH 1/2] iomap: trace iomap_zero_iter zeroing activities Darrick J. Wong
@ 2025-09-16 15:00 ` Darrick J. Wong
  2025-09-16 16:29   ` Christoph Hellwig
  2025-09-19 12:17 ` [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support Christian Brauner
  2 siblings, 1 reply; 9+ messages in thread
From: Darrick J. Wong @ 2025-09-16 15:00 UTC (permalink / raw)
  To: djwong, brauner; +Cc: linux-fsdevel, hch

From: Darrick J. Wong <djwong@kernel.org>

Return IO errors if an ->iomap_begin implementation returns an
IOMAP_INLINE buffer but forgets to set the inline_data pointer.
Filesystems should never do this, but we could help fs developers (me)
fix their bugs by handling this more gracefully than crashing the
kernel.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/iomap/buffered-io.c |   15 ++++++++++-----
 fs/iomap/direct-io.c   |    3 +++
 2 files changed, 13 insertions(+), 5 deletions(-)


diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 741f1f6001e1ff..8dd5421cb910b5 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -312,6 +312,9 @@ static int iomap_read_inline_data(const struct iomap_iter *iter,
 	size_t size = i_size_read(iter->inode) - iomap->offset;
 	size_t offset = offset_in_folio(folio, iomap->offset);
 
+	if (WARN_ON_ONCE(!iomap->inline_data))
+		return -EIO;
+
 	if (folio_test_uptodate(folio))
 		return 0;
 
@@ -913,7 +916,7 @@ static bool __iomap_write_end(struct inode *inode, loff_t pos, size_t len,
 	return true;
 }
 
-static void iomap_write_end_inline(const struct iomap_iter *iter,
+static bool iomap_write_end_inline(const struct iomap_iter *iter,
 		struct folio *folio, loff_t pos, size_t copied)
 {
 	const struct iomap *iomap = &iter->iomap;
@@ -922,12 +925,16 @@ static void iomap_write_end_inline(const struct iomap_iter *iter,
 	WARN_ON_ONCE(!folio_test_uptodate(folio));
 	BUG_ON(!iomap_inline_data_valid(iomap));
 
+	if (WARN_ON_ONCE(!iomap->inline_data))
+		return false;
+
 	flush_dcache_folio(folio);
 	addr = kmap_local_folio(folio, pos);
 	memcpy(iomap_inline_data(iomap, pos), addr, copied);
 	kunmap_local(addr);
 
 	mark_inode_dirty(iter->inode);
+	return true;
 }
 
 /*
@@ -940,10 +947,8 @@ static bool iomap_write_end(struct iomap_iter *iter, size_t len, size_t copied,
 	const struct iomap *srcmap = iomap_iter_srcmap(iter);
 	loff_t pos = iter->pos;
 
-	if (srcmap->type == IOMAP_INLINE) {
-		iomap_write_end_inline(iter, folio, pos, copied);
-		return true;
-	}
+	if (srcmap->type == IOMAP_INLINE)
+		return iomap_write_end_inline(iter, folio, pos, copied);
 
 	if (srcmap->flags & IOMAP_F_BUFFER_HEAD) {
 		size_t bh_written;
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 6dc4e18f93a40a..efb684bdb2cc10 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -523,6 +523,9 @@ static int iomap_dio_inline_iter(struct iomap_iter *iomi, struct iomap_dio *dio)
 	loff_t pos = iomi->pos;
 	u64 copied;
 
+	if (WARN_ON_ONCE(!inline_data))
+		return -EIO;
+
 	if (WARN_ON_ONCE(!iomap_inline_data_valid(iomap)))
 		return -EIO;
 


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer
  2025-09-16 15:00 ` [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer Darrick J. Wong
@ 2025-09-16 16:29   ` Christoph Hellwig
  0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2025-09-16 16:29 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: brauner, linux-fsdevel, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support
  2025-09-16 15:00 [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support Darrick J. Wong
  2025-09-16 15:00 ` [PATCH 1/2] iomap: trace iomap_zero_iter zeroing activities Darrick J. Wong
  2025-09-16 15:00 ` [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer Darrick J. Wong
@ 2025-09-19 12:17 ` Christian Brauner
  2025-09-19 18:14   ` Darrick J. Wong
  2 siblings, 1 reply; 9+ messages in thread
From: Christian Brauner @ 2025-09-19 12:17 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christian Brauner, hch, linux-fsdevel

On Tue, 16 Sep 2025 08:00:24 -0700, Darrick J. Wong wrote:
> In preparation for making fuse use the fs/iomap code for regular file
> data IO, fix a few bugs in fuse and apply a couple of tweaks to iomap.
> These patches can go in immediately.
> 
> If you're going to start using this code, I strongly recommend pulling
> from my git trees, which are linked below.
> 
> [...]

Applied to the vfs-6.18.iomap branch of the vfs/vfs.git tree.
Patches in the vfs-6.18.iomap branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.18.iomap

[1/2] iomap: trace iomap_zero_iter zeroing activities
      https://git.kernel.org/vfs/vfs/c/231af8c14f0f
[2/2] iomap: error out on file IO when there is no inline_data buffer
      https://git.kernel.org/vfs/vfs/c/6a96fb653b64

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support
  2025-09-19 12:17 ` [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support Christian Brauner
@ 2025-09-19 18:14   ` Darrick J. Wong
  0 siblings, 0 replies; 9+ messages in thread
From: Darrick J. Wong @ 2025-09-19 18:14 UTC (permalink / raw)
  To: Christian Brauner; +Cc: hch, linux-fsdevel

On Fri, Sep 19, 2025 at 02:17:38PM +0200, Christian Brauner wrote:
> On Tue, 16 Sep 2025 08:00:24 -0700, Darrick J. Wong wrote:
> > In preparation for making fuse use the fs/iomap code for regular file
> > data IO, fix a few bugs in fuse and apply a couple of tweaks to iomap.
> > These patches can go in immediately.
> > 
> > If you're going to start using this code, I strongly recommend pulling
> > from my git trees, which are linked below.
> > 
> > [...]
> 
> Applied to the vfs-6.18.iomap branch of the vfs/vfs.git tree.
> Patches in the vfs-6.18.iomap branch should appear in linux-next soon.

Thank you!

--D

> Please report any outstanding bugs that were missed during review in a
> new review to the original patch series allowing us to drop it.
> 
> It's encouraged to provide Acked-bys and Reviewed-bys even though the
> patch has now been applied. If possible patch trailers will be updated.
> 
> Note that commit hashes shown below are subject to change due to rebase,
> trailer updates or similar. If in doubt, please check the listed branch.
> 
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
> branch: vfs-6.18.iomap
> 
> [1/2] iomap: trace iomap_zero_iter zeroing activities
>       https://git.kernel.org/vfs/vfs/c/231af8c14f0f
> [2/2] iomap: error out on file IO when there is no inline_data buffer
>       https://git.kernel.org/vfs/vfs/c/6a96fb653b64
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-09-19 18:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-16 15:00 [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support Darrick J. Wong
2025-09-16 15:00 ` [PATCH 1/2] iomap: trace iomap_zero_iter zeroing activities Darrick J. Wong
2025-09-16 15:00 ` [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer Darrick J. Wong
2025-09-16 16:29   ` Christoph Hellwig
2025-09-19 12:17 ` [PATCHSET v5.1] iomap: cleanups ahead of adding fuse support Christian Brauner
2025-09-19 18:14   ` Darrick J. Wong
  -- strict thread matches above, loose matches on Subject: below --
2025-09-16  0:18 [PATCHSET RFC v5 2/8] " Darrick J. Wong
2025-09-16  0:26 ` [PATCH 2/2] iomap: error out on file IO when there is no inline_data buffer Darrick J. Wong
2025-09-16 13:50   ` Christoph Hellwig
2025-09-16 14:50     ` Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.