hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/kernel/events/callchain.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Performance events callchain code, extracted from core.c:
34 *
....@@ -5,8 +6,6 @@
56 * Copyright (C) 2008-2011 Red Hat, Inc., Ingo Molnar
67 * Copyright (C) 2008-2011 Red Hat, Inc., Peter Zijlstra
78 * Copyright © 2009 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
8
- *
9
- * For licensing details see kernel-base/COPYING
109 */
1110
1211 #include <linux/perf_event.h>
....@@ -17,7 +16,7 @@
1716
1817 struct callchain_cpus_entries {
1918 struct rcu_head rcu_head;
20
- struct perf_callchain_entry *cpu_entries[0];
19
+ struct perf_callchain_entry *cpu_entries[];
2120 };
2221
2322 int sysctl_perf_event_max_stack __read_mostly = PERF_MAX_STACK_DEPTH;
....@@ -150,7 +149,7 @@
150149 }
151150 }
152151
153
-static struct perf_callchain_entry *get_callchain_entry(int *rctx)
152
+struct perf_callchain_entry *get_callchain_entry(int *rctx)
154153 {
155154 int cpu;
156155 struct callchain_cpus_entries *entries;
....@@ -160,8 +159,10 @@
160159 return NULL;
161160
162161 entries = rcu_dereference(callchain_cpus_entries);
163
- if (!entries)
162
+ if (!entries) {
163
+ put_recursion_context(this_cpu_ptr(callchain_recursion), *rctx);
164164 return NULL;
165
+ }
165166
166167 cpu = smp_processor_id();
167168
....@@ -169,7 +170,7 @@
169170 (*rctx * perf_callchain_entry__sizeof()));
170171 }
171172
172
-static void
173
+void
173174 put_callchain_entry(int rctx)
174175 {
175176 put_recursion_context(this_cpu_ptr(callchain_recursion), rctx);
....@@ -184,11 +185,8 @@
184185 int rctx;
185186
186187 entry = get_callchain_entry(&rctx);
187
- if (rctx == -1)
188
- return NULL;
189
-
190188 if (!entry)
191
- goto exit_put;
189
+ return NULL;
192190
193191 ctx.entry = entry;
194192 ctx.max_stack = max_stack;
....@@ -219,10 +217,9 @@
219217 if (add_mark)
220218 perf_callchain_store_context(&ctx, PERF_CONTEXT_USER);
221219
222
- fs = get_fs();
223
- set_fs(USER_DS);
220
+ fs = force_uaccess_begin();
224221 perf_callchain_user(&ctx, regs);
225
- set_fs(fs);
222
+ force_uaccess_end(fs);
226223 }
227224 }
228225
....@@ -237,7 +234,7 @@
237234 * sysctl_perf_event_max_contexts_per_stack.
238235 */
239236 int perf_event_max_stack_handler(struct ctl_table *table, int write,
240
- void __user *buffer, size_t *lenp, loff_t *ppos)
237
+ void *buffer, size_t *lenp, loff_t *ppos)
241238 {
242239 int *value = table->data;
243240 int new_value = *value, ret;