umber-kernel/drivers/ata
Henry Tseng 9443fe6d05 ata: libata: avoid long timeouts on hot-unplugged SATA DAS
[ Upstream commit 151cabd140322205e27dae5c4bbf261ede0056e3 ]

When a SATA DAS enclosure is connected behind a Thunderbolt PCIe
switch, hot-unplugging the whole enclosure causes pciehp to tear down
the PCI hierarchy before the SCSI layer issues SYNCHRONIZE CACHE and
START STOP UNIT for the disks.

libata still queues these commands and the AHCI driver tries to access
the HBA registers even though the PCI channel is already offline. This
results in a series of timeouts and error recovery attempts, e.g.:

  [  824.778346] pcieport 0000:00:07.0: pciehp: Slot(14): Link Down
  [  891.612720] ata8.00: qc timeout after 5000 msecs (cmd 0xec)
  [  902.876501] ata8.00: qc timeout after 10000 msecs (cmd 0xec)
  [  934.107998] ata8.00: qc timeout after 30000 msecs (cmd 0xec)
  [  936.206431] sd 7:0:0:0: [sda] Synchronize Cache(10) failed:
      Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
  ...
  [ 1006.298356] ata1.00: qc timeout after 5000 msecs (cmd 0xec)
  [ 1017.561926] ata1.00: qc timeout after 10000 msecs (cmd 0xec)
  [ 1048.791790] ata1.00: qc timeout after 30000 msecs (cmd 0xec)
  [ 1050.890035] sd 0:0:0:0: [sdb] Synchronize Cache(10) failed:
      Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK

With this patch applied, the same hot-unplug looks like:

  [   59.965496] pcieport 0000:00:07.0: pciehp: Slot(14): Link Down
  [   60.002502] sd 7:0:0:0: [sda] Synchronize Cache(10) failed:
      Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
  ...
  [   60.103050] sd 0:0:0:0: [sdb] Synchronize Cache(10) failed:
      Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK

In this test setup with two disks, the hot-unplug sequence shrinks from
about 226 seconds (~3.8 minutes) between the Link Down event and the
last SYNCHRONIZE CACHE failure to under a second. Without this patch the
total delay grows roughly with the number of disks, because each disk
gets its own SYNCHRONIZE CACHE and qc timeout series.

If the underlying PCI device is already gone, these commands cannot
succeed anyway. Avoid issuing them by introducing
ata_adapter_is_online(), which checks pci_channel_offline() for
PCI-based hosts. It is used from ata_scsi_find_dev() to return NULL,
causing the SCSI layer to fail new commands with DID_BAD_TARGET
immediately, and from ata_qc_issue() to bail out before touching the
HBA registers.

Since such failures would otherwise trigger libata error handling,
ata_adapter_is_online() is also consulted from ata_scsi_port_error_handler().
When the adapter is offline, libata skips ap->ops->error_handler(ap) and
completes error handling using the existing path, rather than running
a full EH sequence against a dead adapter.

With this change, SYNCHRONIZE CACHE and START STOP UNIT commands
issued during hot-unplug fail quickly once the PCI channel is offline,
without qc timeout spam or long libata EH delays.

Suggested-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Henry Tseng <henrytseng@qnap.com>
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2026-03-04 07:20:28 -05:00
..
pata_parport ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
Kconfig ata: Fix SATA_MOBILE_LPM_POLICY description in Kconfig 2025-06-30 10:25:45 +09:00
Makefile
acard-ahci.c
ahci.c ata: ahci: Do not read the per port area for unimplemented ports 2026-01-30 10:32:09 +01:00
ahci.h ata: ahci: Allow ignoring the external/hotplug capability of ports 2025-08-26 07:44:32 +09:00
ahci_brcm.c
ahci_ceva.c
ahci_da850.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
ahci_dm816.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
ahci_dwc.c
ahci_imx.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
ahci_mtk.c
ahci_mvebu.c
ahci_octeon.c
ahci_platform.c
ahci_qoriq.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
ahci_seattle.c
ahci_st.c
ahci_sunxi.c
ahci_tegra.c
ahci_xgene.c ata: ahci_xgene: Use int type for 'rc' to store error codes 2025-08-28 13:36:14 +09:00
ata_generic.c
ata_piix.c ata: libata-sata: Add link_power_management_supported sysfs attribute 2025-07-31 12:56:21 +09:00
libahci.c ata: libata-sata: Add link_power_management_supported sysfs attribute 2025-07-31 12:56:21 +09:00
libahci_platform.c ata: libahci_platform: Do not set mask_port_map when not needed 2025-02-10 11:54:38 +01:00
libata-acpi.c ata: libata-acpi: Do not assume 40 wire cable if no devices are enabled 2025-06-10 14:08:24 +02:00
libata-core.c ata: libata: avoid long timeouts on hot-unplugged SATA DAS 2026-03-04 07:20:28 -05:00
libata-eh.c ata: libata: avoid long timeouts on hot-unplugged SATA DAS 2026-03-04 07:20:28 -05:00
libata-pata-timings.c
libata-pmp.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
libata-sata.c ata: libata-sata: Improve link_power_management_supported sysfs attribute 2026-01-30 10:32:09 +01:00
libata-scsi.c ata: libata: avoid long timeouts on hot-unplugged SATA DAS 2026-03-04 07:20:28 -05:00
libata-sff.c ata: libata-sff: drop nth_page() usage within SG entry 2025-09-21 14:22:07 -07:00
libata-trace.c
libata-transport.c ata: libata-transport: replace scnprintf with sysfs_emit for simple attributes 2025-07-09 15:48:17 +02:00
libata-transport.h
libata-zpodd.c ata: libata-zpodd: convert timeouts to secs_to_jiffies() 2025-03-17 12:16:58 -07:00
libata.h ata: libata: avoid long timeouts on hot-unplugged SATA DAS 2026-03-04 07:20:28 -05:00
pata_acpi.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_ali.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_amd.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_arasan_cf.c
pata_artop.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_atiixp.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_atp867x.c
pata_buddha.c
pata_cmd64x.c
pata_cmd640.c
pata_cs5520.c
pata_cs5530.c
pata_cs5535.c
pata_cs5536.c ata: pata_cs5536: fix build on 32-bit UML 2025-06-10 14:26:27 +02:00
pata_cypress.c
pata_efar.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_ep93xx.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_falcon.c
pata_ftide010.c ata: pata_ftide010: Fix some DMA timings 2026-02-26 14:59:45 -08:00
pata_gayle.c
pata_hpt3x2n.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_hpt3x3.c
pata_hpt37x.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_hpt366.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_icside.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_imx.c
pata_isapnp.c
pata_it821x.c
pata_it8213.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_ixp4xx_cf.c
pata_jmicron.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_legacy.c
pata_macio.c ata: pata_macio: Remove space before newline 2025-08-01 08:43:08 +09:00
pata_marvell.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_mpc52xx.c
pata_mpiix.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_netcell.c
pata_ninja32.c
pata_ns87410.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_ns87415.c
pata_octeon_cf.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_of_platform.c
pata_oldpiix.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_opti.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_optidma.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_pcmcia.c ata: libata-core: Rename ata_do_set_mode() 2025-07-04 10:36:00 +02:00
pata_pdc202xx_old.c
pata_pdc2027x.c ata: pata_pdc2027x: Remove space before newline and abbreviations 2025-08-01 08:43:11 +09:00
pata_piccolo.c
pata_platform.c
pata_pxa.c ata: pata_pxa: Fix potential NULL pointer dereference in pxa_ata_probe() 2025-04-08 12:36:03 +09:00
pata_radisys.c
pata_rb532_cf.c
pata_rdc.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_rz1000.c
pata_sc1200.c
pata_sch.c
pata_serverworks.c
pata_sil680.c
pata_sis.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_sl82c105.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_triflex.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_via.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pdc_adma.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_dwc_460ex.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_fsl.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_gemini.c
sata_gemini.h
sata_highbank.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_inic162x.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_mv.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_nv.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_promise.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_promise.h
sata_qstor.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_rcar.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_sil.c ata: libata-core: Rename ata_do_set_mode() 2025-07-04 10:36:00 +02:00
sata_sil24.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_sis.c
sata_svw.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_sx4.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_uli.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_via.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_vsc.c
sis.h