Re: [PATCH 5/5] virtio-blk: Consider virtio_max_dma_size() for maximum segment size

From: Joerg Roedel
Date: Thu Jan 24 2019 - 04:51:55 EST


On Thu, Jan 24, 2019 at 09:42:21AM +0100, Christoph Hellwig wrote:
> Yes. But more importantly it would fix the limit for all other block
> drivers that set large segment sizes when running over swiotlb.

True, so it would be something like the diff below? I havn't worked on
the block layer, so I don't know if that needs additional checks for
->dev or anything.

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 3e7038e475ee..9a927280c904 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -1,6 +1,7 @@
/*
* Functions related to setting various queue properties from drivers
*/
+#include <linux/dma-mapping.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
@@ -303,13 +304,17 @@ EXPORT_SYMBOL_GPL(blk_queue_max_discard_segments);
**/
void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
{
+ unsigned int dma_max_size;
+
if (max_size < PAGE_SIZE) {
max_size = PAGE_SIZE;
printk(KERN_INFO "%s: set to minimum %d\n",
__func__, max_size);
}

- q->limits.max_segment_size = max_size;
+ dma_max_size = dma_max_mapping_size(q->backing_dev_info->dev);
+
+ q->limits.max_segment_size = min(max_size, dma_max_size);
}
EXPORT_SYMBOL(blk_queue_max_segment_size);