diff options
| author | Pavel Begunkov <asml.silence@gmail.com> | 2025-11-12 12:45:56 +0000 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2025-11-13 07:27:34 -0700 |
| commit | 0f4b537363cb66c78e97bb58c26986af62856356 (patch) | |
| tree | 4a71d99f705e158c91cc4c6b6d42e0cb59202f6b /io_uring/io_uring.c | |
| parent | 929dbbb699110c9377da721ed7b44a660bb4ee01 (diff) | |
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>
Diffstat (limited to 'io_uring/io_uring.c')
| -rw-r--r-- | io_uring/io_uring.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index bd8dfa919b61..40dfb851d46b 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3480,7 +3480,7 @@ static int io_uring_sanitise_params(struct io_uring_params *p) return 0; } -int io_uring_fill_params(struct io_uring_params *p) +static int io_uring_fill_params(struct io_uring_params *p) { unsigned entries = p->sq_entries; @@ -3545,12 +3545,9 @@ int io_uring_fill_params(struct io_uring_params *p) return 0; } -static __cold int io_uring_create(struct io_uring_params *p, - struct io_uring_params __user *params) +int io_prepare_config(struct io_ctx_config *config) { - struct io_ring_ctx *ctx; - struct io_uring_task *tctx; - struct file *file; + struct io_uring_params *p = &config->p; int ret; ret = io_uring_sanitise_params(p); @@ -3558,7 +3555,22 @@ static __cold int io_uring_create(struct io_uring_params *p, return ret; ret = io_uring_fill_params(p); - if (unlikely(ret)) + if (ret) + return ret; + + return 0; +} + +static __cold int io_uring_create(struct io_ctx_config *config) +{ + struct io_uring_params *p = &config->p; + struct io_ring_ctx *ctx; + struct io_uring_task *tctx; + struct file *file; + int ret; + + ret = io_prepare_config(config); + if (ret) return ret; ctx = io_ring_ctx_alloc(p); @@ -3631,7 +3643,7 @@ static __cold int io_uring_create(struct io_uring_params *p, p->features = IORING_FEAT_FLAGS; - if (copy_to_user(params, p, sizeof(*p))) { + if (copy_to_user(config->uptr, p, sizeof(*p))) { ret = -EFAULT; goto err; } @@ -3684,16 +3696,19 @@ err_fput: */ static long io_uring_setup(u32 entries, struct io_uring_params __user *params) { - struct io_uring_params p; + struct io_ctx_config config; + + memset(&config, 0, sizeof(config)); - if (copy_from_user(&p, params, sizeof(p))) + if (copy_from_user(&config.p, params, sizeof(config.p))) return -EFAULT; - if (!mem_is_zero(&p.resv, sizeof(p.resv))) + if (!mem_is_zero(&config.p.resv, sizeof(config.p.resv))) return -EINVAL; - p.sq_entries = entries; - return io_uring_create(&p, params); + config.p.sq_entries = entries; + config.uptr = params; + return io_uring_create(&config); } static inline int io_uring_allowed(void) |
