gfs2: Don't get stuck writing page onto itself under direct I/O
authorAndreas Gruenbacher <agruenba@redhat.com>
Wed, 31 May 2023 19:08:26 +0000 (21:08 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Jun 2023 09:12:38 +0000 (11:12 +0200)
commitc2888c460db2a7d83c4d062a22d575b871d98dbc
tree1a53e9f5295ffb4ece3f3b8a5cd72af010cf5d16
parent878dad66b9b5e86a2916858933037c1cb5db275a
gfs2: Don't get stuck writing page onto itself under direct I/O

[ Upstream commit fa58cc888d67e640e354d8b3ceef877ea167b0cf ]

When a direct I/O write is performed, iomap_dio_rw() invalidates the
part of the page cache which the write is going to before carrying out
the write.  In the odd case, the direct I/O write will be reading from
the same page it is writing to.  gfs2 carries out writes with page
faults disabled, so it should have been obvious that this page
invalidation can cause iomap_dio_rw() to never make any progress.
Currently, gfs2 will end up in an endless retry loop in
gfs2_file_direct_write() instead, though.

Break this endless loop by limiting the number of retries and falling
back to buffered I/O after that.

Also simplify should_fault_in_pages() sightly and add a comment to make
the above case easier to understand.

Reported-by: Jan Kara <jack@suse.cz>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/gfs2/file.c