powercap: intel_rapl: Fix locking in TPMI RAPL
authorZhang Rui <rui.zhang@intel.com>
Wed, 31 Jan 2024 11:37:09 +0000 (19:37 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 13 Feb 2024 16:31:48 +0000 (17:31 +0100)
commit1aa09b9379a7a644cd2f75ae0bac82b8783df600
tree68d6f498b4f57253fba50e5c16e107fbc00b0364
parent2d1f5006ff95770da502f8cee2a224a1ff83866e
powercap: intel_rapl: Fix locking in TPMI RAPL

The RAPL framework uses CPU hotplug locking to protect the rapl_packages
list and rp->lead_cpu to guarantee that

 1. the RAPL package device is not unprobed and freed
 2. the cached rp->lead_cpu is always valid

for operations like powercap sysfs accesses.

Current RAPL APIs assume being called from CPU hotplug callbacks which
hold the CPU hotplug lock, but TPMI RAPL driver invokes the APIs in the
driver's .probe() function without acquiring the CPU hotplug lock.

Fix the problem by providing both locked and lockless versions of RAPL
APIs.

Fixes: 9eef7f9da928 ("powercap: intel_rapl: Introduce RAPL TPMI interface driver")
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Cc: 6.5+ <stable@vger.kernel.org> # 6.5+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/powercap/intel_rapl_common.c
drivers/powercap/intel_rapl_msr.c
drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c
include/linux/intel_rapl.h