Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760038Ab2EVSHK (ORCPT ); Tue, 22 May 2012 14:07:10 -0400 Received: from na3sys009aog102.obsmtp.com ([74.125.149.69]:57121 "EHLO na3sys009aog102.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755172Ab2EVSHH (ORCPT ); Tue, 22 May 2012 14:07:07 -0400 MIME-Version: 1.0 In-Reply-To: <20120522135813.GL8730@tbergstrom-lnx.Nvidia.com> References: <1336798797-8724-1-git-send-email-skannan@codeaurora.org> <4FB29E7C.7010606@codeaurora.org> <20120522135813.GL8730@tbergstrom-lnx.Nvidia.com> From: "Turquette, Mike" Date: Tue, 22 May 2012 11:06:45 -0700 Message-ID: Subject: Re: [PATCH] clk: Fix race conditions between clk_set_parent() and clk_enable() To: Peter De Schrijver , Mark Brown Cc: Saravana Kannan , Andrew Lunn , Grant Likely , Jamie Iles , Jeremy Kerr , Magnus Damm , Deepak Saxena , "linux-arm-kernel@lists.infradead.org" , Arnd Bergman , Stephen Warren , "linux-arm-msm@vger.kernel.org" , Sascha Hauer , Rob Herring , Russell King , Thomas Gleixner , Richard Zhao , Shawn Guo , Paul Walmsley , Linus Walleij , Stephen Boyd , "linux-kernel@vger.kernel.org" , Amit Kucheria Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2684 Lines: 68 On Tue, May 22, 2012 at 6:58 AM, Peter De Schrijver wrote: > On Tue, May 15, 2012 at 08:20:44PM +0200, Saravana Kannan wrote: >> On 05/11/2012 09:59 PM, Saravana Kannan wrote: >> > Without this patch, the following race conditions are possible. >> > >> > Race condition 1: >> > * clk-A has two parents - clk-X and clk-Y. >> > * All three are disabled and clk-X is current parent. >> > * Thread A: clk_set_parent(clk-A, clk-Y). >> > * Thread A: >> > * Thread A: Grabs enable lock. >> > * Thread A: Sees enable count of clk-A is 0, so doesn't enable clk-Y. >> > * Thread A: Releases enable lock. >> > * Thread B: Calls clk_enable(clk-A), which in turn enables clk-X. >> > * Thread A: Switches clk-A's parent to clk-Y in hardware. >> > >> > clk-A is now enabled in software, but not clocking in hardware. >> > >> > Race condition 2: >> > * clk-A has two parents - clk-X and clk-Y. >> > * All three are disabled and clk-X is current parent. >> > * Thread A: clk_set_parent(clk-A, clk-Y). >> > * Thread A: >> > * Thread A: Switches parent in hardware to clk-Y. >> > * Thread A: Grabs enable lock. >> > * Thread A: Sees enable count of clk-A is 0, so doesn't disable clk-X. >> > * Thread A: Releases enable lock. >> > * Thread B: Calls clk_enable(clk-A) >> > * Thread B: Software state still says parent is clk-X. >> > * Thread B: So, enables clk-X and then itself. >> > * Thread A: Updates parent in software state to clk-Y. >> > > > This looks correct to me. Is there any usecase where enabling/disabling a > clock would require sleeping but changing the parent would not? > clk_enable & clk_disable must never sleep. clk_prepare and clk_unprepare may sleep. This patch would require the WM831x clock driver to set CLK_SET_PARENT_GATE for the clkout mux. The latest version of this driver sent out by Mark does not do this and I imagine that is because the hardware has no requirement for the mux clock to gate while switching parents. Holding the spinlock across the .set_parent callback breaks this driver since .set_parent results in an i2c transaction. Mark, do you have an opinion on the requirements that this patch imposes on your driver? Regards, Mike > Cheers, > > Peter. > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/