Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Nick Spooner <nicholas.spooner@seagate.com>,
	Niklas Cassel <cassel@kernel.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 7.3.y] ata: libata-scsi: fix REQUESTED MAX LBA field for REMOVE ELEMENT AND TRUNCATE
Date: Fri,  4 Dec 2026 07:23:17 -0500	[thread overview]
Message-ID: <20261204122311.3019689-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120244-gooey-bunkmate-07d7@gregkh>

From: Nick Spooner <nicholas.spooner@seagate.com>

[ Upstream commit 9016b8b9e80d3d340b4ad83d457501e944834538 ]

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>
Link: https://lore.kernel.org/r/20261113151929.9586-1-nicholas.spooner@seagate.com
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 449dd5f1c9ccd..041ed76094cd9 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -4920,6 +4920,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.53.0


      reply	other threads:[~2026-12-04 12:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:35 FAILED: patch "[PATCH] ata: libata-scsi: fix REQUESTED MAX LBA field for REMOVE" failed to apply to 7.3-stable tree gregkh
2026-12-04 12:23 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204122311.3019689-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=cassel@kernel.org \
    --cc=nicholas.spooner@seagate.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox