From nobody Tue Dec 16 23:09:26 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A85301A2553 for ; Mon, 24 Jun 2024 22:12:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267154; cv=none; b=reDz0ejEErjfHgrtD+khaFKkYDq1v75/qKGr5SYztwQXAC8WZSO78n2/cgAYzEIGlWHvHnrg5dk31W4aCjd3l7AV7cRLwke19JDt4l8hwcMS38rnS5jP1NyfcX74WWttOEkQNWswCtSIgy4hb0QrNhiUJ4BB4e+fc6KRO9ZyY+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267154; c=relaxed/simple; bh=+UCCdZQ3eCuIV7Y1LzKbJGHc3JfjUkOY8QeVYo3jO2w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TAqo0Fabbom+ZLmS2cPHwpJ2YZ92rkYPmlecCZyas7qCO6qgcSjpWqJXiu2WLHJ06VLodZqSDdyPpl58ZOh/PaUBumDmT/x5teHFHp3IRwJ8JWZNYZMUsKyvotdYLpfHMF5lbxuHqXbRpFTijooGdVHN1Je45ivtC9U1V3Mr8uI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Vs4QjN1h; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Vs4QjN1h" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7163489149fso4927436a12.3 for ; Mon, 24 Jun 2024 15:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719267152; x=1719871952; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pPYUfgs5zw04kzOhQ8+F9AbTYxqJaear32gPB/pl9ow=; b=Vs4QjN1h1aE9QMbVibdZ7Wi/cj53XvESsgrVGCrCeP9mOcaojZGBGw4C34hrJgJ+PL LQ7M8Ifl1hZ0KjWwG2e9P7y1/dIsfewViPZ9r6akT3/1UPLxRSoQBuy/erkk8sKDa3Pf NqPV1YWFBfI1ATe3kxjs67tO1yW6Ue74KjGO4Uwk6U5tc1JCl4uYAJQnnqIIoLIxZeMf Ph36SjD6uEnXVdbVoxN6+Udhs+oZoQiy5wuHinqtzYyhvBZiurGmbDAzF1kAI6E90TrA UsKlBlx14QKIQsTPoPyUAV3HiymZX2B4myXeuJeSZ6Jdpa5/6IAvDIdw6bkmnHUgVzFe xlyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719267152; x=1719871952; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pPYUfgs5zw04kzOhQ8+F9AbTYxqJaear32gPB/pl9ow=; b=SsEJKqzZgRE4vczDRd/LvdGA89oObZe7XehBuFuX6s15iGpw5kOVrthvfihxekCInr nENXVOoH4GxzfBTSMJkBPgpHBDSkZuX6HVls7T+WsLyhrSdJghn10mmIx1Jk1b4Hf32o MgkgZ0HVoKIH6jV03V9S6wC6tBwD8Q4MFQ/eKmrgJl1JVcqblHqZ+JsVEwYyg4/6yn1C vs6dZBkqlxr74IGBIkb7LP5aUpar7uma0GbBewskcfnNZL3wtLCGVoyvBDGPUYNqdRP0 3e4XXypCmOQrOzHMlIn1pLVwrZCZr2Qwb32bO/E5HZj1COgGlUnMR67OCWPTYOdmG2A2 AkZw== X-Forwarded-Encrypted: i=1; AJvYcCVl4cUa2ElZI+7vSs4Kx+P+4DskEP2nQ0niYqlLTkLeuRSfXox9kZgNvWX/bPpgYDh0cPS3QoAvXMF8auA/XeJBZSu2my23IObVmJ04 X-Gm-Message-State: AOJu0Yz/dCdRqOgP7ksmChaiWqJmtJ3Phy78OgyLm9Z2Ia7ahYF7X2wo BR8sM4TArcNIptc6vc9U5rzbweKquYJkZvyiaAshrih8XRByiw2FR6OtJYLPi/N/bH40q+mjE1w 67wT/o8iwOg== X-Google-Smtp-Source: AGHT+IF6xzy8x66j2jk6t+LDSAGlwtGWFsJBo+x/FEq/umMjUFalVzUGvRMupb1SHy0uxFHIyYxLIGjs7WR2SQ== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a17:902:f685:b0:1f6:917b:e064 with SMTP id d9443c01a7336-1fa1d624449mr6528115ad.6.1719267151816; Mon, 24 Jun 2024 15:12:31 -0700 (PDT) Date: Mon, 24 Jun 2024 22:12:05 +0000 In-Reply-To: <20240624221211.2593736-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240624221211.2593736-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240624221211.2593736-2-ipylypiv@google.com> Subject: [PATCH v2 1/6] ata: libata-scsi: Do not overwrite valid sense data when CK_COND=1 From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , "Martin K. Petersen" , Jason Yan , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Current ata_gen_passthru_sense() code performs two actions: 1. Generates sense data based on the ATA 'status' and ATA 'error' fields. 2. Populates "ATA Status Return sense data descriptor" / "Fixed format sense data" with ATA taskfile fields. The problem is that #1 generates sense data even when a valid sense data is already present (ATA_QCFLAG_SENSE_VALID is set). Factoring out #2 into a separate function allows us to generate sense data only when there is no valid sense data (ATA_QCFLAG_SENSE_VALID is not set). As a bonus, we can now delete a FIXME comment in atapi_qc_complete() which states that we don't want to translate taskfile registers into sense descriptors for ATAPI. Cc: Signed-off-by: Igor Pylypiv Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-scsi.c | 158 +++++++++++++++++++++----------------- 1 file changed, 86 insertions(+), 72 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index bb4d30d377ae..54fed6a427b1 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -230,6 +230,80 @@ void ata_scsi_set_sense_information(struct ata_device = *dev, SCSI_SENSE_BUFFERSIZE, information); } =20 +/** + * ata_scsi_set_passthru_sense_fields - Set ATA fields in sense buffer + * @qc: ATA PASS-THROUGH command. + * + * Populates "ATA Status Return sense data descriptor" / "Fixed format + * sense data" with ATA taskfile fields. + * + * LOCKING: + * None. + */ +static void ata_scsi_set_passthru_sense_fields(struct ata_queued_cmd *qc) +{ + struct scsi_cmnd *cmd =3D qc->scsicmd; + struct ata_taskfile *tf =3D &qc->result_tf; + unsigned char *sb =3D cmd->sense_buffer; + unsigned char *desc =3D sb + 8; + + if ((cmd->sense_buffer[0] & 0x7f) >=3D 0x72) { + u8 len; + + /* descriptor format */ + len =3D sb[7]; + desc =3D (char *)scsi_sense_desc_find(sb, len + 8, 9); + if (!desc) { + if (SCSI_SENSE_BUFFERSIZE < len + 14) + return; + sb[7] =3D len + 14; + desc =3D sb + 8 + len; + } + desc[0] =3D 9; + desc[1] =3D 12; + /* + * Copy registers into sense buffer. + */ + desc[2] =3D 0x00; + desc[3] =3D tf->error; + desc[5] =3D tf->nsect; + desc[7] =3D tf->lbal; + desc[9] =3D tf->lbam; + desc[11] =3D tf->lbah; + desc[12] =3D tf->device; + desc[13] =3D tf->status; + + /* + * Fill in Extend bit, and the high order bytes + * if applicable. + */ + if (tf->flags & ATA_TFLAG_LBA48) { + desc[2] |=3D 0x01; + desc[4] =3D tf->hob_nsect; + desc[6] =3D tf->hob_lbal; + desc[8] =3D tf->hob_lbam; + desc[10] =3D tf->hob_lbah; + } + } else { + /* Fixed sense format */ + desc[0] =3D tf->error; + desc[1] =3D tf->status; + desc[2] =3D tf->device; + desc[3] =3D tf->nsect; + desc[7] =3D 0; + if (tf->flags & ATA_TFLAG_LBA48) { + desc[8] |=3D 0x80; + if (tf->hob_nsect) + desc[8] |=3D 0x40; + if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) + desc[8] |=3D 0x20; + } + desc[9] =3D tf->lbal; + desc[10] =3D tf->lbam; + desc[11] =3D tf->lbah; + } +} + static void ata_scsi_set_invalid_field(struct ata_device *dev, struct scsi_cmnd *cmd, u16 field, u8 bit) { @@ -837,10 +911,8 @@ static void ata_to_sense_error(unsigned id, u8 drv_sta= t, u8 drv_err, u8 *sk, * ata_gen_passthru_sense - Generate check condition sense block. * @qc: Command that completed. * - * This function is specific to the ATA descriptor format sense - * block specified for the ATA pass through commands. Regardless - * of whether the command errored or not, return a sense - * block. Copy all controller registers into the sense + * This function is specific to the ATA pass through commands. + * Regardless of whether the command errored or not, return a sense * block. If there was no error, we get the request from an ATA * passthrough command, so we use the following sense data: * sk =3D RECOVERED ERROR @@ -855,7 +927,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cm= d *qc) struct scsi_cmnd *cmd =3D qc->scsicmd; struct ata_taskfile *tf =3D &qc->result_tf; unsigned char *sb =3D cmd->sense_buffer; - unsigned char *desc =3D sb + 8; u8 sense_key, asc, ascq; =20 memset(sb, 0, SCSI_SENSE_BUFFERSIZE); @@ -876,62 +947,6 @@ static void ata_gen_passthru_sense(struct ata_queued_c= md *qc) */ scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D); } - - if ((cmd->sense_buffer[0] & 0x7f) >=3D 0x72) { - u8 len; - - /* descriptor format */ - len =3D sb[7]; - desc =3D (char *)scsi_sense_desc_find(sb, len + 8, 9); - if (!desc) { - if (SCSI_SENSE_BUFFERSIZE < len + 14) - return; - sb[7] =3D len + 14; - desc =3D sb + 8 + len; - } - desc[0] =3D 9; - desc[1] =3D 12; - /* - * Copy registers into sense buffer. - */ - desc[2] =3D 0x00; - desc[3] =3D tf->error; - desc[5] =3D tf->nsect; - desc[7] =3D tf->lbal; - desc[9] =3D tf->lbam; - desc[11] =3D tf->lbah; - desc[12] =3D tf->device; - desc[13] =3D tf->status; - - /* - * Fill in Extend bit, and the high order bytes - * if applicable. - */ - if (tf->flags & ATA_TFLAG_LBA48) { - desc[2] |=3D 0x01; - desc[4] =3D tf->hob_nsect; - desc[6] =3D tf->hob_lbal; - desc[8] =3D tf->hob_lbam; - desc[10] =3D tf->hob_lbah; - } - } else { - /* Fixed sense format */ - desc[0] =3D tf->error; - desc[1] =3D tf->status; - desc[2] =3D tf->device; - desc[3] =3D tf->nsect; - desc[7] =3D 0; - if (tf->flags & ATA_TFLAG_LBA48) { - desc[8] |=3D 0x80; - if (tf->hob_nsect) - desc[8] |=3D 0x40; - if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) - desc[8] |=3D 0x20; - } - desc[9] =3D tf->lbal; - desc[10] =3D tf->lbam; - desc[11] =3D tf->lbah; - } } =20 /** @@ -1634,6 +1649,8 @@ static void ata_scsi_qc_complete(struct ata_queued_cm= d *qc) u8 *cdb =3D cmd->cmnd; int need_sense =3D (qc->err_mask !=3D 0) && !(qc->flags & ATA_QCFLAG_SENSE_VALID); + int need_passthru_sense =3D (qc->err_mask !=3D 0) || + (qc->flags & ATA_QCFLAG_SENSE_VALID); =20 /* For ATA pass thru (SAT) commands, generate a sense block if * user mandated it or if there's an error. Note that if we @@ -1645,13 +1662,16 @@ static void ata_scsi_qc_complete(struct ata_queued_= cmd *qc) * asc,ascq =3D ATA PASS-THROUGH INFORMATION AVAILABLE */ if (((cdb[0] =3D=3D ATA_16) || (cdb[0] =3D=3D ATA_12)) && - ((cdb[2] & 0x20) || need_sense)) - ata_gen_passthru_sense(qc); - else if (need_sense) + ((cdb[2] & 0x20) || need_passthru_sense)) { + if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) + ata_gen_passthru_sense(qc); + ata_scsi_set_passthru_sense_fields(qc); + } else if (need_sense) { ata_gen_ata_sense(qc); - else + } else { /* Keep the SCSI ML and status byte, clear host byte. */ cmd->result &=3D 0x0000ffff; + } =20 ata_qc_done(qc); } @@ -2590,14 +2610,8 @@ static void atapi_qc_complete(struct ata_queued_cmd = *qc) /* handle completion from EH */ if (unlikely(err_mask || qc->flags & ATA_QCFLAG_SENSE_VALID)) { =20 - if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) { - /* FIXME: not quite right; we don't want the - * translation of taskfile registers into a - * sense descriptors, since that's only - * correct for ATA, not ATAPI - */ + if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) ata_gen_passthru_sense(qc); - } =20 /* SCSI EH automatically locks door if sdev->locked is * set. Sometimes door lock request continues to --=20 2.45.2.741.gdbec12cfda-goog From nobody Tue Dec 16 23:09:26 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AA5B1A255B for ; Mon, 24 Jun 2024 22:12:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267156; cv=none; b=qmxpeDqaR5X+/ccBrnhRUPd2xJqjeWH3Lx7M/V3g8OIYc4IGhZsD5dbLgkbd2wkBhfa/KXirB3jKiLU/zzCl+3nLYyaDQOtPEu2knY+Xct89WxuAuJXnmSQzLHxXHS75mMpSgLdx8avluFvFSdt1vqyj1BZJDppfWVUck2yj6Hg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267156; c=relaxed/simple; bh=H5jrycwQOQCdDzP8twQBwlLk8k5oMojnGk5RZ+lwoJ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=D3598g8HdZ5vSJtgO9y8ESgHfGLfxFaVgxRVi4tRCTjhWgT8q/sBDDZ34JsxzuAL1unPpEYqaYlKdY4JybkdGyO61qwfcZpgw0EQzmXnutzGmKY71yX5liwXl763Md7JcJwjIYN9Bki+F5FY7w35O9BJNamlA+v1LnGcDTTITpk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CeoPKjEN; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CeoPKjEN" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-63bf44b87d4so55161637b3.0 for ; Mon, 24 Jun 2024 15:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719267153; x=1719871953; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=T/zaNrBpCV4cTZnzSBNY9sM7nHv2+L5v4mANyaf/Yiw=; b=CeoPKjENBZb2J4VuW6bGUvi/X0QeGFXyM4UUyyf7nD6jvZaorIMDbRPU0XLMSjArly HLZQNpXH1wMWCaSF4NbQ40Qs7LSFYwJ58h1l8f1z+cv+idGFXr6HDQo8o4Ey+EgEQNTC dZ0xbb5fnItrNmAvXzxxBpfNoXCe/aGvuliGZcGJSQC/EbA6WO9NVSSwaliQDDABkTgf 7bq7ZhSbqQheqkZfOnoYn4v7qrK9RT3zjpPpx92bgT6JhyU/uSsA1NeRMdOMOVSEX1qv tC6s0ONfvDKs55Au6+EdRL507MTO0HxIdXro9h875Mm6T4XR1D76Ww9tc2HhxvMImDTs GmxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719267153; x=1719871953; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=T/zaNrBpCV4cTZnzSBNY9sM7nHv2+L5v4mANyaf/Yiw=; b=qdwQdkaA7G0LoUndHarK+eO0RRzI/x/O9n+bOnR83ZPPIqJY5xr05iSz7lT/6j4vtU 2AuAS8mQ8cgd9VZ+HJkfsfseSAlyLH2J5ifhFBr3L1H+vgMmJsBwNQd5q1Y6kbqBs6dl i1HRF+Azqjjwp0KBCLJjR3XC3x4DEPgrLRBVBtDZWfvEpgJwZZIEjVFAuBy3qBJrj9WU orPsHVrJydQmMk+FHigF1vOCJLnS7Y/WeIZXavrIyQGLXcnVRaO5ZNYFotGUgGU4ubTG 1nuCPqckvpyfggDv3DXShDLxq9+0F2FhPkxaZKegoQTTFEpIpHbXe8sKCk54OiN81EEf 2oYQ== X-Forwarded-Encrypted: i=1; AJvYcCXY1IaS4Y1yTf7qjtt2grvXmdTnDuZfkJ3NZc219bztN0UtZ66wfTVbjoo1b5P/Y0IvkNTiiGZXyT7p4kfr3IU4NzC579dYsy6R2Sl0 X-Gm-Message-State: AOJu0YwG1zs7l4KjVxwmE+kC43JTYkfKMjPhBVC5vzdh/rup8F5bvgbG wMzbfcXiOMuCH//j8Sty8/zIFrONNC+JmeogD56y9ytuD3hK6YlmAPuN+JT0mySinoNGKqA/uu6 VUif7gTFXTg== X-Google-Smtp-Source: AGHT+IGwpjqGiG6hgZr2YQON7q+hgaHg5oxM/rLJ5AZXXSxHW2LM1a7J7YCKisq5jnPXZ8sPzDD0RIZb9fURmA== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:690c:6a0e:b0:61b:32dc:881d with SMTP id 00721157ae682-64255f08ef6mr333117b3.3.1719267153627; Mon, 24 Jun 2024 15:12:33 -0700 (PDT) Date: Mon, 24 Jun 2024 22:12:06 +0000 In-Reply-To: <20240624221211.2593736-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240624221211.2593736-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240624221211.2593736-3-ipylypiv@google.com> Subject: [PATCH v2 2/6] ata: libata-scsi: Fix offsets for the fixed format sense data From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , "Martin K. Petersen" , Jason Yan , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv , Akshat Jain , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Correct the ATA PASS-THROUGH fixed format sense data offsets to conform to SPC-6 and SAT-5 specifications. Additionally, set the VALID bit to indicate that the INFORMATION field contains valid information. INFORMATION =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D SAT-5 Table 212 =E2=80=94 "Fixed format sense data INFORMATION field for th= e ATA PASS-THROUGH commands" defines the following format: +------+------------+ | Byte | Field | +------+------------+ | 0 | ERROR | | 1 | STATUS | | 2 | DEVICE | | 3 | COUNT(7:0) | +------+------------+ SPC-6 Table 48 - "Fixed format sense data" specifies that the INFORMATION field starts at byte 3 in sense buffer resulting in the following offsets for the ATA PASS-THROUGH commands: +------------+-------------------------+ | Field | Offset in sense buffer | +------------+-------------------------+ | ERROR | 3 | | STATUS | 4 | | DEVICE | 5 | | COUNT(7:0) | 6 | +------------+-------------------------+ COMMAND-SPECIFIC INFORMATION =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D SAT-5 Table 213 - "Fixed format sense data COMMAND-SPECIFIC INFORMATION field for ATA PASS-THROUGH" defines the following format: +------+-------------------+ | Byte | Field | +------+-------------------+ | 0 | FLAGS | LOG INDEX | | 1 | LBA (7:0) | | 2 | LBA (15:8) | | 3 | LBA (23:16) | +------+-------------------+ SPC-6 Table 48 - "Fixed format sense data" specifies that the COMMAND-SPECIFIC-INFORMATION field starts at byte 8 in sense buffer resulting in the following offsets for the ATA PASS-THROUGH commands: Offsets of these fields in the fixed sense format are as follows: +-------------------+-------------------------+ | Field | Offset in sense buffer | +-------------------+-------------------------+ | FLAGS | LOG INDEX | 8 | | LBA (7:0) | 9 | | LBA (15:8) | 10 | | LBA (23:16) | 11 | +-------------------+-------------------------+ Reported-by: Akshat Jain Fixes: 11093cb1ef56 ("libata-scsi: generate correct ATA pass-through sense") Cc: stable@vger.kernel.org Signed-off-by: Igor Pylypiv Reviewed-by: Hannes Reinecke --- drivers/ata/libata-scsi.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 54fed6a427b1..26b1263f5c7c 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -245,9 +245,9 @@ static void ata_scsi_set_passthru_sense_fields(struct a= ta_queued_cmd *qc) struct scsi_cmnd *cmd =3D qc->scsicmd; struct ata_taskfile *tf =3D &qc->result_tf; unsigned char *sb =3D cmd->sense_buffer; - unsigned char *desc =3D sb + 8; =20 - if ((cmd->sense_buffer[0] & 0x7f) >=3D 0x72) { + if ((sb[0] & 0x7f) >=3D 0x72) { + unsigned char *desc; u8 len; =20 /* descriptor format */ @@ -286,21 +286,21 @@ static void ata_scsi_set_passthru_sense_fields(struct= ata_queued_cmd *qc) } } else { /* Fixed sense format */ - desc[0] =3D tf->error; - desc[1] =3D tf->status; - desc[2] =3D tf->device; - desc[3] =3D tf->nsect; - desc[7] =3D 0; + sb[0] |=3D 0x80; + sb[3] =3D tf->error; + sb[4] =3D tf->status; + sb[5] =3D tf->device; + sb[6] =3D tf->nsect; if (tf->flags & ATA_TFLAG_LBA48) { - desc[8] |=3D 0x80; + sb[8] |=3D 0x80; if (tf->hob_nsect) - desc[8] |=3D 0x40; + sb[8] |=3D 0x40; if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) - desc[8] |=3D 0x20; + sb[8] |=3D 0x20; } - desc[9] =3D tf->lbal; - desc[10] =3D tf->lbam; - desc[11] =3D tf->lbah; + sb[9] =3D tf->lbal; + sb[10] =3D tf->lbam; + sb[11] =3D tf->lbah; } } =20 --=20 2.45.2.741.gdbec12cfda-goog From nobody Tue Dec 16 23:09:26 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 638311A2573 for ; Mon, 24 Jun 2024 22:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267157; cv=none; b=gysHaN9Ns/cfkDE0NHhf1gOYpWfu8PxiaM8Iou6cHTEfPALsNV/QbicD7hSGZXhzO/+Xe/8RoVANx6Mhw5gRa2ynw0PBpCZpNoWMIMII76vxIxz6U3y/kklY5xLDiIXUVfUfkasTZuhWB2SJ5E64jGAKnxhdlfROeC14Wr3acKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267157; c=relaxed/simple; bh=Up6V+DxPHud41/ok240Yxqnh88BYXSB4LT1/yseuVM4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MYIfayrxlS25PErJisITLfCP24ZdUR/klfAt9TFEKE/KmsV71RVStvjWFY9Y7YzCm3KlZdo4ZXoVmmy91weX5sShBoHhQGzYmnpn6banlny+sDQZU9E1J0G02H1fKA0RJBhWGel0vt6BCaTcBK8TZ08SEEV1B3r1x+r4t/ClUQw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Dj8rYbhh; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Dj8rYbhh" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e02ba91b9f4so6449733276.1 for ; Mon, 24 Jun 2024 15:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719267155; x=1719871955; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tUtfz3bhoNl6XZdgw0Jyrha+rGGjCaq3OYUhxmJGLk4=; b=Dj8rYbhhg1U61NnC+WnlENUSx8Z+mvtXpEIK3qKgugdZNvOQOmHspwnF+lr9U0KBZU Uz1QWa/8ubDpfKa+zAw10x1UjFo1MZO5/1+SI92iNoGxJRACdVY9pRsOdj5sRe1FbZfP Ef5s+9lBSP1e4ibSBHrMpTJJVhXzly14XEn3+aB5qWy9N77TwchrIaBWfp6LszhSBDIo aWQAc2YFWe3ZQcA23zu58vT1Y0DZ8BVkgv3nPEb19/g18eYPnW5wxRbzjzFF2tHzAbu2 GtDnPQ4CxHaIWTkSlkb025FmjkWO1ZIELveob2QCWY/gTXWe16I03TQeBhg7Rwt180pz cwyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719267155; x=1719871955; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tUtfz3bhoNl6XZdgw0Jyrha+rGGjCaq3OYUhxmJGLk4=; b=SgibcI4Lt+JWOHChrynmlLehRPNFhmOeGncEyWLlYusPzc7y4nl0Hcza0Bobbyif8q ICQ0HhBNLTa9xUfHLzksvW0XPBcp0QZS5ze/D82ANkYNCjHZwO+RYRvt4Tlw8rBR7zWt +AUesbXDPHdkAjWWsV3SWdmz8XBLLCM1Arn4zh6+HT+DWbmBc+4f6cE6s4KwVxfPLTD1 b6aE6GtQt42vo+E7edxGVqXcM5m7k6dlG1JYnPvUxB5Q1k1r++dIJUOG1699C6bI5Ncx SNAPwEoA1YvDFgAvwSmB8RzzQEprGV/DTrtzuUxvNV5EzddHbmGr5qnglNz8YlikFI3/ 4JVA== X-Forwarded-Encrypted: i=1; AJvYcCXKzf6rZZvXyVQiotyKogNweNRwrFKTXcQZiYL2JezwaScS4OT719eYjDHirRScL+JniGQup/4J4gGY+ITUjLTKPpeyeCf401yylZuw X-Gm-Message-State: AOJu0Yza8KursuemjAbyfuWAH4S7sS75jajlJLgI/3jRRWqTtB+tOi1J t//OGk8Ugdr13IMp2kEuynpspXEy5bvGQEq4tyy/pon7SetPt07zwLGj8tRCRRVP09gL/q5fuod FQe/AyE1b3A== X-Google-Smtp-Source: AGHT+IFOerdlJvZ2UgYsr6VZcIvadTxqhWj051FHAGqyrWnnWeZQEP6tOT2f0SoGARXgYQA2WDQyb34wRFw//Q== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:1208:b0:e02:bde8:1057 with SMTP id 3f1490d57ef6-e02fa3242e1mr303000276.1.1719267155506; Mon, 24 Jun 2024 15:12:35 -0700 (PDT) Date: Mon, 24 Jun 2024 22:12:07 +0000 In-Reply-To: <20240624221211.2593736-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240624221211.2593736-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240624221211.2593736-4-ipylypiv@google.com> Subject: [PATCH v2 3/6] ata: libata-scsi: Remove redundant sense_buffer memsets From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , "Martin K. Petersen" , Jason Yan , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SCSI layer clears sense_buffer in scsi_queue_rq() so there is no need for libata to clear it again. Signed-off-by: Igor Pylypiv Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-scsi.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 26b1263f5c7c..1aeab6e1c8b3 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -929,8 +929,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cm= d *qc) unsigned char *sb =3D cmd->sense_buffer; u8 sense_key, asc, ascq; =20 - memset(sb, 0, SCSI_SENSE_BUFFERSIZE); - /* * Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. @@ -968,8 +966,6 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) u64 block; u8 sense_key, asc, ascq; =20 - memset(sb, 0, SCSI_SENSE_BUFFERSIZE); - if (ata_dev_disabled(dev)) { /* Device disabled after error recovery */ /* LOGICAL UNIT NOT READY, HARD RESET REQUIRED */ --=20 2.45.2.741.gdbec12cfda-goog From nobody Tue Dec 16 23:09:26 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E23E11A2C0A for ; Mon, 24 Jun 2024 22:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267159; cv=none; b=ROGCadjf/tXJkQ93Y426yvpWN8g61JbVnhsckQZC7mFjt5B68BTMEizbzP8BC91gD4k7tWT0eabi8NX1R1q+TksUtzDeqBV9IvbOIqb8mLG+QVpRrXmVGkkTG4U/q/8xJwKGIPkcuAvv9Mq0sjWko6Ixnqe7M9DOMFQAllTmjFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267159; c=relaxed/simple; bh=4ci67SVFpkWmJkYCTkpx+ig9XBfHau+20YcfXOFnufI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KpaI6gag/R924WnGaI6elLwuBalXAjZzRRUN6akpexjNn5U6aONFMepB9qmdwB2rZs5wM9kyUw1G01goPfFlat2OaiyF2sUzI6Eyd9M+IngYAZuRkMoUj5JqUhOKFBNLBGrLBEYLO3GbZPjyRhRKF7vgFojhRoTeP6h3EuNLIRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=G7/ciOLH; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G7/ciOLH" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1f9db3192d8so28497905ad.1 for ; Mon, 24 Jun 2024 15:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719267157; x=1719871957; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=am7s8zTwG1CQ1DLlONdgBD04NQU7cty5c4MreVuPbFc=; b=G7/ciOLH6m9StJN4nPtD4v+pJj9TGy3y8UqUf+YjvAuaE1ucF4ZbF508wSRz08VbtY jY3Kic/eXE5cVf1xdwQbXrB9EyZt0eA7r4ATWiQvjdBEpcZg7qkUrgsIzAjyMY3g79l1 y5NWMYsB0ojXutD65UGhR5fnMThQtMNlyqijtfYecKVVm4n1JHrFnTNMKZa2sqwxYPMq vagRnBLNs2X1hle4lWy0ZJ2SYcX516zHJrzeKx8EXNM152soJwF71uyttmJPo14IZ3ft acwb2Zv3Lh6IS7H8PEomAIgSMq9U+noTOnL8bzbyel2/yEZEPHW6S73w9OanxDUVXCWx RQWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719267157; x=1719871957; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=am7s8zTwG1CQ1DLlONdgBD04NQU7cty5c4MreVuPbFc=; b=B2JCjmaUzyNzwA29dosi/pF4TkCOffjqXHMZCl7+zAKkhPRdiZqo0+1PzmYc2XxHpF K7ISWUj6RQPRTos4TUHQP9vqmG66w4R5cXUWwKcstV87G0a2leZRgDEUZvIvXIHIanE3 Fc3sNctTieqtkKPqwMVMXv9c5/wc6/tT2/YF5n+PPm7a5O31CHo/8X24sA9oGHZDIuMP D8npD3ZAr+3Q9kzd52UMhQMyZeZ2Y2DH2WAdUvwLFi1nPuU4JbdywoUu6ztrHEaHJecd jTub8q9rIKGmpkwQjkRtm/3b7S4GykbyClv1ihjRxWxhmkozHGp8Er5FywIMlNxzykF1 FN7g== X-Forwarded-Encrypted: i=1; AJvYcCX2+8iw19V+wmZE+TIJs8T0Nr/NuQCbT3TPvj6kj0XHOCiS+zco7XHdkTboG8UqRwKofKKrWmCaOwCcxwitf97QU4/2tYrAaXcbIo3f X-Gm-Message-State: AOJu0YzRgShOwNuQAjNrBg/0pwVa5O+BeRteEfuRrelk57RvZt7no7K5 t4EarHtbLsUeaAVKBowgC81uzYyIf3iDAY2ax3vRSHUx3d/ErwvHTAVh5nC7vbky741AF8OCB6i sCC3bLQMoTg== X-Google-Smtp-Source: AGHT+IGUdOx20r7NDEUvU1cytoPKAzBTVDx7VmCUnni5NL4Qq9RkQzd3oASNoeizoFcr889fkOjJmC0s/e4Cxw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a17:902:eccb:b0:1f9:cc3c:9dc with SMTP id d9443c01a7336-1fa104968e4mr1692405ad.5.1719267157123; Mon, 24 Jun 2024 15:12:37 -0700 (PDT) Date: Mon, 24 Jun 2024 22:12:08 +0000 In-Reply-To: <20240624221211.2593736-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240624221211.2593736-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240624221211.2593736-5-ipylypiv@google.com> Subject: [PATCH v2 4/6] ata: libata-scsi: Do not pass ATA device id to ata_to_sense_error() From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , "Martin K. Petersen" , Jason Yan , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ATA device id is not used in ata_to_sense_error(). Fixes: ff8072d589dc ("ata: libata: remove references to non-existing error_= handler()") Signed-off-by: Igor Pylypiv Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-scsi.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 1aeab6e1c8b3..e5669a296d81 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -785,7 +785,6 @@ static void ata_qc_set_pc_nbytes(struct ata_queued_cmd = *qc) =20 /** * ata_to_sense_error - convert ATA error to SCSI error - * @id: ATA device number * @drv_stat: value contained in ATA status register * @drv_err: value contained in ATA error register * @sk: the sense key we'll fill out @@ -799,8 +798,8 @@ static void ata_qc_set_pc_nbytes(struct ata_queued_cmd = *qc) * LOCKING: * spin_lock_irqsave(host lock) */ -static void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *s= k, - u8 *asc, u8 *ascq) +static void ata_to_sense_error(u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, + u8 *ascq) { int i; =20 @@ -935,7 +934,7 @@ static void ata_gen_passthru_sense(struct ata_queued_cm= d *qc) */ if (qc->err_mask || tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { - ata_to_sense_error(qc->ap->print_id, tf->status, tf->error, + ata_to_sense_error(tf->status, tf->error, &sense_key, &asc, &ascq); ata_scsi_set_sense(qc->dev, cmd, sense_key, asc, ascq); } else { @@ -977,7 +976,7 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) */ if (qc->err_mask || tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { - ata_to_sense_error(qc->ap->print_id, tf->status, tf->error, + ata_to_sense_error(tf->status, tf->error, &sense_key, &asc, &ascq); ata_scsi_set_sense(dev, cmd, sense_key, asc, ascq); } else { --=20 2.45.2.741.gdbec12cfda-goog From nobody Tue Dec 16 23:09:26 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1CF51A2C3D for ; Mon, 24 Jun 2024 22:12:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267161; cv=none; b=BxlPvZRhjRIs/+NJpyLLdFf0bNrisPE4jA25V4PpUEvhND2NPruaInpM5Q/5WjBWTJ2H+xzdabukbjqUoeuuEGuO/TH7VloqNEMQ68+Kpv4dpCtBCtMlaBo6SrSmoVZb3JVcRi0/wkKDLURRzbDlk5oJX+kwYtWiLdga+Tm9YP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267161; c=relaxed/simple; bh=QwejxdxJmtTRHtoUQvB6POU7Ble7ol1nMg9swXRXC+I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=V3rHLt8su8gsW977M7D1mXSYSA6DbsKUUlSzj2iMsiCJkmH1nxcMI+TxxFI7NkQcQvg7rKqiitbjK9XF8sW5y/W9kfrRJs9x1tixW+NtfcvDE6dKw+m/mUSqr8Qb3ozUgPBAmNSoTmoYRhDDBbjnp8p2AQeqeHhPbesm12jXHHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dBLprWoF; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dBLprWoF" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1f682664703so66831205ad.1 for ; Mon, 24 Jun 2024 15:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719267159; x=1719871959; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=W4QNMMnwiVz3ILaswEcfqdDsU4n3tKsCQ2BCKeXeiW4=; b=dBLprWoFTRfE/u7AyClzxqw+HEIsyhK7XguQWzM8mmA1zzqgcFuoJpcjShmQw8csA/ ptns9y4W9s4nzOYMNzaXizZ9GdVu74XSXeRgt8TrUaCbqS53wHkzMIAYIAtycXv96hej sJP6QlDoAoycuVy5VJv6Y9QXKKuvmACTZ5Y6LV+M4hyCgeZ7kzrQDQPc+iZLqVlFlE+d E+zDwYb2Awagp34b+VpWGGE1UnlvlMW052mGmUQPMnsqCYmiwE0WNpKRXQHp+s2LocOz lX2eJxRF32MXulRL3boQmvOGDraRMt36tgpPoDraefsPWdkq47b4Pw63sXRgaZdbWSpH 7cQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719267159; x=1719871959; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W4QNMMnwiVz3ILaswEcfqdDsU4n3tKsCQ2BCKeXeiW4=; b=O6Xj6zOFi6SHfS5Yx7evEJ/Ew8V0rSH/Gk3cHCq9FbKtbYjr/TW00bzzo8c2ggaLsx TBtq7V+xdsmgTk4/v+um4DUvQIsuuzyLwsa1xY5xqidz4/kBDHuQO9iL8ks0vVB1TI6X AmYCfCudYGFOrLTemJB4vhGj0OMkxHTPoaiwB/HxWKIfGTLpYOOXJWyAfLvydW5eGwqt 33e0cL1Fwu+FSIv59RDjMiKQUc5Q+H+KWjVtFwhsSHu0VInQAgYLJrBxfDpJ6rzHLBcJ hISE4Ps7/xUkU4B8+K2UmAs2U6e2tim+dSnQ/uV8Va04P2SSzK5Ec9Cx1kz4Kn5leEW4 uFYQ== X-Forwarded-Encrypted: i=1; AJvYcCVHa6bXaheohTp+p5o4oDY6k+acyB8OVzDvMvFUXOq+mstzryYl0q7mBQ+vI8LIT+hNo1kCp8Qyfbc5+qbImyNptoJWyLflB54AYC7W X-Gm-Message-State: AOJu0Yx0fz5BxXUdy69W0eh+phuZAd0dBTrfYEb7lsWb0HEwdXdE0cXk rE4P4h2OT18QbpD0baUeSzNAw12naH44qpLS+Gy+B1ECZjy8rehNRyZrU6TqryKzaiOP2TR+Urk 424GxFHH7nw== X-Google-Smtp-Source: AGHT+IFflA1G3grpNjsfx2ZiWo2J8fKoDLM8TXPiJruY4xgfYztBbpyEDlvAdfgXscHbWYR37+52a/UFOGMXLQ== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a17:902:f646:b0:1fa:2b89:f558 with SMTP id d9443c01a7336-1fa2b89f864mr6066495ad.7.1719267158936; Mon, 24 Jun 2024 15:12:38 -0700 (PDT) Date: Mon, 24 Jun 2024 22:12:09 +0000 In-Reply-To: <20240624221211.2593736-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240624221211.2593736-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240624221211.2593736-6-ipylypiv@google.com> Subject: [PATCH v2 5/6] ata: libata: Set ATA_QCFLAG_RTF_FILLED in fill_result_tf() From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , "Martin K. Petersen" , Jason Yan , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ATA_QCFLAG_RTF_FILLED is not specific to ahci and can be used generally to check if qc->result_tf contains valid data. Signed-off-by: Igor Pylypiv Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libahci.c | 10 ---------- drivers/ata/libata-core.c | 8 ++++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 83431aae74d8..0728d445e531 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -2075,13 +2075,6 @@ static void ahci_qc_fill_rtf(struct ata_queued_cmd *= qc) struct ahci_port_priv *pp =3D qc->ap->private_data; u8 *rx_fis =3D pp->rx_fis; =20 - /* - * rtf may already be filled (e.g. for successful NCQ commands). - * If that is the case, we have nothing to do. - */ - if (qc->flags & ATA_QCFLAG_RTF_FILLED) - return; - if (pp->fbs_enabled) rx_fis +=3D qc->dev->link->pmp * AHCI_RX_FIS_SZ; =20 @@ -2095,7 +2088,6 @@ static void ahci_qc_fill_rtf(struct ata_queued_cmd *q= c) !(qc->flags & ATA_QCFLAG_EH)) { ata_tf_from_fis(rx_fis + RX_FIS_PIO_SETUP, &qc->result_tf); qc->result_tf.status =3D (rx_fis + RX_FIS_PIO_SETUP)[15]; - qc->flags |=3D ATA_QCFLAG_RTF_FILLED; return; } =20 @@ -2118,12 +2110,10 @@ static void ahci_qc_fill_rtf(struct ata_queued_cmd = *qc) */ qc->result_tf.status =3D fis[2]; qc->result_tf.error =3D fis[3]; - qc->flags |=3D ATA_QCFLAG_RTF_FILLED; return; } =20 ata_tf_from_fis(rx_fis + RX_FIS_D2H_REG, &qc->result_tf); - qc->flags |=3D ATA_QCFLAG_RTF_FILLED; } =20 static void ahci_qc_ncq_fill_rtf(struct ata_port *ap, u64 done_mask) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index e1bf8a19b3c8..a9fc3ec9300f 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -4801,8 +4801,16 @@ static void fill_result_tf(struct ata_queued_cmd *qc) { struct ata_port *ap =3D qc->ap; =20 + /* + * rtf may already be filled (e.g. for successful NCQ commands). + * If that is the case, we have nothing to do. + */ + if (qc->flags & ATA_QCFLAG_RTF_FILLED) + return; + qc->result_tf.flags =3D qc->tf.flags; ap->ops->qc_fill_rtf(qc); + qc->flags |=3D ATA_QCFLAG_RTF_FILLED; } =20 static void ata_verify_xfer(struct ata_queued_cmd *qc) --=20 2.45.2.741.gdbec12cfda-goog From nobody Tue Dec 16 23:09:26 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC9441A2FD7 for ; Mon, 24 Jun 2024 22:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267163; cv=none; b=egMV8/ds2bDfzDUIlFmqPbOrnHZsP76KjTqgVE5vQX9Szr4Zu+J67uQJNWIwicYEWCHdGr4oZDyDsM5YSiEH04Awho+nXutTzXgNlhkrvaOHfFxdqiwiKeVDT0EeOwSId8LwUt01TXTeC0JBgFx5AQDYsCNJfDtt2l0aK2UyJKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719267163; c=relaxed/simple; bh=pfz7uu+jOOwMjwmY/w6sU4kNgauq6UsTyFTXS6nG/Ww=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fvK4LHPKAjhEo5F+5YNCGtMM3QmYX5wFnMx5X+ldCGZDVcuXQCxzvbUppJD5n93VrrxagVM1NlVXsdDXLxEk52pwNHKn9PMGB8RwPul1H1nb5tdlUt1ed59t/74nA6ewRMuVfCmrjPLNPInjAqmtYnAhGubpdFPIubWHpUZip3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PCTXrJ4+; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PCTXrJ4+" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-63bf44b87d4so55163487b3.0 for ; Mon, 24 Jun 2024 15:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719267161; x=1719871961; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PD3uQGUFz5zxx7acHrfAbDYiKppPlFoCwrVRy3QI4Ug=; b=PCTXrJ4+c3s1wYTJ0jMJH4fTwET79Uc9+6+YyBtiSPJgLwGpHxF+0yhgh+Eah7FLKH KOisIfdMC82DaUkW0+v6+VVP50+xLmkmphu8+JZA8FueYtbnFZndRTAj0y26pzY/a59G Fy126dxHyAFHRU7DlAOgrY0A8kr/diZFlFDCwzXTbby4FRPHcJQzjtrg0K3hpuyEt/CU a9lwZ1APRIkREOw7+/gaEc26/SZghVK6Im+lW8ev0pKACC1mbif6/s04ALG/t+oyZgmP ZiWyjVbL9h0XY7rgU0rVs6VdRgtwfscv4gYrHazLDZ/A4Ef/nJEFQVqLj2YuxAvetdRU CHGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719267161; x=1719871961; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PD3uQGUFz5zxx7acHrfAbDYiKppPlFoCwrVRy3QI4Ug=; b=w+eQBOJAdJRvZsxjbOX2YLvRK7B1Gn9Z8aZdcNM2kU+xk0EOV5SFViz+mOez+AuPEo 95LFE0fckZkmzhwiwtN4RPFUTRZgoJcMQXNgftk2BllCPdOUVsScZzfbjFDKGq5S+bW2 YfGPAfSBCwFSezlzzxh/gB6IrtLB8Ey3vdSFMpMoZd9IEYXoTzKjrnYWOpDO98NBHRIG hbKSbZAbee9QwreQ1p1tLvMyAdGgDNM+Y3IqyNe790hsWxi8MhJjAlDGjXr52Mi+YAOA x4QM45WA97A8eNL933lZPnjbV2fZU8TV7KkpyDQr+EwY9V53XW+pz7w8utbMF6tuiwNv vUpA== X-Forwarded-Encrypted: i=1; AJvYcCWdrv2zSbK3/Bm9akDzCdHcXBYLdhUFGUanIAVhDZ9qItZej/fYbRTETHDtQ2XoF+23agNfL6WRz2DoEscnnBOmRLUCEJvjCOUw9Z85 X-Gm-Message-State: AOJu0Yzw07OrblCc2w37xsTh4bhq+ClarRmojzCKMEUYvKIB7h4mwIjG oemNF1d4zwJm/Nti+3/V3kvZ3emL4NrklQMC6dCmgvSQUqmBd07+4NiOvMCC/Lf1oT6+lQ6mbeu qdajpno0XHg== X-Google-Smtp-Source: AGHT+IG855a4XCLpwisoxKNjnI+nzvVm5c+AAl7kfh4POpZN1c2KNve/pvrtKYJHgwmNI/LedE7U9ADzvsbazw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a81:9208:0:b0:631:4588:4acc with SMTP id 00721157ae682-64242491f26mr370887b3.0.1719267160788; Mon, 24 Jun 2024 15:12:40 -0700 (PDT) Date: Mon, 24 Jun 2024 22:12:10 +0000 In-Reply-To: <20240624221211.2593736-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240624221211.2593736-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240624221211.2593736-7-ipylypiv@google.com> Subject: [PATCH v2 6/6] ata: libata-scsi: Check ATA_QCFLAG_RTF_FILLED before using result_tf From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , "Martin K. Petersen" , Jason Yan , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 a= ta_queued_cmd *qc) struct ata_taskfile *tf =3D &qc->result_tf; unsigned char *sb =3D cmd->sense_buffer; =20 + if (WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_RTF_FILLED))) + return; + if ((sb[0] & 0x7f) >=3D 0x72) { unsigned char *desc; u8 len; @@ -928,6 +931,9 @@ static void ata_gen_passthru_sense(struct ata_queued_cm= d *qc) unsigned char *sb =3D cmd->sense_buffer; u8 sense_key, asc, ascq; =20 + 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 *q= c) 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. */ --=20 2.45.2.741.gdbec12cfda-goog