Skip to content

Commit ba56b63

Browse files
committed
io_uring/kbuf: move pinning of provided buffer ring into helper
In preparation for allowing the kernel to allocate the provided buffer rings and have the application mmap it instead, abstract out the current method of pinning and mapping the user allocated ring. No functional changes intended in this patch. Acked-by: Helge Deller <deller@gmx.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d808459 commit ba56b63

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

io_uring/kbuf.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,32 @@ int io_provide_buffers(struct io_kiocb *req, unsigned int issue_flags)
463463
return IOU_OK;
464464
}
465465

466-
int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
466+
static int io_pin_pbuf_ring(struct io_uring_buf_reg *reg,
467+
struct io_buffer_list *bl)
467468
{
468469
struct io_uring_buf_ring *br;
469-
struct io_uring_buf_reg reg;
470-
struct io_buffer_list *bl, *free_bl = NULL;
471470
struct page **pages;
472471
int nr_pages;
473472

473+
pages = io_pin_pages(reg->ring_addr,
474+
flex_array_size(br, bufs, reg->ring_entries),
475+
&nr_pages);
476+
if (IS_ERR(pages))
477+
return PTR_ERR(pages);
478+
479+
br = page_address(pages[0]);
480+
bl->buf_pages = pages;
481+
bl->buf_nr_pages = nr_pages;
482+
bl->buf_ring = br;
483+
return 0;
484+
}
485+
486+
int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
487+
{
488+
struct io_uring_buf_reg reg;
489+
struct io_buffer_list *bl, *free_bl = NULL;
490+
int ret;
491+
474492
if (copy_from_user(&reg, arg, sizeof(reg)))
475493
return -EFAULT;
476494

@@ -504,20 +522,15 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
504522
return -ENOMEM;
505523
}
506524

507-
pages = io_pin_pages(reg.ring_addr,
508-
flex_array_size(br, bufs, reg.ring_entries),
509-
&nr_pages);
510-
if (IS_ERR(pages)) {
525+
ret = io_pin_pbuf_ring(&reg, bl);
526+
if (ret) {
511527
kfree(free_bl);
512-
return PTR_ERR(pages);
528+
return ret;
513529
}
514530

515-
br = page_address(pages[0]);
516-
bl->buf_pages = pages;
517-
bl->buf_nr_pages = nr_pages;
518531
bl->nr_entries = reg.ring_entries;
519-
bl->buf_ring = br;
520532
bl->mask = reg.ring_entries - 1;
533+
521534
io_buffer_add_list(ctx, bl, reg.bgid);
522535
return 0;
523536
}

0 commit comments

Comments
 (0)