tracing: bootconfig: Boot-time tracing and Extra boot config
Subsystems (6)
Masami Hiramatsu
maintainerv6 cover tracing: bootconfig: Boot-time tracing and Extra boot config
Hello,
This is the 6th version of the series for the boot-time tracing.
Previous version is here.
https://lkml.kernel.org/r/157736902773.11126.2531161235817081873.stgit@devnote2
Thanks Steve for reivew. I fixed issues in this version.
- [1/22] Remove "!!" from xbc_node_is_value(). Redefine xbc_node_is_key() as "!xbc_node_is_value()". Fix a memory leak and a bug in __xbc_parse_value(). Add xbc_destroy_all() to clean up the parsed data. Fix to treat comment right after value as a newline.
- [3/22] Fix memory leaks.
Fix to cleanup old bootconfig on memory before load new one. Show applying message.
Suppress parse error with wrong data in initrd for delete_xbc().
- [4/22] Add some testcases for value parser
Add a test case for checking delete old bootconfig
- [9/22] Add a note about comment after value.
- [21/22] Fix to depend on CONFIG_DYNAMIC_FTRACE instead of CONFIG_FUNCTION_TRACER.
This series can be applied on v5.5-rc5 or directly available at;
https://github.com/mhiramat/linux.git ftrace-boottrace-v6
Extra Boot Config
=================
Extra boot config allows admin to pass a tree-structured key-value list when booting up the kernel. This expands the kernel command line in an efficient way.
Each key is described as a dot-jointed-words. And user can write the key-words in tree stlye. (In this version, the tailing ';' becomes optional. See Documentation/admin-guide/bootconfig.rst)
For example,
feature.option.foo = 1
feature.option.bar = 2
can be also written in
feature.option {
foo = 1
bar = 2}
or more compact,
feature.option{foo=1;bar=2}
(Note that in both style, the same words are merged automatically
and make a single tree)
All values are treated as a string, or array of strings, e.g.
feature.options = "foo", "bar"
User can see the loaded key-value list via /proc/bootconfig. The size is limited upto 32KB and 1024 key-words and values in total.
Boot with a Boot Config
=======================
This version doesn't require to modify boot loaders anymore. The boot config is loaded with initrd, and there is new "bootconfig" command under tools/bootconfig.
To add (append) a bootconfig file to an initrd, you can use the bootconfig command like:
# tools/bootconfig/bootconfig -a your-config /boot/initrd.img-X.Y.Z
This verifies the configuration file too.
Boot-time Tracing
=================
Boot-time tracing supports following boot configs. Please read Documentation/trace/boottime-trace.rst for details.
- kernel.dump_on_oops [= MODE]
- kernel.traceoff_on_warning
- kernel.tp_printk
- kernel.fgraph_filters = FILTER[, FILTER2...]
- kernel.fgraph_notraces = FILTER[, FILTER2...]
- kernel.fgraph_max_depth = MAX_DEPTH
- ftrace.[instance.INSTANCE.]options = OPT1[,OPT2...]
- ftrace.[instance.INSTANCE.]trace_clock = CLOCK
- ftrace.[instance.INSTANCE.]buffer_size = SIZE
- ftrace.[instance.INSTANCE.]alloc_snapshot
- ftrace.[instance.INSTANCE.]cpumask = CPUMASK
- ftrace.[instance.INSTANCE.]events = EVENT[, EVENT2...]
- ftrace.[instance.INSTANCE.]tracer = TRACER
- ftrace.[instance.INSTANCE.]ftrace.filters
- ftrace.[instance.INSTANCE.]ftrace.notraces
- ftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER
- ftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2...]
- ftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable
- ftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2...]
- ftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2...]
Kernel and Init Command Line
============================
Boot config also supports kernel and init command line parameters except for early kernel parameters.
In boot config, all key-values start with "kernel." are automatically merged into user passed boot command line, and key-values which start with "init." are also passed to init. These options are visible on /proc/cmdline.
For example,
kernel {
audit = on
audit_backlog_limit = 256
}
init.systemd.unified_cgroup_hierarchy = 1
Usage
=====
With this series, we can setup new kprobe and synthetic events, more complicated event filters and trigger actions including histogram via supplemental kernel cmdline.
We can add filter and actions for each event, define kprobe events, and synthetic events with histogram like below.
ftrace.event {
task.task_newtask {
filter = "pid < 128"
enable
}
kprobes.vfs_read {
probes = "vfs_read $arg1 $arg2"
filter = "common_pid < 200"
enable
}
synthetic.initcall_latency {
fields = "unsigned long func", "u64 lat"
actions = "hist:keys=func.sym,lat:vals=lat:sort=lat"
}
initcall.initcall_start {
actions = "hist:keys=func:ts0=common_timestamp.usecs"
}
initcall.initcall_finish {
actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)"
}
}Also, this supports "instance" node, which allows us to run several tracers for different purpose at once. For example, one tracer is for tracing functions start with "user_", and others tracing "kernel_", you can write boot config as:
ftrace.instance {
foo {
tracer = "function"
ftrace-filters = "user_*"
}
bar {
tracer = "function"
ftrace-filters = "function_*"
}
}The instance node also accepts event nodes so that each instance can customize its event tracing.
This boot-time trace also supports ftrace kernel parameters. For example, following kernel parameters
trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M ftrace=function ftrace_filter="vfs*"
it can be written in boot config like below.
ftrace {
options = sym-addr
events = "initcall:*"
tp-printk
buffer-size = 1MB
ftrace-filters = "vfs*"
}
However, since the initialization timing is different, if you need to trace very early boot, please use normal kernel parameters.
Some Notes
==========
- To align the legacy command line rule, I made the quotes (double quotes or single quotes) not able to be escaped.
Also, this rejects non-printable chars (except for space). Actually legacy cmdline accepts any of them, but it might confuse users if they put a control code by mistake. Imagine that they put a "\b" on it...
- Since it is not easy to write boot-time tracing without any bug in bootconfig, a user-helper command will be needed. That command will generate a boot config file from current ftrace settings, or try to apply given boot config setting to the ftrace.
Thank you,
---
Masami Hiramatsu (22):
bootconfig: Add Extra Boot Config support
bootconfig: Load boot config from the tail of initrd
tools: bootconfig: Add bootconfig command
tools: bootconfig: Add bootconfig test script
proc: bootconfig: Add /proc/bootconfig to show boot config list init/main.c: Alloc initcall_command_line in do_initcall() and free it
bootconfig: init: Allow admin to use bootconfig for kernel command line
bootconfig: init: Allow admin to use bootconfig for init command line
Documentation: bootconfig: Add a doc for extended boot config
tracing: Apply soft-disabled and filter to tracepoints printk
tracing: kprobes: Output kprobe event to printk buffer
tracing: kprobes: Register to dynevent earlier stage
tracing: Accept different type for synthetic event fields
tracing: Add NULL trace-array check in print_synth_event() tracing/boot: Add boot-time tracing
tracing/boot: Add per-event settings
tracing/boot Add kprobe event support
tracing/boot: Add synthetic event support
tracing/boot: Add instance node support
tracing/boot: Add cpu_mask option support
tracing/boot: Add function tracer filter options
Documentation: tracing: Add boot-time tracing document
Documentation/admin-guide/bootconfig.rst | 186 +++++ Documentation/admin-guide/index.rst | 1 Documentation/trace/boottime-trace.rst | 184 +++++ Documentation/trace/index.rst | 1 MAINTAINERS | 9 fs/proc/Makefile | 1 fs/proc/bootconfig.c | 89 ++ include/linux/bootconfig.h | 224 ++++++ include/linux/trace_events.h | 1 init/Kconfig | 12 init/main.c | 213 +++++ kernel/trace/Kconfig | 9 kernel/trace/Makefile | 1 kernel/trace/trace.c | 63 +- kernel/trace/trace_boot.c | 353 +++++++++ kernel/trace/trace_events.c | 1 kernel/trace/trace_events_hist.c | 14 kernel/trace/trace_events_trigger.c | 2 kernel/trace/trace_kprobe.c | 81 +- lib/Kconfig | 3 lib/Makefile | 2 lib/bootconfig.c | 803 ++++++++++++++++++++ tools/Makefile | 11 tools/bootconfig/.gitignore | 1 tools/bootconfig/Makefile | 23 + tools/bootconfig/include/linux/bootconfig.h | 7 tools/bootconfig/include/linux/bug.h | 12 tools/bootconfig/include/linux/ctype.h | 7 tools/bootconfig/include/linux/errno.h | 7 tools/bootconfig/include/linux/kernel.h | 18 tools/bootconfig/include/linux/printk.h | 17 tools/bootconfig/include/linux/string.h | 32 + tools/bootconfig/main.c | 354 +++++++++ .../samples/bad-array-space-comment.bconf | 5 tools/bootconfig/samples/bad-array.bconf | 2 tools/bootconfig/samples/bad-dotword.bconf | 4 tools/bootconfig/samples/bad-empty.bconf | 1 tools/bootconfig/samples/bad-keyerror.bconf | 2 tools/bootconfig/samples/bad-longkey.bconf | 1 tools/bootconfig/samples/bad-manywords.bconf | 1 tools/bootconfig/samples/bad-no-keyword.bconf | 2 tools/bootconfig/samples/bad-nonprintable.bconf | 2 tools/bootconfig/samples/bad-spaceword.bconf | 2 tools/bootconfig/samples/bad-tree.bconf | 5 tools/bootconfig/samples/bad-value.bconf | 3 tools/bootconfig/samples/escaped.bconf | 3 .../samples/good-array-space-comment.bconf | 4 .../samples/good-comment-after-value.bconf | 1 tools/bootconfig/samples/good-printables.bconf | 2 tools/bootconfig/samples/good-simple.bconf | 11 tools/bootconfig/samples/good-single.bconf | 4 .../samples/good-space-after-value.bconf | 1 tools/bootconfig/samples/good-tree.bconf | 12 tools/bootconfig/test-bootconfig.sh | 105 +++ 54 files changed, 2836 insertions(+), 79 deletions(-) create mode 100644 Documentation/admin-guide/bootconfig.rst create mode 100644 Documentation/trace/boottime-trace.rst create mode 100644 fs/proc/bootconfig.c create mode 100644 include/linux/bootconfig.h create mode 100644 kernel/trace/trace_boot.c create mode 100644 lib/bootconfig.c create mode 100644 tools/bootconfig/.gitignore create mode 100644 tools/bootconfig/Makefile create mode 100644 tools/bootconfig/include/linux/bootconfig.h create mode 100644 tools/bootconfig/include/linux/bug.h create mode 100644 tools/bootconfig/include/linux/ctype.h create mode 100644 tools/bootconfig/include/linux/errno.h create mode 100644 tools/bootconfig/include/linux/kernel.h create mode 100644 tools/bootconfig/include/linux/printk.h create mode 100644 tools/bootconfig/include/linux/string.h create mode 100644 tools/bootconfig/main.c create mode 100644 tools/bootconfig/samples/bad-array-space-comment.bconf create mode 100644 tools/bootconfig/samples/bad-array.bconf create mode 100644 tools/bootconfig/samples/bad-dotword.bconf create mode 100644 tools/bootconfig/samples/bad-empty.bconf create mode 100644 tools/bootconfig/samples/bad-keyerror.bconf create mode 100644 tools/bootconfig/samples/bad-longkey.bconf create mode 100644 tools/bootconfig/samples/bad-manywords.bconf create mode 100644 tools/bootconfig/samples/bad-no-keyword.bconf create mode 100644 tools/bootconfig/samples/bad-nonprintable.bconf create mode 100644 tools/bootconfig/samples/bad-spaceword.bconf create mode 100644 tools/bootconfig/samples/bad-tree.bconf create mode 100644 tools/bootconfig/samples/bad-value.bconf create mode 100644 tools/bootconfig/samples/escaped.bconf create mode 100644 tools/bootconfig/samples/good-array-space-comment.bconf create mode 100644 tools/bootconfig/samples/good-comment-after-value.bconf create mode 100644 tools/bootconfig/samples/good-printables.bconf create mode 100644 tools/bootconfig/samples/good-simple.bconf create mode 100644 tools/bootconfig/samples/good-single.bconf create mode 100644 tools/bootconfig/samples/good-space-after-value.bconf create mode 100644 tools/bootconfig/samples/good-tree.bconf create mode 100755 tools/bootconfig/test-bootconfig.sh
--
Masami Hiramatsu (Linaro) <[email protected]>
Masami Hiramatsu
maintainerPATCH v6 1/22 bootconfig: Add Extra Boot Config support
Extra Boot Config (XBC) allows admin to pass a tree-structured boot configuration file when boot up the kernel. This extends the kernel command line in an efficient way.
Boot config will contain some key-value commands, e.g.
key.word = value1
another.key.word = value2
It can fold same keys with braces, also you can write array data. For example,
key {
word1 {
setting1 = data
setting2
}
word2.array = "val1", "val2"
}
User can access these key-value pair and tree structure via SKC APIs.
---
Changes in v6:
- Remove "!!" from xbc_node_is_value().
- Redefine xbc_node_is_key() as "!xbc_node_is_value()".
- Fix a memory leak and a bug in __xbc_parse_value() (Thanks Steve!).
- Add xbc_destroy_all() to clean up the parsed data.
- Fix to treat comment right after value as a newline.
Changes in v5:
- Fix help comment and indent (Thanks Randy!)
- Restrict available characters in values (only printables and spaces.)
- Drop "escape" backslash support.
Changes in v4:
- Rename suppremental kernel command line to extended boot. config so that easy to understand what it is.
- Clean up given data if failed to parse it.
- Add comment support (start with #)
- Return -ENOENT if given data has no node.
- Ensure the key max depth and keylen are under limitation.
- Add single quotes support.
- Allow newline and closing brace to terminate key-value.
- Add xbc_node_compose_key_after().
- Move kconfig to generic setup.
- Expand the max number of node to 1024.
--- MAINTAINERS | 6 include/linux/bootconfig.h | 224 ++++++++++++ init/Kconfig | 11 + lib/Kconfig | 3 lib/Makefile | 2 lib/bootconfig.c | 803 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1049 insertions(+) create mode 100644 include/linux/bootconfig.h create mode 100644 lib/bootconfig.c
MAINTAINERS +6 -0
@@ -15773,6 +15773,12 @@ W: http://www.stlinux.com S: Supported F: drivers/net/ethernet/stmicro/stmmac/ +EXTRA BOOT CONFIG +M: Masami Hiramatsu <[email protected]> +S: Maintained +F: lib/bootconfig.c +F: include/linux/bootconfig.h + SUN3/3X M: Sam Creasey <[email protected]> W: http://sammy.net/sun3/
include/linux/bootconfig.h new file +224 -0
224 lines not on this page · raw message
init/Kconfig +11 -0
@@ -1215,6 +1215,17 @@ source "usr/Kconfig" endif +config BOOT_CONFIG + bool "Boot config support" + select LIBXBC + default y + help + Extra boot config allows system admin to pass a config file as + complemental extension of kernel cmdline when booting. + The boot config file is usually attached at the end of initramfs. + + If unsure, say Y. + choice prompt "Compiler optimization level" default CC_OPTIMIZE_FOR_PERFORMANCE
lib/Kconfig +3 -0
@@ -566,6 +566,9 @@ config DIMLIB config LIBFDT bool +config LIBXBC + bool + config OID_REGISTRY tristate help
lib/Makefile +2 -0
@@ -228,6 +228,8 @@ $(foreach file, $(libfdt_files), \ $(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt)) lib-$(CONFIG_LIBFDT) += $(libfdt_files) +lib-$(CONFIG_LIBXBC) += bootconfig.o + obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o
lib/bootconfig.c new file +803 -0
803 lines not on this page · raw message
Masami Hiramatsu
maintainerPATCH v6 2/22 bootconfig: Load boot config from the tail of initrd
In reply to Masami HiramatsuLoad the extended boot config data from the tail of initrd image. If there is an SKC data there, it has [(u32)size][(u32)checksum] header (in really, this is a footer) at the end of initrd. If the checksum (simple sum of bytes) is match, this starts parsing it from there.
---
Changes in v4:
- Rename skc to bootconfig.
--- init/Kconfig | 1 + init/main.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
init/Kconfig +1 -0
@@ -1217,6 +1217,7 @@ endif config BOOT_CONFIG bool "Boot config support" + depends on BLK_DEV_INITRD select LIBXBC default y help
init/main.c +54 -0
72 lines not on this page · raw message
Masami Hiramatsu
maintainerPATCH v6 3/22 tools: bootconfig: Add bootconfig command
In reply to Masami HiramatsuAdd "bootconfig" command which operates the bootconfig config-data on initrd image.
User can add/delete/verify the boot config on initrd image using this command.
e.g.
Add a boot config to initrd image
# bootconfig -a myboot.conf /boot/initrd.img
Remove it.
# bootconfig -d /boot/initrd.img
Or verify (and show) it.
# bootconfig /boot/initrd.img
---
Changes in v6:
- Fix memory leaks.
- Fix to cleanup old bootconfig on memory before load new one.
- Show applying message.
- Suppress parse error with wrong data in initrd for delete_xbc().
Changes in v5:
- Fix Makefile to compile all C files always.
- Remove unused pattern from Makefile.
--- MAINTAINERS | 1 tools/Makefile | 11 - tools/bootconfig/.gitignore | 1 tools/bootconfig/Makefile | 20 ++ tools/bootconfig/include/linux/bootconfig.h | 7 + tools/bootconfig/include/linux/bug.h | 12 + tools/bootconfig/include/linux/ctype.h | 7 + tools/bootconfig/include/linux/errno.h | 7 + tools/bootconfig/include/linux/kernel.h | 18 + tools/bootconfig/include/linux/printk.h | 17 + tools/bootconfig/include/linux/string.h | 32 ++ tools/bootconfig/main.c | 354 +++++++++++++++++++++++++++ 12 files changed, 482 insertions(+), 5 deletions(-) create mode 100644 tools/bootconfig/.gitignore create mode 100644 tools/bootconfig/Makefile create mode 100644 tools/bootconfig/include/linux/bootconfig.h create mode 100644 tools/bootconfig/include/linux/bug.h create mode 100644 tools/bootconfig/include/linux/ctype.h create mode 100644 tools/bootconfig/include/linux/errno.h create mode 100644 tools/bootconfig/include/linux/kernel.h create mode 100644 tools/bootconfig/include/linux/printk.h create mode 100644 tools/bootconfig/include/linux/string.h create mode 100644 tools/bootconfig/main.c
MAINTAINERS +1 -0
@@ -15778,6 +15778,7 @@ M: Masami Hiramatsu <[email protected]> S: Maintained F: lib/bootconfig.c F: include/linux/bootconfig.h +F: tools/bootconfig/* SUN3/3X M: Sam Creasey <[email protected]>
tools/Makefile +6 -5
@@ -28,6 +28,7 @@ help: @echo ' pci - PCI tools' @echo ' perf - Linux performance measurement and analysis tool' @echo ' selftests - various kernel selftests' + @echo ' bootconfig - boot config tool' @echo ' spi - spi tools' @echo ' tmon - thermal monitoring and tuning tool' @echo ' turbostat - Intel CPU idle stats and freq reporting tool'
@@ -63,7 +64,7 @@ acpi: FORCE cpupower: FORCE $(call descend,power/$@) -cgroup firewire hv guest spi usb virtio vm bpf iio gpio objtool leds wmi pci firmware debugging: FORCE +cgroup firewire hv guest bootconfig spi usb virtio vm bpf iio gpio objtool leds wmi pci firmware debugging: FORCE $(call descend,$@) liblockdep: FORCE
@@ -96,7 +97,7 @@ kvm_stat: FORCE $(call descend,kvm/$@) all: acpi cgroup cpupower gpio hv firewire liblockdep \ - perf selftests spi turbostat usb \ + perf selftests bootconfig spi turbostat usb \ virtio vm bpf x86_energy_perf_policy \ tmon freefall iio objtool kvm_stat wmi \ pci debugging
@@ -107,7 +108,7 @@ acpi_install: cpupower_install: $(call descend,power/$(@:_install=),install) -cgroup_install firewire_install gpio_install hv_install iio_install perf_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install debugging_install: +cgroup_install firewire_install gpio_install hv_install iio_install perf_install bootconfig_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install debugging_install: $(call descend,$(@:_install=),install) liblockdep_install:
@@ -141,7 +142,7 @@ acpi_clean: cpupower_clean: $(call descend,power/cpupower,clean) -cgroup_clean hv_clean firewire_clean spi_clean usb_clean virtio_clean vm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean pci_clean firmware_clean debugging_clean: +cgroup_clean hv_clean firewire_clean bootconfig_clean spi_clean usb_clean virtio_clean vm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean pci_clean firmware_clean debugging_clean: $(call descend,$(@:_clean=),clean) liblockdep_clean:
@@ -176,7 +177,7 @@ build_clean: $(call descend,build,clean) clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean \ - perf_clean selftests_clean turbostat_clean spi_clean usb_clean virtio_clean \ + perf_clean selftests_clean turbostat_clean bootconfig_clean spi_clean usb_clean virtio_clean \ vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ freefall_clean build_clean libbpf_clean libsubcmd_clean liblockdep_clean \ gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \
tools/bootconfig/.gitignore new file +1 -0
@@ -0,0 +1 @@ +bootconfig
tools/bootconfig/Makefile new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for bootconfig command + +bindir ?= /usr/bin + +HEADER = include/linux/bootconfig.h +CFLAGS = -Wall -g -I./include + +PROGS = bootconfig + +all: $(PROGS) + +bootconfig: ../../lib/bootconfig.c main.c $(HEADER) + $(CC) $(filter %.c,$^) $(CFLAGS) -o $@ + +install: $(PROGS) + install bootconfig $(DESTDIR)$(bindir) + +clean: + $(RM) -f *.o bootconfig
tools/bootconfig/include/linux/bootconfig.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BOOTCONFIG_LINUX_BOOTCONFIG_H +#define _BOOTCONFIG_LINUX_BOOTCONFIG_H + +#include "../../../../include/linux/bootconfig.h" + +#endif
tools/bootconfig/include/linux/bug.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SKC_LINUX_BUG_H +#define _SKC_LINUX_BUG_H + +#include <stdio.h> +#include <stdlib.h> + +#define WARN_ON (cond) \ + ((cond) ? printf("Internal warning(%s:%d, %s): %s\n", \ + __FILE__, __LINE__, __func__, #cond) : 0) + +#endif
tools/bootconfig/include/linux/ctype.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SKC_LINUX_CTYPE_H +#define _SKC_LINUX_CTYPE_H + +#include <ctype.h> + +#endif
tools/bootconfig/include/linux/errno.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SKC_LINUX_ERRNO_H +#define _SKC_LINUX_ERRNO_H + +#include <asm/errno.h> + +#endif
tools/bootconfig/include/linux/kernel.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SKC_LINUX_KERNEL_H +#define _SKC_LINUX_KERNEL_H + +#include <stdlib.h> +#include <stdbool.h> + +#include <linux/printk.h> + +typedef unsigned short u16 ; +typedef unsigned int u32 ; + +#define unlikely (cond) (cond) + +#define __init +#define __initdata + +#endif
tools/bootconfig/include/linux/printk.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SKC_LINUX_PRINTK_H +#define _SKC_LINUX_PRINTK_H + +#include <stdio.h> + +/* controllable printf */ +extern int pr_output; +#define printk (fmt, ...) \ + (pr_output ? printf(fmt, __VA_ARGS__) : 0) + +#define pr_err printk +#define pr_warn printk +#define pr_info printk +#define pr_debug printk + +#endif
tools/bootconfig/include/linux/string.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SKC_LINUX_STRING_H +#define _SKC_LINUX_STRING_H + +#include <string.h> + +/* Copied from lib/string.c */ +static inline char *skip_spaces (const char *str) +{ +while (isspace (*str)) + ++str; +return (char *)str; +} + +static inline char *strim (char *s) +{ +size_t size; +char *end; + + size =strlen (s); +if (!size) +return s; + + end = s + size -1 ; +while (end >= s &&isspace (*end)) + end--; + *(end +1 ) ='\0' ; + +return skip_spaces (s); +} + +#endif
tools/bootconfig/main.c new file +354 -0
354 lines not on this page · raw message
Masami Hiramatsu
maintainerPATCH v6 4/22 tools: bootconfig: Add bootconfig test script
In reply to Masami HiramatsuAdd a bootconfig test script to ensure the tool and boot config parser are working correctly.
---
Changes in v6:
- Add some testcases for value parser
- Add a test case for checking delete old bootconfig
Changes in v5:
- Show test target bootconfig name
- Add printables testcases
- Add bad array testcase
--- tools/bootconfig/Makefile | 3 + .../samples/bad-array-space-comment.bconf | 5 + tools/bootconfig/samples/bad-array.bconf | 2 tools/bootconfig/samples/bad-dotword.bconf | 4 + tools/bootconfig/samples/bad-empty.bconf | 1 tools/bootconfig/samples/bad-keyerror.bconf | 2 tools/bootconfig/samples/bad-longkey.bconf | 1 tools/bootconfig/samples/bad-manywords.bconf | 1 tools/bootconfig/samples/bad-no-keyword.bconf | 2 tools/bootconfig/samples/bad-nonprintable.bconf | 2 tools/bootconfig/samples/bad-spaceword.bconf | 2 tools/bootconfig/samples/bad-tree.bconf | 5 + tools/bootconfig/samples/bad-value.bconf | 3 + tools/bootconfig/samples/escaped.bconf | 3 + .../samples/good-array-space-comment.bconf | 4 + .../samples/good-comment-after-value.bconf | 1 tools/bootconfig/samples/good-printables.bconf | 2 tools/bootconfig/samples/good-simple.bconf | 11 ++ tools/bootconfig/samples/good-single.bconf | 4 + .../samples/good-space-after-value.bconf | 1 tools/bootconfig/samples/good-tree.bconf | 12 ++ tools/bootconfig/test-bootconfig.sh | 105 ++++++++++++++++++++ 22 files changed, 176 insertions(+) create mode 100644 tools/bootconfig/samples/bad-array-space-comment.bconf create mode 100644 tools/bootconfig/samples/bad-array.bconf create mode 100644 tools/bootconfig/samples/bad-dotword.bconf create mode 100644 tools/bootconfig/samples/bad-empty.bconf create mode 100644 tools/bootconfig/samples/bad-keyerror.bconf create mode 100644 tools/bootconfig/samples/bad-longkey.bconf create mode 100644 tools/bootconfig/samples/bad-manywords.bconf create mode 100644 tools/bootconfig/samples/bad-no-keyword.bconf create mode 100644 tools/bootconfig/samples/bad-nonprintable.bconf create mode 100644 tools/bootconfig/samples/bad-spaceword.bconf create mode 100644 tools/bootconfig/samples/bad-tree.bconf create mode 100644 tools/bootconfig/samples/bad-value.bconf create mode 100644 tools/bootconfig/samples/escaped.bconf create mode 100644 tools/bootconfig/samples/good-array-space-comment.bconf create mode 100644 tools/bootconfig/samples/good-comment-after-value.bconf create mode 100644 tools/bootconfig/samples/good-printables.bconf create mode 100644 tools/bootconfig/samples/good-simple.bconf create mode 100644 tools/bootconfig/samples/good-single.bconf create mode 100644 tools/bootconfig/samples/good-space-after-value.bconf create mode 100644 tools/bootconfig/samples/good-tree.bconf create mode 100755 tools/bootconfig/test-bootconfig.sh
tools/bootconfig/Makefile +3 -0
@@ -16,5 +16,8 @@ bootconfig: ../../lib/bootconfig.c main.c $(HEADER) install: $(PROGS) install bootconfig $(DESTDIR)$(bindir) +test: bootconfig + ./test-bootconfig.sh + clean: $(RM) -f *.o bootconfig
tools/bootconfig/samples/bad-array-space-comment.bconf new file +5 -0
@@ -0,0 +1,5 @@ +key = # comment + "value1", # comment1 + "value2" # comment2 +, + "value3"
tools/bootconfig/samples/bad-array.bconf new file +2 -0
@@ -0,0 +1,2 @@ +# Array must be comma separated. +key = "value1" "value2"
tools/bootconfig/samples/bad-dotword.bconf new file +4 -0
@@ -0,0 +1,4 @@ +# do not start keyword with . +key { + .word = 1 +}
tools/bootconfig/samples/bad-empty.bconf new file +1 -0
@@ -0,0 +1 @@ +# Wrong boot config: comment only
tools/bootconfig/samples/bad-keyerror.bconf new file +2 -0
@@ -0,0 +1,2 @@ +# key word can not contain "," +key,word
tools/bootconfig/samples/bad-longkey.bconf new file +1 -0
@@ -0,0 +1 @@ +key_word_is_too_long01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
tools/bootconfig/samples/bad-manywords.bconf new file +1 -0
@@ -0,0 +1 @@ +key1.is2.too3.long4.5.6.7.8.9.10.11.12.13.14.15.16.17
tools/bootconfig/samples/bad-no-keyword.bconf new file +2 -0
@@ -0,0 +1,2 @@ +# No keyword +{}
tools/bootconfig/samples/bad-nonprintable.bconf new file +2 -0
@@ -0,0 +1,2 @@ +# Non printable +key = ""
tools/bootconfig/samples/bad-spaceword.bconf new file +2 -0
@@ -0,0 +1,2 @@ +# No space between words +key . word
tools/bootconfig/samples/bad-tree.bconf new file +5 -0
@@ -0,0 +1,5 @@ +# brace is not closing +tree { + node { + value = 1 +}
tools/bootconfig/samples/bad-value.bconf new file +3 -0
@@ -0,0 +1,3 @@ +# Quotes error +value = "data +
tools/bootconfig/samples/escaped.bconf new file +3 -0
@@ -0,0 +1,3 @@ +key1 = "A\B\C" +key2 = '\'\'' +key3 = "\\"
tools/bootconfig/samples/good-array-space-comment.bconf new file +4 -0
@@ -0,0 +1,4 @@ +key = # comment + "value1", # comment1 + "value2" , # comment2 + "value3"
tools/bootconfig/samples/good-comment-after-value.bconf new file +1 -0
@@ -0,0 +1 @@ +key = "value" # comment
tools/bootconfig/samples/good-printables.bconf new file +2 -0
@@ -0,0 +1,2 @@ +key = " + !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
tools/bootconfig/samples/good-simple.bconf new file +11 -0
@@ -0,0 +1,11 @@ +# A good simple bootconfig + +key.word1 = 1 +key.word2=2 +key.word3 = 3; + +key { +word4 = 4 } + +key { word5 = 5; word6 = 6 } +
tools/bootconfig/samples/good-single.bconf new file +4 -0
@@ -0,0 +1,4 @@ +# single key style +key = 1 +key2 = 2 +key3 = "alpha", "beta"
tools/bootconfig/samples/good-space-after-value.bconf new file +1 -0
@@ -0,0 +1 @@ +key = "value"
tools/bootconfig/samples/good-tree.bconf new file +12 -0
@@ -0,0 +1,12 @@ +key { + word { + tree { + value = "0"} + } + word2 { + tree { + value = 1,2 } + } +} +other.tree { + value = 2; value2 = 3;}
tools/bootconfig/test-bootconfig.sh new file +105 -0
105 lines not on this page · raw message
Masami Hiramatsu
maintainerPATCH v6 5/22 proc: bootconfig: Add /proc/bootconfig to show boot config list
In reply to Masami HiramatsuAdd /proc/bootconfig which shows the list of key-value pairs in boot config. Since after boot, all boot configs and tree are removed, this interface just keep a copy of key-value pairs in text.
---
Changes in v4:
- Remove ; in the end of lines.
- Rename /proc/supp_cmdline to /proc/bootconfig
- Simplify code.
--- MAINTAINERS | 1 + fs/proc/Makefile | 1 + fs/proc/bootconfig.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 fs/proc/bootconfig.c
MAINTAINERS +1 -0
@@ -15777,6 +15777,7 @@ EXTRA BOOT CONFIG M: Masami Hiramatsu <[email protected]> S: Maintained F: lib/bootconfig.c +F: fs/proc/bootconfig.c F: include/linux/bootconfig.h F: tools/bootconfig/*
fs/proc/Makefile +1 -0
@@ -33,3 +33,4 @@ proc-$(CONFIG_PROC_KCORE) += kcore.o proc-$(CONFIG_PROC_VMCORE) += vmcore.o proc-$(CONFIG_PRINTK) += kmsg.o proc-$(CONFIG_PROC_PAGE_MONITOR) += page.o +proc-$(CONFIG_BOOT_CONFIG) += bootconfig.o
fs/proc/bootconfig.c new file +89 -0
89 lines not on this page · raw message
Masami Hiramatsu
maintainerPATCH v6 6/22 init/main.c: Alloc initcall_command_line in do_initcall() and free it
In reply to Masami HiramatsuSince initcall_command_line is used as a temporary buffer, it could be freed after usage. Allocate it in do_initcall() and free it after used.
--- init/main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
init/main.c +15 -11
@@ -137,8 +137,6 @@ char __initdata boot_command_line[COMMAND_LINE_SIZE];char *saved_command_line;/* Command line for parameter parsing */ static char *static_command_line; -/* Command line for per-initcall parameter parsing */ -static char *initcall_command_line;static char *execute_command;static char *ramdisk_execute_command;
@@ -433,10 +431,6 @@ static void __init setup_command_line(char *command_line)if (!saved_command_line)panic ("%s: Failed to allocate %zu bytes\n" , __func__, len); - initcall_command_line =memblock_alloc (len,SMP_CACHE_BYTES ); -if (!initcall_command_line) -panic ("%s: Failed to allocate %zu bytes\n" , __func__, len); - static_command_line =memblock_alloc (len,SMP_CACHE_BYTES );if (!static_command_line)panic ("%s: Failed to allocate %zu bytes\n" , __func__, len);
@@ -1044,13 +1038,12 @@ static const char *initcall_level_names[] __initdata = { "late", }; -static void __init do_initcall_level (int level) +static void __init do_initcall_level (int level,char *command_line) {initcall_entry_t *fn; -strcpy (initcall_command_line, saved_command_line);parse_args (initcall_level_names[level], - initcall_command_line, __start___param, + command_line, __start___param, __stop___param - __start___param, level, level,NULL , &repair_env_string);
@@ -1063,9 +1056,20 @@ static void __init do_initcall_level(int level)static void __init do_initcalls (void ) {int level; +size_t len =strlen (saved_command_line) +1 ; +char *command_line; + + command_line =kzalloc (len,GFP_KERNEL ); +if (!command_line) +panic ("%s: Failed to allocate %zu bytes\n" , __func__, len); + +for (level =0 ; level <ARRAY_SIZE (initcall_levels) -1 ; level++) { +/* Parser modifies command_line, restore it each time */ +strcpy (command_line, saved_command_line); +do_initcall_level (level, command_line); + } -for (level =0 ; level <ARRAY_SIZE (initcall_levels) -1 ; level++) -do_initcall_level (level); +kfree (command_line); }/*
Masami Hiramatsu
maintainerPATCH v6 7/22 bootconfig: init: Allow admin to use bootconfig for kernel command line
In reply to Masami HiramatsuSince the current kernel command line is too short to describe many options which supported by kernel, allow user to use boot config to setup (add) the command line options.
All kernel parameters under "kernel." keywords will be used for setting up extra kernel command line.
For example,
kernel {
audit = on
audit_backlog_limit = 256
}
Note that you can not specify some early parameters (like console etc.) by this method, since it is loaded after early parameters parsed.
--- init/main.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 5 deletions(-)
init/main.c +101 -5
@@ -137,6 +137,8 @@ char __initdata boot_command_line[COMMAND_LINE_SIZE];char *saved_command_line;/* Command line for parameter parsing */ static char *static_command_line; +/* Untouched extra command line */ +static char *extra_command_line;static char *execute_command;static char *ramdisk_execute_command;
@@ -245,6 +247,83 @@ static int __init loglevel(char *str)early_param ("loglevel" , loglevel);#ifdef CONFIG_BOOT_CONFIG + +char xbc_namebuf[XBC_KEYLEN_MAX ]__initdata ; + +#define rest (dst, end) ((end) > (dst) ? (end) - (dst) : 0) + +static int __init xbc_snprint_cmdline (char *buf,size_t size, +struct xbc_node *root) +{ +struct xbc_node *knode, *vnode; +char *end = buf + size; +char c ='\"' ; +const char *val; +int ret; + +xbc_node_for_each_key_value (root, knode, val) { + ret =xbc_node_compose_key_after (root, knode, + xbc_namebuf,XBC_KEYLEN_MAX ); +if (ret <0 ) +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) +continue ; + + c ='\"' ; +xbc_array_for_each_value (vnode, val) { + ret =snprintf (buf,rest (buf, end),"%c%s" , c, val); +if (ret <0 ) +return ret; + buf += ret; + c =',' ; + } +if (rest (buf, end) >2 ) +strcpy (buf,"\" " ); + buf +=2 ; + } + +return buf - (end - size); +} +#undef rest + +/* Make an extra command line under given key word */ +static char *__init xbc_make_cmdline (const char *key) +{ +struct xbc_node *root; +char *new_cmdline; +int ret, len =0 ; + + root =xbc_find_node (key); +if (!root) +return NULL ; + +/* Count required buffer size */ + len =xbc_snprint_cmdline (NULL ,0 , root); +if (len <=0 ) +return NULL ; + + new_cmdline =memblock_alloc (len +1 ,SMP_CACHE_BYTES ); +if (!new_cmdline) { +pr_err ("Failed to allocate memory for extra kernel cmdline.\n" ); +return NULL ; + } + + ret =xbc_snprint_cmdline (new_cmdline, len +1 , root); +if (ret <0 || ret > len) { +pr_err ("Failed to print extra kernel cmdline.\n" ); +return NULL ; + } + +return new_cmdline; +} +u32 boot_config_checksum (unsigned char *p,u32 size) {u32 ret =0 ;
@@ -289,8 +368,11 @@ static void __init setup_boot_config(void)if (xbc_init (copy) <0 )pr_err ("Failed to parse boot config\n" ); -else +else {pr_info ("Load boot config: %d bytes\n" , size); +/* keys starting with "kernel." are passed via cmdline */ + extra_command_line =xbc_make_cmdline ("kernel" ); + } }#else #define setup_boot_config () do { } while (0)
@@ -425,7 +507,12 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { }*/ static void __init setup_command_line (char *command_line) { -size_t len =strlen (boot_command_line) +1 ; +size_t len, xlen =0 ; + +if (extra_command_line) + xlen =strlen (extra_command_line); + + len = xlen +strlen (boot_command_line) +1 ; saved_command_line =memblock_alloc (len,SMP_CACHE_BYTES );if (!saved_command_line)
@@ -435,8 +522,17 @@ static void __init setup_command_line(char *command_line)if (!static_command_line)panic ("%s: Failed to allocate %zu bytes\n" , __func__, len); -strcpy (saved_command_line, boot_command_line); -strcpy (static_command_line, command_line); +if (xlen) { +/* +* We have to put extra_command_line before boot command +* lines because there could be dashes (separator of init +* command line) in the command lines. +*/ +strcpy (saved_command_line, extra_command_line); +strcpy (static_command_line, extra_command_line); + } +strcpy (saved_command_line + xlen, boot_command_line); +strcpy (static_command_line + xlen, command_line); }/*
@@ -652,7 +748,7 @@ asmlinkage __visible void __init start_kernel(void)build_all_zonelists (NULL );page_alloc_init (); -pr_notice ("Kernel command line: %s\n" , boot_command_line); +pr_notice ("Kernel command line: %s\n" , saved_command_line);/* parameters may set static keys */ jump_label_init ();parse_early_param ();
Masami Hiramatsu
maintainerPATCH v6 8/22 bootconfig: init: Allow admin to use bootconfig for init command line
In reply to Masami HiramatsuSince the current kernel command line is too short to describe long and many options for init (e.g. systemd command line options), this allows admin to use boot config for init command line.
All init command line under "init." keywords will be passed to init.
For example,
init.systemd {
unified_cgroup_hierarchy = 1
debug_shell
default_timeout_start_sec = 60
}
--- init/main.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
init/main.c +28 -3
@@ -139,6 +139,8 @@ char *saved_command_line;static char *static_command_line;/* Untouched extra command line */ static char *extra_command_line; +/* Extra init arguments */ +static char *extra_init_args;static char *execute_command;static char *ramdisk_execute_command;
@@ -372,6 +374,8 @@ static void __init setup_boot_config(void)pr_info ("Load boot config: %d bytes\n" , size);/* keys starting with "kernel." are passed via cmdline */ extra_command_line =xbc_make_cmdline ("kernel" ); +/* Also, "init." keys are init arguments */ + extra_init_args = xbc_make_cmdline("init"); } }#else
@@ -507,16 +511,18 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { }*/ static void __init setup_command_line (char *command_line) { -size_t len, xlen =0 ; +size_t len, xlen =0 , ilen =0 ;if (extra_command_line) xlen =strlen (extra_command_line); +if (extra_init_args) + ilen =strlen (extra_init_args) +4 ;/* for " -- " */ len = xlen +strlen (boot_command_line) +1 ; - saved_command_line =memblock_alloc (len,SMP_CACHE_BYTES ); + saved_command_line =memblock_alloc (len + ilen,SMP_CACHE_BYTES );if (!saved_command_line) -panic ("%s: Failed to allocate %zu bytes\n" , __func__, len); +panic ("%s: Failed to allocate %zu bytes\n" , __func__, len + ilen); static_command_line =memblock_alloc (len,SMP_CACHE_BYTES );if (!static_command_line)
@@ -533,6 +539,22 @@ static void __init setup_command_line(char *command_line) }strcpy (saved_command_line + xlen, boot_command_line);strcpy (static_command_line + xlen, command_line); + +if (ilen) { +/* +* Append supplemental init boot args to saved_command_line +* so that user can check what command line options passed +* to init. +*/ + len =strlen (saved_command_line); +if (!strstr (boot_command_line," -- " )) { +strcpy (saved_command_line + len," -- " ); + len +=4 ; + }else + saved_command_line[len++] =' ' ; + +strcpy (saved_command_line + len, extra_init_args); + } }/*
@@ -759,6 +781,9 @@ asmlinkage __visible void __init start_kernel(void)if (!IS_ERR_OR_NULL (after_dashes))parse_args ("Setting init args" , after_dashes,NULL ,0 ,-1 ,-1 ,NULL , set_init_arg); +if (extra_init_args) +parse_args ("Setting extra init args" , extra_init_args, +NULL ,0 ,-1 ,-1 ,NULL , set_init_arg);/* * These use large bootmem allocations and must precede
Masami Hiramatsu
maintainerPATCH v6 9/22 Documentation: bootconfig: Add a doc for extended boot config
In reply to Masami HiramatsuAdd a documentation for extended boot config under admin-guide, since it is including the syntax of boot config.
---
Changes in v6:
- Add a note about comment after value.
Changes in v5:
- Fix to insert bootconfig to TOC list alphabetically.
- Add notes about avaliable characters in values.
- Fix to use correct quotes (``) for .rst.
Changes in v4:
- Rename suppremental kernel command line to boot config.
- Update document according to the recent changes.
- Add How to load it on boot.
- Style bugfix.
--- Documentation/admin-guide/bootconfig.rst | 184 ++++++++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 MAINTAINERS | 1 3 files changed, 186 insertions(+) create mode 100644 Documentation/admin-guide/bootconfig.rst
Documentation/admin-guide/bootconfig.rst new file +184 -0
@@ -0,0 +1,184 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================== +Boot Configuration +================== + +:Author: Masami Hiramatsu <[email protected]> + +Overview +======== + +The boot configuration is expanding current kernel cmdline to support +additional key-value data when boot the kernel in an efficient way. +This allows adoministrators to pass a structured-Key config file. + +Config File Syntax +================== + +The boot config syntax is a simple structured key-value. Each key consists +of dot-connected-words, and key and value are connected by "=". The value +has to be terminated by semi-colon (``;``) or newline (``\n``). +For array value, array entries are separated by comma (``,``). :: + +KEY[.WORD[...]] = VALUE[, VALUE2[...]][;] + +Each key word must contain only alphabets, numbers, dash (``-``) or underscore +(``_``). And each value only contains printable characters or spaces except +for delimiters such as semi-colon (``;``), new-line (``\n``), comma (``,``), +hash (``#``) and closing brace (``}``). + +If you want to use those delimiters in a value, you can use either double- +quotes (``"VALUE"``) or single-quotes (``'VALUE'``) to quote it. Note that +you can not escape these quotes. + +There can be a key which doesn't have value or has an empty value. Those keys +are used for checking the key exists or not (like a boolean). + +Key-Value Syntax +---------------- + +The boot config file syntax allows user to merge partially same word keys +by brace. For example:: + + foo.bar.baz = value1 + foo.bar.qux.quux = value2 + +These can be written also in:: + + foo.bar { + baz = value1 + qux.quux = value2 + } + +Or more shorter, written as following:: + + foo.bar { baz = value1; qux.quux = value2 } + +In both styles, same key words are automatically merged when parsing it +at boot time. So you can append similar trees or key-values. + +Comments +-------- + +The config syntax accepts shell-script style comments. The comments start +with hash ("#") until newline ("\n") will be ignored. + +:: + + # comment line + foo = value # value is set to foo. + bar = 1, # 1st element + 2, # 2nd element + 3 # 3rd element + +This is parsed as below:: + + foo = value + bar = 1, 2, 3 + +Note that you can not put a comment between value and delimiter(``,`` or +``;``). This means following config has a syntax error :: + + key = 1 # comment + ,2 + + +/proc/bootconfig +================ + +/proc/bootconfig is a user-space interface of the boot config. +Unlike /proc/cmdline, this file shows the key-value style list. +Each key-value pair is shown in each line with following style:: + + KEY[.WORDS...] = "[VALUE]"[,"VALUE2"...] + + +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. +Because of this "piggyback" method, there is no need to change or +update the boot loader and the kernel image itself. + +To do this operation, Linux kernel provides "bootconfig" command under +tools/bootconfig, which allows admin to apply or delete the config file +to/from initrd image. You can build it by follwoing command:: + + # make -C tools/bootconfig + +To add your boot config file to initrd image, run bootconfig as below +(Old data is removed automatically if exists):: + + # tools/bootconfig/bootconfig -a your-config /boot/initrd.img-X.Y.Z + +To remove the config from the image, you can use -d option as below:: + + # tools/bootconfig/bootconfig -d /boot/initrd.img-X.Y.Z + + +C onfig File Limitation +====================== + +Currently the maximum config size size is 32KB and the total key-words (not +key-value entries) must be under 1024 nodes. +Note: this is not the number of entries but nodes, an entry must consume +more than 2 nodes (a key-word and a value). So theoretically, it will be +up to 512 key-value pairs. If keys contains 3 words in average, it can +contain 256 key-value pairs. In most cases, the number of config items +will be under 100 entries and smaller than 8KB, so it would be enough. +If the node number exceeds 1024, parser returns an error even if the file +size is smaller than 32KB. +Anyway, since bootconfig command verifies it when appending a boot config +to initrd image, user can notice it before boot. + + +Bootconfig APIs +=============== + +User can query or loop on key-value pairs, also it is possible to find +a root (prefix) key node and find key-values under that node. + +If you have a key string, you can query the value directly with the key +using xbc_find_value(). If you want to know what keys exist in the SKC +tree, you can use xbc_for_each_key_value() to iterate key-value pairs. +Note that you need to use xbc_array_for_each_value() for accessing +each arraies value, e.g.:: + + vnode = NULL; + xbc_find_value("key.word", &vnode); + if (vnode && xbc_node_is_array(vnode)) + xbc_array_for_each_value(vnode, value) { + printk("%s ", value); + } + +If you want to focus on keys which has a prefix string, you can use +xbc_find_node() to find a node which prefix key words, and iterate +keys under the prefix node with xbc_node_for_each_key_value(). + +But the most typical usage is to get the named value under prefix +or get the named array under prefix as below:: + + root = xbc_find_node("key.prefix"); + value = xbc_node_find_value(root, "option", &vnode); + ... + xbc_node_for_each_array_value(root, "array-option", value, anode) { + ... + } + +This accesses a value of "key.prefix.option" and an array of +"key.prefix.array-option". + +Locking is not needed, since after initialized, the config becomes readonly. +All data and keys must be copied if you need to modify it. + + +Functions and structures +======================== + +.. kernel-doc:: include/linux/bootconfig.h +.. kernel-doc:: lib/bootconfig.c +
Documentation/admin-guide/index.rst +1 -0
@@ -64,6 +64,7 @@ configure specific aspects of kernel behavior to your liking. binderfs binfmt-misc blockdev/index + bootconfig braille-console btmrvl cgroup-v1/index
MAINTAINERS +1 -0
@@ -15780,6 +15780,7 @@ F: lib/bootconfig.c F: fs/proc/bootconfig.c F: include/linux/bootconfig.h F: tools/bootconfig/* +F: Documentation/admin-guide/bootconfig.rst SUN3/3X M: Sam Creasey <[email protected]>
Masami Hiramatsu
maintainerPATCH v6 10/22 tracing: Apply soft-disabled and filter to tracepoints printk
In reply to Masami HiramatsuApply soft-disabled and the filter rule of the trace events to the printk output of tracepoints (a.k.a. tp_printk kernel parameter) as same as trace buffer output.
--- kernel/trace/trace.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/trace/trace.c +7 -0
@@ -2610,6 +2610,7 @@ static DEFINE_MUTEX(tracepoint_printk_mutex);static void output_printk (struct trace_event_buffer *fbuffer) {struct trace_event_call *event_call; +struct trace_event_file *file;struct trace_event *event;unsigned long flags;struct trace_iterator *iter = tracepoint_print_iter;
@@ -2623,6 +2624,12 @@ static void output_printk(struct trace_event_buffer *fbuffer) !event_call->event.funcs->trace)return ; + file = fbuffer->trace_file; +if (test_bit (EVENT_FILE_FL_SOFT_DISABLED_BIT , &file->flags) || + (unlikely (file->flags &EVENT_FILE_FL_FILTERED ) && + !filter_match_preds (file->filter, fbuffer->entry))) +return ; + event = &fbuffer->trace_file->event_call->event;spin_lock_irqsave (&tracepoint_iter_lock, flags);
Masami Hiramatsu
maintainerPATCH v6 11/22 tracing: kprobes: Output kprobe event to printk buffer
In reply to Masami HiramatsuSince kprobe-events use event_trigger_unlock_commit_regs() directly, that events doesn't show up in printk buffer if "tp_printk" is set.
Use trace_event_buffer_commit() in kprobe events so that it can invoke output_printk() as same as other trace events.
--- include/linux/trace_events.h | 1 + kernel/trace/trace.c | 4 +-- kernel/trace/trace_events.c | 1 + kernel/trace/trace_kprobe.c | 57 +++++++++++++++++++++--------------------- 4 files changed, 32 insertions(+), 31 deletions(-)
include/linux/trace_events.h +1 -0
@@ -216,6 +216,7 @@ struct trace_event_buffer {void *entry;unsigned long flags;int pc; +struct pt_regs *regs; }; void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
kernel/trace/trace.c +2 -2
@@ -2680,9 +2680,9 @@ void trace_event_buffer_commit(struct trace_event_buffer *fbuffer)if (static_key_false (&tracepoint_printk_key.key))output_printk (fbuffer); -event_trigger_unlock_commit (fbuffer->trace_file, fbuffer->buffer, +event_trigger_unlock_commit_regs (fbuffer->trace_file, fbuffer->buffer, fbuffer->event, fbuffer->entry, - fbuffer->flags, fbuffer->pc); + fbuffer->flags, fbuffer->pc, fbuffer->regs); }EXPORT_SYMBOL_GPL (trace_event_buffer_commit);
kernel/trace/trace_events.c +1 -0
@@ -272,6 +272,7 @@ void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,if (!fbuffer->event)return NULL ; + fbuffer->regs =NULL ; fbuffer->entry =ring_buffer_event_data (fbuffer->event);return fbuffer->entry; }
kernel/trace/trace_kprobe.c +28 -29
97 lines not on this page · raw message
Masami Hiramatsu
maintainerPATCH v6 12/22 tracing: kprobes: Register to dynevent earlier stage
In reply to Masami HiramatsuRegister kprobe event to dynevent in subsys_initcall level. This will allow kernel to register new kprobe events in fs_initcall level via trace_run_command.
--- kernel/trace/trace_kprobe.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
kernel/trace/trace_kprobe.c +15 -4
@@ -1685,11 +1685,12 @@ static __init void setup_boot_kprobe_events(void)enable_boot_kprobe_events (); } -/* Make a tracefs interface for controlling probe points */ -static __init int init_kprobe_trace (void ) +/* +* Register dynevent at subsys_initcall. This allows kernel to setup kprobe +* events in fs_initcall without tracefs. +*/ +static __init int init_kprobe_trace_early (void ) { -struct dentry *d_tracer; -struct dentry *entry;int ret; ret =dyn_event_register (&trace_kprobe_ops);
@@ -1699,6 +1700,16 @@ static __init int init_kprobe_trace(void)if (register_module_notifier (&trace_kprobe_module_nb))return -EINVAL ; +return 0 ; +} +subsys_initcall (init_kprobe_trace_early); + +/* Make a tracefs interface for controlling probe points */ +static __init int init_kprobe_trace (void ) +{ +struct dentry *d_tracer; +struct dentry *entry; + d_tracer =tracing_init_dentry ();if (IS_ERR (d_tracer))return 0 ;
Masami Hiramatsu
maintainerPATCH v6 13/22 tracing: Accept different type for synthetic event fields
In reply to Masami HiramatsuMake the synthetic event accepts a different type field to record. However, the size and signed flag must be same.
--- kernel/trace/trace_events_hist.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +5 -2
@@ -4110,8 +4110,11 @@ static int check_synth_field(struct synth_event *event, field = event->fields[field_pos]; -if (strcmp (field->type, hist_field->type) !=0 ) -return -EINVAL ; +if (strcmp (field->type, hist_field->type) !=0 ) { +if (field->size != hist_field->size || + field->is_signed != hist_field->is_signed) +return -EINVAL ; + }return 0 ; }
Masami Hiramatsu
maintainerPATCH v6 14/22 tracing: Add NULL trace-array check in print_synth_event()
In reply to Masami HiramatsuAdd NULL trace-array check in print_synth_event(), because if we enable tp_printk option, iter->tr can be NULL.
--- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
@@ -833,7 +833,7 @@ static enum print_line_t print_synth_event(struct trace_iterator *iter, fmt =synth_field_fmt (se->fields[i]->type);/* parameter types */ -if (tr->trace_flags &TRACE_ITER_VERBOSE ) +if (tr && tr->trace_flags &TRACE_ITER_VERBOSE )trace_seq_printf (s,"%s " , fmt);snprintf (print_fmt,sizeof (print_fmt),"%%s=%s%%s" , fmt);
Masami Hiramatsu
maintainerPATCH v6 15/22 tracing/boot: Add boot-time tracing
In reply to Masami HiramatsuSetup tracing options via extra boot config in addition to kernel command line.
This adds following commands support. These are applied to the global trace instance.
- ftrace.options = OPT1[,OPT2...]
Enable given ftrace options.
- ftrace.trace_clock = CLOCK
Set given CLOCK to ftrace's trace_clock.
- ftrace.buffer_size = SIZE
Configure ftrace buffer size to SIZE. You can use "KB" or "MB" for that SIZE.
- ftrace.events = EVENT[, EVENT2...]
Enable given events on boot. You can use a wild card in EVENT.
- ftrace.tracer = TRACER
Set TRACER to current tracer on boot. (e.g. function)
Note that this is NOT replacing the kernel parameters, because this boot config based setting is later than that. If you want to trace earlier boot events, you still need kernel parameters.
---
Changes in v4:
- Remove parameter which is not related to instance.
- Use bootconfig.
--- kernel/trace/Kconfig | 9 ++++ kernel/trace/Makefile | 1 kernel/trace/trace.c | 10 ++-- kernel/trace/trace_boot.c | 113 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 kernel/trace/trace_boot.c
kernel/trace/Kconfig +9 -0
@@ -814,6 +814,15 @@ config GCOV_PROFILE_FTRACE Note that on a kernel compiled with this config, ftrace will run significantly slower. +config BOOTTIME_TRACING + bool "Boot-time Tracing support" + depends on BOOT_CONFIG && TRACING + default y + help + Enable developer to setup ftrace subsystem via supplemental + kernel cmdline at boot time for debugging (tracing) driver + initialization and boot process. + endif # FTRACE endif # TRACING_SUPPORT
kernel/trace/Makefile +1 -0
@@ -83,6 +83,7 @@ endif obj-$(CONFIG_DYNAMIC_EVENTS) += trace_dynevent.o obj-$(CONFIG_PROBE_EVENTS) += trace_probe.o obj-$(CONFIG_UPROBE_EVENTS) += trace_uprobe.o +obj-$(CONFIG_BOOTTIME_TRACING) += trace_boot.o obj-$(CONFIG_TRACEPOINT_BENCHMARK) += trace_benchmark.o
kernel/trace/trace.c +5 -5
@@ -162,7 +162,7 @@ union trace_eval_map_item {static union trace_eval_map_item *trace_eval_maps;#endif /* CONFIG_TRACE_EVAL_MAP_FILE */ -static int tracing_set_tracer (struct trace_array *tr,const char *buf); +int tracing_set_tracer (struct trace_array *tr,const char *buf);static void ftrace_trace_userstack (struct ring_buffer *buffer,unsigned long flags,int pc);
@@ -4747,7 +4747,7 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)return 0 ; } -static int trace_set_options (struct trace_array *tr,char *option) +int trace_set_options (struct trace_array *tr,char *option) {char *cmp;int neg =0 ;
@@ -5647,8 +5647,8 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,return ret; } -static ssize_t tracing_resize_ring_buffer (struct trace_array *tr, -unsigned long size,int cpu_id) +ssize_t tracing_resize_ring_buffer (struct trace_array *tr, +unsigned long size,int cpu_id) {int ret = size;
@@ -5727,7 +5727,7 @@ static void add_tracer_options(struct trace_array *tr, struct tracer *t)create_trace_option_files (tr, t); } -static int tracing_set_tracer (struct trace_array *tr,const char *buf) +int tracing_set_tracer (struct trace_array *tr,const char *buf) {struct tracer *t;#ifdef CONFIG_TRACER_MAX_TRACE
kernel/trace/trace_boot.c new file +113 -0
113 lines not on this page · raw message
Masami Hiramatsu
maintainerPATCH v6 16/22 tracing/boot: Add per-event settings
In reply to Masami HiramatsuAdd per-event settings for boottime tracing. User can set filter, actions and enable on each event on boot. The event entries are under ftrace.event.GROUP.EVENT node (note that the option key includes event's group name and event name.) This supports below configs.
- ftrace.event.GROUP.EVENT.enable
Enables GROUP:EVENT tracing.
- ftrace.event.GROUP.EVENT.filter = FILTER
Set FILTER rule to the GROUP:EVENT.
- ftrace.event.GROUP.EVENT.actions = ACTION[, ACTION2...] Set ACTIONs to the GROUP:EVENT.
For example,
ftrace.event.sched.sched_process_exec {
filter = "pid < 128"
enable}
this will enable tracing "sched:sched_process_exec" event with "pid < 128" filter.
--- kernel/trace/trace_boot.c | 60 +++++++++++++++++++++++++++++++++++ kernel/trace/trace_events_trigger.c | 2 + 2 files changed, 61 insertions(+), 1 deletion(-)
kernel/trace/trace_boot.c +60 -0
@@ -56,6 +56,7 @@ trace_boot_set_ftrace_options(struct trace_array *tr, struct xbc_node *node)#ifdef CONFIG_EVENT_TRACING extern int ftrace_set_clr_event (struct trace_array *tr,char *buf,int set); +extern int trigger_process_regex (struct trace_event_file *file,char *buff);static void __init trace_boot_enable_events (struct trace_array *tr,struct xbc_node *node)
@@ -74,8 +75,66 @@ trace_boot_enable_events(struct trace_array *tr, struct xbc_node *node) pr_err("Failed to enable event: %s\n", p); } } + +static void __init +trace_boot_init_one_event (struct trace_array *tr,struct xbc_node *gnode, +struct xbc_node *enode) +{ +struct trace_event_file *file; +struct xbc_node *anode; +char buf[MAX_BUF_LEN ]; +const char *p, *group, *event; + + group =xbc_node_get_data (gnode); + event =xbc_node_get_data (enode); + +mutex_lock (&event_mutex); + file =find_event_file (tr, group, event); +if (!file) { +pr_err ("Failed to find event: %s:%s\n" , group, event); + goto out; + } + + p =xbc_node_find_value (enode,"filter" ,NULL ); +if (p && *p !='\0' ) { +if (strlcpy (buf, p,ARRAY_SIZE (buf)) >=ARRAY_SIZE (buf)) +pr_err ("filter string is too long: %s\n" , p); +else if (apply_event_filter (file, buf) <0 ) +pr_err ("Failed to apply filter: %s\n" , buf); + } + +xbc_node_for_each_array_value (enode,"actions" , anode, p) { +if (strlcpy (buf, p,ARRAY_SIZE (buf)) >=ARRAY_SIZE (buf)) +pr_err ("action string is too long: %s\n" , p); +else if (trigger_process_regex (file, buf) <0 ) +pr_err ("Failed to apply an action: %s\n" , buf); + } + +if (xbc_node_find_value (enode,"enable" ,NULL )) { +if (trace_event_enable_disable (file,1 ,0 ) <0 ) +pr_err ("Failed to enable event node: %s:%s\n" , + group, event); + } +out: +mutex_unlock (&event_mutex); +} + +static void __init +trace_boot_init_events (struct trace_array *tr,struct xbc_node *node) +{ +struct xbc_node *gnode, *enode; + + node =xbc_node_find_child (node,"event" ); +if (!node) +return ; +/* per-event key starts with "event.GROUP.EVENT" */ +xbc_node_for_each_child (node, gnode) +xbc_node_for_each_child (gnode, enode) +trace_boot_init_one_event (tr, gnode, enode); +}#else #define trace_boot_enable_events (tr, node) do {} while (0) +#define trace_boot_init_events (tr, node) do {} while (0)#endif static void __init
@@ -104,6 +163,7 @@ static int __init trace_boot_init(void)return 0 ;trace_boot_set_ftrace_options (tr, trace_node); +trace_boot_init_events (tr, trace_node);trace_boot_enable_events (tr, trace_node);trace_boot_enable_tracer (tr, trace_node);
kernel/trace/trace_events_trigger.c +1 -1
@@ -213,7 +213,7 @@ static int event_trigger_regex_open(struct inode *inode, struct file *file)return ret; } -static int trigger_process_regex (struct trace_event_file *file,char *buff) +int trigger_process_regex (struct trace_event_file *file,char *buff) {char *command, *next = buff;struct event_command *p;
Masami Hiramatsu
maintainerPATCH v6 17/22 tracing/boot Add kprobe event support
In reply to Masami HiramatsuAdd kprobe event support on event node to boot-time tracing. If the group name of event is "kprobes", the boot-time tracing defines new probe event according to "probes" values.
- ftrace.event.kprobes.EVENT.probes = PROBE[, PROBE2...] Defines new kprobe event based on PROBEs. It is able to define multiple probes on one event, but those must have same type of arguments.
For example,
ftrace.events.kprobes.myevent {
probes = "vfs_read $arg1 $arg2";
enable;}
This will add kprobes:myevent on vfs_read with the 1st and the 2nd arguments.
--- kernel/trace/trace_boot.c | 46 +++++++++++++++++++++++++++++++++++++++++++ kernel/trace/trace_kprobe.c | 5 +++++ 2 files changed, 51 insertions(+)
kernel/trace/trace_boot.c +46 -0
@@ -76,6 +76,48 @@ trace_boot_enable_events(struct trace_array *tr, struct xbc_node *node) } } +#ifdef CONFIG_KPROBE_EVENTS +extern int trace_kprobe_run_command (const char *command); + +static int __init +trace_boot_add_kprobe_event (struct xbc_node *node,const char *event) +{ +struct xbc_node *anode; +char buf[MAX_BUF_LEN ]; +const char *val; +char *p; +int len; + + len =snprintf (buf,ARRAY_SIZE (buf) -1 ,"p:kprobes/%s " , event); +if (len >=ARRAY_SIZE (buf)) { +pr_err ("Event name is too long: %s\n" , event); +return -E2BIG ; + } + p = buf + len; + len =ARRAY_SIZE (buf) - len; + +xbc_node_for_each_array_value (node,"probes" , anode, val) { +if (strlcpy (p, val, len) >= len) { +pr_err ("Probe definition is too long: %s\n" , val); +return -E2BIG ; + } +if (trace_kprobe_run_command (buf) <0 ) { +pr_err ("Failed to add probe: %s\n" , buf); +return -EINVAL ; + } + } + +return 0 ; +} +#else +static inline int __init +trace_boot_add_kprobe_event (struct xbc_node *node,const char *event) +{ +pr_err ("Kprobe event is not supported.\n" ); +return -ENOTSUPP ; +} +#endif +static void __init trace_boot_init_one_event (struct trace_array *tr,struct xbc_node *gnode,struct xbc_node *enode)
@@ -88,6 +130,10 @@ trace_boot_init_one_event(struct trace_array *tr, struct xbc_node *gnode, group =xbc_node_get_data (gnode); event =xbc_node_get_data (enode); +if (!strcmp (group,"kprobes" )) +if (trace_boot_add_kprobe_event (enode, event) <0 ) +return ; +mutex_lock (&event_mutex); file =find_event_file (tr, group, event);if (!file) {
kernel/trace/trace_kprobe.c +5 -0
@@ -902,6 +902,11 @@ static int create_or_delete_trace_kprobe(int argc, char **argv)return ret == -ECANCELED ? -EINVAL : ret; } +int trace_kprobe_run_command (const char *command) +{ +return trace_run_command (command, create_or_delete_trace_kprobe); +} +static int trace_kprobe_release (struct dyn_event *ev) {struct trace_kprobe *tk =to_trace_kprobe (ev);
Masami Hiramatsu
maintainerPATCH v6 18/22 tracing/boot: Add synthetic event support
In reply to Masami HiramatsuAdd synthetic event node support to boot time tracing. The synthetic event is a kind of event node, but the group name is "synthetic".
- ftrace.event.synthetic.EVENT.fields = FIELD[, FIELD2...] Defines new synthetic event with FIELDs. Each field should be "type varname".
The synthetic node requires "fields" string arraies, which defines the fields as same as tracing/synth_events interface.
--- kernel/trace/trace_boot.c | 47 ++++++++++++++++++++++++++++++++++++++ kernel/trace/trace_events_hist.c | 5 ++++ 2 files changed, 52 insertions(+)
kernel/trace/trace_boot.c +47 -0
@@ -118,6 +118,50 @@ trace_boot_add_kprobe_event(struct xbc_node *node, const char *event) }#endif +#ifdef CONFIG_HIST_TRIGGERS +extern int synth_event_run_command (const char *command); + +static int __init +trace_boot_add_synth_event (struct xbc_node *node,const char *event) +{ +struct xbc_node *anode; +char buf[MAX_BUF_LEN ], *q; +const char *p; +int len, delta, ret; + + len =ARRAY_SIZE (buf); + delta =snprintf (buf, len,"%s" , event); +if (delta >= len) { +pr_err ("Event name is too long: %s\n" , event); +return -E2BIG ; + } + len -= delta; q = buf + delta; + +xbc_node_for_each_array_value (node,"fields" , anode, p) { + delta =snprintf (q, len," %s;" , p); +if (delta >= len) { +pr_err ("fields string is too long: %s\n" , p); +return -E2BIG ; + } + len -= delta; q += delta; + } + + ret =synth_event_run_command (buf); +if (ret <0 ) +pr_err ("Failed to add synthetic event: %s\n" , buf); + + +return ret; +} +#else +static inline int __init +trace_boot_add_synth_event (struct xbc_node *node,const char *event) +{ +pr_err ("Synthetic event is not supported.\n" ); +return -ENOTSUPP ; +} +#endif +static void __init trace_boot_init_one_event (struct trace_array *tr,struct xbc_node *gnode,struct xbc_node *enode)
@@ -133,6 +177,9 @@ trace_boot_init_one_event(struct trace_array *tr, struct xbc_node *gnode,if (!strcmp (group,"kprobes" ))if (trace_boot_add_kprobe_event (enode, event) <0 )return ; +if (!strcmp (group,"synthetic" )) +if (trace_boot_add_synth_event (enode, event) <0 ) +return ;mutex_lock (&event_mutex); file =find_event_file (tr, group, event);
kernel/trace/trace_events_hist.c +5 -0
@@ -1384,6 +1384,11 @@ static int create_or_delete_synth_event(int argc, char **argv)return ret == -ECANCELED ? -EINVAL : ret; } +int synth_event_run_command (const char *command) +{ +return trace_run_command (command, create_or_delete_synth_event); +} +static int synth_event_create (int argc,const char **argv) {const char *name = argv[0 ];
Masami Hiramatsu
maintainerPATCH v6 19/22 tracing/boot: Add instance node support
In reply to Masami HiramatsuAdd instance node support to boot-time tracing. User can set some options and event nodes under instance node.
- ftrace.instance.INSTANCE[...]
Add new INSTANCE instance. Some options and event nodes are acceptable for instance node.
---
Changes in v4:
- Use trace_array_get_by_name() instead of trace_array_create().
- Remove global boot option setting.
--- kernel/trace/trace_boot.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-)
kernel/trace/trace_boot.c +38 -5
@@ -20,7 +20,7 @@ extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr, unsigned long size, int cpu_id);static void __init -trace_boot_set_ftrace_options (struct trace_array *tr,struct xbc_node *node) +trace_boot_set_instance_options (struct trace_array *tr,struct xbc_node *node) {struct xbc_node *anode;const char *p;
@@ -242,6 +242,40 @@ trace_boot_enable_tracer(struct trace_array *tr, struct xbc_node *node) } } +static void __init +trace_boot_init_one_instance (struct trace_array *tr,struct xbc_node *node) +{ +trace_boot_set_instance_options (tr, node); +trace_boot_init_events (tr, node); +trace_boot_enable_events (tr, node); +trace_boot_enable_tracer (tr, node); +} + +static void __init +trace_boot_init_instances (struct xbc_node *node) +{ +struct xbc_node *inode; +struct trace_array *tr; +const char *p; + + node =xbc_node_find_child (node,"instance" ); +if (!node) +return ; + +xbc_node_for_each_child (node, inode) { + p =xbc_node_get_data (inode); +if (!p || *p =='\0' ) +continue ; + + tr =trace_array_get_by_name (p); +if (IS_ERR (tr)) { +pr_err ("Failed to get trace instance %s\n" , p); +continue ; + } +trace_boot_init_one_instance (tr, inode); + } +} +static int __init trace_boot_init (void ) {struct xbc_node *trace_node;
@@ -255,10 +289,9 @@ static int __init trace_boot_init(void)if (!tr)return 0 ; -trace_boot_set_ftrace_options (tr, trace_node); -trace_boot_init_events (tr, trace_node); -trace_boot_enable_events (tr, trace_node); -trace_boot_enable_tracer (tr, trace_node); +/* Global trace array is also one instance */ +trace_boot_init_one_instance (tr, trace_node); +trace_boot_init_instances (trace_node);return 0 ; }
Masami Hiramatsu
maintainerPATCH v6 20/22 tracing/boot: Add cpu_mask option support
In reply to Masami HiramatsuAdd ftrace.cpumask option support to boot-time tracing. This sets cpumask for each instance.
- ftrace.[instance.INSTANCE.]cpumask = CPUMASK;
Set the trace cpumask. Note that the CPUMASK should be a string which <tracefs>/tracing_cpumask can accepts.
--- kernel/trace/trace.c | 42 +++++++++++++++++++++++++++++------------- kernel/trace/trace_boot.c | 14 ++++++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-)
kernel/trace/trace.c +29 -13
@@ -4561,20 +4561,13 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf,return count; } -static ssize_t -tracing_cpumask_write (struct file *filp,const char __user *ubuf, -size_t count,loff_t *ppos) +int tracing_set_cpumask (struct trace_array *tr, +cpumask_var_t tracing_cpumask_new) { -struct trace_array *tr =file_inode (filp)->i_private; -cpumask_var_t tracing_cpumask_new; -int err, cpu; - -if (!alloc_cpumask_var (&tracing_cpumask_new,GFP_KERNEL )) -return -ENOMEM ; +int cpu; - err =cpumask_parse_user (ubuf, count, tracing_cpumask_new); -if (err) - goto err_unlock; +if (!tr) +return -EINVAL ;local_irq_disable ();arch_spin_lock (&tr->max_lock);
@@ -4598,11 +4591,34 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,local_irq_enable ();cpumask_copy (tr->tracing_cpumask, tracing_cpumask_new); + +return 0 ; +} + +static ssize_t +tracing_cpumask_write (struct file *filp,const char __user *ubuf, +size_t count,loff_t *ppos) +{ +struct trace_array *tr =file_inode (filp)->i_private; +cpumask_var_t tracing_cpumask_new; +int err; + +if (!alloc_cpumask_var (&tracing_cpumask_new,GFP_KERNEL )) +return -ENOMEM ; + + err =cpumask_parse_user (ubuf, count, tracing_cpumask_new); +if (err) + goto err_free; + + err =tracing_set_cpumask (tr, tracing_cpumask_new); +if (err) + goto err_free; +free_cpumask_var (tracing_cpumask_new);return count; -err_unlock: +err_free:free_cpumask_var (tracing_cpumask_new);return err;
kernel/trace/trace_boot.c +14 -0
@@ -18,6 +18,8 @@ extern int trace_set_options(struct trace_array *tr, char *option);extern int tracing_set_tracer (struct trace_array *tr,const char *buf);extern ssize_t tracing_resize_ring_buffer (struct trace_array *tr,unsigned long size,int cpu_id); +extern int tracing_set_cpumask (struct trace_array *tr, +cpumask_var_t tracing_cpumask_new);static void __init trace_boot_set_instance_options (struct trace_array *tr,struct xbc_node *node)
@@ -52,6 +54,18 @@ trace_boot_set_instance_options(struct trace_array *tr, struct xbc_node *node)if (tracing_resize_ring_buffer (tr, v,RING_BUFFER_ALL_CPUS ) <0 )pr_err ("Failed to resize trace buffer to %s\n" , p); } + + p =xbc_node_find_value (node,"cpumask" ,NULL ); +if (p && *p !='\0' ) { +cpumask_var_t new_mask; + +if (alloc_cpumask_var (&new_mask,GFP_KERNEL )) { +if (cpumask_parse (p, new_mask) <0 || +tracing_set_cpumask (tr, new_mask) <0 ) +pr_err ("Failed to set new CPU mask %s\n" , p); +free_cpumask_var (new_mask); + } + } }#ifdef CONFIG_EVENT_TRACING
Masami Hiramatsu
maintainerPATCH v6 21/22 tracing/boot: Add function tracer filter options
In reply to Masami HiramatsuAdd below function-tracer filter options to boot-time tracing.
- ftrace.[instance.INSTANCE.]ftrace.filters
This will take an array of tracing function filter rules
- ftrace.[instance.INSTANCE.]ftrace.notraces
This will take an array of NON-tracing function filter rules
---
Changes in v6:
- Fix to depend on CONFIG_DYNAMIC_FTRACE instead of CONFIG_FUNCTION_TRACER.
--- kernel/trace/trace_boot.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
kernel/trace/trace_boot.c +40 -0
@@ -244,11 +244,51 @@ trace_boot_init_events(struct trace_array *tr, struct xbc_node *node)#define trace_boot_init_events (tr, node) do {} while (0)#endif +#ifdef CONFIG_DYNAMIC_FTRACE +extern bool ftrace_filter_param__initdata ; +extern int ftrace_set_filter (struct ftrace_ops *ops,unsigned char *buf, +int len,int reset); +extern int ftrace_set_notrace (struct ftrace_ops *ops,unsigned char *buf, +int len,int reset); +static void __init +trace_boot_set_ftrace_filter (struct trace_array *tr,struct xbc_node *node) +{ +struct xbc_node *anode; +const char *p; +char *q; + +xbc_node_for_each_array_value (node,"ftrace.filters" , anode, p) { + q =kstrdup (p,GFP_KERNEL ); +if (!q) +return ; +if (ftrace_set_filter (tr->ops, q,strlen (q),0 ) <0 ) +pr_err ("Failed to add %s to ftrace filter\n" , p); +else + ftrace_filter_param = true; +kfree (q); + } +xbc_node_for_each_array_value (node,"ftrace.notraces" , anode, p) { + q =kstrdup (p,GFP_KERNEL ); +if (!q) +return ; +if (ftrace_set_notrace (tr->ops, q,strlen (q),0 ) <0 ) +pr_err ("Failed to add %s to ftrace filter\n" , p); +else + ftrace_filter_param = true; +kfree (q); + } +} +#else +#define trace_boot_set_ftrace_filter (tr, node) do {} while (0) +#endif +static void __init trace_boot_enable_tracer (struct trace_array *tr,struct xbc_node *node) {const char *p; +trace_boot_set_ftrace_filter (tr, node); + p =xbc_node_find_value (node,"tracer" ,NULL );if (p && *p !='\0' ) {if (tracing_set_tracer (tr, p) <0 )
Masami Hiramatsu
maintainerPATCH v6 22/22 Documentation: tracing: Add boot-time tracing document
In reply to Masami HiramatsuAdd a documentation about boot-time tracing options in boot config.
--- Documentation/admin-guide/bootconfig.rst | 2 Documentation/trace/boottime-trace.rst | 184 ++++++++++++++++++++++++++++++ Documentation/trace/index.rst | 1 3 files changed, 187 insertions(+) create mode 100644 Documentation/trace/boottime-trace.rst
Documentation/admin-guide/bootconfig.rst +2 -0
@@ -1,5 +1,7 @@ .. SPDX-License-Identifier: GPL-2.0 +.. _bootconfig: + ================== Boot Configuration ==================
Documentation/trace/boottime-trace.rst new file +184 -0
184 lines not on this page · raw message
Documentation/trace/index.rst +1 -0
@@ -19,6 +19,7 @@ Linux Tracing Technologies events-msr mmiotrace histogram + boottime-trace hwlat_detector intel_th stm
Randy Dunlap
reviewerRe: [PATCH v6 22/22] Documentation: tracing: Add boot-time tracing document
Hi,
Here are a few editorial comments for you...
Quoted 32 lines · Masami Hiramatsu
Add a documentation about boot-time tracing options in boot config.
Signed-off-by Masami Hiramatsu <[email protected]>--- Documentation/admin-guide/bootconfig.rst | 2 Documentation/trace/boottime-trace.rst | 184 ++++++++++++++++++++++++++++++ Documentation/trace/index.rst | 1 3 files changed, 187 insertions(+) create mode 100644 Documentation/trace/boottime-trace.rstDocumentation/trace/boottime-trace.rst new file +14
-0@@ -0,0 +1,184 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +Boot-time tracing +================= + +:Author: Masami Hiramatsu <[email protected]> + +Overview +======== + +Boot-time tracing allows users to trace boot-time process including +device initialization with full features of ftrace including per-event +filter and actions, histograms, kprobe-events and synthetic-events,
Documentation/trace/boottime-trace.rst line 24
Quoted 10 lines
Documentation/trace/boottime-trace.rst new file +10
-0+and trace instances. +Since kernel cmdline is not enough to control these complex features, +this uses bootconfig file to describe tracing feature programming. + +Options in the Boot Config +========================== + +Here is the list of available options list for boot time tracing in +boot config file [1]_. All options are under "ftrace." or "kernel." +refix. See kernel parameters for the options which starts
prefix.
Quoted 19 lines
Documentation/trace/boottime-trace.rst new file +19
-0+with "kernel." prefix [2]_. + +.. [1] See :ref:`Documentation/admin-guide/bootconfig.rst <bootconfig>` +.. [2] See :ref:`Documentation/admin-guide/kernel-parameters.rst <kernelparameters>` + +Ftrace Global Options +--------------------- + +Ftrace global options have "kernel." prefix in boot config, which means +these options are passed as a part of kernel legacy command line. + +kernel.tp_printk + Output trace-event data on printk buffer too. + +kernel.dump_on_oops [= MODE] + Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer + on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops. + +kernel.traceoff_on_warning
Documentation/trace/boottime-trace.rst line 53
Quoted 10 lines
Documentation/trace/boottime-trace.rst new file +10
-0+ Stop tracing if WARN_ON() occurs. + +kernel.fgraph_max_depth = MAX_DEPTH + Set MAX_DEPTH to maximum depth of fgraph tracer. + +kernel.fgraph_filters = FILTER[, FILTER2...] + Add fgraph tracing function filters. + +kernel.fgraph_notraces = FILTER[, FILTER2...] + Add fgraph non tracing function filters.
non-tracing
Quoted 21 lines
Documentation/trace/boottime-trace.rst new file +21
-0+ + +Ftrace Per-instance Options +--------------------------- + +These options can be used for each instance including global ftrace node. + +ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]] + Enable given ftrace options. + +ftrace.[instance.INSTANCE.]trace_clock = CLOCK + Set given CLOCK to ftrace's trace_clock. + +ftrace.[instance.INSTANCE.]buffer_size = SIZE + Configure ftrace buffer size to SIZE. You can use "KB" or "MB" + for that SIZE. + +ftrace.[instance.INSTANCE.]alloc_snapshot + Allocate snapshot buffer. + +ftrace.[instance.INSTANCE.]cpumask = CPUMASK
Documentation/trace/boottime-trace.rst line 84
Quoted 10 lines
Documentation/trace/boottime-trace.rst new file +10
-0+ Set CPUMASK as trace cpu-mask. + +ftrace.[instance.INSTANCE.]events = EVENT[, EVENT2[...]] + Enable given events on boot. You can use a wild card in EVENT. + +ftrace.[instance.INSTANCE.]tracer = TRACER + Set TRACER to current tracer on boot. (e.g. function) + +ftrace.[instance.INSTANCE.]ftrace.filters + This will take an array of tracing function filter rules
end with '.' as above descriptions.
Documentation/trace/boottime-trace.rst line 87
Quoted 3 lines
Documentation/trace/boottime-trace.rst new file +3
-0+ +ftrace.[instance.INSTANCE.]ftrace.notraces + This will take an array of NON-tracing function filter rules
ditto
Documentation/trace/boottime-trace.rst line 96
Quoted 9 lines
Documentation/trace/boottime-trace.rst new file +9
-0+ + +Ftrace Per-Event Options +------------------------ + +These options are setting per-event options. + +ftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable + Enables GROUP:EVENT tracing.
Enable
Quoted 42 lines
Documentation/trace/boottime-trace.rst new file +42
-0+ +ftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER + Set FILTER rule to the GROUP:EVENT. + +ftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2[...]] + Set ACTIONs to the GROUP:EVENT. + +ftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2[...]] + Defines new kprobe event based on PROBEs. It is able to define + multiple probes on one event, but those must have same type of + arguments. This option is available only for the event which + group name is "kprobes". + +ftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2[...]] + Defines new synthetic event with FIELDs. Each field should be + "type varname". + +Note that kprobe and synthetic event definitions can be written under +instance node, but those are also visible from other instances. So please +take care for event name conflict. + + +Examples +======== + +For example, to add filter and actions for each event, define kprobe +events, and synthetic events with histogram, write a boot config like +below:: + + ftrace.event { + task.task_newtask { + filter = "pid < 128" + enable + } + kprobes.vfs_read { + probes = "vfs_read $arg1 $arg2" + filter = "common_pid < 200" + enable + } + synthetic.initcall_latency { + fields = "unsigned long func", "u64 lat" + actions = "hist:keys=func.sym,lat:vals=lat:sort=lat"
Documentation/trace/boottime-trace.rst line 148
Quoted 10 lines
Documentation/trace/boottime-trace.rst new file +10
-0+ } + initcall.initcall_start { + actions = "hist:keys=func:ts0=common_timestamp.usecs" + } + initcall.initcall_finish { + actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)" + } + } + +Also, boottime tracing supports "instance" node, which allows us to run
boot-time [for consistency]
Documentation/trace/boottime-trace.rst line 150
Quoted 2 lines
Documentation/trace/boottime-trace.rst new file +2
-0+several tracers for different purpose at once. For example, one tracer +is for tracing functions start with "user\_", and others tracing "kernel\_"
starting
Quoted 24 lines
Documentation/trace/boottime-trace.rst new file +24
-0+functions, you can write boot config as below:: + + ftrace.instance { + foo { + tracer = "function" + ftrace.filters = "user_*" + } + bar { + tracer = "function" + ftrace.filters = "kernel_*" + } + } + +The instance node also accepts event nodes so that each instance +can customize its event tracing. + +This boot-time tracing also supports ftrace kernel parameters via boot +config. +For example, following kernel parameters:: + + trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M ftrace=function ftrace_filter="vfs*" + +This can be written in boot config like below:: +
Documentation/trace/boottime-trace.rst line 184
Quoted 10 lines
Documentation/trace/boottime-trace.rst new file +10
-0+ kernel { + trace_options = sym-addr + trace_event = "initcall:*" + tp_printk + trace_buf_size = 1M + ftrace = function + ftrace_filter = "vfs*" + } + +Note that parameters start with "kernel" prefix instead of "ftrace".
HTH.
Signature · 1 line
~Randy
Randy Dunlap
reviewerRe: [PATCH v6 09/22] Documentation: bootconfig: Add a doc for extended boot config
In reply to Masami HiramatsuHi,
Editorial comments/corrections below...
Quoted 4 lines · Masami Hiramatsu
Add a documentation for extended boot config under admin-guide, since it is including the syntax of boot config.
Signed-off-by Masami Hiramatsu <[email protected]>
Quoted 9 lines
---
Changes in v6:
- Add a note about comment after value.
Changes in v5:
- Fix to insert bootconfig to TOC list alphabetically.
- Add notes about avaliable characters in values.
- Fix to use correct quotes (``) for .rst.
Changes in v4:
- Rename suppremental kernel command line to boot config.
supplemental
Quoted 19 lines
- Update document according to the recent changes.
- Add How to load it on boot.
- Style bugfix.--- Documentation/admin-guide/bootconfig.rst | 184 ++++++++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 MAINTAINERS | 1 3 files changed, 186 insertions(+) create mode 100644 Documentation/admin-guide/bootconfig.rstDocumentation/admin-guide/bootconfig.rst new file +2
-0@@ -0,0 +1,184 @@ +.. SPDX-License-Identifier: GPL-2.0 +
Documentation/admin-guide/bootconfig.rst line 12
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+================== +Boot Configuration +================== + +:Author: Masami Hiramatsu <[email protected]> + +Overview +======== + +The boot configuration is expanding current kernel cmdline to support
expands the current kernel command line to support
Documentation/admin-guide/bootconfig.rst line 13
Quoted 1 line
Documentation/admin-guide/bootconfig.rst new file +1
-0+additional key-value data when boot the kernel in an efficient way.
booting
Documentation/admin-guide/bootconfig.rst line 14
Quoted 1 line
Documentation/admin-guide/bootconfig.rst new file +1
-0+This allows adoministrators to pass a structured-Key config file.
administrators
Documentation/admin-guide/bootconfig.rst line 24
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+ +Config File Syntax +================== + +The boot config syntax is a simple structured key-value. Each key consists +of dot-connected-words, and key and value are connected by "=". The value +has to be terminated by semi-colon (``;``) or newline (``\n``). +For array value, array entries are separated by comma (``,``). :: + +KEY[.WORD[...]] = VALUE[, VALUE2[...]][;]
(just a note: spaces are OK here, unlike in kernel command line syntax [unless quoted].)
Documentation/admin-guide/bootconfig.rst line 29
Quoted 5 lines
Documentation/admin-guide/bootconfig.rst new file +5
-0+ +Each key word must contain only alphabets, numbers, dash (``-``) or underscore +(``_``). And each value only contains printable characters or spaces except +for delimiters such as semi-colon (``;``), new-line (``\n``), comma (``,``), +hash (``#``) and closing brace (``}``).
what about opening brace '{'?
Documentation/admin-guide/bootconfig.rst line 36
Quoted 7 lines
Documentation/admin-guide/bootconfig.rst new file +7
-0+ +If you want to use those delimiters in a value, you can use either double- +quotes (``"VALUE"``) or single-quotes (``'VALUE'``) to quote it. Note that +you can not escape these quotes. + +There can be a key which doesn't have value or has an empty value. Those keys +are used for checking the key exists or not (like a boolean).
I would say: checking if the key exists or not
Quoted 18 lines
Documentation/admin-guide/bootconfig.rst new file +18
-0+ +Key-Value Syntax +---------------- + +The boot config file syntax allows user to merge partially same word keys +by brace. For example:: + + foo.bar.baz = value1 + foo.bar.qux.quux = value2 + +These can be written also in:: + + foo.bar { + baz = value1 + qux.quux = value2 + } + +Or more shorter, written as following::
Documentation/admin-guide/bootconfig.rst line 64
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+ + foo.bar { baz = value1; qux.quux = value2 } + +In both styles, same key words are automatically merged when parsing it +at boot time. So you can append similar trees or key-values. + +Comments +-------- + +The config syntax accepts shell-script style comments. The comments start
s/start/starting/
Quoted 35 lines
Documentation/admin-guide/bootconfig.rst new file +35
-0+with hash ("#") until newline ("\n") will be ignored. + +:: + + # comment line + foo = value # value is set to foo. + bar = 1, # 1st element + 2, # 2nd element + 3 # 3rd element + +This is parsed as below:: + + foo = value + bar = 1, 2, 3 + +Note that you can not put a comment between value and delimiter(``,`` or +``;``). This means following config has a syntax error :: + + key = 1 # comment + ,2 + + +/proc/bootconfig +================ + +/proc/bootconfig is a user-space interface of the boot config. +Unlike /proc/cmdline, this file shows the key-value style list. +Each key-value pair is shown in each line with following style:: + + KEY[.WORDS...] = "[VALUE]"[,"VALUE2"...] + + +Boot Kernel With a Boot Config +============================== +
Documentation/admin-guide/bootconfig.rst line 109
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+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. +Because of this "piggyback" method, there is no need to change or +update the boot loader and the kernel image itself. + +To do this operation, Linux kernel provides "bootconfig" command under +tools/bootconfig, which allows admin to apply or delete the config file +to/from initrd image. You can build it by follwoing command::
by the following
Quoted 4 lines
Documentation/admin-guide/bootconfig.rst new file +4
-0+ + # make -C tools/bootconfig + +To add your boot config file to initrd image, run bootconfig as below
Documentation/admin-guide/bootconfig.rst line 123
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+(Old data is removed automatically if exists):: + + # tools/bootconfig/bootconfig -a your-config /boot/initrd.img-X.Y.Z + +To remove the config from the image, you can use -d option as below:: + + # tools/bootconfig/bootconfig -d /boot/initrd.img-X.Y.Z + + +C onfig File Limitation
Config
Quoted 16 lines
Documentation/admin-guide/bootconfig.rst new file +16
-0+====================== + +Currently the maximum config size size is 32KB and the total key-words (not +key-value entries) must be under 1024 nodes. +Note: this is not the number of entries but nodes, an entry must consume +more than 2 nodes (a key-word and a value). So theoretically, it will be +up to 512 key-value pairs. If keys contains 3 words in average, it can +contain 256 key-value pairs. In most cases, the number of config items +will be under 100 entries and smaller than 8KB, so it would be enough. +If the node number exceeds 1024, parser returns an error even if the file +size is smaller than 32KB. +Anyway, since bootconfig command verifies it when appending a boot config +to initrd image, user can notice it before boot. + + +Bootconfig APIs
Documentation/admin-guide/bootconfig.rst line 149
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+=============== + +User can query or loop on key-value pairs, also it is possible to find +a root (prefix) key node and find key-values under that node. + +If you have a key string, you can query the value directly with the key +using xbc_find_value(). If you want to know what keys exist in the SKC +tree, you can use xbc_for_each_key_value() to iterate key-value pairs. +Note that you need to use xbc_array_for_each_value() for accessing +each arraies value, e.g.::
array's
(I think)
Documentation/admin-guide/bootconfig.rst line 158
Quoted 9 lines
Documentation/admin-guide/bootconfig.rst new file +9
-0+ + vnode = NULL; + xbc_find_value("key.word", &vnode); + if (vnode && xbc_node_is_array(vnode)) + xbc_array_for_each_value(vnode, value) { + printk("%s ", value); + } + +If you want to focus on keys which has a prefix string, you can use
have
Documentation/admin-guide/bootconfig.rst line 159
Quoted 1 line
Documentation/admin-guide/bootconfig.rst new file +1
-0+xbc_find_node() to find a node which prefix key words, and iterate
[confusing above]
Quoted 6 lines
Documentation/admin-guide/bootconfig.rst new file +6
-0+keys under the prefix node with xbc_node_for_each_key_value(). + +But the most typical usage is to get the named value under prefix +or get the named array under prefix as below:: + + root = xbc_find_node("key.prefix");
Documentation/admin-guide/bootconfig.rst line 175
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+ value = xbc_node_find_value(root, "option", &vnode); + ... + xbc_node_for_each_array_value(root, "array-option", value, anode) { + ... + } + +This accesses a value of "key.prefix.option" and an array of +"key.prefix.array-option". + +Locking is not needed, since after initialized, the config becomes readonly.
after initialization,
Documentation/admin-guide/bootconfig.rst line 184
Quoted 9 lines
Documentation/admin-guide/bootconfig.rst new file +9
-0+All data and keys must be copied if you need to modify it. + + +Functions and structures +======================== + +.. kernel-doc:: include/linux/bootconfig.h +.. kernel-doc:: lib/bootconfig.c +
HTH.
Signature · 1 line
~Randy
Randy Dunlap
reviewerRe: [PATCH v6 01/22] bootconfig: Add Extra Boot Config support
In reply to Masami HiramatsuQuoted 6 lines · Masami Hiramatsu
init/Kconfig +0
-0@@ -1215,6 +1215,17 @@ source "usr/Kconfig"
init/Kconfig source "usr/Kconfig" · line 1225
Quoted 10 lines
init/Kconfig +8
-0endif +config BOOT_CONFIG + bool "Boot config support" + select LIBXBC + default y + help + Extra boot config allows system admin to pass a config file as + complemental extension of kernel cmdline when booting. + The boot config file is usually attached at the end of initramfs.
Is there some other location where it might be attached? Please explain.
Quoted 6 lines
init/Kconfig +3
-0+ + If unsure, say Y. + choice prompt "Compiler optimization level" default CC_OPTIMIZE_FOR_PERFORMANCE
Signature · 1 line
~Randy
Masami Hiramatsu
maintainerRe: [PATCH v6 01/22] bootconfig: Add Extra Boot Config support
Quoted 9 lines · On Sat, 18 Jan 2020 10:33:01 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 8 lines · Masami Hiramatsu
init/Kconfig +0
-0@@ -1215,6 +1215,17 @@ source "usr/Kconfig" endif
Quoted 11 lines
init/Kconfig source "usr/Kconfig" · line 1225
Quoted 8 lines
init/Kconfig +8
-0+config BOOT_CONFIG + bool "Boot config support" + select LIBXBC + default y + help + Extra boot config allows system admin to pass a config file as + complemental extension of kernel cmdline when booting. + The boot config file is usually attached at the end of initramfs.Is there some other location where it might be attached? Please explain.
Oops, good catch!
No, it supports only initramfs.
I missed to leave the comment written in planning phase. I need to update it.
Thank you!
Quoted 11 lines
Quoted 7 lines
init/Kconfig +3
-0+ + If unsure, say Y. + choice prompt "Compiler optimization level" default CC_OPTIMIZE_FOR_PERFORMANCESignature · 1 line
~Randy
Signature · 1 line
Masami Hiramatsu <[email protected]>
Masami Hiramatsu
maintainerRe: [PATCH v6 09/22] Documentation: bootconfig: Add a doc for extended boot config
In reply to Randy DunlapHi Randy,
Quoted 3 lines · On Sat, 18 Jan 2020 10:28:40 -0800 Randy Dunlap <[email protected]> wrote:
Hi,
Editorial comments/corrections below...
Thank you for your comments! This is very helpful for me.
Quoted 41 lines · Masami Hiramatsu
Quoted 4 lines
Add a documentation for extended boot config under admin-guide, since it is including the syntax of boot config.
Signed-off-by Masami Hiramatsu <[email protected]>Quoted 9 lines
---
Changes in v6:
- Add a note about comment after value.
Changes in v5:
- Fix to insert bootconfig to TOC list alphabetically.
- Add notes about avaliable characters in values.
- Fix to use correct quotes (``) for .rst.
Changes in v4:
- Rename suppremental kernel command line to boot config.supplemental
Quoted 23 lines
- Update document according to the recent changes.
- Add How to load it on boot.
- Style bugfix.--- Documentation/admin-guide/bootconfig.rst | 184 ++++++++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 MAINTAINERS | 1 3 files changed, 186 insertions(+) create mode 100644 Documentation/admin-guide/bootconfig.rstDocumentation/admin-guide/bootconfig.rst new file +6
-0@@ -0,0 +1,184 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================== +Boot Configuration +================== +
Quoted 8 lines
Documentation/admin-guide/bootconfig.rst line 12
Quoted 6 lines
Documentation/admin-guide/bootconfig.rst new file +6
-0+:Author: Masami Hiramatsu <[email protected]> + +Overview +======== + +The boot configuration is expanding current kernel cmdline to supportexpands the current kernel command line to support
OK.
Quoted 4 lines
Documentation/admin-guide/bootconfig.rst line 13
Quoted 2 lines
Documentation/admin-guide/bootconfig.rst new file +1
-0+additional key-value data when boot the kernel in an efficient way.booting
OK.
Quoted 4 lines
Documentation/admin-guide/bootconfig.rst line 14
Quoted 2 lines
Documentation/admin-guide/bootconfig.rst new file +1
-0+This allows adoministrators to pass a structured-Key config file.administrators
Oops. OK.
Quoted 13 lines
Documentation/admin-guide/bootconfig.rst line 24
Quoted 11 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+ +Config File Syntax +================== + +The boot config syntax is a simple structured key-value. Each key consists +of dot-connected-words, and key and value are connected by "=". The value +has to be terminated by semi-colon (``;``) or newline (``\n``). +For array value, array entries are separated by comma (``,``). :: + +KEY[.WORD[...]] = VALUE[, VALUE2[...]][;](just a note: spaces are OK here, unlike in kernel command line syntax [unless quoted].)
Yes.
Quoted 7 lines
Documentation/admin-guide/bootconfig.rst line 29
Quoted 5 lines
Documentation/admin-guide/bootconfig.rst new file +5
-0+ +Each key word must contain only alphabets, numbers, dash (``-``) or underscore +(``_``). And each value only contains printable characters or spaces except +for delimiters such as semi-colon (``;``), new-line (``\n``), comma (``,``), +hash (``#``) and closing brace (``}``).what about opening brace '{'?
Good question! Since the bootconfig doesn't support anonymous key-word block, opening brace doesn't become a delimiter. (So, the above explanation might better use "except for *some* delimiters"...)
For example, following data should be wrong.
key = value { key2 = value }
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst line 36
Quoted 8 lines
Documentation/admin-guide/bootconfig.rst new file +7
-0+ +If you want to use those delimiters in a value, you can use either double- +quotes (``"VALUE"``) or single-quotes (``'VALUE'``) to quote it. Note that +you can not escape these quotes. + +There can be a key which doesn't have value or has an empty value. Those keys +are used for checking the key exists or not (like a boolean).I would say: checking if the key exists or not
OK.
Quoted 23 lines
Quoted 23 lines
Documentation/admin-guide/bootconfig.rst new file +22
-0+ +Key-Value Syntax +---------------- + +The boot config file syntax allows user to merge partially same word keys +by brace. For example:: + + foo.bar.baz = value1 + foo.bar.qux.quux = value2 + +These can be written also in:: + + foo.bar { + baz = value1 + qux.quux = value2 + } + +Or more shorter, written as following:: + + foo.bar { baz = value1; qux.quux = value2 } + +In both styles, same key words are automatically merged when parsing it
Quoted 8 lines
Documentation/admin-guide/bootconfig.rst line 64
Quoted 6 lines
Documentation/admin-guide/bootconfig.rst new file +6
-0+at boot time. So you can append similar trees or key-values. + +Comments +-------- + +The config syntax accepts shell-script style comments. The comments starts/start/starting/
OK.
Quoted 40 lines
Quoted 40 lines
Documentation/admin-guide/bootconfig.rst new file +39
-0+with hash ("#") until newline ("\n") will be ignored. + +:: + + # comment line + foo = value # value is set to foo. + bar = 1, # 1st element + 2, # 2nd element + 3 # 3rd element + +This is parsed as below:: + + foo = value + bar = 1, 2, 3 + +Note that you can not put a comment between value and delimiter(``,`` or +``;``). This means following config has a syntax error :: + + key = 1 # comment + ,2 + + +/proc/bootconfig +================ + +/proc/bootconfig is a user-space interface of the boot config. +Unlike /proc/cmdline, this file shows the key-value style list. +Each key-value pair is shown in each line with following style:: + + KEY[.WORDS...] = "[VALUE]"[,"VALUE2"...] + + +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.
Quoted 8 lines
Documentation/admin-guide/bootconfig.rst line 109
Quoted 6 lines
Documentation/admin-guide/bootconfig.rst new file +6
-0+Because of this "piggyback" method, there is no need to change or +update the boot loader and the kernel image itself. + +To do this operation, Linux kernel provides "bootconfig" command under +tools/bootconfig, which allows admin to apply or delete the config file +to/from initrd image. You can build it by follwoing command::by the following
Oops, a typo...
Quoted 17 lines
Quoted 5 lines
Documentation/admin-guide/bootconfig.rst new file +4
-0+ + # make -C tools/bootconfig + +To add your boot config file to initrd image, run bootconfig as belowDocumentation/admin-guide/bootconfig.rst line 123
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+(Old data is removed automatically if exists):: + + # tools/bootconfig/bootconfig -a your-config /boot/initrd.img-X.Y.Z + +To remove the config from the image, you can use -d option as below:: + + # tools/bootconfig/bootconfig -d /boot/initrd.img-X.Y.Z + + +C onfig File LimitationConfig
Oops
Quoted 22 lines
Quoted 22 lines
Documentation/admin-guide/bootconfig.rst new file +21
-0+====================== + +Currently the maximum config size size is 32KB and the total key-words (not +key-value entries) must be under 1024 nodes. +Note: this is not the number of entries but nodes, an entry must consume +more than 2 nodes (a key-word and a value). So theoretically, it will be +up to 512 key-value pairs. If keys contains 3 words in average, it can +contain 256 key-value pairs. In most cases, the number of config items +will be under 100 entries and smaller than 8KB, so it would be enough. +If the node number exceeds 1024, parser returns an error even if the file +size is smaller than 32KB. +Anyway, since bootconfig command verifies it when appending a boot config +to initrd image, user can notice it before boot. + + +Bootconfig APIs +=============== + +User can query or loop on key-value pairs, also it is possible to find +a root (prefix) key node and find key-values under that node. +
Quoted 8 lines
Documentation/admin-guide/bootconfig.rst line 149
Quoted 5 lines
Documentation/admin-guide/bootconfig.rst new file +5
-0+If you have a key string, you can query the value directly with the key +using xbc_find_value(). If you want to know what keys exist in the SKC +tree, you can use xbc_for_each_key_value() to iterate key-value pairs. +Note that you need to use xbc_array_for_each_value() for accessing +each arraies value, e.g.::array's
(I think)
Yes, OK.
Quoted 12 lines
Documentation/admin-guide/bootconfig.rst line 158
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +9
-0+ + vnode = NULL; + xbc_find_value("key.word", &vnode); + if (vnode && xbc_node_is_array(vnode)) + xbc_array_for_each_value(vnode, value) { + printk("%s ", value); + } + +If you want to focus on keys which has a prefix string, you can usehave
OK.
Quoted 4 lines
Documentation/admin-guide/bootconfig.rst line 159
Quoted 2 lines
Documentation/admin-guide/bootconfig.rst new file +1
-0+xbc_find_node() to find a node which prefix key words, and iterate[confusing above]
Ah, it should be "to find a node by the prefix string,"
Quoted 11 lines
Quoted 11 lines
Documentation/admin-guide/bootconfig.rst new file +10
-0+keys under the prefix node with xbc_node_for_each_key_value(). + +But the most typical usage is to get the named value under prefix +or get the named array under prefix as below:: + + root = xbc_find_node("key.prefix"); + value = xbc_node_find_value(root, "option", &vnode); + ... + xbc_node_for_each_array_value(root, "array-option", value, anode) { + ...
Quoted 8 lines
Documentation/admin-guide/bootconfig.rst line 175
Quoted 6 lines
Documentation/admin-guide/bootconfig.rst new file +6
-0+ } + +This accesses a value of "key.prefix.option" and an array of +"key.prefix.array-option". + +Locking is not needed, since after initialized, the config becomes readonly.after initialization,
OK.
Quoted 12 lines
Documentation/admin-guide/bootconfig.rst line 184
Quoted 10 lines
Documentation/admin-guide/bootconfig.rst new file +9
-0+All data and keys must be copied if you need to modify it. + + +Functions and structures +======================== + +.. kernel-doc:: include/linux/bootconfig.h +.. kernel-doc:: lib/bootconfig.c +HTH.
Thank you very much!
Quoted 2 lines
Signature · 1 line
~Randy
Signature · 1 line
Masami Hiramatsu <[email protected]>
Masami Hiramatsu
maintainerRe: [PATCH v6 22/22] Documentation: tracing: Add boot-time tracing document
In reply to Randy DunlapHi Randy,
Thank you for your comments!
Quoted 42 lines · On Sat, 18 Jan 2020 10:14:08 -0800 Randy Dunlap <[email protected]> wrote:
Hi,
Here are a few editorial comments for you...
Quoted 36 lines · Masami Hiramatsu
Add a documentation about boot-time tracing options in boot config.
Signed-off-by Masami Hiramatsu <[email protected]>--- Documentation/admin-guide/bootconfig.rst | 2 Documentation/trace/boottime-trace.rst | 184 ++++++++++++++++++++++++++++++ Documentation/trace/index.rst | 1 3 files changed, 187 insertions(+) create mode 100644 Documentation/trace/boottime-trace.rstDocumentation/trace/boottime-trace.rst new file +18
-0@@ -0,0 +1,184 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +Boot-time tracing +================= + +:Author: Masami Hiramatsu <[email protected]> + +Overview +======== + +Boot-time tracing allows users to trace boot-time process including +device initialization with full features of ftrace including per-event +filter and actions, histograms, kprobe-events and synthetic-events, +and trace instances. +Since kernel cmdline is not enough to control these complex features, +this uses bootconfig file to describe tracing feature programming. +
Quoted 8 lines
Documentation/trace/boottime-trace.rst line 24
Quoted 6 lines
Documentation/trace/boottime-trace.rst new file +6
-0+Options in the Boot Config +========================== + +Here is the list of available options list for boot time tracing in +boot config file [1]_. All options are under "ftrace." or "kernel." +refix. See kernel parameters for the options which startsprefix.
Oops, OK.
Quoted 24 lines
Quoted 24 lines
Documentation/trace/boottime-trace.rst new file +23
-0+with "kernel." prefix [2]_. + +.. [1] See :ref:`Documentation/admin-guide/bootconfig.rst <bootconfig>` +.. [2] See :ref:`Documentation/admin-guide/kernel-parameters.rst <kernelparameters>` + +Ftrace Global Options +--------------------- + +Ftrace global options have "kernel." prefix in boot config, which means +these options are passed as a part of kernel legacy command line. + +kernel.tp_printk + Output trace-event data on printk buffer too. + +kernel.dump_on_oops [= MODE] + Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer + on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops. + +kernel.traceoff_on_warning + Stop tracing if WARN_ON() occurs. + +kernel.fgraph_max_depth = MAX_DEPTH + Set MAX_DEPTH to maximum depth of fgraph tracer.
Quoted 8 lines
Documentation/trace/boottime-trace.rst line 53
Quoted 6 lines
Documentation/trace/boottime-trace.rst new file +6
-0+ +kernel.fgraph_filters = FILTER[, FILTER2...] + Add fgraph tracing function filters. + +kernel.fgraph_notraces = FILTER[, FILTER2...] + Add fgraph non tracing function filters.non-tracing
OK.
Quoted 26 lines
Quoted 26 lines
Documentation/trace/boottime-trace.rst new file +25
-0+ + +Ftrace Per-instance Options +--------------------------- + +These options can be used for each instance including global ftrace node. + +ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]] + Enable given ftrace options. + +ftrace.[instance.INSTANCE.]trace_clock = CLOCK + Set given CLOCK to ftrace's trace_clock. + +ftrace.[instance.INSTANCE.]buffer_size = SIZE + Configure ftrace buffer size to SIZE. You can use "KB" or "MB" + for that SIZE. + +ftrace.[instance.INSTANCE.]alloc_snapshot + Allocate snapshot buffer. + +ftrace.[instance.INSTANCE.]cpumask = CPUMASK + Set CPUMASK as trace cpu-mask. + +ftrace.[instance.INSTANCE.]events = EVENT[, EVENT2[...]] + Enable given events on boot. You can use a wild card in EVENT.
Quoted 8 lines
Documentation/trace/boottime-trace.rst line 84
Quoted 6 lines
Documentation/trace/boottime-trace.rst new file +6
-0+ +ftrace.[instance.INSTANCE.]tracer = TRACER + Set TRACER to current tracer on boot. (e.g. function) + +ftrace.[instance.INSTANCE.]ftrace.filters + This will take an array of tracing function filter rulesend with '.' as above descriptions.
Yes, I missed it.
Quoted 6 lines
Documentation/trace/boottime-trace.rst line 87
Quoted 4 lines
Documentation/trace/boottime-trace.rst new file +3
-0+ +ftrace.[instance.INSTANCE.]ftrace.notraces + This will take an array of NON-tracing function filter rulesditto
OK.
Quoted 12 lines
Documentation/trace/boottime-trace.rst line 96
Quoted 10 lines
Documentation/trace/boottime-trace.rst new file +9
-0+ + +Ftrace Per-Event Options +------------------------ + +These options are setting per-event options. + +ftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable + Enables GROUP:EVENT tracing.Enable
OK.
Quoted 47 lines
Quoted 47 lines
Documentation/trace/boottime-trace.rst new file +46
-0+ +ftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER + Set FILTER rule to the GROUP:EVENT. + +ftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2[...]] + Set ACTIONs to the GROUP:EVENT. + +ftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2[...]] + Defines new kprobe event based on PROBEs. It is able to define + multiple probes on one event, but those must have same type of + arguments. This option is available only for the event which + group name is "kprobes". + +ftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2[...]] + Defines new synthetic event with FIELDs. Each field should be + "type varname". + +Note that kprobe and synthetic event definitions can be written under +instance node, but those are also visible from other instances. So please +take care for event name conflict. + + +Examples +======== + +For example, to add filter and actions for each event, define kprobe +events, and synthetic events with histogram, write a boot config like +below:: + + ftrace.event { + task.task_newtask { + filter = "pid < 128" + enable + } + kprobes.vfs_read { + probes = "vfs_read $arg1 $arg2" + filter = "common_pid < 200" + enable + } + synthetic.initcall_latency { + fields = "unsigned long func", "u64 lat" + actions = "hist:keys=func.sym,lat:vals=lat:sort=lat" + } + initcall.initcall_start { + actions = "hist:keys=func:ts0=common_timestamp.usecs" + }
Quoted 8 lines
Documentation/trace/boottime-trace.rst line 148
Quoted 6 lines
Documentation/trace/boottime-trace.rst new file +6
-0+ initcall.initcall_finish { + actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)" + } + } + +Also, boottime tracing supports "instance" node, which allows us to runboot-time [for consistency]
OK.
Quoted 5 lines
Documentation/trace/boottime-trace.rst line 150
Quoted 3 lines
Documentation/trace/boottime-trace.rst new file +2
-0+several tracers for different purpose at once. For example, one tracer +is for tracing functions start with "user\_", and others tracing "kernel\_"starting
OK.
Quoted 29 lines
Quoted 29 lines
Documentation/trace/boottime-trace.rst new file +28
-0+functions, you can write boot config as below:: + + ftrace.instance { + foo { + tracer = "function" + ftrace.filters = "user_*" + } + bar { + tracer = "function" + ftrace.filters = "kernel_*" + } + } + +The instance node also accepts event nodes so that each instance +can customize its event tracing. + +This boot-time tracing also supports ftrace kernel parameters via boot +config. +For example, following kernel parameters:: + + trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M ftrace=function ftrace_filter="vfs*" + +This can be written in boot config like below:: + + kernel { + trace_options = sym-addr + trace_event = "initcall:*" + tp_printk
Quoted 8 lines
Documentation/trace/boottime-trace.rst line 184
Quoted 6 lines
Documentation/trace/boottime-trace.rst new file +6
-0+ trace_buf_size = 1M + ftrace = function + ftrace_filter = "vfs*" + } + +Note that parameters start with "kernel" prefix instead of "ftrace".HTH.
Very helpful. Thanks!
Signature · 1 line
Masami Hiramatsu <[email protected]>
Masami Hiramatsu
maintainerHi Steve,
Thanks for pick this series on your tree. I would like to fix some patches according to Randy's comments. Should I update this series or just incremental updates on top of your tree?
Thank you,
Quoted 340 lines · On Sat, 11 Jan 2020 01:03:20 +0900 Masami Hiramatsu <[email protected]> wrote:
Hello,
This is the 6th version of the series for the boot-time tracing.
Previous version is here.
https://lkml.kernel.org/r/157736902773.11126.2531161235817081873.stgit@devnote2
Thanks Steve for reivew. I fixed issues in this version.
- [1/22] Remove "!!" from
xbc_node_is_value(). Redefinexbc_node_is_key()as "!xbc_node_is_value()". Fix a memory leak and a bug in__xbc_parse_value(). Addxbc_destroy_all()to clean up the parsed data. Fix to treat comment right after value as a newline.- [3/22] Fix memory leaks.
Fix to cleanup old bootconfig on memory before load new one. Show applying message.
Suppress parse error with wrong data in initrd fordelete_xbc().- [4/22] Add some testcases for value parser
Add a test case for checking delete old bootconfig- [9/22] Add a note about comment after value.
- [21/22] Fix to depend on
CONFIG_DYNAMIC_FTRACEinstead ofCONFIG_FUNCTION_TRACER.This series can be applied on v5.5-rc5 or directly available at;
https://github.com/mhiramat/linux.git ftrace-boottrace-v6
Extra Boot Config
=================Extra boot config allows admin to pass a tree-structured key-value list when booting up the kernel. This expands the kernel command line in an efficient way.
Each key is described as a dot-jointed-words. And user can write the key-words in tree stlye. (In this version, the tailing ';' becomes optional. See
Documentation/admin-guide/bootconfig.rst)For example,
feature.option.foo = 1
feature.option.bar = 2can be also written in
feature.option { foo = 1 bar = 2}
or more compact,
feature.option{foo=1;bar=2}
(Note that in both style, the same words are merged automatically
and make a single tree)
All values are treated as a string, or array of strings, e.g.feature.options = "foo", "bar"
User can see the loaded key-value list via
/proc/bootconfig. The size is limited upto 32KB and 1024 key-words and values in total.Boot with a Boot Config
=======================This version doesn't require to modify boot loaders anymore. The boot config is loaded with initrd, and there is new "bootconfig" command under
tools/bootconfig.
To add (append) a bootconfig file to an initrd, you can use the bootconfig command like:# tools/bootconfig/bootconfig -a your-config /boot/initrd.img-X.Y.ZThis verifies the configuration file too.
Boot-time Tracing
=================Boot-time tracing supports following boot configs. Please read
Documentation/trace/boottime-trace.rstfor details.- kernel.dump_on_oops [= MODE]
- kernel.traceoff_on_warning
- kernel.tp_printk
- kernel.fgraph_filters = FILTER[, FILTER2...]
- kernel.fgraph_notraces = FILTER[, FILTER2...]
- kernel.fgraph_max_depth =MAX_DEPTH
- ftrace.[instance.INSTANCE.]options = OPT1[,OPT2...]
- ftrace.[instance.INSTANCE.]trace_clock = CLOCK
- ftrace.[instance.INSTANCE.]buffer_size = SIZE
- ftrace.[instance.INSTANCE.]alloc_snapshot
- ftrace.[instance.INSTANCE.]cpumask = CPUMASK
- ftrace.[instance.INSTANCE.]events = EVENT[, EVENT2...]
- ftrace.[instance.INSTANCE.]tracer = TRACER
- ftrace.[instance.INSTANCE.]ftrace.filters
- ftrace.[instance.INSTANCE.]ftrace.notraces
- ftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER
- ftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2...]
- ftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable
- ftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2...]
- ftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2...]Kernel and Init Command Line
============================Boot config also supports kernel and init command line parameters except for early kernel parameters.
In boot config, all key-values start with "kernel." are automatically merged into user passed boot command line, and key-values which start with "init." are also passed to init. These options are visible on
/proc/cmdline.For example,
kernel {
audit = on
audit_backlog_limit= 256
}
init.systemd.unified_cgroup_hierarchy = 1Usage
=====With this series, we can setup new kprobe and synthetic events, more complicated event filters and trigger actions including histogram via supplemental kernel cmdline.
We can add filter and actions for each event, define kprobe events, and synthetic events with histogram like below.
ftrace.event { task.task_newtask { filter = "pid < 128" enable } kprobes.vfs_read { probes = "vfs_read $arg1 $arg2" filter = "common_pid < 200" enable } synthetic.initcall_latency { fields = "unsigned long func", "u64 lat" actions = "hist:keys=func.sym,lat:vals=lat:sort=lat" } initcall.initcall_start { actions = "hist:keys=func:ts0=common_timestamp.usecs" } initcall.initcall_finish { actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)" } }Also, this supports "instance" node, which allows us to run several tracers for different purpose at once. For example, one tracer is for tracing functions start with "
user_", and others tracing "kernel_", you can write boot config as:ftrace.instance { foo { tracer = "function" ftrace-filters = "user_*" } bar { tracer = "function" ftrace-filters = "function_*" } }The instance node also accepts event nodes so that each instance can customize its event tracing.
This boot-time trace also supports ftrace kernel parameters. For example, following kernel parameters
trace_options=sym-addr trace_event=initcall:*
tp_printktrace_buf_size=1M ftrace=function ftrace_filter="vfs*"it can be written in boot config like below.
ftrace {
options = sym-addr
events = "initcall:*"
tp-printk
buffer-size = 1MB
ftrace-filters = "vfs*"
}However, since the initialization timing is different, if you need to trace very early boot, please use normal kernel parameters.
Some Notes
==========- To align the legacy command line rule, I made the quotes (double quotes or single quotes) not able to be escaped.
Also, this rejects non-printable chars (except for space). Actually legacy cmdline accepts any of them, but it might confuse users if they put a control code by mistake. Imagine that they put a "\b" on it...- Since it is not easy to write boot-time tracing without any bug in bootconfig, a user-helper command will be needed. That command will generate a boot config file from current ftrace settings, or try to apply given boot config setting to the ftrace.
Thank you,
---
Masami Hiramatsu (22):
bootconfig: Add Extra Boot Config support
bootconfig: Load boot config from the tail of initrd
tools: bootconfig: Add bootconfig command
tools: bootconfig: Add bootconfig test script
proc: bootconfig: Add/proc/bootconfigto show boot config listinit/main.c: Allocinitcall_command_lineindo_initcall()and free it
bootconfig: init: Allow admin to use bootconfig for kernel command line
bootconfig: init: Allow admin to use bootconfig for init command line
Documentation: bootconfig: Add a doc for extended boot config
tracing: Apply soft-disabled and filter to tracepoints printk
tracing: kprobes: Output kprobe event to printk buffer
tracing: kprobes: Register to dynevent earlier stage
tracing: Accept different type for synthetic event fields
tracing: Add NULL trace-array check inprint_synth_event()tracing/boot: Add boot-time tracing
tracing/boot: Add per-event settings
tracing/boot Add kprobe event support
tracing/boot: Add synthetic event support
tracing/boot: Add instance node support
tracing/boot: Addcpu_maskoption support
tracing/boot: Add function tracer filter options
Documentation: tracing: Add boot-time tracing documentDocumentation/admin-guide/bootconfig.rst | 186 +++++ Documentation/admin-guide/index.rst | 1 Documentation/trace/boottime-trace.rst | 184 +++++ Documentation/trace/index.rst | 1 MAINTAINERS | 9 fs/proc/Makefile | 1 fs/proc/bootconfig.c | 89 ++ include/linux/bootconfig.h | 224 ++++++ include/linux/trace_events.h | 1 init/Kconfig | 12 init/main.c | 213 +++++ kernel/trace/Kconfig | 9 kernel/trace/Makefile | 1 kernel/trace/trace.c | 63 +- kernel/trace/trace_boot.c | 353 +++++++++ kernel/trace/trace_events.c | 1 kernel/trace/trace_events_hist.c | 14 kernel/trace/trace_events_trigger.c | 2 kernel/trace/trace_kprobe.c | 81 +- lib/Kconfig | 3 lib/Makefile | 2 lib/bootconfig.c | 803 ++++++++++++++++++++ tools/Makefile | 11 tools/bootconfig/.gitignore | 1 tools/bootconfig/Makefile | 23 + tools/bootconfig/include/linux/bootconfig.h | 7 tools/bootconfig/include/linux/bug.h | 12 tools/bootconfig/include/linux/ctype.h | 7 tools/bootconfig/include/linux/errno.h | 7 tools/bootconfig/include/linux/kernel.h | 18 tools/bootconfig/include/linux/printk.h | 17 tools/bootconfig/include/linux/string.h | 32 + tools/bootconfig/main.c | 354 +++++++++ .../samples/bad-array-space-comment.bconf | 5 tools/bootconfig/samples/bad-array.bconf | 2 tools/bootconfig/samples/bad-dotword.bconf | 4 tools/bootconfig/samples/bad-empty.bconf | 1 tools/bootconfig/samples/bad-keyerror.bconf | 2 tools/bootconfig/samples/bad-longkey.bconf | 1 tools/bootconfig/samples/bad-manywords.bconf | 1 tools/bootconfig/samples/bad-no-keyword.bconf | 2 tools/bootconfig/samples/bad-nonprintable.bconf | 2 tools/bootconfig/samples/bad-spaceword.bconf | 2 tools/bootconfig/samples/bad-tree.bconf | 5 tools/bootconfig/samples/bad-value.bconf | 3 tools/bootconfig/samples/escaped.bconf | 3 .../samples/good-array-space-comment.bconf | 4 .../samples/good-comment-after-value.bconf | 1 tools/bootconfig/samples/good-printables.bconf | 2 tools/bootconfig/samples/good-simple.bconf | 11 tools/bootconfig/samples/good-single.bconf | 4 .../samples/good-space-after-value.bconf | 1 tools/bootconfig/samples/good-tree.bconf | 12 tools/bootconfig/test-bootconfig.sh | 105 +++ 54 files changed, 2836 insertions(+), 79 deletions(-) create mode 100644 Documentation/admin-guide/bootconfig.rst create mode 100644 Documentation/trace/boottime-trace.rst create mode 100644 fs/proc/bootconfig.c create mode 100644 include/linux/bootconfig.h create mode 100644 kernel/trace/trace_boot.c create mode 100644 lib/bootconfig.c create mode 100644 tools/bootconfig/.gitignore create mode 100644 tools/bootconfig/Makefile create mode 100644 tools/bootconfig/include/linux/bootconfig.h create mode 100644 tools/bootconfig/include/linux/bug.h create mode 100644 tools/bootconfig/include/linux/ctype.h create mode 100644 tools/bootconfig/include/linux/errno.h create mode 100644 tools/bootconfig/include/linux/kernel.h create mode 100644 tools/bootconfig/include/linux/printk.h create mode 100644 tools/bootconfig/include/linux/string.h create mode 100644 tools/bootconfig/main.c create mode 100644 tools/bootconfig/samples/bad-array-space-comment.bconf create mode 100644 tools/bootconfig/samples/bad-array.bconf create mode 100644 tools/bootconfig/samples/bad-dotword.bconf create mode 100644 tools/bootconfig/samples/bad-empty.bconf create mode 100644 tools/bootconfig/samples/bad-keyerror.bconf create mode 100644 tools/bootconfig/samples/bad-longkey.bconf create mode 100644 tools/bootconfig/samples/bad-manywords.bconf create mode 100644 tools/bootconfig/samples/bad-no-keyword.bconf create mode 100644 tools/bootconfig/samples/bad-nonprintable.bconf create mode 100644 tools/bootconfig/samples/bad-spaceword.bconf create mode 100644 tools/bootconfig/samples/bad-tree.bconf create mode 100644 tools/bootconfig/samples/bad-value.bconf create mode 100644 tools/bootconfig/samples/escaped.bconf create mode 100644 tools/bootconfig/samples/good-array-space-comment.bconf create mode 100644 tools/bootconfig/samples/good-comment-after-value.bconf create mode 100644 tools/bootconfig/samples/good-printables.bconf create mode 100644 tools/bootconfig/samples/good-simple.bconf create mode 100644 tools/bootconfig/samples/good-single.bconf create mode 100644 tools/bootconfig/samples/good-space-after-value.bconf create mode 100644 tools/bootconfig/samples/good-tree.bconf create mode 100755 tools/bootconfig/test-bootconfig.sh--
Masami Hiramatsu (Linaro) <[email protected]>
Signature · 1 line
Masami Hiramatsu <[email protected]>
Steven Rostedt
maintainerQuoted 6 lines · On Sun, 19 Jan 2020 23:20:37 +0900 Masami Hiramatsu <[email protected]> wrote:
Hi Steve,
Thanks for pick this series on your tree. I would like to fix some patches according to Randy's comments. Should I update this series or just incremental updates on top of your tree?
Hi Masami,
Just send me incremental patches. I try not to ever rebase what I push to linux-next (except for adding changes that don't affect the content of the code, like adding acked-by to commit messages).
Thanks,
-- Steve
Re: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line
In reply to Masami HiramatsuQuoted 74 lines · Masami Hiramatsu
Since the current kernel command line is too short to describe long and many options for init (e.g. systemd command line options), this allows admin to use boot config for init command line.
All init command line under "init." keywords will be passed to init.
For example,
init.systemd {
unified_cgroup_hierarchy= 1
debug_shell
default_timeout_start_sec= 60
}Signed-off-by Masami Hiramatsu <[email protected]>--- init/main.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)init/main.c +15
-3@@ -139,6 +139,8 @@ char *saved_command_line;static char *static_command_line;/* Untouched extra command line */ static char *extra_command_line; +/* Extra init arguments */ +static char *extra_init_args;static char *execute_command;static char *ramdisk_execute_command;@@ -372,6 +374,8 @@ static void __init setup_boot_config(void)pr_info ("Load boot config: %d bytes\n" , size);/* keys starting with "kernel." are passed via cmdline */ extra_command_line =xbc_make_cmdline ("kernel" ); +/* Also, "init." keys are init arguments */ + extra_init_args = xbc_make_cmdline("init"); } }#else @@ -507,16 +511,18 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { }*/ static void __init setup_command_line (char *command_line) { -size_t len, xlen =0 ; +size_t len, xlen =0 , ilen =0 ;if (extra_command_line) xlen =strlen (extra_command_line); +if (extra_init_args) + ilen =strlen (extra_init_args) +4 ;/* for " -- " */ len = xlen +strlen (boot_command_line) +1 ; - saved_command_line =memblock_alloc (len,SMP_CACHE_BYTES ); + saved_command_line =memblock_alloc (len + ilen,SMP_CACHE_BYTES );if (!saved_command_line) -panic ("%s: Failed to allocate %zu bytes\n" , __func__, len); +panic ("%s: Failed to allocate %zu bytes\n" , __func__, len + ilen); static_command_line =memblock_alloc (len,SMP_CACHE_BYTES );if (!static_command_line)@@ -533,6 +539,22 @@ static void __init setup_command_line(char *command_line) }strcpy (saved_command_line + xlen, boot_command_line);strcpy (static_command_line + xlen, command_line); + +if (ilen) { +/* +* Append supplemental init boot args to saved_command_line +* so that user can check what command line options passed +* to init.
init/main.c static void __init setup_command_line(char *command_line) · line 557
Quoted 10 lines
init/main.c +10
-0+*/ + len =strlen (saved_command_line); +if (!strstr (boot_command_line," -- " )) { +strcpy (saved_command_line + len," -- " ); + len +=4 ; + }else + saved_command_line[len++] =' ' ; + +strcpy (saved_command_line + len, extra_init_args); + }
This isn't safe because it will destroy any argument with " -- " in quotes and anything after it. For example, booting with:
thing=on acpi_osi="! -- " other=setting
will wreck acpi_osi's value and potentially overwrite "other=settings", etc.
(Yes, this seems very unlikely, but you can't treat " -- " as special, the command line string must be correct parsed for double quotes, as parse_args() does.)
init/main.c asmlinkage __visible void __init start_kernel(void) · line 786
Quoted 10 lines
init/main.c +3
-0}/* @@ -759,6 +781,9 @@ asmlinkage __visible void __init start_kernel(void)if (!IS_ERR_OR_NULL (after_dashes))parse_args ("Setting init args" , after_dashes,NULL ,0 ,-1 ,-1 ,NULL , set_init_arg); +if (extra_init_args) +parse_args ("Setting extra init args" , extra_init_args, +NULL ,0 ,-1 ,-1 ,NULL , set_init_arg);
Here is where you can append the extra_init_args, since parse_args() will have done the work to find after_dashes correctly.
-Kees
Quoted 4 lines
init/main.c +0
-0/* * These use large bootmem allocations and must precede
Signature · 1 line
Kees Cook
Re: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line
Quoted 20 lines · Kees Cook
Quoted 6 lines
init/main.c +6
-0+ +if (ilen) { +/* +* Append supplemental init boot args to saved_command_line +* so that user can check what command line options passed +* to init. init/main.c static void __init setup_command_line(char *command_line) · line 557
Quoted 10 lines
init/main.c +10
-0+*/ + len =strlen (saved_command_line); +if (!strstr (boot_command_line," -- " )) { +strcpy (saved_command_line + len," -- " ); + len +=4 ; + }else + saved_command_line[len++] =' ' ; + +strcpy (saved_command_line + len, extra_init_args); + }This isn't safe because it will destroy any argument with " -- " in quotes and anything after it. For example, booting with:
Quoted 9 lines
thing=on acpi_osi="! -- " other=setting
will wreck acpi_osi's value and potentially overwrite "other=settings", etc.
(Yes, this seems very unlikely, but you can't treat " -- " as special, the command line string must be correct parsed for double quotes, as
parse_args()does.)
I think it won't overwrite anything, it will just leave out the " -- " that should have been added?
I wonder if this is necessary, though -- since commit b88c50ac304a ("log arguments and environment passed to init") the init arguments will be in the kernel log anyway.
Steven Rostedt
maintainerRe: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line
In reply to Kees CookQuoted 44 lines · On Fri, 7 Feb 2020 10:03:16 -0800 Kees Cook <[email protected]> wrote:
Quoted 30 lines
static void
__initsetup_command_line(char *command_line){(quoted diff) +11
-3- size_t len, xlen = 0; + size_t len, xlen = 0, ilen = 0; if (extra_command_line) xlen = strlen(extra_command_line); + if (extra_init_args) + ilen = strlen(extra_init_args) + 4; /* for " -- " */ len = xlen + strlen(boot_command_line) + 1; - saved_command_line = memblock_alloc(len, SMP_CACHE_BYTES); + saved_command_line = memblock_alloc(len + ilen, SMP_CACHE_BYTES); if (!saved_command_line) - panic("%s: Failed to allocate %zu bytes\n", __func__, len); + panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen); static_command_line = memblock_alloc(len, SMP_CACHE_BYTES); if (!static_command_line)@@ -533,6 +539,22 @@ static void __init setup_command_line(char *command_line) } strcpy(saved_command_line + xlen, boot_command_line); strcpy(static_command_line + xlen, command_line); + + if (ilen) { + /* + * Append supplemental init boot args to saved_command_line + * so that user can check what command line options passed + * to init.Review static void __init setup_command_line(char *command_line) · line 557
Quoted 10 lines
(quoted diff) +10
-0+ */ + len = strlen(saved_command_line); + if (!strstr(boot_command_line, " -- ")) { + strcpy(saved_command_line + len, " -- "); + len += 4; + } else + saved_command_line[len++] = ' '; + + strcpy(saved_command_line + len, extra_init_args); + }This isn't safe because it will destroy any argument with " -- " in quotes and anything after it. For example, booting with:
Quoted 9 lines
thing=on acpi_osi="! -- " other=setting
will wreck acpi_osi's value and potentially overwrite "other=settings", etc.
(Yes, this seems very unlikely, but you can't treat " -- " as special, the command line string must be correct parsed for double quotes, as
parse_args()does.)
This is not the args you are looking for. ;-)
There is a slight bug, but not as bad as you may think it is. bootconfig (when added to the command line) will look for a json like file appended to the initrd, and it will parse that. That's what all the xbc_*() functions do (extended boot commandline). If one of the options in that json like file is "init", then it will create the extra_init_args, which will make ilen greater than zero.
The above if statement looks for that ' -- ', and if it doesn't find it (strcmp() returns NULL when not found) it will than append " -- " to the boot_command_line. If it is found, then the " -- " is not added. In either case, the init args found in the json like file in the initrd is appended to the saved_command_line.
I did say there's a slight bug here. If you have your condition, and you add init arguments to that json file, it wont properly add the " -- ", and the init arguments in that file will be ignored.
That should be fixed, and I think I was able to do that below. I also noticed that we don't properly look for "bootconfig" either.
-- Steve
Quoted 10 lines
Review asmlinkage __visible void __init start_kernel(void) · line 786
Quoted 10 lines
(quoted diff) +3
-0} /*@@ -759,6 +781,9 @@ asmlinkage __visible void __init start_kernel(void) if (!IS_ERR_OR_NULL(after_dashes)) parse_args("Setting init args", after_dashes, NULL, 0, -1, -1, NULL, set_init_arg); + if (extra_init_args) + parse_args("Setting extra init args", extra_init_args, + NULL, 0, -1, -1, NULL, set_init_arg);
init/main.c +31 -6
@@ -142,6 +142,15 @@ static char *extra_command_line;/* Extra init arguments */ static char *extra_init_args; +#ifdef CONFIG_BOOT_CONFIG +/* Is bootconfig on command line? */ +static bool bootconfig_found; +static bool initargs_found; +#else +# define bootconfig_found false +# define initargs_found false +#endif +static char *execute_command;static char *ramdisk_execute_command;
@@ -336,17 +345,32 @@ u32 boot_config_checksum(unsigned char *p, u32 size)return ret; } +static int __init bootconfig_params (char *param,char *val, +const char *unused,void *arg) +{ +if (strcmp (param,"bootconfig" ) ==0 ) { + bootconfig_found = true; + }else if (strcmp (param,"--" ) ==0 ) { + initargs_found = true; + } +return 0 ; +} +static void __init setup_boot_config (const char *cmdline) { +static char tmp_cmdline[COMMAND_LINE_SIZE ]__initdata ;u32 size, csum;char *data, *copy;const char *p;u32 *hdr;int ret; - p =strstr (cmdline,"bootconfig" ); -if (!p || (p != cmdline && !isspace (*(p-1 ))) || - (p[10 ] && !isspace (p[10 ]))) +/* All fall through to do_early_param. */ +strlcpy (tmp_cmdline, boot_command_line,COMMAND_LINE_SIZE ); +parse_args ("bootconfig" , tmp_cmdline,NULL ,0 ,0 ,0 ,NULL , + bootconfig_params); + +if (!bootconfig_found)return ;if (!initrd_end)
@@ -563,11 +587,12 @@ static void __init setup_command_line(char *command_line)* to init. */ len =strlen (saved_command_line); -if (!strstr (boot_command_line," -- " )) { +if (initargs_found) { + saved_command_line[len++] =' ' ; + }else {strcpy (saved_command_line + len," -- " ); len +=4 ; - }else - saved_command_line[len++] =' ' ; + }strcpy (saved_command_line + len, extra_init_args); }
Re: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line
Quoted 40 lines · Steven Rostedt
Quoted 13 lines · On Fri, 7 Feb 2020 10:03:16 -0800 Kees Cook <[email protected]> wrote:
Review
Quoted 9 lines
(quoted diff) +9
-0+ len = strlen(saved_command_line); + if (!strstr(boot_command_line, " -- ")) { + strcpy(saved_command_line + len, " -- "); + len += 4; + } else + saved_command_line[len++] = ' '; + + strcpy(saved_command_line + len, extra_init_args); + }This isn't safe because it will destroy any argument with " -- " in quotes and anything after it. For example, booting with:
Quoted 9 lines
thing=on acpi_osi="! -- " other=setting
will wreck acpi_osi's value and potentially overwrite "other=settings", etc.
(Yes, this seems very unlikely, but you can't treat " -- " as special, the command line string must be correct parsed for double quotes, as
parse_args()does.)This is not the args you are looking for. ;-)
There is a slight bug, but not as bad as you may think it is. bootconfig (when added to the command line) will look for a json like file appended to the initrd, and it will parse that. That's what all the xbc_*() functions do (extended boot commandline). If one of the options in that json like file is "init", then it will create the
extra_init_args, which will make ilen greater than zero.The above if statement looks for that ' -- ', and if it doesn't find it (
strcmp()returns NULL when not found) it will than append " -- " to theboot_command_line. If it is found, then the " -- " is not added. In either case, the init args found in the json like file in the initrd is appended to thesaved_command_line.
Quoted 3 lines
I did say there's a slight bug here. If you have your condition, and you add init arguments to that json file, it wont properly add the " -- ", and the init arguments in that file will be ignored.
Ah, right, it's even more slight, sorry, I had the strstr() in my head still. So, yes, with an "init" section and a very goofy " -- " present in a kernel bootparam string value, the appended init args will be parsed as kernel options.
Signature · 1 line
Kees Cook
Re: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line
In reply to Steven RostedtQuoted 26 lines · Steven Rostedt
init/main.c +10
-0@@ -142,6 +142,15 @@ static char *extra_command_line;/* Extra init arguments */ static char *extra_init_args; +#ifdef CONFIG_BOOT_CONFIG +/* Is bootconfig on command line? */ +static bool bootconfig_found; +static bool initargs_found; +#else +# define bootconfig_found false +# define initargs_found false +#endif +static char *execute_command;static char *ramdisk_execute_command;@@ -336,17 +345,32 @@ u32 boot_config_checksum(unsigned char *p, u32 size)return ret; } +static int __init bootconfig_params(char *param, char *val,
init/main.c u32 boot_config_checksum(unsigned char *p, u32 size) · line 358
Quoted 10 lines
init/main.c +10
-0+ const char *unused, void *arg) +{ + if (strcmp(param, "bootconfig") == 0) { + bootconfig_found = true; + } else if (strcmp(param, "--") == 0) { + initargs_found = true; + } +return 0 ; +} +
I came across this as I was poking around some of the command line parsing. AFAICT, initargs_found will never be set to true here, because parse_args handles "--" itself by immediately returning: it doesn't invoke the callback for it. So you'd instead have to check the return of parse_args("bootconfig"...) to detect the initargs_found case.
Quoted 19 lines
init/main.c +7
-3static void __init setup_boot_config (const char *cmdline) { +static char tmp_cmdline[COMMAND_LINE_SIZE ]__initdata ;u32 size, csum;char *data, *copy;const char *p;u32 *hdr;int ret; - p =strstr (cmdline,"bootconfig" ); -if (!p || (p != cmdline && !isspace (*(p-1 ))) || - (p[10 ] && !isspace (p[10 ]))) +/* All fall through to do_early_param. */ +strlcpy (tmp_cmdline, boot_command_line,COMMAND_LINE_SIZE ); +parse_args ("bootconfig" , tmp_cmdline,NULL ,0 ,0 ,0 ,NULL , + bootconfig_params); + +if (!bootconfig_found)return ;
Masami Hiramatsu
maintainerRe: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line
Quoted 35 lines · On Sat, 1 Aug 2020 22:33:18 -0400 Arvind Sankar <[email protected]> wrote:
Quoted 34 lines · Steven Rostedt
init/main.c +18
-0@@ -142,6 +142,15 @@ static char *extra_command_line;/* Extra init arguments */ static char *extra_init_args; +#ifdef CONFIG_BOOT_CONFIG +/* Is bootconfig on command line? */ +static bool bootconfig_found; +static bool initargs_found; +#else +# define bootconfig_found false +# define initargs_found false +#endif +static char *execute_command;static char *ramdisk_execute_command;@@ -336,17 +345,32 @@ u32 boot_config_checksum(unsigned char *p, u32 size)return ret; } +static int __init bootconfig_params (char *param,char *val, +const char *unused,void *arg) +{ +if (strcmp (param,"bootconfig" ) ==0 ) { + bootconfig_found = true; + }else if (strcmp (param,"--" ) ==0 ) { + initargs_found = true; + } +return 0 ;
Quoted 8 lines
init/main.c u32 boot_config_checksum(unsigned char *p, u32 size) · line 358
Quoted 2 lines
init/main.c +2
-0+} +I came across this as I was poking around some of the command line parsing. AFAICT,
initargs_foundwill never be set to true here, becauseparse_argshandles "--" itself by immediately returning: it doesn't invoke the callback for it. So you'd instead have to check the return ofparse_args("bootconfig"...)to detect theinitargs_foundcase.
Oops, good catch!
Does this fixes the problem?
From b078e8b02ad54aea74f8c3645fc11dd3a1cdc1e7 Mon Sep 17 00:00:00 2001
From: Masami Hiramatsu <[email protected]>
Date: Mon, 3 Aug 2020 23:57:29 +0900
Subject: [PATCH] bootconfig: Fix to find the initargs correctly
Since the parse_args() stops parsing at '--', bootconfig_params() will never get the '--' as param and initargs_found never be true. In the result, if we pass some init arguments via the bootconfig, those are always appended to the kernel command line with '--' and user will see double '--'.
To fix this correctly, check the return value of parse_args() and set initargs_found true if the return value is not an error but a valid address.
--- init/main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
init/main.c +8 -6
@@ -387,8 +387,6 @@ static int __init bootconfig_params(char *param, char *val, {if (strcmp (param,"bootconfig" ) ==0 ) { bootconfig_found = true; - }else if (strcmp (param,"--" ) ==0 ) { - initargs_found = true; }return 0 ; }
@@ -399,19 +397,23 @@ static void __init setup_boot_config(const char *cmdline)const char *msg;int pos;u32 size, csum; -char *data, *copy; +char *data, *copy, *err;int ret;/* Cut out the bootconfig data even if we have no bootconfig option */ data =get_boot_config_from_initrd (&size, &csum);strlcpy (tmp_cmdline, boot_command_line,COMMAND_LINE_SIZE ); -parse_args ("bootconfig" , tmp_cmdline,NULL ,0 ,0 ,0 ,NULL , - bootconfig_params); + err =parse_args ("bootconfig" , tmp_cmdline,NULL ,0 ,0 ,0 ,NULL , + bootconfig_params); -if (!bootconfig_found) +if (IS_ERR (err) || !bootconfig_found)return ; +/* parse_args() stops at '--' and returns an address */ +if (!IS_ERR (err) && err) + initargs_found = true; +if (!data) {pr_err ("'bootconfig' found on command line, but no bootconfig found\n" );return ;
Signature · 1 line
2.25.1
Re: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line
Quoted 11 lines · Masami Hiramatsu
Quoted 6 lines · On Sat, 1 Aug 2020 22:33:18 -0400 Arvind Sankar <[email protected]> wrote:
I came across this as I was poking around some of the command line parsing. AFAICT,
initargs_foundwill never be set to true here, becauseparse_argshandles "--" itself by immediately returning: it doesn't invoke the callback for it. So you'd instead have to check the return ofparse_args("bootconfig"...)to detect theinitargs_foundcase.Oops, good catch!
Does this fixes the problem?
Note I found the issue by code inspection, I don't have an actual test case. But the change looks good to me, with one comment below.
Quoted 5 lines
init/main.c +1
-2strlcpy (tmp_cmdline, boot_command_line,COMMAND_LINE_SIZE ); -parse_args ("bootconfig" , tmp_cmdline,NULL ,0 ,0 ,0 ,NULL , - bootconfig_params); + err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
init/main.c static void __init setup_boot_config(const char *cmdline) · line 416
Quoted 10 lines
init/main.c +6
-1+ bootconfig_params); -if (!bootconfig_found) +if (IS_ERR (err) || !bootconfig_found)return ; +/* parse_args() stops at '--' and returns an address */ +if (!IS_ERR (err) && err) + initargs_found = true; +
I think you can drop the second IS_ERR, since we already checked that.
Quoted 5 lines
init/main.c +0
-0if (!data) {pr_err ("'bootconfig' found on command line, but no bootconfig found\n" );return ;Signature · 1 line
2.25.1
Steven Rostedt
maintainerRe: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line
Quoted 6 lines · On Mon, 3 Aug 2020 11:29:59 -0400 Arvind Sankar <[email protected]> wrote:
init/main.c static void __init setup_boot_config(const char *cmdline) · line 416
Quoted 4 lines
init/main.c +4
-0+/* parse_args() stops at '--' and returns an address */ +if (!IS_ERR (err) && err) + initargs_found = true; +I think you can drop the second
IS_ERR, since we already checked that.
Masami,
Can you send this with the update as a normal patch (not a Cc to this thread). That way it gets caught by my patchwork scanning of my inbox.
Thanks!
(/me is currently going through all his patchwork patches to pull in for the merge window.)
-- Steve
Masami Hiramatsu
maintainerRe: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line
Quoted 10 lines · On Mon, 3 Aug 2020 13:22:38 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 6 lines · On Mon, 3 Aug 2020 11:29:59 -0400 Arvind Sankar <[email protected]> wrote:
init/main.c static void __init setup_boot_config(const char *cmdline) · line 416
Quoted 4 lines
init/main.c +4
-0+/* parse_args() stops at '--' and returns an address */ +if (!IS_ERR (err) && err) + initargs_found = true; +I think you can drop the second
IS_ERR, since we already checked that.
Quoted 4 lines
Masami,
Can you send this with the update as a normal patch (not a Cc to this thread). That way it gets caught by my patchwork scanning of my inbox.
OK, I'll update it.
Quoted 5 lines
Thanks!
(/me is currently going through all his patchwork patches to pull in for the merge window.)
Thank you!
Quoted 2 lines
-- Steve
Signature · 1 line
Masami Hiramatsu <[email protected]>