Skip to content

Commit dc05414

Browse files
johnpgarrygregkh
authored andcommitted
block: Ensure start sector is aligned for stacking atomic writes
[ Upstream commit 6564862 ] 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 <[email protected]> Signed-off-by: John Garry <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 88b34fb commit dc05414

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

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

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

619+
if (!blk_atomic_write_start_sect_aligned(start, b))
620+
goto unsupported;
621+
619622
/*
620623
* If atomic_write_hw_max is set, we have already stacked 1x bottom
621624
* device, so check for compliance.
@@ -798,7 +801,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
798801
t->zone_write_granularity = 0;
799802
t->max_zone_append_sectors = 0;
800803
}
801-
blk_stack_atomic_writes_limits(t, b);
804+
blk_stack_atomic_writes_limits(t, b, start);
802805

803806
return ret;
804807
}

include/linux/blkdev.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,15 @@ struct io_comp_batch {
17011701
void (*complete)(struct io_comp_batch *);
17021702
};
17031703

1704+
static inline bool blk_atomic_write_start_sect_aligned(sector_t sector,
1705+
struct queue_limits *limits)
1706+
{
1707+
unsigned int alignment = max(limits->atomic_write_hw_unit_min,
1708+
limits->atomic_write_hw_boundary);
1709+
1710+
return IS_ALIGNED(sector, alignment >> SECTOR_SHIFT);
1711+
}
1712+
17041713
static inline bool bdev_can_atomic_write(struct block_device *bdev)
17051714
{
17061715
struct request_queue *bd_queue = bdev->bd_queue;
@@ -1709,15 +1718,9 @@ static inline bool bdev_can_atomic_write(struct block_device *bdev)
17091718
if (!limits->atomic_write_unit_min)
17101719
return false;
17111720

1712-
if (bdev_is_partition(bdev)) {
1713-
sector_t bd_start_sect = bdev->bd_start_sect;
1714-
unsigned int alignment =
1715-
max(limits->atomic_write_unit_min,
1716-
limits->atomic_write_hw_boundary);
1717-
1718-
if (!IS_ALIGNED(bd_start_sect, alignment >> SECTOR_SHIFT))
1719-
return false;
1720-
}
1721+
if (bdev_is_partition(bdev))
1722+
return blk_atomic_write_start_sect_aligned(bdev->bd_start_sect,
1723+
limits);
17211724

17221725
return true;
17231726
}

0 commit comments

Comments
 (0)