From: John Garry <john.g.garry@oracle.com> mainline inclusion from mainline-v6.14-rc1 commit aacd436e40b0a8f0e8411438c5b5db98bd8f0256 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/ID2HML CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- Help explain the code. Also clarify the comment for bio size check. Signed-off-by: John Garry <john.g.garry@oracle.com> Link: https://lore.kernel.org/r/20250320120250.4087011-3-john.g.garry@oracle.com Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Long Li <leo.lilong@huawei.com> --- fs/iomap/direct-io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index aa8245f7d740..7a734b95773e 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -290,6 +290,11 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, bio_opf |= REQ_OP_WRITE; if (iter->flags & IOMAP_ATOMIC_HW) { + /* + * Ensure that the mapping covers the full write + * length, otherwise it won't be submitted as a single + * bio, which is required to use hardware atomics. + */ if (length != iter->len) return -EINVAL; bio_opf |= REQ_ATOMIC; @@ -392,7 +397,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, n = bio->bi_iter.bi_size; if (WARN_ON_ONCE((bio_opf & REQ_ATOMIC) && n != length)) { /* - * This bio should have covered the complete length, + * An atomic write bio must cover the complete length, * which it doesn't, so error. We may need to zero out * the tail (complete FS block), similar to when * bio_iov_iter_get_pages() returns an error, above. -- 2.39.2