public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ublk: allow non-blocking ctrl cmds in IO_URING_F_NONBLOCK issue
@ 2025-12-01 21:41 Caleb Sander Mateos
  2025-12-08  7:59 ` Ming Lei
  2025-12-09 17:21 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Caleb Sander Mateos @ 2025-12-01 21:41 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: Caleb Sander Mateos, linux-block, linux-kernel

Handling most of the ublksrv_ctrl_cmd opcodes require locking a mutex,
so ublk_ctrl_uring_cmd() bails out with EAGAIN when called with the
IO_URING_F_NONBLOCK issue flag. However, several opcodes can be handled
without blocking:
- UBLK_CMD_GET_QUEUE_AFFINITY
- UBLK_CMD_GET_DEV_INFO
- UBLK_CMD_GET_DEV_INFO2
- UBLK_U_CMD_GET_FEATURES

Handle these opcodes synchronously instead of returning EAGAIN so
io_uring doesn't need to issue the command via the worker thread pool.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 drivers/block/ublk_drv.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index c2250172de4c..3d6d5f568779 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -3671,19 +3671,33 @@ static int ublk_ctrl_uring_cmd_permission(struct ublk_device *ub,
 exit:
 	kfree(dev_path);
 	return ret;
 }
 
+static bool ublk_ctrl_uring_cmd_may_sleep(u32 cmd_op)
+{
+	switch (_IOC_NR(cmd_op)) {
+	case UBLK_CMD_GET_QUEUE_AFFINITY:
+	case UBLK_CMD_GET_DEV_INFO:
+	case UBLK_CMD_GET_DEV_INFO2:
+	case _IOC_NR(UBLK_U_CMD_GET_FEATURES):
+		return false;
+	default:
+		return true;
+	}
+}
+
 static int ublk_ctrl_uring_cmd(struct io_uring_cmd *cmd,
 		unsigned int issue_flags)
 {
 	const struct ublksrv_ctrl_cmd *header = io_uring_sqe_cmd(cmd->sqe);
 	struct ublk_device *ub = NULL;
 	u32 cmd_op = cmd->cmd_op;
 	int ret = -EINVAL;
 
-	if (issue_flags & IO_URING_F_NONBLOCK)
+	if (ublk_ctrl_uring_cmd_may_sleep(cmd_op) &&
+	    issue_flags & IO_URING_F_NONBLOCK)
 		return -EAGAIN;
 
 	ublk_ctrl_cmd_dump(cmd);
 
 	if (!(issue_flags & IO_URING_F_SQE128))
-- 
2.45.2


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

* Re: [PATCH] ublk: allow non-blocking ctrl cmds in IO_URING_F_NONBLOCK issue
  2025-12-01 21:41 [PATCH] ublk: allow non-blocking ctrl cmds in IO_URING_F_NONBLOCK issue Caleb Sander Mateos
@ 2025-12-08  7:59 ` Ming Lei
  2025-12-09 17:21 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Ming Lei @ 2025-12-08  7:59 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: Jens Axboe, linux-block, linux-kernel

On Mon, Dec 01, 2025 at 02:41:44PM -0700, Caleb Sander Mateos wrote:
> Handling most of the ublksrv_ctrl_cmd opcodes require locking a mutex,
> so ublk_ctrl_uring_cmd() bails out with EAGAIN when called with the
> IO_URING_F_NONBLOCK issue flag. However, several opcodes can be handled
> without blocking:
> - UBLK_CMD_GET_QUEUE_AFFINITY
> - UBLK_CMD_GET_DEV_INFO
> - UBLK_CMD_GET_DEV_INFO2
> - UBLK_U_CMD_GET_FEATURES
> 
> Handle these opcodes synchronously instead of returning EAGAIN so
> io_uring doesn't need to issue the command via the worker thread pool.
> 
> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>

Reviewed-by: Ming Lei <ming.lei@redhat.com>


Thanks,
Ming


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

* Re: [PATCH] ublk: allow non-blocking ctrl cmds in IO_URING_F_NONBLOCK issue
  2025-12-01 21:41 [PATCH] ublk: allow non-blocking ctrl cmds in IO_URING_F_NONBLOCK issue Caleb Sander Mateos
  2025-12-08  7:59 ` Ming Lei
@ 2025-12-09 17:21 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-12-09 17:21 UTC (permalink / raw)
  To: Ming Lei, Caleb Sander Mateos; +Cc: linux-block, linux-kernel


On Mon, 01 Dec 2025 14:41:44 -0700, Caleb Sander Mateos wrote:
> Handling most of the ublksrv_ctrl_cmd opcodes require locking a mutex,
> so ublk_ctrl_uring_cmd() bails out with EAGAIN when called with the
> IO_URING_F_NONBLOCK issue flag. However, several opcodes can be handled
> without blocking:
> - UBLK_CMD_GET_QUEUE_AFFINITY
> - UBLK_CMD_GET_DEV_INFO
> - UBLK_CMD_GET_DEV_INFO2
> - UBLK_U_CMD_GET_FEATURES
> 
> [...]

Applied, thanks!

[1/1] ublk: allow non-blocking ctrl cmds in IO_URING_F_NONBLOCK issue
      commit: 87213b0d847cd300285b5545598e0548baeb5208

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-12-09 17:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-01 21:41 [PATCH] ublk: allow non-blocking ctrl cmds in IO_URING_F_NONBLOCK issue Caleb Sander Mateos
2025-12-08  7:59 ` Ming Lei
2025-12-09 17:21 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox