Skip to content

Commit 6564862

Browse files
johnpgarryaxboe
authored andcommitted
block: Ensure start sector is aligned for stacking atomic writes
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>
1 parent 6593815 commit 6564862

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
@@ -609,14 +609,17 @@ static bool blk_stack_atomic_writes_head(struct queue_limits *t,
609609
}
610610

611611
static void blk_stack_atomic_writes_limits(struct queue_limits *t,
612-
struct queue_limits *b)
612+
struct queue_limits *b, sector_t start)
613613
{
614614
if (!(t->features & BLK_FEAT_ATOMIC_WRITES_STACKED))
615615
goto unsupported;
616616

617617
if (!b->atomic_write_unit_min)
618618
goto unsupported;
619619

620+
if (!blk_atomic_write_start_sect_aligned(start, b))
621+
goto unsupported;
622+
620623
/*
621624
* If atomic_write_hw_max is set, we have already stacked 1x bottom
622625
* device, so check for compliance.
@@ -799,7 +802,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
799802
t->zone_write_granularity = 0;
800803
t->max_zone_append_sectors = 0;
801804
}
802-
blk_stack_atomic_writes_limits(t, b);
805+
blk_stack_atomic_writes_limits(t, b, start);
803806

804807
return ret;
805808
}

include/linux/blkdev.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,15 @@ struct io_comp_batch {
17061706
void (*complete)(struct io_comp_batch *);
17071707
};
17081708

1709+
static inline bool blk_atomic_write_start_sect_aligned(sector_t sector,
1710+
struct queue_limits *limits)
1711+
{
1712+
unsigned int alignment = max(limits->atomic_write_hw_unit_min,
1713+
limits->atomic_write_hw_boundary);
1714+
1715+
return IS_ALIGNED(sector, alignment >> SECTOR_SHIFT);
1716+
}
1717+
17091718
static inline bool bdev_can_atomic_write(struct block_device *bdev)
17101719
{
17111720
struct request_queue *bd_queue = bdev->bd_queue;
@@ -1714,15 +1723,9 @@ static inline bool bdev_can_atomic_write(struct block_device *bdev)
17141723
if (!limits->atomic_write_unit_min)
17151724
return false;
17161725

1717-
if (bdev_is_partition(bdev)) {
1718-
sector_t bd_start_sect = bdev->bd_start_sect;
1719-
unsigned int alignment =
1720-
max(limits->atomic_write_unit_min,
1721-
limits->atomic_write_hw_boundary);
1722-
1723-
if (!IS_ALIGNED(bd_start_sect, alignment >> SECTOR_SHIFT))
1724-
return false;
1725-
}
1726+
if (bdev_is_partition(bdev))
1727+
return blk_atomic_write_start_sect_aligned(bdev->bd_start_sect,
1728+
limits);
17261729

17271730
return true;
17281731
}

0 commit comments

Comments
 (0)