From: Ritesh Harjani <riteshh@linux.ibm.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, jack@suse.cz, Ritesh Harjani <riteshh@linux.ibm.com>
Subject: [RFC 1/2] iomap: direct-io: Move inode_dio_begin before filemap_write_and_wait_range
Date: Mon, 13 Jan 2020 16:34:21 +0530 [thread overview]
Message-ID: <27607a16327fe9664f32d09abe565af0d1ae56c9.1578907891.git.riteshh@linux.ibm.com> (raw)
In-Reply-To: <cover.1578907890.git.riteshh@linux.ibm.com>
Some filesystems (e.g. ext4) need to know in it's writeback path, that
whether DIO is in progress or not. This info may be needed to avoid the
stale data exposure race with DIO reads.
Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>
---
fs/iomap/direct-io.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 23837926c0c5..d1c159bd3854 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -468,9 +468,18 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
flags |= IOMAP_NOWAIT;
}
+ /*
+ * Call inode_dio_begin() before we write out and wait for writeback to
+ * complete. This may be needed by some filesystems to prevent race
+ * like stale data exposure by DIO reads.
+ */
+ inode_dio_begin(inode);
+ /* So that i_dio_count is incremented before below operation */
+ smp_mb__after_atomic();
+
ret = filemap_write_and_wait_range(mapping, pos, end);
if (ret)
- goto out_free_dio;
+ goto out_end_dio;
/*
* Try to invalidate cache pages for the range we're direct
@@ -488,11 +497,9 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
!inode->i_sb->s_dio_done_wq) {
ret = sb_init_dio_done_wq(inode->i_sb);
if (ret < 0)
- goto out_free_dio;
+ goto out_end_dio;
}
- inode_dio_begin(inode);
-
blk_start_plug(&plug);
do {
ret = iomap_apply(inode, pos, count, flags, ops, dio,
@@ -568,6 +575,8 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
return iomap_dio_complete(dio);
+out_end_dio:
+ inode_dio_end(inode);
out_free_dio:
kfree(dio);
return ret;
--
2.21.0
next prev parent reply other threads:[~2020-01-13 11:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-13 11:04 [RFC 0/2] ext4: Fix stale data read exposure problem with DIO read/page_mkwrite Ritesh Harjani
2020-01-13 11:04 ` Ritesh Harjani [this message]
2020-01-13 21:51 ` [RFC 1/2] iomap: direct-io: Move inode_dio_begin before filemap_write_and_wait_range Darrick J. Wong
2020-01-14 9:05 ` Jan Kara
2020-01-14 16:38 ` Christoph Hellwig
2020-01-15 9:19 ` Jan Kara
2020-01-15 14:56 ` Christoph Hellwig
2020-01-14 9:12 ` Jan Kara
2020-01-14 16:37 ` Christoph Hellwig
2020-01-14 17:19 ` Jan Kara
2020-01-14 18:27 ` Christoph Hellwig
2020-01-15 9:08 ` Jan Kara
2020-01-13 11:04 ` [RFC 2/2] ext4: Fix stale data read issue with DIO read & ext4_page_mkwrite path Ritesh Harjani
2020-01-14 9:47 ` Jan Kara
2020-01-14 22:25 ` Ritesh Harjani
2020-01-14 16:39 ` [RFC 0/2] ext4: Fix stale data read exposure problem with DIO read/page_mkwrite Christoph Hellwig
2020-01-14 22:33 ` Ritesh Harjani
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=27607a16327fe9664f32d09abe565af0d1ae56c9.1578907891.git.riteshh@linux.ibm.com \
--to=riteshh@linux.ibm.com \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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).