mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 01:49:46 +00:00
virtio-blk: Don't use MAX_DISCARD_SEGMENTS if max_discard_seg is zero
[ Upstream commitdacc73ed0b] Currently the value of max_discard_segment will be set to MAX_DISCARD_SEGMENTS (256) with no basis in hardware if device set 0 to max_discard_seg in configuration space. It's incorrect since the device might not be able to handle such large descriptors. To fix it, let's follow max_segments restrictions in this case. Fixes:1f23816b8e("virtio_blk: add discard and write zeroes support") Signed-off-by: Xie Yongji <xieyongji@bytedance.com> Link: https://lore.kernel.org/r/20220304100058.116-1-xieyongji@bytedance.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
a3d5fcc6cf
commit
cca9d5035b
@@ -869,9 +869,15 @@ static int virtblk_probe(struct virtio_device *vdev)
|
|||||||
|
|
||||||
virtio_cread(vdev, struct virtio_blk_config, max_discard_seg,
|
virtio_cread(vdev, struct virtio_blk_config, max_discard_seg,
|
||||||
&v);
|
&v);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* max_discard_seg == 0 is out of spec but we always
|
||||||
|
* handled it.
|
||||||
|
*/
|
||||||
|
if (!v)
|
||||||
|
v = sg_elems - 2;
|
||||||
blk_queue_max_discard_segments(q,
|
blk_queue_max_discard_segments(q,
|
||||||
min_not_zero(v,
|
min(v, MAX_DISCARD_SEGMENTS));
|
||||||
MAX_DISCARD_SEGMENTS));
|
|
||||||
|
|
||||||
blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
|
blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user