From: "Theodore Ts'o" <tytso@mit.edu>
To: Lukas Czerner <lczerner@redhat.com>
Cc: linux-ext4@vger.kernel.org, Frank Sorenson <fsorenso@redhat.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] ext4: Fix data corruption caused by unaligned direct AIO
Date: Thu, 14 Mar 2019 23:38:21 -0400 [thread overview]
Message-ID: <20190315033821.GC11334@mit.edu> (raw)
In-Reply-To: <20190306110642.11804-1-lczerner@redhat.com>
On Wed, Mar 06, 2019 at 12:06:42PM +0100, Lukas Czerner wrote:
> Ext4 needs to serialize unaligned direct AIO because the zeroing of
> partial blocks of two competing unaligned AIOs can result in data
> corruption.
>
> However it decides not to serialize if the potentially unaligned aio is
> past i_size with the rationale that no pending writes are possible past
> i_size. Unfortunately if the i_size is not block aligned and the second
> unaligned write lands past i_size, but still into the same block, it has
> the potential of corrupting the previous unaligned write to the same
> block.
>
> This is (very simplified) reproducer from Frank
>
> // 41472 = (10 * 4096) + 512
> // 37376 = 41472 - 4096
>
> ftruncate(fd, 41472);
> io_prep_pwrite(iocbs[0], fd, buf[0], 4096, 37376);
> io_prep_pwrite(iocbs[1], fd, buf[1], 4096, 41472);
>
> io_submit(io_ctx, 1, &iocbs[1]);
> io_submit(io_ctx, 1, &iocbs[2]);
>
> io_getevents(io_ctx, 2, 2, events, NULL);
>
> Without this patch the 512B range from 40960 up to the start of the
> second unaligned write (41472) is going to be zeroed overwriting the data
> written by the first write. This is a data corruption.
>
> 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> *
> 00009200 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
> *
> 0000a000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> *
> 0000a200 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31
>
> With this patch the data corruption is avoided because we will recognize
> the unaligned_aio and wait for the unwritten extent conversion.
>
> 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> *
> 00009200 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
> *
> 0000a200 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31
> *
> 0000b200
>
> Reported-by: Frank Sorenson <fsorenso@redhat.com>
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> Fixes: e9e3bcecf44c ("ext4: serialize unaligned asynchronous DIO")
> Cc: <stable@vger.kernel.org>
Thanks, applied.
- Ted
prev parent reply other threads:[~2019-03-15 3:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-06 11:06 [PATCH] ext4: Fix data corruption caused by unaligned direct AIO Lukas Czerner
2019-03-15 3:38 ` Theodore Ts'o [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190315033821.GC11334@mit.edu \
--to=tytso@mit.edu \
--cc=fsorenso@redhat.com \
--cc=lczerner@redhat.com \
--cc=linux-ext4@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).