From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1418C43381 for ; Wed, 6 Mar 2019 04:12:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93DE620675 for ; Wed, 6 Mar 2019 04:12:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="PneuEQz/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727181AbfCFEMJ (ORCPT ); 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-Google-Smtp-Source: APXvYqzzglElDR1D4t81plRiZtamMX56ugLYpYTHsVMIRqPBa76+GJwz3Vhuamnt3DPyIOFqzcF9CAFlAI2q+Jptzao= 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. > > From mboxrd@z Thu Jan 1 00:00:00 1970 From: "dbasehore ." Subject: Re: [PATCH v2 1/6] clk: Remove recursion in clk_core_{prepare, enable}() Date: Tue, 5 Mar 2019 20:11:57 -0800 Message-ID: References: <20190305044936.22267-1-dbasehore@chromium.org> <20190305044936.22267-2-dbasehore@chromium.org> <155181177527.20095.15680753964583935841@swboyd.mtv.corp.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=m.gmane.org@lists.infradead.org To: Stephen Boyd Cc: aisheng.dong@nxp.com, =?UTF-8?Q?Heiko_St=C3=BCbner?= , linux-doc@vger.kernel.org, Michael Turquette , Jonathan Corbet , Stephen Boyd , linux-kernel , linux-rockchip@lists.infradead.org, mchehab+samsung@kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jbrunet@baylibre.com List-Id: linux-rockchip.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. > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ABA0C43381 for ; Wed, 6 Mar 2019 04:12:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4982E20675 for ; Wed, 6 Mar 2019 04:12:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="USWZiK3A"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="PneuEQz/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4982E20675 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AtCCM+WP60E7yhJztvB5EAix1zNZwUKc8XFE4Fw4mLI=; b=USWZiK3AeWborI 7ejN15GiA096YfDKxKgyT60Z+veZ7zVo04+2BBNSquPQBxSSgupliX/aC3NuWnRZR9Xc22KI0Z/u1 aMlRQ6Rw3vFvZb2ZqewpQsa507/Aa65yGTJOcw2q+hCcaf816+vUMKnjMlf3BCgYTYb3CWAaZdWQ5 fGaJzM3Z9kMW5YFzAad5AK3D6JaxuJomHO51CuDtKnhIFEvVzVCU2lE7N/ZS2gOtAVdej5UAFoV9Q TCpKCx4YAB7qVh/el+kVgC+W8ETD8o39pOYidK5oLI3DJoxuDrOXd+9YzTYt9Gmx5mXPW6wPByyxb MxhPCw/zKzXzthnSWNDg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h1Nuf-0005fC-Pg; Wed, 06 Mar 2019 04:12:13 +0000 Received: from mail-it1-x144.google.com ([2607:f8b0:4864:20::144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h1Nub-0005eG-MO for linux-arm-kernel@lists.infradead.org; Wed, 06 Mar 2019 04:12:11 +0000 Received: by mail-it1-x144.google.com with SMTP id l139so8123600ita.5 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=iMzWVhG/K6go1WENY+qXdPnWY563aGOab4JZCKQZslzoLBpnR389la7c2DlLeDRU1O 8M3SC2rKSgwxptiQXqXpuGRXBABYtH8M4ptDaD8w+UDIT6pE9XHiRHeNl0XB1kDm3TZI YbQ/lC267z0lsphA1vBwyuyG/wZIPNwlJ5gMMLwktH+wz26fTTUUtc9EvGJ1NObTdQcZ Pvt5H1Mlc8tbYmniQGEaTyEVjgMRzolNJtahsfak3aS1qaEFQrOl4h4Cu7TiivcrqMXZ nPQt0rE6ewl3ruFaFqnNRhf9kmB9oK5XkAHbzwmOVC34jaG4YlwgG7HiTPckCxgmOjx9 DhLw== X-Gm-Message-State: APjAAAU3hsmIotfHzC4g3A4WXCOCgXUBE4+ywzI+vVSjruIQ5yFYecL9 sMrwGgxJG2mETTHld44356chQiucat+l3RyrD/5+CQ== X-Google-Smtp-Source: APXvYqzzglElDR1D4t81plRiZtamMX56ugLYpYTHsVMIRqPBa76+GJwz3Vhuamnt3DPyIOFqzcF9CAFlAI2q+Jptzao= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190305_201209_759647_AE0C77D3 X-CRM114-Status: GOOD ( 24.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aisheng.dong@nxp.com, =?UTF-8?Q?Heiko_St=C3=BCbner?= , linux-doc@vger.kernel.org, Michael Turquette , Jonathan Corbet , Stephen Boyd , linux-kernel , linux-rockchip@lists.infradead.org, mchehab+samsung@kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jbrunet@baylibre.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.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. > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel