Skip to content

Commit c964d62

Browse files
keithbuschaxboe
authored andcommitted
block: make dma_alignment a stacking queue_limit
Device mappers had always been getting the default 511 dma mask, but the underlying device might have a larger alignment requirement. Since this value is used to determine alloweable direct-io alignment, this needs to be a stackable limit. 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 a7a1598 commit c964d62

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

block/blk-core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ struct request_queue *blk_alloc_queue(int node_id, bool alloc_srcu)
425425
PERCPU_REF_INIT_ATOMIC, GFP_KERNEL))
426426
goto fail_stats;
427427

428-
blk_queue_dma_alignment(q, 511);
429428
blk_set_default_limits(&q->limits);
430429
q->nr_requests = BLKDEV_DEFAULT_RQ;
431430

block/blk-settings.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void blk_set_default_limits(struct queue_limits *lim)
5757
lim->misaligned = 0;
5858
lim->zoned = BLK_ZONED_NONE;
5959
lim->zone_write_granularity = 0;
60+
lim->dma_alignment = 511;
6061
}
6162
EXPORT_SYMBOL(blk_set_default_limits);
6263

@@ -600,6 +601,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
600601

601602
t->io_min = max(t->io_min, b->io_min);
602603
t->io_opt = lcm_not_zero(t->io_opt, b->io_opt);
604+
t->dma_alignment = max(t->dma_alignment, b->dma_alignment);
603605

604606
/* Set non-power-of-2 compatible chunk_sectors boundary */
605607
if (b->chunk_sectors)
@@ -773,7 +775,7 @@ EXPORT_SYMBOL(blk_queue_virt_boundary);
773775
**/
774776
void blk_queue_dma_alignment(struct request_queue *q, int mask)
775777
{
776-
q->dma_alignment = mask;
778+
q->limits.dma_alignment = mask;
777779
}
778780
EXPORT_SYMBOL(blk_queue_dma_alignment);
779781

@@ -795,8 +797,8 @@ void blk_queue_update_dma_alignment(struct request_queue *q, int mask)
795797
{
796798
BUG_ON(mask > PAGE_SIZE);
797799

798-
if (mask > q->dma_alignment)
799-
q->dma_alignment = mask;
800+
if (mask > q->limits.dma_alignment)
801+
q->limits.dma_alignment = mask;
800802
}
801803
EXPORT_SYMBOL(blk_queue_update_dma_alignment);
802804

include/linux/blkdev.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ struct queue_limits {
311311
unsigned char discard_misaligned;
312312
unsigned char raid_partial_stripes_expensive;
313313
enum blk_zoned_model zoned;
314+
315+
/*
316+
* Drivers that set dma_alignment to less than 511 must be prepared to
317+
* handle individual bvec's that are not a multiple of a SECTOR_SIZE
318+
* due to possible offsets.
319+
*/
320+
unsigned int dma_alignment;
314321
};
315322

316323
typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx,
@@ -456,12 +463,6 @@ struct request_queue {
456463
unsigned long nr_requests; /* Max # of requests */
457464

458465
unsigned int dma_pad_mask;
459-
/*
460-
* Drivers that set dma_alignment to less than 511 must be prepared to
461-
* handle individual bvec's that are not a multiple of a SECTOR_SIZE
462-
* due to possible offsets.
463-
*/
464-
unsigned int dma_alignment;
465466

466467
#ifdef CONFIG_BLK_INLINE_ENCRYPTION
467468
struct blk_crypto_profile *crypto_profile;
@@ -1324,7 +1325,7 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev)
13241325

13251326
static inline int queue_dma_alignment(const struct request_queue *q)
13261327
{
1327-
return q ? q->dma_alignment : 511;
1328+
return q ? q->limits.dma_alignment : 511;
13281329
}
13291330

13301331
static inline unsigned int bdev_dma_alignment(struct block_device *bdev)

0 commit comments

Comments
 (0)