Skip to content

scsi: release completed passthrough requests before user copyback

Yingjie Wang linux-scsi lkml 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest4 patches 3 repliesIn review
  2. v3 RFC6 patches 4 repliesSuperseded
  3. v26 patches 5 repliesSuperseded

Changes in v4 from the cover letter

- 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.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4scsi: core: release SG_IO request before user copybackdrivers/scsi/scsi_ioctl.c+12 -41 reply
2/4scsi: core: release legacy ioctl request before user copybackdrivers/scsi/scsi_ioctl.c+12 -62 replies
3/4scsi: sr: release CDDA request before user copybackdrivers/scsi/sr.c+3 -00 replies
4/4scsi: bsg: release synchronous request before user copybackdrivers/scsi/scsi_bsg.c+14 -80 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

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

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/[email protected]
v2: https://lore.kernel.org/r/[email protected]
RFC v3: https://lore.kernel.org/r/[email protected]

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

Signature · 1 line
2.43.0