[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240903150748.2179966-2-john.g.garry@oracle.com>
Date: Tue, 3 Sep 2024 15:07:45 +0000
From: John Garry <john.g.garry@...cle.com>
To: axboe@...nel.dk, song@...nel.org, yukuai3@...wei.com, kbusch@...nel.org,
hch@....de, sagi@...mberg.me, James.Bottomley@...senPartnership.com,
martin.petersen@...cle.com
Cc: linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-raid@...r.kernel.org, linux-nvme@...ts.infradead.org,
linux-scsi@...r.kernel.org, John Garry <john.g.garry@...cle.com>
Subject: [PATCH RFC 1/4] block: Make bdev_can_atomic_write() robust against mis-aligned bdev size
For bdev file operations, a write will be truncated when trying to write
past the end of the device. This could not be tolerated for an atomic
write.
Ensure that the size of the bdev matches max atomic write unit so that this
truncation would never occur.
Fixes: 9da3d1e912f3 ("block: Add core atomic write support")
Signed-off-by: John Garry <john.g.garry@...cle.com>
---
include/linux/blkdev.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b7664d593486..af8434e391fa 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1662,6 +1662,9 @@ static inline bool bdev_can_atomic_write(struct block_device *bdev)
if (!limits->atomic_write_unit_min)
return false;
+ if (!IS_ALIGNED(bdev_nr_bytes(bdev), limits->atomic_write_unit_max))
+ return false;
+
if (bdev_is_partition(bdev)) {
sector_t bd_start_sect = bdev->bd_start_sect;
unsigned int alignment =
--
2.31.1
Powered by blists - more mailing lists