Received: by 10.223.185.116 with SMTP id b49csp272679wrg; Tue, 20 Feb 2018 21:04:23 -0800 (PST) X-Google-Smtp-Source: AH8x225e16BWan9MFEUYFO1oUTf1BOYfYJ3F15GXTDmm3DCVcxluhKqWKO9DW+HcQ9nlFhBJLtiT X-Received: by 10.99.52.203 with SMTP id b194mr1727937pga.349.1519189463371; Tue, 20 Feb 2018 21:04:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519189463; cv=none; d=google.com; s=arc-20160816; b=qchu8VNaXrU/K663HkFFmftF5LfLiJiBJUREmS2APu1CMD6HP0fAU0GK5mRT44k3l0 Q9rx4H1J5A+PAuF08HVSt/iefRps4RPtHcAdHaNx7wid0+SgdzbP5IXIaGZOFtyeNtUC rzmSw7dGyRhPAzKKNkbOKyj6QDeRBkNu1vHICofxubSLqW8U/8N0FJ3C1TkojavBjFj8 HgzTY+llBEcGQCtFlsf0RYyRc2ZPsJO+VpYhH/q8/A3IBfxG8uml6IlWJKzod/Ko05Fc 9ALQ2K/c8f8Bn5xwLnLeIHG0uyWm2j6G2KWvZ657nORvWR5qTTewnLc+Zt5oEEvynlpN CWkw== 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=u3cKm/P6WDZVKH65TKTPOLW459pgPEyvov9P7ys6fYc=; b=QRMoaLPV73mI5Z1HteRc7ywIMo8dJVHNpoAL+idFhIMOANPHr/K+0ZcfYx2lEO7SfQ IhmiM7jrQgaHjE4jjwLQLApMIf+YkqdWjI5fZBOh/xoBAESCqV4lVENqzeRUbML1EqCM jUsT6eFvYF1TzTVeF7IWe+UoUeLp+j8BppEg7N05eymH305Nj/YkZwD9Hh42mDIdBI9x pi4nnKeuPXRO7KhyoDSqjq4wX62V3M5FHNj18MojBYn08qoXTireCkZpRxm7S0aLrCfy g+9U+3qS9e2+8W2qaEv+3e5KEXYyvVWB86FkPYQMb7JT3Ww2APeMdZxBl3YnZ72+snB1 pI3A== 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 n6-v6si698678pla.619.2018.02.20.21.04.09; Tue, 20 Feb 2018 21:04:23 -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; 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 S1751480AbeBUFD2 (ORCPT + 99 others); Wed, 21 Feb 2018 00:03:28 -0500 Received: from alexa-out-tai-01.qualcomm.com ([103.229.16.226]:64584 "EHLO alexa-out-tai-01.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751417AbeBUFDZ (ORCPT ); Wed, 21 Feb 2018 00:03:25 -0500 X-IronPort-AV: E=Sophos;i="5.46,542,1511798400"; d="scan'208";a="707" Received: from ironmsg01-tai.qualcomm.com ([10.249.140.6]) by alexa-out-tai-01.qualcomm.com with ESMTP; 21 Feb 2018 12:57:03 +0800 X-IronPort-AV: E=McAfee;i="5900,7806,8810"; a="2400694" Received: from asutoshd-linux.qualcomm.com ([10.206.24.163]) by ironmsg01-tai.qualcomm.com with ESMTP; 20 Feb 2018 20:56:52 -0800 Received: by asutoshd-linux.qualcomm.com (Postfix, from userid 92687) id 8B6D92396; Wed, 21 Feb 2018 10:26:49 +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 Cc: linux-scsi@vger.kernel.org, Vijay Viswanath , Asutosh Das , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 9/9] scsi: ufs: Add clock ungating to a separate workqueue Date: Wed, 21 Feb 2018 10:26:40 +0530 Message-Id: <1c92a979dce897db920d9b9a625923d64cba2266.1519120988.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__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 | 10 +++++++++- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 6541e1d..bb3382a 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1503,7 +1503,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. @@ -1689,6 +1690,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; @@ -1696,6 +1699,10 @@ 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 = create_singlethread_workqueue(wq_name); + hba->clk_gating.is_enabled = true; hba->clk_gating.delay_attr.show = ufshcd_clkgate_delay_show; @@ -1723,6 +1730,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 4385741..570c33e 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.