Skip to content

Commit b1a000d

Browse files
keithbuschaxboe
authored andcommitted
block: relax direct io memory alignment
Use the address alignment requirements from the block_device for direct io instead of requiring addresses be aligned to the block size. User space can discover the alignment requirements from the dma_alignment queue attribute. User space can specify any hardware compatible DMA offset for each segment, but every segment length is still required to be a multiple of the block size. Signed-off-by: Keith Busch <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 5debd96 commit b1a000d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

block/bio.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,16 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
12201220
BUILD_BUG_ON(PAGE_PTRS_PER_BVEC < 2);
12211221
pages += entries_left * (PAGE_PTRS_PER_BVEC - 1);
12221222

1223+
/*
1224+
* Each segment in the iov is required to be a block size multiple.
1225+
* However, we may not be able to get the entire segment if it spans
1226+
* more pages than bi_max_vecs allows, so we have to ALIGN_DOWN the
1227+
* result to ensure the bio's total size is correct. The remainder of
1228+
* the iov data will be picked up in the next bio iteration.
1229+
*/
12231230
size = iov_iter_get_pages(iter, pages, LONG_MAX, nr_pages, &offset);
1231+
if (size > 0)
1232+
size = ALIGN_DOWN(size, bdev_logical_block_size(bio->bi_bdev));
12241233
if (unlikely(size <= 0))
12251234
return size ? size : -EFAULT;
12261235

block/fops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ static unsigned int dio_bio_write_op(struct kiocb *iocb)
4545
static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos,
4646
struct iov_iter *iter)
4747
{
48-
return ((pos | iov_iter_alignment(iter)) &
49-
(bdev_logical_block_size(bdev) - 1));
48+
return pos & (bdev_logical_block_size(bdev) - 1) ||
49+
!bdev_iter_is_aligned(bdev, iter);
5050
}
5151

5252
#define DIO_INLINE_BIO_VECS 4

include/linux/blkdev.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ struct request_queue {
424424
unsigned long nr_requests; /* Max # of requests */
425425

426426
unsigned int dma_pad_mask;
427+
/*
428+
* Drivers that set dma_alignment to less than 511 must be prepared to
429+
* handle individual bvec's that are not a multiple of a SECTOR_SIZE
430+
* due to possible offsets.
431+
*/
427432
unsigned int dma_alignment;
428433

429434
#ifdef CONFIG_BLK_INLINE_ENCRYPTION

0 commit comments

Comments
 (0)