Skip to content

Commit

Permalink
block: update bio according to DMA alignment padding
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: James Bottomley <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
htejun authored and Jens Axboe committed Feb 19, 2008
1 parent 56c819d commit 40b01b9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions block/blk-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
ubuf += ret;
}

/*
* __blk_rq_map_user() copies the buffers if starting address
* or length isn't aligned. As the copied buffer is always
* page aligned, we know that there's enough room for padding.
* Extend the last bio and update rq->data_len accordingly.
*
* On unmap, bio_uncopy_user() will use unmodified
* bio_map_data pointed to by bio->bi_private.
*/
if (len & queue_dma_alignment(q)) {
unsigned int pad_len = (queue_dma_alignment(q) & ~len) + 1;
struct bio *bio = rq->biotail;

bio->bi_io_vec[bio->bi_vcnt - 1].bv_len += pad_len;
bio->bi_size += pad_len;
}

rq->buffer = rq->data = NULL;
return 0;
unmap_rq:
Expand Down

0 comments on commit 40b01b9

Please sign in to comment.