[PATCH 1/2] iouring: one capable call per iouring instance

Jens Axboe axboe at kernel.dk
Mon Dec 4 10:15:08 PST 2023


On 12/4/23 10:53 AM, Keith Busch wrote:
> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
> index 1d254f2c997de..4aa10b64f539e 100644
> --- a/io_uring/io_uring.c
> +++ b/io_uring/io_uring.c
> @@ -3980,6 +3980,7 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
>  		ctx->syscall_iopoll = 1;
>  
>  	ctx->compat = in_compat_syscall();
> +	ctx->sys_admin = capable(CAP_SYS_ADMIN);
>  	if (!ns_capable_noaudit(&init_user_ns, CAP_IPC_LOCK))
>  		ctx->user = get_uid(current_user());
>  
> diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> index 8a38b9f75d841..764f0e004aa00 100644
> --- a/io_uring/uring_cmd.c
> +++ b/io_uring/uring_cmd.c
> @@ -164,6 +164,8 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
>  		issue_flags |= IO_URING_F_CQE32;
>  	if (ctx->compat)
>  		issue_flags |= IO_URING_F_COMPAT;
> +	if (ctx->sys_admin)
> +		issue_flags |= IO_URING_F_SYS_ADMIN;
>  	if (ctx->flags & IORING_SETUP_IOPOLL) {
>  		if (!file->f_op->uring_cmd_iopoll)
>  			return -EOPNOTSUPP;

Since we know have two flags that would be cached from init time, rather
than add a second branch for this, why not have:

io_uring_create()
{
	[...]
	if (in_compat_syscall())
		ctx->issue_flags |= IO_URING_F_COMPAT;
	if (capable(CAP_SYS_ADMIN))
		ctx->issue_flags |= IO_URING_F_SYS_ADMIN;
	[...]
}

and get rid of ->compat and ->sys_admin, and then have:

io_uring_cmd()
{
	issue_flags |= ctx->issue_flags;
}

Then we can also drop checking for IORING_SETUP_SQE128/CQE32 as well,
dropping two more fast path branches.

-- 
Jens Axboe




More information about the Linux-nvme mailing list