History

Merge tag 'trace-v7.0-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull tracing fixes from Steven Rostedt: - Fix potential deadlock in osnoise and hotplug The interface_lock can be called by a osnoise thread and the CPU shutdown logic of osnoise can wait for this thread to finish. But cpus_read_lock() can also be taken while holding the interface_lock. This produces a circular lock dependency and can cause a deadlock. Swap the ordering of cpus_read_lock() and the interface_lock to have interface_lock taken within the cpus_read_lock() context to prevent this circular dependency. - Fix freeing of event triggers in early boot up If the same trigger is added on the kernel command line, the second one will fail to be applied and the trigger created will be freed. This calls into the deferred logic and creates a kernel thread to do the freeing. But the command line logic is called before kernel threads can be created and this leads to a NULL pointer dereference. Delay freeing event triggers until late init. * tag 'trace-v7.0-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing: Drain deferred trigger frees if kthread creation fails tracing: Fix potential deadlock in cpu hotplug with osnoise

Linus Torvalds committed 7 months ago

Commit cbfffcc2 parents e522b75 250ab252 files · +71 −18Browse files

Unified · Split

2 files
  1. kernel/trace/trace_events_trigger.c +66 −13
  2. kernel/trace/trace_osnoise.c +5 −5
kernel/trace/trace_events_trigger.c+66−13
@@ -22,6 +22,39 @@ static struct task_struct *trigger_kthread; · 21 unmodified lines
22static struct llist_head trigger_data_free_list;22static struct llist_head trigger_data_free_list;
23static DEFINE_MUTEX(trigger_data_kthread_mutex);23static DEFINE_MUTEX(trigger_data_kthread_mutex);
24 24
25static int trigger_kthread_fn(void *ignore);
26
27static void trigger_create_kthread_locked(void)
28{
29 lockdep_assert_held(&trigger_data_kthread_mutex);
30
31 if (!trigger_kthread) {
32 struct task_struct *kthread;
33
34 kthread = kthread_create(trigger_kthread_fn, NULL,
35 "trigger_data_free");
36 if (!IS_ERR(kthread))
37 WRITE_ONCE(trigger_kthread, kthread);
38 }
39}
40
41static void trigger_data_free_queued_locked(void)
42{
43 struct event_trigger_data *data, *tmp;
44 struct llist_node *llnodes;
45
46 lockdep_assert_held(&trigger_data_kthread_mutex);
47
48 llnodes = llist_del_all(&trigger_data_free_list);
49 if (!llnodes)
50 return;
51
52 tracepoint_synchronize_unregister();
53
54 llist_for_each_entry_safe(data, tmp, llnodes, llist)
55 kfree(data);
56}
57
25/* Bulk garbage collection of event_trigger_data elements */58/* Bulk garbage collection of event_trigger_data elements */
26static int trigger_kthread_fn(void *ignore)59static int trigger_kthread_fn(void *ignore)
27{60{
@@ -56,30 +89,50 @@ void trigger_data_free(struct event_trigger_data *data) · 28 unmodified lines
56 if (data->cmd_ops->set_filter)89 if (data->cmd_ops->set_filter)
57 data->cmd_ops->set_filter(NULL, data, NULL);90 data->cmd_ops->set_filter(NULL, data, NULL);
58 91
92 /*
93 * Boot-time trigger registration can fail before kthread creation
94 * works. Keep the deferred-free semantics during boot and let late
95 * init start the kthread to drain the list.
96 */
97 if (system_state == SYSTEM_BOOTING && !trigger_kthread) {
98 llist_add(&data->llist, &trigger_data_free_list);
99 return;
100 }
101
59 if (unlikely(!trigger_kthread)) {102 if (unlikely(!trigger_kthread)) {
60 guard(mutex)(&trigger_data_kthread_mutex);103 guard(mutex)(&trigger_data_kthread_mutex);
104
105 trigger_create_kthread_locked();
61 /* Check again after taking mutex */106 /* Check again after taking mutex */
62 if (!trigger_kthread) {107 if (!trigger_kthread) {
63 struct task_struct *kthread;108 llist_add(&data->llist, &trigger_data_free_list);
64 109 /* Drain the queued frees synchronously if creation failed. */
65 kthread = kthread_create(trigger_kthread_fn, NULL,110 trigger_data_free_queued_locked();
66 "trigger_data_free");111 return;
67 if (!IS_ERR(kthread))
68 WRITE_ONCE(trigger_kthread, kthread);
69 }112 }
70 }113 }
71 114
72 if (!trigger_kthread) {
73 /* Do it the slow way */
74 tracepoint_synchronize_unregister();
75 kfree(data);
76 return;
77 }
78
79 llist_add(&data->llist, &trigger_data_free_list);115 llist_add(&data->llist, &trigger_data_free_list);
80 wake_up_process(trigger_kthread);116 wake_up_process(trigger_kthread);
81}117}
82 118
119static int __init trigger_data_free_init(void)
120{
121 guard(mutex)(&trigger_data_kthread_mutex);
122
123 if (llist_empty(&trigger_data_free_list))
124 return 0;
125
126 trigger_create_kthread_locked();
127 if (trigger_kthread)
128 wake_up_process(trigger_kthread);
129 else
130 trigger_data_free_queued_locked();
131
132 return 0;
133}
134late_initcall(trigger_data_free_init);
135
83static inline void data_ops_trigger(struct event_trigger_data *data,136static inline void data_ops_trigger(struct event_trigger_data *data,
84 struct trace_buffer *buffer, void *rec,137 struct trace_buffer *buffer, void *rec,
85 struct ring_buffer_event *event)138 struct ring_buffer_event *event)
kernel/trace/trace_osnoise.c+5−5
@@ -2073,8 +2073,8 @@ static void osnoise_hotplug_workfn(struct work_struct *dummy) · 2072 unmodified lines
2073 if (!osnoise_has_registered_instances())2073 if (!osnoise_has_registered_instances())
2074 return;2074 return;
2075 2075
2076 guard(mutex)(&interface_lock);
2077 guard(cpus_read_lock)();2076 guard(cpus_read_lock)();
2077 guard(mutex)(&interface_lock);
2078 2078
2079 if (!cpu_online(cpu))2079 if (!cpu_online(cpu))
2080 return;2080 return;
@@ -2237,11 +2237,11 @@ static ssize_t osnoise_options_write(struct file *filp, const char __user *ubuf, · 156 unmodified lines
2237 if (running)2237 if (running)
2238 stop_per_cpu_kthreads();2238 stop_per_cpu_kthreads();
2239 2239
2240 mutex_lock(&interface_lock);
2241 /*2240 /*
2242 * avoid CPU hotplug operations that might read options.2241 * avoid CPU hotplug operations that might read options.
2243 */2242 */
2244 cpus_read_lock();2243 cpus_read_lock();
2244 mutex_lock(&interface_lock);
2245 2245
2246 retval = cnt;2246 retval = cnt;
2247 2247
@@ -2257,8 +2257,8 @@ static ssize_t osnoise_options_write(struct file *filp, const char __user *ubuf, · 9 unmodified lines
2257 clear_bit(option, &osnoise_options);2257 clear_bit(option, &osnoise_options);
2258 }2258 }
2259 2259
2260 cpus_read_unlock();
2261 mutex_unlock(&interface_lock);2260 mutex_unlock(&interface_lock);
2261 cpus_read_unlock();
2262 2262
2263 if (running)2263 if (running)
2264 start_per_cpu_kthreads();2264 start_per_cpu_kthreads();
@@ -2345,16 +2345,16 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count, · 80 unmodified lines
2345 if (running)2345 if (running)
2346 stop_per_cpu_kthreads();2346 stop_per_cpu_kthreads();
2347 2347
2348 mutex_lock(&interface_lock);
2349 /*2348 /*
2350 * osnoise_cpumask is read by CPU hotplug operations.2349 * osnoise_cpumask is read by CPU hotplug operations.
2351 */2350 */
2352 cpus_read_lock();2351 cpus_read_lock();
2352 mutex_lock(&interface_lock);
2353 2353
2354 cpumask_copy(&osnoise_cpumask, osnoise_cpumask_new);2354 cpumask_copy(&osnoise_cpumask, osnoise_cpumask_new);
2355 2355
2356 cpus_read_unlock();
2357 mutex_unlock(&interface_lock);2356 mutex_unlock(&interface_lock);
2357 cpus_read_unlock();
2358 2358
2359 if (running)2359 if (running)
2360 start_per_cpu_kthreads();2360 start_per_cpu_kthreads();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t