Skip to content

Commit 0b93b92

Browse files
committed
block: Ensure start sector is aligned for stacking atomic writes
JIRA: https://issues.redhat.com/browse/RHEL-73514 For stacking atomic writes, ensure that the start sector is aligned with the device atomic write unit min and any boundary. Otherwise, we may permit misaligned atomic writes. Rework bdev_can_atomic_write() into a common helper to resuse the alignment check. There also use atomic_write_hw_unit_min, which is more proper (than atomic_write_unit_min). Fixes: d7f36dc ("block: Support atomic writes limits for stacked devices") Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/20250109114000.2299896-2-john.g.garry@oracle.com Signed-off-by: Jens Axboe <axboe@kernel.dk> (cherry picked from commit 6564862) Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
1 parent 669038c commit 0b93b92

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

block/blk-settings.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,17 @@ static bool blk_stack_atomic_writes_head(struct queue_limits *t,
587587
}
588588

589589
static void blk_stack_atomic_writes_limits(struct queue_limits *t,
590-
struct queue_limits *b)
590+
struct queue_limits *b, sector_t start)
591591
{
592592
if (!(t->features & BLK_FEAT_ATOMIC_WRITES_STACKED))
593593
goto unsupported;
594594

595595
if (!b->atomic_write_unit_min)
596596
goto unsupported;
597597

598+
if (!blk_atomic_write_start_sect_aligned(start, b))
599+
goto unsupported;
600+
598601
/*
599602
* If atomic_write_hw_max is set, we have already stacked 1x bottom
600603
* device, so check for compliance.
@@ -777,7 +780,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
777780
t->zone_write_granularity = 0;
778781
t->max_zone_append_sectors = 0;
779782
}
780-
blk_stack_atomic_writes_limits(t, b);
783+
blk_stack_atomic_writes_limits(t, b, start);
781784

782785
return ret;
783786
}

include/linux/blkdev.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,15 @@ struct io_comp_batch {
16711671
void (*complete)(struct io_comp_batch *);
16721672
};
16731673

1674+
static inline bool blk_atomic_write_start_sect_aligned(sector_t sector,
1675+
struct queue_limits *limits)
1676+
{
1677+
unsigned int alignment = max(limits->atomic_write_hw_unit_min,
1678+
limits->atomic_write_hw_boundary);
1679+
1680+
return IS_ALIGNED(sector, alignment >> SECTOR_SHIFT);
1681+
}
1682+
16741683
static inline bool bdev_can_atomic_write(struct block_device *bdev)
16751684
{
16761685
struct request_queue *bd_queue = bdev->bd_queue;
@@ -1679,15 +1688,9 @@ static inline bool bdev_can_atomic_write(struct block_device *bdev)
16791688
if (!limits->atomic_write_unit_min)
16801689
return false;
16811690

1682-
if (bdev_is_partition(bdev)) {
1683-
sector_t bd_start_sect = bdev->bd_start_sect;
1684-
unsigned int alignment =
1685-
max(limits->atomic_write_unit_min,
1686-
limits->atomic_write_hw_boundary);
1687-
1688-
if (!IS_ALIGNED(bd_start_sect, alignment >> SECTOR_SHIFT))
1689-
return false;
1690-
}
1691+
if (bdev_is_partition(bdev))
1692+
return blk_atomic_write_start_sect_aligned(bdev->bd_start_sect,
1693+
limits);
16911694

16921695
return true;
16931696
}

0 commit comments

Comments
 (0)