public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: io-uring <[email protected]>
Cc: Kanchan Joshi <[email protected]>
Subject: [PATCH] io_uring/uring_cmd: ensure that device supports IOPOLL
Date: Wed, 8 Mar 2023 09:30:56 -0700	[thread overview]
Message-ID: <[email protected]> (raw)

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: [email protected]
Fixes: 5756a3a7e713 ("io_uring: add iopoll infrastructure for io_uring_cmd")
Link: https://github.com/axboe/liburing/issues/816
Signed-off-by: Jens Axboe <[email protected]>

---

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


             reply	other threads:[~2023-03-08 16:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230308163102epcas5p45cc9c1b5b2ab0bcd772c5ff8d72acd93@epcas5p4.samsung.com>
2023-03-08 16:30 ` Jens Axboe [this message]
2023-03-09  9:27   ` [PATCH] io_uring/uring_cmd: ensure that device supports IOPOLL Kanchan Joshi
2023-03-09 16:25     ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox