Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp176761rwo; Fri, 21 Jul 2023 10:06:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlHAJawmqaUlcOnxRKXrfOj2FkI3Jz3M07mRHcGgZ4LjigOxM7NZHV3dzwQcjYcW3oJYCFQP X-Received: by 2002:a05:6a20:441c:b0:135:110c:c6dd with SMTP id ce28-20020a056a20441c00b00135110cc6ddmr2890704pzb.53.1689959217474; Fri, 21 Jul 2023 10:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689959217; cv=none; d=google.com; s=arc-20160816; b=wr7HozWytPzOgvbO0F1xDAs/wpEIhdYtnKZNqkC46+Kx3iDNuJaEtv7Asp6ezg7RLk PNONsKgx5I/KdDolEWq7XFhOEQSafw3OTPMvWyf7hKFUfuET17lAZ5MB1TsrDn1einHL EpEKJohUCwpk8gnbGU8wErCxmpiRYCsT+zQNEVhn7QSvlBklKFn6rH/gGrwsbF/IZrDU f1X5tuMYd0Yh69imRlpZAzvlGuRGmqkzghYnXi/M5LsOWmb0jVNVpMkyXQrMPEsvH1h1 NPxt6ujHbFnhGCR6x1Nt4/C/mcs6gFunRjIq0Cuz5eSmYWf/osp6A8cswfcpim7dXcNP yLog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=nMqpAHzPpQ8p1VY1demvfqMIMPRVFFpZskkZxzdoi/4=; fh=xPFBitaHVonp9KhE1RtpZ2TNA9d/SMIq6MMtmWQAAlc=; b=EyDvM1Ac0K4+cQd/bZ1MTKHrvhZU4HeqXo1+nYWP4Tmy5KBUjq1U6fXvdt+KzLahDt hf6xIQn9wRJ/U/nUpQwE8AV829tjsDRuPJ5nqs/YW3xq39rIu0XSP5pRdsHjIuUcjPSU yp7prQcKx+e6ZK3SN9FE/YHQHOySgx1QLe0CIe0r92ItHY5zsBh6CijJ40/y5eQZCD5i JISSIdOlDepIX30Qn6mB3ZUvRwPWINMIPmXxkqk+9TKQcYo+r0M9dGaHR6Xz3QQ+X5F/ qzYd6dD2H3AZoi7P2rxEhhgireF5pPpDrV7tqfb+1YSIABT7OrP4t/bBspch2UDVglhy 2k9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=kOiuronF; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p15-20020a63f44f000000b00557673fdd1asi3132173pgk.313.2023.07.21.10.06.42; Fri, 21 Jul 2023 10:06:57 -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=@gmail.com header.s=20221208 header.b=kOiuronF; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232528AbjGUQP5 (ORCPT + 99 others); Fri, 21 Jul 2023 12:15:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230413AbjGUQPh (ORCPT ); Fri, 21 Jul 2023 12:15:37 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0062E44A8; Fri, 21 Jul 2023 09:15:00 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-78372b896d0so90665639f.2; Fri, 21 Jul 2023 09:15:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689956100; x=1690560900; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=nMqpAHzPpQ8p1VY1demvfqMIMPRVFFpZskkZxzdoi/4=; b=kOiuronFPr5v6XeELMEAdxOfWvDrFi3wKedhBRC5NHp+m8wIcgNErDvBMkzT+/pwNG N8B+ZOLREoBDcA6ZgvBhVI9VBThCndaKBKtuc2b8OUTpBkV2XCEOSPM9P7hl2SQJFFGB FFs7P16tclcgZRx3keARryU9ib/Ja1tLL03bKkcscHhgE0YRPsN5hFRcQFmFXpBjeqE6 y8c9B/wwln73DFqu80WmGYfzv/pKcItBOqT/npi7TQ2rXOw6HMKMHTRH2VrWC8dFsbDD vzql/apz7PD6Pjer3SJPrV1dWM5uA/SSxkQnWvM3Bw7UwbZc9g9c7XYGcKzEC6e54P1g nFqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689956100; x=1690560900; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nMqpAHzPpQ8p1VY1demvfqMIMPRVFFpZskkZxzdoi/4=; b=FknxYQgdkIHbH5+LQ19zM15CjyB8UTJN0Lx9s8KHBhVpSUE/FVZj2wOVWPlBbD1Oul msXXIA+NR1/vpilsuiwz9/tiirwLwBL+UZImuE1UGQDIKS0nutm4gPenIEx7J7IUWF1+ vCR/ugTfUXgDM9J+Gy44WS2xCh4/91H/yFEeLNOcbCu7NB7uaY3p1Ppd7cGxHrEIP97W Y4fgWD802zXAv4OQE2LMsRo4xv+pym+tRXnMwyj5Y59sYMhGefxMfq1Qg/LdJ6f+FxPK CncM6UwK900yMzZKnowI+wz4dYgnpYcc2xLeRU+nLKtnekoCOK1cclk488Fk+EeOhUvi FYow== X-Gm-Message-State: ABy/qLbREZimhjSTcBZ2nSDaOLhgreTc1ulpY7Tu2ZHS0lnHYNVuRis+ /LLngUfXrAfVFHF+CkP3YNZ/EAV6/E8= X-Received: by 2002:a05:6602:2993:b0:787:8fc:307d with SMTP id o19-20020a056602299300b0078708fc307dmr465985ior.5.1689956100196; Fri, 21 Jul 2023 09:15:00 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id j9-20020a02cc69000000b0042b45d29facsm1076088jaq.152.2023.07.21.09.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 09:14:59 -0700 (PDT) Sender: Guenter Roeck Date: Fri, 21 Jul 2023 09:14:58 -0700 From: Guenter Roeck To: Maxime Ripard Cc: Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Subject: Re: [PATCH 1/2] clk: Introduce kunit wrapper around clk_hw_init_rate_request Message-ID: <24a22c85-d4f6-4598-a95f-a1f0503978a2@roeck-us.net> References: <20230721-clk-fix-kunit-lockdep-v1-0-32cdba4c8fc1@kernel.org> <20230721-clk-fix-kunit-lockdep-v1-1-32cdba4c8fc1@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230721-clk-fix-kunit-lockdep-v1-1-32cdba4c8fc1@kernel.org> X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Fri, Jul 21, 2023 at 09:09:32AM +0200, Maxime Ripard wrote: > Some kunit tests are meant to test the behaviour of providers (and > most notably __clk_determine_rate()), but don't run those functions with > the clk prepare_lock held which results in lockdep warning. > > clk_hw_init_rate_request is one of the functions being executed from a > test which should have the lock held. Let's introduce a wrapper around > it meant to be used only by kunit tests. > > Reported-by: Guenter Roeck > Link: https://lore.kernel.org/linux-clk/2b594e50-2bbf-4a2d-88e6-49fc39f3957a@roeck-us.net/ > Reported-by: kernel test robot > Link: https://lore.kernel.org/oe-lkp/202301310919.b9d56ee3-yujie.liu@intel.com > Fixes: 262ca38f4b6e ("clk: Stop forwarding clk_rate_requests to the parent") > Signed-off-by: Maxime Ripard Tested-by: Guenter Roeck > --- > drivers/clk/clk.c | 26 ++++++++++++++++++++++++++ > drivers/clk/clk_test.c | 2 +- > include/linux/clk-provider.h | 11 +++++++++++ > 3 files changed, 38 insertions(+), 1 deletion(-) > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index c249f9791ae8..8ee9bd02af76 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -6,6 +6,7 @@ > * Standard functionality for the common clock API. See Documentation/driver-api/clk.rst > */ > > +#include > #include > #include > #include > @@ -1556,6 +1557,31 @@ void clk_hw_init_rate_request(const struct clk_hw *hw, > } > EXPORT_SYMBOL_GPL(clk_hw_init_rate_request); > > +#if IS_ENABLED(CONFIG_KUNIT) > +/** > + * clk_kunit_init_rate_request - Initializes a clk_rate_request > + * @hw: the clk for which we want to submit a rate request > + * @req: the clk_rate_request structure we want to initialise > + * @rate: the rate which is to be requested > + * > + * Initializes a clk_rate_request structure to submit to > + * __clk_determine_rate() or similar functions. Only usable in kunit > + * test contexts, use clk_hw_init_rate_request() otherwise. > + */ > +void clk_kunit_init_rate_request(const struct clk_hw *hw, > + struct clk_rate_request *req, > + unsigned long rate) > +{ > + if (!kunit_get_current_test()) > + return; > + > + clk_prepare_lock(); > + clk_hw_init_rate_request(hw, req, rate); > + clk_prepare_unlock(); > +} > +EXPORT_SYMBOL_GPL(clk_kunit_init_rate_request); > +#endif > + > /** > * clk_hw_forward_rate_request - Forwards a clk_rate_request to a clock's parent > * @hw: the original clock that got the rate request > diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c > index a154ec9d0111..a64f7036baa3 100644 > --- a/drivers/clk/clk_test.c > +++ b/drivers/clk/clk_test.c > @@ -2230,7 +2230,7 @@ static void clk_leaf_mux_set_rate_parent_determine_rate(struct kunit *test) > rate = clk_get_rate(clk); > KUNIT_ASSERT_EQ(test, rate, DUMMY_CLOCK_RATE_1); > > - clk_hw_init_rate_request(hw, &req, DUMMY_CLOCK_RATE_2); > + clk_kunit_init_rate_request(hw, &req, DUMMY_CLOCK_RATE_2); > > ret = __clk_determine_rate(hw, &req); > KUNIT_ASSERT_EQ(test, ret, 0); > diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h > index 0f0cd01906b4..efdebfa3fce9 100644 > --- a/include/linux/clk-provider.h > +++ b/include/linux/clk-provider.h > @@ -67,6 +67,17 @@ struct clk_rate_request { > void clk_hw_init_rate_request(const struct clk_hw *hw, > struct clk_rate_request *req, > unsigned long rate); > +#if IS_ENABLED(CONFIG_KUNIT) > +void clk_kunit_init_rate_request(const struct clk_hw *hw, > + struct clk_rate_request *req, > + unsigned long rate); > +#else > +static inline void clk_kunit_init_rate_request(const struct clk_hw *hw, > + struct clk_rate_request *req, > + unsigned long rate) > +{ > +} > +#endif > void clk_hw_forward_rate_request(const struct clk_hw *core, > const struct clk_rate_request *old_req, > const struct clk_hw *parent, > > -- > 2.41.0 >