
From: Jens Axboe <axboe@kernel.dk> mainline inclusion from mainline-v6.15 commit 34ecde3c56066ba79e5ec3d93c5b14ea83e3603e category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICPOEB CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- DONTCACHE I/O must have the completion punted to a workqueue, just like what is done for unwritten extents, as the completion needs task context to perform the invalidation of the folio(s). However, if writeback is started off filemap_fdatawrite_range() off generic_sync() and it's an overwrite, then the DONTCACHE marking gets lost as iomap_add_to_ioend() don't look at the folio being added and no further state is passed down to help it know that this is a dropbehind/DONTCACHE write. Check if the folio being added is marked as dropbehind, and set IOMAP_IOEND_DONTCACHE if that is the case. Then XFS can factor this into the decision making of completion context in xfs_submit_ioend(). Additionally include this ioend flag in the NOMERGE flags, to avoid mixing it with unrelated IO. Since this is the 3rd flag that will cause XFS to punt the completion to a workqueue, add a helper so that each one of them can get appropriately commented. This fixes extra page cache being instantiated when the write performed is an overwrite, rather than newly instantiated blocks. Fixes: b2cd5ae693a3 ("iomap: make buffered writes work with RWF_DONTCACHE") Signed-off-by: Jens Axboe <axboe@kernel.dk> Link: https://lore.kernel.org/5153f6e8-274d-4546-bf55-30a5018e0d03@kernel.dk Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Christian Brauner <brauner@kernel.org> Conflicts: fs/ext4/inode.c fs/iomap/buffered-io.c fs/xfs/xfs_aops.c include/linux/iomap.h [Context conflicts] Signed-off-by: Long Li <leo.lilong@huawei.com> --- fs/ext4/inode.c | 3 ++- fs/iomap/buffered-io.c | 3 +++ fs/xfs/xfs_aops.c | 3 ++- include/linux/iomap.h | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 045a7213d6b6..3d57bf1b7df4 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3932,7 +3932,8 @@ static int ext4_iomap_prepare_ioend(struct iomap_ioend *ioend, int status) /* Need to convert unwritten extents when I/Os are completed. */ if (ioend->io_type == IOMAP_UNWRITTEN || - ioend->io_offset + ioend->io_size > READ_ONCE(ei->i_disksize)) + ioend->io_offset + ioend->io_size > READ_ONCE(ei->i_disksize) || + ioend->io_flags & IOMAP_F_DONTCACHE) ioend->io_bio.bi_end_io = ext4_iomap_end_bio; return status; diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 3a3f82966fbf..3da42ca9a365 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1871,6 +1871,9 @@ static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, if (!bio_add_folio(&wpc->ioend->io_bio, folio, len, poff)) goto new_ioend; + if (folio_test_dropbehind(folio)) + wpc->ioend->io_flags |= IOMAP_F_DONTCACHE; + if (ifs) atomic_add(len, &ifs->write_bytes_pending); diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 82f18f28c1c1..3fb35bad75ec 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -418,7 +418,8 @@ xfs_prepare_ioend( /* send ioends that might require a transaction to the completion wq */ if (xfs_ioend_is_append(ioend) || ioend->io_type == IOMAP_UNWRITTEN || - (ioend->io_flags & IOMAP_F_SHARED)) + (ioend->io_flags & IOMAP_F_SHARED) || + ioend->io_flags & IOMAP_F_DONTCACHE) ioend->io_bio.bi_end_io = xfs_end_bio; return status; } diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 05d68152edb3..5d9782909b1f 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -64,6 +64,7 @@ struct vm_fault; #define IOMAP_F_BUFFER_HEAD 0 #endif /* CONFIG_BUFFER_HEAD */ #define IOMAP_F_XATTR (1U << 5) +#define IOMAP_F_DONTCACHE (1U << 6) /* * Flags set by the core iomap code during operations: -- 2.39.2