Skip to content

Commit 91ad64a

Browse files
committed
Merge tag 'trace-v5.6-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing and bootconfig updates: "Fixes and changes to bootconfig before it goes live in a release. Change in API of bootconfig (before it comes live in a release): - Have a magic value "BOOTCONFIG" in initrd to know a bootconfig exists - Set CONFIG_BOOT_CONFIG to 'n' by default - Show error if "bootconfig" on cmdline but not compiled in - Prevent redefining the same value - Have a way to append values - Added a SELECT BLK_DEV_INITRD to fix a build failure Synthetic event fixes: - Switch to raw_smp_processor_id() for recording CPU value in preempt section. (No care for what the value actually is) - Fix samples always recording u64 values - Fix endianess - Check number of values matches number of fields - Fix a printing bug Fix of trace_printk() breaking postponed start up tests Make a function static that is only used in a single file" * tag 'trace-v5.6-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: bootconfig: Fix CONFIG_BOOTTIME_TRACING dependency issue bootconfig: Add append value operator support bootconfig: Prohibit re-defining value on same key bootconfig: Print array as multiple commands for legacy command line bootconfig: Reject subkey and value on same parent key tools/bootconfig: Remove unneeded error message silencer bootconfig: Add bootconfig magic word for indicating bootconfig explicitly bootconfig: Set CONFIG_BOOT_CONFIG=n by default tracing: Clear trace_state when starting trace bootconfig: Mark boot_config_checksum() static tracing: Disable trace_printk() on post poned tests tracing: Have synthetic event test use raw_smp_processor_id() tracing: Fix number printing bug in print_synth_event() tracing: Check that number of vals matches number of synth event fields tracing: Make synth_event trace functions endian-correct tracing: Make sure synth_event_trace() example always uses u64
2 parents b98cce1 + 2910b5a commit 91ad64a

File tree

15 files changed

+272
-92
lines changed

15 files changed

+272
-92
lines changed

Documentation/admin-guide/bootconfig.rst

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ Or more shorter, written as following::
6262
In both styles, same key words are automatically merged when parsing it
6363
at boot time. So you can append similar trees or key-values.
6464

65+
Same-key Values
66+
---------------
67+
68+
It is prohibited that two or more values or arrays share a same-key.
69+
For example,::
70+
71+
foo = bar, baz
72+
foo = qux # !ERROR! we can not re-define same key
73+
74+
If you want to append the value to existing key as an array member,
75+
you can use ``+=`` operator. For example::
76+
77+
foo = bar, baz
78+
foo += qux
79+
80+
In this case, the key ``foo`` has ``bar``, ``baz`` and ``qux``.
81+
82+
However, a sub-key and a value can not co-exist under a parent key.
83+
For example, following config is NOT allowed.::
84+
85+
foo = value1
86+
foo.bar = value2 # !ERROR! subkey "bar" and value "value1" can NOT co-exist
87+
88+
6589
Comments
6690
--------
6791

@@ -102,9 +126,13 @@ Boot Kernel With a Boot Config
102126
==============================
103127

104128
Since the boot configuration file is loaded with initrd, it will be added
105-
to the end of the initrd (initramfs) image file. The Linux kernel decodes
106-
the last part of the initrd image in memory to get the boot configuration
107-
data.
129+
to the end of the initrd (initramfs) image file with size, checksum and
130+
12-byte magic word as below.
131+
132+
[initrd][bootconfig][size(u32)][checksum(u32)][#BOOTCONFIG\n]
133+
134+
The Linux kernel decodes the last part of the initrd image in memory to
135+
get the boot configuration data.
108136
Because of this "piggyback" method, there is no need to change or
109137
update the boot loader and the kernel image itself.
110138

include/linux/bootconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <linux/kernel.h>
1111
#include <linux/types.h>
1212

13+
#define BOOTCONFIG_MAGIC "#BOOTCONFIG\n"
14+
#define BOOTCONFIG_MAGIC_LEN 12
15+
1316
/* XBC tree node */
1417
struct xbc_node {
1518
u16 next;

init/Kconfig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,13 +1226,12 @@ endif
12261226

12271227
config BOOT_CONFIG
12281228
bool "Boot config support"
1229-
depends on BLK_DEV_INITRD
1230-
default y
1229+
select BLK_DEV_INITRD
12311230
help
12321231
Extra boot config allows system admin to pass a config file as
12331232
complemental extension of kernel cmdline when booting.
12341233
The boot config file must be attached at the end of initramfs
1235-
with checksum and size.
1234+
with checksum, size and magic word.
12361235
See <file:Documentation/admin-guide/bootconfig.rst> for details.
12371236

12381237
If unsure, say Y.

init/main.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size,
268268
{
269269
struct xbc_node *knode, *vnode;
270270
char *end = buf + size;
271-
char c = '\"';
272271
const char *val;
273272
int ret;
274273

@@ -279,25 +278,20 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size,
279278
return ret;
280279

281280
vnode = xbc_node_get_child(knode);
282-
ret = snprintf(buf, rest(buf, end), "%s%c", xbc_namebuf,
283-
vnode ? '=' : ' ');
284-
if (ret < 0)
285-
return ret;
286-
buf += ret;
287-
if (!vnode)
281+
if (!vnode) {
282+
ret = snprintf(buf, rest(buf, end), "%s ", xbc_namebuf);
283+
if (ret < 0)
284+
return ret;
285+
buf += ret;
288286
continue;
289-
290-
c = '\"';
287+
}
291288
xbc_array_for_each_value(vnode, val) {
292-
ret = snprintf(buf, rest(buf, end), "%c%s", c, val);
289+
ret = snprintf(buf, rest(buf, end), "%s=\"%s\" ",
290+
xbc_namebuf, val);
293291
if (ret < 0)
294292
return ret;
295293
buf += ret;
296-
c = ',';
297294
}
298-
if (rest(buf, end) > 2)
299-
strcpy(buf, "\" ");
300-
buf += 2;
301295
}
302296

303297
return buf - (end - size);
@@ -335,7 +329,7 @@ static char * __init xbc_make_cmdline(const char *key)
335329
return new_cmdline;
336330
}
337331

338-
u32 boot_config_checksum(unsigned char *p, u32 size)
332+
static u32 boot_config_checksum(unsigned char *p, u32 size)
339333
{
340334
u32 ret = 0;
341335

@@ -374,7 +368,11 @@ static void __init setup_boot_config(const char *cmdline)
374368
if (!initrd_end)
375369
goto not_found;
376370

377-
hdr = (u32 *)(initrd_end - 8);
371+
data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
372+
if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
373+
goto not_found;
374+
375+
hdr = (u32 *)(data - 8);
378376
size = hdr[0];
379377
csum = hdr[1];
380378

@@ -418,6 +416,14 @@ static void __init setup_boot_config(const char *cmdline)
418416
}
419417
#else
420418
#define setup_boot_config(cmdline) do { } while (0)
419+
420+
static int __init warn_bootconfig(char *str)
421+
{
422+
pr_warn("WARNING: 'bootconfig' found on the kernel command line but CONFIG_BOOTCONFIG is not set.\n");
423+
return 0;
424+
}
425+
early_param("bootconfig", warn_bootconfig);
426+
421427
#endif
422428

423429
/* Change NUL term back to "=", to make "param" the whole string. */

kernel/trace/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ if FTRACE
143143

144144
config BOOTTIME_TRACING
145145
bool "Boot-time Tracing support"
146-
depends on BOOT_CONFIG && TRACING
147-
default y
146+
depends on TRACING
147+
select BOOT_CONFIG
148148
help
149149
Enable developer to setup ftrace subsystem via supplemental
150150
kernel cmdline at boot time for debugging (tracing) driver

kernel/trace/synth_event_gen_test.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ static int __init test_gen_synth_cmd(void)
111111
/* Create some bogus values just for testing */
112112

113113
vals[0] = 777; /* next_pid_field */
114-
vals[1] = (u64)"hula hoops"; /* next_comm_field */
114+
vals[1] = (u64)(long)"hula hoops"; /* next_comm_field */
115115
vals[2] = 1000000; /* ts_ns */
116116
vals[3] = 1000; /* ts_ms */
117-
vals[4] = smp_processor_id(); /* cpu */
118-
vals[5] = (u64)"thneed"; /* my_string_field */
117+
vals[4] = raw_smp_processor_id(); /* cpu */
118+
vals[5] = (u64)(long)"thneed"; /* my_string_field */
119119
vals[6] = 598; /* my_int_field */
120120

121121
/* Now generate a gen_synth_test event */
@@ -218,11 +218,11 @@ static int __init test_empty_synth_event(void)
218218
/* Create some bogus values just for testing */
219219

220220
vals[0] = 777; /* next_pid_field */
221-
vals[1] = (u64)"tiddlywinks"; /* next_comm_field */
221+
vals[1] = (u64)(long)"tiddlywinks"; /* next_comm_field */
222222
vals[2] = 1000000; /* ts_ns */
223223
vals[3] = 1000; /* ts_ms */
224-
vals[4] = smp_processor_id(); /* cpu */
225-
vals[5] = (u64)"thneed_2.0"; /* my_string_field */
224+
vals[4] = raw_smp_processor_id(); /* cpu */
225+
vals[5] = (u64)(long)"thneed_2.0"; /* my_string_field */
226226
vals[6] = 399; /* my_int_field */
227227

228228
/* Now trace an empty_synth_test event */
@@ -290,11 +290,11 @@ static int __init test_create_synth_event(void)
290290
/* Create some bogus values just for testing */
291291

292292
vals[0] = 777; /* next_pid_field */
293-
vals[1] = (u64)"tiddlywinks"; /* next_comm_field */
293+
vals[1] = (u64)(long)"tiddlywinks"; /* next_comm_field */
294294
vals[2] = 1000000; /* ts_ns */
295295
vals[3] = 1000; /* ts_ms */
296-
vals[4] = smp_processor_id(); /* cpu */
297-
vals[5] = (u64)"thneed"; /* my_string_field */
296+
vals[4] = raw_smp_processor_id(); /* cpu */
297+
vals[5] = (u64)(long)"thneed"; /* my_string_field */
298298
vals[6] = 398; /* my_int_field */
299299

300300
/* Now generate a create_synth_test event */
@@ -330,7 +330,7 @@ static int __init test_add_next_synth_val(void)
330330
goto out;
331331

332332
/* next_comm_field */
333-
ret = synth_event_add_next_val((u64)"slinky", &trace_state);
333+
ret = synth_event_add_next_val((u64)(long)"slinky", &trace_state);
334334
if (ret)
335335
goto out;
336336

@@ -345,12 +345,12 @@ static int __init test_add_next_synth_val(void)
345345
goto out;
346346

347347
/* cpu */
348-
ret = synth_event_add_next_val(smp_processor_id(), &trace_state);
348+
ret = synth_event_add_next_val(raw_smp_processor_id(), &trace_state);
349349
if (ret)
350350
goto out;
351351

352352
/* my_string_field */
353-
ret = synth_event_add_next_val((u64)"thneed_2.01", &trace_state);
353+
ret = synth_event_add_next_val((u64)(long)"thneed_2.01", &trace_state);
354354
if (ret)
355355
goto out;
356356

@@ -388,20 +388,20 @@ static int __init test_add_synth_val(void)
388388
if (ret)
389389
goto out;
390390

391-
ret = synth_event_add_val("cpu", smp_processor_id(), &trace_state);
391+
ret = synth_event_add_val("cpu", raw_smp_processor_id(), &trace_state);
392392
if (ret)
393393
goto out;
394394

395395
ret = synth_event_add_val("next_pid_field", 777, &trace_state);
396396
if (ret)
397397
goto out;
398398

399-
ret = synth_event_add_val("next_comm_field", (u64)"silly putty",
399+
ret = synth_event_add_val("next_comm_field", (u64)(long)"silly putty",
400400
&trace_state);
401401
if (ret)
402402
goto out;
403403

404-
ret = synth_event_add_val("my_string_field", (u64)"thneed_9",
404+
ret = synth_event_add_val("my_string_field", (u64)(long)"thneed_9",
405405
&trace_state);
406406
if (ret)
407407
goto out;
@@ -423,13 +423,13 @@ static int __init test_trace_synth_event(void)
423423

424424
/* Trace some bogus values just for testing */
425425
ret = synth_event_trace(create_synth_test, 7, /* number of values */
426-
444, /* next_pid_field */
427-
(u64)"clackers", /* next_comm_field */
428-
1000000, /* ts_ns */
429-
1000, /* ts_ms */
430-
smp_processor_id(), /* cpu */
431-
(u64)"Thneed", /* my_string_field */
432-
999); /* my_int_field */
426+
(u64)444, /* next_pid_field */
427+
(u64)(long)"clackers", /* next_comm_field */
428+
(u64)1000000, /* ts_ns */
429+
(u64)1000, /* ts_ms */
430+
(u64)raw_smp_processor_id(), /* cpu */
431+
(u64)(long)"Thneed", /* my_string_field */
432+
(u64)999); /* my_int_field */
433433
return ret;
434434
}
435435

kernel/trace/trace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,7 @@ static __init int init_trace_selftests(void)
18371837

18381838
pr_info("Running postponed tracer tests:\n");
18391839

1840+
tracing_selftest_running = true;
18401841
list_for_each_entry_safe(p, n, &postponed_selftests, list) {
18411842
/* This loop can take minutes when sanitizers are enabled, so
18421843
* lets make sure we allow RCU processing.
@@ -1859,6 +1860,7 @@ static __init int init_trace_selftests(void)
18591860
list_del(&p->list);
18601861
kfree(p);
18611862
}
1863+
tracing_selftest_running = false;
18621864

18631865
out:
18641866
mutex_unlock(&trace_types_lock);

0 commit comments

Comments
 (0)