Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring: introduce struct io_ctx_config

There will be more information needed during ctx setup, and instead of
passing a handful of pointers around, wrap them all into a new
structure. Add a helper for encapsulating all configuration checks and
preparation, that's also reused for ring resizing.

Note, it indirectly adds a io_uring_sanitise_params() check to ring
resizing, which is a good thing.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
0f4b5373 929dbbb6

+40 -16
+28 -13
io_uring/io_uring.c
··· 3480 3480 return 0; 3481 3481 } 3482 3482 3483 - int io_uring_fill_params(struct io_uring_params *p) 3483 + static int io_uring_fill_params(struct io_uring_params *p) 3484 3484 { 3485 3485 unsigned entries = p->sq_entries; 3486 3486 ··· 3545 3545 return 0; 3546 3546 } 3547 3547 3548 - static __cold int io_uring_create(struct io_uring_params *p, 3549 - struct io_uring_params __user *params) 3548 + int io_prepare_config(struct io_ctx_config *config) 3550 3549 { 3551 - struct io_ring_ctx *ctx; 3552 - struct io_uring_task *tctx; 3553 - struct file *file; 3550 + struct io_uring_params *p = &config->p; 3554 3551 int ret; 3555 3552 3556 3553 ret = io_uring_sanitise_params(p); ··· 3555 3558 return ret; 3556 3559 3557 3560 ret = io_uring_fill_params(p); 3558 - if (unlikely(ret)) 3561 + if (ret) 3562 + return ret; 3563 + 3564 + return 0; 3565 + } 3566 + 3567 + static __cold int io_uring_create(struct io_ctx_config *config) 3568 + { 3569 + struct io_uring_params *p = &config->p; 3570 + struct io_ring_ctx *ctx; 3571 + struct io_uring_task *tctx; 3572 + struct file *file; 3573 + int ret; 3574 + 3575 + ret = io_prepare_config(config); 3576 + if (ret) 3559 3577 return ret; 3560 3578 3561 3579 ctx = io_ring_ctx_alloc(p); ··· 3643 3631 3644 3632 p->features = IORING_FEAT_FLAGS; 3645 3633 3646 - if (copy_to_user(params, p, sizeof(*p))) { 3634 + if (copy_to_user(config->uptr, p, sizeof(*p))) { 3647 3635 ret = -EFAULT; 3648 3636 goto err; 3649 3637 } ··· 3696 3684 */ 3697 3685 static long io_uring_setup(u32 entries, struct io_uring_params __user *params) 3698 3686 { 3699 - struct io_uring_params p; 3687 + struct io_ctx_config config; 3700 3688 3701 - if (copy_from_user(&p, params, sizeof(p))) 3689 + memset(&config, 0, sizeof(config)); 3690 + 3691 + if (copy_from_user(&config.p, params, sizeof(config.p))) 3702 3692 return -EFAULT; 3703 3693 3704 - if (!mem_is_zero(&p.resv, sizeof(p.resv))) 3694 + if (!mem_is_zero(&config.p.resv, sizeof(config.p.resv))) 3705 3695 return -EINVAL; 3706 3696 3707 - p.sq_entries = entries; 3708 - return io_uring_create(&p, params); 3697 + config.p.sq_entries = entries; 3698 + config.uptr = params; 3699 + return io_uring_create(&config); 3709 3700 } 3710 3701 3711 3702 static inline int io_uring_allowed(void)
+7 -1
io_uring/io_uring.h
··· 17 17 #include <trace/events/io_uring.h> 18 18 #endif 19 19 20 + struct io_ctx_config { 21 + struct io_uring_params p; 22 + struct io_uring_params __user *uptr; 23 + }; 24 + 20 25 #define IORING_FEAT_FLAGS (IORING_FEAT_SINGLE_MMAP |\ 21 26 IORING_FEAT_NODROP |\ 22 27 IORING_FEAT_SUBMIT_STABLE |\ ··· 141 136 142 137 unsigned long rings_size(unsigned int flags, unsigned int sq_entries, 143 138 unsigned int cq_entries, size_t *sq_offset); 144 - int io_uring_fill_params(struct io_uring_params *p); 139 + int io_prepare_config(struct io_ctx_config *config); 140 + 145 141 bool io_cqe_cache_refill(struct io_ring_ctx *ctx, bool overflow, bool cqe32); 146 142 int io_run_task_work_sig(struct io_ring_ctx *ctx); 147 143 int io_run_local_work(struct io_ring_ctx *ctx, int min_events, int max_events);
+5 -2
io_uring/register.c
··· 398 398 399 399 static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg) 400 400 { 401 + struct io_ctx_config config; 401 402 struct io_uring_region_desc rd; 402 403 struct io_ring_ctx_rings o = { }, n = { }, *to_free = NULL; 403 404 size_t size, sq_array_offset; 404 405 unsigned i, tail, old_head; 405 - struct io_uring_params __p, *p = &__p; 406 + struct io_uring_params *p = &config.p; 406 407 int ret; 408 + 409 + memset(&config, 0, sizeof(config)); 407 410 408 411 /* limited to DEFER_TASKRUN for now */ 409 412 if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN)) ··· 419 416 /* properties that are always inherited */ 420 417 p->flags |= (ctx->flags & COPY_FLAGS); 421 418 422 - ret = io_uring_fill_params(p); 419 + ret = io_prepare_config(&config); 423 420 if (unlikely(ret)) 424 421 return ret; 425 422