]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nbd: correct the maximum value for discard sectors
authorWouter Verhelst <w@uter.be>
Mon, 12 Aug 2024 13:20:42 +0000 (15:20 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 14:32:32 +0000 (16:32 +0200)
[ Upstream commit 296dbc72d29085d5fc34430d0760423071e9e81d ]

The version of the NBD protocol implemented by the kernel driver
currently has a 32 bit field for length values. As the NBD protocol uses
bytes as a unit of length, length values larger than 2^32 bytes cannot
be expressed.

Update the max_hw_discard_sectors field to match that.

Signed-off-by: Wouter Verhelst <w@uter.be>
Fixes: 268283244c0f ("nbd: use the atomic queue limits API in nbd_set_size")
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Cc: Eric Blake <eblake@redhat.Com>
Link: https://lore.kernel.org/r/20240812133032.115134-8-w@uter.be
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/block/nbd.c

index 0e8ddf30563d015e7d35a0d673ce9db5d91cf78e..d4e260d3218063823298f47b796a704b49bdbc44 100644 (file)
@@ -350,7 +350,7 @@ static int __nbd_set_size(struct nbd_device *nbd, loff_t bytesize,
 
        lim = queue_limits_start_update(nbd->disk->queue);
        if (nbd->config->flags & NBD_FLAG_SEND_TRIM)
-               lim.max_hw_discard_sectors = UINT_MAX;
+               lim.max_hw_discard_sectors = UINT_MAX >> SECTOR_SHIFT;
        else
                lim.max_hw_discard_sectors = 0;
        lim.logical_block_size = blksize;