Skip to content

Commit 4317562

Browse files
committed
Merge tag 'trace-v5.15-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull more tracing updates from Steven Rostedt: - Add migrate-disable counter to tracing header - Fix error handling in event probes - Fix missed unlock in osnoise in error path - Fix merge issue with tools/bootconfig - Clean up bootconfig data when init memory is removed - Fix bootconfig to loop only on subkeys - Have kernel command lines override bootconfig options - Increase field counts for synthetic events - Have histograms dynamic allocate event elements to save space - Fixes in testing and documentation * tag 'trace-v5.15-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: tracing/boot: Fix to loop on only subkeys selftests/ftrace: Exclude "(fault)" in testing add/remove eprobe events tracing: Dynamically allocate the per-elt hist_elt_data array tracing: synth events: increase max fields count tools/bootconfig: Show whole test command for each test case bootconfig: Fix missing return check of xbc_node_compose_key function tools/bootconfig: Fix tracing_on option checking in ftrace2bconf.sh docs: bootconfig: Add how to use bootconfig for kernel parameters init/bootconfig: Reorder init parameter from bootconfig and cmdline init: bootconfig: Remove all bootconfig data when the init memory is removed tracing/osnoise: Fix missed cpus_read_unlock() in start_per_cpu_kthreads() tracing: Fix some alloc_event_probe() error handling bugs tracing: Add migrate-disabled counter to tracing output.
2 parents f154c80 + cfd7998 commit 4317562

File tree

14 files changed

+122
-39
lines changed

14 files changed

+122
-39
lines changed

Documentation/admin-guide/bootconfig.rst

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ update the boot loader and the kernel image itself as long as the boot
178178
loader passes the correct initrd file size. If by any chance, the boot
179179
loader passes a longer size, the kernel fails to find the bootconfig data.
180180

181-
To do this operation, Linux kernel provides "bootconfig" command under
181+
To do this operation, Linux kernel provides ``bootconfig`` command under
182182
tools/bootconfig, which allows admin to apply or delete the config file
183183
to/from initrd image. You can build it by the following command::
184184

@@ -196,6 +196,43 @@ To remove the config from the image, you can use -d option as below::
196196
Then add "bootconfig" on the normal kernel command line to tell the
197197
kernel to look for the bootconfig at the end of the initrd file.
198198

199+
200+
Kernel parameters via Boot Config
201+
=================================
202+
203+
In addition to the kernel command line, the boot config can be used for
204+
passing the kernel parameters. All the key-value pairs under ``kernel``
205+
key will be passed to kernel cmdline directly. Moreover, the key-value
206+
pairs under ``init`` will be passed to init process via the cmdline.
207+
The parameters are concatinated with user-given kernel cmdline string
208+
as the following order, so that the command line parameter can override
209+
bootconfig parameters (this depends on how the subsystem handles parameters
210+
but in general, earlier parameter will be overwritten by later one.)::
211+
212+
[bootconfig params][cmdline params] -- [bootconfig init params][cmdline init params]
213+
214+
Here is an example of the bootconfig file for kernel/init parameters.::
215+
216+
kernel {
217+
root = 01234567-89ab-cdef-0123-456789abcd
218+
}
219+
init {
220+
splash
221+
}
222+
223+
This will be copied into the kernel cmdline string as the following::
224+
225+
root="01234567-89ab-cdef-0123-456789abcd" -- splash
226+
227+
If user gives some other command line like,::
228+
229+
ro bootconfig -- quiet
230+
231+
The final kernel cmdline will be the following::
232+
233+
root="01234567-89ab-cdef-0123-456789abcd" ro bootconfig -- splash quiet
234+
235+
199236
Config File Limitation
200237
======================
201238

init/main.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ static char *extra_init_args;
153153
#ifdef CONFIG_BOOT_CONFIG
154154
/* Is bootconfig on command line? */
155155
static bool bootconfig_found;
156-
static bool initargs_found;
156+
static size_t initargs_offs;
157157
#else
158158
# define bootconfig_found false
159-
# define initargs_found false
159+
# define initargs_offs 0
160160
#endif
161161

162162
static char *execute_command;
@@ -422,9 +422,9 @@ static void __init setup_boot_config(void)
422422
if (IS_ERR(err) || !bootconfig_found)
423423
return;
424424

425-
/* parse_args() stops at '--' and returns an address */
425+
/* parse_args() stops at the next param of '--' and returns an address */
426426
if (err)
427-
initargs_found = true;
427+
initargs_offs = err - tmp_cmdline;
428428

429429
if (!data) {
430430
pr_err("'bootconfig' found on command line, but no bootconfig found\n");
@@ -468,7 +468,12 @@ static void __init setup_boot_config(void)
468468
return;
469469
}
470470

471-
#else
471+
static void __init exit_boot_config(void)
472+
{
473+
xbc_destroy_all();
474+
}
475+
476+
#else /* !CONFIG_BOOT_CONFIG */
472477

473478
static void __init setup_boot_config(void)
474479
{
@@ -481,7 +486,11 @@ static int __init warn_bootconfig(char *str)
481486
pr_warn("WARNING: 'bootconfig' found on the kernel command line but CONFIG_BOOT_CONFIG is not set.\n");
482487
return 0;
483488
}
484-
#endif
489+
490+
#define exit_boot_config() do {} while (0)
491+
492+
#endif /* CONFIG_BOOT_CONFIG */
493+
485494
early_param("bootconfig", warn_bootconfig);
486495

487496
/* Change NUL term back to "=", to make "param" the whole string. */
@@ -646,16 +655,21 @@ static void __init setup_command_line(char *command_line)
646655
* Append supplemental init boot args to saved_command_line
647656
* so that user can check what command line options passed
648657
* to init.
658+
* The order should always be
659+
* " -- "[bootconfig init-param][cmdline init-param]
649660
*/
650-
len = strlen(saved_command_line);
651-
if (initargs_found) {
652-
saved_command_line[len++] = ' ';
661+
if (initargs_offs) {
662+
len = xlen + initargs_offs;
663+
strcpy(saved_command_line + len, extra_init_args);
664+
len += ilen - 4; /* strlen(extra_init_args) */
665+
strcpy(saved_command_line + len,
666+
boot_command_line + initargs_offs - 1);
653667
} else {
668+
len = strlen(saved_command_line);
654669
strcpy(saved_command_line + len, " -- ");
655670
len += 4;
671+
strcpy(saved_command_line + len, extra_init_args);
656672
}
657-
658-
strcpy(saved_command_line + len, extra_init_args);
659673
}
660674
}
661675

@@ -1494,6 +1508,7 @@ static int __ref kernel_init(void *unused)
14941508
kprobe_free_init_mem();
14951509
ftrace_free_init_mem();
14961510
kgdb_free_init_mem();
1511+
exit_boot_config();
14971512
free_initmem();
14981513
mark_readonly();
14991514

kernel/trace/trace.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,15 @@ enum print_line_t trace_handle_return(struct trace_seq *s)
26032603
}
26042604
EXPORT_SYMBOL_GPL(trace_handle_return);
26052605

2606+
static unsigned short migration_disable_value(void)
2607+
{
2608+
#if defined(CONFIG_SMP)
2609+
return current->migration_disabled;
2610+
#else
2611+
return 0;
2612+
#endif
2613+
}
2614+
26062615
unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
26072616
{
26082617
unsigned int trace_flags = irqs_status;
@@ -2621,7 +2630,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
26212630
trace_flags |= TRACE_FLAG_NEED_RESCHED;
26222631
if (test_preempt_need_resched())
26232632
trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;
2624-
return (trace_flags << 16) | (pc & 0xff);
2633+
return (trace_flags << 16) | (min_t(unsigned int, pc & 0xff, 0xf)) |
2634+
(min_t(unsigned int, migration_disable_value(), 0xf)) << 4;
26252635
}
26262636

26272637
struct ring_buffer_event *
@@ -4189,9 +4199,10 @@ static void print_lat_help_header(struct seq_file *m)
41894199
"# | / _----=> need-resched \n"
41904200
"# || / _---=> hardirq/softirq \n"
41914201
"# ||| / _--=> preempt-depth \n"
4192-
"# |||| / delay \n"
4193-
"# cmd pid ||||| time | caller \n"
4194-
"# \\ / ||||| \\ | / \n");
4202+
"# |||| / _-=> migrate-disable \n"
4203+
"# ||||| / delay \n"
4204+
"# cmd pid |||||| time | caller \n"
4205+
"# \\ / |||||| \\ | / \n");
41954206
}
41964207

41974208
static void print_event_info(struct array_buffer *buf, struct seq_file *m)
@@ -4229,9 +4240,10 @@ static void print_func_help_header_irq(struct array_buffer *buf, struct seq_file
42294240
seq_printf(m, "# %.*s / _----=> need-resched\n", prec, space);
42304241
seq_printf(m, "# %.*s| / _---=> hardirq/softirq\n", prec, space);
42314242
seq_printf(m, "# %.*s|| / _--=> preempt-depth\n", prec, space);
4232-
seq_printf(m, "# %.*s||| / delay\n", prec, space);
4233-
seq_printf(m, "# TASK-PID %.*s CPU# |||| TIMESTAMP FUNCTION\n", prec, " TGID ");
4234-
seq_printf(m, "# | | %.*s | |||| | |\n", prec, " | ");
4243+
seq_printf(m, "# %.*s||| / _-=> migrate-disable\n", prec, space);
4244+
seq_printf(m, "# %.*s|||| / delay\n", prec, space);
4245+
seq_printf(m, "# TASK-PID %.*s CPU# ||||| TIMESTAMP FUNCTION\n", prec, " TGID ");
4246+
seq_printf(m, "# | | %.*s | ||||| | |\n", prec, " | ");
42354247
}
42364248

42374249
void

kernel/trace/trace_boot.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,14 @@ trace_boot_init_events(struct trace_array *tr, struct xbc_node *node)
522522
if (!node)
523523
return;
524524
/* per-event key starts with "event.GROUP.EVENT" */
525-
xbc_node_for_each_child(node, gnode) {
525+
xbc_node_for_each_subkey(node, gnode) {
526526
data = xbc_node_get_data(gnode);
527527
if (!strcmp(data, "enable")) {
528528
enable_all = true;
529529
continue;
530530
}
531531
enable = false;
532-
xbc_node_for_each_child(gnode, enode) {
532+
xbc_node_for_each_subkey(gnode, enode) {
533533
data = xbc_node_get_data(enode);
534534
if (!strcmp(data, "enable")) {
535535
enable = true;
@@ -625,7 +625,7 @@ trace_boot_init_instances(struct xbc_node *node)
625625
if (!node)
626626
return;
627627

628-
xbc_node_for_each_child(node, inode) {
628+
xbc_node_for_each_subkey(node, inode) {
629629
p = xbc_node_get_data(inode);
630630
if (!p || *p == '\0')
631631
continue;

kernel/trace/trace_eprobe.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static struct trace_eprobe *alloc_event_probe(const char *group,
151151

152152
ep = kzalloc(struct_size(ep, tp.args, nargs), GFP_KERNEL);
153153
if (!ep) {
154-
trace_event_put_ref(ep->event);
154+
trace_event_put_ref(event);
155155
goto error;
156156
}
157157
ep->event = event;
@@ -851,7 +851,8 @@ static int __trace_eprobe_create(int argc, const char *argv[])
851851
ret = PTR_ERR(ep);
852852
/* This must return -ENOMEM, else there is a bug */
853853
WARN_ON_ONCE(ret != -ENOMEM);
854-
goto error; /* We know ep is not allocated */
854+
ep = NULL;
855+
goto error;
855856
}
856857

857858
argc -= 2; argv += 2;

kernel/trace/trace_events.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ static int trace_define_common_fields(void)
181181

182182
__common_field(unsigned short, type);
183183
__common_field(unsigned char, flags);
184+
/* Holds both preempt_count and migrate_disable */
184185
__common_field(unsigned char, preempt_count);
185186
__common_field(int, pid);
186187

kernel/trace/trace_events_hist.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ struct track_data {
508508
struct hist_elt_data {
509509
char *comm;
510510
u64 *var_ref_vals;
511-
char *field_var_str[SYNTH_FIELDS_MAX];
511+
char **field_var_str;
512+
int n_field_var_str;
512513
};
513514

514515
struct snapshot_context {
@@ -1401,9 +1402,11 @@ static void hist_elt_data_free(struct hist_elt_data *elt_data)
14011402
{
14021403
unsigned int i;
14031404

1404-
for (i = 0; i < SYNTH_FIELDS_MAX; i++)
1405+
for (i = 0; i < elt_data->n_field_var_str; i++)
14051406
kfree(elt_data->field_var_str[i]);
14061407

1408+
kfree(elt_data->field_var_str);
1409+
14071410
kfree(elt_data->comm);
14081411
kfree(elt_data);
14091412
}
@@ -1451,6 +1454,13 @@ static int hist_trigger_elt_data_alloc(struct tracing_map_elt *elt)
14511454

14521455
size = STR_VAR_LEN_MAX;
14531456

1457+
elt_data->field_var_str = kcalloc(n_str, sizeof(char *), GFP_KERNEL);
1458+
if (!elt_data->field_var_str) {
1459+
hist_elt_data_free(elt_data);
1460+
return -EINVAL;
1461+
}
1462+
elt_data->n_field_var_str = n_str;
1463+
14541464
for (i = 0; i < n_str; i++) {
14551465
elt_data->field_var_str[i] = kzalloc(size, GFP_KERNEL);
14561466
if (!elt_data->field_var_str[i]) {

kernel/trace/trace_osnoise.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ static int start_kthread(unsigned int cpu)
15481548
static int start_per_cpu_kthreads(struct trace_array *tr)
15491549
{
15501550
struct cpumask *current_mask = &save_cpumask;
1551-
int retval;
1551+
int retval = 0;
15521552
int cpu;
15531553

15541554
cpus_read_lock();
@@ -1568,13 +1568,13 @@ static int start_per_cpu_kthreads(struct trace_array *tr)
15681568
retval = start_kthread(cpu);
15691569
if (retval) {
15701570
stop_per_cpu_kthreads();
1571-
return retval;
1571+
break;
15721572
}
15731573
}
15741574

15751575
cpus_read_unlock();
15761576

1577-
return 0;
1577+
return retval;
15781578
}
15791579

15801580
#ifdef CONFIG_HOTPLUG_CPU

kernel/trace/trace_output.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,13 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
492492
trace_seq_printf(s, "%c%c%c",
493493
irqs_off, need_resched, hardsoft_irq);
494494

495-
if (entry->preempt_count)
496-
trace_seq_printf(s, "%x", entry->preempt_count);
495+
if (entry->preempt_count & 0xf)
496+
trace_seq_printf(s, "%x", entry->preempt_count & 0xf);
497+
else
498+
trace_seq_putc(s, '.');
499+
500+
if (entry->preempt_count & 0xf0)
501+
trace_seq_printf(s, "%x", entry->preempt_count >> 4);
497502
else
498503
trace_seq_putc(s, '.');
499504

@@ -656,7 +661,7 @@ int trace_print_lat_context(struct trace_iterator *iter)
656661
trace_seq_printf(
657662
s, "%16s %7d %3d %d %08x %08lx ",
658663
comm, entry->pid, iter->cpu, entry->flags,
659-
entry->preempt_count, iter->idx);
664+
entry->preempt_count & 0xf, iter->idx);
660665
} else {
661666
lat_print_generic(s, entry, iter->cpu);
662667
}

kernel/trace/trace_synth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "trace_dynevent.h"
66

77
#define SYNTH_SYSTEM "synthetic"
8-
#define SYNTH_FIELDS_MAX 32
8+
#define SYNTH_FIELDS_MAX 64
99

1010
#define STR_VAR_LEN_MAX MAX_FILTER_STR_VAL /* must be multiple of sizeof(u64) */
1111

0 commit comments

Comments
 (0)