From patchwork Sat Aug 1 17:19:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6922521 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CDC40C05AC for ; Sat, 1 Aug 2015 17:20:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EA3F920501 for ; Sat, 1 Aug 2015 17:20:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E3309202B8 for ; Sat, 1 Aug 2015 17:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751470AbbHARUE (ORCPT ); Sat, 1 Aug 2015 13:20:04 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:33111 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751015AbbHARUA (ORCPT ); Sat, 1 Aug 2015 13:20:00 -0400 Received: by padck2 with SMTP id ck2so59214357pad.0 for ; Sat, 01 Aug 2015 10:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LCjl0YO3J7XGf1iVfPmFn/XFDT4mXjjJUoDPuenTSbI=; b=JhDPYAQeumATnKe4yScJM9v0BKcd2dKhVBYtasL3cBDklK6ry9ghoCEs/FJvRNEAab WTlbywk6oOiS+MmeJA3ZBiVo20byrhkarFo7qzcbactzm0IJEpM7n11wGvANSOxgCSEa CxAjKF/CzXpNoHdDl/dnfryz8IUeI7+YHrIIMHLPWmqz1QY3ZqJFAyM9GAwm/YTCDWMM /ZoovQBebLi1SkpvWgoBDnOmgDkOzW89dByq0FRe9awuDzT4ohrz4OT+4jhvp1tfLKUp nueYLTmPqLrrPD6mZJETvyURuhDshgb168CKNutFVYKi+c5/p7TmJ1ll0IxWDxzD6P6+ hhOg== X-Received: by 10.66.236.167 with SMTP id uv7mr19256630pac.134.1438449600393; Sat, 01 Aug 2015 10:20:00 -0700 (PDT) Received: from localhost.localdomain (KD113159139091.ppp-bb.dion.ne.jp. [113.159.139.91]) by smtp.gmail.com with ESMTPSA id tm3sm12259153pac.44.2015.08.01.10.19.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 01 Aug 2015 10:19:59 -0700 (PDT) From: Akinobu Mita To: linux-scsi@vger.kernel.org Cc: Akinobu Mita , Vinayak Holikatti , "James E.J. Bottomley" , Christoph Hellwig , Dolev Raviv , Sujit Reddy Thumma , Subhash Jadavani , Sahitya Tummala , Yaniv Gardi Subject: [PATCH v2 5/6] scsi: ufs: fix unloading module while runtime suspended Date: Sun, 2 Aug 2015 02:19:19 +0900 Message-Id: <1438449560-4106-6-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438449560-4106-1-git-send-email-akinobu.mita@gmail.com> References: <1438449560-4106-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ufs driver calls scsi_device_get() in ufshcd_set_dev_pwr_mode() in order to avoid manual delete of UFS device W-LUN by holding the reference. But scsi_device_get() has been changed to fail when the LLD module is in the process of being unloaded. So it no longer doesn't work if the module is unloaded while the device is runtime suspended. (i.e. driver_detach -> ... pm_runtime_get_sync() ... -> ufshcd_runtime_resume -> ufshcd_resume -> ufshcd_set_dev_pwr_mode -> scsi_device_get -> try_module_get -> return -ENXIO) As the reason for scsi_device_get() is to avoid manual delete of UFS device W-LUN, this acquires shost->scan_mutex lock instead of scsi_device_get() to work around the problem. Signed-off-by: Akinobu Mita Cc: Vinayak Holikatti Cc: "James E.J. Bottomley" Cc: Christoph Hellwig Cc: Dolev Raviv Cc: Sujit Reddy Thumma Cc: Akinobu Mita Cc: Subhash Jadavani Cc: Sahitya Tummala Cc: Yaniv Gardi Cc: linux-scsi@vger.kernel.org --- drivers/scsi/ufs/ufshcd.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index d425816..d287207 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4792,23 +4792,19 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba, struct scsi_sense_hdr sshdr; struct scsi_device *sdp; unsigned long flags; - int ret; + int ret = 0; + mutex_lock(&hba->host->scan_mutex); spin_lock_irqsave(hba->host->host_lock, flags); sdp = hba->sdev_ufs_device; - if (sdp) { - ret = scsi_device_get(sdp); - if (!ret && !scsi_device_online(sdp)) { - ret = -ENODEV; - scsi_device_put(sdp); - } - } else { + if (!sdp || !scsi_device_online(sdp)) ret = -ENODEV; - } spin_unlock_irqrestore(hba->host->host_lock, flags); - if (ret) + if (ret) { + mutex_unlock(&hba->host->scan_mutex); return ret; + } /* * If scsi commands fail, the scsi mid-layer schedules scsi error- @@ -4845,7 +4841,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba, if (!ret) hba->curr_dev_pwr_mode = pwr_mode; out: - scsi_device_put(sdp); + mutex_unlock(&hba->host->scan_mutex); hba->host->eh_noresume = 0; return ret; }