[PATCH v5 0/4] scsi: Release completed passthrough requests before user copyback
From: Yingjie Wang
Date: Sat Nov 21 2026 - 03:27:26 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 access faults and needs I/O from the same queue, the
task can wait for a tag held by the request it would release only after
the fault returns.
Each patch saves the completion state needed for copyback, releases the
request, then performs the user access:
1/4 SG_IO on a SCSI block device
2/4 the legacy SCSI_IOCTL_SEND_COMMAND ioctl
3/4 CDROMREADAUDIO through sr_read_cdda_bpc()
4/4 the synchronous BSG ioctl
This series addresses the completion side only. As Bart pointed out,
these paths also access user memory after allocating a request and
before submitting it. Without an I/O scheduler, that request already
holds a driver tag, so a fault needing I/O from the same exhausted tag
pool can encounter a similar dependency. The submission-side ordering
is unchanged here.
Moving CDB copies before request allocation would not address faults
in blk_rq_map_user*(), which needs an allocated request. Addressing
that dependency requires a different approach and is outside this
series.
Changes in v5:
- Document that scsi_complete_sghdr_rq() frees its request, as requested
by Bart Van Assche.
- Set rq to NULL after the legacy ioctl's early free and use conditional
cleanup, removing the extra success-path goto, as suggested by Bart.
- Clarify the completion-side scope and tag dependency. Patches 3 and 4
have no functional changes.
Tested on 9f9e0b1e5399 with QEMU, a virtio-scsi disk and CD-ROM,
KASAN and lockdep. The base and v5 each passed 960 regression checks,
including 220 synchronous checks. Tracing covered 100 synchronous
windows: 80 showed v5 releasing the request before unmapping, while
the base retained it; 20 checked legacy ioctl execution and release.
CDDA coverage exercised EIO and release ordering, not successful audio
extraction. The unchanged io_uring path still retained its request
until task work, as expected. No page-fault deadlock was reproduced.
Each patch passed an x86_64 W=1 build of the affected objects. Kernel
selftests were not run.
The BSG io_uring completion fix remains a separate two-patch series,
which applies on top of these four patches.
v4: https://lore.kernel.org/r/cover.1794990780.git.x-professor@xxxxxxxxxxx
RFC v3: https://lore.kernel.org/r/cover.1794045010.git.x-professor@xxxxxxxxxxx
Bart's scope question:
https://lore.kernel.org/r/3dcb1a44-6e99-4d34-9b49-675d98c90da1@xxxxxxx
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 | 23 ++++++++++++++--------
drivers/scsi/scsi_ioctl.c | 41 ++++++++++++++++++++++++++++-----------
drivers/scsi/sr.c | 3 +++
3 files changed, 48 insertions(+), 19 deletions(-)
base-commit: 9f9e0b1e5399045982788a954d3461de894e40c7
--
2.43.0