summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMing Lei <tom.leiming@gmail.com>2014-01-10 12:41:46 +1100
committerStephen Rothwell <sfr@canb.auug.org.au>2014-01-10 12:41:46 +1100
commit97e890b9c839c191a500c3a19bfb4539f65c70be (patch)
tree16d2ac676f4bbf4e852b8b4a6f95ec667e39e852 /lib
parent55cbfd15fd125aad68b9a958749ae2d3c192db9c (diff)
lib/percpu_counter.c: disable local irq when updating percpu couter
__percpu_counter_add() may be called in softirq/hardirq handler (such as, blk_mq_queue_exit() is typically called in hardirq/softirq handler), so we need to disable local irq when updating the percpu counter, otherwise counts may be lost. The patch fixes problem that 'rmmod null_blk' may hang in blk_cleanup_queue() because of miscounting of request_queue->mq_usage_counter. Signed-off-by: Ming Lei <tom.leiming@gmail.com> Cc: Paul Gortmaker <paul.gortmaker@windriver.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Shaohua Li <shli@fusionio.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Fan Du <fan.du@windriver.com> Cc: Tejun Heo <tj@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/percpu_counter.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index 7473ee3b4ee7..2b87bc19b35f 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -75,19 +75,19 @@ EXPORT_SYMBOL(percpu_counter_set);
void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch)
{
s64 count;
+ unsigned long flags;
- preempt_disable();
+ raw_local_irq_save(flags);
count = __this_cpu_read(*fbc->counters) + amount;
if (count >= batch || count <= -batch) {
- unsigned long flags;
- raw_spin_lock_irqsave(&fbc->lock, flags);
+ raw_spin_lock(&fbc->lock);
fbc->count += count;
- raw_spin_unlock_irqrestore(&fbc->lock, flags);
+ raw_spin_unlock(&fbc->lock);
__this_cpu_write(*fbc->counters, 0);
} else {
__this_cpu_write(*fbc->counters, count);
}
- preempt_enable();
+ raw_local_irq_restore(flags);
}
EXPORT_SYMBOL(__percpu_counter_add);