Skip to content

Commit 40b01b9

Browse files
htejunJens Axboe
authored andcommitted
block: update bio according to DMA alignment padding
DMA start address and transfer size alignment for PC requests are achieved using bio_copy_user() instead of bio_map_user(). This works because bio_copy_user() always uses full pages and block DMA alignment isn't allowed to go over PAGE_SIZE. However, the implementation didn't update the last bio of the request to make this padding visible to lower layers. This patch makes blk_rq_map_user() extend the last bio such that it includes the padding area and the size of area pointed to by the request is properly aligned. Signed-off-by: Tejun Heo <htejun@gmail.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent 56c819d commit 40b01b9

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎block/blk-map.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
139139
ubuf += ret;
140140
}
141141

142+
/*
143+
* __blk_rq_map_user() copies the buffers if starting address
144+
* or length isn't aligned. As the copied buffer is always
145+
* page aligned, we know that there's enough room for padding.
146+
* Extend the last bio and update rq->data_len accordingly.
147+
*
148+
* On unmap, bio_uncopy_user() will use unmodified
149+
* bio_map_data pointed to by bio->bi_private.
150+
*/
151+
if (len & queue_dma_alignment(q)) {
152+
unsigned int pad_len = (queue_dma_alignment(q) & ~len) + 1;
153+
struct bio *bio = rq->biotail;
154+
155+
bio->bi_io_vec[bio->bi_vcnt - 1].bv_len += pad_len;
156+
bio->bi_size += pad_len;
157+
}
158+
142159
rq->buffer = rq->data = NULL;
143160
return 0;
144161
unmap_rq:

0 commit comments

Comments
 (0)