Skip to content

Commit 4232c6e

Browse files
leitaoaxboe
authored andcommitted
io_uring/cmd: Introduce SOCKET_URING_OP_SETSOCKOPT
Add initial support for SOCKET_URING_OP_SETSOCKOPT. This new command is similar to setsockopt. This implementation leverages the function do_sock_setsockopt(), which is shared with the setsockopt() system call path. Important to say that userspace needs to keep the pointer's memory alive until the operation is completed. I.e, the memory could not be deallocated before the CQE is returned to userspace. Signed-off-by: Breno Leitao <leitao@debian.org> Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de> Link: https://lore.kernel.org/r/20231016134750.1381153-11-leitao@debian.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a5d2f99 commit 4232c6e

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

include/uapi/linux/io_uring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ enum {
743743
SOCKET_URING_OP_SIOCINQ = 0,
744744
SOCKET_URING_OP_SIOCOUTQ,
745745
SOCKET_URING_OP_GETSOCKOPT,
746+
SOCKET_URING_OP_SETSOCKOPT,
746747
};
747748

748749
#ifdef __cplusplus

io_uring/uring_cmd.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,25 @@ static inline int io_uring_cmd_getsockopt(struct socket *sock,
240240
return optlen;
241241
}
242242

243+
static inline int io_uring_cmd_setsockopt(struct socket *sock,
244+
struct io_uring_cmd *cmd,
245+
unsigned int issue_flags)
246+
{
247+
bool compat = !!(issue_flags & IO_URING_F_COMPAT);
248+
int optname, optlen, level;
249+
void __user *optval;
250+
sockptr_t optval_s;
251+
252+
optval = u64_to_user_ptr(READ_ONCE(cmd->sqe->optval));
253+
optname = READ_ONCE(cmd->sqe->optname);
254+
optlen = READ_ONCE(cmd->sqe->optlen);
255+
level = READ_ONCE(cmd->sqe->level);
256+
optval_s = USER_SOCKPTR(optval);
257+
258+
return do_sock_setsockopt(sock, compat, level, optname, optval_s,
259+
optlen);
260+
}
261+
243262
#if defined(CONFIG_NET)
244263
int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags)
245264
{
@@ -264,6 +283,8 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags)
264283
return arg;
265284
case SOCKET_URING_OP_GETSOCKOPT:
266285
return io_uring_cmd_getsockopt(sock, cmd, issue_flags);
286+
case SOCKET_URING_OP_SETSOCKOPT:
287+
return io_uring_cmd_setsockopt(sock, cmd, issue_flags);
267288
default:
268289
return -EOPNOTSUPP;
269290
}

0 commit comments

Comments
 (0)