Skip to contentSkip to conversation

percpu_counter: Remove debug_object_free call twice

PATCH In review Gaurav Kohli 2 participants 4 messages Apr 13, 2018 – Aug 27, 2018

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

PATCH 1/1 percpu_counter: Remove debug_object_free call twice

During percpu_counter destroy, debug_object_free is calling twice which may create race. So removing once instance of call from debug_percpu_counter_deactivate.

lib/percpu_counter.c +0 -1
index c72577e..68ad030 100644
@@ -48,7 +48,6 @@ static inline void debug_percpu_counter_activate(struct percpu_counter *fbc)
 static inline void debug_percpu_counter_deactivate(struct percpu_counter *fbc)
 {
 	debug_object_deactivate(fbc, &percpu_counter_debug_descr);
-	debug_object_free(fbc, &percpu_counter_debug_descr);
 }
 
 #else	/* CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER */
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
maintainer
#1 lore raw
Quoted 3 lines · Gaurav Kohli

During percpu_counter destroy, debug_object_free is calling twice which may create race. So removing once instance of call from debug_percpu_counter_deactivate.

I don't quite follow. Can you please elaborate how it can be called twice?

Thanks.

Signature · 1 line
tejun
#2 lore raw
Quoted 6 lines · Tejun Heo
Quoted 3 lines · Gaurav Kohli

During percpu_counter destroy, debug_object_free is calling twice which may create race. So removing once instance of call from debug_percpu_counter_deactivate.

I don't quite follow. Can you please elaborate how it can be called twice?

Hi Tejun,

In percpu_counter_fixup_free function, first call is percpu_counter_destroy -> debug_percpu_counter_deactivate (this will set inactive and free the debug object as well for percpu counter) -> free_percpu (finally freeing the counters).

Below is the code snippet:

        case DEBUG_STATE_ACTIVE:

                percpu_counter_destroy(fbc); -> first call

                debug_object_free(fbc, &percpu_counter_debug_descr); -> this will again call the same debug object free, if somehow counters will reinitialize between these two calls.

We are seeing one race condition issue where one object of db list is corrupted and just before object of that corrupted node is percpu_counter, Still i am not sure the reason of race as it is very

difficult to reproduce. But i have found this during code review. Please correct me, if i misunderstood this.

Quoted 4 lines

Thanks.

Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
#3 lore raw

Hi ,

Sorry for very late reminder, just wanted to know is below understanding of code is wrong?

Regards
Gaurav

Quoted 31 lines · Gaurav
Quoted 6 lines · Tejun Heo
Quoted 3 lines · Gaurav Kohli

During percpu_counter destroy, debug_object_free is calling twice which may create race. So removing once instance of call from debug_percpu_counter_deactivate.

I don't quite follow.  Can you please elaborate how it can be called twice?

Hi Tejun,

In percpu_counter_fixup_free function, first call is percpu_counter_destroy -> debug_percpu_counter_deactivate (this will set inactive and free the debug object as well for percpu counter) -> free_percpu (finally freeing the counters).

Below is the code snippet:

        case DEBUG_STATE_ACTIVE:

                percpu_counter_destroy(fbc); -> first call

                debug_object_free(fbc, &percpu_counter_debug_descr); ->
this will again call the same debug object free, if somehow counters will reinitialize between these two calls.

We are seeing one race condition issue where one object of db list is corrupted and just before object of that corrupted node is percpu_counter, Still i am not sure the reason of race as it is very

difficult to reproduce. But i have found this during code review. Please correct me, if i misunderstood this.

Quoted 4 lines

Thanks.

Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.