Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp1449812rwl; Fri, 4 Nov 2022 14:13:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4GdL3sAW8w+LkrMp1eAze1zhC5qYVMTWQTspDgGBGHhO5rBC3dgE+wc9C7GX9ijVjjP4UC X-Received: by 2002:a17:902:d386:b0:187:190f:6ac7 with SMTP id e6-20020a170902d38600b00187190f6ac7mr30586351pld.170.1667596435827; Fri, 04 Nov 2022 14:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667596435; cv=none; d=google.com; s=arc-20160816; b=uaQn+eZLr00VhPMlbz62L6A9WMGo15bJkpIWa8cnNcNsxaLSpWC8REX2/eksvIRVHj D/HrhCiba1b2CLy1yHKCR97mU4ROqsO06S8PpjLK2C7UtF1hsEhA5WVebLVh0DhOragn p+mkpRTUZEiZX726Dz+3rB1Q6ZWhBv89o0/uXMuQa6LSKmL6OdJ8kYYpxMigj+W0SEgc 9WYV05w0Pvfk7ZwQnYp34Q506SJ5SQXveQmKexYDonjo+6eSNTl4kqb6sL/SxLow9/nd Zne1gfx5l98nJIOqVB02xiplQfSzEuK9cKbNaBNg82Bvuy3A5KZO2Vs1JbzD1GznQYhH 3kJw== 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:user-agent:from :references:in-reply-to:mime-version:dkim-signature; bh=zMfksGVovJyKssatLq3qPApzW4xAJ9RmshsVA1B1FUM=; b=ian66ZPVtauHWsZjehgM90Ua/5rbxg3hr/S7E/sExYB2hs2xvVNR3kaA6LCnqITdLg gumKNTFSmo2bQgXemBDJY85bE9HyWomtzZKRBuR/kBUMPQvncWmFYekOLXzZytN1o5Vn Fwk9P/cURHlD9dCHyHcrLYMr+N0En1E5/IbxohWv3Qv2CXrC7aUjOZGpJbQigCSk8tgi hXekOL7xc9vL+X9k4jv/+Q8xwStKyczzOjK4jdU7cJEYCwhQ4NF3+rRF4aNN/EWgWOVf EIia3GWpJchQzZ5B1C3WXZI+9EVOORoH7jq9uBNkSfIARwCh4Hox9Rs11OcBkop9putH aAtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AOyUYLhQ; 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 q8-20020a632a08000000b004700eee2923si583945pgq.792.2022.11.04.14.13.43; Fri, 04 Nov 2022 14:13:55 -0700 (PDT) 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=AOyUYLhQ; 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 S230017AbiKDUva (ORCPT + 97 others); Fri, 4 Nov 2022 16:51:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbiKDUv1 (ORCPT ); Fri, 4 Nov 2022 16:51:27 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27A4149B46 for ; Fri, 4 Nov 2022 13:51:26 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id b3so8948408lfv.2 for ; Fri, 04 Nov 2022 13:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:subject:message-id:date:user-agent:from:references :in-reply-to:mime-version:from:to:cc:subject:date:message-id :reply-to; bh=zMfksGVovJyKssatLq3qPApzW4xAJ9RmshsVA1B1FUM=; b=AOyUYLhQB+OF+RwYwdDwwmQ38cHBcpL55GVlYYpbmo/IhTvhxI2JCo4BQLlSpPfIt2 A7kQpV15ys91B7Xw/oO6H4/94pyD7p5R/9pipaspVrj1YHbAAqWxDnhqCXtufv9IbnSe ojKjV/3UgyYxiFjqcvbEBI8RtCfQXB/dzzgWQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:user-agent:from:references :in-reply-to:mime-version:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zMfksGVovJyKssatLq3qPApzW4xAJ9RmshsVA1B1FUM=; b=KL9XHK4hJ4J3Ht2wzJ4oL6xfQCEQt+u9jX9kaxgEd5hL2nTWMFKO5sFgKyya9NtTBH Sz64ko6b0MmL6+4sd2PXbTtPUXrSJWxHyEwk4mYXW6IIsqDMJ0FGwkH92onFemZSBrRy PjYKde6mO8n9VwCFsYWW/YRfEa9X5ao87tWPIxbrcVFeCZvpdffEzHxjeB8z5qrrE8iX XSkFVNVAvmVJEGCOPGP/LFAT6gpLBEu2wBHJP96BjnGxBnmpp4VTMThx2L/N1rC2Urh6 Nl0YiOVc/2CQwd7OcqGtwx6acH9V5j0HQthxB6Z5dHRUJaSaZzLxs8aqOgxcKNJAR7QB Dd5Q== X-Gm-Message-State: ACrzQf2bdHXO4B20FVIhKWTayhkVO9Mumm5X+yXfRJa0V+D1N7ZczLne 1lObCxyAlvIDrx8V2tht+txqS3gEH5VLFL+OuZ17qw== X-Received: by 2002:a05:6512:3dac:b0:4a4:8044:9c3 with SMTP id k44-20020a0565123dac00b004a4804409c3mr13585880lfv.145.1667595084419; Fri, 04 Nov 2022 13:51:24 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Fri, 4 Nov 2022 13:51:23 -0700 MIME-Version: 1.0 In-Reply-To: <20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid> References: <20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid> From: Stephen Boyd User-Agent: alot/0.10 Date: Fri, 4 Nov 2022 13:51:23 -0700 Message-ID: Subject: Re: [PATCH 1/3] clk: qcom: lpass-sc7280: Fix pm_runtime usage To: Bjorn Andersson , Douglas Anderson 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.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 Quoting Douglas Anderson (2022-11-04 06:56:28) > 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 > --- Reviewed-by: Stephen Boyd