Skip to contentSkip to conversation

ublk: remove unnecessary ubq checks

PATCH Applied Caleb Sander Mateos 4 participants 5 messages Apr 16, 2025 – Apr 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ublk: remove unnecessary ubq checks

ublk_init_queues() ensures that all nr_hw_queues queues are initialized, with each ublk_queue's q_id set to its index. And ublk_init_queues() is called before ublk_add_chdev(), which creates the cdev. Is is therefore impossible for the !ubq || ub_cmd->q_id != ubq->q_id condition to hit in __ublk_ch_uring_cmd(). Remove it to avoids some branches in the I/O path.

---
 drivers/block/ublk_drv.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/block/ublk_drv.c +0 -3
index cdb1543fa4a9..bc86231f5e27 100644
@@ -1947,13 +1947,10 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
 
 	if (ub_cmd->q_id >= ub->dev_info.nr_hw_queues)
 		goto out;
 
 	ubq = ublk_get_queue(ub, ub_cmd->q_id);
-	if (!ubq || ub_cmd->q_id != ubq->q_id)
-		goto out;
-
 	if (ubq->ubq_daemon && ubq->ubq_daemon != current)
 		goto out;
 
 	if (tag >= ubq->q_depth)
 		goto out;
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Caleb Sander Mateos

ublk_init_queues() ensures that all nr_hw_queues queues are initialized, with each ublk_queue's q_id set to its index. And ublk_init_queues() is called before ublk_add_chdev(), which creates the cdev. Is is therefore impossible for the !ubq || ub_cmd->q_id != ubq->q_id condition to hit in __ublk_ch_uring_cmd(). Remove it to avoids some branches in the I/O path.

Quoted 25 lines
---
 drivers/block/ublk_drv.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/block/ublk_drv.c +0 -3
index cdb1543fa4a9..bc86231f5e27 100644
@@ -1947,13 +1947,10 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
 
 	if (ub_cmd->q_id >= ub->dev_info.nr_hw_queues)
 		goto out;
 
 	ubq = ublk_get_queue(ub, ub_cmd->q_id);
-	if (!ubq || ub_cmd->q_id != ubq->q_id)
-		goto out;
-
 	if (ubq->ubq_daemon && ubq->ubq_daemon != current)
 		goto out;
 
 	if (tag >= ubq->q_depth)
 		goto out;
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#2 lore raw
In reply to Caleb Sander Mateos
Quoted 16 lines · Caleb Sander Mateos

ublk_init_queues() ensures that all nr_hw_queues queues are initialized, with each ublk_queue's q_id set to its index. And ublk_init_queues() is called before ublk_add_chdev(), which creates the cdev. Is is therefore impossible for the !ubq || ub_cmd->q_id != ubq->q_id condition to hit in __ublk_ch_uring_cmd(). Remove it to avoids some branches in the I/O path.

---
 drivers/block/ublk_drv.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/block/ublk_drv.c +0 -0
index cdb1543fa4a9..bc86231f5e27 100644

drivers/block/ublk_drv.c static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd, · line 1954

Quoted 8 lines
drivers/block/ublk_drv.c +0 -3
@@ -1947,13 +1947,10 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
 
 	if (ub_cmd->q_id >= ub->dev_info.nr_hw_queues)
 		goto out;
 
 	ubq = ublk_get_queue(ub, ub_cmd->q_id);
-	if (!ubq || ub_cmd->q_id != ubq->q_id)
-		goto out;
-

Looks correct, ubq->q_id is always same with the index passed to ublk_get_queue().

Thanks,
Ming

#3 lore raw

Hi Jens,
Would you mind queueing up this small patch for 6.16? Uday and Ming have reviewed it.

Thanks,
Caleb

Quoted 36 lines · Ming Lei
Quoted 16 lines · Caleb Sander Mateos

ublk_init_queues() ensures that all nr_hw_queues queues are initialized, with each ublk_queue's q_id set to its index. And ublk_init_queues() is called before ublk_add_chdev(), which creates the cdev. Is is therefore impossible for the !ubq || ub_cmd->q_id != ubq->q_id condition to hit in __ublk_ch_uring_cmd(). Remove it to avoids some branches in the I/O path.

---
 drivers/block/ublk_drv.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/block/ublk_drv.c +0 -0
index cdb1543fa4a9..bc86231f5e27 100644

drivers/block/ublk_drv.c static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd, · line 1954

Quoted 8 lines
drivers/block/ublk_drv.c +0 -3
@@ -1947,13 +1947,10 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
 
      if (ub_cmd->q_id >= ub->dev_info.nr_hw_queues)
              goto out;
 
      ubq = ublk_get_queue(ub, ub_cmd->q_id);
-     if (!ubq || ub_cmd->q_id != ubq->q_id)
-             goto out;
-

Looks correct, ubq->q_id is always same with the index passed to ublk_get_queue().

Thanks,
Ming

maintainer Applied
#4 lore raw
In reply to Caleb Sander Mateos
Quoted 8 lines · Caleb Sander Mateos

ublk_init_queues() ensures that all nr_hw_queues queues are initialized, with each ublk_queue's q_id set to its index. And ublk_init_queues() is called before ublk_add_chdev(), which creates the cdev. Is is therefore impossible for the !ubq || ub_cmd->q_id != ubq->q_id condition to hit in __ublk_ch_uring_cmd(). Remove it to avoids some branches in the I/O path.

[...]

Applied, thanks!

[1/1] ublk: remove unnecessary ubq checks

      commit: 4c7d3c88c77bf227c12ef13e8461a0c940f775e8

Best regards,

Signature · 1 line
Jens Axboe