* [PATCH] xfs: restore bi_bdev in xfs_zone_gc_write_chunk
@ 2026-08-13 14:56 Christoph Hellwig
2026-08-13 15:11 ` Darrick J. Wong
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2026-08-13 14:56 UTC (permalink / raw)
To: cem; +Cc: hans.holmberg, dlemoal, linux-xfs
xfs_zone_gc_write_chunk relies on bi_bdev to still be valid, which is not
true when XFS is used on top of a stacked block device. This can lead to
misdirected GC writes, writing of plain text when using dm-crypt, or
miscalculated I/O limits in xfs_zone_gc_split_write.
Fix this by reassigning bi_bdev.
Fixes: 080d01c41d44 ("xfs: implement zoned garbage collection")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/xfs/xfs_zone_gc.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/xfs/xfs_zone_gc.c b/fs/xfs/xfs_zone_gc.c
index 7ab8f2218c6a..5cc5ad1e3483 100644
--- a/fs/xfs/xfs_zone_gc.c
+++ b/fs/xfs/xfs_zone_gc.c
@@ -869,6 +869,11 @@ xfs_zone_gc_write_chunk(
WRITE_ONCE(chunk->state, XFS_GC_BIO_NEW);
list_move_tail(&chunk->entry, &data->writing);
+ /*
+ * If we run on top of stacked block device, the read I/O might have
+ * reset bi_bdev, restore it to the one we want.
+ */
+ bio_set_dev(&chunk->bio, mp->m_rtdev_targp->bt_bdev);
bio_reuse(&chunk->bio, REQ_OP_WRITE);
while ((split_chunk = xfs_zone_gc_split_write(data, chunk)))
xfs_zone_gc_submit_write(data, split_chunk);
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] xfs: restore bi_bdev in xfs_zone_gc_write_chunk
2026-08-13 14:56 [PATCH] xfs: restore bi_bdev in xfs_zone_gc_write_chunk Christoph Hellwig
@ 2026-08-13 15:11 ` Darrick J. Wong
2026-08-14 6:24 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2026-08-13 15:11 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: cem, hans.holmberg, dlemoal, linux-xfs
On Thu, Aug 13, 2026 at 04:56:12PM +0200, Christoph Hellwig wrote:
> xfs_zone_gc_write_chunk relies on bi_bdev to still be valid, which is not
> true when XFS is used on top of a stacked block device. This can lead to
> misdirected GC writes, writing of plain text when using dm-crypt, or
> miscalculated I/O limits in xfs_zone_gc_split_write.
>
> Fix this by reassigning bi_bdev.
ewww, what??
Should bio_reuse take a bdev parameter and set_dev itself? I had no
idea that bi_bdev could get changed by the time the bio completes.
> Fixes: 080d01c41d44 ("xfs: implement zoned garbage collection")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
From a purely defensive standpoint this makes sense, so
Cc: <stable@vger.kernel.org> # v6.15
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> fs/xfs/xfs_zone_gc.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/fs/xfs/xfs_zone_gc.c b/fs/xfs/xfs_zone_gc.c
> index 7ab8f2218c6a..5cc5ad1e3483 100644
> --- a/fs/xfs/xfs_zone_gc.c
> +++ b/fs/xfs/xfs_zone_gc.c
> @@ -869,6 +869,11 @@ xfs_zone_gc_write_chunk(
> WRITE_ONCE(chunk->state, XFS_GC_BIO_NEW);
> list_move_tail(&chunk->entry, &data->writing);
>
> + /*
> + * If we run on top of stacked block device, the read I/O might have
> + * reset bi_bdev, restore it to the one we want.
> + */
> + bio_set_dev(&chunk->bio, mp->m_rtdev_targp->bt_bdev);
> bio_reuse(&chunk->bio, REQ_OP_WRITE);
> while ((split_chunk = xfs_zone_gc_split_write(data, chunk)))
> xfs_zone_gc_submit_write(data, split_chunk);
> --
> 2.53.0
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] xfs: restore bi_bdev in xfs_zone_gc_write_chunk
2026-08-13 15:11 ` Darrick J. Wong
@ 2026-08-14 6:24 ` Christoph Hellwig
0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-08-14 6:24 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Christoph Hellwig, cem, hans.holmberg, dlemoal, linux-xfs
On Thu, Aug 13, 2026 at 08:11:50AM -0700, Darrick J. Wong wrote:
> On Thu, Aug 13, 2026 at 04:56:12PM +0200, Christoph Hellwig wrote:
> > xfs_zone_gc_write_chunk relies on bi_bdev to still be valid, which is not
> > true when XFS is used on top of a stacked block device. This can lead to
> > misdirected GC writes, writing of plain text when using dm-crypt, or
> > miscalculated I/O limits in xfs_zone_gc_split_write.
> >
> > Fix this by reassigning bi_bdev.
>
> ewww, what??
>
> Should bio_reuse take a bdev parameter and set_dev itself? I had no
> idea that bi_bdev could get changed by the time the bio completes.
It probably should, and at some point it did, but it got dropped
somewhere in review. But ket's get the fix in without that first.
Also note that dm-crypt actually always clones these days as I figured
out when trying to come up with an xfstests for this. So this is
mostly limited to dm-linear and nvme-multipath.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-14 6:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-13 14:56 [PATCH] xfs: restore bi_bdev in xfs_zone_gc_write_chunk Christoph Hellwig
2026-08-13 15:11 ` Darrick J. Wong
2026-08-14 6:24 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox