From: Roman Pen <roman.penyaev@profitbricks.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Roman Pen <roman.penyaev@profitbricks.com>,
Tejun Heo <tj@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] percpu-refcount: do not forget to rcu_barrier() just before freeing
Date: Fri, 5 Aug 2016 19:41:31 +0200 [thread overview]
Message-ID: <20160805174131.22043-2-roman.penyaev@profitbricks.com> (raw)
In-Reply-To: <20160805174131.22043-1-roman.penyaev@profitbricks.com>
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
---
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
next prev parent reply other threads:[~2016-08-05 17:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-05 17:41 [PATCH 1/1] blk-mq: fix hang caused by freeze/unfreeze sequence Roman Pen
2016-08-05 17:41 ` Roman Pen [this message]
2016-08-05 18:04 ` kbuild test robot
2016-08-05 18:19 ` kbuild test robot
2016-08-05 18:28 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160805174131.22043-2-roman.penyaev@profitbricks.com \
--to=roman.penyaev@profitbricks.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®