Received: by 10.192.165.156 with SMTP id m28csp1224071imm; Wed, 11 Apr 2018 14:59:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/iaERPaCfJdStzcHsgv9mDMR3Q2qP3SI/ycQIcwXrZCqIZpqpvVsNVziIgo92+lMaqfLDy X-Received: by 2002:a17:902:9349:: with SMTP id g9-v6mr6773752plp.243.1523483996176; Wed, 11 Apr 2018 14:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523483996; cv=none; d=google.com; s=arc-20160816; b=sLRS3UtMkq+bYIIumCWIsTThUnzBHRC47BI5CLVVxE0iyWdt0Objfd9zVeD+VSdZll UpaTb1lD5Zx9HTUkH+octGxpKxQTUutbEHXwCmBjQ1eQ+2huD+QLzrgaQIeUTRJB3Ggb 9DFh+icl8JudoJ6RMJPgBvslI03GLs7y51VzlXDWqkW/Q7SRjuUpv1mgN0dTMkjUYtDt +/2jHKfKmXQ75VXnCZYxT89omXqhRqK5BbKDjiVxo8UgRCowm1LYvb8bbIqM4sE/Q7z/ qgj8w21XO2v9HsPe2zWiDQkEhW7FLdDUq11t/LbfMC8k7rx/uRIpPjrpln43MkeRq+m+ oexA== 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=cszONKg+HElrbqP2TYdIroKi68JsEtE1MZy+CK2mlRg=; b=K0WQDew6l3Tv4HoCIcqw+OTr/nnr9141+WUamQx+eOUkr5DDFY9qfmNuIP579AmUYv KWwmUWwTG40iiD2p+b3aj67nhWo9LxZC/wOap0NpXYEKtfX8jl8fRicL5kNT4RPzR5hd VVuyGFP2jcdakfbwe+VCN6wJ0L0gKC61nMImaJM7wzSFWpoR/rgxRZJI7FHM3AY5wgBC bNrOASXyBfUpGlTElsj6MO/roTrULJgl+tLSDu/Zq3cvYif2XOk2wO+JErfzsL/kSYIf Sb047S3QyNgD0LddG3zdqLnpyFD1b9sNyCiztKz9fSRvBOJA1WO/aW1zXBUyH97Bvvlg C4Ew== 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 a33-v6si1857760plc.507.2018.04.11.14.59.19; Wed, 11 Apr 2018 14:59:56 -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 S933971AbeDKS6l (ORCPT + 99 others); Wed, 11 Apr 2018 14:58:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36748 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756560AbeDKS6j (ORCPT ); Wed, 11 Apr 2018 14:58:39 -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 52D5ADD3; Wed, 11 Apr 2018 18:58:38 +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.9 135/310] scsi: mpt3sas: Proper handling of set/clear of "ATA command pending" flag. Date: Wed, 11 Apr 2018 20:34:34 +0200 Message-Id: <20180411183628.264137152@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@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.9-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 @@ -4065,19 +4065,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 */ @@ -4103,6 +4090,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) @@ -4124,6 +4124,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); @@ -4154,6 +4155,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