Skip to content

Commit fb6d032

Browse files
mhiramatrostedt
authored andcommitted
tracing: Freeable reserved ring buffer
Make the ring buffer on reserved memory to be freeable. This allows us to free the trace instance on the reserved memory without changing cmdline and rebooting. Even if we can not change the kernel cmdline for security reason, we can release the reserved memory for the ring buffer as free (available) memory. For example, boot kernel with reserved memory; "reserve_mem=20M:2M:trace trace_instance=boot_mapped^traceoff@trace" ~ # free total used free shared buff/cache available Mem: 1995548 50544 1927568 14964 17436 1911480 Swap: 0 0 0 ~ # rmdir /sys/kernel/tracing/instances/boot_mapped/ [ 23.704023] Freeing reserve_mem:trace memory: 20476K ~ # free total used free shared buff/cache available Mem: 2016024 41844 1956740 14968 17440 1940572 Swap: 0 0 0 Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Mike Rapoport <rppt@kernel.org> Link: https://lore.kernel.org/173989134814.230693.18199312930337815629.stgit@devnote2 Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 74e2498 commit fb6d032

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

kernel/trace/trace.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9479,6 +9479,9 @@ static void free_trace_buffers(struct trace_array *tr)
94799479
#ifdef CONFIG_TRACER_MAX_TRACE
94809480
free_trace_buffer(&tr->max_buffer);
94819481
#endif
9482+
9483+
if (tr->range_addr_start)
9484+
vunmap((void *)tr->range_addr_start);
94829485
}
94839486

94849487
static void init_trace_flags_index(struct trace_array *tr)
@@ -9640,6 +9643,7 @@ trace_array_create_systems(const char *name, const char *systems,
96409643
free_cpumask_var(tr->pipe_cpumask);
96419644
free_cpumask_var(tr->tracing_cpumask);
96429645
kfree_const(tr->system_names);
9646+
kfree(tr->range_name);
96439647
kfree(tr->name);
96449648
kfree(tr);
96459649

@@ -9766,6 +9770,11 @@ static int __remove_instance(struct trace_array *tr)
97669770
free_trace_buffers(tr);
97679771
clear_tracing_err_log(tr);
97689772

9773+
if (tr->range_name) {
9774+
reserve_mem_release_by_name(tr->range_name);
9775+
kfree(tr->range_name);
9776+
}
9777+
97699778
for (i = 0; i < tr->nr_topts; i++) {
97709779
kfree(tr->topts[i].topts);
97719780
}
@@ -10590,6 +10599,7 @@ __init static void enable_instances(void)
1059010599
bool traceoff = false;
1059110600
char *flag_delim;
1059210601
char *addr_delim;
10602+
char *rname __free(kfree) = NULL;
1059310603

1059410604
tok = strsep(&curr_str, ",");
1059510605

@@ -10646,6 +10656,7 @@ __init static void enable_instances(void)
1064610656
pr_warn("Failed to map boot instance %s to %s\n", name, tok);
1064710657
continue;
1064810658
}
10659+
rname = kstrdup(tok, GFP_KERNEL);
1064910660
}
1065010661

1065110662
if (start) {
@@ -10682,7 +10693,7 @@ __init static void enable_instances(void)
1068210693
*/
1068310694
if (start) {
1068410695
tr->flags |= TRACE_ARRAY_FL_BOOT | TRACE_ARRAY_FL_LAST_BOOT;
10685-
tr->ref++;
10696+
tr->range_name = no_free_ptr(rname);
1068610697
}
1068710698

1068810699
while ((tok = strsep(&curr_str, ","))) {

kernel/trace/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ struct trace_array {
348348
unsigned int mapped;
349349
unsigned long range_addr_start;
350350
unsigned long range_addr_size;
351+
char *range_name;
351352
long text_delta;
352353
void *scratch; /* pointer in persistent memory */
353354
int scratch_size;

0 commit comments

Comments
 (0)