linux/drivers/ata
Damien Le Moal 0ea84089db ata: libata-scsi: avoid Non-NCQ command starvation
When a non-NCQ command is issued while NCQ commands are being executed,
ata_scsi_qc_issue() indicates to the SCSI layer that the command issuing
should be deferred by returning SCSI_MLQUEUE_XXX_BUSY.  This command
deferring is correct and as mandated by the ACS specifications since
NCQ and non-NCQ commands cannot be mixed.

However, in the case of a host adapter using multiple submission queues,
when the target device is under a constant load of NCQ commands, there
are no guarantees that requeueing the non-NCQ command will be executed
later and it may be deferred again repeatedly as other submission queues
can constantly issue NCQ commands from different CPUs ahead of the
non-NCQ command. This can lead to very long delays for the execution of
non-NCQ commands, and even complete starvation for these commands in the
worst case scenario.

Since the block layer and the SCSI layer do not distinguish between
queueable (NCQ) and non queueable (non-NCQ) commands, libata-scsi SAT
implementation must ensure forward progress for non-NCQ commands in the
presence of NCQ command traffic. This is similar to what SAS HBAs with a
hardware/firmware based SAT implementation do.

Implement such forward progress guarantee by limiting requeueing of
non-NCQ commands from ata_scsi_qc_issue(): when a non-NCQ command is
received and NCQ commands are in-flight, do not force a requeue of the
non-NCQ command by returning SCSI_MLQUEUE_XXX_BUSY and instead return 0
to indicate that the command was accepted but hold on to the qc using
the new deferred_qc field of struct ata_port.

This deferred qc will be issued using the work item deferred_qc_work
running the function ata_scsi_deferred_qc_work() once all in-flight
commands complete, which is checked with the port qc_defer() callback
return value indicating that no further delay is necessary. This check
is done using the helper function ata_scsi_schedule_deferred_qc() which
is called from ata_scsi_qc_complete(). This thus excludes this mechanism
from all internal non-NCQ commands issued by ATA EH.

When a port deferred_qc is non NULL, that is, the port has a command
waiting for the device queue to drain, the issuing of all incoming
commands (both NCQ and non-NCQ) is deferred using the regular busy
mechanism. This simplifies the code and also avoids potential denial of
service problems if a user issues too many non-NCQ commands.

Finally, whenever ata EH is scheduled, regardless of the reason, a
deferred qc is always requeued so that it can be retried once EH
completes. This is done by calling the function
ata_scsi_requeue_deferred_qc() from ata_eh_set_pending(). This avoids
the need for any special processing for the deferred qc in case of NCQ
error, link or device reset, or device timeout.

Reported-by: Xingui Yang <yangxingui@huawei.com>
Reported-by: Igor Pylypiv <ipylypiv@google.com>
Fixes: bdb01301f3 ("scsi: Add host and host template flag 'host_tagset'")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Tested-by: Igor Pylypiv <ipylypiv@google.com>
Tested-by: Xingui Yang <yangxingui@huawei.com>
2026-01-14 19:07:14 +09:00
..
pata_parport ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
acard-ahci.c ata: ahci: Replace deprecated PCI functions 2024-10-30 16:07:36 -05:00
ahci.c ata: ahci: Allow ignoring the external/hotplug capability of ports 2025-08-26 07:44:32 +09: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: Introduce ahci_ignore_port() helper 2025-01-09 17:52:17 +09:00
ahci_ceva.c ahci: Introduce ahci_ignore_port() helper 2025-01-09 17:52:17 +09:00
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 ata: ahci-dwc: Simplify with scoped for each OF child loop 2026-01-08 17:42:56 +09:00
ahci_imx.c ata: ahci-imx: Fix Wvoid-pointer-to-enum-cast warning 2026-01-08 17:43:00 +09:00
ahci_mtk.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
ahci_mvebu.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
ahci_octeon.c ata: ahci_octeon: Convert to devm_platform_ioremap_resource() 2023-08-02 17:37:06 +09:00
ahci_platform.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
ahci_qoriq.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
ahci_seattle.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
ahci_st.c ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() 2025-01-15 15:21:27 +01:00
ahci_sunxi.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
ahci_tegra.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
ahci_xgene.c ata: ahci-xgene: Fix Wvoid-pointer-to-enum-cast warning 2026-01-08 17:43:04 +09:00
ata_generic.c ata: Constify struct pci_device_id 2024-12-03 05:10:20 +01:00
ata_piix.c ata: libata-sata: Add link_power_management_supported sysfs attribute 2025-07-31 12:56:21 +09:00
Kconfig ata: Fix SATA_MOBILE_LPM_POLICY description in Kconfig 2025-06-30 10:25:45 +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 scsi: ata: Stop disk on restart if ACPI power resources are found 2025-11-08 13:24:56 -05:00
libata-core.c ata: libata-scsi: avoid Non-NCQ command starvation 2026-01-14 19:07:14 +09:00
libata-eh.c ata: libata-scsi: avoid Non-NCQ command starvation 2026-01-14 19:07:14 +09:00
libata-pata-timings.c ata: separate PATA timings code from libata-core.c 2020-03-26 10:28:19 -06:00
libata-pmp.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
libata-sata.c ata: libata-sata: Add link_power_management_supported sysfs attribute 2025-07-31 12:56:21 +09:00
libata-scsi.c ata: libata-scsi: avoid Non-NCQ command starvation 2026-01-14 19:07:14 +09:00
libata-sff.c ata: libata-sff: add WQ_PERCPU to alloc_workqueue users 2025-11-07 09:42:36 +01:00
libata-trace.c ata: scsi: rename flag ATA_QCFLAG_FAILED to ATA_QCFLAG_EH 2023-01-04 13:36:26 +09:00
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 ata,scsi: Remove wrappers ata_sas_tport_{add,delete}() 2024-07-04 11:52:31 +02:00
libata-zpodd.c ata: libata-zpodd: convert timeouts to secs_to_jiffies() 2025-03-17 12:16:58 -07:00
libata.h ata: libata-scsi: avoid Non-NCQ command starvation 2026-01-14 19:07:14 +09:00
Makefile ATA changes for 6.3-rc1 2023-02-22 13:35:51 -08: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 ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
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 ata: Constify struct pci_device_id 2024-12-03 05:10:20 +01:00
pata_buddha.c ata: pata_buddha: Remove #include <asm/ide.h> 2023-08-24 08:09:59 +09:00
pata_cmd64x.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cmd640.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cs5520.c ata: pata_cs5520: Rephrase file header comment 2024-07-30 07:10:30 +09:00
pata_cs5530.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cs5535.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cs5536.c ata: pata_cs5536: fix build on 32-bit UML 2025-06-10 14:26:27 +02:00
pata_cypress.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
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 ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
pata_ftide010.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
pata_gayle.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
pata_hpt3x2n.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_hpt3x3.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
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 ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
pata_isapnp.c ata: pata_isapnp: Add missing error check for devm_ioport_map() 2023-11-20 09:22:26 +09:00
pata_it821x.c ata: pata_it821x: Replace deprecated strcpy with strscpy in it821x_display_disk 2025-10-23 14:23:40 +02:00
pata_it8213.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_ixp4xx_cf.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
pata_jmicron.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_legacy.c ata: pata_legacy: make legacy_exit() work again 2024-05-07 07:23:31 +09:00
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 ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
pata_mpiix.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_netcell.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_ninja32.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_ns87410.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_ns87415.c ata: pata_ns87415: mark ns87560_tf_read static 2023-07-28 08:52:42 +09:00
pata_octeon_cf.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_of_platform.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
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: pata_pcmcia: Add Iomega Clik! PCMCIA ATA/ATAPI Adapter 2025-11-18 21:58:41 +01:00
pata_pdc202xx_old.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_pdc2027x.c ata: pata_pdc2027x: Remove space before newline and abbreviations 2025-08-01 08:43:11 +09:00
pata_piccolo.c ata: Constify struct pci_device_id 2024-12-03 05:10:20 +01:00
pata_platform.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
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 ata: Fix typos in the comment 2024-10-01 09:22:02 +02:00
pata_rb532_cf.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
pata_rdc.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_rz1000.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_sc1200.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_sch.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_serverworks.c ata: pata_serverworks: Do not use the term blacklist 2024-07-30 07:10:08 +09:00
pata_sil680.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
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 ata: sata_gemini: Remove remaining reset glue 2024-12-16 22:36:27 +09:00
sata_gemini.h ata: sata_gemini: Remove unused gemini_sata_reset_bridge() 2024-12-11 13:18:25 +09:00
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 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
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 ata: Use always-managed version of pci_intx() 2025-01-18 14:38:49 -06:00
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 ata: Use always-managed version of pci_intx() 2025-01-18 14:38:49 -06:00
sis.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00