Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iomap: Fix broken data integrity guarantees for O_SYNC writes

Commit d279c80e0bac ("iomap: inline iomap_dio_bio_opflags()") has broken
the logic in iomap_dio_bio_iter() in a way that when the device does
support FUA (or has no writeback cache) and the direct IO happens to
freshly allocated or unwritten extents, we will *not* issue fsync after
completing direct IO O_SYNC / O_DSYNC write because the
IOMAP_DIO_WRITE_THROUGH flag stays mistakenly set. Fix the problem by
clearing IOMAP_DIO_WRITE_THROUGH whenever we do not perform FUA write as
it was originally intended.

CC: John Garry <john.g.garry@oracle.com>
CC: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Fixes: d279c80e0bac ("iomap: inline iomap_dio_bio_opflags()")
CC: stable@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/20250730102840.20470-2-jack@suse.cz
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Jan Kara and committed by
Christian Brauner
6b65028e d02d2c98

+7 -7
+7 -7
fs/iomap/direct-io.c
··· 363 363 if (iomap->flags & IOMAP_F_SHARED) 364 364 dio->flags |= IOMAP_DIO_COW; 365 365 366 - if (iomap->flags & IOMAP_F_NEW) { 366 + if (iomap->flags & IOMAP_F_NEW) 367 367 need_zeroout = true; 368 - } else if (iomap->type == IOMAP_MAPPED) { 369 - if (iomap_dio_can_use_fua(iomap, dio)) 370 - bio_opf |= REQ_FUA; 371 - else 372 - dio->flags &= ~IOMAP_DIO_WRITE_THROUGH; 373 - } 368 + else if (iomap->type == IOMAP_MAPPED && 369 + iomap_dio_can_use_fua(iomap, dio)) 370 + bio_opf |= REQ_FUA; 371 + 372 + if (!(bio_opf & REQ_FUA)) 373 + dio->flags &= ~IOMAP_DIO_WRITE_THROUGH; 374 374 375 375 /* 376 376 * We can only do deferred completion for pure overwrites that