public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Igor Pylypiv <ipylypiv@google.com>
To: Hannes Reinecke <hare@suse.de>
Cc: Damien Le Moal <dlemoal@kernel.org>,
	Niklas Cassel <cassel@kernel.org>, Tejun Heo <tj@kernel.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Jason Yan <yanaijie@huawei.com>,
	linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/6] ata: libata-scsi: Check ATA_QCFLAG_RTF_FILLED before using result_tf
Date: Wed, 26 Jun 2024 00:30:35 +0000	[thread overview]
Message-ID: <ZnthK-NjkSgIiGiE@google.com> (raw)
In-Reply-To: <7d085940-2ad1-4f44-83bb-33d852e80da0@suse.de>

On Tue, Jun 25, 2024 at 08:26:59AM +0200, Hannes Reinecke wrote:
> On 6/25/24 00:12, Igor Pylypiv wrote:
> > qc->result_tf contents are only valid when the ATA_QCFLAG_RTF_FILLED flag
> > is set. The ATA_QCFLAG_RTF_FILLED flag should be always set for commands
> > that failed or for commands that have the ATA_QCFLAG_RESULT_TF flag set.
> > 
> > For ATA errors and ATA PASS-THROUGH commands the ATA_QCFLAG_RTF_FILLED
> > flag should be always set. Added WARN_ON_ONCE() checks to generate
> > a warning when ATA_QCFLAG_RTF_FILLED is not set and libata needs to
> > generate sense data.
> > 
> > Signed-off-by: Igor Pylypiv <ipylypiv@google.com>
> > ---
> >   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 e5669a296d81..7a8a08692ce9 100644
> > --- a/drivers/ata/libata-scsi.c
> > +++ b/drivers/ata/libata-scsi.c
> > @@ -246,6 +246,9 @@ static void ata_scsi_set_passthru_sense_fields(struct ata_queued_cmd *qc)
> >   	struct ata_taskfile *tf = &qc->result_tf;
> >   	unsigned char *sb = cmd->sense_buffer;
> >
> > +	if (WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_RTF_FILLED)))
> > +		return;
> > +
> >   	if ((sb[0] & 0x7f) >= 0x72) {
> >   		unsigned char *desc;
> >   		u8 len;
> > @@ -928,6 +931,9 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
> >   	unsigned char *sb = cmd->sense_buffer;
> >   	u8 sense_key, asc, ascq;
> > +	if (WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_RTF_FILLED)))
> > +		return;
> > +
> >   	/*
> >   	 * Use ata_to_sense_error() to map status register bits
> >   	 * onto sense key, asc & ascq.
> > @@ -971,6 +977,10 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
> >   		ata_scsi_set_sense(dev, cmd, NOT_READY, 0x04, 0x21);
> >   		return;
> >   	}
> > +
> > +	if (WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_RTF_FILLED)))
> > +		return;
> > +
> >   	/* Use ata_to_sense_error() to map status register bits
> >   	 * onto sense key, asc & ascq.
> >   	 */
> 
> Hmm. Not sure if we really need the WARN_ON() here or whether a simple
> logging message wouldn't be sufficient; after all, we continue fine here.
> 

My worry about adding a simple log statement is that it might cause a log
spam if things go wrong for some reason.

This code is more like a "this should never happen" comment and we always
expect ATA_QCFLAG_RTF_FILLED to be present when generating sense data
based on ATA registers.

If WARN_ON_ONCE() is too much for this case I guess we can just remove it
and silently return?

Damien, Niklas, what are your thoughts on this?

Thanks,
Igor

> Cheers,
> 
> Hannes
> -- 
> Dr. Hannes Reinecke                  Kernel Storage Architect
> hare@suse.de                                +49 911 74053 688
> SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
> HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
> 

  reply	other threads:[~2024-06-26  0:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-24 22:12 [PATCH v2 0/6] ATA PASS-THROUGH sense data fixes Igor Pylypiv
2024-06-24 22:12 ` [PATCH v2 1/6] ata: libata-scsi: Do not overwrite valid sense data when CK_COND=1 Igor Pylypiv
2024-06-25  6:19   ` Hannes Reinecke
2024-06-26  6:27   ` Damien Le Moal
2024-06-24 22:12 ` [PATCH v2 2/6] ata: libata-scsi: Fix offsets for the fixed format sense data Igor Pylypiv
2024-06-25  6:21   ` Hannes Reinecke
2024-06-26  6:28   ` Damien Le Moal
2024-06-24 22:12 ` [PATCH v2 3/6] ata: libata-scsi: Remove redundant sense_buffer memsets Igor Pylypiv
2024-06-25  6:22   ` Hannes Reinecke
2024-06-26  6:30   ` Damien Le Moal
2024-06-26 10:56   ` kernel test robot
2024-06-24 22:12 ` [PATCH v2 4/6] ata: libata-scsi: Do not pass ATA device id to ata_to_sense_error() Igor Pylypiv
2024-06-25  6:23   ` Hannes Reinecke
2024-06-26  6:32   ` Damien Le Moal
2024-06-24 22:12 ` [PATCH v2 5/6] ata: libata: Set ATA_QCFLAG_RTF_FILLED in fill_result_tf() Igor Pylypiv
2024-06-25  6:25   ` Hannes Reinecke
2024-06-26  6:33   ` Damien Le Moal
2024-06-24 22:12 ` [PATCH v2 6/6] ata: libata-scsi: Check ATA_QCFLAG_RTF_FILLED before using result_tf Igor Pylypiv
2024-06-25  6:26   ` Hannes Reinecke
2024-06-26  0:30     ` Igor Pylypiv [this message]
2024-06-26  6:21       ` Damien Le Moal
2024-06-26 23:11         ` Igor Pylypiv

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=ZnthK-NjkSgIiGiE@google.com \
    --to=ipylypiv@google.com \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=hare@suse.de \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=tj@kernel.org \
    --cc=yanaijie@huawei.com \
    /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