Skip to contentSkip to conversation

xfs: restore bi_bdev in xfs_zone_gc_write_chunk

PATCH Applied Christoph Hellwig 4 participants 5 messages Aug 13 – Aug 21 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: restore bi_bdev in xfs_zone_gc_write_chunk

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")
---
 fs/xfs/xfs_zone_gc.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/xfs/xfs_zone_gc.c +5 -0
index 7ab8f2218c6a..5cc5ad1e3483 100644
@@ -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);
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Christoph Hellwig

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.

Quoted 2 lines
Fixes 080d01c41d44 ("xfs: implement zoned garbage collection")

From a purely defensive standpoint this makes sense, so

--D

Quoted 24 lines
---
 fs/xfs/xfs_zone_gc.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/xfs/xfs_zone_gc.c +5 -0
index 7ab8f2218c6a..5cc5ad1e3483 100644
@@ -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);
Signature · 1 line
2.53.0
#2 lore raw
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Christoph Hellwig

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.

Quoted 6 lines
Quoted 1 line

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.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

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")
Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer Applied
#4 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

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.

[...]

Applied to for-next, thanks!

[1/1] xfs: restore bi_bdev in xfs_zone_gc_write_chunk

      commit: 885435535bb1d07746916d4c8832f95767bf2d7e

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>