Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6219368rwb; Mon, 14 Nov 2022 16:34:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf6iFtZrnppNfdZ0tOo8be+v21vD8xPxWgX7k344kAnSCmv5NGft5ca94YaL3NaSPYoyZRBb X-Received: by 2002:aa7:8d1a:0:b0:56d:d08c:baf0 with SMTP id j26-20020aa78d1a000000b0056dd08cbaf0mr16331542pfe.72.1668472453616; Mon, 14 Nov 2022 16:34:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668472453; cv=none; d=google.com; s=arc-20160816; b=WQlOFTUw4pnkoQI6La85plFxKrp4qowkwzGzKNTa9m7QZDOO8doYlLfi72LqOphg++ w2Q+8IRQ4rf4rfxiVSStLomQAiUk+TmjZm3pu+gkF6/LZ3sjsrnsPJODf5uWEH+H8vEC hQQHGdfcBNDsczqfHLjCXh4uwk7CV/7mm5RAY1aEiRaLhqIar3U6i9BJozqLi3rsmYmm MUxwukCsFZs73VmPp/7jqwC09hp66fUknw+R6XkIRmA7KLb5yXFq0LJdyQnZNfeLFwjO AONRJYbDhQHhDEcSKbg0WGy715/rP4pH7lXUy8y8O59K3/QK/xDg4c1g7cSRtsZkqwOc ZGvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=e8DEyGtnR3E51A3LHZsY+6bNt9izsNvoJTKMNpkota0=; b=O44ZKgLq/kagZuMnrcJPdE5BSL4M7MOj/dBwvBoj6b62XBsWs6PJxuao8SgoIehWmE ZzdFNIlc6he7+q4slPRVg6XXZ8D6lJmjUevPU6h1a8SJKtZ9PfMxRMaKkEE/9zoiCX8+ WQ7Um4FNlq7yUkSWlpbUa6yKg7F/ojWkAfNTmWW7KCCd4PP4QPAW8NpDD0yCqxbot4WE mDP1Ow0QXVuXwURXWmxzM2PrkK2pOG4BiWfKAlvgAdX2agDM0+Xbvv3qANcYC+ma+zjU FxNwczyt7nCCAKUIrtMUrxCGvn+bwK5HXDpxNRM2ZxpgONSW2/wnm4sIwbbZde9w0+So qSag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=b6losVzS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u14-20020a63790e000000b0043c0b4f2b68si11046442pgc.318.2022.11.14.16.34.02; Mon, 14 Nov 2022 16:34:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=b6losVzS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236406AbiKOAI2 (ORCPT + 88 others); Mon, 14 Nov 2022 19:08:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236120AbiKOAI0 (ORCPT ); Mon, 14 Nov 2022 19:08:26 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 161082F2 for ; Mon, 14 Nov 2022 16:08:24 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id s5so3453967edc.12 for ; Mon, 14 Nov 2022 16:08:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=e8DEyGtnR3E51A3LHZsY+6bNt9izsNvoJTKMNpkota0=; b=b6losVzSt1LsO1uAuD3bhs2NGAXC8uf9KiabRTwzuTa1mNOajTwAvj9lgPz9xCqgB0 OdhliqNT3S6ehFbfekme7ex+RkUMXEWjyv6U1s2uSsBulLxff149DQJCXq1NlLq4UFuO MfstcMGHw/zmNh7ohyPGNT6fQZUtaFre4lAxY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=e8DEyGtnR3E51A3LHZsY+6bNt9izsNvoJTKMNpkota0=; b=QGCbcJd0pLJf8LXtwBvAs6xmWTrAbNkxZsHneOkQ+804K0ubNYxst40XUYl4oawqk/ XWnzS0A8XO8MOKes5HxsCy3ua9uDB5HE8ZPtj8OeDuVcxkB/vEEeozwisVJybgPLL72n URVOzfY+NJxjTKDQeiJSWJ6p8JW6ouTjct1y8dRlC940hg6ND9tQamRP8aAOGebg9+Ga Psl6QVrtMfAZGEfFCyRvOcTI5S5GUcIrzapgzca7iIfPjd8g8Vn5dDbpJFlabsCcOECD 91K3ROLZmE8Ru2pSXOES9QIYNSOtuBpY+HfG70qq+4BWQyf5AH9bIsSGm0N+0VdqhCzk p0Qw== X-Gm-Message-State: ANoB5pmMAPJ2IbHHu6ldOvcBwKnXlXv+a9hUK94PotP/IpVn8rhYZE70 Tk6wgX8EjMElvv0Y2OflMCpI9EhyJsrgmYu8 X-Received: by 2002:a05:6402:501a:b0:467:6b55:3cf5 with SMTP id p26-20020a056402501a00b004676b553cf5mr12287483eda.22.1668470902468; Mon, 14 Nov 2022 16:08:22 -0800 (PST) Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com. [209.85.128.54]) by smtp.gmail.com with ESMTPSA id w12-20020a056402128c00b0046730154ccbsm5422758edv.42.2022.11.14.16.08.17 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Nov 2022 16:08:18 -0800 (PST) Received: by mail-wm1-f54.google.com with SMTP id j5-20020a05600c410500b003cfa9c0ea76so9152249wmi.3 for ; Mon, 14 Nov 2022 16:08:17 -0800 (PST) X-Received: by 2002:a05:600c:1c97:b0:3cf:b0ed:de9d with SMTP id k23-20020a05600c1c9700b003cfb0edde9dmr9143461wms.188.1668470896844; Mon, 14 Nov 2022 16:08:16 -0800 (PST) MIME-Version: 1.0 References: <20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid> In-Reply-To: <20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid> From: Doug Anderson Date: Mon, 14 Nov 2022 16:08:04 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/3] clk: qcom: lpass-sc7280: Fix pm_runtime usage To: Bjorn Andersson Cc: Taniya Das , Dmitry Baryshkov , Judy Hsiao , Srinivasa Rao Mandadapu , Matthias Kaehlcke , Andy Gross , Konrad Dybcio , Michael Turquette , Stephen Boyd , Taniya Das , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Stephen Boyd Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bjorn, On Fri, Nov 4, 2022 at 6:57 AM Douglas Anderson wrote: > > The pm_runtime usage in lpass-sc7280 was broken in quite a few > ways. Specifically: > > 1. At the end of probe it called "put" twice. This is a no-no and will > end us up with a negative usage count. Even worse than calling > "put" twice, it never called "get" once. Thus after bootup it could > be seen that the runtime usage of the devices managed by this > driver was -2. > 2. In some error cases it manually called pm_runtime_disable() even > though it had previously used devm_add_action_or_reset() to set > this up to be called automatically. This meant that in these error > cases we'd double-call pm_runtime_disable(). > 3. It forgot to call undo pm_runtime_use_autosuspend(), which can > sometimes have subtle problems (and the docs specifically mention > that you need to undo this function). > > Overall the above seriously calls into question how this driver is > working. It seems like a combination of "it doesn't", "by luck", and > "because of the weirdness of runtime_pm". Specifically I put a > printout to the serial console every time the runtime suspend/resume > was called for the two devices created by this driver (I wrapped the > pm_clk calls). When I had serial console enabled, I found that the > calls got resumed at bootup (when the clk core probed and before our > double-put) and then never touched again. That's no good. > [ 0.829997] DOUG: my_pm_clk_resume, usage=1 > [ 0.835487] DOUG: my_pm_clk_resume, usage=1 > > When I disabled serial console (speeding up boot), I got a different > pattern, which I guess (?) is better: > [ 0.089767] DOUG: my_pm_clk_resume, usage=1 > [ 0.090507] DOUG: my_pm_clk_resume, usage=1 > [ 0.151885] DOUG: my_pm_clk_suspend, usage=-2 > [ 0.151914] DOUG: my_pm_clk_suspend, usage=-2 > [ 1.825747] DOUG: my_pm_clk_resume, usage=-1 > [ 1.825774] DOUG: my_pm_clk_resume, usage=-1 > [ 1.888269] DOUG: my_pm_clk_suspend, usage=-2 > [ 1.888282] DOUG: my_pm_clk_suspend, usage=-2 > > These different patterns have to do with the fact that the core PM > Runtime code really isn't designed to be robust to negative usage > counts and sometimes may happen to stumble upon a behavior that > happens to "work". For instance, you can see that > __pm_runtime_suspend() will treat any non-zero value (including > negative numbers) as if the device is in use. > > In any case, let's fix the driver to be correct. We'll hold a > pm_runtime reference for the whole probe and then drop it (once!) at > the end. We'll get rid of manual pm_runtime_disable() calls in the > error handling. We'll also switch to devm_pm_runtime_enable(), which > magically handles undoing pm_runtime_use_autosuspend() as of commit > b4060db9251f ("PM: runtime: Have devm_pm_runtime_enable() handle > pm_runtime_dont_use_autosuspend()"). > > While we're at this, let's also use devm_pm_clk_create() instead of > rolling it ourselves. > > Note that the above changes make it obvious that > lpassaudio_create_pm_clks() was doing more than just creating > clocks. It was also setting up pm_runtime parameters. Let's rename it. > > All of these problems were found by code inspection. I started looking > at this driver because it was involved in a deadlock that I reported a > while ago [1]. Though I bisected the deadlock to commit 1b771839de05 > ("clk: qcom: gdsc: enable optional power domain support"), it was > never really clear why that patch affected it other than a luck of > timing changes. I'll also note that by fixing the timing (as done in > this change) we also seem to aboid the deadlock, which is a nice > benefit. > > Also note that some of the fixes here are much the same type of stuff > that Dmitry did in commit 72cfc73f4663 ("clk: qcom: use > devm_pm_runtime_enable and devm_pm_clk_create"), but I guess > lpassaudiocc-sc7280.c didn't exist then. > > [1] https://lore.kernel.org/r/20220922154354.2486595-1-dianders@chromium.org > > Fixes: a9dd26639d05 ("clk: qcom: lpass: Add support for LPASS clock controller for SC7280") > Signed-off-by: Douglas Anderson > --- > > drivers/clk/qcom/lpassaudiocc-sc7280.c | 55 ++++++++++---------------- > 1 file changed, 21 insertions(+), 34 deletions(-) Is anything blocking this series from landing? I noticed a few other patches have landed since then to your Qualcomm clk branch, but I don't see these there. I assume it'll land through your tree. Thanks! -Doug