A dma-buf iterator can't fall back to a bounce copy, so map it directly with blk_rq_map_user_bvec(), which already handles it through bio_iov_iter_set(). Fail with -EINVAL where a copy would otherwise be needed, and update the blk_rq_map_user_bvec() comment to match. Signed-off-by: Anuj Gupta Reviewed-by: Christoph Hellwig --- block/blk-map.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/block/blk-map.c b/block/blk-map.c index 7369aba74771..a65b255b229c 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -459,7 +459,7 @@ int blk_rq_append_bio(struct request *rq, struct bio *bio) } EXPORT_SYMBOL(blk_rq_append_bio); -/* Prepare bio for passthrough IO given ITER_BVEC iter */ +/* Prepare a bio for passthrough I/O from a directly mapped iterator. */ static int blk_rq_map_user_bvec(struct request *rq, const struct iov_iter *iter) { unsigned int max_bytes = rq->q->limits.max_hw_sectors << SECTOR_SHIFT; @@ -506,6 +506,19 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq, struct iov_iter i; int ret = -EINVAL; + if (iov_iter_is_dmabuf_map(iter)) { + if (map_data || (iov_iter_alignment(iter) & align)) + return -EINVAL; + ret = blk_rq_map_user_bvec(rq, iter); + /* + * -EREMOTEIO asks the caller to fall back to a bounce copy, + * which a dma-buf can't do. + */ + if (ret == -EREMOTEIO) + ret = -EINVAL; + return ret; + } + if (map_data) copy = true; else if (iov_iter_alignment(iter) & align) -- 2.25.1