io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] io_uring/uring_cmd: ensure that device supports IOPOLL
@ 2023-03-08 16:30 ` Jens Axboe
  2023-03-09  9:27   ` Kanchan Joshi
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2023-03-08 16:30 UTC (permalink / raw)
  To: io-uring; +Cc: Kanchan Joshi

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.

Cc: stable@vger.kernel.org
Fixes: 5756a3a7e713 ("io_uring: add iopoll infrastructure for io_uring_cmd")
Link: https://github.com/axboe/liburing/issues/816
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
index 446a189b78b0..e3413f131887 100644
--- a/io_uring/uring_cmd.c
+++ b/io_uring/uring_cmd.c
@@ -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);

-- 
Jens Axboe


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] io_uring/uring_cmd: ensure that device supports IOPOLL
  2023-03-08 16:30 ` [PATCH] io_uring/uring_cmd: ensure that device supports IOPOLL Jens Axboe
@ 2023-03-09  9:27   ` Kanchan Joshi
  2023-03-09 16:25     ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Kanchan Joshi @ 2023-03-09  9:27 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring

[-- Attachment #1: Type: text/plain, Size: 335 bytes --]

On Wed, Mar 08, 2023 at 09:30:56AM -0700, Jens Axboe wrote:
>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.

Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] io_uring/uring_cmd: ensure that device supports IOPOLL
  2023-03-09  9:27   ` Kanchan Joshi
@ 2023-03-09 16:25     ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2023-03-09 16:25 UTC (permalink / raw)
  To: Kanchan Joshi; +Cc: io-uring

On 3/9/23 2:27 AM, Kanchan Joshi wrote:
> On Wed, Mar 08, 2023 at 09:30:56AM -0700, Jens Axboe wrote:
>> 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.
> 
> Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>

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 <axboe@kernel.dk>
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.
    
    Cc: stable@vger.kernel.org
    Fixes: 5756a3a7e713 ("io_uring: add iopoll infrastructure for io_uring_cmd")
    Link: https://github.com/axboe/liburing/issues/816
    Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
index 446a189b78b0..2e4c483075d3 100644
--- a/io_uring/uring_cmd.c
+++ b/io_uring/uring_cmd.c
@@ -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);

-- 
Jens Axboe



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-09 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20230308163102epcas5p45cc9c1b5b2ab0bcd772c5ff8d72acd93@epcas5p4.samsung.com>
2023-03-08 16:30 ` [PATCH] io_uring/uring_cmd: ensure that device supports IOPOLL Jens Axboe
2023-03-09  9:27   ` Kanchan Joshi
2023-03-09 16:25     ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).