Skip to content

Commit

Permalink
Merge tag 'trace-v5.6-rc2' of git://git.kernel.org/pub/scm/linux/kern…
Browse files Browse the repository at this point in the history
…el/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
  • Loading branch information
torvalds committed Feb 26, 2020
2 parents b98cce1 + 2910b5a commit 91ad64a
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 92 deletions.
34 changes: 31 additions & 3 deletions Documentation/admin-guide/bootconfig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ Or more shorter, written as following::
In both styles, same key words are automatically merged when parsing it
at boot time. So you can append similar trees or key-values.

Same-key Values
---------------

It is prohibited that two or more values or arrays share a same-key.
For example,::

foo = bar, baz
foo = qux # !ERROR! we can not re-define same key

If you want to append the value to existing key as an array member,
you can use ``+=`` operator. For example::

foo = bar, baz
foo += qux

In this case, the key ``foo`` has ``bar``, ``baz`` and ``qux``.

However, a sub-key and a value can not co-exist under a parent key.
For example, following config is NOT allowed.::

foo = value1
foo.bar = value2 # !ERROR! subkey "bar" and value "value1" can NOT co-exist


Comments
--------

Expand Down Expand Up @@ -102,9 +126,13 @@ Boot Kernel With a Boot Config
==============================

Since the boot configuration file is loaded with initrd, it will be added
to the end of the initrd (initramfs) image file. The Linux kernel decodes
the last part of the initrd image in memory to get the boot configuration
data.
to the end of the initrd (initramfs) image file with size, checksum and
12-byte magic word as below.

[initrd][bootconfig][size(u32)][checksum(u32)][#BOOTCONFIG\n]

The Linux kernel decodes the last part of the initrd image in memory to
get the boot configuration data.
Because of this "piggyback" method, there is no need to change or
update the boot loader and the kernel image itself.

Expand Down
3 changes: 3 additions & 0 deletions include/linux/bootconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <linux/kernel.h>
#include <linux/types.h>

#define BOOTCONFIG_MAGIC "#BOOTCONFIG\n"
#define BOOTCONFIG_MAGIC_LEN 12

/* XBC tree node */
struct xbc_node {
u16 next;
Expand Down
5 changes: 2 additions & 3 deletions init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1226,13 +1226,12 @@ endif

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

If unsure, say Y.
Expand Down
38 changes: 22 additions & 16 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ static int __init xbc_snprint_cmdline(char *buf, size_t size,
{
struct xbc_node *knode, *vnode;
char *end = buf + size;
char c = '\"';
const char *val;
int ret;

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

vnode = xbc_node_get_child(knode);
ret = snprintf(buf, rest(buf, end), "%s%c", xbc_namebuf,
vnode ? '=' : ' ');
if (ret < 0)
return ret;
buf += ret;
if (!vnode)
if (!vnode) {
ret = snprintf(buf, rest(buf, end), "%s ", xbc_namebuf);
if (ret < 0)
return ret;
buf += ret;
continue;

c = '\"';
}
xbc_array_for_each_value(vnode, val) {
ret = snprintf(buf, rest(buf, end), "%c%s", c, val);
ret = snprintf(buf, rest(buf, end), "%s=\"%s\" ",
xbc_namebuf, val);
if (ret < 0)
return ret;
buf += ret;
c = ',';
}
if (rest(buf, end) > 2)
strcpy(buf, "\" ");
buf += 2;
}

return buf - (end - size);
Expand Down Expand Up @@ -335,7 +329,7 @@ static char * __init xbc_make_cmdline(const char *key)
return new_cmdline;
}

u32 boot_config_checksum(unsigned char *p, u32 size)
static u32 boot_config_checksum(unsigned char *p, u32 size)
{
u32 ret = 0;

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

hdr = (u32 *)(initrd_end - 8);
data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
goto not_found;

hdr = (u32 *)(data - 8);
size = hdr[0];
csum = hdr[1];

Expand Down Expand Up @@ -418,6 +416,14 @@ static void __init setup_boot_config(const char *cmdline)
}
#else
#define setup_boot_config(cmdline) do { } while (0)

static int __init warn_bootconfig(char *str)
{
pr_warn("WARNING: 'bootconfig' found on the kernel command line but CONFIG_BOOTCONFIG is not set.\n");
return 0;
}
early_param("bootconfig", warn_bootconfig);

#endif

/* Change NUL term back to "=", to make "param" the whole string. */
Expand Down
4 changes: 2 additions & 2 deletions kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ if FTRACE

config BOOTTIME_TRACING
bool "Boot-time Tracing support"
depends on BOOT_CONFIG && TRACING
default y
depends on TRACING
select BOOT_CONFIG
help
Enable developer to setup ftrace subsystem via supplemental
kernel cmdline at boot time for debugging (tracing) driver
Expand Down
44 changes: 22 additions & 22 deletions kernel/trace/synth_event_gen_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ static int __init test_gen_synth_cmd(void)
/* Create some bogus values just for testing */

vals[0] = 777; /* next_pid_field */
vals[1] = (u64)"hula hoops"; /* next_comm_field */
vals[1] = (u64)(long)"hula hoops"; /* next_comm_field */
vals[2] = 1000000; /* ts_ns */
vals[3] = 1000; /* ts_ms */
vals[4] = smp_processor_id(); /* cpu */
vals[5] = (u64)"thneed"; /* my_string_field */
vals[4] = raw_smp_processor_id(); /* cpu */
vals[5] = (u64)(long)"thneed"; /* my_string_field */
vals[6] = 598; /* my_int_field */

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

vals[0] = 777; /* next_pid_field */
vals[1] = (u64)"tiddlywinks"; /* next_comm_field */
vals[1] = (u64)(long)"tiddlywinks"; /* next_comm_field */
vals[2] = 1000000; /* ts_ns */
vals[3] = 1000; /* ts_ms */
vals[4] = smp_processor_id(); /* cpu */
vals[5] = (u64)"thneed_2.0"; /* my_string_field */
vals[4] = raw_smp_processor_id(); /* cpu */
vals[5] = (u64)(long)"thneed_2.0"; /* my_string_field */
vals[6] = 399; /* my_int_field */

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

vals[0] = 777; /* next_pid_field */
vals[1] = (u64)"tiddlywinks"; /* next_comm_field */
vals[1] = (u64)(long)"tiddlywinks"; /* next_comm_field */
vals[2] = 1000000; /* ts_ns */
vals[3] = 1000; /* ts_ms */
vals[4] = smp_processor_id(); /* cpu */
vals[5] = (u64)"thneed"; /* my_string_field */
vals[4] = raw_smp_processor_id(); /* cpu */
vals[5] = (u64)(long)"thneed"; /* my_string_field */
vals[6] = 398; /* my_int_field */

/* Now generate a create_synth_test event */
Expand Down Expand Up @@ -330,7 +330,7 @@ static int __init test_add_next_synth_val(void)
goto out;

/* next_comm_field */
ret = synth_event_add_next_val((u64)"slinky", &trace_state);
ret = synth_event_add_next_val((u64)(long)"slinky", &trace_state);
if (ret)
goto out;

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

/* cpu */
ret = synth_event_add_next_val(smp_processor_id(), &trace_state);
ret = synth_event_add_next_val(raw_smp_processor_id(), &trace_state);
if (ret)
goto out;

/* my_string_field */
ret = synth_event_add_next_val((u64)"thneed_2.01", &trace_state);
ret = synth_event_add_next_val((u64)(long)"thneed_2.01", &trace_state);
if (ret)
goto out;

Expand Down Expand Up @@ -388,20 +388,20 @@ static int __init test_add_synth_val(void)
if (ret)
goto out;

ret = synth_event_add_val("cpu", smp_processor_id(), &trace_state);
ret = synth_event_add_val("cpu", raw_smp_processor_id(), &trace_state);
if (ret)
goto out;

ret = synth_event_add_val("next_pid_field", 777, &trace_state);
if (ret)
goto out;

ret = synth_event_add_val("next_comm_field", (u64)"silly putty",
ret = synth_event_add_val("next_comm_field", (u64)(long)"silly putty",
&trace_state);
if (ret)
goto out;

ret = synth_event_add_val("my_string_field", (u64)"thneed_9",
ret = synth_event_add_val("my_string_field", (u64)(long)"thneed_9",
&trace_state);
if (ret)
goto out;
Expand All @@ -423,13 +423,13 @@ static int __init test_trace_synth_event(void)

/* Trace some bogus values just for testing */
ret = synth_event_trace(create_synth_test, 7, /* number of values */
444, /* next_pid_field */
(u64)"clackers", /* next_comm_field */
1000000, /* ts_ns */
1000, /* ts_ms */
smp_processor_id(), /* cpu */
(u64)"Thneed", /* my_string_field */
999); /* my_int_field */
(u64)444, /* next_pid_field */
(u64)(long)"clackers", /* next_comm_field */
(u64)1000000, /* ts_ns */
(u64)1000, /* ts_ms */
(u64)raw_smp_processor_id(), /* cpu */
(u64)(long)"Thneed", /* my_string_field */
(u64)999); /* my_int_field */
return ret;
}

Expand Down
2 changes: 2 additions & 0 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,7 @@ static __init int init_trace_selftests(void)

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

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

out:
mutex_unlock(&trace_types_lock);
Expand Down
Loading

0 comments on commit 91ad64a

Please sign in to comment.