Received: by 10.192.165.156 with SMTP id m28csp47795imm; Tue, 10 Apr 2018 16:07:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+4/kmGbJ/1LmxHngEWdHXJUt+KQpLrlDT2PGO3/y2cztOM1K1it83/eEG8hzbnplfpHTF9 X-Received: by 2002:a17:902:2a43:: with SMTP id i61-v6mr2430373plb.54.1523401623990; Tue, 10 Apr 2018 16:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523401623; cv=none; d=google.com; s=arc-20160816; b=gvRSxe8umLMY9VogWXqjr66m0gKbgI0AS10gevj7a0B5AAqDZK/Dim3igfcPCulqdi 0PILwTtSKoIXtCY8Su6ijOINhz0+RchbRAi0toNJW3v0bB4Ypdm9uFWZK4u34bPyx9+b GjUkF5FNoDrSO2tJWrElzKGRvYjIAtWNdH/wFB/I06F4XblixDxdIjv8sivxBUq6vlui D4/PBtcO9jo10EPIE6koKOI0EDPYzxcaZOk874wnDT0IsyIHAiqr/J2QSHtTUHsnaCKf NRHvaMtOr89e8UKA/bmRfaHGxeO5rvgR4jJ6gTsh83ZG6jA7cC6efujuKuVp44xGqB88 dtjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=4cFHlIafkfskBO79d+nbtcJmm4BitimTjkuMMqFKgWY=; b=sZwSAqLAQ/1Fmth23n0LB9JgEY+E4XL0C5ftzdl2ytq5D2HAhu7gUR/jidPMAIrCQL mk4PBtq/teFpsmZXvm6PSP9YpruplwWH4HKVhA6x+PJR/gpa/Q1Murf5/ebKfPCP92Zs iKwrIaQkgSaxGHLH+J62ca/cpVGKqq22iOTwxBXjn8pGAhCVHH+dzhuPYC5wzmFX8wDV fAQEKL+PI00LOkQKyTvpWJmauJfajrCGzPjxMupQZ9KPWeOvkDgyHPEn93PEy6dS/aFk ZjkYNyrU+CNgtJ8vdx43DFMcFq8boIVNVeo7J9UQciAph7KVrMWr0VatH4TGVjf+9CCm 2R0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64-v6si3498256plk.239.2018.04.10.16.06.27; Tue, 10 Apr 2018 16:07:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932418AbeDJXAK (ORCPT + 99 others); Tue, 10 Apr 2018 19:00:10 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42260 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932304AbeDJWfp (ORCPT ); Tue, 10 Apr 2018 18:35:45 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 044B6D66; Tue, 10 Apr 2018 22:35:44 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chaitra P B , Suganath Prabu S , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 031/138] scsi: mpt3sas: Proper handling of set/clear of "ATA command pending" flag. Date: Wed, 11 Apr 2018 00:23:41 +0200 Message-Id: <20180410212905.731904871@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212902.121524696@linuxfoundation.org> References: <20180410212902.121524696@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chaitra P B [ Upstream commit f49d4aed1315a7b766d855f1367142e682b0cc87 ] 1. In IO path, setting of "ATA command pending" flag early before device removal, invalid device handle etc., checks causes any new commands to be always returned with SAM_STAT_BUSY and when the driver removes the drive the SML issues SYNC Cache command and that command is always returned with SAM_STAT_BUSY and thus making SYNC Cache command to requeued. 2. If the driver gets an ATA PT command for a SATA drive then the driver set "ATA command pending" flag in device specific data structure not to allow any further commands until the ATA PT command is completed. However, after setting the flag if the driver decides to return the command back to upper layers without actually issuing to the firmware (i.e., returns from qcmd failure return paths) then the corresponding flag is not cleared and this prevents the driver from sending any new commands to the drive. This patch fixes above two issues by setting of "ATA command pending" flag after checking for whether device deleted, invalid device handle, device busy with task management. And by setting "ATA command pending" flag to false in all of the qcmd failure return paths after setting the flag. Signed-off-by: Chaitra P B Signed-off-by: Suganath Prabu S Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -4106,19 +4106,6 @@ scsih_qcmd(struct Scsi_Host *shost, stru return 0; } - /* - * Bug work around for firmware SATL handling. The loop - * is based on atomic operations and ensures consistency - * since we're lockless at this point - */ - do { - if (test_bit(0, &sas_device_priv_data->ata_command_pending)) { - scmd->result = SAM_STAT_BUSY; - scmd->scsi_done(scmd); - return 0; - } - } while (_scsih_set_satl_pending(scmd, true)); - sas_target_priv_data = sas_device_priv_data->sas_target; /* invalid device handle */ @@ -4144,6 +4131,19 @@ scsih_qcmd(struct Scsi_Host *shost, stru sas_device_priv_data->block) return SCSI_MLQUEUE_DEVICE_BUSY; + /* + * Bug work around for firmware SATL handling. The loop + * is based on atomic operations and ensures consistency + * since we're lockless at this point + */ + do { + if (test_bit(0, &sas_device_priv_data->ata_command_pending)) { + scmd->result = SAM_STAT_BUSY; + scmd->scsi_done(scmd); + return 0; + } + } while (_scsih_set_satl_pending(scmd, true)); + if (scmd->sc_data_direction == DMA_FROM_DEVICE) mpi_control = MPI2_SCSIIO_CONTROL_READ; else if (scmd->sc_data_direction == DMA_TO_DEVICE) @@ -4170,6 +4170,7 @@ scsih_qcmd(struct Scsi_Host *shost, stru if (!smid) { pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", ioc->name, __func__); + _scsih_set_satl_pending(scmd, false); goto out; } mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); @@ -4200,6 +4201,7 @@ scsih_qcmd(struct Scsi_Host *shost, stru if (mpi_request->DataLength) { if (ioc->build_sg_scmd(ioc, scmd, smid)) { mpt3sas_base_free_smid(ioc, smid); + _scsih_set_satl_pending(scmd, false); goto out; } } else