Received: by 10.223.185.116 with SMTP id b49csp1305320wrg; Fri, 23 Feb 2018 15:58:58 -0800 (PST) X-Google-Smtp-Source: AH8x22519y0rmqebKB70f/+S+A2MUVg6JA3YQoBgTRMLs5BNMvH6qEg7Ust+DXVZ3ys6ExEwtDVt X-Received: by 10.101.73.197 with SMTP id t5mr2727729pgs.426.1519430338675; Fri, 23 Feb 2018 15:58:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519430338; cv=none; d=google.com; s=arc-20160816; b=h9bvkkCLU4AuinMylLtcWwC9aZnwpxBWVFgf2b7fPyguYf8MCN0mPnpOXQP9sGnZ4n YSirOM7DQK/TDi1VmUTSZ60htaW6AEVoC9QDM8/15t/oX7JxFaWLewM46Hy+N9vxDc0C OwCMdQpF58NO5bRiRJeJ/yX6+UT2a6Hmtp+RCHKNPkRVJ+L0MosS1/yTBkLY+H2CtObR r3SOU5rv8VHNrWP+0N0SE94uL8xgV2ps+nMyaVBdc3S9y7UoE4C1syMe0k2+WhXoBQN6 +8wcTInyzGvdgam6VtM9YLBZJzqKumFOsOlS8xTTxyjt+TtxP2gzq1ElR7HjKERSo1JV bM1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ighOOD8Zu0xsFvyXlwEKyUSWUZkTThhU+sbHOVFLKqU=; b=LPnv8HzjafHmpkx3PQ0GYy5B1rouU5cT7MrxKSHfKXY1stqhcRSXT4LgS3piVjiEpf 4te1kxoKMUSreb9t+zW/0TnjlYWy7HdKfc1oux8cJqPI0IgoFfVKehG7Rv+OM1f4amOw bjU6X8CSQU1kzpD7PmkyyAy8j0MQ+vBrcrvkdaBdoqBPouFEyn23uGYGxX+DSzR3mw0M qzYRwp+uKiJd1NceyAH0EsFAzO1R0BsfflBdSsiEDO/tFA6ZYt7A0oospf9Z7bIZzW4O NJBH8x6XoBvcTdoNqpUQPEzpQXF24sJO+4SHfnh7Dl9I5egytJe2IuvNu4rJHhNuuov5 vcdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RjvOT+L4; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si2132012pgc.455.2018.02.23.15.58.42; Fri, 23 Feb 2018 15:58:58 -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=pass header.i=@gmail.com header.s=20161025 header.b=RjvOT+L4; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752586AbeBWX6D (ORCPT + 99 others); Fri, 23 Feb 2018 18:58:03 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:36138 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752014AbeBWX6B (ORCPT ); Fri, 23 Feb 2018 18:58:01 -0500 Received: by mail-qt0-f195.google.com with SMTP id c7so12586866qtn.3; Fri, 23 Feb 2018 15:58:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ighOOD8Zu0xsFvyXlwEKyUSWUZkTThhU+sbHOVFLKqU=; b=RjvOT+L4Z2Tw9mBc2yyGOCNpZhcfK8ovHZojVRT4qFbnbdmmjpje9BG122M0IwXQFT 5+AQmTm1TKZwb3yhx6upzOJnX3ors7go3fFGCZ57XoFlqF2F16Rf1chtWCzDvmFSTCBX QN6Vn0/mHhpFTERUxbi7rzixGO7+9QMqQrwobNRSWBSeOB20VFI54bx3+MEEtG0Aayk9 8r1vlNeO6Ek+yYCPBO6IFfCSis9CZSv6m/VdTh2Kga0TFVc36ixKtNjc2suZ7hh2Tmvs DQWjoXQpXfXo7aUvH/xmWVz5uwv8v6fy2QxJQgP5oaa2mAoH7RlP2dEOEXWVTNZYyefM +m8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ighOOD8Zu0xsFvyXlwEKyUSWUZkTThhU+sbHOVFLKqU=; b=XuLa4A9fzidnGhS2xO92VIm/aF6uaQL5aaa484Whm9G0G/GSfXWE9pgV2h0Nk7CYDx CkjNH7M4xK53UifrpDWZUXPVXT2oB82I1CeI5dq3zkwStoP7rzmaitW1Dg7y2OD/acBo EVaG0adK3HaBq68Vr7sW+/qPOTFr+gOkF9vU+piNdFJkYlh8SR2ynRQ1BEVEvS3iQela Yhl9uXgPetd/myrtaqpQ9a41HiCouvIZyWpByB7OUievQpC8N/Ezl/rSSNpv3IVLraGz lRkC6BmdLubZHLDK1UpVx07RdyqCzEHP5LBI7r3tzyK1TSLImX8fc99CGEO3viso1qlO oDJA== X-Gm-Message-State: APf1xPA9oPRIZrHnG9XnUTEMDLsB+QiW1b16GIOVCO/b7dsbhl/YdPVM lQoWoTJu7Lro6G7iHO1QMYWOW/XatYR//Odt1Eab99OlzHs= X-Received: by 10.200.48.229 with SMTP id w34mr5452319qta.226.1519430280784; Fri, 23 Feb 2018 15:58:00 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.52.247 with HTTP; Fri, 23 Feb 2018 15:57:40 -0800 (PST) In-Reply-To: <1c92a979dce897db920d9b9a625923d64cba2266.1519120988.git.asutoshd@codeaurora.org> References: <1c92a979dce897db920d9b9a625923d64cba2266.1519120988.git.asutoshd@codeaurora.org> From: Miguel Ojeda Date: Sat, 24 Feb 2018 00:57:40 +0100 Message-ID: Subject: Re: [PATCH 9/9] scsi: ufs: Add clock ungating to a separate workqueue To: Asutosh Das Cc: 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, linux-scsi@vger.kernel.org, Vijay Viswanath , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 21, 2018 at 5:56 AM, Asutosh Das wrote: > 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 WQ_MEM_RECLAIM here. Also space after dot. > 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); Shouldn't this be alloc_ordered_workqueue() with WQ_MEM_RECLAIM then? (create_singlethread_workqueue() and friends are deprecated). Cheers, Miguel > + > 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. >