Skip to content

Commit 929dbbb

Browse files
isilenceaxboe
authored andcommitted
io_uring: convert params to pointer in ring reisze
The parameters in io_register_resize_rings() will be moved into another structure in a later patch. In preparation to that, convert the params variable it to a pointer, but still store the data on stack. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 94cd832 commit 929dbbb

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

io_uring/register.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -402,33 +402,33 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
402402
struct io_ring_ctx_rings o = { }, n = { }, *to_free = NULL;
403403
size_t size, sq_array_offset;
404404
unsigned i, tail, old_head;
405-
struct io_uring_params p;
405+
struct io_uring_params __p, *p = &__p;
406406
int ret;
407407

408408
/* limited to DEFER_TASKRUN for now */
409409
if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN))
410410
return -EINVAL;
411-
if (copy_from_user(&p, arg, sizeof(p)))
411+
if (copy_from_user(p, arg, sizeof(*p)))
412412
return -EFAULT;
413-
if (p.flags & ~RESIZE_FLAGS)
413+
if (p->flags & ~RESIZE_FLAGS)
414414
return -EINVAL;
415415

416416
/* properties that are always inherited */
417-
p.flags |= (ctx->flags & COPY_FLAGS);
417+
p->flags |= (ctx->flags & COPY_FLAGS);
418418

419-
ret = io_uring_fill_params(&p);
419+
ret = io_uring_fill_params(p);
420420
if (unlikely(ret))
421421
return ret;
422422

423-
size = rings_size(p.flags, p.sq_entries, p.cq_entries,
423+
size = rings_size(p->flags, p->sq_entries, p->cq_entries,
424424
&sq_array_offset);
425425
if (size == SIZE_MAX)
426426
return -EOVERFLOW;
427427

428428
memset(&rd, 0, sizeof(rd));
429429
rd.size = PAGE_ALIGN(size);
430-
if (p.flags & IORING_SETUP_NO_MMAP) {
431-
rd.user_addr = p.cq_off.user_addr;
430+
if (p->flags & IORING_SETUP_NO_MMAP) {
431+
rd.user_addr = p->cq_off.user_addr;
432432
rd.flags |= IORING_MEM_REGION_TYPE_USER;
433433
}
434434
ret = io_create_region(ctx, &n.ring_region, &rd, IORING_OFF_CQ_RING);
@@ -445,29 +445,29 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
445445
* intent... Use read/write once helpers from here on to indicate the
446446
* shared nature of it.
447447
*/
448-
WRITE_ONCE(n.rings->sq_ring_mask, p.sq_entries - 1);
449-
WRITE_ONCE(n.rings->cq_ring_mask, p.cq_entries - 1);
450-
WRITE_ONCE(n.rings->sq_ring_entries, p.sq_entries);
451-
WRITE_ONCE(n.rings->cq_ring_entries, p.cq_entries);
448+
WRITE_ONCE(n.rings->sq_ring_mask, p->sq_entries - 1);
449+
WRITE_ONCE(n.rings->cq_ring_mask, p->cq_entries - 1);
450+
WRITE_ONCE(n.rings->sq_ring_entries, p->sq_entries);
451+
WRITE_ONCE(n.rings->cq_ring_entries, p->cq_entries);
452452

453-
if (copy_to_user(arg, &p, sizeof(p))) {
453+
if (copy_to_user(arg, p, sizeof(*p))) {
454454
io_register_free_rings(ctx, &n);
455455
return -EFAULT;
456456
}
457457

458-
if (p.flags & IORING_SETUP_SQE128)
459-
size = array_size(2 * sizeof(struct io_uring_sqe), p.sq_entries);
458+
if (p->flags & IORING_SETUP_SQE128)
459+
size = array_size(2 * sizeof(struct io_uring_sqe), p->sq_entries);
460460
else
461-
size = array_size(sizeof(struct io_uring_sqe), p.sq_entries);
461+
size = array_size(sizeof(struct io_uring_sqe), p->sq_entries);
462462
if (size == SIZE_MAX) {
463463
io_register_free_rings(ctx, &n);
464464
return -EOVERFLOW;
465465
}
466466

467467
memset(&rd, 0, sizeof(rd));
468468
rd.size = PAGE_ALIGN(size);
469-
if (p.flags & IORING_SETUP_NO_MMAP) {
470-
rd.user_addr = p.sq_off.user_addr;
469+
if (p->flags & IORING_SETUP_NO_MMAP) {
470+
rd.user_addr = p->sq_off.user_addr;
471471
rd.flags |= IORING_MEM_REGION_TYPE_USER;
472472
}
473473
ret = io_create_region(ctx, &n.sq_region, &rd, IORING_OFF_SQES);
@@ -508,11 +508,11 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
508508
*/
509509
tail = READ_ONCE(o.rings->sq.tail);
510510
old_head = READ_ONCE(o.rings->sq.head);
511-
if (tail - old_head > p.sq_entries)
511+
if (tail - old_head > p->sq_entries)
512512
goto overflow;
513513
for (i = old_head; i < tail; i++) {
514514
unsigned src_head = i & (ctx->sq_entries - 1);
515-
unsigned dst_head = i & (p.sq_entries - 1);
515+
unsigned dst_head = i & (p->sq_entries - 1);
516516

517517
n.sq_sqes[dst_head] = o.sq_sqes[src_head];
518518
}
@@ -521,7 +521,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
521521

522522
tail = READ_ONCE(o.rings->cq.tail);
523523
old_head = READ_ONCE(o.rings->cq.head);
524-
if (tail - old_head > p.cq_entries) {
524+
if (tail - old_head > p->cq_entries) {
525525
overflow:
526526
/* restore old rings, and return -EOVERFLOW via cleanup path */
527527
ctx->rings = o.rings;
@@ -532,7 +532,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
532532
}
533533
for (i = old_head; i < tail; i++) {
534534
unsigned src_head = i & (ctx->cq_entries - 1);
535-
unsigned dst_head = i & (p.cq_entries - 1);
535+
unsigned dst_head = i & (p->cq_entries - 1);
536536

537537
n.rings->cqes[dst_head] = o.rings->cqes[src_head];
538538
}
@@ -550,8 +550,8 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
550550
if (!(ctx->flags & IORING_SETUP_NO_SQARRAY))
551551
ctx->sq_array = (u32 *)((char *)n.rings + sq_array_offset);
552552

553-
ctx->sq_entries = p.sq_entries;
554-
ctx->cq_entries = p.cq_entries;
553+
ctx->sq_entries = p->sq_entries;
554+
ctx->cq_entries = p->cq_entries;
555555

556556
ctx->rings = n.rings;
557557
ctx->sq_sqes = n.sq_sqes;

0 commit comments

Comments
 (0)