* [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* Re: [PATCH] ata: libata-scsi: fix REQUESTED MAX LBA field for REMOVE ELEMENT AND TRUNCATE
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 17:40 ` Niklas Cassel
1 sibling, 1 reply; 5+ messages in thread
From: Damien Le Moal @ 2026-11-15 1:58 UTC (permalink / raw)
To: Nick Spooner, Niklas Cassel
Cc: linux-ide, Hannes Reinecke, Martin K . Petersen, stable
On 11/14/26 00:19, Nick Spooner wrote:
> 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>
Good catch for the "- 1", but checking SAT, it says that:
If the REQUESTED CAPACITY field is set to one, then the REMOVE
ELEMENT AND TRUNCATE command shall be terminated with a
CHECK CONDITION status with the sense key set to ILLEGAL
REQUEST and the additional sense code set to INVALID FIELD IN
CDB.
So we should not silently ignore the 1 case and fail it.
Can you send a v2 with that failure added?
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ata: libata-scsi: fix REQUESTED MAX LBA field for REMOVE ELEMENT AND TRUNCATE
2026-11-15 1:58 ` Damien Le Moal
@ 2026-11-16 16:47 ` Nick Spooner
2026-11-16 20:30 ` Damien Le Moal
0 siblings, 1 reply; 5+ messages in thread
From: Nick Spooner @ 2026-11-16 16:47 UTC (permalink / raw)
To: dlemoal; +Cc: cassel, linux-ide, stable, hare, mkp
On 11/15/26 01:58 UTC, Damien Le Moal wrote:
> So we should not silently ignore the 1 case and fail it.
> Can you send a v2 with that failure added?
The 1 case should already fail. The check was in the existing code just
above where I patched, but the diff context cut it off:
req_capacity = get_unaligned_be64(&cdb[2]);
if (req_capacity == 1) {
ata_scsi_set_invalid_field(dev, scmd, 2, 0);
return 1;
}
if (req_capacity > 1)
req_capacity--;
I believe that should cover all three cases in SAT-6.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ata: libata-scsi: fix REQUESTED MAX LBA field for REMOVE ELEMENT AND TRUNCATE
2026-11-16 16:47 ` Nick Spooner
@ 2026-11-16 20:30 ` Damien Le Moal
0 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2026-11-16 20:30 UTC (permalink / raw)
To: Nick Spooner; +Cc: cassel, linux-ide, stable, hare, mkp
On 11/16/26 08:47, Nick Spooner wrote:
> On 11/15/26 01:58 UTC, Damien Le Moal wrote:
>> So we should not silently ignore the 1 case and fail it.
>> Can you send a v2 with that failure added?
>
> The 1 case should already fail. The check was in the existing code just
> above where I patched, but the diff context cut it off:
>
> req_capacity = get_unaligned_be64(&cdb[2]);
> if (req_capacity == 1) {
> ata_scsi_set_invalid_field(dev, scmd, 2, 0);
> return 1;
> }
>
> if (req_capacity > 1)
> req_capacity--;
>
> I believe that should cover all three cases in SAT-6.
Good. Thanks for checking!
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ata: libata-scsi: fix REQUESTED MAX LBA field for REMOVE ELEMENT AND TRUNCATE
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 17:40 ` Niklas Cassel
1 sibling, 0 replies; 5+ messages in thread
From: Niklas Cassel @ 2026-11-16 17:40 UTC (permalink / raw)
To: Damien Le Moal, Nick Spooner
Cc: linux-ide, Hannes Reinecke, Martin K . Petersen, stable
On Fri, 13 Nov 2026 08:19:29 -0700, Nick Spooner wrote:
> 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).
>
> [...]
Applied to libata/linux.git (for-7.4-fixes), thanks!
[1/1] ata: libata-scsi: fix REQUESTED MAX LBA field for REMOVE ELEMENT AND TRUNCATE
https://git.kernel.org/libata/linux/c/9016b8b9
Kind regards,
Niklas
^ permalink raw reply [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