mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] percpu-refcount: Add a WARN() for ref going negative
@ 2014-01-06 21:13 Kent Overstreet
  2014-01-12  3:35 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Kent Overstreet @ 2014-01-06 21:13 UTC (permalink / raw)
  To: tj; +Cc: linux-kernel, 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.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Tejun Heo <tj@kernel.org>
---
 lib/percpu-refcount.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index 1a53d497a8..32538f12f8 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -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);
-- 
1.8.5.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] percpu-refcount: Add a WARN() for ref going negative
  2014-01-06 21:13 [PATCH] percpu-refcount: Add a WARN() for ref going negative Kent Overstreet
@ 2014-01-12  3:35 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2014-01-12  3:35 UTC (permalink / raw)
  To: Kent Overstreet; +Cc: linux-kernel

On Mon, Jan 06, 2014 at 01:13:26PM -0800, Kent Overstreet wrote:
> 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.
> 
> Signed-off-by: Kent Overstreet <kmo@daterainc.com>
> Cc: Tejun Heo <tj@kernel.org>

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

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-12  3:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-06 21:13 [PATCH] percpu-refcount: Add a WARN() for ref going negative Kent Overstreet
2014-01-12  3:35 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®