public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin Wilck <mwilck@suse.com>
To: Jens Axboe <axboe@kernel.dk>, Jan Kara <jack@suse.com>,
	Ming Lei <ming.lei@redhat.com>, Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>,
	Johannes Thumshirn <jthumshirn@suse.de>,
	Kent Overstreet <kent.overstreet@gmail.com>,
	linux-block@vger.kernel.org, Martin Wilck <mwilck@suse.com>
Subject: [PATCH v4 4/4] blkdev: __blkdev_direct_IO_simple: make sure to fill up the bio
Date: Fri, 20 Jul 2018 15:05:52 +0200	[thread overview]
Message-ID: <20180720130552.21432-5-mwilck@suse.com> (raw)
In-Reply-To: <20180720130552.21432-1-mwilck@suse.com>

bio_iov_iter_get_pages() returns only pages for a single non-empty
segment of the input iov_iter's iovec. This may be less than the
number of pages __blkdev_direct_IO_simple() is supposed to process.
Call the new bio_iov_iter_get_all_pages() helper instead to avoid
short reads or writes. Otherwise, __generic_file_write_iter() falls
back to buffered writes, which has been observed to cause data
corruption in certain workloads.

Fixes: 72ecad22d9f1 ("block: support a full bio worth of IO for
 simplified bdev direct-io")
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 fs/block_dev.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index aba2541..010708a 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -219,9 +219,16 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
 	bio.bi_end_io = blkdev_bio_end_io_simple;
 	bio.bi_ioprio = iocb->ki_ioprio;
 
-	ret = bio_iov_iter_get_pages(&bio, iter);
+	ret = bio_iov_iter_get_all_pages(&bio, iter);
 	if (unlikely(ret))
 		goto out;
+
+	/*
+	 * Our bi_io_vec should be big enough to hold all data from the
+	 * iov_iter, as this has been checked before calling this function.
+	 */
+	WARN_ON_ONCE(iov_iter_count(iter));
+
 	ret = bio.bi_iter.bi_size;
 
 	if (iov_iter_rw(iter) == READ) {
-- 
2.17.1

      parent reply	other threads:[~2018-07-20 13:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-20 13:05 [PATCH v4 0/4] Fix silent data corruption in blkdev_direct_IO() Martin Wilck
2018-07-20 13:05 ` [PATCH v4 1/4] block: bio_iov_iter_get_pages: fix size of last iovec Martin Wilck
2018-07-20 13:05 ` [PATCH v4 2/4] blkdev: __blkdev_direct_IO_simple: fix leak in error case Martin Wilck
2018-07-20 15:09   ` Christoph Hellwig
2018-07-20 13:05 ` [PATCH v4 3/4] block: add bio_iov_iter_get_all_pages() helper Martin Wilck
2018-07-20 15:11   ` Christoph Hellwig
2018-07-20 15:29     ` Martin Wilck
2018-07-20 16:16   ` Ming Lei
2018-07-20 16:54     ` Martin Wilck
2018-07-20 23:48       ` Ming Lei
2018-07-20 13:05 ` Martin Wilck [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=20180720130552.21432-5-mwilck@suse.com \
    --to=mwilck@suse.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jack@suse.com \
    --cc=jthumshirn@suse.de \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.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