aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
authorYang Xiuwei <yangxiuwei@kylinos.cn>2026-03-17 15:22:25 +0800
committerJens Axboe <axboe@kernel.dk>2026-03-19 11:38:24 -0600
commita1e97ce80d9f41d0bb83951d758ff6fe49f3de60 (patch)
tree76c84703b7d5b00cb692f6a08938137a87ac9c8b /block
parent7da9261bab0a82bdbc4aafd2ad4bc3529b7cb772 (diff)
downloadlinux-next-history-a1e97ce80d9f41d0bb83951d758ff6fe49f3de60.tar.gz
bsg: add io_uring command support to generic layer
Add an io_uring command handler to the generic BSG layer. The new .uring_cmd file operation validates io_uring features and delegates handling to a per-queue bsg_uring_cmd_fn callback. Extend bsg_register_queue() so transport drivers can register both sg_io and io_uring command handlers. Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Link: https://patch.msgid.link/20260317072226.2598233-3-yangxiuwei@kylinos.cn Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r--block/bsg-lib.c2
-rw-r--r--block/bsg.c33
2 files changed, 33 insertions, 2 deletions
diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 20cd0ef3c394b..fdb4b290ca689 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -393,7 +393,7 @@ struct request_queue *bsg_setup_queue(struct device *dev, const char *name,
blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
- bset->bd = bsg_register_queue(q, dev, name, bsg_transport_sg_io_fn);
+ bset->bd = bsg_register_queue(q, dev, name, bsg_transport_sg_io_fn, NULL);
if (IS_ERR(bset->bd)) {
ret = PTR_ERR(bset->bd);
goto out_cleanup_queue;
diff --git a/block/bsg.c b/block/bsg.c
index e0af6206ed287..82aaf3cee5825 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -12,6 +12,7 @@
#include <linux/idr.h>
#include <linux/bsg.h>
#include <linux/slab.h>
+#include <linux/io_uring/cmd.h>
#include <scsi/scsi.h>
#include <scsi/scsi_ioctl.h>
@@ -28,6 +29,7 @@ struct bsg_device {
unsigned int timeout;
unsigned int reserved_size;
bsg_sg_io_fn *sg_io_fn;
+ bsg_uring_cmd_fn *uring_cmd_fn;
};
static inline struct bsg_device *to_bsg_device(struct inode *inode)
@@ -158,11 +160,38 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
}
}
+static int bsg_check_uring_features(unsigned int issue_flags)
+{
+ /* BSG passthrough requires big SQE/CQE support */
+ if ((issue_flags & (IO_URING_F_SQE128|IO_URING_F_CQE32)) !=
+ (IO_URING_F_SQE128|IO_URING_F_CQE32))
+ return -EOPNOTSUPP;
+ return 0;
+}
+
+static int bsg_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags)
+{
+ struct bsg_device *bd = to_bsg_device(file_inode(ioucmd->file));
+ bool open_for_write = ioucmd->file->f_mode & FMODE_WRITE;
+ struct request_queue *q = bd->queue;
+ int ret;
+
+ ret = bsg_check_uring_features(issue_flags);
+ if (ret)
+ return ret;
+
+ if (!bd->uring_cmd_fn)
+ return -EOPNOTSUPP;
+
+ return bd->uring_cmd_fn(q, ioucmd, issue_flags, open_for_write);
+}
+
static const struct file_operations bsg_fops = {
.open = bsg_open,
.release = bsg_release,
.unlocked_ioctl = bsg_ioctl,
.compat_ioctl = compat_ptr_ioctl,
+ .uring_cmd = bsg_uring_cmd,
.owner = THIS_MODULE,
.llseek = default_llseek,
};
@@ -187,7 +216,8 @@ void bsg_unregister_queue(struct bsg_device *bd)
EXPORT_SYMBOL_GPL(bsg_unregister_queue);
struct bsg_device *bsg_register_queue(struct request_queue *q,
- struct device *parent, const char *name, bsg_sg_io_fn *sg_io_fn)
+ struct device *parent, const char *name, bsg_sg_io_fn *sg_io_fn,
+ bsg_uring_cmd_fn *uring_cmd_fn)
{
struct bsg_device *bd;
int ret;
@@ -199,6 +229,7 @@ struct bsg_device *bsg_register_queue(struct request_queue *q,
bd->reserved_size = INT_MAX;
bd->queue = q;
bd->sg_io_fn = sg_io_fn;
+ bd->uring_cmd_fn = uring_cmd_fn;
ret = ida_alloc_max(&bsg_minor_ida, BSG_MAX_DEVS - 1, GFP_KERNEL);
if (ret < 0) {