Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2546654ybl; Sat, 14 Dec 2019 14:26:03 -0800 (PST) X-Google-Smtp-Source: APXvYqw36TYNU1438AOiGr2JjbPUaxH+ycrogh3/uqrrGsScXhGq0PE9lKlICBzcqfWkA2UZycec X-Received: by 2002:a9d:7b50:: with SMTP id f16mr23288309oto.18.1576362363799; Sat, 14 Dec 2019 14:26:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576362363; cv=none; d=google.com; s=arc-20160816; b=nA4F92YsFktagE11aiycEoFxeUWsDvC98eAHBKzmWL6upUpvKmV98NOp7wrbAn5eRZ I/8LgS6VjKtX/lfqU1crIkKflZ2CgLY3ddXz1ITJ6cWWkihzvmRK+RZIrNfMfDvgPW3t quzCjv4fOVHjH20yor2Rq1oUCm/mR6J74KdBWELHnbuNFPJZILQR+vAsM8COBAF2rqvk MdwZS7ZDkG6aiXravEs5t4G8rFeWgREMaHkB9l19nkByzps6TerxVU29aYKF+JSv9VDE 27UvmtY9CsM+XBgTu2C3NDC8tuipoaifY3GZixkLR3U2xDUU9xd9cWKFdvmVIUPIAnB1 6cuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=Y5yEn+ClqcrfpLwbDUFf91viLP/3PPAwp482cettCXw=; b=lBNHs3/cGu9YPXzX0sybd+PFQvA25mDenTLCABk4lVvxBtmzknSTwiFMNBSjiIMRkk 2kwDcYV/xMoe6aLL+SKLIWTR1gLsFrDWXFODGy81Bh/xlV0fCPBuaxJLMQxCQSafmbEY SCYBTTnqfTPnVBYc2sTCPsGSrkfZkdYNBh6JSL/H6Ri7Cp9XNuSCPoy5EGSQ/amUTjiV AAY8DEsxhQawRnm2IwLRAeaKVJi2w7PsJKsYBQW19eY79JKHXAnpCfJVSVlou/vrED6d zelnqxKjMH60EBVOIludOoKE6btLc9oNgWSxYS5kpouAIcPN7okgqBM3CSAcBTVXS6y5 CWZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=Ck31fifn; 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 101si8631903otc.322.2019.12.14.14.25.51; Sat, 14 Dec 2019 14:26:03 -0800 (PST) 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; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=Ck31fifn; 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 S1726948AbfLNWYt (ORCPT + 99 others); Sat, 14 Dec 2019 17:24:49 -0500 Received: from mail26.static.mailgun.info ([104.130.122.26]:35430 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726783AbfLNWYs (ORCPT ); Sat, 14 Dec 2019 17:24:48 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1576362288; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=Y5yEn+ClqcrfpLwbDUFf91viLP/3PPAwp482cettCXw=; b=Ck31fifnSJG7cH+9ooHMudV5w4VyFkWvu7IWGK8NwdtuqdAspam5iZELC8uappQT0eRDxiuT TqrljYgiuuU97EbXTKlwzvx2/gBeE3jmWSEzUMebcqvBFfxKRXLropF0LnyXSo6E01rAn4dA qgEf9MfgzyMxZ019Qpk1hqVgbPI= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5df5612e.7fee1ed14030-smtp-out-n01; Sat, 14 Dec 2019 22:24:46 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 86026C4479C; Sat, 14 Dec 2019 22:24:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: cang) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4572BC43383; Sat, 14 Dec 2019 22:24:43 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 15 Dec 2019 06:24:43 +0800 From: cang@codeaurora.org To: Bart Van Assche Cc: asutoshd@codeaurora.org, nguyenb@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, Alim Akhtar , Avri Altman , Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Venkat Gopalakrishnan , Tomas Winkler , open list Subject: Re: [PATCH 1/2] scsi: ufs: Put SCSI host after remove it In-Reply-To: <85475247-efd5-732e-ae74-6d9a11e1bdf2@acm.org> References: <1576328616-30404-1-git-send-email-cang@codeaurora.org> <1576328616-30404-2-git-send-email-cang@codeaurora.org> <85475247-efd5-732e-ae74-6d9a11e1bdf2@acm.org> Message-ID: <5aa3a266e3db3403e663b36ddfdc4d60@codeaurora.org> X-Sender: cang@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-12-15 02:32, Bart Van Assche wrote: > On 12/14/19 8:03 AM, Can Guo wrote: >> In ufshcd_remove(), after SCSI host is removed, put it once so that >> its >> resources can be released. >> >> Signed-off-by: Can Guo >> >> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c >> index b5966fa..a86b0fd 100644 >> --- a/drivers/scsi/ufs/ufshcd.c >> +++ b/drivers/scsi/ufs/ufshcd.c >> @@ -8251,6 +8251,7 @@ void ufshcd_remove(struct ufs_hba *hba) >> ufs_bsg_remove(hba); >> ufs_sysfs_remove_nodes(hba->dev); >> scsi_remove_host(hba->host); >> + scsi_host_put(hba->host); >> /* disable interrupts */ >> ufshcd_disable_intr(hba, hba->intr_mask); >> ufshcd_hba_stop(hba, true); > > Hi Can, > > The UFS driver may queue work asynchronously and that asynchronous > work may refer to the SCSI host, e.g. ufshcd_err_handler(). Is it > guaranteed that all that asynchronous work has finished before > scsi_host_put() is called? > > Thanks, > > Bart. Hi Bart, Thanks for pointing it out. I noticed that you are changing this path too in below 2 changes. https://marc.info/?l=linux-scsi&m=157591520015924&w=2 https://marc.info/?l=linux-scsi&m=157591519915923&w=2 Actually the async works you pointed may also affect your change, because you may tear down the hba->cmd_queue too early, as there can be devm commands sent by clock gating, eeh_work and eh_work after that point, meaning when blk_get_request is called in exec_dev_cmd(), hba->cmd_queue may have been released already. @@ -8263,6 +8232,7 @@ void ufshcd_remove(struct ufs_hba *hba) { ufs_bsg_remove(hba); ufs_sysfs_remove_nodes(hba->dev); + blk_cleanup_queue(hba->cmd_queue); scsi_remove_host(hba->host); /* disable interrupts */ ufshcd_disable_intr(hba, hba->intr_mask); How do you think if I replace my patch with below one? In this way, you can also move blk_cleanup_queue() behind cancel_work_sync(eh_work). diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index b5966fa..bd4ae75 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -8251,15 +8251,17 @@ void ufshcd_remove(struct ufs_hba *hba) ufs_bsg_remove(hba); ufs_sysfs_remove_nodes(hba->dev); scsi_remove_host(hba->host); - /* disable interrupts */ - ufshcd_disable_intr(hba, hba->intr_mask); - ufshcd_hba_stop(hba, true); - ufshcd_exit_clk_scaling(hba); ufshcd_exit_clk_gating(hba); if (ufshcd_is_clkscaling_supported(hba)) device_remove_file(hba->dev, &hba->clk_scaling.enable_attr); + cancel_work_sync(&hba->eeh_work); + cancel_work_sync(&hba->eh_work); + /* disable interrupts */ + ufshcd_disable_intr(hba, hba->intr_mask); + ufshcd_hba_stop(hba, true); ufshcd_hba_exit(hba); + ufshcd_dealloc_host(hba); } EXPORT_SYMBOL_GPL(ufshcd_remove); -- Thanks, Can Guo.