Commit 580eaab8 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Wentao Guan
Browse files

iomap: handle a post-direct I/O invalidate race in iomap_write_delalloc_release

stable inclusion
from stable-v6.6.55
commit 390b9e54cdfd6bb2cf3286db77691f2fd391aafe
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IB0MX4

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=390b9e54cdfd6bb2cf3286db77691f2fd391aafe



--------------------------------

[ Upstream commit 7a9d43eace888a0ee6095035997bb138425844d3 ]

When direct I/O completions invalidates the page cache it holds neither the
i_rwsem nor the invalidate_lock so it can be racing with
iomap_write_delalloc_release.  If the search for the end of the region that
contains data returns the start offset we hit such a race and just need to
look for the end of the newly created hole instead.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20240910043949.3481298-2-hch@lst.de


Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
[ Conflict in comment ]
(cherry picked from commit 390b9e54cdfd6bb2cf3286db77691f2fd391aafe)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent 93a16312
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1309,6 +1309,8 @@ static int iomap_write_delalloc_release(struct inode *inode,
		 * cache, if data page was dropped between seek for data and
		 * hole, data_end may be equal to start_byte, just let it keep
		 * seeking.
		 * If we race with post-direct I/O invalidation of the page cache,
		 * there might be no data left at start_byte.
		 */
		if (data_end == start_byte)
			continue;