From: Dave Chinner <david@fromorbit.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org,
linux-block@vger.kernel.org, linux-arch@vger.kernel.org,
hch@lst.de, jmoyer@redhat.com, avi@scylladb.com
Subject: Re: [PATCH 12/15] io_uring: add support for pre-mapped user IO buffers
Date: Thu, 17 Jan 2019 07:53:38 +1100 [thread overview]
Message-ID: <20190116205338.GQ4205@dastard> (raw)
In-Reply-To: <20190116175003.17880-13-axboe@kernel.dk>
On Wed, Jan 16, 2019 at 10:50:00AM -0700, Jens Axboe wrote:
> If we have fixed user buffers, we can map them into the kernel when we
> setup the io_context. That avoids the need to do get_user_pages() for
> each and every IO.
.....
> + return -ENOMEM;
> + } while (atomic_long_cmpxchg(&ctx->user->locked_vm, cur_pages,
> + new_pages) != cur_pages);
> +
> + return 0;
> +}
> +
> +static int io_sqe_buffer_unregister(struct io_ring_ctx *ctx)
> +{
> + int i, j;
> +
> + if (!ctx->user_bufs)
> + return -EINVAL;
> +
> + for (i = 0; i < ctx->sq_entries; i++) {
> + struct io_mapped_ubuf *imu = &ctx->user_bufs[i];
> +
> + for (j = 0; j < imu->nr_bvecs; j++) {
> + set_page_dirty_lock(imu->bvec[j].bv_page);
> + put_page(imu->bvec[j].bv_page);
> + }
Hmmm, so we call set_page_dirty() when the gup reference is dropped...
.....
> +static int io_sqe_buffer_register(struct io_ring_ctx *ctx, void __user *arg,
> + unsigned nr_args)
> +{
.....
> + down_write(¤t->mm->mmap_sem);
> + pret = get_user_pages_longterm(ubuf, nr_pages, FOLL_WRITE,
> + pages, NULL);
> + up_write(¤t->mm->mmap_sem);
Thought so. This has the same problem as RDMA w.r.t. using
file-backed mappings for the user buffer. It is not synchronised
against truncate, hole punches, async page writeback cleaning the
page, etc, and so can lead to data corruption and/or kernel panics.
It also can't be used with DAX because the above problems are
actually a user-after-free of storage space, not just a dangling
page reference that can be cleaned up after the gup pin is dropped.
Perhaps, at least until we solve the GUP problems w.r.t. file backed
pages and/or add and require file layout leases for these reference,
we should error out if the user buffer pages are file-backed
mappings?
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2019-01-16 20:53 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-16 17:49 [PATCHSET v5] io_uring IO interface Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 01/15] fs: add an iopoll method to struct file_operations Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 02/15] block: wire up block device iopoll method Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 03/15] block: add bio_set_polled() helper Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 04/15] iomap: wire up the iopoll method Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 05/15] Add io_uring IO interface Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-17 12:02 ` Roman Penyaev
2019-01-17 12:02 ` Roman Penyaev
2019-01-17 13:54 ` Jens Axboe
2019-01-17 13:54 ` Jens Axboe
2019-01-17 14:34 ` Roman Penyaev
2019-01-17 14:34 ` Roman Penyaev
2019-01-17 14:54 ` Jens Axboe
2019-01-17 14:54 ` Jens Axboe
2019-01-17 15:19 ` Roman Penyaev
2019-01-17 15:19 ` Roman Penyaev
2019-01-17 12:48 ` Roman Penyaev
2019-01-17 12:48 ` Roman Penyaev
2019-01-17 14:01 ` Jens Axboe
2019-01-17 14:01 ` Jens Axboe
2019-01-17 20:03 ` Jeff Moyer
2019-01-17 20:03 ` Jeff Moyer
2019-01-17 20:09 ` Jens Axboe
2019-01-17 20:09 ` Jens Axboe
2019-01-17 20:14 ` Jens Axboe
2019-01-17 20:14 ` Jens Axboe
2019-01-17 20:50 ` Jeff Moyer
2019-01-17 20:50 ` Jeff Moyer
2019-01-17 20:53 ` Jens Axboe
2019-01-17 20:53 ` Jens Axboe
2019-01-17 21:02 ` Jeff Moyer
2019-01-17 21:02 ` Jeff Moyer
2019-01-17 21:17 ` Jens Axboe
2019-01-17 21:21 ` Jeff Moyer
2019-01-17 21:27 ` Jens Axboe
2019-01-18 8:23 ` Roman Penyaev
2019-01-16 17:49 ` [PATCH 06/15] io_uring: add fsync support Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 07/15] io_uring: support for IO polling Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 08/15] fs: add fget_many() and fput_many() Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 09/15] io_uring: use fget/fput_many() for file references Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 10/15] io_uring: batch io_kiocb allocation Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:49 ` [PATCH 11/15] block: implement bio helper to add iter bvec pages to bio Jens Axboe
2019-01-16 17:49 ` Jens Axboe
2019-01-16 17:50 ` [PATCH 12/15] io_uring: add support for pre-mapped user IO buffers Jens Axboe
2019-01-16 17:50 ` Jens Axboe
2019-01-16 20:53 ` Dave Chinner [this message]
2019-01-16 21:20 ` Jens Axboe
2019-01-16 21:20 ` Jens Axboe
2019-01-16 22:09 ` Dave Chinner
2019-01-16 22:21 ` Jens Axboe
2019-01-16 22:21 ` Jens Axboe
2019-01-16 23:09 ` Dave Chinner
2019-01-16 23:17 ` Jens Axboe
2019-01-16 23:17 ` Jens Axboe
2019-01-16 22:13 ` Jens Axboe
2019-01-16 22:13 ` Jens Axboe
2019-01-16 17:50 ` [PATCH 13/15] io_uring: add submission polling Jens Axboe
2019-01-16 17:50 ` Jens Axboe
2019-01-16 17:50 ` [PATCH 14/15] io_uring: add file registration Jens Axboe
2019-01-16 17:50 ` Jens Axboe
2019-01-16 17:50 ` [PATCH 15/15] io_uring: add io_uring_event cache hit information Jens Axboe
2019-01-16 17:50 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2019-01-10 2:43 [PATCHSET v2] io_uring IO interface Jens Axboe
2019-01-10 2:44 ` [PATCH 12/15] io_uring: add support for pre-mapped user IO buffers Jens Axboe
2019-01-10 2:44 ` Jens Axboe
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=20190116205338.GQ4205@dastard \
--to=david@fromorbit.com \
--cc=avi@scylladb.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=jmoyer@redhat.com \
--cc=linux-aio@kvack.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@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).