From patchwork Mon Jan 8 12:04:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 10149293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4DD52602B3 for ; Mon, 8 Jan 2018 12:04:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DEB527F88 for ; Mon, 8 Jan 2018 12:04:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F4DC28697; Mon, 8 Jan 2018 12:04:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AFAE27F88 for ; Mon, 8 Jan 2018 12:04:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756172AbeAHMEu (ORCPT ); Mon, 8 Jan 2018 07:04:50 -0500 Received: from mx2.suse.de ([195.135.220.15]:56320 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756046AbeAHMEu (ORCPT ); Mon, 8 Jan 2018 07:04:50 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0DCACACC4; Mon, 8 Jan 2018 12:04:49 +0000 (UTC) From: Hannes Reinecke To: "Martin K. Petersen" Cc: Christoph Hellwig , James Bottomley , linux-scsi@vger.kernel.org, Yves-Alexis Perez , Hannes Reinecke , Hannes Reinecke Subject: [PATCHv2] libsas: Check for completed commands before calling lldd_abort_task() Date: Mon, 8 Jan 2018 13:04:46 +0100 Message-Id: <1515413086-34256-1-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The abort handler might be racing with command completion, so the task might already be NULL by the time the abort handler is called. Signed-off-by: Hannes Reinecke --- drivers/scsi/libsas/sas_scsi_host.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index 58476b7..08203fb 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -486,18 +486,34 @@ static int sas_queue_reset(struct domain_device *dev, int reset_type, int sas_eh_abort_handler(struct scsi_cmnd *cmd) { - int res; - struct sas_task *task = TO_SAS_TASK(cmd); + int res = TMF_RESP_FUNC_COMPLETE; + struct sas_task *task; struct Scsi_Host *host = cmd->device->host; struct sas_internal *i = to_sas_internal(host->transportt); + struct domain_device *dev = cmd_to_domain_dev(cmd); + struct sas_ha_struct *ha = dev->port->ha; + unsigned long flags; if (!i->dft->lldd_abort_task) return FAILED; - res = i->dft->lldd_abort_task(task); + /* Avoid sas_scsi_task_done() interfering */ + spin_lock_irqsave(&dev->done_lock, flags); + task = TO_SAS_TASK(cmd); + if (test_bit(SAS_HA_FROZEN, &ha->state)) { + res = TMF_RESP_FUNC_FAILED; + task = NULL; + } else + ASSIGN_SAS_TASK(cmd, NULL); + spin_unlock_irqrestore(&dev->done_lock, flags); + if (task) + res = i->dft->lldd_abort_task(task); if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE) return SUCCESS; + spin_lock_irqsave(&dev->done_lock, flags); + ASSIGN_SAS_TASK(cmd, task); + spin_unlock_irqrestore(&dev->done_lock, flags); return FAILED; } EXPORT_SYMBOL_GPL(sas_eh_abort_handler);