mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/1] percpu-refcount: do not forget to rcu_barrier() just before freeing
@ 2016-08-10 19:55 Roman Pen
  2016-08-10 22:09 ` Tejun Heo
  2016-08-15  4:34 ` [lkp] [percpu] e1bd8275fa: xfstests.generic.323.fail kernel test robot
  0 siblings, 2 replies; 6+ messages in thread
From: Roman Pen @ 2016-08-10 19:55 UTC (permalink / raw)
  Cc: Roman Pen, Tejun Heo, linux-kernel

percpu issues some RCU callbacks to synchronize its state, so before
freeing we have to wait all those callbacks to finish.

E.g. the following simple sequence on stack causes nasty crash:

    struct percpu_ref ref;

    percpu_ref_init(&ref, release, 0, GFP_KERNEL);
    percpu_ref_kill(&ref);
    percpu_ref_exit(&ref);

Also this patch includes inition to NULL of confirm_switch callback.
Without this inition you have to zero out a chunk of memory or kernel
frightfully complains with WARN_ON_ONCE(ref->confirm_switch) at
__percpu_ref_switch_to_atomic.

Signed-off-by: Roman Pen <roman.penyaev@profitbricks.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org
---
 v2:
   - just sending one more time because v1 was accidently
     sent as a reply to not related issue.

 lib/percpu-refcount.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index 6111bcb..ddf934b 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -82,6 +82,7 @@ int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release,
 	atomic_long_set(&ref->count, start_count);
 
 	ref->release = release;
+	ref->confirm_switch = NULL;
 	return 0;
 }
 EXPORT_SYMBOL_GPL(percpu_ref_init);
@@ -101,6 +102,7 @@ void percpu_ref_exit(struct percpu_ref *ref)
 	unsigned long __percpu *percpu_count = percpu_count_ptr(ref);
 
 	if (percpu_count) {
+		rcu_barrier_sched();
 		free_percpu(percpu_count);
 		ref->percpu_count_ptr = __PERCPU_REF_ATOMIC_DEAD;
 	}
-- 
2.9.0

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

end of thread, other threads:[~2016-08-15  4:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-10 19:55 [PATCH v2 1/1] percpu-refcount: do not forget to rcu_barrier() just before freeing Roman Pen
2016-08-10 22:09 ` Tejun Heo
2016-08-11  9:07   ` Roman Penyaev
2016-08-11 16:29     ` Tejun Heo
2016-08-11 17:29       ` Roman Penyaev
2016-08-15  4:34 ` [lkp] [percpu] e1bd8275fa: xfstests.generic.323.fail kernel test robot

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®