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>pull/1354/merge
parent
929dbbb699
commit
0f4b537363
|
|
@ -3480,7 +3480,7 @@ static int io_uring_sanitise_params(struct io_uring_params *p)
|
||||||
return 0;
|
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;
|
unsigned entries = p->sq_entries;
|
||||||
|
|
||||||
|
|
@ -3545,12 +3545,9 @@ int io_uring_fill_params(struct io_uring_params *p)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __cold int io_uring_create(struct io_uring_params *p,
|
int io_prepare_config(struct io_ctx_config *config)
|
||||||
struct io_uring_params __user *params)
|
|
||||||
{
|
{
|
||||||
struct io_ring_ctx *ctx;
|
struct io_uring_params *p = &config->p;
|
||||||
struct io_uring_task *tctx;
|
|
||||||
struct file *file;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = io_uring_sanitise_params(p);
|
ret = io_uring_sanitise_params(p);
|
||||||
|
|
@ -3558,7 +3555,22 @@ static __cold int io_uring_create(struct io_uring_params *p,
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = io_uring_fill_params(p);
|
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;
|
return ret;
|
||||||
|
|
||||||
ctx = io_ring_ctx_alloc(p);
|
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;
|
p->features = IORING_FEAT_FLAGS;
|
||||||
|
|
||||||
if (copy_to_user(params, p, sizeof(*p))) {
|
if (copy_to_user(config->uptr, p, sizeof(*p))) {
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
@ -3684,16 +3696,19 @@ err_fput:
|
||||||
*/
|
*/
|
||||||
static long io_uring_setup(u32 entries, struct io_uring_params __user *params)
|
static long io_uring_setup(u32 entries, struct io_uring_params __user *params)
|
||||||
{
|
{
|
||||||
struct io_uring_params p;
|
struct io_ctx_config config;
|
||||||
|
|
||||||
if (copy_from_user(&p, params, sizeof(p)))
|
memset(&config, 0, sizeof(config));
|
||||||
|
|
||||||
|
if (copy_from_user(&config.p, params, sizeof(config.p)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
if (!mem_is_zero(&p.resv, sizeof(p.resv)))
|
if (!mem_is_zero(&config.p.resv, sizeof(config.p.resv)))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
p.sq_entries = entries;
|
config.p.sq_entries = entries;
|
||||||
return io_uring_create(&p, params);
|
config.uptr = params;
|
||||||
|
return io_uring_create(&config);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int io_uring_allowed(void)
|
static inline int io_uring_allowed(void)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,11 @@
|
||||||
#include <trace/events/io_uring.h>
|
#include <trace/events/io_uring.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct io_ctx_config {
|
||||||
|
struct io_uring_params p;
|
||||||
|
struct io_uring_params __user *uptr;
|
||||||
|
};
|
||||||
|
|
||||||
#define IORING_FEAT_FLAGS (IORING_FEAT_SINGLE_MMAP |\
|
#define IORING_FEAT_FLAGS (IORING_FEAT_SINGLE_MMAP |\
|
||||||
IORING_FEAT_NODROP |\
|
IORING_FEAT_NODROP |\
|
||||||
IORING_FEAT_SUBMIT_STABLE |\
|
IORING_FEAT_SUBMIT_STABLE |\
|
||||||
|
|
@ -136,7 +141,8 @@ static inline bool io_should_wake(struct io_wait_queue *iowq)
|
||||||
|
|
||||||
unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
|
unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
|
||||||
unsigned int cq_entries, size_t *sq_offset);
|
unsigned int cq_entries, size_t *sq_offset);
|
||||||
int io_uring_fill_params(struct io_uring_params *p);
|
int io_prepare_config(struct io_ctx_config *config);
|
||||||
|
|
||||||
bool io_cqe_cache_refill(struct io_ring_ctx *ctx, bool overflow, bool cqe32);
|
bool io_cqe_cache_refill(struct io_ring_ctx *ctx, bool overflow, bool cqe32);
|
||||||
int io_run_task_work_sig(struct io_ring_ctx *ctx);
|
int io_run_task_work_sig(struct io_ring_ctx *ctx);
|
||||||
int io_run_local_work(struct io_ring_ctx *ctx, int min_events, int max_events);
|
int io_run_local_work(struct io_ring_ctx *ctx, int min_events, int max_events);
|
||||||
|
|
|
||||||
|
|
@ -398,13 +398,16 @@ static void io_register_free_rings(struct io_ring_ctx *ctx,
|
||||||
|
|
||||||
static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
|
static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
|
||||||
{
|
{
|
||||||
|
struct io_ctx_config config;
|
||||||
struct io_uring_region_desc rd;
|
struct io_uring_region_desc rd;
|
||||||
struct io_ring_ctx_rings o = { }, n = { }, *to_free = NULL;
|
struct io_ring_ctx_rings o = { }, n = { }, *to_free = NULL;
|
||||||
size_t size, sq_array_offset;
|
size_t size, sq_array_offset;
|
||||||
unsigned i, tail, old_head;
|
unsigned i, tail, old_head;
|
||||||
struct io_uring_params __p, *p = &__p;
|
struct io_uring_params *p = &config.p;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
memset(&config, 0, sizeof(config));
|
||||||
|
|
||||||
/* limited to DEFER_TASKRUN for now */
|
/* limited to DEFER_TASKRUN for now */
|
||||||
if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN))
|
if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
@ -416,7 +419,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
|
||||||
/* properties that are always inherited */
|
/* properties that are always inherited */
|
||||||
p->flags |= (ctx->flags & COPY_FLAGS);
|
p->flags |= (ctx->flags & COPY_FLAGS);
|
||||||
|
|
||||||
ret = io_uring_fill_params(p);
|
ret = io_prepare_config(&config);
|
||||||
if (unlikely(ret))
|
if (unlikely(ret))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue