* [PATCH] io_uring: Factor out a function to parse restrictions
@ 2025-01-15 9:14 Josh Triplett
2025-01-15 15:39 ` Pavel Begunkov
2025-01-15 15:54 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Josh Triplett @ 2025-01-15 9:14 UTC (permalink / raw)
To: Jens Axboe, Pavel Begunkov; +Cc: io-uring
Preparation for subsequent work on inherited restrictions.
Signed-off-by: Josh Triplett <[email protected]>
---
io_uring/register.c | 64 +++++++++++++++++++++++----------------------
1 file changed, 33 insertions(+), 31 deletions(-)
diff --git a/io_uring/register.c b/io_uring/register.c
index fdd44914c39c..c13a34dd2255 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -104,21 +104,13 @@ static int io_register_personality(struct io_ring_ctx *ctx)
return id;
}
-static __cold int io_register_restrictions(struct io_ring_ctx *ctx,
- void __user *arg, unsigned int nr_args)
+static __cold int io_parse_restrictions(void __user *arg, unsigned int nr_args,
+ struct io_restriction *restrictions)
{
struct io_uring_restriction *res;
size_t size;
int i, ret;
- /* Restrictions allowed only if rings started disabled */
- if (!(ctx->flags & IORING_SETUP_R_DISABLED))
- return -EBADFD;
-
- /* We allow only a single restrictions registration */
- if (ctx->restrictions.registered)
- return -EBUSY;
-
if (!arg || nr_args > IORING_MAX_RESTRICTIONS)
return -EINVAL;
@@ -130,47 +122,57 @@ static __cold int io_register_restrictions(struct io_ring_ctx *ctx,
if (IS_ERR(res))
return PTR_ERR(res);
- ret = 0;
+ ret = -EINVAL;
for (i = 0; i < nr_args; i++) {
switch (res[i].opcode) {
case IORING_RESTRICTION_REGISTER_OP:
- if (res[i].register_op >= IORING_REGISTER_LAST) {
- ret = -EINVAL;
- goto out;
- }
-
- __set_bit(res[i].register_op,
- ctx->restrictions.register_op);
+ if (res[i].register_op >= IORING_REGISTER_LAST)
+ goto err;
+ __set_bit(res[i].register_op, restrictions->register_op);
break;
case IORING_RESTRICTION_SQE_OP:
- if (res[i].sqe_op >= IORING_OP_LAST) {
- ret = -EINVAL;
- goto out;
- }
-
- __set_bit(res[i].sqe_op, ctx->restrictions.sqe_op);
+ if (res[i].sqe_op >= IORING_OP_LAST)
+ goto err;
+ __set_bit(res[i].sqe_op, restrictions->sqe_op);
break;
case IORING_RESTRICTION_SQE_FLAGS_ALLOWED:
- ctx->restrictions.sqe_flags_allowed = res[i].sqe_flags;
+ restrictions->sqe_flags_allowed = res[i].sqe_flags;
break;
case IORING_RESTRICTION_SQE_FLAGS_REQUIRED:
- ctx->restrictions.sqe_flags_required = res[i].sqe_flags;
+ restrictions->sqe_flags_required = res[i].sqe_flags;
break;
default:
- ret = -EINVAL;
- goto out;
+ goto err;
}
}
-out:
+ ret = 0;
+
+err:
+ kfree(res);
+ return ret;
+}
+
+static __cold int io_register_restrictions(struct io_ring_ctx *ctx,
+ void __user *arg, unsigned int nr_args)
+{
+ int ret;
+
+ /* Restrictions allowed only if rings started disabled */
+ if (!(ctx->flags & IORING_SETUP_R_DISABLED))
+ return -EBADFD;
+
+ /* We allow only a single restrictions registration */
+ if (ctx->restrictions.registered)
+ return -EBUSY;
+
+ ret = io_parse_restrictions(arg, nr_args, &ctx->restrictions);
/* Reset all restrictions if an error happened */
if (ret != 0)
memset(&ctx->restrictions, 0, sizeof(ctx->restrictions));
else
ctx->restrictions.registered = true;
-
- kfree(res);
return ret;
}
--
2.48.0.rc1.219.gb6b6757d772
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring: Factor out a function to parse restrictions
2025-01-15 9:14 [PATCH] io_uring: Factor out a function to parse restrictions Josh Triplett
@ 2025-01-15 15:39 ` Pavel Begunkov
2025-01-15 15:54 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2025-01-15 15:39 UTC (permalink / raw)
To: Josh Triplett, Jens Axboe; +Cc: io-uring
On 1/15/25 09:14, Josh Triplett wrote:
> Preparation for subsequent work on inherited restrictions.
>
> Signed-off-by: Josh Triplett <[email protected]>
> ---
> io_uring/register.c | 64 +++++++++++++++++++++++----------------------
> 1 file changed, 33 insertions(+), 31 deletions(-)
lgtm
Reviewed-by: Pavel Begunkov <[email protected]>
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring: Factor out a function to parse restrictions
2025-01-15 9:14 [PATCH] io_uring: Factor out a function to parse restrictions Josh Triplett
2025-01-15 15:39 ` Pavel Begunkov
@ 2025-01-15 15:54 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-01-15 15:54 UTC (permalink / raw)
To: Pavel Begunkov, Josh Triplett; +Cc: io-uring
On Wed, 15 Jan 2025 11:14:33 +0200, Josh Triplett wrote:
> Preparation for subsequent work on inherited restrictions.
>
>
Applied, thanks!
[1/1] io_uring: Factor out a function to parse restrictions
(no commit info)
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-15 15:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-15 9:14 [PATCH] io_uring: Factor out a function to parse restrictions Josh Triplett
2025-01-15 15:39 ` Pavel Begunkov
2025-01-15 15:54 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox