From: sashiko-bot@kernel.org
To: "Niklas Cassel" <cassel@kernel.org>
Cc: linux-ide@vger.kernel.org, dlemoal@kernel.org, cassel@kernel.org
Subject: Re: [PATCH 2/2] ata: libata-scsi: scale DSM TRIM payload by MAX PAGES PER DSM COMMAND
Date: Wed, 01 Jul 2026 22:58:03 +0000 [thread overview]
Message-ID: <20260701225804.0DFA01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701224638.1835123-6-cassel@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ATA DATA SET MANAGEMENT (TRIM) commands will fail on 4Kn devices that do not report a maximum DSM page limit, because the code defaults to sending up to 8 pages instead of the specification-mandated safe minimum of 1.
- [Medium] 32-bit integer overflow in the DSM TRIM maximum blocks calculation artificially clamps the block layer discard limit, causing performance regressions.
--
commit a387741dfad7fa23a80a62ebd7e1d57854a6d80e
Author: Niklas Cassel <cassel@kernel.org>
ata: libata-scsi: scale DSM TRIM payload by MAX PAGES PER DSM COMMAND
This commit updates the DSM TRIM command translation to scale the payload
size based on the MAX PAGES PER DSM COMMAND reported by the device. It
sizes the TRIM descriptor as a whole number of 512-byte pages, capped
by both the device limit and the logical sector size.
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -2198,6 +2198,36 @@ static unsigned int ata_scsiop_inq_89(struct ata_device *dev,
[ ... ]
> +static unsigned int ata_dsm_trim_pages(struct ata_device *dev)
> +{
> + unsigned int sector_size = ata_id_logical_sector_size(dev->id);
> + unsigned int max_pages = ata_id_dsm_max_pages(dev->id);
> + unsigned int pages = sector_size / ATA_SECT_SIZE;
> +
> + if (max_pages)
> + pages = min(pages, max_pages);
> +
> + return pages;
> +}
[Severity: High]
For 4Kn devices that report 0 for the maximum DSM limit (word 105), this
defaults to sending up to 8 pages (4096 / 512). Does this exceed the ATA
specification's guaranteed safe minimum of 1 page, potentially causing the
device to reject the command with an I/O error?
> @@ -2237,7 +2267,8 @@ static unsigned int ata_scsiop_inq_b0(struct ata_device *dev,
> * with the unmap bit set.
> */
> if (ata_id_has_trim(dev->id)) {
> - u64 max_blocks = 65535 * ATA_MAX_TRIM_RNUM;
> + unsigned int max_pages = ata_dsm_trim_pages(dev);
> + u64 max_blocks = U16_MAX * max_pages * ATA_MAX_TRIM_RNUM;
[Severity: Medium]
When calculating max_blocks in ata_scsiop_inq_b0(), the multiplication involves
a 32-bit unsigned int (U16_MAX * max_pages * 64). If max_pages is greater
than 1024, can this expression overflow a 32-bit integer before being
zero-extended and assigned to the 64-bit max_blocks? This might artificially
truncate the block layer discard limit for devices supporting large TRIMs.
[ ... ]
> @@ -3523,7 +3565,7 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
> goto invalid_fld;
> }
> /* If the request is too large the cmd is invalid */
> - if (n_block > 0xffff * trmax) {
> + if (n_block > U16_MAX * max_pages * ATA_MAX_TRIM_RNUM) {
[Severity: Medium]
Similarly, in ata_scsi_write_same_xlat(), could this 32-bit arithmetic
truncate the intended validation limit if the device reports a large
maximum DSM page limit, inadvertently masking the mismatch from the truncated
limit above?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260701224638.1835123-4-cassel@kernel.org?part=2
next prev parent reply other threads:[~2026-07-01 22:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 22:46 [PATCH 0/2] ata: DSM TRIM fix and improvements Niklas Cassel
2026-07-01 22:46 ` [PATCH 1/2] ata: libata-scsi: fix DSM TRIM for sector sizes larger than 2048 bytes Niklas Cassel
2026-07-02 7:00 ` Hannes Reinecke
2026-07-01 22:46 ` [PATCH 2/2] ata: libata-scsi: scale DSM TRIM payload by MAX PAGES PER DSM COMMAND Niklas Cassel
2026-07-01 22:58 ` sashiko-bot [this message]
2026-07-01 23:56 ` Niklas Cassel
2026-07-02 7:04 ` Hannes Reinecke
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=20260701225804.0DFA01F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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