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, bvanassche@acm.org,
Yang Xiuwei <yangxiuwei@kylinos.cn>
Subject: [RFC PATCH v2 0/3] bsg: add io_uring command support for SCSI passthrough
Date: Thu, 15 Jan 2026 09:24:34 +0800 [thread overview]
Message-ID: <cover.1768439194.git.yangxiuwei@kylinos.cn> (raw)
This RFC series adds io_uring command support to the BSG (Block layer
SCSI Generic) driver, enabling asynchronous SCSI passthrough operations
via io_uring.
Motivation:
-----------
The current BSG interface uses ioctl() for SCSI passthrough, which is
synchronous and has limitations for high-performance applications. By
integrating with io_uring, we can provide:
1. Asynchronous I/O support for better scalability
2. Zero-copy I/O via io_uring fixed buffers
3. Better integration with modern async I/O frameworks
4. Reduced system call overhead
Design:
-------
The implementation follows the io_uring uring_cmd pattern used by other
drivers (e.g., nvme). Key design decisions:
1. UAPI Structure: A new bsg_uring_cmd structure is defined that fits
within the 80-byte cmd field of a 128-byte SQE, with 24 bytes reserved
for future extensions. The structure uses protocol-agnostic field names
to support multiple protocols beyond SCSI.
2. Status Information: SCSI status (device_status, host_status,
driver_status, sense_len, resid_len) is returned in the CQE res2 field
using a compact 64-bit encoding.
3. Zero-copy Support: The implementation supports both traditional
user buffers and io_uring fixed buffers for zero-copy I/O.
4. Async Completion: Command completion is handled via task work to
safely access user space and copy sense data.
5. Non-blocking I/O: Support for IO_URING_F_NONBLOCK flag to enable
non-blocking command submission.
Limitations:
-----------
- Currently only SCSI commands are supported (BSG_PROTOCOL_SCSI)
- Scatter/gather I/O (iovec arrays) is not currently supported, but
the data structure includes fields for future implementation.
- Bidirectional transfers are not supported (consistent with existing
BSG behavior).
Testing:
--------
A user-space test program has been developed to validate the
implementation, including:
- Basic SCSI commands (INQUIRY, READ CAPACITY (10), READ (10),
WRITE (10))
- Zero-copy mode using fixed buffers
- Error handling (invalid flags, unsupported features)
The test program is available separately and can be provided upon request.
Changes since v1:
-----------------
- Renamed SCSI-specific fields (cdb_addr/cdb_len) to protocol-agnostic
names (request/request_len) to support multiple protocols beyond SCSI
- Removed __packed attribute and optimized field alignment to avoid
suboptimal code generation on architectures that don't support unaligned
accesses
- Simplified data transfer structure: unified din_xferp/dout_xferp into a
single xfer_addr field with xfer_dir to indicate direction (0=read, 1=write),
consistent with existing BSG behavior where bidirectional transfers are not
supported
- Updated implementation to use new protocol-agnostic field names
Yang Xiuwei (3):
bsg: add bsg_uring_cmd uapi structure
bsg: add uring_cmd support to BSG generic layer
bsg: implement SCSI BSG uring_cmd handler
block/bsg.c | 28 +++++
drivers/scsi/scsi_bsg.c | 222 +++++++++++++++++++++++++++++++++++++++
include/linux/bsg.h | 4 +
include/uapi/linux/bsg.h | 19 ++++
4 files changed, 273 insertions(+)
--
2.25.1
next reply other threads:[~2026-01-15 1:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 1:24 Yang Xiuwei [this message]
2026-01-15 1:24 ` [RFC PATCH v2 1/3] bsg: add bsg_uring_cmd uapi structure Yang Xiuwei
2026-01-15 1:24 ` [RFC PATCH v2 2/3] bsg: add uring_cmd support to BSG generic layer Yang Xiuwei
2026-01-15 1:24 ` [RFC PATCH v2 3/3] bsg: implement SCSI BSG uring_cmd handler Yang Xiuwei
2026-01-16 4:25 ` [RFC PATCH v3 0/3] bsg: add io_uring command support for SCSI passthrough Yang Xiuwei
2026-01-16 4:25 ` [RFC PATCH v3 1/3] bsg: add bsg_uring_cmd uapi structure Yang Xiuwei
2026-01-16 4:25 ` [RFC PATCH v3 2/3] bsg: add uring_cmd support to BSG generic layer Yang Xiuwei
2026-01-16 4:25 ` [RFC PATCH v3 3/3] bsg: implement SCSI BSG uring_cmd handler Yang Xiuwei
2026-01-16 4:52 ` [RFC PATCH v3 0/3] bsg: add io_uring command support for SCSI passthrough 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=cover.1768439194.git.yangxiuwei@kylinos.cn \
--to=yangxiuwei@kylinos.cn \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--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