Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp881914pxk; Thu, 17 Sep 2020 20:13:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOSN73Sh2O3wXcb854fiGQ/LPKc4PJJklGQFy4hh2WUgS6OuPOBTKXzRpZTIevJ//afCYz X-Received: by 2002:a17:906:2b83:: with SMTP id m3mr16003415ejg.456.1600398827624; Thu, 17 Sep 2020 20:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398827; cv=none; d=google.com; s=arc-20160816; b=WOjXULKhlRMPDdqcVaG950edAiYMniCb/CP9yVqFCMxoIsoubAeyCJGYj+QEJmDJcd KNjZQk1kfsJYzmxs1OI8Z+vc8sKt46166FYkSrQzrisSH7DHbQH7XEIrXH8TI94u2ib2 JQolw4kJTkg2BsWRSbPwM7jVH3iqQ77buPr4X70+oA56/y00NJjnRuJ5NxcmeF76QpjS f+xxqUjW4SgTPlJ0rn4mXk8gx17MFZrlWzitaGGqWNgzqtNo2SNOQsfBnxS8IxISXQ3c ZJi9BVi69QB6Z9O8cL8XUSAJdWFN7fsXhB4CA1uJeR6h8FLbLlVeH7sCLpJYJqNYTLv0 3lTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hq3FxyBYNH+k9pdEra9P4JsjLnKp8DgM51H4ENVcKi4=; b=GUQQmFtslF3a5IPZhIq9jzlbJR00N0sQ5sbYcAiaAj+X+GfoiefXVny771SJqQv5qV GCTlNJSmvBEfuqpvUW38qoHpI2g7a94PPzAQGD78xXkelBmLifsnMDSas5gltT7EHj7O o5jXM14kg641lu3gsRlYjGEn1tZeKvTfGdt5+5uuF/6Z8DHdnzrsNuxWYvbAet5fmLIt 93rTFGrkX6wAE8k672qVChT3gJsJZiSihsGzNCletNUmpQ+tXqliXAtIGrFNdpibAngr vLrIydLU8+nsbUE4GnfPpQ7iv1hvQalASI4BDiu+zl3idJl0QJ+MdKMKZs4hC/MeBULP qBJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bVjdW9zR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp19si1151179ejc.122.2020.09.17.20.13.24; Thu, 17 Sep 2020 20:13:47 -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; dkim=pass header.i=@kernel.org header.s=default header.b=bVjdW9zR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730694AbgIRDLu (ORCPT + 99 others); Thu, 17 Sep 2020 23:11:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:47382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbgIRCCU (ORCPT ); Thu, 17 Sep 2020 22:02:20 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 21C28208DB; Fri, 18 Sep 2020 02:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394539; bh=c/L8j8VEhAr71cncFsoYSautMCqDG9hga+JTrHmg8Kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bVjdW9zRG7kNKZqrBHMEInABoYE4qiZ8R1s4IuaNNPkv8uHq6DXZDW+kfLPiVNdci 63AgPapz5P5wsttXVVSNxknKroWjoWzDXQARKYo90kXNkL7V+2XlWNEBqoeaLapu6E MfyEb/DTTFUJ0xFr0bITSyQDzBNCfrMtsfOWZUA0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: peter chang , Jack Wang , Deepak Ukey , Viswas G , "Martin K . Petersen" , Sasha Levin , pmchba@pmcs.com, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 057/330] scsi: pm80xx: Cleanup command when a reset times out Date: Thu, 17 Sep 2020 21:56:37 -0400 Message-Id: <20200918020110.2063155-57-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: peter chang [ Upstream commit 51c1c5f6ed64c2b65a8cf89dac136273d25ca540 ] Added the fix so the if driver properly sent the abort it tries to remove it from the firmware's list of outstanding commands regardless of the abort status. This means that the task gets freed 'now' rather than possibly getting freed later when the scsi layer thinks it's leaked but still valid. Link: https://lore.kernel.org/r/20191114100910.6153-10-deepak.ukey@microchip.com Acked-by: Jack Wang Signed-off-by: peter chang Signed-off-by: Deepak Ukey Signed-off-by: Viswas G Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/pm8001/pm8001_sas.c | 50 +++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c index 7e48154e11c36..7912ed64d3b9c 100644 --- a/drivers/scsi/pm8001/pm8001_sas.c +++ b/drivers/scsi/pm8001/pm8001_sas.c @@ -1202,8 +1202,8 @@ int pm8001_abort_task(struct sas_task *task) pm8001_dev = dev->lldd_dev; pm8001_ha = pm8001_find_ha_by_dev(dev); phy_id = pm8001_dev->attached_phy; - rc = pm8001_find_tag(task, &tag); - if (rc == 0) { + ret = pm8001_find_tag(task, &tag); + if (ret == 0) { pm8001_printk("no tag for task:%p\n", task); return TMF_RESP_FUNC_FAILED; } @@ -1241,26 +1241,50 @@ int pm8001_abort_task(struct sas_task *task) /* 2. Send Phy Control Hard Reset */ reinit_completion(&completion); + phy->port_reset_status = PORT_RESET_TMO; phy->reset_success = false; phy->enable_completion = &completion; phy->reset_completion = &completion_reset; ret = PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id, PHY_HARD_RESET); - if (ret) - goto out; - PM8001_MSG_DBG(pm8001_ha, - pm8001_printk("Waiting for local phy ctl\n")); - wait_for_completion(&completion); - if (!phy->reset_success) + if (ret) { + phy->enable_completion = NULL; + phy->reset_completion = NULL; goto out; + } - /* 3. Wait for Port Reset complete / Port reset TMO */ + /* In the case of the reset timeout/fail we still + * abort the command at the firmware. The assumption + * here is that the drive is off doing something so + * that it's not processing requests, and we want to + * avoid getting a completion for this and either + * leaking the task in libsas or losing the race and + * getting a double free. + */ PM8001_MSG_DBG(pm8001_ha, + pm8001_printk("Waiting for local phy ctl\n")); + ret = wait_for_completion_timeout(&completion, + PM8001_TASK_TIMEOUT * HZ); + if (!ret || !phy->reset_success) { + phy->enable_completion = NULL; + phy->reset_completion = NULL; + } else { + /* 3. Wait for Port Reset complete or + * Port reset TMO + */ + PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Waiting for Port reset\n")); - wait_for_completion(&completion_reset); - if (phy->port_reset_status) { - pm8001_dev_gone_notify(dev); - goto out; + ret = wait_for_completion_timeout( + &completion_reset, + PM8001_TASK_TIMEOUT * HZ); + if (!ret) + phy->reset_completion = NULL; + WARN_ON(phy->port_reset_status == + PORT_RESET_TMO); + if (phy->port_reset_status == PORT_RESET_TMO) { + pm8001_dev_gone_notify(dev); + goto out; + } } /* -- 2.25.1