Linux ATA/IDE development
 help / color / mirror / Atom feed
* [PATCH] ata: libata-scsi: fix REQUESTED MAX LBA field for REMOVE ELEMENT AND TRUNCATE
@ 2026-11-13 15:19 Nick Spooner
  2026-11-15  1:58 ` Damien Le Moal
  2026-11-16 17:40 ` Niklas Cassel
  0 siblings, 2 replies; 5+ messages in thread
From: Nick Spooner @ 2026-11-13 15:19 UTC (permalink / raw)
  To: Damien Le Moal, Niklas Cassel
  Cc: linux-ide, Hannes Reinecke, Martin K . Petersen, Nick Spooner,
	stable

ata_scsi_remove_element_and_truncate_xlat() copies the REQUESTED CAPACITY
field, req_capacity, to REQUESTED MAX LBA for every block count except 1.

However, SAT-6 specifies that if REQUESTED CAPACITY is greater than one,
the REQUESTED MAX LBA shall be set to REQUESTED CAPACITY minus one, since
the max LBA = count - 1 (see SAT-6 rev2, 9.16.1, Table 74). For example, if
a capacity C > 1 is requested, the capacity ends up one block larger if the
drive can provide C + 1. If the drive can provide C but not C + 1, a
request that should be valid is instead rejected with INVALID FIELD IN CDB
(see ACS-5 rev10, 7.33.3.3).

Modify ata_scsi_remove_element_and_truncate_xlat() to decrement
req_capacity, except when equal to 1 or 0 (rejected if 1, let the device
choose if 0).

Tested by issuing sg_rem_rest_elem on a Seagate drive ST32000NM001F,
firmware db02 and checking the taskfile.

Fixes: db496721cb0d ("ata: libata-scsi: add support for the REMOVE ELEMENT AND TRUNCATE command")
Cc: stable@vger.kernel.org
Signed-off-by: Nick Spooner <nicholas.spooner@seagate.com>
---
Tested on libata/for-7.4-fixes by capturing the trace of what libata sends to the drive.

  sg_rem_rest_elem --remove --element=0x30 --capacity=<C> /dev/sda

  Unpatched, C=1000000:
    ata_qc_issue: ata_port=2 ata_dev=0 tag=12 proto=ATA_PROT_NODATA cmd=0x7c  tf=(7c/00:30:40:42:0f/00:00:00:00:00/40)

  Patched, C=1000000, 0, 2:
    ata_qc_issue: ata_port=2 ata_dev=0 tag=0 proto=ATA_PROT_NODATA cmd=0x7c  tf=(7c/00:30:3f:42:0f/00:00:00:00:00/40)
    ... tf=(7c/00:30:00:00:00/00:00:00:00:00/40)
    ... tf=(7c/00:30:01:00:00/00:00:00:00:00/40)

 drivers/ata/libata-scsi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 87a57495d2e4..20ea1c997d56 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -4991,6 +4991,9 @@ ata_scsi_remove_element_and_truncate_xlat(struct ata_queued_cmd *qc)
 		return 1;
 	}
 
+	if (req_capacity > 1)
+		req_capacity--;
+
 	id = get_unaligned_be32(&cdb[10]);
 
 	tf->protocol = ATA_PROT_NODATA;
-- 
2.56.0


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

end of thread, other threads:[~2026-11-16 20:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 15:19 [PATCH] ata: libata-scsi: fix REQUESTED MAX LBA field for REMOVE ELEMENT AND TRUNCATE Nick Spooner
2026-11-15  1:58 ` Damien Le Moal
2026-11-16 16:47   ` Nick Spooner
2026-11-16 20:30     ` Damien Le Moal
2026-11-16 17:40 ` Niklas Cassel

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