Skip to content

Commit 8790407

Browse files
fujitaJens Axboe
authored andcommitted
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: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Jens Axboe <jens.axboe@oracle.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent 4d8ab62 commit 8790407

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

‎block/blk-map.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
4545
unsigned int len, gfp_t gfp_mask)
4646
{
4747
unsigned long uaddr;
48-
unsigned int alignment;
4948
struct bio *bio, *orig_bio;
5049
int reading, ret;
5150

@@ -56,8 +55,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
5655
* direct dma. else, set up kernel bounce buffers
5756
*/
5857
uaddr = (unsigned long) ubuf;
59-
alignment = queue_dma_alignment(q) | q->dma_pad_mask;
60-
if (!(uaddr & alignment) && !(len & alignment) && !map_data)
58+
if (blk_rq_aligned(q, ubuf, len) && !map_data)
6159
bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
6260
else
6361
bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
@@ -274,8 +272,6 @@ EXPORT_SYMBOL(blk_rq_unmap_user);
274272
int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
275273
unsigned int len, gfp_t gfp_mask)
276274
{
277-
unsigned long kaddr;
278-
unsigned int alignment;
279275
int reading = rq_data_dir(rq) == READ;
280276
int do_copy = 0;
281277
struct bio *bio;
@@ -285,11 +281,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
285281
if (!len || !kbuf)
286282
return -EINVAL;
287283

288-
kaddr = (unsigned long)kbuf;
289-
alignment = queue_dma_alignment(q) | q->dma_pad_mask;
290-
do_copy = ((kaddr & alignment) || (len & alignment) ||
291-
object_is_on_stack(kbuf));
292-
284+
do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
293285
if (do_copy)
294286
bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
295287
else

‎include/linux/blkdev.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,13 @@ static inline int queue_dma_alignment(struct request_queue *q)
899899
return q ? q->dma_alignment : 511;
900900
}
901901

902+
static inline int blk_rq_aligned(struct request_queue *q, void *addr,
903+
unsigned int len)
904+
{
905+
unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
906+
return !((unsigned long)addr & alignment) && !(len & alignment);
907+
}
908+
902909
/* assumes size > 256 */
903910
static inline unsigned int blksize_bits(unsigned int size)
904911
{

0 commit comments

Comments
 (0)