From: Viresh Kumar <viresh.kumar@linaro.org>
To: rafael@kernel.org, spidermana <xuyiwen14@gmail.com>
Cc: ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
dakr@kernel.org, daniel.almeida@collabora.com, tamird@kernel.org,
acourbot@nvidia.com, work@onurozkan.dev,
linux-pm@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, sumit.semwal@linaro.org
Subject: Re: [BUG] rust: cpufreq: get_callback() recursively read-locks cpufreq_driver_lock
Date: Mon, 5 Oct 2026 12:10:16 +0530 [thread overview]
Message-ID: <asNGUIFbiCncMXf6@vireshk-B250M-D3H> (raw)
In-Reply-To: <20261001172953.4013498-1-xuyiwen14@gmail.com>
On 01-10-26, 19:29, spidermana wrote:
> Possible fixes
> --------------
> I'm not sure what the right fix is, so I'd appreciate guidance:
From C API's perspective, cpufreq_quick_get() needs the lock (for setplicy
drivers) to make sure the driver stays around while its ->get() callback is
executing. But the ->get() callback is free to call cpufreq_cpu_get() in that
case to get hold of the policy if needed. Many drivers do call cpufreq_cpu_get()
from their .get() callback and it should ideally be fine.
Thankfully the only cpufreq driver with both setpolicy() and get() callbacks
doesn't call cpufreq_cpu_get() for now.
> 1. Use cpufreq_cpu_get_raw()/cpufreq_generic_get() in get_callback(). This
> avoids the lock, but it does not take a reference on the policy. And I'm
> not sure it is safe for the other ->get() call paths in the future that
> don't hold cpufreq_driver_lock.
Calling cpufreq_cpu_get_raw() (as you suggested) isn't enough as the policy may
get unregistered regardless while being used.
cpufreq_generic_get() returns the frequency directly for drivers that have a
valid policy->clk. That won't work here.
> 2. Change the Rust ->get() so it does not look up the policy at all, which matches the C
> callback signature.
> 3. Something else you'd prefer.
I think this is a C API problem as longrun doesn't call cpufreq_cpu_get() at the
moment just by chance. Maybe we need to add some workaround in
cpufreq_quick_get() instead so it doesn't take lock any longer.
Rafael, what do you suggest ?
--
viresh
prev parent reply other threads:[~2026-10-05 6:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 17:29 [BUG] rust: cpufreq: get_callback() recursively read-locks cpufreq_driver_lock spidermana
2026-10-05 6:40 ` Viresh Kumar [this message]
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=asNGUIFbiCncMXf6@vireshk-B250M-D3H \
--to=viresh.kumar@linaro.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=xuyiwen14@gmail.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