All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iomap: don't update i_size of block devices on buffered write
@ 2026-11-20 20:24 Breno Leitao
  2026-11-21  0:15 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Breno Leitao @ 2026-11-20 20:24 UTC (permalink / raw)
  To: Christian Brauner, Jens Axboe, Hannes Reinecke, Pankaj Raghav,
	Johannes Thumshirn
  Cc: Luis Chamberlain, Christoph Hellwig, linux-xfs, linux-fsdevel,
	linux-kernel, kernel-team, Breno Leitao

We are seeing this warning on an arm64 linux-next host while the ublk
selftests run (stress_01 deletes the ublk disks under fio buffered
writes):

  WARNING: mm/truncate.c:902 at pagecache_isize_extended+0x37c/0x490, CPU#40: iou-wrk-3496756/3497370
  Call trace:
   pagecache_isize_extended+0x37c/0x490 (P)
   iomap_file_buffered_write+0x38c/0x5d0
   blkdev_buffered_write+0xcc/0x138
   blkdev_write_iter+0x32c/0x4e0
   io_write+0x77c/0xff8

The theory is that the disk shrank under the write. del_gendisk() sets
the capacity to 0, which writes the bdev inode's i_size under
bd_size_lock only. A writer whose mapping predates that reads
old_size == 0 in iomap_write_iter(), sets i_size to pos + written and
calls pagecache_isize_extended(inode, 0, pos). blkdev_buffered_write()
holds i_rwsem shared, so a writer at a lower offset can store a smaller
i_size in between, and WARN_ON(to > inode->i_size) fires. Even without
the warning, the write path regrows the size of a dead disk. The block
layer owns that size (bdev_set_nr_sectors()), and blkdev_write_end()
never touched it before the switch to iomap.

A reproducer on linux-next supports the theory: 128 threads doing 64K
buffered writes to a loop device, while another thread flips its
capacity between 1M and 1G with LOOP_SET_STATUS64, hit the warning 6
to 18 times per 30 second run (4 runs). With this patch it never fires,
and data written through the page cache still reads back intact.

Skip the size update and pagecache_isize_extended() for block devices.

Fixes: 487c607df790 ("block: use iomap for writes to block devices")
Signed-off-by: Breno Leitao <leitao@debian.org>
---
Changes in v2:
- Use a function-scope update_isize variable instead of duplicating the
  S_ISBLK and IOMAP_F_FSVERITY checks (hch)
- Link to v1: https://patch.msgid.link/20261113-iomap-bdev-isize-v1-1-699603b589da@debian.org
---
 fs/iomap/buffered-io.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 6d843b168d5f7d..d3311e7066c13f 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -1191,6 +1191,8 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i,
 {
 	int status = 0;
 	struct address_space *mapping = iter->inode->i_mapping;
+	bool update_isize = !S_ISBLK(iter->inode->i_mode) &&
+			    !(iter->iomap.flags & IOMAP_F_FSVERITY);
 	size_t chunk = mapping_max_folio_size(mapping);
 	unsigned int bdp_flags = (iter->flags & IOMAP_NOWAIT) ? BDP_ASYNC : 0;
 
@@ -1256,14 +1258,13 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i,
 		 * unlock and release the folio.
 		 */
 		old_size = iter->inode->i_size;
-		if (pos + written > old_size &&
-		    !(iter->iomap.flags & IOMAP_F_FSVERITY)) {
+		if (pos + written > old_size && update_isize) {
 			i_size_write(iter->inode, pos + written);
 			iter->iomap.flags |= IOMAP_F_SIZE_CHANGED;
 		}
 		__iomap_put_folio(iter, write_ops, written, folio);
 
-		if (old_size < pos && !(iter->iomap.flags & IOMAP_F_FSVERITY))
+		if (old_size < pos && update_isize)
 			pagecache_isize_extended(iter->inode, old_size, pos);
 
 		cond_resched();

---
base-commit: 6d582d78fad9d828e575ca0cdcff8ea47a77220b
change-id: 20261113-iomap-bdev-isize-a67166c971b7

Best regards,
--  
Breno Leitao <leitao@debian.org>


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

* Re: [PATCH v2] iomap: don't update i_size of block devices on buffered write
  2026-11-20 20:24 [PATCH v2] iomap: don't update i_size of block devices on buffered write Breno Leitao
@ 2026-11-21  0:15 ` Christoph Hellwig
  2026-11-23 13:25 ` Pankaj Raghav (Samsung)
  2026-12-01 13:04 ` Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-11-21  0:15 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Christian Brauner, Jens Axboe, Hannes Reinecke, Pankaj Raghav,
	Johannes Thumshirn, Luis Chamberlain, Christoph Hellwig,
	linux-xfs, linux-fsdevel, linux-kernel, kernel-team

Looks good:

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


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

* Re: [PATCH v2] iomap: don't update i_size of block devices on buffered write
  2026-11-20 20:24 [PATCH v2] iomap: don't update i_size of block devices on buffered write Breno Leitao
  2026-11-21  0:15 ` Christoph Hellwig
@ 2026-11-23 13:25 ` Pankaj Raghav (Samsung)
  2026-12-01 13:04 ` Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Pankaj Raghav (Samsung) @ 2026-11-23 13:25 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Christian Brauner, Jens Axboe, Hannes Reinecke, Pankaj Raghav,
	Johannes Thumshirn, Luis Chamberlain, Christoph Hellwig,
	linux-xfs, linux-fsdevel, linux-kernel, kernel-team

On Fri, Nov 20, 2026 at 12:24:39PM -0800, Breno Leitao wrote:
> We are seeing this warning on an arm64 linux-next host while the ublk
> selftests run (stress_01 deletes the ublk disks under fio buffered
> writes):
> 
>   WARNING: mm/truncate.c:902 at pagecache_isize_extended+0x37c/0x490, CPU#40: iou-wrk-3496756/3497370
>   Call trace:
>    pagecache_isize_extended+0x37c/0x490 (P)
>    iomap_file_buffered_write+0x38c/0x5d0
>    blkdev_buffered_write+0xcc/0x138
>    blkdev_write_iter+0x32c/0x4e0
>    io_write+0x77c/0xff8
> 
> The theory is that the disk shrank under the write. del_gendisk() sets
> the capacity to 0, which writes the bdev inode's i_size under
> bd_size_lock only. A writer whose mapping predates that reads
> old_size == 0 in iomap_write_iter(), sets i_size to pos + written and
> calls pagecache_isize_extended(inode, 0, pos). blkdev_buffered_write()
> holds i_rwsem shared, so a writer at a lower offset can store a smaller
> i_size in between, and WARN_ON(to > inode->i_size) fires. Even without
> the warning, the write path regrows the size of a dead disk. The block
> layer owns that size (bdev_set_nr_sectors()), and blkdev_write_end()
> never touched it before the switch to iomap.
> 
> A reproducer on linux-next supports the theory: 128 threads doing 64K
> buffered writes to a loop device, while another thread flips its
> capacity between 1M and 1G with LOOP_SET_STATUS64, hit the warning 6
> to 18 times per 30 second run (4 runs). With this patch it never fires,
> and data written through the page cache still reads back intact.
> 
> Skip the size update and pagecache_isize_extended() for block devices.
> 
> Fixes: 487c607df790 ("block: use iomap for writes to block devices")
> Signed-off-by: Breno Leitao <leitao@debian.org>

Looks good,
Reviewed-by: Pankaj Raghav (Samsung) <pankaj.raghav@linux.dev>

--
Pankaj

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

* Re: [PATCH v2] iomap: don't update i_size of block devices on buffered write
  2026-11-20 20:24 [PATCH v2] iomap: don't update i_size of block devices on buffered write Breno Leitao
  2026-11-21  0:15 ` Christoph Hellwig
  2026-11-23 13:25 ` Pankaj Raghav (Samsung)
@ 2026-12-01 13:04 ` Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2026-12-01 13:04 UTC (permalink / raw)
  To: Jens Axboe, Hannes Reinecke, Pankaj Raghav, Johannes Thumshirn,
	Breno Leitao
  Cc: Luis Chamberlain, Christoph Hellwig, linux-xfs, linux-fsdevel,
	linux-kernel, kernel-team

On Fri, 20 Nov 2026 12:24:39 -0800, Breno Leitao wrote:
> We are seeing this warning on an arm64 linux-next host while the ublk
> selftests run (stress_01 deletes the ublk disks under fio buffered
> writes):
> 
>   WARNING: mm/truncate.c:902 at pagecache_isize_extended+0x37c/0x490, CPU#40: iou-wrk-3496756/3497370
>   Call trace:
>    pagecache_isize_extended+0x37c/0x490 (P)
>    iomap_file_buffered_write+0x38c/0x5d0
>    blkdev_buffered_write+0xcc/0x138
>    blkdev_write_iter+0x32c/0x4e0
>    io_write+0x77c/0xff8
> 
> [...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes 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.fixes

[1/1] iomap: don't update i_size of block devices on buffered write
      https://git.kernel.org/vfs/vfs/c/dfd4ce60416c


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

end of thread, other threads:[~2026-12-01 13:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 20:24 [PATCH v2] iomap: don't update i_size of block devices on buffered write Breno Leitao
2026-11-21  0:15 ` Christoph Hellwig
2026-11-23 13:25 ` Pankaj Raghav (Samsung)
2026-12-01 13:04 ` Christian Brauner

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.