Received: by 10.192.165.148 with SMTP id m20csp1711601imm; Thu, 3 May 2018 04:17:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqFq/nc6tvALILsBXKqtUmofcNxKU9Dh24wRpa4L+53586wTNNULHReqWycVU1aSwWz9ip3 X-Received: by 2002:a63:a50a:: with SMTP id n10-v6mr19183862pgf.141.1525346265030; Thu, 03 May 2018 04:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525346264; cv=none; d=google.com; s=arc-20160816; b=T63yCUAHbsZiT8QcREz0VK19MNtn7kwqzjEGgK2guFhtA13fO7aLC/J/FmkaCnXdRj dVPYZd8WCRq537bMRXe4+hnWt8/gfe9N3hc+tq1a4BfOTAXzBnCnO45/dXHCPXQBTeAL Px0QguWXTsJFpFGKg/Q/gcd1QcZIO7MwFS4gMhvn+L70YO4mlpsitbm4kdsVc6De1/Qc emzOVThXik7a/IcemRhamFCJkjuAp4lpkBDJXQb7BYS2W/WN3rabR06McPr+UkNwHw6I caZUzYTyrLY720TqMQ6o6Q3gDdPaSlWWdafMNHANQvJcQhPjf6i2Q7hPRe64bJ1wwwfy oE1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=qtZrNWGGYmxlCz2R0WVXLvd8uKYBlWHw+VHnc8MfFW8=; b=NtrKj5lzRl55V/MofgnlSsDvMXnDqj9itUTz7hiDNSfztbv+M5l3r/8BLPtfHUMzJO slHVJsg6e4e1yJ3cTTNN5tValuhAdQD/CZdRe6PTqAN3ANdczvLWUqew6S/2DHHPPOmR H/ZTGUcLnT1W+aPqJQGxDQnl3ZHDLdmucT3Mef7Oo4NnJ4PWavNU6heBSjh42W/dJaT6 rNaB5Xgz80tXcYhnbiaTzc0BtIj95zAVRbAhAI3BDzZ+McSHvx5VlPnmclNV9GTdgtRh d1nm0J8hZISPNHesjUxuOs5L2cW5vE8MLglCIpA/v/AOZYe8FJgJA2LF+zbLgro9Yb18 +9DA== 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 i4-v6si11248539pgr.362.2018.05.03.04.17.31; Thu, 03 May 2018 04:17:44 -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 S1751903AbeECLPq (ORCPT + 99 others); Thu, 3 May 2018 07:15:46 -0400 Received: from alexa-out-tai-02.qualcomm.com ([103.229.16.227]:53647 "EHLO alexa-out-tai-02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751454AbeECLOR (ORCPT ); Thu, 3 May 2018 07:14:17 -0400 X-IronPort-AV: E=Sophos;i="5.49,358,1520870400"; d="scan'208";a="447818" Received: from ironmsg01-tai.qualcomm.com ([10.249.140.6]) by alexa-out-tai-02.qualcomm.com with ESMTP; 03 May 2018 19:07:50 +0800 X-IronPort-AV: E=McAfee;i="5900,7806,8881"; a="7302708" Received: from asutoshd-linux.qualcomm.com ([10.206.24.163]) by ironmsg01-tai.qualcomm.com with ESMTP; 03 May 2018 19:07:41 +0800 Received: by asutoshd-linux.qualcomm.com (Postfix, from userid 92687) id 269A82E91; Thu, 3 May 2018 16:37:39 +0530 (IST) From: Asutosh Das To: subhashj@codeaurora.org, cang@codeaurora.org, vivek.gautam@codeaurora.org, rnayak@codeaurora.org, vinholikatti@gmail.com, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com, asutoshd@codeaurora.org, linux-mmc@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Vijay Viswanath , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 10/10] scsi: ufs: Add clock ungating to a separate workqueue Date: Thu, 3 May 2018 16:37:22 +0530 Message-Id: <0bfae28dbfb4cf86e80435639b92c7f4023041dc.1525343531.git.asutoshd@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vijay Viswanath UFS driver can receive a request during memory reclaim by kswapd. So when ufs driver puts the ungate work in queue, and if there are no idle workers, kthreadd is invoked to create a new kworker. Since kswapd task holds a mutex which kthreadd also needs, this can cause a deadlock situation. So ungate work must be done in a separate work queue with WQ_MEM_RECLAIM flag enabled. Such a workqueue will have a rescue thread which will be called when the above deadlock condition is possible. Signed-off-by: Vijay Viswanath Signed-off-by: Can Guo Signed-off-by: Asutosh Das --- drivers/scsi/ufs/ufshcd.c | 11 ++++++++++- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 557d538..3be61b7 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1483,7 +1483,8 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) hba->clk_gating.state = REQ_CLKS_ON; trace_ufshcd_clk_gating(dev_name(hba->dev), hba->clk_gating.state); - schedule_work(&hba->clk_gating.ungate_work); + queue_work(hba->clk_gating.clk_gating_workq, + &hba->clk_gating.ungate_work); /* * fall through to check if we should wait for this * work to be done or not. @@ -1669,6 +1670,8 @@ static ssize_t ufshcd_clkgate_enable_store(struct device *dev, static void ufshcd_init_clk_gating(struct ufs_hba *hba) { + char wq_name[sizeof("ufs_clk_gating_00")]; + if (!ufshcd_is_clkgating_allowed(hba)) return; @@ -1676,6 +1679,11 @@ static void ufshcd_init_clk_gating(struct ufs_hba *hba) INIT_DELAYED_WORK(&hba->clk_gating.gate_work, ufshcd_gate_work); INIT_WORK(&hba->clk_gating.ungate_work, ufshcd_ungate_work); + snprintf(wq_name, ARRAY_SIZE(wq_name), "ufs_clk_gating_%d", + hba->host->host_no); + hba->clk_gating.clk_gating_workq = alloc_ordered_workqueue(wq_name, + WQ_MEM_RECLAIM); + hba->clk_gating.is_enabled = true; hba->clk_gating.delay_attr.show = ufshcd_clkgate_delay_show; @@ -1703,6 +1711,7 @@ static void ufshcd_exit_clk_gating(struct ufs_hba *hba) device_remove_file(hba->dev, &hba->clk_gating.enable_attr); cancel_work_sync(&hba->clk_gating.ungate_work); cancel_delayed_work_sync(&hba->clk_gating.gate_work); + destroy_workqueue(hba->clk_gating.clk_gating_workq); } /* Must be called with host lock acquired */ diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 76c31d5..2e6bdc0 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -361,6 +361,7 @@ struct ufs_clk_gating { struct device_attribute enable_attr; bool is_enabled; int active_reqs; + struct workqueue_struct *clk_gating_workq; }; struct ufs_saved_pwr_info { -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.