summaryrefslogtreecommitdiffstats
path: root/fs/io_uring.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2021-04-11 02:46:35 +0200
committerJens Axboe <axboe@kernel.dk>2021-04-12 17:32:55 +0200
commit7f61a1e9ef511660d66ea926b5899559fe94b1d0 (patch)
tree4c667fe774fff42272e23fd7ca4a270c67c90687 /fs/io_uring.c
parentio_uring: simplify io_rsrc_data refcounting (diff)
downloadlinux-7f61a1e9ef511660d66ea926b5899559fe94b1d0.tar.xz
linux-7f61a1e9ef511660d66ea926b5899559fe94b1d0.zip
io_uring: add buffer unmap helper
Add a helper for unmapping registered buffers, better than double indexing and will be reused in the future. Suggested-by: Bijan Mottahedeh <bijan.mottahedeh@oracle.com> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/66cbc6ea863be865bac7b7080ed6a3d5c542b71f.1618101759.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to '')
-rw-r--r--fs/io_uring.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 1eb815660fe8..e9a2f8f39eb3 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8093,25 +8093,27 @@ static unsigned long rings_size(unsigned sq_entries, unsigned cq_entries,
return off;
}
+static void io_buffer_unmap(struct io_ring_ctx *ctx, struct io_mapped_ubuf *imu)
+{
+ unsigned int i;
+
+ for (i = 0; i < imu->nr_bvecs; i++)
+ unpin_user_page(imu->bvec[i].bv_page);
+ if (imu->acct_pages)
+ io_unaccount_mem(ctx, imu->acct_pages);
+ kvfree(imu->bvec);
+ imu->nr_bvecs = 0;
+}
+
static int io_sqe_buffers_unregister(struct io_ring_ctx *ctx)
{
- int i, j;
+ unsigned int i;
if (!ctx->user_bufs)
return -ENXIO;
- for (i = 0; i < ctx->nr_user_bufs; i++) {
- struct io_mapped_ubuf *imu = &ctx->user_bufs[i];
-
- for (j = 0; j < imu->nr_bvecs; j++)
- unpin_user_page(imu->bvec[j].bv_page);
-
- if (imu->acct_pages)
- io_unaccount_mem(ctx, imu->acct_pages);
- kvfree(imu->bvec);
- imu->nr_bvecs = 0;
- }
-
+ for (i = 0; i < ctx->nr_user_bufs; i++)
+ io_buffer_unmap(ctx, &ctx->user_bufs[i]);
kfree(ctx->user_bufs);
ctx->user_bufs = NULL;
ctx->nr_user_bufs = 0;