Commit 05bbb936 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull perf fixes from Thomas Gleixner:
 "Two small fixes for kprobes and perf:

   - Prevent a deadlock in kprobe_optimizer() causes by reverse lock
     ordering

   - Fix a comment typo"

* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  kprobes: Fix potential deadlock in kprobe_optimizer()
  perf/x86: Fix typo in comment
parents 44c471e4 f1c6ece2
...@@ -1236,7 +1236,7 @@ void x86_pmu_enable_event(struct perf_event *event) ...@@ -1236,7 +1236,7 @@ void x86_pmu_enable_event(struct perf_event *event)
* Add a single event to the PMU. * Add a single event to the PMU.
* *
* The event is added to the group of enabled events * The event is added to the group of enabled events
* but only if it can be scehduled with existing events. * but only if it can be scheduled with existing events.
*/ */
static int x86_pmu_add(struct perf_event *event, int flags) static int x86_pmu_add(struct perf_event *event, int flags)
{ {
......
...@@ -470,6 +470,7 @@ static DECLARE_DELAYED_WORK(optimizing_work, kprobe_optimizer); ...@@ -470,6 +470,7 @@ static DECLARE_DELAYED_WORK(optimizing_work, kprobe_optimizer);
*/ */
static void do_optimize_kprobes(void) static void do_optimize_kprobes(void)
{ {
lockdep_assert_held(&text_mutex);
/* /*
* The optimization/unoptimization refers online_cpus via * The optimization/unoptimization refers online_cpus via
* stop_machine() and cpu-hotplug modifies online_cpus. * stop_machine() and cpu-hotplug modifies online_cpus.
...@@ -487,9 +488,7 @@ static void do_optimize_kprobes(void) ...@@ -487,9 +488,7 @@ static void do_optimize_kprobes(void)
list_empty(&optimizing_list)) list_empty(&optimizing_list))
return; return;
mutex_lock(&text_mutex);
arch_optimize_kprobes(&optimizing_list); arch_optimize_kprobes(&optimizing_list);
mutex_unlock(&text_mutex);
} }
/* /*
...@@ -500,6 +499,7 @@ static void do_unoptimize_kprobes(void) ...@@ -500,6 +499,7 @@ static void do_unoptimize_kprobes(void)
{ {
struct optimized_kprobe *op, *tmp; struct optimized_kprobe *op, *tmp;
lockdep_assert_held(&text_mutex);
/* See comment in do_optimize_kprobes() */ /* See comment in do_optimize_kprobes() */
lockdep_assert_cpus_held(); lockdep_assert_cpus_held();
...@@ -507,7 +507,6 @@ static void do_unoptimize_kprobes(void) ...@@ -507,7 +507,6 @@ static void do_unoptimize_kprobes(void)
if (list_empty(&unoptimizing_list)) if (list_empty(&unoptimizing_list))
return; return;
mutex_lock(&text_mutex);
arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list); arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list);
/* Loop free_list for disarming */ /* Loop free_list for disarming */
list_for_each_entry_safe(op, tmp, &freeing_list, list) { list_for_each_entry_safe(op, tmp, &freeing_list, list) {
...@@ -524,7 +523,6 @@ static void do_unoptimize_kprobes(void) ...@@ -524,7 +523,6 @@ static void do_unoptimize_kprobes(void)
} else } else
list_del_init(&op->list); list_del_init(&op->list);
} }
mutex_unlock(&text_mutex);
} }
/* Reclaim all kprobes on the free_list */ /* Reclaim all kprobes on the free_list */
...@@ -556,6 +554,7 @@ static void kprobe_optimizer(struct work_struct *work) ...@@ -556,6 +554,7 @@ static void kprobe_optimizer(struct work_struct *work)
{ {
mutex_lock(&kprobe_mutex); mutex_lock(&kprobe_mutex);
cpus_read_lock(); cpus_read_lock();
mutex_lock(&text_mutex);
/* Lock modules while optimizing kprobes */ /* Lock modules while optimizing kprobes */
mutex_lock(&module_mutex); mutex_lock(&module_mutex);
...@@ -583,6 +582,7 @@ static void kprobe_optimizer(struct work_struct *work) ...@@ -583,6 +582,7 @@ static void kprobe_optimizer(struct work_struct *work)
do_free_cleaned_kprobes(); do_free_cleaned_kprobes();
mutex_unlock(&module_mutex); mutex_unlock(&module_mutex);
mutex_unlock(&text_mutex);
cpus_read_unlock(); cpus_read_unlock();
mutex_unlock(&kprobe_mutex); mutex_unlock(&kprobe_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment