Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1625224 > unrolled thread
| Started by | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| First post | 2017-04-18 12:40 +0200 |
| Last post | 2017-04-21 19:10 +0200 |
| Articles | 7 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH 0/3] more cpu hotplug fail Peter Zijlstra <peterz@infradead.org> - 2017-04-18 12:40 +0200
[PATCH 3/3] perf: Avoid cpu_hotplug_lock r-r recursion Peter Zijlstra <peterz@infradead.org> - 2017-04-18 12:40 +0200
[tip:smp/hotplug] perf: Avoid cpu_hotplug_lock r-r recursion "tip-bot for Peter Zijlstra (Intel)" <tipbot@zytor.com> - 2017-04-20 13:40 +0200
[PATCH 1/3] jump_label: Pull get_online_cpus() into generic code Peter Zijlstra <peterz@infradead.org> - 2017-04-18 12:40 +0200
[tip:smp/hotplug] jump_label: Pull get_online_cpus() into generic code "tip-bot for Peter Zijlstra (Intel)" <tipbot@zytor.com> - 2017-04-20 13:40 +0200
Re: [PATCH 1/3] jump_label: Pull get_online_cpus() into generic code Jason Baron <jbaron@akamai.com> - 2017-04-21 19:10 +0200
Re: [PATCH 1/3] jump_label: Pull get_online_cpus() into generic code Peter Zijlstra <peterz@infradead.org> - 2017-04-21 19:10 +0200
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2017-04-18 12:40 +0200 |
| Subject | [PATCH 0/3] more cpu hotplug fail |
| Message-ID | <txyI9-54q-3@gated-at.bofh.it> |
Now that the CPU hotplug lock is a regular per-cpu rwsem it can no longer nest read-sides. Fix two such sites in perf.
[toc] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2017-04-18 12:40 +0200 |
| Subject | [PATCH 3/3] perf: Avoid cpu_hotplug_lock r-r recursion |
| Message-ID | <txyIa-54q-9@gated-at.bofh.it> |
| In reply to | #1625224 |
There are two call-sites where using static_key results in recursing
on the cpu_hotplug_lock.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/events/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7785,7 +7785,7 @@ static int perf_swevent_init(struct perf
if (err)
return err;
- static_key_slow_inc(&perf_swevent_enabled[event_id]);
+ static_key_slow_inc_nohp(&perf_swevent_enabled[event_id]);
event->destroy = sw_perf_event_destroy;
}
@@ -9294,7 +9294,7 @@ static void account_event(struct perf_ev
mutex_lock(&perf_sched_mutex);
if (!atomic_read(&perf_sched_count)) {
- static_branch_enable(&perf_sched_events);
+ static_key_slow_inc_nohp(&perf_sched_events.key);
/*
* Guarantee that all CPUs observe they key change and
* call the perf scheduling hooks before proceeding to
[toc] | [prev] | [next] | [standalone]
| From | "tip-bot for Peter Zijlstra (Intel)" <tipbot@zytor.com> |
|---|---|
| Date | 2017-04-20 13:40 +0200 |
| Subject | [tip:smp/hotplug] perf: Avoid cpu_hotplug_lock r-r recursion |
| Message-ID | <tyiBj-8mU-1@gated-at.bofh.it> |
| In reply to | #1625229 |
Commit-ID: 641693094ee1568502280f95900f374b2226b51d
Gitweb: http://git.kernel.org/tip/641693094ee1568502280f95900f374b2226b51d
Author: Peter Zijlstra (Intel) <peterz@infradead.org>
AuthorDate: Tue, 18 Apr 2017 19:05:05 +0200
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 20 Apr 2017 13:08:57 +0200
perf: Avoid cpu_hotplug_lock r-r recursion
There are two call-sites where using static_key results in recursing on the
cpu_hotplug_lock.
Use the hotplug locked version of static_key_slow_inc().
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Sebastian Siewior <bigeasy@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: jbaron@akamai.com
Link: http://lkml.kernel.org/r/20170418103422.687248115@infradead.org
---
kernel/events/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 634dd95..8aa3063 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7653,7 +7653,7 @@ static int perf_swevent_init(struct perf_event *event)
if (err)
return err;
- static_key_slow_inc(&perf_swevent_enabled[event_id]);
+ static_key_slow_inc_cpuslocked(&perf_swevent_enabled[event_id]);
event->destroy = sw_perf_event_destroy;
}
@@ -9160,7 +9160,7 @@ static void account_event(struct perf_event *event)
mutex_lock(&perf_sched_mutex);
if (!atomic_read(&perf_sched_count)) {
- static_branch_enable(&perf_sched_events);
+ static_key_slow_inc_cpuslocked(&perf_sched_events.key);
/*
* Guarantee that all CPUs observe they key change and
* call the perf scheduling hooks before proceeding to
[toc] | [prev] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2017-04-18 12:40 +0200 |
| Subject | [PATCH 1/3] jump_label: Pull get_online_cpus() into generic code |
| Message-ID | <txyIb-54q-19@gated-at.bofh.it> |
| In reply to | #1625224 |
This change does two things; it moves the get_online_cpus() call into
generic code, with the aim of later providing some static_key ops that
avoid it.
And as a side effect it inverts the relation between cpu_hotplug_lock
and jump_label_mutex.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
--- a/arch/mips/kernel/jump_label.c
+++ b/arch/mips/kernel/jump_label.c
@@ -58,7 +58,6 @@ void arch_jump_label_transform(struct ju
insn.word = 0; /* nop */
}
- get_online_cpus();
mutex_lock(&text_mutex);
if (IS_ENABLED(CONFIG_CPU_MICROMIPS)) {
insn_p->halfword[0] = insn.word >> 16;
@@ -70,7 +69,6 @@ void arch_jump_label_transform(struct ju
(unsigned long)insn_p + sizeof(*insn_p));
mutex_unlock(&text_mutex);
- put_online_cpus();
}
#endif /* HAVE_JUMP_LABEL */
--- a/arch/sparc/kernel/jump_label.c
+++ b/arch/sparc/kernel/jump_label.c
@@ -41,12 +41,10 @@ void arch_jump_label_transform(struct ju
val = 0x01000000;
}
- get_online_cpus();
mutex_lock(&text_mutex);
*insn = val;
flushi(insn);
mutex_unlock(&text_mutex);
- put_online_cpus();
}
#endif
--- a/arch/tile/kernel/jump_label.c
+++ b/arch/tile/kernel/jump_label.c
@@ -45,14 +45,12 @@ static void __jump_label_transform(struc
void arch_jump_label_transform(struct jump_entry *e,
enum jump_label_type type)
{
- get_online_cpus();
mutex_lock(&text_mutex);
__jump_label_transform(e, type);
flush_icache_range(e->code, e->code + sizeof(tilegx_bundle_bits));
mutex_unlock(&text_mutex);
- put_online_cpus();
}
__init_or_module void arch_jump_label_transform_static(struct jump_entry *e,
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -105,11 +105,9 @@ static void __jump_label_transform(struc
void arch_jump_label_transform(struct jump_entry *entry,
enum jump_label_type type)
{
- get_online_cpus();
mutex_lock(&text_mutex);
__jump_label_transform(entry, type, NULL, 0);
mutex_unlock(&text_mutex);
- put_online_cpus();
}
static enum {
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -15,6 +15,7 @@
#include <linux/static_key.h>
#include <linux/jump_label_ratelimit.h>
#include <linux/bug.h>
+#include <linux/cpu.h>
#ifdef HAVE_JUMP_LABEL
@@ -124,6 +125,12 @@ void static_key_slow_inc(struct static_k
return;
}
+ /*
+ * A number of architectures need to synchronize I$ across
+ * the all CPUs, for that to be serialized against CPU hot-plug
+ * we need to avoid CPUs coming online.
+ */
+ get_online_cpus();
jump_label_lock();
if (atomic_read(&key->enabled) == 0) {
atomic_set(&key->enabled, -1);
@@ -133,6 +140,7 @@ void static_key_slow_inc(struct static_k
atomic_inc(&key->enabled);
}
jump_label_unlock();
+ put_online_cpus();
}
EXPORT_SYMBOL_GPL(static_key_slow_inc);
@@ -146,6 +154,7 @@ static void __static_key_slow_dec(struct
* returns is unbalanced, because all other static_key_slow_inc()
* instances block while the update is in progress.
*/
+ get_online_cpus();
if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) {
WARN(atomic_read(&key->enabled) < 0,
"jump label: negative count!\n");
@@ -159,6 +168,7 @@ static void __static_key_slow_dec(struct
jump_label_update(key);
}
jump_label_unlock();
+ put_online_cpus();
}
static void jump_label_update_timeout(struct work_struct *work)
@@ -592,6 +602,10 @@ jump_label_module_notify(struct notifier
switch (val) {
case MODULE_STATE_COMING:
+ /*
+ * XXX do we need get_online_cpus() ? the module isn't
+ * executable yet, so nothing should be looking at our code.
+ */
jump_label_lock();
ret = jump_label_add_module(mod);
if (ret) {
[toc] | [prev] | [next] | [standalone]
| From | "tip-bot for Peter Zijlstra (Intel)" <tipbot@zytor.com> |
|---|---|
| Date | 2017-04-20 13:40 +0200 |
| Subject | [tip:smp/hotplug] jump_label: Pull get_online_cpus() into generic code |
| Message-ID | <tyiBk-8mU-9@gated-at.bofh.it> |
| In reply to | #1625231 |
Commit-ID: 82947f31231157d8ab70fa8961f23fd3887a3327
Gitweb: http://git.kernel.org/tip/82947f31231157d8ab70fa8961f23fd3887a3327
Author: Peter Zijlstra (Intel) <peterz@infradead.org>
AuthorDate: Tue, 18 Apr 2017 19:05:03 +0200
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 20 Apr 2017 13:08:57 +0200
jump_label: Pull get_online_cpus() into generic code
This change does two things:
- it moves the get_online_cpus() call into generic code, with the aim of
later providing some static_key ops that avoid it.
- as a side effect it inverts the lock order between cpu_hotplug_lock and
jump_label_mutex.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Sebastian Siewior <bigeasy@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: jbaron@akamai.com
Link: http://lkml.kernel.org/r/20170418103422.590118425@infradead.org
---
arch/mips/kernel/jump_label.c | 2 --
arch/sparc/kernel/jump_label.c | 2 --
arch/tile/kernel/jump_label.c | 2 --
arch/x86/kernel/jump_label.c | 2 --
kernel/jump_label.c | 14 ++++++++++++++
5 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/arch/mips/kernel/jump_label.c b/arch/mips/kernel/jump_label.c
index 3e586da..32e3168 100644
--- a/arch/mips/kernel/jump_label.c
+++ b/arch/mips/kernel/jump_label.c
@@ -58,7 +58,6 @@ void arch_jump_label_transform(struct jump_entry *e,
insn.word = 0; /* nop */
}
- get_online_cpus();
mutex_lock(&text_mutex);
if (IS_ENABLED(CONFIG_CPU_MICROMIPS)) {
insn_p->halfword[0] = insn.word >> 16;
@@ -70,7 +69,6 @@ void arch_jump_label_transform(struct jump_entry *e,
(unsigned long)insn_p + sizeof(*insn_p));
mutex_unlock(&text_mutex);
- put_online_cpus();
}
#endif /* HAVE_JUMP_LABEL */
diff --git a/arch/sparc/kernel/jump_label.c b/arch/sparc/kernel/jump_label.c
index 07933b9..93adde1 100644
--- a/arch/sparc/kernel/jump_label.c
+++ b/arch/sparc/kernel/jump_label.c
@@ -41,12 +41,10 @@ void arch_jump_label_transform(struct jump_entry *entry,
val = 0x01000000;
}
- get_online_cpus();
mutex_lock(&text_mutex);
*insn = val;
flushi(insn);
mutex_unlock(&text_mutex);
- put_online_cpus();
}
#endif
diff --git a/arch/tile/kernel/jump_label.c b/arch/tile/kernel/jump_label.c
index 07802d5..93931a4 100644
--- a/arch/tile/kernel/jump_label.c
+++ b/arch/tile/kernel/jump_label.c
@@ -45,14 +45,12 @@ static void __jump_label_transform(struct jump_entry *e,
void arch_jump_label_transform(struct jump_entry *e,
enum jump_label_type type)
{
- get_online_cpus();
mutex_lock(&text_mutex);
__jump_label_transform(e, type);
flush_icache_range(e->code, e->code + sizeof(tilegx_bundle_bits));
mutex_unlock(&text_mutex);
- put_online_cpus();
}
__init_or_module void arch_jump_label_transform_static(struct jump_entry *e,
diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index c37bd0f..ab4f491 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -105,11 +105,9 @@ static void __jump_label_transform(struct jump_entry *entry,
void arch_jump_label_transform(struct jump_entry *entry,
enum jump_label_type type)
{
- get_online_cpus();
mutex_lock(&text_mutex);
__jump_label_transform(entry, type, NULL, 0);
mutex_unlock(&text_mutex);
- put_online_cpus();
}
static enum {
diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index 6c9cb20..f3afe07 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -15,6 +15,7 @@
#include <linux/static_key.h>
#include <linux/jump_label_ratelimit.h>
#include <linux/bug.h>
+#include <linux/cpu.h>
#ifdef HAVE_JUMP_LABEL
@@ -124,6 +125,12 @@ void static_key_slow_inc(struct static_key *key)
return;
}
+ /*
+ * A number of architectures need to synchronize I$ across
+ * the all CPUs, for that to be serialized against CPU hot-plug
+ * we need to avoid CPUs coming online.
+ */
+ get_online_cpus();
jump_label_lock();
if (atomic_read(&key->enabled) == 0) {
atomic_set(&key->enabled, -1);
@@ -133,6 +140,7 @@ void static_key_slow_inc(struct static_key *key)
atomic_inc(&key->enabled);
}
jump_label_unlock();
+ put_online_cpus();
}
EXPORT_SYMBOL_GPL(static_key_slow_inc);
@@ -146,6 +154,7 @@ static void __static_key_slow_dec(struct static_key *key,
* returns is unbalanced, because all other static_key_slow_inc()
* instances block while the update is in progress.
*/
+ get_online_cpus();
if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) {
WARN(atomic_read(&key->enabled) < 0,
"jump label: negative count!\n");
@@ -159,6 +168,7 @@ static void __static_key_slow_dec(struct static_key *key,
jump_label_update(key);
}
jump_label_unlock();
+ put_online_cpus();
}
static void jump_label_update_timeout(struct work_struct *work)
@@ -592,6 +602,10 @@ jump_label_module_notify(struct notifier_block *self, unsigned long val,
switch (val) {
case MODULE_STATE_COMING:
+ /*
+ * XXX do we need get_online_cpus() ? the module isn't
+ * executable yet, so nothing should be looking at our code.
+ */
jump_label_lock();
ret = jump_label_add_module(mod);
if (ret) {
[toc] | [prev] | [next] | [standalone]
| From | Jason Baron <jbaron@akamai.com> |
|---|---|
| Date | 2017-04-21 19:10 +0200 |
| Subject | Re: [PATCH 1/3] jump_label: Pull get_online_cpus() into generic code |
| Message-ID | <tyKef-8vc-67@gated-at.bofh.it> |
| In reply to | #1625231 |
On 04/18/2017 06:32 AM, Peter Zijlstra wrote:
> This change does two things; it moves the get_online_cpus() call into
> generic code, with the aim of later providing some static_key ops that
> avoid it.
>
> And as a side effect it inverts the relation between cpu_hotplug_lock
> and jump_label_mutex.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
...
> @@ -146,6 +154,7 @@ static void __static_key_slow_dec(struct
> * returns is unbalanced, because all other static_key_slow_inc()
> * instances block while the update is in progress.
> */
> + get_online_cpus();
> if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) {
> WARN(atomic_read(&key->enabled) < 0,
> "jump label: negative count!\n");
So the get and put can be unbalanced here since the above:
'if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex))'
is followed by 'return;'. However, I see that the next patch removes
this and so things are balanced again...
> @@ -159,6 +168,7 @@ static void __static_key_slow_dec(struct
> jump_label_update(key);
> }
> jump_label_unlock();
> + put_online_cpus();
> }
>
> static void jump_label_update_timeout(struct work_struct *work)
> @@ -592,6 +602,10 @@ jump_label_module_notify(struct notifier
>
> switch (val) {
> case MODULE_STATE_COMING:
> + /*
> + * XXX do we need get_online_cpus() ? the module isn't
> + * executable yet, so nothing should be looking at our code.
> + */
Since we're just updating the table of places we potentially need to
patch, but not actually doing any patching, we should not need
get_online_cpus() here...so in attempt to reduce confusion I would
remove this.
Thanks,
-Jason
[toc] | [prev] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2017-04-21 19:10 +0200 |
| Subject | Re: [PATCH 1/3] jump_label: Pull get_online_cpus() into generic code |
| Message-ID | <tyKeg-8vc-83@gated-at.bofh.it> |
| In reply to | #1628382 |
On Fri, Apr 21, 2017 at 12:08:26PM -0400, Jason Baron wrote:
> On 04/18/2017 06:32 AM, Peter Zijlstra wrote:
> > @@ -146,6 +154,7 @@ static void __static_key_slow_dec(struct
> > * returns is unbalanced, because all other static_key_slow_inc()
> > * instances block while the update is in progress.
> > */
> > + get_online_cpus();
> > if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) {
> > WARN(atomic_read(&key->enabled) < 0,
> > "jump label: negative count!\n");
>
> So the get and put can be unbalanced here since the above:
>
> 'if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex))'
>
> is followed by 'return;'. However, I see that the next patch removes this
> and so things are balanced again...
Duh.. right you are.
> > @@ -159,6 +168,7 @@ static void __static_key_slow_dec(struct
> > jump_label_update(key);
> > }
> > jump_label_unlock();
> > + put_online_cpus();
> > }
> >
> > static void jump_label_update_timeout(struct work_struct *work)
> > @@ -592,6 +602,10 @@ jump_label_module_notify(struct notifier
> >
> > switch (val) {
> > case MODULE_STATE_COMING:
> > + /*
> > + * XXX do we need get_online_cpus() ? the module isn't
> > + * executable yet, so nothing should be looking at our code.
> > + */
>
> Since we're just updating the table of places we potentially need to patch,
> but not actually doing any patching, we should not need get_online_cpus()
> here...so in attempt to reduce confusion I would remove this.
Thanks for confirming it is indeed not required. Will make it go away.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web