Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH v7 0/5] scsi: Refresh INQUIRY data and reprobe on rescan
@ 2026-10-14 22:00 Brian Bunker
  2026-10-14 22:00 ` [PATCH v7 1/5] scsi: core: Protect INQUIRY sysfs attributes with mutex Brian Bunker
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Brian Bunker @ 2026-10-14 22:00 UTC (permalink / raw)
  To: linux-scsi
  Cc: Martin K . Petersen, Martin K . Petersen, James.Bottomley,
	Hannes Reinecke, Bart Van Assche, krishna.kant, Brian Bunker

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

v6 cover-letter Message-ID: <20261012210511.16061-1-brian@purestorage.com>
v5 cover-letter Message-ID: <20260618233508.97960-1-brian@purestorage.com>
v4 cover-letter Message-ID: <20260530002019.47109-1-brian@purestorage.com>
v3 cover-letter Message-ID: <20260429224939.77082-1-brian@purestorage.com>
v2 cover-letter Message-ID: <20260429012733.40855-1-brian@purestorage.com>
v1 cover-letter Message-ID: <20260424215324.99045-1-brian@purestorage.com>

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        | 205 ++++++++++++++++++++++++++++++
 drivers/scsi/scsi_scan.c   | 250 +++++++++++++++++++++----------------
 drivers/scsi/scsi_sysfs.c  |  28 +++--
 include/scsi/scsi_device.h |  13 ++
 4 files changed, 377 insertions(+), 119 deletions(-)


base-commit: 2f4880c22e838d54eae9ab153b0f8dce60531bf1
-- 
2.56.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-10-14 22:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-14 22:00 [PATCH v7 0/5] scsi: Refresh INQUIRY data and reprobe on rescan Brian Bunker
2026-10-14 22:00 ` [PATCH v7 1/5] scsi: core: Protect INQUIRY sysfs attributes with mutex Brian Bunker
2026-10-14 22:12   ` sashiko-bot
2026-10-14 22:00 ` [PATCH v7 2/5] scsi: core: Add scsi_update_inquiry_data() for updating INQUIRY data Brian Bunker
2026-10-14 22:00 ` [PATCH v7 3/5] scsi: core: Refactor scsi_add_lun() to use scsi_update_inquiry_data() Brian Bunker
2026-10-14 22:00 ` [PATCH v7 4/5] scsi: core: Add device reprobe support to scsi_rescan_device() Brian Bunker
2026-10-14 22:17   ` sashiko-bot
2026-10-14 22:00 ` [PATCH v7 5/5] scsi: core: Handle reprobe for existing devices during SCSI scan Brian Bunker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox