From: Maxime Ripard <mripard@kernel.org>
To: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
Maxime Ripard <mripard@kernel.org>,
Guenter Roeck <linux@roeck-us.net>,
kernel test robot <yujie.liu@intel.com>
Subject: [PATCH 1/2] clk: Introduce kunit wrapper around clk_hw_init_rate_request
Date: Fri, 21 Jul 2023 09:09:32 +0200 [thread overview]
Message-ID: <20230721-clk-fix-kunit-lockdep-v1-1-32cdba4c8fc1@kernel.org> (raw)
In-Reply-To: <20230721-clk-fix-kunit-lockdep-v1-0-32cdba4c8fc1@kernel.org>
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 <linux@roeck-us.net>
Link: https://lore.kernel.org/linux-clk/2b594e50-2bbf-4a2d-88e6-49fc39f3957a@roeck-us.net/
Reported-by: kernel test robot <yujie.liu@intel.com>
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 <mripard@kernel.org>
---
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 <kunit/test-bug.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/clk/clk-conf.h>
@@ -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
next prev parent reply other threads:[~2023-07-21 7:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-21 7:09 [PATCH 0/2] clk: kunit: Fix the lockdep warnings Maxime Ripard
2023-07-21 7:09 ` Maxime Ripard [this message]
2023-07-21 16:14 ` [PATCH 1/2] clk: Introduce kunit wrapper around clk_hw_init_rate_request Guenter Roeck
2023-07-21 7:09 ` [PATCH 2/2] clk: Introduce kunit wrapper around __clk_determine_rate Maxime Ripard
2023-07-21 16:15 ` Guenter Roeck
2023-07-21 16:16 ` [PATCH 0/2] clk: kunit: Fix the lockdep warnings Guenter Roeck
2023-08-09 23:21 ` Stephen Boyd
2023-08-10 0:02 ` Guenter Roeck
2023-08-10 1:37 ` Stephen Boyd
2023-08-21 11:16 ` Maxime Ripard
2023-08-23 19:50 ` Stephen Boyd
2023-08-24 9:56 ` Maxime Ripard
2023-09-12 0:53 ` Stephen Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230721-clk-fix-kunit-lockdep-v1-1-32cdba4c8fc1@kernel.org \
--to=mripard@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mturquette@baylibre.com \
--cc=sboyd@kernel.org \
--cc=yujie.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®