From: Sahitya Tummala <stummala@codeaurora.org>
To: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Chao Yu <yuchao0@huawei.com>,
linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] f2fs: fix data corruption issue with hardware encryption
Date: Thu, 11 Oct 2018 05:59:35 +0530 [thread overview]
Message-ID: <20181011002935.GA24669@codeaurora.org> (raw)
In-Reply-To: <20181010213402.GA52406@jaegeuk-macbookpro.roam.corp.google.com>
On Wed, Oct 10, 2018 at 02:34:02PM -0700, Jaegeuk Kim wrote:
> On 10/10, Sahitya Tummala wrote:
> > Direct IO can be used in case of hardware encryption. The following
> > scenario results into data corruption issue in this path -
> >
> > Thread A - Thread B-
> > -> write file#1 in direct IO
> > -> GC gets kicked in
> > -> GC submitted bio on meta mapping
> > for file#1, but pending completion
> > -> write file#1 again with new data
> > in direct IO
> > -> GC bio gets completed now
> > -> GC writes old data to the new
> > location and thus file#1 is
> > corrupted.
> >
> > Fix this by submitting and waiting for pending io on meta mapping
> > for direct IO case in f2fs_map_blocks().
> >
> > Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
> > ---
> > fs/f2fs/data.c | 12 ++++++++++++
> > 1 file changed, 12 insertions(+)
> >
> > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > index 9ef6f1f..7b2fef0 100644
> > --- a/fs/f2fs/data.c
> > +++ b/fs/f2fs/data.c
> > @@ -1028,6 +1028,12 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
> > map->m_pblk = ei.blk + pgofs - ei.fofs;
> > map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs);
> > map->m_flags = F2FS_MAP_MAPPED;
> > + /* for HW encryption, but to avoid potential issue in future */
> > + if (flag == F2FS_GET_BLOCK_DIO) {
> > + blkaddr = map->m_pblk;
> > + for (; blkaddr < map->m_pblk + map->m_len; blkaddr++)
> > + f2fs_wait_on_block_writeback(sbi, blkaddr);
>
> Do we need this? IIRC, DIO would give create=1.
Yes, we need it. When we are overwriting an existing file, DIO calls
f2fs_map_blocks() with create=0. From the DIO code, I see that this happens
because blockdev_direct_IO() passes this dio flag DIO_SKIP_HOLES. And then
in get_more_blocks(), below code updates create=0, when we are overwriting
an existing file.
create = dio->op == REQ_OP_WRITE;
if (dio->flags & DIO_SKIP_HOLES) {
if (fs_startblk <= ((i_size_read(dio->inode) - 1) >>
i_blkbits))
create = 0;
}
ret = (*sdio->get_block)(dio->inode, fs_startblk,
map_bh, create);
>
> > + }
> > if (map->m_next_extent)
> > *map->m_next_extent = pgofs + map->m_len;
> > goto out;
> > @@ -1188,6 +1194,12 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
> > goto next_dnode;
> >
> > sync_out:
> > + /* for hardware encryption, but to avoid potential issue in future */
> > + if (flag == F2FS_GET_BLOCK_DIO && map->m_flags & F2FS_MAP_MAPPED) {
> > + blkaddr = map->m_pblk;
> > + for (; blkaddr < map->m_pblk + map->m_len; blkaddr++)
> > + f2fs_wait_on_block_writeback(sbi, blkaddr);
> > + }
> > if (flag == F2FS_GET_BLOCK_PRECACHE) {
> > if (map->m_flags & F2FS_MAP_MAPPED) {
> > unsigned int ofs = start_pgofs - map->m_lblk;
> > --
> > Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
> > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
--
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
next prev parent reply other threads:[~2018-10-11 0:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-10 5:26 [PATCH] f2fs: fix data corruption issue with hardware encryption Sahitya Tummala
2018-10-10 21:34 ` Jaegeuk Kim
2018-10-11 0:29 ` Sahitya Tummala [this message]
2018-10-11 2:15 ` Jaegeuk Kim
2018-10-11 3:05 ` Jaegeuk Kim
2018-10-11 3:45 ` Sahitya Tummala
2018-10-15 12:26 ` [f2fs-dev] " Chao Yu
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=20181011002935.GA24669@codeaurora.org \
--to=stummala@codeaurora.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=yuchao0@huawei.com \
/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).