[PATCH v2 0/2] cpufreq: governor: Fix races and stale baseline on prev_cpu_nice
From: Zhongqiu Han
Date: Thu Apr 09 2026 - 07:14:23 EST
Patch 1 fixes a data race between sysfs store callbacks and the DBS
work handler. gov_update_cpu_data() writes prev_cpu_idle and
prev_cpu_nice while holding only attr_set->update_lock, whereas
dbs_update() reads and writes the same fields while holding only
policy_dbs->update_mutex. Because these are independent locks, the
two paths are not mutually exclusive. The fix acquires
policy_dbs->update_mutex inside gov_update_cpu_data() for each
policy, and also holds it around the initialization loop in
cpufreq_dbs_governor_start() to close a similar window against
concurrent sysfs writes.
Patch 2 fixes a stale-baseline spike on prev_cpu_nice that occurs
when ignore_nice_load is enabled via sysfs. Because prev_cpu_nice
is only advanced in dbs_update() when ignore_nice is true, it
accumulates an unbounded debt of nice CPU time while ignore_nice is
false. The moment ignore_nice_load is flipped to 1, the next
dbs_update() computes a massive idle_time delta against the stale
baseline, producing an incorrect CPU load value. The fix
unconditionally samples and advances prev_cpu_nice on every
dbs_update() call, regardless of ignore_nice, so the baseline is
always current. As a consequence, the prev_cpu_nice reset in
gov_update_cpu_data() and the gov_update_cpu_data() call in
ignore_nice_load_store() are no longer needed and are removed.
Changelog:
- Update linux-next base
- Based on v1 review, patch 1 is updated to add the missing
protection around cpufreq_dbs_governor_start(), and patch 2/2 is added.
- Link to v1: https://lore.kernel.org/all/20260406110113.3475920-1-zhongqiu.han@xxxxxxxxxxxxxxxx/
Zhongqiu Han (2):
cpufreq: governor: Fix race between sysfs store and dbs work handler
cpufreq: governor: Fix stale prev_cpu_nice spike when enabling
ignore_nice_load
drivers/cpufreq/cpufreq_conservative.c | 3 ---
drivers/cpufreq/cpufreq_governor.c | 35 ++++++++++++++++++--------
drivers/cpufreq/cpufreq_ondemand.c | 3 ---
3 files changed, 24 insertions(+), 17 deletions(-)
base-commit: f3e6330d7fe42b204af05a2dbc68b379e0ad179e
--
2.43.0