block: Copy a user iovec if it includes gaps

For drivers that don't support gaps in the SG lists handed to
them we must bounce (copy the user buffers) and pass a bio that
does not include gaps. This doesn't matter for any current user,
but will help to allow iser which can't handle gaps to use the
block virtual boundary instead of using driver-local bounce
buffering when handling SG_IO commands.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Jens Axboe <axboe@fb.com>

authored by Sagi Grimberg and committed by Jens Axboe 46348456 87a816df

+24 -2
+24 -2
block/blk-map.c
··· 9 9 10 10 #include "blk.h" 11 11 12 + static bool iovec_gap_to_prv(struct request_queue *q, 13 + struct iovec *prv, struct iovec *cur) 14 + { 15 + unsigned long prev_end; 16 + 17 + if (!queue_virt_boundary(q)) 18 + return false; 19 + 20 + if (prv->iov_base == NULL && prv->iov_len == 0) 21 + /* prv is not set - don't check */ 22 + return false; 23 + 24 + prev_end = (unsigned long)(prv->iov_base + prv->iov_len); 25 + 26 + return (((unsigned long)cur->iov_base & queue_virt_boundary(q)) || 27 + prev_end & queue_virt_boundary(q)); 28 + } 29 + 12 30 int blk_rq_append_bio(struct request_queue *q, struct request *rq, 13 31 struct bio *bio) 14 32 { ··· 85 67 struct bio *bio; 86 68 int unaligned = 0; 87 69 struct iov_iter i; 88 - struct iovec iov; 70 + struct iovec iov, prv = {.iov_base = NULL, .iov_len = 0}; 89 71 90 72 if (!iter || !iter->count) 91 73 return -EINVAL; ··· 99 81 /* 100 82 * Keep going so we check length of all segments 101 83 */ 102 - if (uaddr & queue_dma_alignment(q)) 84 + if ((uaddr & queue_dma_alignment(q)) || 85 + iovec_gap_to_prv(q, &prv, &iov)) 103 86 unaligned = 1; 87 + 88 + prv.iov_base = iov.iov_base; 89 + prv.iov_len = iov.iov_len; 104 90 } 105 91 106 92 if (unaligned || (q->dma_pad_mask & iter->count) || map_data)