]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
block: fix bio_split_rw_at to take zone_write_granularity into account
authorChristoph Hellwig <hch@lst.de>
Mon, 4 Nov 2024 06:26:30 +0000 (07:26 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2024 12:52:47 +0000 (13:52 +0100)
[ Upstream commit 7ecd2cd4fae3e8410c0a6620f3a83dcdbb254f02 ]

Otherwise it can create unaligned writes on zoned devices.

Fixes: a805a4fa4fa3 ("block: introduce zone_write_granularity limit")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Link: https://lore.kernel.org/r/20241104062647.91160-3-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
block/blk-merge.c

index f2b5f63e118bd2d6f3a13b20bcb20b83179d9e3d..32d60294a44af26eaef52d5d275a7b2bd8012fa2 100644 (file)
@@ -287,6 +287,14 @@ static bool bvec_split_segs(const struct queue_limits *lim,
        return len > 0 || bv->bv_len > max_len;
 }
 
+static unsigned int bio_split_alignment(struct bio *bio,
+               const struct queue_limits *lim)
+{
+       if (op_is_write(bio_op(bio)) && lim->zone_write_granularity)
+               return lim->zone_write_granularity;
+       return lim->logical_block_size;
+}
+
 /**
  * bio_split_rw_at - check if and where to split a read/write bio
  * @bio:  [in] bio to be split
@@ -349,7 +357,7 @@ split:
         * split size so that each bio is properly block size aligned, even if
         * we do not use the full hardware limits.
         */
-       bytes = ALIGN_DOWN(bytes, lim->logical_block_size);
+       bytes = ALIGN_DOWN(bytes, bio_split_alignment(bio, lim));
 
        /*
         * Bio splitting may cause subtle trouble such as hang when doing sync