Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1950110ima; Thu, 25 Oct 2018 07:27:43 -0700 (PDT) X-Google-Smtp-Source: AJdET5fYPC2U2xKhEGI46IFlRKOv7MoKbrlNd0bMVslmAgfZc3erEQTmN5S2bBjZWRii74M2+tOt X-Received: by 2002:a17:902:7e41:: with SMTP id a1-v6mr1711740pln.149.1540477663727; Thu, 25 Oct 2018 07:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540477663; cv=none; d=google.com; s=arc-20160816; b=NcDfBwswggdFkrgyMAPNIazSfy/9IyMEGH/htROmsbM/vQvhB8B6kfSSX3TiHliTO1 md0X2dY9FTLuikAwGjwx99p/Ig6MNNPtpntKb5flsz09VpwS5SLeXZdcmKOwAJyF5/GB 7iVCa5WvAf7KMEjoLZ73Z0O3B8ulGNcQP+Gj/vGvMeT6n/n2m20Iiyp6aNqRs6yh1L55 oKvN+wNR2QWZ7eYo3ZCb0Hqm7up2DfPiUdyb7ky12miviQ4p+TvlDZi6q1Ov904a86C4 GDpZwyTulNH6ZCRiUqv3yAG7ap2kBgEgBgzs09AdXuGWvlsfEG+0ov8kCAHovhZnTrss T3xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ssnFl9y0uRVsgXM4TKuQ1lIyAZom3ilsmo0v8h77rQk=; b=gmgiH8FtMh9xOpM1Ic6/jJGvhIV/FqikXPcJ4hGxmDyocYTQ4JQBnJrCUZKm7K6/x4 5quNW5daIN70wgInXi3G/nAjPJYLB7jcFk6x/0fuuOJC7GBuLnMVkOuj2N0cHfSXfokH iM8Tv+g4ewNGDS1byX7fWdWLUDkn7JETRTOhm11q/GHNKs5fu1SiRe3ZI4J5uoEEO8c9 dy8mBIjQm5o8plTv03m2c2CC0qcUflxKkLcpdfSGZUspNl5dRAqH61YtQdQmVJn/eJF3 rDbt+5s3GBGZJwxWkHyOU7+ZMB39IU8uGZZ9Fc9oNAwvZ2O+1uVLypK1DBw46jvU5Spz 9woA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iLePvqOI; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e13-v6si8041710pge.0.2018.10.25.07.26.45; Thu, 25 Oct 2018 07:27:43 -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; dkim=pass header.i=@kernel.org header.s=default header.b=iLePvqOI; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730909AbeJYWxM (ORCPT + 99 others); Thu, 25 Oct 2018 18:53:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:35538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730875AbeJYWxK (ORCPT ); Thu, 25 Oct 2018 18:53:10 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 555342147A; Thu, 25 Oct 2018 14:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540477212; bh=1n5SNyyr5qFt08kLKu2tpMLK0c62CjZoNp6440KVWyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iLePvqOIfJmLQyuQStbxcYRnGBTm7aCKLOt+XdmRfiYfjjJ6kNKddEfxpmts/T6IS 3SDasO61xBt9AniHIVzYxNS7lUADxm4B6sALcvI7omJiB6qCOI/leS6+1xgFnL+5C+ 9ShUbMeciy54QElImPIGQBvJ2JP4ftOY5aBQMRQE= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Heiko=20St=C3=BCbner?= , Michael Turquette , Sasha Levin Subject: [PATCH AUTOSEL 3.18 51/98] clk: rockchip: fix deadlock possibility in cpuclk Date: Thu, 25 Oct 2018 10:18:06 -0400 Message-Id: <20181025141853.214051-51-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141853.214051-1-sashal@kernel.org> References: <20181025141853.214051-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Heiko Stübner [ Upstream commit a5e1baf7dca10f8cf945394034013260297bc416 ] Lockdep reported a possible deadlock between the cpuclk lock and for example the i2c driver. CPU0 CPU1 ---- ---- lock(clk_lock); local_irq_disable(); lock(&(&i2c->lock)->rlock); lock(clk_lock); lock(&(&i2c->lock)->rlock); *** DEADLOCK *** The generic clock-types of the core ccf already use spin_lock_irqsave when touching clock registers, so do the same for the cpuclk. Signed-off-by: Heiko Stuebner Reviewed-by: Doug Anderson Signed-off-by: Michael Turquette [mturquette@linaro.org: removed initialization of "flags"] Signed-off-by: Sasha Levin --- drivers/clk/rockchip/clk-cpu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/clk/rockchip/clk-cpu.c b/drivers/clk/rockchip/clk-cpu.c index 75c8c45ef728..8539c4fd34cc 100644 --- a/drivers/clk/rockchip/clk-cpu.c +++ b/drivers/clk/rockchip/clk-cpu.c @@ -124,10 +124,11 @@ static int rockchip_cpuclk_pre_rate_change(struct rockchip_cpuclk *cpuclk, { const struct rockchip_cpuclk_reg_data *reg_data = cpuclk->reg_data; unsigned long alt_prate, alt_div; + unsigned long flags; alt_prate = clk_get_rate(cpuclk->alt_parent); - spin_lock(cpuclk->lock); + spin_lock_irqsave(cpuclk->lock, flags); /* * If the old parent clock speed is less than the clock speed @@ -164,7 +165,7 @@ static int rockchip_cpuclk_pre_rate_change(struct rockchip_cpuclk *cpuclk, cpuclk->reg_base + reg_data->core_reg); } - spin_unlock(cpuclk->lock); + spin_unlock_irqrestore(cpuclk->lock, flags); return 0; } @@ -173,6 +174,7 @@ static int rockchip_cpuclk_post_rate_change(struct rockchip_cpuclk *cpuclk, { const struct rockchip_cpuclk_reg_data *reg_data = cpuclk->reg_data; const struct rockchip_cpuclk_rate_table *rate; + unsigned long flags; rate = rockchip_get_cpuclk_settings(cpuclk, ndata->new_rate); if (!rate) { @@ -181,7 +183,7 @@ static int rockchip_cpuclk_post_rate_change(struct rockchip_cpuclk *cpuclk, return -EINVAL; } - spin_lock(cpuclk->lock); + spin_lock_irqsave(cpuclk->lock, flags); if (ndata->old_rate < ndata->new_rate) rockchip_cpuclk_set_dividers(cpuclk, rate); @@ -201,7 +203,7 @@ static int rockchip_cpuclk_post_rate_change(struct rockchip_cpuclk *cpuclk, if (ndata->old_rate > ndata->new_rate) rockchip_cpuclk_set_dividers(cpuclk, rate); - spin_unlock(cpuclk->lock); + spin_unlock_irqrestore(cpuclk->lock, flags); return 0; } -- 2.17.1