Skip to content

sg: add v4 interface

Douglas Gilbert linux-scsi 22 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v25 Latest44 patches 0 repliesNew
  2. v2446 patches 0 repliesSuperseded
  3. v2146 patches 3 repliesSuperseded
Earlier versions · 19
VersionPostedPatchesRepliesStatus
v2046 patches1 replySuperseded
v1945 patches2 repliesSuperseded
v18 posting 2/283 patches1 replySuperseded
v18 posting 1/20 of 45 patches0 repliesSuperseded
v1745 patches7 repliesSuperseded
v1645 patches0 repliesSuperseded
v1545 patches1 replySuperseded
v1445 patches0 repliesSuperseded
v1345 patches15 repliesSuperseded
v121 of 44 patches0 repliesSuperseded
v1144 patches1 replySuperseded
v1040 patches0 repliesSuperseded
v940 patches0 repliesSuperseded
v838 patches0 repliesSuperseded
v738 patches33 repliesSuperseded
v637 patches4 repliesSuperseded
v523 patches19 repliesSuperseded
v422 patches5 repliesSuperseded
v320 patches42 repliesSuperseded

Changes in v25 from the cover letter

- refine "scsi: sg: Allow waiting for commands to complete on removed device" patch after discussion with author, see patch 43
- pick up block layer changes since lk 5.19
- point out that this patchset adds debugfs support that may hasten the retirement of /proc/scsi/sg/debug and friends

Patches in v25 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/44sg: move functions arounddrivers/scsi/sg.c+210 -2120 replies
2/44sg: remove typedefs, type+formatting cleanupdrivers/scsi/sg.c+218 -1750 replies
3/44sg: sg_log and is_enableddrivers/scsi/sg.c+126 -1250 replies
4/44sg: remove typedefs, type+formatting cleanupdrivers/scsi/sg.c+27 -320 replies
5/44sg: bitops in sg_devicedrivers/scsi/sg.c+50 -480 replies
6/44sg: make open count an atomicdrivers/scsi/sg.c+23 -210 replies
7/44sg: move header to uapi sectioninclude/scsi/sg.h include/uapi/scsi/sg.h+372 -2920 replies
8/44sg: speed sg_poll and sg_get_num_waitingdrivers/scsi/sg.c+27 -270 replies
9/44sg: sg_allow_if_err_recovery and renamesdrivers/scsi/sg.c+254 -2180 replies
10/44sg: change rwlock to spinlockdrivers/scsi/sg.c+29 -290 replies
11/44sg: ioctl handlingdrivers/scsi/sg.c+195 -1260 replies
12/44sg: split sg_readdrivers/scsi/sg.c+100 -940 replies
13/44sg: sg_common_write add structure for argumentsdrivers/scsi/sg.c+32 -150 replies
14/44sg: rework sg_vma_faultdrivers/scsi/sg.c+23 -100 replies
15/44sg: rework sg_mmapdrivers/scsi/sg.c+15 -100 replies
16/44sg: replace sg_allow_accessdrivers/scsi/sg.c+82 -680 replies
17/44sg: rework scatter gather handlingdrivers/scsi/sg.c+160 -1300 replies
18/44sg: introduce request state machinedrivers/scsi/sg.c+120 -560 replies
19/44sg: sg_find_srp_by_iddrivers/scsi/sg.c+229 -1160 replies
20/44sg: sg_fill_request_elementdrivers/scsi/sg.c+117 -940 replies
21/44sg: printk change %p to %pKdrivers/scsi/sg.c+14 -130 replies
22/44sg: xarray for fds in devicedrivers/scsi/sg.c+63 -460 replies
23/44sg: xarray for reqs in fddrivers/scsi/sg.c+232 -970 replies
24/44sg: replace rq array with xarraydrivers/scsi/sg.c+917 -5620 replies
25/44sg: sense buffer reworkdrivers/scsi/sg.c+89 -280 replies
26/44sg: add sg v4 interface supportdrivers/scsi/sg.c include/uapi/scsi/sg.h+394 -790 replies
27/44sg: rework debug infodrivers/scsi/sg.c+177 -780 replies
28/44sg: add 8 byte SCSI LUN to sg_scsi_iddrivers/scsi/sg.c include/uapi/scsi/sg.h+9 -40 replies
29/44sg: expand sg_comm_wr_tdrivers/scsi/sg.c+83 -790 replies
30/44sg: add sg_iosubmit_v3 and sg_ioreceive_v3 ioctlsdrivers/scsi/sg.c include/uapi/scsi/sg.h+81 -00 replies
31/44sg: move procfs objects to avoid forward declsdrivers/scsi/sg.c+60 -730 replies
32/44sg: protect multiple receiversdrivers/scsi/sg.c+39 -140 replies
33/44sg: first debugfs supportdrivers/scsi/sg.c+332 -720 replies
34/44sg: rework mmap supportdrivers/scsi/sg.c+109 -720 replies
35/44sg: defang allow_diodrivers/scsi/sg.c+7 -160 replies
36/44sg: warn v3 write system call usersdrivers/scsi/sg.c+3 -00 replies
37/44sg: add mmap_sz trackingdrivers/scsi/sg.c+13 -90 replies
38/44sg: track lowest inactive and await indexesdrivers/scsi/sg.c+256 -1650 replies
39/44sg: remove unit attention check for device changeddrivers/scsi/sg.c+12 -370 replies
40/44sg: no_dxfer: move to/from kernel buffersdrivers/scsi/sg.c+76 -20 replies
41/44sg: add bio_poll supportdrivers/scsi/sg.c include/uapi/scsi/sg.h+182 -240 replies
42/44sg: add statistics similar to stdrivers/scsi/sg.c+228 -320 replies
43/44sg: rework command completion when removed devicedrivers/scsi/sg.c+97 -830 replies
44/44sg: bump version to 4.0.14drivers/scsi/sg.c include/uapi/scsi/sg.h+9 -80 replies

Reviews trailers per patch

43 of 44 patches have a Reviewed-by or Acked-by.

PatchHannes ReineckeJohannes ThumshirnChristoph HellwigDamien Le Moal
1/44R-b
2/44R-b R-b R-b
3/44R-b
4/44R-b R-b R-b
5/44R-b
6/44R-b
7/44R-b
8/44R-b
9/44R-b
10/44R-b
11/44R-b
12/44R-b
13/44R-b
14/44R-b
15/44R-b
16/44R-b
17/44R-b
18/44R-b
19/44R-b
20/44R-b
21/44R-b
22/44R-b
23/44R-b
24/44R-b
25/44R-b
26/44R-b
27/44R-b
28/44R-b
29/44R-b
30/44R-b
31/44R-b
32/44R-b
33/44R-b
34/44R-b
35/44R-b
36/44R-b
37/44R-b
38/44R-b
39/44R-b
40/44R-b
41/44R-b
42/44R-b R-b
43/44
44/44R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v25 thread

Cover letter [PATCH v25 00/44] sg: add v4 interface

This patchset is the first stage of a two stage rewrite of the scsi generic (sg) driver. The main goal of the first stage is to introduce the sg v4 interface that uses 'struct sg_io_v4' as well as keeping and modernizing the sg v3 interface (based on 'struct sg_io_hdr'). The async interface formerly requiring the use of write() and read() system calls now has ioctl(SG_IOSUBMIT) and ioctl(SG_IORECEIVE) replacements. The sg v4 interface is not new, it has been used by the bsg driver since it was introduced to the kernel around 15 years ago.

For documentation see either url:

    https://sg.danny.cz/sg/sg_v40.html
    https://doug-gilbert.github.io/sg_v40.html

This driver has been tested with utilities found at:
https://github.com/doug-gilbert/sg3_utils
specifically sgh_dd found under the testing directory. The new statistics gathering facility can be tested with either sgstat or 'tapestat -g' using the author's clone of the sysstat package:
https://github.com/doug-gilbert/sysstat

This patchset is against Martin Petersen's 6.2/scsi-queue branch.

Changes since v24 (sent to linux-scsi list on 20220410)
- refine "scsi: sg: Allow waiting for commands to complete on removed device" patch after discussion with author, see patch 43
- pick up block layer changes since lk 5.19
- point out that this patchset adds debugfs support that may hasten the retirement of /proc/scsi/sg/debug and friends

Changes since v21 (sent to linux-scsi list on 20211003)
- versions 21, 22 and 23 failed under heavy load when the 'POLLED' flag (formerly 'HIPRI') was used. It took several kernel cycles for driver to successfully pass that area of the testing code. Bug fixes in the scsi_debug driver and most likely the block layer issues were the probable culprits
- rebase against lk 5.18.0-rc1
- introduce 'struct block_device *dummy_bdev' in struct sg_device to circumvent the block API shut-out of char devices using bio_poll(). bio_poll() was formerly called blk_poll(). The dummy block_device object is only associated with a sg_device the first time a SGV4_FLAG_POLLED flag is set on a pass-through command. So only sg devices that actually use bio_poll() are burdened with carrying a block_device object. The dummy block_device object only holds parameters like the request_queue that were formerly given directly to blk_poll(). The NVMe pass-through will face the same problem if it tries to use bio_poll()

Changes since v20 (sent to linux-scsi list on 20210915)
- apply changes requested by Damien Le Moal to '[PATCH v21 00/46] sg: add statistics similar to st' patch. Drop comp_stats option; statistics always gathered
- fix broken usage of scsi_cmd_allowed() introduced in

    lk 5.15.0-rc1

Changes since v19 (sent to linux-scsi list on 20210523)
- add statistics gathering similar to that found in st driver. The tapestat utility in the sysstat package can be used to display those statistics; similar arrangement for the sg driver. Make changes suggested by Damien Le Moal.
- rebase on 5.16/scsi-queue branch [lk 5.15.0-rc1]
- gendisk dependency removed
- various other Christoph Hellwig cleanups

Changes since v18 (sent to linux-scsi list on 20210407)
- a request queue's QUEUE_FLAG_POLL flag can be cleared via sysfs, overriding the ability to use blk_poll() even when the associated LLD allows it. Check that flag and, only when it is set and the sg user gives SGV4_FLAG_HIPRI, set REQ_HIPRI on a request.
- simplify the functions supporting ioctl(SG_SET_RESERVED_SIZE)
- replace blk_rq_append_bio() calls with the simpler

    blk_rq_bio_prep() calls
    [see lk: a4fe2d3afe3ce77edeadb567c0d0a8d102c6b159]

- rebase on 5.14/scsi-queue branch [lk 5.13.0-rc1]
- unchecked_isa_dma removed
- BIO_MAX_PAGES renamed to BIO_MAX_VECS

Changes since v17 (sent to linux-scsi list on 20210407)
- make clearer distinction between user pollable (i.e. async) requests and (user) non-pollable requests (e.g. those injected with ioctl(SG_IO), IOWs sync requests)
- fix crash is sg_start_req() when blk_get_request() yields an error (e.g. -EAGAIN when low on resources)
- sg_finish_scsi_blk_rq(): remove now_zero variable as suggested by Hannes R.
- change deprecation warning url reference from http to https

Changes since v16 (sent to linux-scsi list on 20210208)
- sg_start_req() fix double free on error path [KASAN]
- sg_rq_map_kern() fix uninitialized variable [coverity]
- sg_add_sfp() fix use after free [coverity]
- sg_remove_sfp_usercontext(): remove pointless NULL check [coverity]
- fix misuse of WARN_ONCE in sg_rq_end_io_usercontext() [D. Carpenter]
- remove unused error checks: tracking blk_put_request() calls and multiple SG_XA_RQ_FREE calls
- hipri: as blk_poll() can return > 0 for requests other than the one that is being checked for, need to re-check that request is ready
- rebased on MKP's 5.13/scsi-queue

Changes since v15 (sent to linux-scsi list on 20210125)
- tweak state machine which sets INFLIGHT state _before_ blk_execute_rq_nowait() is called. Add a bit flag that indicates the logic flow has returned from that call. This guards against blk_poll() being called before the block layer has really launched the request.
- fix bug clearing SG_FFD_HIPRI_SEEN bit as atomic_dec_and_test() returns true when the post-decrement value is zero, the opposite of what a C conditional does.

Changes since v14 and earlier
- see: the v18 patchset sent to linux-scsi on 20210427

Douglas Gilbert (44):
sg: move functions around
sg: remove typedefs, type+formatting cleanup
sg: sg_log and is_enabled
sg: remove typedefs, type+formatting cleanup
sg: bitops in sg_device
sg: make open count an atomic
sg: move header to uapi section
sg: speed sg_poll and sg_get_num_waiting
sg: sg_allow_if_err_recovery and renames
sg: change rwlock to spinlock
sg: ioctl handling
sg: split sg_read
sg: sg_common_write add structure for arguments
sg: rework sg_vma_fault
sg: rework sg_mmap
sg: replace sg_allow_access
sg: rework scatter gather handling
sg: introduce request state machine
sg: sg_find_srp_by_id
sg: sg_fill_request_element
sg: printk change %p to %pK
sg: xarray for fds in device
sg: xarray for reqs in fd
sg: replace rq array with xarray
sg: sense buffer rework
sg: add sg v4 interface support
sg: rework debug info
sg: add 8 byte SCSI LUN to sg_scsi_id
sg: expand sg_comm_wr_t
sg: add sg_iosubmit_v3 and sg_ioreceive_v3 ioctls
sg: move procfs objects to avoid forward decls
sg: protect multiple receivers
sg: first debugfs support
sg: rework mmap support
sg: defang allow_dio
sg: warn v3 write system call users
sg: add mmap_sz tracking
sg: track lowest inactive and await indexes
sg: remove unit attention check for device changed
sg: no_dxfer: move to/from kernel buffers
sg: add bio_poll support
sg: add statistics similar to st
sg: rework command completion when removed device
sg: bump version to 4.0.14

 drivers/scsi/sg.c      | 5607 ++++++++++++++++++++++++++++------------
 include/scsi/sg.h      |  301 +--
 include/uapi/scsi/sg.h |  408 +++
 3 files changed, 4358 insertions(+), 1958 deletions(-)
 create mode 100644 include/uapi/scsi/sg.h
Signature · 1 line
2.37.3