Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring: track restrictions separately for IORING_OP and IORING_REGISTER

It's quite likely that only register opcode restrictions exists, in
which case we'd never need to check the normal opcodes. Split
ctx->restricted into two separate fields, one for I/O opcodes, and one
for register opcodes.

Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

+22 -9
+6 -2
include/linux/io_uring_types.h
··· 224 224 DECLARE_BITMAP(sqe_op, IORING_OP_LAST); 225 225 u8 sqe_flags_allowed; 226 226 u8 sqe_flags_required; 227 - bool registered; 227 + /* IORING_OP_* restrictions exist */ 228 + bool op_registered; 229 + /* IORING_REGISTER_* restrictions exist */ 230 + bool reg_registered; 228 231 }; 229 232 230 233 struct io_submit_link { ··· 262 259 struct { 263 260 unsigned int flags; 264 261 unsigned int drain_next: 1; 265 - unsigned int restricted: 1; 262 + unsigned int op_restricted: 1; 263 + unsigned int reg_restricted: 1; 266 264 unsigned int off_timeout_used: 1; 267 265 unsigned int drain_active: 1; 268 266 unsigned int has_evfd: 1;
+2 -2
io_uring/io_uring.c
··· 2056 2056 struct io_kiocb *req, 2057 2057 unsigned int sqe_flags) 2058 2058 { 2059 - if (!ctx->restricted) 2059 + if (!ctx->op_restricted) 2060 2060 return true; 2061 2061 if (!test_bit(req->opcode, ctx->restrictions.sqe_op)) 2062 2062 return false; ··· 2159 2159 io_init_drain(ctx); 2160 2160 } 2161 2161 } 2162 - if (unlikely(ctx->restricted || ctx->drain_active || ctx->drain_next)) { 2162 + if (unlikely(ctx->op_restricted || ctx->drain_active || ctx->drain_next)) { 2163 2163 if (!io_check_restriction(ctx, req, sqe_flags)) 2164 2164 return io_init_fail_req(req, -EACCES); 2165 2165 /* knock it to the slow queue path, will be drained there */
+14 -5
io_uring/register.c
··· 133 133 if (res[i].register_op >= IORING_REGISTER_LAST) 134 134 goto err; 135 135 __set_bit(res[i].register_op, restrictions->register_op); 136 + restrictions->reg_registered = true; 136 137 break; 137 138 case IORING_RESTRICTION_SQE_OP: 138 139 if (res[i].sqe_op >= IORING_OP_LAST) 139 140 goto err; 140 141 __set_bit(res[i].sqe_op, restrictions->sqe_op); 142 + restrictions->op_registered = true; 141 143 break; 142 144 case IORING_RESTRICTION_SQE_FLAGS_ALLOWED: 143 145 restrictions->sqe_flags_allowed = res[i].sqe_flags; 146 + restrictions->op_registered = true; 144 147 break; 145 148 case IORING_RESTRICTION_SQE_FLAGS_REQUIRED: 146 149 restrictions->sqe_flags_required = res[i].sqe_flags; 150 + restrictions->op_registered = true; 147 151 break; 148 152 default: 149 153 goto err; 150 154 } 151 155 } 152 156 ret = nr_args; 153 - restrictions->registered = true; 157 + if (!nr_args) { 158 + restrictions->op_registered = true; 159 + restrictions->reg_registered = true; 160 + } 154 161 err: 155 162 kfree(res); 156 163 return ret; ··· 173 166 return -EBADFD; 174 167 175 168 /* We allow only a single restrictions registration */ 176 - if (ctx->restrictions.registered) 169 + if (ctx->restrictions.op_registered || ctx->restrictions.reg_registered) 177 170 return -EBUSY; 178 171 179 172 ret = io_parse_restrictions(arg, nr_args, &ctx->restrictions); ··· 182 175 memset(&ctx->restrictions, 0, sizeof(ctx->restrictions)); 183 176 return ret; 184 177 } 185 - if (ctx->restrictions.registered) 186 - ctx->restricted = 1; 178 + if (ctx->restrictions.op_registered) 179 + ctx->op_restricted = 1; 180 + if (ctx->restrictions.reg_registered) 181 + ctx->reg_restricted = 1; 187 182 return 0; 188 183 } 189 184 ··· 635 626 if (ctx->submitter_task && ctx->submitter_task != current) 636 627 return -EEXIST; 637 628 638 - if (ctx->restricted && !(ctx->flags & IORING_SETUP_R_DISABLED)) { 629 + if (ctx->reg_restricted && !(ctx->flags & IORING_SETUP_R_DISABLED)) { 639 630 opcode = array_index_nospec(opcode, IORING_REGISTER_LAST); 640 631 if (!test_bit(opcode, ctx->restrictions.register_op)) 641 632 return -EACCES;