From patchwork Tue Jan 3 09:23:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 38328 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4522669wrt; Tue, 3 Jan 2023 01:32:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXt7vMREfGhrgiPPlbsO6ii8KmGcBUWi6C1Q1ladymmYaUU0923VLGCOHwoGviHKw79n3pJH X-Received: by 2002:a17:907:8d1c:b0:7fd:f3ae:8ab8 with SMTP id tc28-20020a1709078d1c00b007fdf3ae8ab8mr40582869ejc.9.1672738370186; Tue, 03 Jan 2023 01:32:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672738370; cv=none; d=google.com; s=arc-20160816; b=JI2weSWWIrK1KEzNqU7TawVbYEUTDUU5Sl7ir6LRNzCy7u+bscxXa9dXkEjAwXJ1dv 4N+em7b8wa799IWCaG7tzbItQBm91l8+ybmIhLxKK3CVb4DjmBLcUIxfYBq/rZFNUlKA Yt/inZvc0pm62Po0Ws+6WGJbDvEb+kGEp8KCAzEHWfAsQVG1Kt+nQ8Fnj12OuXBSS5/g uy1ULmoX27BsSxeFSO7QIRHLzdRQ0jM4GbrB9uYQUX1s6T54nsdNREFkurR15tczsE1r jzuWZ5UUCfa8Dad9f4N0Qf2qKjHPufP3sAV0qte9WgfzxTLxM1JEV5+c3aIoN/Hm8Q5T dWLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=AaEgQoi2wV88iETdzvSp20U7Cda3EBi9Iq1BYplBC3U=; b=FV+2t+JIHBkyaakYOwoF/1Vm8O+oioJHI//JtPHi1uXAbn23pqzjHmte9v+hDxDmnE nH4uFILZ0SjbxyNu0S/LRRBq5inBx18exlWJAREGzPNsxAWsCueU0zASSuNP5WvAqcwA BimSEfigf2oN5SjQfJ2w+EkSY7d1EU2hWhEKo3Pi4HcajT3iHDeEZrMWiB+b1gZZVp4f T18tFUMd5uu3d+9p2Ry5sk4eW9vaCeEyFAZ67R/fpsVQKwtfPYTEby2oE0JdfenOGov0 a49/dovYJ5eVQADvhZhP0Hair+ZtsUHfVlX8X608xXihTNRiz4A1gg1Kidg2EHtXX4m2 EbnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fRKiuLLP; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn21-20020a17090794d500b007a087ccd275si30262883ejc.384.2023.01.03.01.32.26; Tue, 03 Jan 2023 01:32:50 -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=fRKiuLLP; 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 S236976AbjACJYO (ORCPT + 99 others); Tue, 3 Jan 2023 04:24:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237217AbjACJXh (ORCPT ); Tue, 3 Jan 2023 04:23:37 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7495E117A for ; Tue, 3 Jan 2023 01:23:36 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id o31-20020a17090a0a2200b00223fedffb30so30514668pjo.3 for ; Tue, 03 Jan 2023 01:23:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AaEgQoi2wV88iETdzvSp20U7Cda3EBi9Iq1BYplBC3U=; b=fRKiuLLPQXtm+PoLAnEO0C/uRszb5OZg3YHcvW2RCgSXdgYSqmUNIVOR6Yw5IkkkHr +QjxZ3RVzCBOcOirYxxHt0r1WoqCp6tPnX+mb/UoZ6kAIx7Lm+E/ou+rSr9EZ2qoQeD6 bIpAN5WyNbnUdEwIzQE/O3pT9ZYGzuzsfHPQo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AaEgQoi2wV88iETdzvSp20U7Cda3EBi9Iq1BYplBC3U=; b=19qMB9joEmmZ2AW96rWeew+nbSMU55Kmf2zjt+GNO72oyZSO4YVNmupy2MasoLLBzq Gdq9mMNKkSeigm6iZaMYi3BK+tvgGWib3+JVK7UGPLCTJB6xHG1nIf0yw+21z7z5UHhp l5tdZ7h3kFR282+oLYPyM3nk0956lpT2bWzF94Ri74Hzl4dsfs3bHgxcsM6ieqAkv9zC eKgoPh82sncbD1ceJT6gkUeMMwwm/gsPm5/5t+esKMXWEQkJD+tBFQLlKNT+Z8Mdvel3 R6kKCrLwErh28kZyi/kLSB/64JJSaqo0QcUXY9RZcIRBYM3Mp71CvTnEH5r13tkgwuEM itsw== X-Gm-Message-State: AFqh2kqYGFanhC8FN8NakE+aqp6u5mHuZGOPF4Hmi+XHeT506FFiAlXV CdP8+V1prrqh5h+PtBXjG+Pxxw== X-Received: by 2002:a17:902:f112:b0:189:9ee0:cc8e with SMTP id e18-20020a170902f11200b001899ee0cc8emr40941085plb.57.1672737815982; Tue, 03 Jan 2023 01:23:35 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:96d9:31a:590:4d72]) by smtp.gmail.com with ESMTPSA id y126-20020a636484000000b0049f5da82b12sm6868632pgb.93.2023.01.03.01.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 01:23:35 -0800 (PST) From: Chen-Yu Tsai To: Michael Turquette , Stephen Boyd Cc: Chen-Yu Tsai , AngeloGioacchino Del Regno , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Alexander Stein , Marcel Ziswiler , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] clk: core: Honor CLK_OPS_PARENT_ENABLE in clk_core_is_enabled Date: Tue, 3 Jan 2023 17:23:30 +0800 Message-Id: <20230103092330.494102-1-wenst@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 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=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753993309159680147?= X-GMAIL-MSGID: =?utf-8?q?1753993309159680147?= In the previous commits that added CLK_OPS_PARENT_ENABLE, support for this flag was only added to rate change operations (rate setting and reparent) and disabling unused subtree. It was not added to the clock gate related operations. Any hardware driver that needs it for these operations will either see bogus results, or worse, hang. This has been seen on MT8192 and MT8195, where the imp_ii2_* clk drivers set this, but dumping debugfs clk_summary would cause it to hang. Prepare parent on prepare and enable parent on enable dependencies are already handled automatically by the core as part of its sequencing. Whether the case for "enable parent on prepare" should be supported by this flag or not is not clear, and thus ignored for now. This change solely fixes the handling of clk_core_is_enabled, i.e. enabling the parent clock when reading the hardware state. Unfortunately clk_core_is_enabled is called in a variety of places, sometimes with the enable clock already held. To avoid deadlocking, the core will ignore readouts and just return false if CLK_OPS_PARENT_ENABLE is set but the parent isn't currently enabled. Fixes: fc8726a2c021 ("clk: core: support clocks which requires parents enable (part 2)") Fixes: a4b3518d146f ("clk: core: support clocks which requires parents enable (part 1)") Signed-off-by: Chen-Yu Tsai Reviewed-by: AngeloGioacchino Del Regno Tested-by: AngeloGioacchino Del Regno --- This is a less invasive version of "clk: core: Honor CLK_OPS_PARENT_ENABLE for clk gate ops" [1] which caused regressions on i.MX platforms. My guess is that the i.MX clock driver uses clk_hw_is_enabled() in it's set_rate callback, in which the new code causes a deadlock. v3 drops the enable parent on prepare/unprepare bits, as it's unclear who benefits from it, and the locking is hard to get right. The part in clk_core_is_enabled() is changed into a bypass path, as described in the commit message. This fixes the issue I'm seeing, and hopefully doesn't change the behavior on other platforms. [1] https://lore.kernel.org/linux-clk/20220822081424.1310926-2-wenst@chromium.org/ drivers/clk/clk.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index e62552a75f08..496b86e2753c 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -244,6 +244,17 @@ static bool clk_core_is_enabled(struct clk_core *core) } } + /* + * This could be called with the enable lock held, or from atomic + * context. If the parent isn't enabled already, we can't do + * anything here. We can also assume this clock isn't enabled. + */ + if ((core->flags & CLK_OPS_PARENT_ENABLE) && core->parent) + if (!clk_core_is_enabled(core->parent)) { + ret = false; + goto done; + } + ret = core->ops->is_enabled(core->hw); done: if (core->rpm_enabled)