linux/drivers/ata
Hengyu Liang bc8ce2cea5 ata: libata-scsi: do not lose CHECK CONDITION for failed ATAPI commands
Since commit 2e1d2e65e7 ("ata: libata-scsi: terminate deferred commands
on time out"), atapi_qc_complete() sets SAM_STAT_CHECK_CONDITION for a
failed command only if cmd->result is zero, so that the DID_TIME_OUT or
DID_REQUEUE host byte of a terminated command is preserved.

However, cmd->result can also be non-zero for a regular failed ATAPI
command completed through libata EH: ata_eh_analyze_tf() calls
ata_eh_decide_disposition(), that is, scsi_check_sense(), on the sense
data obtained with REQUEST SENSE, and scsi_check_sense() sets the SCSI
midlayer internal byte of the result for some sense codes, e.g.
SCSIML_STAT_TGT_FAILURE for ILLEGAL REQUEST with ASC 0x20 (INVALID
COMMAND OPERATION CODE) or 0x24 (INVALID FIELD IN CDB), or
SCSIML_STAT_MED_ERROR for MEDIUM ERROR with ASC 0x11 (UNRECOVERED READ
ERROR). For such commands, atapi_qc_complete() keeps the result as is and
the command completes with a GOOD status byte, even though it failed and
valid sense data is available.

As a result, passthrough users see these failed ATAPI commands as
successful. For example, with the emulated IDE CD-ROM drive of QEMU and
no medium loaded, a PLAY AUDIO MSF command issued with SG_IO completes
with status 0x00 (and no DRIVER_SENSE) instead of 0x02 (CHECK CONDITION)
with sense key ILLEGAL REQUEST, ASC/ASCQ 0x20/0x00, and the CDROM ioctls
CDROMPLAYTRKIND, CDROMSUBCHNL, CDROMPAUSE, CDROMRESUME, CDROMPLAYMSF and
CDROM_GET_MCN return 0 instead of -ENOMEDIUM or -EOPNOTSUPP.

Fix this by setting the status byte to SAM_STAT_CHECK_CONDITION whenever
the host byte is not set. Use set_status_byte() rather than overwriting
the whole result, so that the SCSI midlayer internal byte set by
scsi_check_sense() is preserved, as ata_scsi_qc_complete() already does
for ATA commands.

Fixes: 2e1d2e65e7 ("ata: libata-scsi: terminate deferred commands on time out")
Cc: stable@vger.kernel.org
Suggested-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Link: https://lore.kernel.org/r/20260929164135.266708-1-hengyul@cs.unc.edu
Signed-off-by: Niklas Cassel <cassel@kernel.org>
2026-09-30 10:42:26 +02:00
..
pata_parport ata: pata_parport: switch to dynamic root device 2026-04-27 11:38:16 +02:00
acard-ahci.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
ahci_brcm.c ahci: Introduce ahci_ignore_port() helper 2025-01-09 17:52:17 +09:00
ahci_ceva.c ata: ahci_ceva: fix error paths in ceva_ahci_platform_enable_resources() 2026-07-18 10:37:02 +09:00
ahci_da850.c ata: ahci_da850: use devm_platform_ioremap_resource() 2026-07-18 11:58:16 +09: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: Remove not-going-to-be-supported code for Baikal SoC 2026-02-24 15:29:57 +01:00
ahci_imx.c ata: libata: Document when host->eh_mutex should be held 2026-06-01 19:09:08 +02: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: use named initializers for acpi_device_id 2026-08-04 18:48:43 +09:00
ahci_qoriq.c ata: use named initializers for acpi_device_id 2026-08-04 18:48:43 +09:00
ahci_seattle.c ata: use named initializers for acpi_device_id 2026-08-04 18:48:43 +09: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 Replace <linux/mod_devicetable.h> by more specific <linux/device-id/*.h> (c files) 2026-07-03 07:38:17 +02:00
ahci_tegra.c ata: ahci_tegra: Explicitly specify PMC instance to use 2026-05-28 22:46:11 +02:00
ahci_xgene.c ata: use named initializers for acpi_device_id 2026-08-04 18:48:43 +09:00
ahci.c ata: ahci: work around lost interrupts on Marvell 88SE61xx 2026-09-02 07:00:09 +02:00
ahci.h ata: libata: Document when host->eh_mutex should be held 2026-06-01 19:09:08 +02:00
ata_generic.c ata: ata_generic: Don't store pci_device_id 2026-07-28 11:15:20 -05:00
ata_piix.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
Kconfig ata: pata_ep93xx: add COMPILE_TEST support 2026-06-02 11:47:45 +02:00
libahci_platform.c ata: libahci_platform: Fix device reference leak in ahci_platform_get_resources() 2026-09-16 07:22:53 +02:00
libahci.c ata: libahci: clear PxCLBU and PxFBU for AHCI_HFLAG_32BIT_ONLY 2026-09-15 11:13:31 +02:00
libata-acpi.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
libata-core.c ata: libata-core: Extend Samsung LPM quirk to AMD controllers 2026-09-21 13:08:58 +02:00
libata-eh.c ata changes for 7.3 2026-08-19 12:31:50 -07:00
libata-pata-timings.c
libata-pmp.c ata: libata-pmp: add JMicron JMS562 quirk 2026-06-10 11:39:37 +02:00
libata-sata.c ata: libata-sata: fix ata_scsi_lpm_supported() iteration 2026-07-29 10:55:11 +09:00
libata-scsi.c ata: libata-scsi: do not lose CHECK CONDITION for failed ATAPI commands 2026-09-30 10:42:26 +02:00
libata-sff.c ata: libata-sff: don't busy-wait for PIO data-in command completion 2026-07-21 08:55:31 +09: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: remove static variable ata_scsi_transport_template 2026-04-02 21:01:10 +02:00
libata-transport.h ata: libata-transport: remove static variable ata_scsi_transport_template 2026-04-02 21:01:10 +02:00
libata-zpodd.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
libata.h ata changes for 7.3 2026-08-19 12:31:50 -07:00
Makefile ata: libata: Document when host->eh_mutex should be held 2026-06-01 19:09:08 +02:00
pata_acpi.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
pata_ali.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_amd.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
pata_arasan_cf.c ata: libata: Document when host->eh_mutex should be held 2026-06-01 19:09:08 +02:00
pata_artop.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
pata_atiixp.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_atp867x.c ata: Drop unused assignments of pci_device_id driver data 2026-06-12 11:43:53 +02:00
pata_buddha.c SCSI misc on 20260821 2026-08-21 11:23:20 -07:00
pata_cmd64x.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
pata_cmd640.c ata: Drop unused assignments of pci_device_id driver data 2026-06-12 11:43:53 +02: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 ata: pata_cypress: fix typo in error message 2026-02-02 13:47:40 +09:00
pata_efar.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_ep93xx.c ata: pata_ep93xx: fix PIO fallback when DMA init fails 2026-07-23 16:40:05 +09:00
pata_falcon.c ata: Switch back to struct platform_driver::remove() 2024-10-17 09:55:08 +02:00
pata_ftide010.c ata: pata_ftide010: Fix some DMA timings 2026-02-04 12:23:23 +01: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 Replace <linux/mod_devicetable.h> by more specific <linux/device-id/*.h> (c files) 2026-07-03 07:38:17 +02:00
pata_isapnp.c ata: pata_isapnp: Drop unused assignments from pnp_device_id array 2026-06-10 09:41:26 +02: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: Drop unused assignments of pci_device_id driver data 2026-06-12 11:43:53 +02:00
pata_legacy.c ata: pata_legacy: remove VLB support 2026-02-02 13:47:37 +09:00
pata_macio.c ata: Drop unused assignments of pci_device_id driver data 2026-06-12 11:43:53 +02:00
pata_marvell.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_mpc52xx.c ata: pata_mpc52xx: Remove redundant dev_err() 2026-07-18 10:09:19 +09: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 ata: Drop unused assignments of pci_device_id driver data 2026-06-12 11:43:53 +02: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: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +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 ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
pata_pdc2027x.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02: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: use devres for DMA channel management 2026-07-23 16:40:05 +09:00
pata_radisys.c ata: Fix typos in the comment 2024-10-01 09:22:02 +02:00
pata_rb532_cf.c ata: pata_rb532_cf: use devm_platform_ioremap_resource() 2026-07-18 11:58:16 +09: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 ata: Drop unused assignments of pci_device_id driver data 2026-06-12 11:43:53 +02:00
pata_serverworks.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
pata_sil680.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_sis.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
pata_sl82c105.c ata: pata_sl82c105: fix bridge revision use-after-free 2026-08-07 00:55:53 +09:00
pata_triflex.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
pata_via.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
pdc_adma.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_dwc_460ex.c ata: sata_dwc_460ex: fix infinite loop in NCQ tag completion bit-scanning 2026-07-13 14:32:11 +09:00
sata_fsl.c ata: libata: Document when host->eh_mutex should be held 2026-06-01 19:09:08 +02:00
sata_gemini.c ata: sata_gemini: unwind clocks on IDE pinctrl errors 2026-07-03 13:44:18 +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: sata_highbank: use devm_platform_ioremap_resource 2026-07-18 11:58:16 +09:00
sata_inic162x.c ata: libata: Document when host->eh_mutex should be held 2026-06-01 19:09:08 +02:00
sata_mv.c ata changes for 7.3 2026-08-19 12:31:50 -07:00
sata_nv.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_promise.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_promise.h
sata_qstor.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_rcar.c ata: libata-eh: Simplify reset operation management 2025-07-16 09:31:43 +02:00
sata_sil.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_sil24.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_sis.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_svw.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_sx4.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_uli.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_via.c ata: Use named initializers for pci_device_id arrays 2026-06-12 11:44:30 +02:00
sata_vsc.c ata: Drop unused assignments of pci_device_id driver data 2026-06-12 11:43:53 +02:00
sis.h