2022-09-26 17:59:59

by Dylan Yudaken

[permalink] [raw]
Subject: [PATCH v2 1/3] io_uring: register single issuer task at creation

Instead of picking the task from the first submitter task, rather use the
creator task or in the case of disabled (IORING_SETUP_R_DISABLED) the
enabling task.

This approach allows a lot of simplification of the logic here. This
removes init logic from the submission path, which can always be a bit
confusing, but also removes the need for locking to write (or read) the
submitter_task.

Users that want to move a ring before submitting can create the ring
disabled and then enable it on the submitting task.

Signed-off-by: Dylan Yudaken <[email protected]>
---
io_uring/io_uring.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 2965b354efc8..242d896c00f3 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3357,6 +3357,10 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
goto err;
}

+ if (ctx->flags & IORING_SETUP_SINGLE_ISSUER
+ && !(ctx->flags & IORING_SETUP_R_DISABLED))
+ ctx->submitter_task = get_task_struct(current);
+
file = io_uring_get_file(ctx);
if (IS_ERR(file)) {
ret = PTR_ERR(file);
@@ -3548,6 +3552,9 @@ static int io_register_enable_rings(struct io_ring_ctx *ctx)
if (!(ctx->flags & IORING_SETUP_R_DISABLED))
return -EBADFD;

+ if (ctx->flags & IORING_SETUP_SINGLE_ISSUER && !ctx->submitter_task)
+ ctx->submitter_task = get_task_struct(current);
+
if (ctx->restrictions.registered)
ctx->restricted = 1;

--
2.30.2


2022-09-26 19:22:14

by Pavel Begunkov

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] io_uring: register single issuer task at creation

On 9/26/22 18:09, Dylan Yudaken wrote:
> Instead of picking the task from the first submitter task, rather use the
> creator task or in the case of disabled (IORING_SETUP_R_DISABLED) the
> enabling task.
>
> This approach allows a lot of simplification of the logic here. This
> removes init logic from the submission path, which can always be a bit
> confusing, but also removes the need for locking to write (or read) the
> submitter_task.
>
> Users that want to move a ring before submitting can create the ring
> disabled and then enable it on the submitting task.

I think Dylan briefly mentioned before that it might be a good
idea to task limit registration as well. I can't think of a use
case at the moment but I agree we may find some in the future.


diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 242d896c00f3..60a471e43fd9 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3706,6 +3706,9 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
if (WARN_ON_ONCE(percpu_ref_is_dying(&ctx->refs)))
return -ENXIO;

+ if (ctx->submitter_task && ctx->submitter_task != current)
+ return -EEXIST;
+
if (ctx->restricted) {
if (opcode >= IORING_REGISTER_LAST)
return -EINVAL;


--
Pavel Begunkov

2022-09-26 19:48:03

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] io_uring: register single issuer task at creation

On 9/26/22 1:12 PM, Pavel Begunkov wrote:
> On 9/26/22 18:09, Dylan Yudaken wrote:
>> Instead of picking the task from the first submitter task, rather use the
>> creator task or in the case of disabled (IORING_SETUP_R_DISABLED) the
>> enabling task.
>>
>> This approach allows a lot of simplification of the logic here. This
>> removes init logic from the submission path, which can always be a bit
>> confusing, but also removes the need for locking to write (or read) the
>> submitter_task.
>>
>> Users that want to move a ring before submitting can create the ring
>> disabled and then enable it on the submitting task.
>
> I think Dylan briefly mentioned before that it might be a good
> idea to task limit registration as well. I can't think of a use
> case at the moment but I agree we may find some in the future.
>
>
> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
> index 242d896c00f3..60a471e43fd9 100644
> --- a/io_uring/io_uring.c
> +++ b/io_uring/io_uring.c
> @@ -3706,6 +3706,9 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
>      if (WARN_ON_ONCE(percpu_ref_is_dying(&ctx->refs)))
>          return -ENXIO;
>  
> +    if (ctx->submitter_task && ctx->submitter_task != current)
> +        return -EEXIST;
> +
>      if (ctx->restricted) {
>          if (opcode >= IORING_REGISTER_LAST)
>              return -EINVAL;

Yes, I don't see any reason why not to enforce this for registration
too. Don't think there's currently a need to do so, but it'd be easy
to miss once we do add that. Let's queue that up for 6.1?

--
Jens Axboe


2022-09-26 20:39:12

by Pavel Begunkov

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] io_uring: register single issuer task at creation

On 9/26/22 20:40, Jens Axboe wrote:
> On 9/26/22 1:12 PM, Pavel Begunkov wrote:
>> On 9/26/22 18:09, Dylan Yudaken wrote:
>>> Instead of picking the task from the first submitter task, rather use the
>>> creator task or in the case of disabled (IORING_SETUP_R_DISABLED) the
>>> enabling task.
>>>
>>> This approach allows a lot of simplification of the logic here. This
>>> removes init logic from the submission path, which can always be a bit
>>> confusing, but also removes the need for locking to write (or read) the
>>> submitter_task.
>>>
>>> Users that want to move a ring before submitting can create the ring
>>> disabled and then enable it on the submitting task.
>>
>> I think Dylan briefly mentioned before that it might be a good
>> idea to task limit registration as well. I can't think of a use
>> case at the moment but I agree we may find some in the future.
>>
>>
>> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
>> index 242d896c00f3..60a471e43fd9 100644
>> --- a/io_uring/io_uring.c
>> +++ b/io_uring/io_uring.c
>> @@ -3706,6 +3706,9 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
>>      if (WARN_ON_ONCE(percpu_ref_is_dying(&ctx->refs)))
>>          return -ENXIO;
>>
>> +    if (ctx->submitter_task && ctx->submitter_task != current)
>> +        return -EEXIST;
>> +
>>      if (ctx->restricted) {
>>          if (opcode >= IORING_REGISTER_LAST)
>>              return -EINVAL;
>
> Yes, I don't see any reason why not to enforce this for registration
> too. Don't think there's currently a need to do so, but it'd be easy
> to miss once we do add that. Let's queue that up for 6.1?

6.1 + stable sounds ok, I don't have an opinion on how to how
to merge it.

--
Pavel Begunkov

2022-09-26 21:22:41

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] io_uring: register single issuer task at creation

On 9/26/22 2:29 PM, Pavel Begunkov wrote:
> On 9/26/22 20:40, Jens Axboe wrote:
>> On 9/26/22 1:12 PM, Pavel Begunkov wrote:
>>> On 9/26/22 18:09, Dylan Yudaken wrote:
>>>> Instead of picking the task from the first submitter task, rather use the
>>>> creator task or in the case of disabled (IORING_SETUP_R_DISABLED) the
>>>> enabling task.
>>>>
>>>> This approach allows a lot of simplification of the logic here. This
>>>> removes init logic from the submission path, which can always be a bit
>>>> confusing, but also removes the need for locking to write (or read) the
>>>> submitter_task.
>>>>
>>>> Users that want to move a ring before submitting can create the ring
>>>> disabled and then enable it on the submitting task.
>>>
>>> I think Dylan briefly mentioned before that it might be a good
>>> idea to task limit registration as well. I can't think of a use
>>> case at the moment but I agree we may find some in the future.
>>>
>>>
>>> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
>>> index 242d896c00f3..60a471e43fd9 100644
>>> --- a/io_uring/io_uring.c
>>> +++ b/io_uring/io_uring.c
>>> @@ -3706,6 +3706,9 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
>>>       if (WARN_ON_ONCE(percpu_ref_is_dying(&ctx->refs)))
>>>           return -ENXIO;
>>>   +    if (ctx->submitter_task && ctx->submitter_task != current)
>>> +        return -EEXIST;
>>> +
>>>       if (ctx->restricted) {
>>>           if (opcode >= IORING_REGISTER_LAST)
>>>               return -EINVAL;
>>
>> Yes, I don't see any reason why not to enforce this for registration
>> too. Don't think there's currently a need to do so, but it'd be easy
>> to miss once we do add that. Let's queue that up for 6.1?
>
> 6.1 + stable sounds ok, I don't have an opinion on how to how
> to merge it.

That's the plan. If you can just send it out as a separate commit,
I'll stage it up behind the two others from Dylan.

--
Jens Axboe