[PATCH v4 0/4] scsi: release completed passthrough requests before user copyback

From: Yingjie Wang

Date: Wed Nov 18 2026 - 03:33:29 EST


Four synchronous SCSI passthrough paths copy data to userspace, or unmap
a user buffer that needs copyback, while they still hold the completed
request. If that user access faults and the fault needs I/O from the
same queue, the task can wait for a tag held by the request it would
only release after the fault returns.

Each patch saves what the copyback still needs (the result, bounded
sense data and, where a user buffer is mapped, the BIO chain saved at
mapping time), releases the request, and then performs the user
copyback:

1/4 SG_IO on a SCSI block device (scsi_ioctl.c)
2/4 the legacy SCSI_IOCTL_SEND_COMMAND ioctl (scsi_ioctl.c)
3/4 CDROMREADAUDIO through sr_read_cdda_bpc() (sr.c)
4/4 the synchronous BSG ioctl (scsi_bsg.c)

Changes since RFC v3:

- Dropped the RFC tag and the io_uring half. RFC v3 5/6 and 6/6
changed the asynchronous BSG path; after review they are being
reworked to use a completion-buffer pool owned by bsg and will be
posted as a separate series.
- 1/4 to 4/4 are RFC v3 1/6 to 4/6, unchanged apart from rebasing onto
9f9e0b1e5399 from 7.4/scsi-fixes, which applied without edits.

Testing on this tip and, for comparison, on the unpatched base, both
with KASAN and lockdep, in QEMU with a virtio-scsi disk and CD-ROM:

- 20 iterations of the existing regression pass 960 assertions on both
kernels with no kernel warnings: 220 for the synchronous paths
(SG_IO, SCSI_IOCTL_SEND_COMMAND, BSG and CDDA) and 740 for the
io_uring path, which this series does not change.
- Tracing the 80 SG_IO, BSG and CDDA commands that map a user buffer
shows the request freed before blk_rq_unmap_user() on this tip, and
after it on the base kernel, in every case. The legacy ioctl has no
user mapping to trace, so it is covered by the functional assertions
only. These tests check the release order, not the hang itself.
- The CDDA cases exercise the virtual CD-ROM's expected error path, not
audio extraction from real media.
- Each commit builds with W=1 on x86-64; the tip also builds on i386,
which was not booted.

All four patches carry Fixes: d285203cf647 ("scsi: add support for a
blk-mq based I/O path.") and Cc: stable.

v1: https://lore.kernel.org/r/cover.1792237341.git.x-professor@xxxxxxxxxxx
v2: https://lore.kernel.org/r/cover.1793003363.git.x-professor@xxxxxxxxxxx
RFC v3: https://lore.kernel.org/r/cover.1794045010.git.x-professor@xxxxxxxxxxx

Yingjie Wang (4):
scsi: core: release SG_IO request before user copyback
scsi: core: release legacy ioctl request before user copyback
scsi: sr: release CDDA request before user copyback
scsi: bsg: release synchronous request before user copyback

drivers/scsi/scsi_bsg.c | 22 ++++++++++++++--------
drivers/scsi/scsi_ioctl.c | 34 ++++++++++++++++++++++++----------
drivers/scsi/sr.c | 3 +++
3 files changed, 41 insertions(+), 18 deletions(-)


base-commit: 9f9e0b1e5399045982788a954d3461de894e40c7
--
2.43.0