Skip to content

Commit d431f47

Browse files
committed
block: Ensure start sector is aligned for stacking atomic writes
JIRA: https://issues.redhat.com/browse/RHEL-73721 commit 6564862 Author: John Garry <john.g.garry@oracle.com> Date: Thu Jan 9 11:39:59 2025 +0000 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> (cherry picked from commit 6564862) Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
1 parent 98c47d0 commit d431f47

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
@@ -562,14 +562,17 @@ static bool blk_stack_atomic_writes_head(struct queue_limits *t,
562562
}
563563

564564
static void blk_stack_atomic_writes_limits(struct queue_limits *t,
565-
struct queue_limits *b)
565+
struct queue_limits *b, sector_t start)
566566
{
567567
if (!(t->features & BLK_FEAT_ATOMIC_WRITES_STACKED))
568568
goto unsupported;
569569

570570
if (!b->atomic_write_unit_min)
571571
goto unsupported;
572572

573+
if (!blk_atomic_write_start_sect_aligned(start, b))
574+
goto unsupported;
575+
573576
/*
574577
* If atomic_write_hw_max is set, we have already stacked 1x bottom
575578
* device, so check for compliance.
@@ -752,7 +755,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
752755
t->zone_write_granularity = 0;
753756
t->max_zone_append_sectors = 0;
754757
}
755-
blk_stack_atomic_writes_limits(t, b);
758+
blk_stack_atomic_writes_limits(t, b, start);
756759

757760
return ret;
758761
}

include/linux/blkdev.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,15 @@ struct io_comp_batch {
16851685
void (*complete)(struct io_comp_batch *);
16861686
};
16871687

1688+
static inline bool blk_atomic_write_start_sect_aligned(sector_t sector,
1689+
struct queue_limits *limits)
1690+
{
1691+
unsigned int alignment = max(limits->atomic_write_hw_unit_min,
1692+
limits->atomic_write_hw_boundary);
1693+
1694+
return IS_ALIGNED(sector, alignment >> SECTOR_SHIFT);
1695+
}
1696+
16881697
static inline bool bdev_can_atomic_write(struct block_device *bdev)
16891698
{
16901699
struct request_queue *bd_queue = bdev->bd_queue;
@@ -1693,15 +1702,9 @@ static inline bool bdev_can_atomic_write(struct block_device *bdev)
16931702
if (!limits->atomic_write_unit_min)
16941703
return false;
16951704

1696-
if (bdev_is_partition(bdev)) {
1697-
sector_t bd_start_sect = bdev->bd_start_sect;
1698-
unsigned int alignment =
1699-
max(limits->atomic_write_unit_min,
1700-
limits->atomic_write_hw_boundary);
1701-
1702-
if (!IS_ALIGNED(bd_start_sect, alignment >> SECTOR_SHIFT))
1703-
return false;
1704-
}
1705+
if (bdev_is_partition(bdev))
1706+
return blk_atomic_write_start_sect_aligned(bdev->bd_start_sect,
1707+
limits);
17051708

17061709
return true;
17071710
}

0 commit comments

Comments
 (0)