Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp11622535rwl; Tue, 3 Jan 2023 02:06:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXvuDjwjRqO4aKLpbRnUQnPZYhmPKvtTvPPNneThq8CkoLbd44w8F9ot6kaOaHQBY9ZOs4Iv X-Received: by 2002:a05:6a21:70cb:b0:ad:ceba:1bdc with SMTP id xd11-20020a056a2170cb00b000adceba1bdcmr50005282pzb.16.1672740359865; Tue, 03 Jan 2023 02:05:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672740359; cv=none; d=google.com; s=arc-20160816; b=fQZNBZVaiRUnFjATQI8v65Ydi9XpcQJI6ZULAPcshHCve6QAcrfPOgF4XYgc+JR8xA /WztRUuDjl97LgJk7tW2KUE7Ce5iQ92YAv8TjDNIBGz3IfoV5WhksEXfIUG8Z+wyDCDP DeEQS9cXQ8yY9UnSheDnttVXSiMSJp/gf0uwZOoudgzOj8ZQYDgLOm5Qj1lLLlvwJfya UrFxOwmXxsqGU32Uqt077ajmd7FDOPg01EhQYkDppJ8yxGtZQ6K2UT7zu/wCZKVXw+3t TDZODLdAdxXgEzfHKxsMd1d854S9VxuaAjhzFDwdgM2CUbHyfQvQlz23Q7g0C4U/7VRz QUPQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x195-20020a6331cc000000b00476a48051edsi35309941pgx.476.2023.01.03.02.05.52; Tue, 03 Jan 2023 02:05:59 -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 + 61 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=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , 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 Content-Transfer-Encoding: 8bit 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 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 --- 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) -- 2.39.0.314.g84b9a713c41-goog