Skip to content

Commit 1bdd3db

Browse files
committed
Merge tag 'io_uring-20190323' of git://git.kernel.dk/linux-block
Pull io_uring fixes and improvements from Jens Axboe: "The first five in this series are heavily inspired by the work Al did on the aio side to fix the races there. The last two re-introduce a feature that was in io_uring before it got merged, but which I pulled since we didn't have a good way to have BVEC iters that already have a stable reference. These aren't necessarily related to block, it's just how io_uring pins fixed buffers" * tag 'io_uring-20190323' of git://git.kernel.dk/linux-block: block: add BIO_NO_PAGE_REF flag iov_iter: add ITER_BVEC_FLAG_NO_REF flag io_uring: mark me as the maintainer io_uring: retry bulk slab allocs as single allocs io_uring: fix poll races io_uring: fix fget/fput handling io_uring: add prepped flag io_uring: make io_read/write return an integer io_uring: use regular request ref counts
2 parents 2335cbe + 399254a commit 1bdd3db

File tree

7 files changed

+284
-257
lines changed

7 files changed

+284
-257
lines changed

MAINTAINERS

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8096,6 +8096,16 @@ F: include/linux/iommu.h
80968096
F: include/linux/of_iommu.h
80978097
F: include/linux/iova.h
80988098

8099+
IO_URING
8100+
M: Jens Axboe <axboe@kernel.dk>
8101+
L: linux-block@vger.kernel.org
8102+
L: linux-fsdevel@vger.kernel.org
8103+
T: git git://git.kernel.dk/linux-block
8104+
T: git git://git.kernel.dk/liburing
8105+
S: Maintained
8106+
F: fs/io_uring.c
8107+
F: include/uapi/linux/io_uring.h
8108+
80998109
IP MASQUERADING
81008110
M: Juanjo Ciarlante <jjciarla@raiz.uncu.edu.ar>
81018111
S: Maintained

block/bio.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -849,20 +849,14 @@ static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter)
849849
size = bio_add_page(bio, bv->bv_page, len,
850850
bv->bv_offset + iter->iov_offset);
851851
if (size == len) {
852-
struct page *page;
853-
int i;
852+
if (!bio_flagged(bio, BIO_NO_PAGE_REF)) {
853+
struct page *page;
854+
int i;
855+
856+
mp_bvec_for_each_page(page, bv, i)
857+
get_page(page);
858+
}
854859

855-
/*
856-
* For the normal O_DIRECT case, we could skip grabbing this
857-
* reference and then not have to put them again when IO
858-
* completes. But this breaks some in-kernel users, like
859-
* splicing to/from a loop device, where we release the pipe
860-
* pages unconditionally. If we can fix that case, we can
861-
* get rid of the get here and the need to call
862-
* bio_release_pages() at IO completion time.
863-
*/
864-
mp_bvec_for_each_page(page, bv, i)
865-
get_page(page);
866860
iov_iter_advance(iter, size);
867861
return 0;
868862
}
@@ -925,10 +919,12 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
925919
* This takes either an iterator pointing to user memory, or one pointing to
926920
* kernel pages (BVEC iterator). If we're adding user pages, we pin them and
927921
* map them into the kernel. On IO completion, the caller should put those
928-
* pages. For now, when adding kernel pages, we still grab a reference to the
929-
* page. This isn't strictly needed for the common case, but some call paths
930-
* end up releasing pages from eg a pipe and we can't easily control these.
931-
* See comment in __bio_iov_bvec_add_pages().
922+
* pages. If we're adding kernel pages, and the caller told us it's safe to
923+
* do so, we just have to add the pages to the bio directly. We don't grab an
924+
* extra reference to those pages (the user should already have that), and we
925+
* don't put the page on IO completion. The caller needs to check if the bio is
926+
* flagged BIO_NO_PAGE_REF on IO completion. If it isn't, then pages should be
927+
* released.
932928
*
933929
* The function tries, but does not guarantee, to pin as many pages as
934930
* fit into the bio, or are requested in *iter, whatever is smaller. If
@@ -940,6 +936,13 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
940936
const bool is_bvec = iov_iter_is_bvec(iter);
941937
unsigned short orig_vcnt = bio->bi_vcnt;
942938

939+
/*
940+
* If this is a BVEC iter, then the pages are kernel pages. Don't
941+
* release them on IO completion, if the caller asked us to.
942+
*/
943+
if (is_bvec && iov_iter_bvec_no_ref(iter))
944+
bio_set_flag(bio, BIO_NO_PAGE_REF);
945+
943946
do {
944947
int ret;
945948

@@ -1696,7 +1699,8 @@ static void bio_dirty_fn(struct work_struct *work)
16961699
next = bio->bi_private;
16971700

16981701
bio_set_pages_dirty(bio);
1699-
bio_release_pages(bio);
1702+
if (!bio_flagged(bio, BIO_NO_PAGE_REF))
1703+
bio_release_pages(bio);
17001704
bio_put(bio);
17011705
}
17021706
}
@@ -1713,7 +1717,8 @@ void bio_check_pages_dirty(struct bio *bio)
17131717
goto defer;
17141718
}
17151719

1716-
bio_release_pages(bio);
1720+
if (!bio_flagged(bio, BIO_NO_PAGE_REF))
1721+
bio_release_pages(bio);
17171722
bio_put(bio);
17181723
return;
17191724
defer:

fs/block_dev.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,14 @@ static void blkdev_bio_end_io(struct bio *bio)
336336
if (should_dirty) {
337337
bio_check_pages_dirty(bio);
338338
} else {
339-
struct bio_vec *bvec;
340-
int i;
341-
struct bvec_iter_all iter_all;
339+
if (!bio_flagged(bio, BIO_NO_PAGE_REF)) {
340+
struct bvec_iter_all iter_all;
341+
struct bio_vec *bvec;
342+
int i;
342343

343-
bio_for_each_segment_all(bvec, bio, i, iter_all)
344-
put_page(bvec->bv_page);
344+
bio_for_each_segment_all(bvec, bio, i, iter_all)
345+
put_page(bvec->bv_page);
346+
}
345347
bio_put(bio);
346348
}
347349
}

0 commit comments

Comments
 (0)