Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Niklas Cassel <cassel@kernel.org>
Cc: linux-ide@vger.kernel.org, Igor Pylypiv <ipylypiv@google.com>,
	Shao Mingyin <shao.mingyin@zte.com.cn>,
	Hannes Reinecke <hare@kernel.org>
Subject: Re: [PATCH 3/8] ata: libata-scsi: reject MODE SELECT mode pages with a wrong SPF bit
Date: Wed, 4 Nov 2026 06:22:08 +0900	[thread overview]
Message-ID: <1af3f18a-5595-4591-8fbc-e5e4d889b036@kernel.org> (raw)
In-Reply-To: <20261103205448.931471-13-cassel@kernel.org>

On 11/4/26 05:54, Niklas Cassel wrote:
> ata_scsi_mode_select_xlat() accepts the caching and control mode pages
> both in page_0 format and in sub_page format with SUBPAGE CODE 00h.
> 
> However, SAT-2 and later versions of SAT define the SPF bit of the
> Caching mode page and of the Control mode page as not changeable and
> set to zero (see SAT-6, 10.4.9 and 10.4.6), and SPC-7 (6.12, MODE
> SELECT(10) command) requires the device server to terminate a MODE
> SELECT command with INVALID FIELD IN PARAMETER LIST if the application
> client sets any field that is reported as not changeable to a value
> other than its current value.
> 
> Reject a mode page with the SPF bit set to one and SUBPAGE CODE 00h,
> with the FIELD POINTER set to the byte containing the SPF bit. The only
> mode page with the SPF bit set to one that remains accepted is the ATA
> Feature Control mode page (control mode page, sub-page f2h), for which
> SAT-6 (12.3.4) requires the SPF bit to be set to one. The opposite case
> does not need a check: a mode page in page_0 format always has subpage
> code 00h, so it can never be the ATA Feature Control mode page.
> 
> This also allows the mode page handlers to rely on the format of their
> mode page, which a later patch will make use of.
> 
> Fixes: 1b26d29ccd59 ("[libata] scsi: implement MODE SELECT command")
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
> ---
>  drivers/ata/libata-scsi.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index d7923bc664d6..7b0a02903fda 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -4629,6 +4629,16 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)
>  			goto invalid_param_len;
>  
>  		spg = p[1];
> +		/*
> +		 * Mode pages with subpage code 00h use the page_0 format: SAT
> +		 * defines the SPF bit of the Caching and Control mode pages,
> +		 * for subpage code 00h, as not changeable and set to zero.
> +		 */
> +		if (!spg) {
> +			fp = hdr_len + bd_len;
> +			goto invalid_param;
> +		}

The comment block in-between the assignment and test is odd. Can you move the
assignment right before the if, after the comment block? That makes the code a
lot prettier :)

> +
>  		pg_len = get_unaligned_be16(&p[2]);
>  		p += 4;
>  		len -= 4;


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2026-11-03 21:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 20:54 [PATCH 0/8] ata: libata-scsi: MODE SELECT fixes and cleanups Niklas Cassel
2026-11-03 20:54 ` [PATCH 1/8] ata: libata-scsi: fix MODE SELECT handling of data after the mode page Niklas Cassel
2026-11-03 21:20   ` Damien Le Moal
2026-11-03 20:54 ` [PATCH 2/8] ata: libata-scsi: do not accept subpage code FFh in MODE SELECT Niklas Cassel
2026-11-03 21:20   ` Damien Le Moal
2026-11-03 20:54 ` [PATCH 3/8] ata: libata-scsi: reject MODE SELECT mode pages with a wrong SPF bit Niklas Cassel
2026-11-03 21:22   ` Damien Le Moal [this message]
2026-11-03 20:54 ` [PATCH 4/8] ata: libata-scsi: fix MODE SELECT field pointer for unsupported subpages Niklas Cassel
2026-11-03 21:23   ` Damien Le Moal
2026-11-03 20:54 ` [PATCH 5/8] ata: libata-scsi: fix MODE SELECT field pointer for block descriptor length Niklas Cassel
2026-11-03 21:24   ` Damien Le Moal
2026-11-03 20:54 ` [PATCH 6/8] ata: libata-scsi: pass the whole mode page to the MODE SELECT handlers Niklas Cassel
2026-11-03 21:33   ` Damien Le Moal
2026-11-03 20:54 ` [PATCH 7/8] ata: libata-scsi: set the field pointer when rejecting CDL Niklas Cassel
2026-11-03 21:34   ` Damien Le Moal
2026-11-03 20:54 ` [PATCH 8/8] ata: libata-scsi: document the MODE SENSE mode page functions Niklas Cassel
2026-11-03 21:36   ` Damien Le Moal

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=1af3f18a-5595-4591-8fbc-e5e4d889b036@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=cassel@kernel.org \
    --cc=hare@kernel.org \
    --cc=ipylypiv@google.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=shao.mingyin@zte.com.cn \
    /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