Skip to contentSkip to conversation

io_uring/uring_cmd: ensure that device supports IOPOLL

PATCH In review Jens Axboe 2 participants 3 messages Mar 8, 2023 – Mar 9, 2023 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring/uring_cmd: ensure that device supports IOPOLL

It's possible for a file type to support uring commands, but not pollable ones. Hence before issuing one of those, we should check that it is supported and error out upfront if it isn't.

Fixes 5756a3a7e713 ("io_uring: add iopoll infrastructure for io_uring_cmd")

---

io_uring/uring_cmd.c +13 -1
index 446a189b78b0..e3413f131887 100644
@@ -101,6 +101,18 @@ int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	return 0;
 }
 
+static bool io_uring_cmd_supported(struct io_ring_ctx *ctx, struct file *file)
+{
+	/* no issue method, fail */
+	if (!file->f_op->uring_cmd)
+		return false;
+	/* IOPOLL enabled and no poll method, fail */
+	if (ctx->flags & IORING_SETUP_IOPOLL && !file->f_op->uring_cmd_iopoll)
+		return false;
+
+	return true;
+}
+
 int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
 {
 	struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
@@ -108,7 +120,7 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
 	struct file *file = req->file;
 	int ret;
 
-	if (!req->file->f_op->uring_cmd)
+	if (!io_uring_cmd_supported(ctx, file))
 		return -EOPNOTSUPP;
 
 	ret = security_uring_cmd(ioucmd);
Signature · 1 line
Jens Axboe
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Jens Axboe

It's possible for a file type to support uring commands, but not pollable ones. Hence before issuing one of those, we should check that it is supported and error out upfront if it isn't.

Indeed, I missed that altogether.

author maintainer Reviewed-by Kanchan Joshi
#2 lore raw
Quoted 8 lines · Kanchan Joshi
Quoted 3 lines · Jens Axboe

It's possible for a file type to support uring commands, but not pollable ones. Hence before issuing one of those, we should check that it is supported and error out upfront if it isn't.

Indeed, I missed that altogether.

FWIW, I changed it a bit so we can fold that check in with the other IOPOLL section. I added your Reviewed-by still, here's the v2:

commit 03b3d6be73e81ddb7c2930d942cdd17f4cfd5ba5

Author: Jens Axboe <[email protected]>
Date:   Wed Mar 8 09:26:13 2023 -0700

io_uring/uring_cmd: ensure that device supports IOPOLL

It's possible for a file type to support uring commands, but not pollable ones. Hence before issuing one of those, we should check that it is supported and error out upfront if it isn't.

Fixes 5756a3a7e713 ("io_uring: add iopoll infrastructure for io_uring_cmd")
io_uring/uring_cmd.c +3 -1
index 446a189b78b0..2e4c483075d3 100644
@@ -108,7 +108,7 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
 	struct file *file = req->file;
 	int ret;
 
-	if (!req->file->f_op->uring_cmd)
+	if (!file->f_op->uring_cmd)
 		return -EOPNOTSUPP;
 
 	ret = security_uring_cmd(ioucmd);
@@ -120,6 +120,8 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
 	if (ctx->flags & IORING_SETUP_CQE32)
 		issue_flags |= IO_URING_F_CQE32;
 	if (ctx->flags & IORING_SETUP_IOPOLL) {
+		if (!file->f_op->uring_cmd_iopoll)
+			return -EOPNOTSUPP;
 		issue_flags |= IO_URING_F_IOPOLL;
 		req->iopoll_completed = 0;
 		WRITE_ONCE(ioucmd->cookie, NULL);
Signature · 1 line
Jens Axboe