Skip to content

Commit

Permalink
block: blk_rq_map_kern uses the bounce buffers for stack buffers
Browse files Browse the repository at this point in the history
blk_rq_map_kern is used for kernel internal I/Os. Some callers use
this function with stack buffers but DMA to/from the stack buffers
leads to memory corruption on a non-coherent platform.

This patch make blk_rq_map_kern uses the bounce buffers if a caller
passes a stack buffer (on the all platforms for simplicity).

Signed-off-by: FUJITA Tomonori <[email protected]>
Cc: Bartlomiej Zolnierkiewicz <[email protected]>
Cc: Thomas Bogendoerfer <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: James Bottomley <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
fujita authored and Jens Axboe committed Jul 4, 2008
1 parent 27f8221 commit 30c00ed
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions block/blk-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
int reading = rq_data_dir(rq) == READ;
int do_copy = 0;
struct bio *bio;
unsigned long stack_mask = ~(THREAD_SIZE - 1);

if (len > (q->max_hw_sectors << 9))
return -EINVAL;
Expand All @@ -279,6 +280,10 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
alignment = queue_dma_alignment(q) | q->dma_pad_mask;
do_copy = ((kaddr & alignment) || (len & alignment));

if (!((kaddr & stack_mask) ^
((unsigned long)current->stack & stack_mask)))
do_copy = 1;

if (do_copy)
bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
else
Expand Down

0 comments on commit 30c00ed

Please sign in to comment.