Skip to content

Commit 29a02ec

Browse files
committed
tracing: Allow boot instances to use reserve_mem boot memory
Allow boot instances to use memory reserved by the reserve_mem boot option. reserve_mem=12M:4096:trace trace_instance=boot_mapped@trace The above will allocate 12 megs with 4096 alignment and label it "trace". The second parameter will create a "boot_mapped" instance and use the memory reserved and labeled as "trace" as the memory for the ring buffer. That will create an instance called "boot_mapped": /sys/kernel/tracing/instances/boot_mapped Note, because the ring buffer is using a defined memory ranged, it will act just like a memory mapped ring buffer. It will not have a snapshot buffer, as it can't swap out the buffer. The snapshot files as well as any tracers that uses a snapshot will not be present in the boot_mapped instance. Also note that reserve_mem is not reliable in acquiring the same physical memory at each soft reboot. It is possible that KALSR could map the kernel at the previous boot memory location forcing the reserve_mem to return a different memory location. In this case, the previous ring buffer will be lost. Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Vincent Donnefort <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 6d02eef commit 29a02ec

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6752,6 +6752,19 @@
67526752
memory at 0x284500000 that is 12Megs. The per CPU buffers of that
67536753
instance will be split up accordingly.
67546754

6755+
Alternatively, the memory can be reserved by the reserve_mem option:
6756+
6757+
reserve_mem=12M:4096:trace trace_instance=boot_map@trace
6758+
6759+
This will reserve 12 megabytes at boot up with a 4096 byte alignment
6760+
and place the ring buffer in this memory. Note that due to KASLR, the
6761+
memory may not be the same location each time, which will not preserve
6762+
the buffer content.
6763+
6764+
Also note that the layout of the ring buffer data may change between
6765+
kernel versions where the validator will fail and reset the ring buffer
6766+
if the layout is not the same as the previous kernel.
6767+
67556768
trace_options=[option-list]
67566769
[FTRACE] Enable or disable tracer options at boot.
67576770
The option-list is a comma delimited list of options

kernel/trace/trace.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10465,22 +10465,20 @@ __init static void enable_instances(void)
1046510465
str = boot_instance_info;
1046610466

1046710467
while ((curr_str = strsep(&str, "\t"))) {
10468-
unsigned long start = 0;
10469-
unsigned long size = 0;
10468+
phys_addr_t start = 0;
10469+
phys_addr_t size = 0;
1047010470
unsigned long addr = 0;
1047110471

1047210472
tok = strsep(&curr_str, ",");
1047310473
name = strsep(&tok, "@");
10474-
if (tok) {
10474+
10475+
if (tok && isdigit(*tok)) {
1047510476
start = memparse(tok, &tok);
1047610477
if (!start) {
1047710478
pr_warn("Tracing: Invalid boot instance address for %s\n",
1047810479
name);
1047910480
continue;
1048010481
}
10481-
}
10482-
10483-
if (start) {
1048410482
if (*tok != ':') {
1048510483
pr_warn("Tracing: No size specified for instance %s\n", name);
1048610484
continue;
@@ -10492,10 +10490,19 @@ __init static void enable_instances(void)
1049210490
name);
1049310491
continue;
1049410492
}
10493+
} else if (tok) {
10494+
if (!reserve_mem_find_by_name(tok, &start, &size)) {
10495+
start = 0;
10496+
pr_warn("Failed to map boot instance %s to %s\n", name, tok);
10497+
continue;
10498+
}
10499+
}
10500+
10501+
if (start) {
1049510502
addr = map_pages(start, size);
1049610503
if (addr) {
10497-
pr_info("Tracing: mapped boot instance %s at physical memory 0x%lx of size 0x%lx\n",
10498-
name, start, size);
10504+
pr_info("Tracing: mapped boot instance %s at physical memory %pa of size 0x%lx\n",
10505+
name, &start, (unsigned long)size);
1049910506
} else {
1050010507
pr_warn("Tracing: Failed to map boot instance %s\n", name);
1050110508
continue;

0 commit comments

Comments
 (0)