Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3797608imb; Tue, 5 Mar 2019 20:23:40 -0800 (PST) X-Google-Smtp-Source: APXvYqzFyuB+VIM745Ok6f3jd0dDig/ikeHzsSgNrqP/lN7mCzDXZ5NvIx5FJ6/N4N1Lv34y4qU+ X-Received: by 2002:a62:4188:: with SMTP id g8mr5441590pfd.205.1551846220776; Tue, 05 Mar 2019 20:23:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551846220; cv=none; d=google.com; s=arc-20160816; b=C51WC9dEgX08wk1bq8d5/7oW6ZUAQpCzQcaV8McAZQIuzp9YrNit6hOwoCnQS4EiDG Fdy7btlr3ggrvvKpL3fsHagurFVifmOBBFzTRYj+mG98/2dRWpBDijgXlcUprXVMu18u kQRj78+XFDZi5offBWT/0PEIl46W+VCMCf0wKQKyr5lcIBKpN/ouIW5jptUfSmv8sUqi veVeGoEhau3+YWn5KQK8ntGA7RIR5rWA/kbdVYDJvgwUux4Cp11AzREgLDGEfHKZ5K70 gwOJq9haKO1V7Z146ub4Sn5D9qUVdrv0LLiP+Qv2N/iapzI1D1HIXpGiSqyD4iIDEgqD yjYA== 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 :in-reply-to:references:mime-version:dkim-signature; bh=StaGLvBUS5TkIV4j1JexcDZXarlMywUEPr5FgW/yy0o=; b=p3G5+kI69uwLz6IXYN6mNlylBUx5WxpnN5y9XxLYUvGBbyvvELHnbZC+VbKCktljze SWSJYmhfc8cbOgoTsaWNOxaPxCjKQ8rJFPRZ+4HJbx6XIlNAu7j9Atczc1wUrPz44ddO Bi+CsA7tf69RjIaaHbTV4fjjz1f5PkhIihOGhEQSEjzxFADW8H7H7HAYvw4UaulEw+7U dHJkF1eDfSyXkuss6WytrnJ6h45IanRmgbUNF3hKssjI2yKPiFK364AEIX4JnkRSTRKf sHFrFNuUgjoyiMsmhpRy3YPIZl2K0uryf9c5Mtr134G4BmVZPenzwfVUuB/ke77n+/uN jRQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="PneuEQz/"; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x123si692236pfx.135.2019.03.05.20.23.25; Tue, 05 Mar 2019 20:23:40 -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=@chromium.org header.s=google header.b="PneuEQz/"; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727082AbfCFEMJ (ORCPT + 99 others); Tue, 5 Mar 2019 23:12:09 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:39191 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726432AbfCFEMJ (ORCPT ); Tue, 5 Mar 2019 23:12:09 -0500 Received: by mail-it1-f193.google.com with SMTP id l15so8134468iti.4 for ; Tue, 05 Mar 2019 20:12:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=StaGLvBUS5TkIV4j1JexcDZXarlMywUEPr5FgW/yy0o=; b=PneuEQz/skP/WogMeUOW+UYsnaNE/hhVPn4Zv7tbSkwSNBVpHGZBTsOFMOlRXox3dq 4gNhG4yWKXNgsToj0PufVCK0vKMTZvDZIRi2hR+xwSpsXhJRPx7feF3xe7PxoqQpj2xl a7ES/NWzqQ1YKpH0+LLop6IVIBGc213WPiNGM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=StaGLvBUS5TkIV4j1JexcDZXarlMywUEPr5FgW/yy0o=; b=XFcsZZlSp7wDeuT3QtqWPEgIbVZsP+qKFwjR/lCCjATuGyN0C40dDQnyIwZRhsyyzU toI+LjPhfp5Gy3TRvrL/CHyQrc7U6ftHHgu2xmk79SdgeOxqc/Kz4V2ovhmw4SkKaqKI kZkHDEdG3cZJvouCN8FO7yOyYOXrvxcb1ntI6GSmWHHjfve9W74LkjZgp4K5K7onpwqV PVjqRKQmu0qsrQcle55HXeHCaTSvTJyIRdFzElvpdBJ55rcYBTC0j/MOF2Yn+On6Gy4S MNHqxq8Ez7kB39ZFRB1zJRkVp/fDSD7QsguLuR40FzxQsPN5Nxym64dVstybR+QWLX5h OlhQ== X-Gm-Message-State: APjAAAU45Iws3SymCt1+R2vMaq0TaMUjfZP0fw8zKdVFtS6zhuucuZ8b k5FxqFu9Dhk1P8EzwNwaLlONLUR+K2bYu5AxdHCjzg0On/I= X-Received: by 2002:a24:338a:: with SMTP id k132mr930699itk.123.1551845528178; Tue, 05 Mar 2019 20:12:08 -0800 (PST) MIME-Version: 1.0 References: <20190305044936.22267-1-dbasehore@chromium.org> <20190305044936.22267-2-dbasehore@chromium.org> <155181177527.20095.15680753964583935841@swboyd.mtv.corp.google.com> In-Reply-To: From: "dbasehore ." Date: Tue, 5 Mar 2019 20:11:57 -0800 Message-ID: Subject: Re: [PATCH v2 1/6] clk: Remove recursion in clk_core_{prepare,enable}() To: Stephen Boyd Cc: linux-kernel , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-doc@vger.kernel.org, Michael Turquette , =?UTF-8?Q?Heiko_St=C3=BCbner?= , aisheng.dong@nxp.com, mchehab+samsung@kernel.org, Jonathan Corbet , jbrunet@baylibre.com, Stephen Boyd 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 Tue, Mar 5, 2019 at 5:35 PM dbasehore . wrote: > > On Tue, Mar 5, 2019 at 10:49 AM Stephen Boyd wrote: > > > > Quoting Derek Basehore (2019-03-04 20:49:31) > > > From: Stephen Boyd > > > > > > Enabling and preparing clocks can be written quite naturally with > > > recursion. We start at some point in the tree and recurse up the > > > tree to find the oldest parent clk that needs to be enabled or > > > prepared. Then we enable/prepare and return to the caller, going > > > back to the clk we started at and enabling/preparing along the > > > way. This also unroll the recursion in unprepare,disable which can > > > just be done in the order of walking up the clk tree. > > > > > > The problem is recursion isn't great for kernel code where we > > > have a limited stack size. Furthermore, we may be calling this > > > code inside clk_set_rate() which also has recursion in it, so > > > we're really not looking good if we encounter a tall clk tree. > > > > > > Let's create a stack instead by looping over the parent chain and > > > collecting clks of interest. Then the enable/prepare becomes as > > > simple as iterating over that list and calling enable. > > > > > > Modified verison of https://lore.kernel.org/patchwork/patch/814369/ > > > -Fixed kernel warning > > > -unrolled recursion in unprepare/disable too > > > > > > Cc: Jerome Brunet > > > Signed-off-by: Stephen Boyd > > > Signed-off-by: Derek Basehore > > > --- > > > > From the original post: > > > > "I have some vague fear that this may not work if a clk op is framework > > reentrant and attemps to call consumer clk APIs from within the clk ops. > > If the reentrant call tries to add a clk that's already in the list then > > we'll corrupt the list. Ugh." > > > > Do we have this sort of problem here? Or are you certain that we don't > > have clks that prepare or enable something that is already in the > > process of being prepared or enabled? > > I can look into whether anything's doing this and add a WARN_ON which > returns an error if we ever hit that case. If this is happening on > some platform, we'd want to correct that anyways. > Also, if we're ever able to move to another locking scheme (hopefully soon...), we can make the prepare/enable locks non-reentrant. Then if anyone recursively calls back into the framework for another prepare/enable, they will deadlock. I guess that's one way of making sure no one does that. > >