[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d606f285-a31f-4b36-a7a9-bd913e1b0836@kernel.dk>
Date: Wed, 13 Sep 2023 13:36:33 -0600
From: Jens Axboe <axboe@...nel.dk>
To: Breno Leitao <leitao@...ian.org>, sdf@...gle.com, asml.silence@...il.com,
willemdebruijn.kernel@...il.com, kuba@...nel.org, pabeni@...hat.com,
martin.lau@...ux.dev, krisman@...e.de
Cc: bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
netdev@...r.kernel.org, io-uring@...r.kernel.org
Subject: Re: [PATCH v6 6/8] io_uring/cmd: Introduce SOCKET_URING_OP_GETSOCKOPT
On 9/13/23 9:27 AM, Breno Leitao wrote:
> Add support for getsockopt command (SOCKET_URING_OP_GETSOCKOPT), where
> level is SOL_SOCKET. This is similar to the getsockopt(2) system
> call, and both parameters are pointers to userspace.
>
> Important to say that userspace needs to keep the pointer alive until
> the CQE is completed.
Since it's holding the data needed, this is true for any request that
is writing data. IOW, this is not unusual and should be taken for
granted. I think this may warrant a bit of rewording if the patch is
respun, if not then just ignore it.
> diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> index 5753c3611b74..a2a6ac0c503b 100644
> --- a/io_uring/uring_cmd.c
> +++ b/io_uring/uring_cmd.c
> @@ -167,6 +167,19 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
> }
> EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed);
>
> +static inline int io_uring_cmd_getsockopt(struct socket *sock,
> + struct io_uring_cmd *cmd,
> + unsigned int issue_flags)
> +{
> + void __user *optval = u64_to_user_ptr(READ_ONCE(cmd->sqe->optval));
> + int __user *optlen = u64_to_user_ptr(READ_ONCE(cmd->sqe->optlen));
> + bool compat = !!(issue_flags & IO_URING_F_COMPAT);
> + int optname = READ_ONCE(cmd->sqe->optname);
> + int level = READ_ONCE(cmd->sqe->level);
> +
> + return do_sock_getsockopt(sock, compat, level, optname, optval, optlen);
> +}
Personal preference, but any other io_uring generally uses the format
of:
bool compat = !!(issue_flags & IO_URING_F_COMPAT);
void __user *optval;
int __user *optlen;
int optname, level;
optval = u64_to_user_ptr(READ_ONCE(cmd->sqe->optval));
optlen = u64_to_user_ptr(READ_ONCE(cmd->sqe->optlen));
optname = READ_ONCE(cmd->sqe->optname);
level = READ_ONCE(cmd->sqe->level);
return do_sock_getsockopt(sock, compat, level, optname, optval, optlen);
which I find a lot easier to read than bundling variable declarations
and reading the values into them.
And I always forget that cmd->sqe is a copy for URING_CMD, which makes
this just look wrong as they should've been read at prep time rather
than issue time. But it's fine!
--
Jens Axboe
Powered by blists - more mailing lists