Skip to content

Commit e78d483

Browse files
jankaraFengguang Wu
authored andcommitted
lib: Fix possible deadlock in flexible proportion code
When percpu counter function in fprop_new_period() is interrupted by an interrupt while holding counter lock, it can cause deadlock when the interrupt wants to take the lock as well. Fix the problem by disabling interrupts when calling percpu counter functions. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
1 parent f3109a5 commit e78d483

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎lib/flex_proportions.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,26 @@ void fprop_global_destroy(struct fprop_global *p)
6262
*/
6363
bool fprop_new_period(struct fprop_global *p, int periods)
6464
{
65-
u64 events = percpu_counter_sum(&p->events);
65+
u64 events;
66+
unsigned long flags;
6667

68+
local_irq_save(flags);
69+
events = percpu_counter_sum(&p->events);
6770
/*
6871
* Don't do anything if there are no events.
6972
*/
70-
if (events <= 1)
73+
if (events <= 1) {
74+
local_irq_restore(flags);
7175
return false;
76+
}
7277
write_seqcount_begin(&p->sequence);
7378
if (periods < 64)
7479
events -= events >> periods;
7580
/* Use addition to avoid losing events happening between sum and set */
7681
percpu_counter_add(&p->events, -events);
7782
p->period += periods;
7883
write_seqcount_end(&p->sequence);
84+
local_irq_restore(flags);
7985

8086
return true;
8187
}

0 commit comments

Comments
 (0)