Skip to contentSkip to conversation

powerpc/perf: double unlock bug in imc_common_cpuhp_mem_free()

PATCH Applied Dan Carpenter 4 participants 5 messages Aug 11, 2017 – Aug 16, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/perf: double unlock bug in imc_common_cpuhp_mem_free()

There is a typo so we call unlock instead of lock.

Fixes 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")

---
I also don't understand how the &nest_imc_refc[node_id].lock works. Why can't we use ref->lock everywhere? They seem equivalent, and my static checker complains if we call the same lock different names.

arch/powerpc/perf/imc-pmu.c +1 -1
index 46cd912af060..52017f6eafd9 100644
@@ -1124,7 +1124,7 @@ static void cleanup_all_thread_imc_memory(void)
 static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
 {
 	if (pmu_ptr->domain = IMC_DOMAIN_NEST) {
-		mutex_unlock(&nest_init_lock);
+		mutex_lock(&nest_init_lock);
 		if (nest_pmus = 1) {
 			cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_NEST_IMC_ONLINE);
 			kfree(nest_imc_refc);
#1 lore raw
Quoted 8 lines · Dan Carpenter

There is a typo so we call unlock instead of lock.

Fixes 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")

---
I also don't understand how the &nest_imc_refc[node_id].lock works. Why can't we use ref->lock everywhere? They seem equivalent, and my static checker complains if we call the same lock different names.

That looks like a bug to me, ie. we should always use ref.

Maddy?

cheers

Quoted 13 lines
arch/powerpc/perf/imc-pmu.c +1 -1
index 46cd912af060..52017f6eafd9 100644
@@ -1124,7 +1124,7 @@ static void cleanup_all_thread_imc_memory(void)
 static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
 {
 	if (pmu_ptr->domain = IMC_DOMAIN_NEST) {
-		mutex_unlock(&nest_init_lock);
+		mutex_lock(&nest_init_lock);
 		if (nest_pmus = 1) {
 			cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_NEST_IMC_ONLINE);
 			kfree(nest_imc_refc);
#2 lore raw
Quoted 11 lines · Michael Ellerman
Quoted 8 lines · Dan Carpenter

There is a typo so we call unlock instead of lock.

Fixes 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")

---
I also don't understand how the &nest_imc_refc[node_id].lock works. Why can't we use ref->lock everywhere? They seem equivalent, and my static checker complains if we call the same lock different names.

That looks like a bug to me, ie. we should always use ref.

ok. will send a fix.

Thanks
Maddy

Quoted 18 lines

Maddy?

cheers

Quoted 13 lines
arch/powerpc/perf/imc-pmu.c +1 -1
index 46cd912af060..52017f6eafd9 100644
@@ -1124,7 +1124,7 @@ static void cleanup_all_thread_imc_memory(void)
  static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
  {
  	if (pmu_ptr->domain == IMC_DOMAIN_NEST) {
-		mutex_unlock(&nest_init_lock);
+		mutex_lock(&nest_init_lock);
  		if (nest_pmus == 1) {
  			cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_NEST_IMC_ONLINE);
  			kfree(nest_imc_refc);
Reviewed-by on v1 1/1
#3 lore raw
In reply to Dan Carpenter
Quoted 1 line · Dan Carpenter

There is a typo so we call unlock instead of lock.

nest_imc_refc used to maintain list of perf sessions thats using the nest units currently. This is needed in turning off nest engine microcode when not in use.

Yes will send a patch to fix ref->lock change.

Thanks for fix

Maddy

Quoted 22 lines
Fixes 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")

---
I also don't understand how the &nest_imc_refc[node_id].lock works. Why can't we use ref->lock everywhere? They seem equivalent, and my static checker complains if we call the same lock different names.

arch/powerpc/perf/imc-pmu.c +1 -1
index 46cd912af060..52017f6eafd9 100644
@@ -1124,7 +1124,7 @@ static void cleanup_all_thread_imc_memory(void)
  static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
  {
  	if (pmu_ptr->domain == IMC_DOMAIN_NEST) {
-		mutex_unlock(&nest_init_lock);
+		mutex_lock(&nest_init_lock);
  		if (nest_pmus == 1) {
  			cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_NEST_IMC_ONLINE);
  			kfree(nest_imc_refc);