Skip to content

Commit ad53db4

Browse files
committed
powerpc/imc-pmu: Revert nest_init_lock to being a mutex
The recent commit 76d588d ("powerpc/imc-pmu: Fix use of mutex in IRQs disabled section") fixed warnings (and possible deadlocks) in the IMC PMU driver by converting the locking to use spinlocks. It also converted the init-time nest_init_lock to a spinlock, even though it's not used at runtime in IRQ disabled sections or while holding other spinlocks. This leads to warnings such as: BUG: sleeping function called from invalid context at include/linux/percpu-rwsem.h:49 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1, name: swapper/0 preempt_count: 1, expected: 0 CPU: 7 PID: 1 Comm: swapper/0 Not tainted 6.2.0-rc2-14719-gf12cd06109f4-dirty #1 Hardware name: Mambo,Simulated-System POWER9 0x4e1203 opal:v6.6.6 PowerNV Call Trace: dump_stack_lvl+0x74/0xa8 (unreliable) __might_resched+0x178/0x1a0 __cpuhp_setup_state+0x64/0x1e0 init_imc_pmu+0xe48/0x1250 opal_imc_counters_probe+0x30c/0x6a0 platform_probe+0x78/0x110 really_probe+0x104/0x420 __driver_probe_device+0xb0/0x170 driver_probe_device+0x58/0x180 __driver_attach+0xd8/0x250 bus_for_each_dev+0xb4/0x140 driver_attach+0x34/0x50 bus_add_driver+0x1e8/0x2d0 driver_register+0xb4/0x1c0 __platform_driver_register+0x38/0x50 opal_imc_driver_init+0x2c/0x40 do_one_initcall+0x80/0x360 kernel_init_freeable+0x310/0x3b8 kernel_init+0x30/0x1a0 ret_from_kernel_thread+0x5c/0x64 Fix it by converting nest_init_lock back to a mutex, so that we can call sleeping functions while holding it. There is no interaction between nest_init_lock and the runtime spinlocks used by the actual PMU routines. Fixes: 76d588d ("powerpc/imc-pmu: Fix use of mutex in IRQs disabled section") Tested-by: Kajol Jain<[email protected]> Reviewed-by: Kajol Jain<[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c285480 commit ad53db4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

arch/powerpc/perf/imc-pmu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Used to avoid races in counting the nest-pmu units during hotplug
2323
* register and unregister
2424
*/
25-
static DEFINE_SPINLOCK(nest_init_lock);
25+
static DEFINE_MUTEX(nest_init_lock);
2626
static DEFINE_PER_CPU(struct imc_pmu_ref *, local_nest_imc_refc);
2727
static struct imc_pmu **per_nest_pmu_arr;
2828
static cpumask_t nest_imc_cpumask;
@@ -1629,7 +1629,7 @@ static void imc_common_mem_free(struct imc_pmu *pmu_ptr)
16291629
static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
16301630
{
16311631
if (pmu_ptr->domain == IMC_DOMAIN_NEST) {
1632-
spin_lock(&nest_init_lock);
1632+
mutex_lock(&nest_init_lock);
16331633
if (nest_pmus == 1) {
16341634
cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_NEST_IMC_ONLINE);
16351635
kfree(nest_imc_refc);
@@ -1639,7 +1639,7 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
16391639

16401640
if (nest_pmus > 0)
16411641
nest_pmus--;
1642-
spin_unlock(&nest_init_lock);
1642+
mutex_unlock(&nest_init_lock);
16431643
}
16441644

16451645
/* Free core_imc memory */
@@ -1796,27 +1796,27 @@ int init_imc_pmu(struct device_node *parent, struct imc_pmu *pmu_ptr, int pmu_id
17961796
* rest. To handle the cpuhotplug callback unregister, we track
17971797
* the number of nest pmus in "nest_pmus".
17981798
*/
1799-
spin_lock(&nest_init_lock);
1799+
mutex_lock(&nest_init_lock);
18001800
if (nest_pmus == 0) {
18011801
ret = init_nest_pmu_ref();
18021802
if (ret) {
1803-
spin_unlock(&nest_init_lock);
1803+
mutex_unlock(&nest_init_lock);
18041804
kfree(per_nest_pmu_arr);
18051805
per_nest_pmu_arr = NULL;
18061806
goto err_free_mem;
18071807
}
18081808
/* Register for cpu hotplug notification. */
18091809
ret = nest_pmu_cpumask_init();
18101810
if (ret) {
1811-
spin_unlock(&nest_init_lock);
1811+
mutex_unlock(&nest_init_lock);
18121812
kfree(nest_imc_refc);
18131813
kfree(per_nest_pmu_arr);
18141814
per_nest_pmu_arr = NULL;
18151815
goto err_free_mem;
18161816
}
18171817
}
18181818
nest_pmus++;
1819-
spin_unlock(&nest_init_lock);
1819+
mutex_unlock(&nest_init_lock);
18201820
break;
18211821
case IMC_DOMAIN_CORE:
18221822
ret = core_imc_pmu_cpumask_init();

0 commit comments

Comments
 (0)