All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: Fix data corruption caused by overlapping unaligned and aligned IO
@ 2019-05-06 13:49 Lukas Czerner
  2019-05-11  1:53 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Lukas Czerner @ 2019-05-06 13:49 UTC (permalink / raw)
  To: linux-ext4

Unaligned AIO must be serialized because the zeroing of partial blocks
of unaligned AIO can result in data corruption in case it's overlapping
another in flight IO.

Currently we wait for all unwritten extents before we submit unaligned
AIO which protects data in case of unaligned AIO is following overlapping
IO. However if a unaligned AIO is followed by overlapping aligned AIO we
can still end up corrupting data.

To fix this, we must make sure that the unaligned AIO is the only IO in
flight by waiting for unwritten extents conversion not just before the
IO submission, but right after it as well.

This problem can be reproduced by xfstest generic/538

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 fs/ext4/file.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 98ec11f69cd4..2c5baa5e8291 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -264,6 +264,13 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	}
 
 	ret = __generic_file_write_iter(iocb, from);
+	/*
+	 * Unaligned direct AIO must be the only IO in flight. Otherwise
+	 * overlapping aligned IO after unaligned might result in data
+	 * corruption.
+	 */
+	if (ret == -EIOCBQUEUED && unaligned_aio)
+		ext4_unwritten_wait(inode);
 	inode_unlock(inode);
 
 	if (ret > 0)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: Fix data corruption caused by overlapping unaligned and aligned IO
  2019-05-06 13:49 [PATCH] ext4: Fix data corruption caused by overlapping unaligned and aligned IO Lukas Czerner
@ 2019-05-11  1:53 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2019-05-11  1:53 UTC (permalink / raw)
  To: Lukas Czerner; +Cc: linux-ext4

On Mon, May 06, 2019 at 03:49:52PM +0200, Lukas Czerner wrote:
> Unaligned AIO must be serialized because the zeroing of partial blocks
> of unaligned AIO can result in data corruption in case it's overlapping
> another in flight IO.
> 
> Currently we wait for all unwritten extents before we submit unaligned
> AIO which protects data in case of unaligned AIO is following overlapping
> IO. However if a unaligned AIO is followed by overlapping aligned AIO we
> can still end up corrupting data.
> 
> To fix this, we must make sure that the unaligned AIO is the only IO in
> flight by waiting for unwritten extents conversion not just before the
> IO submission, but right after it as well.
> 
> This problem can be reproduced by xfstest generic/538
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>

Many thanks, applied.

						- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-11 17:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-06 13:49 [PATCH] ext4: Fix data corruption caused by overlapping unaligned and aligned IO Lukas Czerner
2019-05-11  1:53 ` Theodore Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.