From: Yang Xiuwei <yangxiuwei@kylinos.cn>
To: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
io-uring@vger.kernel.org
Cc: fujita.tomonori@lab.ntt.co.jp, axboe@kernel.dk,
James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com, Yang Xiuwei <yangxiuwei@kylinos.cn>
Subject: [RFC PATCH 2/3] bsg: add uring_cmd support to BSG generic layer
Date: Mon, 12 Jan 2026 16:46:05 +0800 [thread overview]
Message-ID: <20260112084606.570887-3-yangxiuwei@kylinos.cn> (raw)
In-Reply-To: <20260112084606.570887-1-yangxiuwei@kylinos.cn>
Add io_uring command handler to the generic BSG layer. This handler
validates that SQE128 and CQE32 flags are set (required for the command
structure and status information), then delegates to the SCSI-specific
handler.
The handler is registered via the file_operations.uring_cmd field.
Add function declaration in include/linux/bsg.h and a stub
implementation
in drivers/scsi/scsi_bsg.c to allow compilation.
Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
diff --git a/block/bsg.c b/block/bsg.c
index 72157a59b788..cdccf86b8673 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>
@@ -158,11 +159,38 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
}
}
+static int bsg_uring_cmd_checks(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));
+ struct request_queue *q = bd->queue;
+ bool open_for_write = ioucmd->file->f_mode & FMODE_WRITE;
+ int ret;
+
+ if (!q)
+ return -EINVAL;
+
+ ret = bsg_uring_cmd_checks(issue_flags);
+ if (ret)
+ return ret;
+
+ return scsi_bsg_uring_cmd(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,
};
diff --git a/drivers/scsi/scsi_bsg.c b/drivers/scsi/scsi_bsg.c
index a9a9ec086a7e..4399a25990fc 100644
--- a/drivers/scsi/scsi_bsg.c
+++ b/drivers/scsi/scsi_bsg.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/bsg.h>
+#include <linux/io_uring/cmd.h>
#include <scsi/scsi.h>
#include <scsi/scsi_ioctl.h>
#include <scsi/scsi_cmnd.h>
@@ -9,6 +10,12 @@
#define uptr64(val) ((void __user *)(uintptr_t)(val))
+int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *ioucmd,
+ unsigned int issue_flags, bool open_for_write)
+{
+ return -EOPNOTSUPP;
+}
+
static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
bool open_for_write, unsigned int timeout)
{
diff --git a/include/linux/bsg.h b/include/linux/bsg.h
index ee2df73edf83..68ec50b5e97c 100644
--- a/include/linux/bsg.h
+++ b/include/linux/bsg.h
@@ -7,6 +7,7 @@
struct bsg_device;
struct device;
struct request_queue;
+struct io_uring_cmd;
typedef int (bsg_sg_io_fn)(struct request_queue *, struct sg_io_v4 *hdr,
bool open_for_write, unsigned int timeout);
@@ -16,4 +17,7 @@ struct bsg_device *bsg_register_queue(struct request_queue *q,
bsg_sg_io_fn *sg_io_fn);
void bsg_unregister_queue(struct bsg_device *bcd);
+int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *ioucmd,
+ unsigned int issue_flags, bool open_for_write);
+
#endif /* _LINUX_BSG_H */
--
2.25.1
next prev parent reply other threads:[~2026-01-12 8:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-12 8:46 [RFC PATCH 0/3] bsg: add io_uring command support for SCSI passthrough Yang Xiuwei
2026-01-12 8:46 ` [RFC PATCH 1/3] bsg: add bsg_uring_cmd uapi structure Yang Xiuwei
2026-01-12 17:44 ` Bart Van Assche
2026-01-13 1:26 ` Yang Xiuwei
2026-01-12 8:46 ` Yang Xiuwei [this message]
2026-01-12 8:46 ` [RFC PATCH 3/3] bsg: implement SCSI BSG uring_cmd handler Yang Xiuwei
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 \
--in-reply-to=20260112084606.570887-3-yangxiuwei@kylinos.cn \
--to=yangxiuwei@kylinos.cn \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=io-uring@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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