Skip to contentSkip to conversation

io_uring/uring_cmd: use cached cmd_op in io_uring_cmd_sock()

PATCH In review Jens Axboe 2 participants 2 messages Jan 23, 2025 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring/uring_cmd: use cached cmd_op in io_uring_cmd_sock()

io_uring_cmd_sock() does a read of cmd->sqe->cmd_op, which may look like it's the userspace shared SQE, but it's a copy at this point. Use cmd->cmd_op rather than dip into the allocated SQE copy - it's both simpler and faster and leaves less room for confusion.

---

io_uring/uring_cmd.c +1 -1
index fc94c465a985..3993c9339ac7 100644
@@ -350,7 +350,7 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags)
 	if (!prot || !prot->ioctl)
 		return -EOPNOTSUPP;
 
-	switch (cmd->sqe->cmd_op) {
+	switch (cmd->cmd_op) {
 	case SOCKET_URING_OP_SIOCINQ:
 		ret = prot->ioctl(sk, SIOCINQ, &arg);
 		if (ret)
Signature · 1 line
Jens Axboe
#1 lore raw
Quoted 15 lines · Jens Axboe

io_uring_cmd_sock() does a read of cmd->sqe->cmd_op, which may look like it's the userspace shared SQE, but it's a copy at this point. Use cmd->cmd_op rather than dip into the allocated SQE copy - it's both simpler and faster and leaves less room for confusion.

---

io_uring/uring_cmd.c +0 -0
index fc94c465a985..3993c9339ac7 100644

io_uring/uring_cmd.c int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags) · line 353

Quoted 5 lines
io_uring/uring_cmd.c +1 -1
@@ -350,7 +350,7 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags)
        if (!prot || !prot->ioctl)
                return -EOPNOTSUPP;
 
-       switch (cmd->sqe->cmd_op) {
+       switch (cmd->cmd_op) {

Ah, yeah, this does look better than the READ_ONCE() I suggested.