Commit 87904074 authored by FUJITA Tomonori's avatar FUJITA Tomonori Committed by Jens Axboe

block: add blk_rq_aligned helper function

This adds blk_rq_aligned helper function to see if alignment and
padding requirement is satisfied for DMA transfer. This also converts
blk_rq_map_kern and __blk_rq_map_user to use the helper function.
Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 4d8ab62e
...@@ -45,7 +45,6 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq, ...@@ -45,7 +45,6 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
unsigned int len, gfp_t gfp_mask) unsigned int len, gfp_t gfp_mask)
{ {
unsigned long uaddr; unsigned long uaddr;
unsigned int alignment;
struct bio *bio, *orig_bio; struct bio *bio, *orig_bio;
int reading, ret; int reading, ret;
...@@ -56,8 +55,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq, ...@@ -56,8 +55,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
* direct dma. else, set up kernel bounce buffers * direct dma. else, set up kernel bounce buffers
*/ */
uaddr = (unsigned long) ubuf; uaddr = (unsigned long) ubuf;
alignment = queue_dma_alignment(q) | q->dma_pad_mask; if (blk_rq_aligned(q, ubuf, len) && !map_data)
if (!(uaddr & alignment) && !(len & alignment) && !map_data)
bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask); bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
else else
bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask); bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
...@@ -274,8 +272,6 @@ EXPORT_SYMBOL(blk_rq_unmap_user); ...@@ -274,8 +272,6 @@ EXPORT_SYMBOL(blk_rq_unmap_user);
int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
unsigned int len, gfp_t gfp_mask) unsigned int len, gfp_t gfp_mask)
{ {
unsigned long kaddr;
unsigned int alignment;
int reading = rq_data_dir(rq) == READ; int reading = rq_data_dir(rq) == READ;
int do_copy = 0; int do_copy = 0;
struct bio *bio; struct bio *bio;
...@@ -285,11 +281,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, ...@@ -285,11 +281,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
if (!len || !kbuf) if (!len || !kbuf)
return -EINVAL; return -EINVAL;
kaddr = (unsigned long)kbuf; do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
alignment = queue_dma_alignment(q) | q->dma_pad_mask;
do_copy = ((kaddr & alignment) || (len & alignment) ||
object_is_on_stack(kbuf));
if (do_copy) if (do_copy)
bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading); bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
else else
......
...@@ -899,6 +899,13 @@ static inline int queue_dma_alignment(struct request_queue *q) ...@@ -899,6 +899,13 @@ static inline int queue_dma_alignment(struct request_queue *q)
return q ? q->dma_alignment : 511; return q ? q->dma_alignment : 511;
} }
static inline int blk_rq_aligned(struct request_queue *q, void *addr,
unsigned int len)
{
unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
return !((unsigned long)addr & alignment) && !(len & alignment);
}
/* assumes size > 256 */ /* assumes size > 256 */
static inline unsigned int blksize_bits(unsigned int size) static inline unsigned int blksize_bits(unsigned int size)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment