From: John Garry <john.g.garry@oracle.com>
To: axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, hch@lst.de
Cc: mpatocka@redhat.com, martin.petersen@oracle.com,
linux-block@vger.kernel.org, dm-devel@lists.linux.dev,
linux-kernel@vger.kernel.org,
John Garry <john.g.garry@oracle.com>
Subject: [PATCH 1/5] block: Ensure start sector is aligned for stacking atomic writes
Date: Mon, 6 Jan 2025 12:41:15 +0000 [thread overview]
Message-ID: <20250106124119.1318428-2-john.g.garry@oracle.com> (raw)
In-Reply-To: <20250106124119.1318428-1-john.g.garry@oracle.com>
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: d7f36dc446e89 ("block: Support atomic writes limits for stacked devices")
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
block/blk-settings.c | 7 +++++--
include/linux/blkdev.h | 21 ++++++++++++---------
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 8f09e33f41f6..a8dd5c097b8a 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -584,7 +584,7 @@ static bool blk_stack_atomic_writes_head(struct queue_limits *t,
}
static void blk_stack_atomic_writes_limits(struct queue_limits *t,
- struct queue_limits *b)
+ struct queue_limits *b, sector_t start)
{
if (!(t->features & BLK_FEAT_ATOMIC_WRITES_STACKED))
goto unsupported;
@@ -592,6 +592,9 @@ static void blk_stack_atomic_writes_limits(struct queue_limits *t,
if (!b->atomic_write_unit_min)
goto unsupported;
+ if (!blk_atomic_write_start_sect_aligned(start, b))
+ goto unsupported;
+
/*
* If atomic_write_hw_max is set, we have already stacked 1x bottom
* device, so check for compliance.
@@ -774,7 +777,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
t->zone_write_granularity = 0;
t->max_zone_append_sectors = 0;
}
- blk_stack_atomic_writes_limits(t, b);
+ blk_stack_atomic_writes_limits(t, b, start);
return ret;
}
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 378d3a1a22fc..b9776d469781 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1699,6 +1699,15 @@ struct io_comp_batch {
void (*complete)(struct io_comp_batch *);
};
+static inline bool blk_atomic_write_start_sect_aligned(sector_t sector,
+ struct queue_limits *limits)
+{
+ unsigned int alignment = max(limits->atomic_write_hw_unit_min,
+ limits->atomic_write_hw_boundary);
+
+ return IS_ALIGNED(sector, alignment >> SECTOR_SHIFT);
+}
+
static inline bool bdev_can_atomic_write(struct block_device *bdev)
{
struct request_queue *bd_queue = bdev->bd_queue;
@@ -1707,15 +1716,9 @@ static inline bool bdev_can_atomic_write(struct block_device *bdev)
if (!limits->atomic_write_unit_min)
return false;
- if (bdev_is_partition(bdev)) {
- sector_t bd_start_sect = bdev->bd_start_sect;
- unsigned int alignment =
- max(limits->atomic_write_unit_min,
- limits->atomic_write_hw_boundary);
-
- if (!IS_ALIGNED(bd_start_sect, alignment >> SECTOR_SHIFT))
- return false;
- }
+ if (bdev_is_partition(bdev))
+ return blk_atomic_write_start_sect_aligned(bdev->bd_start_sect,
+ limits);
return true;
}
--
2.31.1
next prev parent reply other threads:[~2025-01-06 12:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-06 12:41 [PATCH RFC 0/5] device mapper atomic write support John Garry
2025-01-06 12:41 ` John Garry [this message]
2025-01-06 15:36 ` [PATCH 1/5] block: Ensure start sector is aligned for stacking atomic writes Christoph Hellwig
2025-01-06 12:41 ` [PATCH RFC 2/5] block: Change blk_stack_atomic_writes_limits() unit_min check John Garry
2025-01-06 15:37 ` Christoph Hellwig
2025-01-06 12:41 ` [PATCH RFC 3/5] dm-table: Atomic writes support John Garry
2025-01-06 17:49 ` Mike Snitzer
2025-01-06 18:18 ` John Garry
2025-01-06 12:41 ` [PATCH RFC 4/5] dm: Ensure cloned bio is same length for atomic write John Garry
2025-01-06 12:41 ` [PATCH RFC 5/5] dm-linear: Enable atomic writes John Garry
2025-01-06 17:26 ` [PATCH RFC 0/5] device mapper atomic write support Mike Snitzer
2025-01-06 18:14 ` John Garry
2025-01-07 17:13 ` Mikulas Patocka
2025-01-07 17:58 ` John Garry
2025-01-07 18:56 ` Mikulas Patocka
2025-01-16 11:28 ` John Garry
2025-01-16 12:59 ` Mikulas Patocka
2025-01-16 13:03 ` John Garry
2025-01-16 14:58 ` Mikulas Patocka
2025-01-16 15:01 ` John Garry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250106124119.1318428-2-john.g.garry@oracle.com \
--to=john.g.garry@oracle.com \
--cc=agk@redhat.com \
--cc=axboe@kernel.dk \
--cc=dm-devel@lists.linux.dev \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mpatocka@redhat.com \
--cc=snitzer@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®