Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp790315pxk; Mon, 31 Aug 2020 00:30:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXYOBSj4MIcXBEy+vLSOrIyc80jK/Ds4PnBvw7PAyc6KmFMwo1Ki73/MPXf1zpN7OCC33N X-Received: by 2002:a05:6402:ca7:: with SMTP id cn7mr2496534edb.143.1598859057157; Mon, 31 Aug 2020 00:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598859057; cv=none; d=google.com; s=arc-20160816; b=G2eO1vT79GzOoUfmLIbkKobnD7Rf3lobKwY85GYOxDp9RFM5gH1rHlsVA9d/0MmxtF SHCxCwBXjrHjFwpeQ7T4tzdqcdiwkoJioL+N4YsLWKm+yBlnW1VMgQh7eZ65a0Z+ePLr 00XqF/dQxrQ9cjBtyWyTf4NBI/gOzx+FuTNNUiwLXS5T4Zb5FIfVq0WZ/urd2m9H904p 1eO594HmJ7mQPmGSi77lVa2rB8bYASBEKQ/ydaBpjscRw84ta/pcADqJLsG9Zgnz2aR1 BKd24xdji1ZT7IB/yHMWAwmFlDZU5c9Y0T8YcQ78xUgD/LnvKlyImNNQIgkCIbAZxLXm VDIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=oPC6ZILqOHf3ek3MjJ/MeI6lFnD1RidMLRKP76DVtNM=; b=mGQ/yMv4pQY+iZgYN5VHjzXKJvH8XbyYEOelUDz+rBf74hW/5kGrDR2Ujg/E8j/1og 3STEpG+CtXoUGqKA3+j61mqMEZpFuyyusAQlIqSUQDF9CSdjTXn+oeFh69amjAVHq1Ed 9DGHU58G4VwU8z8yR98StN1ebIzrIGdhkMnq0hODHDI9HLWIHfGNVpQPgxNF8bKaxqzX Jx//OG+CaMXV4fpojyw0at+1AlXP4d7I8nCKnQ1gZpvT/preWjyj72NmXsvDEvNGRIEN TcLrnAv4NlCpcysR5fLN4I80nL8vCC3yY1Mz43nKJuUqLDog9mMVo1MIS/Bexbp6zofh rE3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si5534836ejc.7.2020.08.31.00.30.34; Mon, 31 Aug 2020 00:30:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726800AbgHaHaA (ORCPT + 99 others); Mon, 31 Aug 2020 03:30:00 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10352 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725794AbgHaHaA (ORCPT ); Mon, 31 Aug 2020 03:30:00 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 976326E2594D1CC70A1E; Mon, 31 Aug 2020 15:29:56 +0800 (CST) Received: from [127.0.0.1] (10.174.179.92) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Mon, 31 Aug 2020 15:29:49 +0800 Subject: Re: [PATCH v1] scsi: libsas: set data_dir as DMA_NONE if libata mark qc as NODATA To: Luo Jiaxing , , CC: , , , , References: <1598426666-54544-1-git-send-email-luojiaxing@huawei.com> From: Jason Yan Message-ID: Date: Mon, 31 Aug 2020 15:29:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: <1598426666-54544-1-git-send-email-luojiaxing@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.92] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2020/8/26 15:24, Luo Jiaxing ะด??: > We found that it will fail every time when set feature to SATA disk by > "sdparm -s WCE=0 /dev/sde". > > After checking protocol, we know that MODE SELECT is the SCSI command for > setting WCE, and it do not exist in the SATA protocol. Therefore, this > commands are encapsulated in the SET FEATURE command in SATA protocol. > The difference is that the MODE SELECT command sent to SAS disk contains > data and is sent through the DMA. But when send to SATA disk through > SET FEATURE command, it does not contain data. > > I think libsas was not thorough enough in dealing with the situation, at > sas_ata_qc_issue(), task->dma_dir is inherited from qc->dma_dir(qc->dma_dir > is also inherited from SCSI). However, in ATA driver, if qc->tf.protocol is > set to ATA_PROT_NODATA, ata_sg_setup() will not invoked by ata_qc_issue(). > It mean that ATA didn't use dma_dir and it's not reliable. So, if libsas > still inherits from qc->dma_dir when there is no data need to be send. As a > result, task with no data are mistakenly considered as carrying data and it > will make LLDD report an error on IO completion. > > So, When ATA driver mark tf->protocol as NODATA, dma_dir should be set as > DMA_NONE. And we can see WCE is successfully disable for SATA disk then. > > Euler:~ # sdparm -s WCE=0 /dev/sde > /dev/sde: ATA ST4000NM0035-1V4 TN03 > Euler:~ # sdparm /dev/sde > /dev/sde: ATA ST4000NM0035-1V4 TN03 > Read write error recovery mode page: > AWRE 1 [cha: n, def: 1] > ARRE 0 [cha: n, def: 0] > PER 0 [cha: n, def: 0] > Caching (SBC) mode page: > WCE 0 [cha: y, def: 0] > RCD 0 [cha: n, def: 0] > Control mode page: > SWP 0 [cha: n, def: 0] > > Fixes: fa1c1e8f1ece ("[SCSI] Add SATA support to libsas") > > Signed-off-by: Luo Jiaxing > Reviewed-by: John Garry > --- > drivers/scsi/libsas/sas_ata.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c > index 6a521ba..a488798 100644 > --- a/drivers/scsi/libsas/sas_ata.c > +++ b/drivers/scsi/libsas/sas_ata.c > @@ -209,7 +209,10 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) > task->num_scatter = si; > } > > - task->data_dir = qc->dma_dir; > + if (qc->tf.protocol == ATA_PROT_NODATA) > + task->data_dir = DMA_NONE; > + else > + task->data_dir = qc->dma_dir; > task->scatter = qc->sg; > task->ata_task.retry_count = 1; > task->task_state_flags = SAS_TASK_STATE_PENDING; > Reviewed-by: Jason Yan