From nobody Thu Dec 18 07:19:53 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 7563519309C for ; Wed, 26 Jun 2024 23:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443067; cv=none; b=HGGnLFFED1l6/GsGAPYp50gUhemRQsWhHdwbEg5AdvQhtvqj4YCRcmEOdJ3kJmlLl+ULYx6xcfVTJbaeFnf2NBDV3BTc8HlgITdCnt+ygscG8qEKvnG5V3GEkNmSvVzu+dNqZu4U9mW9bWyrieiGq82dASOegz0HZinI2ayj9Tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443067; c=relaxed/simple; bh=khdJffv/7S+fJo+T1ERSS/3kzh8tOaLDJIGVkc4xP/s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YzfXz1pKsu4oi73RaMkvSNoRE8/wHh8fnjRH6XtrHG1m5O++s9bcshRJGdbHMYiiXLLYDZDdOXaE4qYT64auUC2bJFwOf+ng+Ag2VjAUhc4l3DK0Dz36VCBt5wuUCqhxzs1lJ6FoHZAqU5zYyEn3JPIjJhYPW1thkvR9J4W9kRE= 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=BnlfWH+k; arc=none smtp.client-ip=209.85.210.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="BnlfWH+k" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-70667c46701so6134723b3a.3 for ; Wed, 26 Jun 2024 16:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443066; x=1720047866; 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=dnwRRitprzkm9CFQnXP8vP+tPUkvyuIbgLz5w5FglfM=; b=BnlfWH+kh4pCSzSEkA0JamA1/YmsqWcYd5476OH6k4G7l4Oblp6jxNxDyr1zeg9+0/ BjeTM+s9+o0NhMPcINf+RAl/e2ET2gVrDoCcQIIIUymr3MgS3gBSjufDy+OdapotWTG2 R6Gbk1DdvZv78rNwPb72ZcqORnjPibBYuWePHXQNbNBPa9ISpYp8knYKAYSCH4Fe5wCd gWfEor51PdTw1+Dsj2iIaRiFovVA19YmTkm7VP3H+hGDn/CMb01An4gqY/bfsQ82tPT+ 7MG9KazcDzqH6PpHM3JqjSBXI6iK8x0bzq1xpxUZxuz8aXDZKAQ6AbnFZ6JTq3oFWh7A jiog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443066; x=1720047866; 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=dnwRRitprzkm9CFQnXP8vP+tPUkvyuIbgLz5w5FglfM=; b=N17fOsXAbXT7GLvHMMcKBfrrhcg5lmLANzZ/rVSbuc6sEADBQAXeLRU+iiSs+Ic55F pJs81hwyoUtoQSnCCttd6J2gKsR9eSRYtAod9aT4e2WLLsTM1KFHyzZ/RDQvs0/8X6/X DFyGYYB2RS73HWqwNqr8axpD7QrCiVRr4fRZ55AZa4WXonF4jydMCfYzETqPH22GY61d eOUfNAagVTFeSPoTUpNATNnJqKWZXAbapUMcbEDhsuAXEF2a84vsQRpFtNaU5V12ebPR /qpf/zT+MVhLeggWVl1xLUF0XARXda7OJLyZHuyW0zfHP1NzXZw8Ab53F49Z9NBD12rk +Tnw== X-Forwarded-Encrypted: i=1; AJvYcCUNVd0d/GAo/10YsZ3h2avqWCT0EQY/KMVfAhvGk6IsyoHngh73BiEvkF/8CTC0LENhN2GvNqgnd8yD6XaNkRMrz1LZQK/DggFNJeGU X-Gm-Message-State: AOJu0Yyhg5I5rO9n37sA6CN1jN/kiyuv6Z1/ZHmHD/IKhzF8rPodhnaO cpl2V0MkTyr9uSUwrdVtSN/dIKILxVb5pliG+lVrPPj4bjZnm9zRJkpYVZFfyXM69tPG0/7d0Jo eE4QvGFS50g== X-Google-Smtp-Source: AGHT+IHvsNwVLyqt1nlHJrNX+JOFz8qm6kONJcbmJ7hVLToZgq5nwNwp7+9RQ6WkWCM2moHWG+jhCkeW/hz4Og== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6a00:3319:b0:704:2cd2:7822 with SMTP id d2e1a72fcca58-7066e721059mr108308b3a.4.1719443065577; Wed, 26 Jun 2024 16:04:25 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:06 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-2-ipylypiv@google.com> Subject: [PATCH v3 1/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 , 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 Reviewed-by: Hannes Reinecke Signed-off-by: Igor Pylypiv --- 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 bb4d30d377ae..a9e44ad4c2de 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -855,7 +855,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); @@ -877,7 +876,8 @@ static void ata_gen_passthru_sense(struct ata_queued_cm= d *qc) scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D); } =20 - if ((cmd->sense_buffer[0] & 0x7f) >=3D 0x72) { + if ((sb[0] & 0x7f) >=3D 0x72) { + unsigned char *desc; u8 len; =20 /* descriptor format */ @@ -916,21 +916,21 @@ static void ata_gen_passthru_sense(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.803.g4e1b14247a-goog From nobody Thu Dec 18 07:19:53 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 47912194132 for ; Wed, 26 Jun 2024 23:04:28 +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=1719443070; cv=none; b=fKWuPMTX/pTNWEvIUGuZn8CjTJRX2vk4VWWma3WNx03ljCgE31lkRPqX94M9mCIhXxaIL0mDLIXLUE0St51PNFewrh55miWo6aYNPuGZaNvlAYQ22zU2oq2kQjXvtDRNQcPFkC29Fchf6i7vlN55fhPW3FpTFv3m6fFaJGC6V08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443070; c=relaxed/simple; bh=X36javU244m1Pe7Nm6RJMAr7OamOkUPb1UbNIZe4cd8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W3z/au5q26WfoVnW6i6l04wiNK3b/2IAD9iEu4AAcCH2hU/FKnJpmFfoZt3itxzyjjg+5jJ+FnNZfnxT+8MBO2DYfCVi1yh9ppmp0J4l0RrHbfbncoBkmYyDSyP8f92UDwxdWH2cK1r8ekwE0l1RvF87FzrpawagkXJPcPm4KN4= 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=mx8v7Sf5; 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="mx8v7Sf5" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-721d20a0807so3111137a12.1 for ; Wed, 26 Jun 2024 16:04:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443067; x=1720047867; 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=jYTcox1uxiDsgrgstLUNMompUZVUnfSZPE6ZrKVubcY=; b=mx8v7Sf5VSZ/raWU8yjyqdOgcCg0xNkuiNr2Ez/PP56TT6o4zPZXp6pI6aqbYYRLjX kKF+FBeaaDpAgYh9YuJo5zrJohSnorUnkL0uODIG7J9k7SMO8JocD5ekS37UTHC4DFvc 207j9SpkKOtMcjI8v7bLNb2Wj9WKQ+IGyUtOe9ud3qTucj9VHiNZz6OrMeaq6u0mRs7U WB0+iQUkNhbi0eVhK2c6yPbsbE91AkDOrlesG1Xfbue2QddhU8XVVdEDyg1B7CZJubNY yGRIWWMMY8aoYee4GxbFkXNx70R5VHp+CSdM+Veyo/vkqlmw+zVMSnOaOb5jhvyU3kRT UwHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443067; x=1720047867; 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=jYTcox1uxiDsgrgstLUNMompUZVUnfSZPE6ZrKVubcY=; b=OnnmAhBM4CzMw5YjIQP3fHdKFzNkkDj8RWzwoWXrF8gSfodyzh2xNK7HFdJWnwWen4 5Bx+OiUMnleiASbccV+TEPtoKKK/mMZuAO868nV7pQkdy8PJd9kUVWQb073aZ2BkdhRH HKnSGcapQlxAgc+5k4QYuUm7j1WEr7dU5wSJjh1R28NORARwAoXxUHLsuCDZMXJGId/4 aPBPsDYgj3hdoBWWk7gQkfvN5hpVEiu9JxeiNwJHfeo7fDWVe/QJ27uLKthS8zOLTpY+ 6th8KFmuh3INIW8VRzrewX5Q7uSsa6ypyHYG2QyGth9Fx+MkqAhOJqVRgRtVX9ecru1u Vukw== X-Forwarded-Encrypted: i=1; AJvYcCUHUNSophi7oasyyTrt8eAHGscElfg9mEOuJDYcNGVFwI3EgM112kfQMgOB5mWQhdeEv2IS3hwLHh+i5hJzUCPKHeM+ScZIVs0Y80oU X-Gm-Message-State: AOJu0YxuiwLDCSon1E/Bvpzwr02oivl8ynwMqTA96rat7Lnvmuci4hmv FqPwwvXPN4432qfSxUfFVOSr8TQ3rkxCW9W4rGVNgZRuVhNr7ir4Kz95JE7zFI7vgJ0xREbxLPu kWeJW4loPYg== X-Google-Smtp-Source: AGHT+IFovcMZN+k505LVJQ0M7+wE+Qk1gQ7CAGuZCVOne74Cr/uZsi84LMT4f7Jo9RaI7qWgiK8IxZ8+6US2HQ== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a63:3d43:0:b0:71a:1f6f:1d0f with SMTP id 41be03b00d2f7-71b5c3db10amr29716a12.6.1719443067521; Wed, 26 Jun 2024 16:04:27 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:07 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-3-ipylypiv@google.com> Subject: [PATCH v3 2/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 , 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: stable@vger.kernel.org Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv --- 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 a9e44ad4c2de..26b1263f5c7c 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; + + if ((sb[0] & 0x7f) >=3D 0x72) { + unsigned char *desc; + 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 */ + 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) { + sb[8] |=3D 0x80; + if (tf->hob_nsect) + sb[8] |=3D 0x40; + if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) + sb[8] |=3D 0x20; + } + sb[9] =3D tf->lbal; + sb[10] =3D tf->lbam; + sb[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 @@ -875,63 +947,6 @@ static void ata_gen_passthru_sense(struct ata_queued_c= md *qc) */ scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D); } - - if ((sb[0] & 0x7f) >=3D 0x72) { - unsigned char *desc; - 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 */ - 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) { - sb[8] |=3D 0x80; - if (tf->hob_nsect) - sb[8] |=3D 0x40; - if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) - sb[8] |=3D 0x20; - } - sb[9] =3D tf->lbal; - sb[10] =3D tf->lbam; - sb[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.803.g4e1b14247a-goog From nobody Thu Dec 18 07:19:53 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 0669E194157 for ; Wed, 26 Jun 2024 23:04:29 +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=1719443071; cv=none; b=rHigrRA/ugiA/qkKLD+oLleAK0muANDNi7dHbOEk8xnql1euEFC4zvC6DcQTB6LyBXgSFUW3O0i6Z+jCcygVn43v9dXN2BrRAWzPzlyCcODwNvcLrH8eaI4yq9Wji6SAGsv5brQvwoDSlC7YS16C8kGUPpltJ1EO+upNDO3VnXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443071; c=relaxed/simple; bh=QOUE3m85wg/4GIuezGsx91HxmkwAowzlGh5n1SnE+jk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=k5c+ec0RjiQb/53ZAZCYhNj6VCOhDLeVvndntLNgDbYgGqOsMzWjzKIMwmgfHX/18E/y1PyziSgFvynqmBYwdVuUV1VG2oRTfd0EiiPWwJ2AORKhNLhsCalRkpXSi6rV6YLy4fXh+3+1+Pmmd/2Up0nANEzAyqDSIoWtV1gNevE= 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=3NyliBBX; 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="3NyliBBX" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1f9ec9aae70so62937015ad.0 for ; Wed, 26 Jun 2024 16:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443069; x=1720047869; 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=WRuxhaMQ+1lW78nuyDa9Lm/q++gXoPPs3JwtC5y4GFo=; b=3NyliBBXP/fMKNHYsdd9Rjno6iYeRXJ9Q0JR8vH8xzdYYZbQo7ZIN4jVnXAQwNL5N0 GXiVIpz1DUDINdc1ZHbfDtOQId92SmFdjl2FuR0fYCCm/rDcaFuiRUyjoPNUAlXM2vEP JhGTCoPf9gqLqZx4l9fupbIcFRdFn9FnPawUsw7OuTq4VgG2g7iKBnEgBk6QfksEQuYr Em132c68o7KwcGsJnYp3fnkh2MfiUKdnIkaGVu0FVwZ3+cj/+BRFSbWTKJVXtq+cXqbA bQitxYyTu1NuWXLXnYGpt4JYFkSGlYJOXKaBf2STv1TwhogdMyXt5XDjYjZ3ItjIGiom Or8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443069; x=1720047869; 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=WRuxhaMQ+1lW78nuyDa9Lm/q++gXoPPs3JwtC5y4GFo=; b=BzWP0f+EB+y/80ETgqf7uQAtPwqcaCuHZFOjpg5Q37nrltuV099GtSQFUjnsk/TKi6 EI0tunVg8u87C0ThzBtbI0dBNzVWNnelNhPgCqdXQrSNHSXlrYB/FVsDzyuX6XX0IvqB GooAUvlU22PApIBtPByN96LnpZ3TKw6rm98rKAFs8WyiI3wqhpxnwdqvNJ+tK+5oUV0x sEiTV7BN86yhJgtPuzri3bQp/AisWxY+orRrY7JXVc0U0SJOTblEGVs5It73WBFuw7O9 QwcfQs0a908S647lf/+jPgX6+pEBni6sS7JcDR3k64OcdFji8+g4GUV6D+nyR60jCiVm dVZw== X-Forwarded-Encrypted: i=1; AJvYcCWNPN2SnZo3blHJyl27nSpLA9etFtrkHICZr6Y1Yk0Ym6x2sFM1vfUuPgXymPhnzYNl7PhhiO29bB7S7T4S7t7XWr/VrFFAR14WeOK5 X-Gm-Message-State: AOJu0YxQWZASSOVp1twa7X7/EcqkBp85ve0IjzvPDn91zhhUcYAdDW16 cLALEjmRJgtl+JSYROziud7t07edgvb5QeRat4MrSq+MHNnZSSCqUbFXudbrRh/ULr6PjMqM3u4 u2gstHPexMA== X-Google-Smtp-Source: AGHT+IEIAPNfqnBOOftySkpy/S1qLhtNZDiXS8lsXqrU0dYyZt2TBCiMdv15J5+VPG4DtZa7SQgsCmuWlH4hFA== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a17:902:c40c:b0:1fa:1be4:1e5c with SMTP id d9443c01a7336-1fa1be42246mr10318515ad.3.1719443069215; Wed, 26 Jun 2024 16:04:29 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:08 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-4-ipylypiv@google.com> Subject: [PATCH v3 3/6] ata: libata-scsi: Remove redundant sense_buffer memsets From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , 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. Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv --- drivers/ata/libata-scsi.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 26b1263f5c7c..6b6e35292620 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -926,11 +926,8 @@ static void ata_gen_passthru_sense(struct ata_queued_c= md *qc) { struct scsi_cmnd *cmd =3D qc->scsicmd; struct ata_taskfile *tf =3D &qc->result_tf; - 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 +965,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.803.g4e1b14247a-goog From nobody Thu Dec 18 07:19:53 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 D2BDA194158 for ; Wed, 26 Jun 2024 23:04:31 +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=1719443073; cv=none; b=js6A6vdThahMA5GNCrBmCSySnncCLnxWvI3oc2pE3XSqy2CnY/sFgAY9NXXUL5mT2G6N3Ff+W/8X2xiOvqSsICLDkfaBOfA/pKuREsHsxW4EnutCLkuLKKoYJTdAF5Yq9+mvTpgKC5NzPtiTqqlj7SHv2PCawIRsDYvg5yq/Ea8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443073; c=relaxed/simple; bh=rrgk4/GN+4afQi82RWjkVdACN68Mce2bh09M2M+kIiE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LiRL/FqCM/qsVJGzKAMskJ/U3mwh9hRTaCNjS06TFmOa6VVA6slGOpw7lFjkfllatsIxgYTUHfs0EMfWtIsSr+G2+LOBZcHhmKDc0+6+1LLd1ngG8+BcDhb3fCnTP5gJ8QlmlIMTCYZ4nqIVcqvDz+Ufh9qpA6X/griuV/TCgiw= 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=wLm0kUne; 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="wLm0kUne" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62fb4a1f7bfso173886097b3.3 for ; Wed, 26 Jun 2024 16:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443071; x=1720047871; 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=t/AvM/q6eju1FsW+yZoXAdsmFslERaWnMqALTvRepcM=; b=wLm0kUne+f06wja8x6z0zsOrKV5ScP28P/L/bdTpFOyUM1ZIhDhGDy+hboncNldeZ0 AfABcmWmhvwIgCXoC7bbeowqvcGTd7ZyzQnbRYJY2NMYxNWqjkDB93iy2r1IohQGzAZG OK+JQU/wc23B+zbdhc2zSie+k3ag9/MuTFahFwLVtLCuiEZBGnwWbOdYomTZ3ozx3hYK lo7w0X1j7z9hNkmijOWRPqsW4QnwtOv7XiQ77HOEHy9/5JAcnhpLia6dstp9LOkkZwqL BZIEXaWNfn9aYXwKtet/ZZpWHruVCDycYdTzgGCzXqKL9K6uMqDlrP0TomkZzKeg0MUM lV2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443071; x=1720047871; 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=t/AvM/q6eju1FsW+yZoXAdsmFslERaWnMqALTvRepcM=; b=hBwH0IbN+bbmlAPw4xFit81B10NcpXjf9Vv92ZQvLHjddKlEef+f80Ba1gg4gF7kA2 ideeRhe0ZBpwnnWDyObGZl7gBZsjHUTLyO2chowsFIQiPg+K0bSuuIYAT8PSdkDghBAR 7UF2pc56QpfO9vs5etdtii/wI56foESEUuRCN1EwPN5PUhIcbQzbecS+g7kojvibWckh i7yDljZstHSuIUu9MFq2OS6VLJufHhVhm0O+q5Nj6CKGpxlaKlCvYVi84wN1vzm//FIu Xdl2qJnPj/7V4LKptpdml6NLcnmMie1GRj4qxzEnM+W0LiDl5wjpHyCK7JCSQKh6K+rk t3IA== X-Forwarded-Encrypted: i=1; AJvYcCVqF7fVA8Y+9xHwyyU2+2Y956lsDiMiBK8WJPg0bbfJOBUIdZsBUgykAVu4PlFR1wwpeY3eQ1BBBkQbmhvBglgcSHxX4EXAGCDinL3h X-Gm-Message-State: AOJu0YwwQkQIWe9RJ64UtWZomm85BcgkmYVL6oe6bNFXHJaUGs9ls/GL rWBFx9PvgyXNut0hAcQ4AEjqyRly5X0TqrSqTuRQ4R0rl94r3j0qPWZRjozVlynkBzNXk91e/BB TlLHQACRHqA== X-Google-Smtp-Source: AGHT+IGHbW9wWs9Mfi0inpboOmSQg9uCUPvebnEdxpQuJ2+zXLOG/ST6R9W4mdAq7jmPeHiFUa3LGqjhiLvsAw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:f85:b0:e03:33c7:5678 with SMTP id 3f1490d57ef6-e0333c75779mr304400276.13.1719443070943; Wed, 26 Jun 2024 16:04:30 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:09 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-5-ipylypiv@google.com> Subject: [PATCH v3 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 , 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(). Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv --- 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 6b6e35292620..02af4d5d5799 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 @@ -934,7 +933,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 { @@ -976,7 +975,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.803.g4e1b14247a-goog From nobody Thu Dec 18 07:19:53 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 AB645194A44 for ; Wed, 26 Jun 2024 23:04:33 +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=1719443075; cv=none; b=qQ50txH5UVragRtG0WHBdRIGQOTmMIl2390V3WtiX6SfTq4J9FQnpo2H0rdaB92t26y1h9kgrk67mpMeGL1IbapbRML3a4eVQewIlQdrTNdsonVtU9YBZTJ/I88yCCFJ/nr1WDSQqgUf8KYHCIRPdJePCCfmn3fCsyCX3fbjfFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443075; c=relaxed/simple; bh=bVYP/yh9H60FMAxPtcm0Q5OLzE/o5Ocz16UtfVNPa4U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eNL4PcD8McWUNCaCO7QZZvNUXKRFT63yz0se1tInvkdg6zGogfUzhY2+IjLk6Il0pkIRhWEQUObwki35fM1QIGkC4bB5jkJiYDFjmT9WaCHU/gTv0WYJF1iaaaJynghyOgYXm9bWKxZYpzO4Hw0PbhNjaPzuFnYg4uZXTjcttFg= 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=fd5cMyQh; 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="fd5cMyQh" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e033554101bso2317820276.2 for ; Wed, 26 Jun 2024 16:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443073; x=1720047873; 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=TktkKoidPCE335Y52c+z5B8f/TUhLrrbeBqorbEFGO4=; b=fd5cMyQhfvZ/Uhp1HdtqM3KHl4H0XLxRdEvI+VSfv2VxmKyynKF59gkJQwnFgiLw+a McS2IqGXQp2A3iXZ2wTnACOZf5mkWxBvRAwbm8gP7kYXlE4r6o84miIYRwinvJ41gxte gVqyESHOb4ZUKO+IUvPpFF+dm5F0yrGr7plV5ySl/NAR/joGzJCaFBDtn0tGjtvu4/R8 a/LYn0lXdDHHHsonRBNkCcL0vQvSlN4hqqxD9eOYw4poSsKzWdHmGJfZJcu3azPBiIgf EUZ9At8dO5K8jogKYvUbbTAgjbxVEABiKv5Conl5jJfY9+1vSJFuc4rE7/Pgf/JhJCnZ j3xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443073; x=1720047873; 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=TktkKoidPCE335Y52c+z5B8f/TUhLrrbeBqorbEFGO4=; b=WhmhJKLA7HMy9m6X7BCmIsWk1uLtvjbCVFps8xd73WF2h2DQxpxz1m2zaH0pFG2BGh vhZcGvKy46yP4v0GN41tC51FZHqioB0c3H1TAadgMR7TcAStVGwHw/FgsVZI7rLBnMhX lenDFXM7qFQMET+cRMifrKnOf/Q9YHP9UWFnmupUHrgO8/AKly5kCIJ/SZOOaxtKtGve BTrt3foyog5b1KrK980LovL9cr95gkJYVW2u++/wTSjknTP4NNmzvby2TUfXceToxlRR TEljBMP5PQ6fsvDTl9JoWINpK/rXYzq1aeZqSBn/ehtIW+GU45MffPCXOAwDyug4Bs0g oqyw== X-Forwarded-Encrypted: i=1; AJvYcCX3LxohiUHM6qeQAOb6/rH9lXvKHgynEYPn0BLkSETibuaxrqFtV9MkCVx7osP6M//0+fFLR4UbIIIlgRE9xQkKqxGGO6kdFtjCFwNH X-Gm-Message-State: AOJu0Yw0vMo0ee9BUneJWtbN+rLuG+GayyAVwyLSTuDwjY3WnCYrlFRx fIuFlEp5q4+F+f7msaCXowjgcLK8IJd4OrUTq+F+xnTL0f8mUC6C7ZcpqyrkD+lj18WduTbQaym aZRRwWk2MhQ== X-Google-Smtp-Source: AGHT+IEb4we7BM5x93dwmclinIUkfoKE9eA0csWjhO9wldRsT+EUgld1jSbloaZMyQXtxOZFolUe7L1HRqV/XA== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:1109:b0:e03:3683:e67f with SMTP id 3f1490d57ef6-e033683e751mr4888276.5.1719443072715; Wed, 26 Jun 2024 16:04:32 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:10 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-6-ipylypiv@google.com> Subject: [PATCH v3 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 , 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. Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv --- 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.803.g4e1b14247a-goog From nobody Thu Dec 18 07:19:53 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 3C06B194A61 for ; Wed, 26 Jun 2024 23:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443076; cv=none; b=DQSeUHcLwDiRWClHVXKccbQbz4dcEyIdm/baoFxWsP04HrGQ1shUbm3+iZr1syyZwZmoeijiCPwgYKLjkMS5bXW+NYRzLW/JUIOGiG/0Aed8W3Lr4Y8btM76szptU1thfVKSD38BFO5XCIJksHsH/fruGy450FBinJxuRF/9c7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443076; c=relaxed/simple; bh=vKCPSZCxsriB7WThJFHjvVytk0B8CH0/B2lctEhKZJI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PCQ5ajjFVovYSZndtCOnHUkDohpRBKCVQNfm9RYMP32l3842ia0mPB+gFOFstWxWe2Y5wWa0xYab8mub/hF+u1g8lnGKAzOOugKrL0hx0ZDs1j9h+s1UgrBURuOH95L5/iH/NmAxIvXLcvHQTnhctDQrOmya0gYmUuCW7F9ScRw= 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=f0NnXEZ9; arc=none smtp.client-ip=209.85.128.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="f0NnXEZ9" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62fb4a1f7bfso173887227b3.3 for ; Wed, 26 Jun 2024 16:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443074; x=1720047874; 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=PEyKI1QsiIJEewnF527ltuQV4oeBpkyWMn9QtWCUb2g=; b=f0NnXEZ9Kk4PBi87AmOOr4ZP9E2uGHCVvpqZazMUUTnAs56AaHJtI/TOfFi+tLtBmJ hH1+RGzbJecDuDK8XCgF0jd1BHxkK2W4/DW5Xx8Y1hGbIlx6/cSpp7Wq9aJ0Qag1HtUj xvjC8sOa5CdpkYChSCUZSQztrLTia3kk6ueGISxEhtSfI540IwHJ2kwGpxNOZ9MO35jZ zCWGT6Kl1AJ6JyIfjmIBdqolHdxz8vwze/xfFsG028AMF9aTVv8416EhTuzTLbliM5QS bGmdjgHNPR+F4a5iYJxmEC0DqqHZrzCb3umUBCfDT6X0imzoE1Zh6a2GCGQOvZAYmNeQ JxMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443074; x=1720047874; 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=PEyKI1QsiIJEewnF527ltuQV4oeBpkyWMn9QtWCUb2g=; b=jmu8boNG1IvqIOx9jnuVtjC75oP8aOWKcwkE1ugbnOmcvzmmwCXQmZmwMptlr6Cteo 0VVT6eaXKWcn4AdoZPO1F8ako1tqCxOeT5M5xe9Y/cGuO/NO7L/DSVEIkeFR+jL/7eji OVwdV8HtK6gRJyBSWmDpa8awiEbfVWxjrD1sLBsf0aIkMT159rEpMeKQin0b+bjqjq1r QRoPi9uYYxPbDuWozPkRf92WzuVgD5rs8ao7TLqfp25zcDYXmmIStJVmmxV6lr48IAZ4 C9TVjN2BCWBLTkyin6e+GOjXhOhgkDwXg6VgaDCDBwIdn89lms4j2SGyPMFIf2FDE8Fi P46w== X-Forwarded-Encrypted: i=1; AJvYcCXZPAbIIwRShKU/5mHWzeWwiF64JZfGjsUs+FoMwWBf9hiFeru1YiACqnnzooxwxB6AXqdAD4TSr2anov1TxwuAVcNfEUZaPRt8utBF X-Gm-Message-State: AOJu0YzX9+HOVbuM5X15yU0VNdLAFe+fpMGkMlNm6T+oYS5QHpT9xSQp jfBLV82UtPS5TE0bna8fyQKo6WVJ4Iku3hMMnwFxl5QoZ7pYkoJNXTeTfNLqPK6V9z7IJi0U1Ms /fjt8fXQNVA== X-Google-Smtp-Source: AGHT+IHEjGoOj0rKBY90tBQ+URsGB4VTurQ8pFXkmw/P+KxoNfpIx64+6no67l8qdUYDXNV6XjzwXAXXQvy3Bw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:690c:fc8:b0:648:2a9d:1a63 with SMTP id 00721157ae682-6482a9d24bfmr2023537b3.7.1719443074353; Wed, 26 Jun 2024 16:04:34 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:11 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-7-ipylypiv@google.com> Subject: [PATCH v3 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 , 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. Signed-off-by: Igor Pylypiv Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-scsi.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 02af4d5d5799..d5874d4b9253 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -242,10 +242,16 @@ void ata_scsi_set_sense_information(struct ata_device= *dev, */ static void ata_scsi_set_passthru_sense_fields(struct ata_queued_cmd *qc) { + struct ata_device *dev =3D qc->dev; struct scsi_cmnd *cmd =3D qc->scsicmd; struct ata_taskfile *tf =3D &qc->result_tf; unsigned char *sb =3D cmd->sense_buffer; =20 + if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) { + ata_dev_dbg(dev, "Missing RTF: cannot set ATA PT sense fields.\n"); + return; + } + if ((sb[0] & 0x7f) >=3D 0x72) { unsigned char *desc; u8 len; @@ -923,10 +929,16 @@ static void ata_to_sense_error(u8 drv_stat, u8 drv_er= r, u8 *sk, u8 *asc, */ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) { + struct ata_device *dev =3D qc->dev; struct scsi_cmnd *cmd =3D qc->scsicmd; struct ata_taskfile *tf =3D &qc->result_tf; u8 sense_key, asc, ascq; =20 + if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) { + ata_dev_dbg(dev, "Missing RTF: cannot generate ATA PT sense data.\n"); + return; + } + /* * Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. @@ -970,6 +982,12 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *q= c) ata_scsi_set_sense(dev, cmd, NOT_READY, 0x04, 0x21); return; } + + if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) { + ata_dev_dbg(dev, "Missing RTF: cannot generate sense data.\n"); + return; + } + /* Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. */ --=20 2.45.2.803.g4e1b14247a-goog