Re: [PATCHv2] io_uring: Support calling io_uring_register with a registered ring fd

From: Jens Axboe
Date: Thu Feb 16 2023 - 08:10:52 EST


On 2/16/23 5:05?AM, Josh Triplett wrote:
> On Thu, Feb 16, 2023 at 09:35:44AM +0000, Dylan Yudaken wrote:
>> On Tue, 2023-02-14 at 16:42 -0800, Josh Triplett wrote:
>>> @@ -4177,17 +4177,37 @@ SYSCALL_DEFINE4(io_uring_register, unsigned
>>> int, fd, unsigned int, opcode,
>>> struct io_ring_ctx *ctx;
>>> long ret = -EBADF;
>>> struct fd f;
>>> + bool use_registered_ring;
>>> +
>>> + use_registered_ring = !!(opcode &
>>> IORING_REGISTER_USE_REGISTERED_RING);
>>> + opcode &= ~IORING_REGISTER_USE_REGISTERED_RING;
>>>
>>> if (opcode >= IORING_REGISTER_LAST)
>>> return -EINVAL;
>>>
>>> - f = fdget(fd);
>>> - if (!f.file)
>>> - return -EBADF;
>>> + if (use_registered_ring) {
>>> + /*
>>> + * Ring fd has been registered via
>>> IORING_REGISTER_RING_FDS, we
>>> + * need only dereference our task private array to
>>> find it.
>>> + */
>>> + struct io_uring_task *tctx = current->io_uring;
>>>
>>> - ret = -EOPNOTSUPP;
>>> - if (!io_is_uring_fops(f.file))
>>> - goto out_fput;
>>> + if (unlikely(!tctx || fd >= IO_RINGFD_REG_MAX))
>>> + return -EINVAL;
>>> + fd = array_index_nospec(fd, IO_RINGFD_REG_MAX);
>>> + f.file = tctx->registered_rings[fd];
>>> + f.flags = 0;
>>> + if (unlikely(!f.file))
>>> + return -EBADF;
>>> + opcode &= ~IORING_REGISTER_USE_REGISTERED_RING;
>>
>> ^ this line looks duplicated at the top of the function?
>
> Good catch!

Indeed!

> Jens, since you've already applied this, can you remove this line or
> would you like a patch doing so?

It's still top-of-tree, I just amended it.

--
Jens Axboe