scsi: Refresh INQUIRY data and reprobe on rescan
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v8 Latest5 patches 10 repliesIn review
- v75 patches 0 repliesSuperseded
- v65 patches 1 replySuperseded
Earlier versions · 4
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v5 | 5 patches | 7 replies | Applied | |
| v4 | 5 patches | 9 replies | Superseded | |
| v3 | 1 of 6 patches | 10 replies | Superseded | |
| v2 | 1 of 6 patches | 2 replies | Superseded |
Changes in v8 from the cover letter
- 1/5: Also take inquiry_mutex in the modalias attribute, and read sdev->type with READ_ONCE() in scsi_bus_uevent(), which gets a const device. Dropped Hannes' Reviewed-by.
- 2/5: Compute scsi_level and type in local variables and store each once with WRITE_ONCE(). Both are read without inquiry_mutex (the I/O path, upper-level drivers, scsi_bus_uevent()), and v7 stored an intermediate value first: the unincremented scsi_level, and the uncorrected type of a well-known LUN. Found while addressing the 1/5 comment, not by Sashiko.
- 4/5: Set the device offline after a failed device_reprobe() under state_mutex, so a concurrent __scsi_remove_device() cannot have SDEV_CANCEL or SDEV_DEL overwritten with SDEV_OFFLINE.
- 4/5: scsi_probe_lun() takes a rescan argument and, on a rescan, no longer writes the host's short_inquiry flag, the target's scsi_level or lun_in_cdb. These share words with bitfields that are written at runtime without a common lock (tmf_in_progress, cdl_enable); they are only set when a device is first probed.
- Rebased onto the current 7.4/scsi-staging; no conflicts.
Patches in v8 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | scsi: core: Protect INQUIRY sysfs attributes with mutexdrivers/ | +27 | 0 replies | |
| 2/5 | scsi: core: Add scsi_update_inquiry_data() for updating INQUIRY datadrivers/ include/ | +228 | 0 replies | |
| 3/5 | scsi: core: Refactor scsi_add_lun() to use scsi_update_inquiry_data()drivers/ | +29 | 0 replies | |
| 4/5 | scsi: core: Add device reprobe support to scsi_rescan_device()drivers/ | +119 | 0 replies | |
| 5/5 | scsi: core: Handle reprobe for existing devices during SCSI scandrivers/ | +10 | 0 replies |
Reviews trailers per patch
1 of 5 patches has a Reviewed-by or Acked-by.
| Patch | Hannes Reinecke |
|---|---|
| 1/5 | |
| 2/5 | |
| 3/5 | R-b |
| 4/5 | |
| 5/5 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v8 0/5] scsi: Refresh INQUIRY data and reprobe on rescan
This series teaches the SCSI rescan path to refetch standard INQUIRY data and reprobe the device when the peripheral qualifier or device type has changed. The motivating case is an ALUA target that transitions through the "unavailable" state and afterwards reports a different peripheral qualifier; today the kernel keeps the stale INQUIRY data and the device's sysfs attributes diverge from what the target reports.
1/5 serializes the INQUIRY-derived sysfs attributes under
sdev->inquiry_mutex so a concurrent reprobe cannot tear the read.
2/5 adds scsi_update_inquiry_data() as the single point that stores
INQUIRY data in sdev and updates the fields derived from it. Returns SCSI_INQ_REPROBE_NEEDED only when peripheral qualifier or device type changes, as these are the only fields that determine driver binding.
3/5 refactors scsi_add_lun() to use scsi_update_inquiry_data(), sharing
one implementation between initial-probe and reprobe paths.
4/5 teaches scsi_rescan_device() to refetch INQUIRY and reprobe the
device when scsi_update_inquiry_data() reports a change.
5/5 calls scsi_rescan_device() from the scan path for existing devices
so that a SCAN_LUNS pass refreshes them as well.
Changes since v7 (prompted by the Sashiko review of v7 unless noted):
- 1/5: Also take inquiry_mutex in the modalias attribute, and read sdev->type with READ_ONCE() in scsi_bus_uevent(), which gets a const device. Dropped Hannes' Reviewed-by.
- 2/5: Compute scsi_level and type in local variables and store each once with WRITE_ONCE(). Both are read without inquiry_mutex (the I/O path, upper-level drivers, scsi_bus_uevent()), and v7 stored an intermediate value first: the unincremented scsi_level, and the uncorrected type of a well-known LUN. Found while addressing the 1/5 comment, not by Sashiko.
- 4/5: Set the device offline after a failed device_reprobe() under state_mutex, so a concurrent __scsi_remove_device() cannot have SDEV_CANCEL or SDEV_DEL overwritten with SDEV_OFFLINE.
- 4/5: scsi_probe_lun() takes a rescan argument and, on a rescan, no longer writes the host's short_inquiry flag, the target's scsi_level or lun_in_cdb. These share words with bitfields that are written at runtime without a common lock (tmf_in_progress, cdl_enable); they are only set when a device is first probed.
- Rebased onto the current 7.4/scsi-staging; no conflicts.
Changes since v6 (all prompted by the Sashiko review of v6):
- 2/5: sdev->inquiry is now allocated once at its maximum size (256 bytes) and later updates are copied into it in place. v6 freed and replaced the buffer, which is a use-after-free for the helpers in scsi_device.h that read sdev->inquiry without a lock (scsi_device_tpgs(), scsi_device_protection(), ...). The fixed size also means a growing inquiry_len can never run past the buffer, and inq_len is clamped to 255 to fit the unsigned char inquiry_len.
- 2/5: Capability flags (removable, lockable, ppr, wdtr, sdtr, tagged_supported, simple_tags, soft_reset, is_ata, allow_restart) are now set only on the first call. Rewriting them on a live device undid adjustments made after probe (BLIST_NOT_LOCKABLE, usb-storage and scsi_ioctl clearing lockable, aacraid forcing tagged_supported, ...), and raced with runtime state bits in the same word. A rescan now updates the INQUIRY buffer, vendor/model/rev, PQ, type and scsi_level only. Dropped Hannes' Reviewed-by.
- 3/5: No code changes.
- 4/5: Rewritten. If the INQUIRY refresh fails, the rescan carries on with the existing data instead of skipping the VPD update and the driver rescan and returning success. The device handler rescan method is called in all cases again, as before this series. The get_device()/put_device() pair around device_reprobe() is removed:
callers hold a reference, and dropping the last one from scsi_evt_thread() would have run the release function from the work it cancels. The reprobe failure path now checks whether the device could actually be set offline before saying so. scsi_probe_lun() is now called for live devices, so it returns the INQUIRY length instead of storing it in sdev (the length is updated with the data under inquiry_mutex), and only writes lun_in_cdb and the target's scsi_level when they change. Dropped Hannes' Reviewed-by.
- 5/5: Rewritten. v6 allocated a second scsi_device when an initial scan found a device still in SDEV_CREATED, passed a length of 256 that truncated inquiry_len to 0, leaked a reference for pseudo devices, and called the driver rescan method without the device lock. The scan path is now unchanged apart from calling scsi_rescan_device() for an existing, fully set up device. Dropped Hannes' Reviewed-by.
- Build-tested every patch with gcc W=1, and the series with clang 23 and CONFIG_WARN_CONTEXT_ANALYSIS=y; no new warnings.
v7 cover-letter Message-ID: <[email protected]> v6 cover-letter Message-ID: <[email protected]> v5 cover-letter Message-ID: <[email protected]> v4 cover-letter Message-ID: <[email protected]> v3 cover-letter Message-ID: <[email protected]> v2 cover-letter Message-ID: <[email protected]> v1 cover-letter Message-ID: <[email protected]>
Brian Bunker (5):
scsi: core: Protect INQUIRY sysfs attributes with mutex
scsi: core: Add scsi_update_inquiry_data() for updating INQUIRY data
scsi: core: Refactor scsi_add_lun() to use scsi_update_inquiry_data()
scsi: core: Add device reprobe support to scsi_rescan_device()
scsi: core: Handle reprobe for existing devices during SCSI scan
drivers/scsi/scsi.c | 215 +++++++++++++++++++++++++++++ drivers/scsi/scsi_scan.c | 271 +++++++++++++++++++++---------------- drivers/scsi/scsi_sysfs.c | 37 +++-- include/scsi/scsi_device.h | 13 ++ 4 files changed, 410 insertions(+), 126 deletions(-)
base-commit: db8b4d2bf2d3e02b4ff78bbf69d00e11795840de
Signature · 1 line
2.56.0