Linux ATA/IDE development
 help / color / mirror / Atom feed
* [PATCH] ata: libata-scsi: set the field pointer when rejecting CDL
@ 2026-10-29 11:03 shao.mingyin
  2026-11-03 21:04 ` Niklas Cassel
  0 siblings, 1 reply; 4+ messages in thread
From: shao.mingyin @ 2026-10-29 11:03 UTC (permalink / raw)
  To: dlemoal, cassel, linux-ide; +Cc: linux-kernel

From: Shao Mingyin <shao.mingyin@zte.com.cn>

ata_mselect_control_ata_feature() rejects enabling CDL while NCQ
priority is enabled, but unlike its other error branches it returns
without setting *fp.

ata_scsi_mode_select_xlat() initializes fp to 0xffff and, when the
handler fails, adds the mode select header and block descriptor lengths
to it.  The resulting sense data then reports a field pointer far
outside of the submitted parameter list instead of the byte that has to
be changed.

Set *fp to the beginning of the mode page data, as the other branches of
this function do.

Fixes: df60f9c64576 ("scsi: ata: libata: Add ATA feature control sub-page translation")
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 5cde90fe594e..c07c1ff09757 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -4494,6 +4494,7 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc,
 		if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED) {
 			ata_dev_err(dev,
 				"NCQ priority must be disabled to enable CDL\n");
+			*fp = 0;
 			return -EINVAL;
 		}
 		ata_dev_dbg(dev, "Enabling CDL\n");

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

* Re: [PATCH] ata: libata-scsi: set the field pointer when rejecting CDL
  2026-10-29 11:03 [PATCH] ata: libata-scsi: set the field pointer when rejecting CDL shao.mingyin
@ 2026-11-03 21:04 ` Niklas Cassel
  2026-11-03 21:18   ` Niklas Cassel
  0 siblings, 1 reply; 4+ messages in thread
From: Niklas Cassel @ 2026-11-03 21:04 UTC (permalink / raw)
  To: shao.mingyin; +Cc: dlemoal, linux-ide

Hello Shao,

On Thu, Oct 29, 2026 at 07:03:14PM +0800, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> ata_mselect_control_ata_feature() rejects enabling CDL while NCQ
> priority is enabled, but unlike its other error branches it returns
> without setting *fp.
> 
> ata_scsi_mode_select_xlat() initializes fp to 0xffff and, when the
> handler fails, adds the mode select header and block descriptor lengths
> to it.  The resulting sense data then reports a field pointer far
> outside of the submitted parameter list instead of the byte that has to
> be changed.
> 
> Set *fp to the beginning of the mode page data, as the other branches of
> this function do.
> 
> Fixes: df60f9c64576 ("scsi: ata: libata: Add ATA feature control sub-page translation")
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> ---
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index 5cde90fe594e..c07c1ff09757 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -4494,6 +4494,7 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc,
>  		if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED) {
>  			ata_dev_err(dev,
>  				"NCQ priority must be disabled to enable CDL\n");
> +			*fp = 0;
>  			return -EINVAL;
>  		}
>  		ata_dev_dbg(dev, "Enabling CDL\n");


Setting fp to zero looks very wrong to me, even though with the current
overly complicated code where buf and fp was using completely different
offsets, it was actually correct.

I reworked and included your patch in my series:
https://lore.kernel.org/linux-ide/20261103205448.931471-17-cassel@kernel.org/

This way we can set the fp to the logical value for anyone actually
looking at the definition of this mode page in the SAT spec.

(Where the CDL_CTRL field is at offset 4 in the ATA Feature Control mode page)


Kind regards,
Niklas

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

* Re: [PATCH] ata: libata-scsi: set the field pointer when rejecting CDL
  2026-11-03 21:04 ` Niklas Cassel
@ 2026-11-03 21:18   ` Niklas Cassel
  2026-11-04  1:55     ` shao.mingyin
  0 siblings, 1 reply; 4+ messages in thread
From: Niklas Cassel @ 2026-11-03 21:18 UTC (permalink / raw)
  To: shao.mingyin; +Cc: dlemoal, linux-ide

On Tue, Nov 03, 2026 at 10:04:18PM +0100, Niklas Cassel wrote:
> Hello Shao,
> 
> On Thu, Oct 29, 2026 at 07:03:14PM +0800, shao.mingyin@zte.com.cn wrote:
> > From: Shao Mingyin <shao.mingyin@zte.com.cn>
> > 
> > ata_mselect_control_ata_feature() rejects enabling CDL while NCQ
> > priority is enabled, but unlike its other error branches it returns
> > without setting *fp.
> > 
> > ata_scsi_mode_select_xlat() initializes fp to 0xffff and, when the
> > handler fails, adds the mode select header and block descriptor lengths
> > to it.  The resulting sense data then reports a field pointer far
> > outside of the submitted parameter list instead of the byte that has to
> > be changed.
> > 
> > Set *fp to the beginning of the mode page data, as the other branches of
> > this function do.
> > 
> > Fixes: df60f9c64576 ("scsi: ata: libata: Add ATA feature control sub-page translation")
> > Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> > ---
> > diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> > index 5cde90fe594e..c07c1ff09757 100644
> > --- a/drivers/ata/libata-scsi.c
> > +++ b/drivers/ata/libata-scsi.c
> > @@ -4494,6 +4494,7 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc,
> >  		if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED) {
> >  			ata_dev_err(dev,
> >  				"NCQ priority must be disabled to enable CDL\n");
> > +			*fp = 0;
> >  			return -EINVAL;
> >  		}
> >  		ata_dev_dbg(dev, "Enabling CDL\n");
> 
> 
> Setting fp to zero looks very wrong to me, even though with the current
> overly complicated code where buf and fp was using completely different
> offsets, it was actually correct.

Sorry, to clarify, 0 would have been wrong anyway, but because of existing
bugs in ata_scsi_mode_select_xlat() related to fp, not because your patch
was wrong:
https://lore.kernel.org/linux-ide/20261103205448.931471-10-cassel@kernel.org

  Parameter list                                     Before After Correct
  CDL enable while NCQ priority is enabled                7    12      12


Kind regards,
Niklas

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

* Re: [PATCH] ata: libata-scsi: set the field pointer when rejecting CDL
  2026-11-03 21:18   ` Niklas Cassel
@ 2026-11-04  1:55     ` shao.mingyin
  0 siblings, 0 replies; 4+ messages in thread
From: shao.mingyin @ 2026-11-04  1:55 UTC (permalink / raw)
  To: cassel; +Cc: dlemoal, linux-ide

Hi Niklas,

On Tue, Nov 03, 2026 at 10:18:26PM +0100, Niklas Cassel wrote:
> Sorry, to clarify, 0 would have been wrong anyway, but because of existing
> bugs in ata_scsi_mode_select_xlat() related to fp, not because of your patch
> was wrong:

Understood, and agreed.  With 6/8 passing the whole mode page to the
handler, the offset is the one from the mode page definition: CDL_CTRL is
the first byte after the four-byte mode page header, so fp = 4 is correct.
My 0 only looked consistent with the surrounding code because the handler
still saw the page data without its header.

I also saw that you carried the fix as 7/8 of the series.  That works for
me: I am dropping my standalone patch, so please keep 7/8 as it is and do
not respin it on my account.

Thanks for the clarification and for carrying the fix.

Best regards,
Shao

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

end of thread, other threads:[~2026-11-04  1:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-29 11:03 [PATCH] ata: libata-scsi: set the field pointer when rejecting CDL shao.mingyin
2026-11-03 21:04 ` Niklas Cassel
2026-11-03 21:18   ` Niklas Cassel
2026-11-04  1:55     ` shao.mingyin

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