linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ata: libata-core: Return sense data in descriptor format by default
@ 2024-08-12 15:15 Niklas Cassel
  2024-08-12 17:40 ` Christian Heusel
  2024-08-12 18:43 ` Niklas Cassel
  0 siblings, 2 replies; 9+ messages in thread
From: Niklas Cassel @ 2024-08-12 15:15 UTC (permalink / raw)
  To: Damien Le Moal, Niklas Cassel, Hannes Reinecke, Igor Pylypiv
  Cc: Martin K . Petersen, stable, Stephan Eisvogel, Christian Heusel,
	linux-ide

Sense data can be in either fixed format or descriptor format.

SAT-6 revision 1, 10.4.6 Control mode page, says that if the D_SENSE bit
is set to zero (i.e., fixed format sense data), then the SATL should
return fixed format sense data for ATA PASS-THROUGH commands.

A lot of user space programs incorrectly assume that the sense data is in
descriptor format, without checking the RESPONSE CODE field of the
returned sense data (to see which format the sense data is in).

The libata SATL has always kept D_SENSE set to zero by default.
(It is however possible to change the value using a MODE SELECT command.)

For failed ATA PASS-THROUGH commands, we correctly generated sense data
according to the D_SENSE bit. However, because of a bug, sense data for
successful ATA PASS-THROUGH commands was always generated in the
descriptor format.

This was fixed to consistently respect D_SENSE for both failed and
successful ATA PASS-THROUGH commands in commit 28ab9769117c ("ata:
libata-scsi: Honor the D_SENSE bit for CK_COND=1 and no error").

After commit 28ab9769117c ("ata: libata-scsi: Honor the D_SENSE bit for
CK_COND=1 and no error"), we started receiving bug reports that we broke
these user space programs (these user space programs must never have
encountered a failing command, as the sense data for failing commands has
always correctly respected D_SENSE, which by default meant fixed format).

Since a lot of user space programs seem to assume that the sense data is
in descriptor format (without checking the type), let's simply change the
default to have D_SENSE set to one by default.

That way:
-Broken user space programs will see no regression.
-Both failed and successful ATA PASS-THROUGH commands will respect D_SENSE,
 as per SAT-6 revision 1.
-Apparently it seems way more common for user space applications to assume
 that the sense data is in descriptor format, rather than fixed format.
 (A user space program should of course support both, and check the
 RESPONSE CODE field to see which format the returned sense data is in.)

Cc: stable@vger.kernel.org # 4.19+
Reported-by: Stephan Eisvogel <eisvogel@seitics.de>
Reported-by: Christian Heusel <christian@heusel.eu>
Closes: https://lore.kernel.org/linux-ide/0bf3f2f0-0fc6-4ba5-a420-c0874ef82d64@heusel.eu/
Fixes: 28ab9769117c ("ata: libata-scsi: Honor the D_SENSE bit for CK_COND=1 and no error")
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
 drivers/ata/libata-core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index c7752dc80028..590bebe1354d 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5368,6 +5368,13 @@ void ata_dev_init(struct ata_device *dev)
 	 */
 	spin_lock_irqsave(ap->lock, flags);
 	dev->flags &= ~ATA_DFLAG_INIT_MASK;
+
+	/*
+	 * A lot of user space programs incorrectly assume that the sense data
+	 * is in descriptor format, without checking the RESPONSE CODE field of
+	 * the returned sense data (to see which format the sense data is in).
+	 */
+	dev->flags |= ATA_DFLAG_D_SENSE;
 	dev->horkage = 0;
 	spin_unlock_irqrestore(ap->lock, flags);
 
-- 
2.46.0


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

end of thread, other threads:[~2024-08-13 13:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-12 15:15 [PATCH] ata: libata-core: Return sense data in descriptor format by default Niklas Cassel
2024-08-12 17:40 ` Christian Heusel
2024-08-12 18:43 ` Niklas Cassel
2024-08-12 18:46   ` Niklas Cassel
2024-08-12 19:23   ` Martin K. Petersen
2024-08-13  6:37   ` Hannes Reinecke
2024-08-13  9:41     ` Niklas Cassel
2024-08-13 12:15       ` Christoph Hellwig
2024-08-13 13:26         ` Niklas Cassel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).