Skip to contentSkip to conversation

percpu-refcount: Add a WARN() for ref going negative

PATCH Applied Kent Overstreet 2 participants 2 messages Jan 6, 2014 – Jan 12, 2014

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

PATCH 1/1 percpu-refcount: Add a WARN() for ref going negative

AIO had a missing get, which led to an ioctx leak - after percpu_ref_kill() the ref was 0 so percpu_ref_put() never saw it hit 0.

This wasn't noticed at the time because it all happened completely silently, this adds a WARN() which would've caught the aio bug.

---
 lib/percpu-refcount.c | 3 +++
 1 file changed, 3 insertions(+)
lib/percpu-refcount.c +3 -0
index 1a53d497a8..32538f12f8 100644
@@ -120,6 +120,9 @@ static void percpu_ref_kill_rcu(struct rcu_head *rcu)
 
 	atomic_add((int) count - PCPU_COUNT_BIAS, &ref->count);
 
+	WARN(atomic_read(&ref->count) <= 0,
+	     "percpu ref <= 0 (%i)", atomic_read(&ref->count));
+
 	/* @ref is viewed as dead on all CPUs, send out kill confirmation */
 	if (ref->confirm_kill)
 		ref->confirm_kill(ref);
Signature · 1 line
1.8.5.2
maintainer Applied
#1 lore raw
Quoted 8 lines · Kent Overstreet

AIO had a missing get, which led to an ioctx leak - after percpu_ref_kill() the ref was 0 so percpu_ref_put() never saw it hit 0.

This wasn't noticed at the time because it all happened completely silently, this adds a WARN() which would've caught the aio bug.

Applied to percpu/for-3.14 w/ WARN_ONCE() instead WARN().

Thanks.

Signature · 1 line
tejun