Buffered writes to zoned realtime files hold XFS_IOLOCK_EXCL, but direct I/O submitted earlier while holding the lock shared can still be active. The buffered write can dirty page cache before the asynchronous direct write completes its post-I/O invalidation, causing an invalidation failure and a mapping error. Use the buffered-write DIO drain after acquiring XFS_IOLOCK_EXCL and before the zoned write checks can touch page cache. Preserve NOWAIT semantics by returning -EAGAIN when a wait would be needed. Fixes: 2e2383405824 ("xfs: implement direct writes to zoned RT devices") Cc: stable@vger.kernel.org Signed-off-by: Jiale Yao --- fs/xfs/xfs_file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index aa7cf51b5843..96a11af8e71a 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1121,6 +1121,10 @@ xfs_file_buffered_write_zoned( if (ret) goto out_unreserve; + ret = xfs_file_buffered_write_dio_wait(iocb); + if (ret) + goto out_unlock; + ret = xfs_file_write_checks(iocb, from, &iolock, &ac); if (ret) goto out_unlock; -- 2.34.1