linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline
@ 2019-08-26  3:15 Masami Hiramatsu
  2019-08-26  3:15 ` [RFC PATCH v3 01/19] skc: Add supplemental kernel cmdline support Masami Hiramatsu
                   ` (18 more replies)
  0 siblings, 19 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:15 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Hello,

This is the 3rd version of RFC series for the boot-time tracing.

Previous thread is here.

https://lkml.kernel.org/r/156316746861.23477.5815110570539190650.stgit@devnote2

On that thread and offline talk with Frank Rowand at OSS Japan2019
last month, we agreed that the devicetree is only for hardware
description and should not expand it for software settings.

Thus, in this version, I introduced a new extended command line
feature called Supplemental Kernel Cmdline (SKC) instead of
devicetree, and rewrote the boot-time tracing part based on that.

Supplemental Kernel Cmdline
===========================

Supplemental kernel command line (SKC) allows admin to pass a
tree-structured supplemental kernel commandline file (SKC file)
when boot up kernel. This expands the kernel command line in
efficient way.

Each key is described as a dot-jointed-words. And user can write
the key-words in tree stlye.
For example,

 feature.option.foo = 1;
 feature.option.bar = 2;

can be also written in

 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 SKC key-value list via /proc/skc.
The size of SKC is limited upto 32KB and 512 key-words and values
in total.

SKC and Bootloader
==================

To play with SKC, you need to use patched qemu or patched grub.
Please checkout below for x86 support. (for PoC, I implemented it
only for x86, but it is not so hard to do same on other archs)

https://github.com/mhiramat/qemu.git skc

https://github.com/mhiramat/grub.git grub-x86-skc

User can pass an skc file when boot the qemu machine with "-skc PATH"
option. Or specify the skc file on grub console by "skc PATH".

Boot-time Tracing
=================

Boot-time tracing side has been updated for SKC, but the difference
is small, because SKC has similar tree-based interfaces to OF APIs.
Currently, it supports following SKC options. Please read
Documentation/trace/boottime-trace.rst for details.

     - ftrace.options = OPT1[,OPT2...];
     - ftrace.trace_clock = CLOCK;
     - ftrace.dump_on_oops [= MODE];
     - ftrace.traceoff_on_warning;
     - ftrace.tp_printk;
     - ftrace.buffer_size = SIZE;
     - ftrace.alloc_snapshot;
     - ftrace.events = EVENT[, EVENT2...];
     - ftrace.tracer = TRACER;
     - ftrace.event.GROUP.EVENT.filter = FILTER;
     - ftrace.event.GROUP.EVENT.actions = ACTION[, ACTION2...];
     - ftrace.event.GROUP.EVENT.enable;
     - ftrace.event.kprobes.EVENT.probes = PROBE[, PROBE2...];
     - ftrace.event.synthetic.EVENT.fields = FIELD[, FIELD2...];
     - ftrace.[instance.INSTANCE.]cpumask = CPUMASK;
     - ftrace.[instance.INSTANCE.]ftrace.filters
     - ftrace.[instance.INSTANCE.]ftrace.notraces
     - ftrace.fgraph.filters = FILTER[, FILTER2...];
     - ftrace.fgraph.notraces = FILTER[, FILTER2...];
     - ftrace.fgraph.max_depth = MAX_DEPTH;

This series can be applied on Steve's tracing tree (ftrace/core) or
available on below

https://github.com/mhiramat/linux.git ftrace-boottrace-v3

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 in module alpha, and others tracing module beta,
you can write followings.

ftrace.instance {
	foo {
		tracer = "function";
		ftrace-filters = "*:mod:alpha";
	}
	bar {
		tracer = "function";
		ftrace-filters = "*:mod:beta";
	}
}

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 SKC 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
==========

- For specifying the skc data address, there are 2 ways to pass it
to kernel. One is expanding arch-specific entries (e.g. setup_data
on x86), another is passing it via kernel cmdline. The former may
need to expand devicetree anyway (we need /chosen/skc_addr property
for some arch.) The latter is more generic, but it may not work if
the space on cmdline shorts.
According to Frank's suggestion, I introduced "skc=PADDR,SIZE" option
to kernel cmdline, boot loaders must support it. This is generic, and
I still have some concerns, like memory reservation. In this version,
I used early_param() to reserve SKC memory. If it is too late, we'd
better considering to use arch specific data passing.

- Currently, supplemental kernel cmdline doesn't support __setup()
routine to avoid confusion, but I think it is possible to support it.

- For saving memory consuming after boot, all variables and APIs are
__init and __initdata. Thus runtime memory footprint becomes minimum.
But if some loadable modules wants to use it. We have to keep at least
query interface and tree nodes on memory.

- As you can see, the EVENT.actions value is a bit ugly. Maybe we can
introduce sub-nodes under action node, something like below.

ftrace.event.initcall.initcall_finish.action.hist {
	keys = "func";
	lat = "common_timestamp.usecs-$ts0";
	onmatch = "initcall.initcall_start";
        call = "initcall_latency(func,$lat)";
}

Any suggestions, thoughts?

Thank you,

---

Masami Hiramatsu (19):
      skc: Add supplemental kernel cmdline support
      skc: Add /proc/sup_cmdline to show SKC key-value list
      skc: Add a boot setup routine from cmdline
      Documentation: skc: Add a doc for supplemental kernel cmdline
      tracing: Apply soft-disabled and filter to tracepoints printk
      tracing: kprobes: Output kprobe event to printk buffer
      tracing: Expose EXPORT_SYMBOL_GPL symbol
      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 by supplemental kernel cmdline
      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
      tracing/boot: Add function-graph tracer options
      Documentation: tracing: Add boot-time tracing document


 Documentation/admin-guide/index.rst             |    1 
 Documentation/admin-guide/kernel-parameters.txt |    6 
 Documentation/admin-guide/skc.rst               |  123 ++++
 Documentation/trace/boottime-trace.rst          |  185 ++++++
 MAINTAINERS                                     |    8 
 arch/Kconfig                                    |    9 
 fs/proc/Makefile                                |    1 
 fs/proc/sup_cmdline.c                           |  106 ++++
 include/linux/skc.h                             |  205 +++++++
 include/linux/trace_events.h                    |    1 
 init/main.c                                     |   54 ++
 kernel/trace/Kconfig                            |    9 
 kernel/trace/Makefile                           |    1 
 kernel/trace/ftrace.c                           |   85 ++-
 kernel/trace/trace.c                            |   90 ++-
 kernel/trace/trace_boot.c                       |  457 +++++++++++++++
 kernel/trace/trace_events.c                     |    3 
 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/skc.c                                       |  694 +++++++++++++++++++++++
 23 files changed, 2044 insertions(+), 96 deletions(-)
 create mode 100644 Documentation/admin-guide/skc.rst
 create mode 100644 Documentation/trace/boottime-trace.rst
 create mode 100644 fs/proc/sup_cmdline.c
 create mode 100644 include/linux/skc.h
 create mode 100644 kernel/trace/trace_boot.c
 create mode 100644 lib/skc.c

--
Masami Hiramatsu (Linaro) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 01/19] skc: Add supplemental kernel cmdline support
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
@ 2019-08-26  3:15 ` Masami Hiramatsu
  2019-08-26 13:27   ` Rob Herring
  2019-08-26  3:16 ` [RFC PATCH v3 02/19] skc: Add /proc/sup_cmdline to show SKC key-value list Masami Hiramatsu
                   ` (17 subsequent siblings)
  18 siblings, 1 reply; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:15 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Supplemental kernel command line (SKC) allows admin to pass a
tree-structured supplemental kernel commandline file (SKC file)
when boot up kernel. This expands the kernel command line in
efficient way.

SKC file 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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 MAINTAINERS         |    6 
 arch/Kconfig        |    9 +
 include/linux/skc.h |  205 +++++++++++++++
 lib/Kconfig         |    3 
 lib/Makefile        |    2 
 lib/skc.c           |  694 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 919 insertions(+)
 create mode 100644 include/linux/skc.h
 create mode 100644 lib/skc.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 035ffc1e16a3..67590c0e37c5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15362,6 +15362,12 @@ W:	http://www.stlinux.com
 S:	Supported
 F:	drivers/net/ethernet/stmicro/stmmac/
 
+SUPPLEMENTAL KERNEL CMDLINE
+M:	Masami Hiramatsu <mhiramat@kernel.org>
+S:	Maintained
+F:	lib/skc.c
+F:	include/linux/skc.h
+
 SUN3/3X
 M:	Sam Creasey <sammy@sammy.net>
 W:	http://sammy.net/sun3/
diff --git a/arch/Kconfig b/arch/Kconfig
index a7b57dd42c26..14d709ef0396 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -24,6 +24,15 @@ config HAVE_IMA_KEXEC
 config HOTPLUG_SMT
 	bool
 
+config SKC
+	bool "Supplemental kernel cmdline"
+	select LIBSKC
+	default y
+	help
+	 Supplemental kernel command line allows system admin to pass a
+	 text file as complemental extension of kernel cmdline when boot.
+	 The bootloader needs to support loading the SKC file.
+
 config OPROFILE
 	tristate "OProfile system profiling"
 	depends on PROFILING
diff --git a/include/linux/skc.h b/include/linux/skc.h
new file mode 100644
index 000000000000..71e485ce947f
--- /dev/null
+++ b/include/linux/skc.h
@@ -0,0 +1,205 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_SKC_H
+#define _LINUX_SKC_H
+/*
+ * Supplemental Kernel Command Line
+ * Copyright (C) 2019 Linaro Ltd.
+ * Author: Masami Hiramatsu <mhiramat@kernel.org>
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+
+/* SKC tree node */
+struct skc_node {
+	u16 next;
+	u16 child;
+	u16 parent;
+	u16 data;
+} __attribute__ ((__packed__));
+
+#define SKC_KEY		0
+#define SKC_VALUE	(1 << 15)
+/* Maximum size of supplemental kernel cmdline is 32KB - 1 */
+#define SKC_DATA_MAX	(SKC_VALUE - 1)
+
+#define SKC_NODE_MAX	512
+#define SKC_KEYLEN_MAX	256
+#define SKC_DEPTH_MAX	16
+
+/* Node tree access raw APIs */
+struct skc_node * __init skc_root_node(void);
+int __init skc_node_index(struct skc_node *node);
+struct skc_node * __init skc_node_get_parent(struct skc_node *node);
+struct skc_node * __init skc_node_get_child(struct skc_node *node);
+struct skc_node * __init skc_node_get_next(struct skc_node *node);
+const char * __init skc_node_get_data(struct skc_node *node);
+
+/**
+ * skc_node_is_value() - Test the node is a value node
+ * @node: An SKC node.
+ *
+ * Test the @node is a value node and return true if a value node, false if not.
+ */
+static inline __init bool skc_node_is_value(struct skc_node *node)
+{
+	return !!(node->data & SKC_VALUE);
+}
+
+/**
+ * skc_node_is_key() - Test the node is a key node
+ * @node: An SKC node.
+ *
+ * Test the @node is a key node and return true if a key node, false if not.
+ */
+static inline __init bool skc_node_is_key(struct skc_node *node)
+{
+	return !(node->data & SKC_VALUE);
+}
+
+/**
+ * skc_node_is_array() - Test the node is an arraied value node
+ * @node: An SKC node.
+ *
+ * Test the @node is an arraied value node.
+ */
+static inline __init bool skc_node_is_array(struct skc_node *node)
+{
+	return skc_node_is_value(node) && node->next != 0;
+}
+
+/**
+ * skc_node_is_leaf() - Test the node is a leaf key node
+ * @node: An SKC node.
+ *
+ * Test the @node is a leaf key node which is a key node and has a value node
+ * or no child. Returns true if it is a leaf node, or false if not.
+ */
+static inline __init bool skc_node_is_leaf(struct skc_node *node)
+{
+	return skc_node_is_key(node) &&
+		(!node->child || skc_node_is_value(skc_node_get_child(node)));
+}
+
+/* Tree-based key-value access APIs */
+struct skc_node * __init skc_node_find_child(struct skc_node *parent,
+					     const char *key);
+
+const char * __init skc_node_find_value(struct skc_node *parent,
+					const char *key,
+					struct skc_node **vnode);
+
+struct skc_node * __init skc_node_find_next_leaf(struct skc_node *root,
+						 struct skc_node *leaf);
+
+const char * __init skc_node_find_next_key_value(struct skc_node *root,
+						 struct skc_node **leaf);
+
+/**
+ * skc_find_value() - Find a value which matches the key
+ * @key: Search key
+ * @vnode: A container pointer of SKC value node.
+ *
+ * Search a value whose key matches @key from whole of SKC tree and return
+ * the value if found. Found value node is stored in *@vnode.
+ * Note that this can return 0-length string and store NULL in *@vnode for
+ * key-only (non-value) entry.
+ */
+static inline const char * __init
+skc_find_value(const char *key, struct skc_node **vnode)
+{
+	return skc_node_find_value(NULL, key, vnode);
+}
+
+/**
+ * skc_find_node() - Find a node which matches the key
+ * @key: Search key
+ * @value: A container pointer of SKC value node.
+ *
+ * Search a (key) node whose key matches @key from whole of SKC tree and
+ * return the node if found. If not found, returns NULL.
+ */
+static inline struct skc_node * __init skc_find_node(const char *key)
+{
+	return skc_node_find_child(NULL, key);
+}
+
+/**
+ * skc_array_for_each_value() - Iterate value nodes on an array
+ * @anode: An SKC arraied value node
+ * @value: A value
+ *
+ * Iterate array value nodes and values starts from @anode. This is expected to
+ * be used with skc_find_value() and skc_node_find_value(), so that user can
+ * process each array entry node.
+ */
+#define skc_array_for_each_value(anode, value)				\
+	for (value = skc_node_get_data(anode); anode != NULL ;		\
+	     anode = skc_node_get_next(anode),				\
+	     value = anode ? skc_node_get_data(anode) : NULL)
+
+/**
+ * skc_node_for_each_child() - Iterate child nodes
+ * @parent: An SKC node.
+ * @child: Iterated SKC node.
+ *
+ * Iterate child nodes of @parent. Each child nodes are stored to @child.
+ */
+#define skc_node_for_each_child(parent, child)				\
+	for (child = skc_node_get_child(parent); child != NULL ;	\
+	     child = skc_node_get_next(child))
+
+/**
+ * skc_node_for_each_array_value() - Iterate array entries of geven key
+ * @node: An SKC node.
+ * @key: A key string searched under @node
+ * @anode: Iterated SKC node of array entry.
+ * @value: Iterated value of array entry.
+ *
+ * Iterate array entries of given @key under @node. Each array entry node
+ * is stroed to @anode and @value. If the @node doesn't have @key node,
+ * it does nothing.
+ * Note that even if the found key node has only one value (not array)
+ * this executes block once. Hoever, if the found key node has no value
+ * (key-only node), this does nothing. So don't use this for testing the
+ * key-value pair existence.
+ */
+#define skc_node_for_each_array_value(node, key, anode, value)		\
+	for (value = skc_node_find_value(node, key, &anode); value != NULL; \
+	     anode = skc_node_get_next(anode),				\
+	     value = anode ? skc_node_get_data(anode) : NULL)
+
+/**
+ * skc_node_for_each_key_value() - Iterate key-value pairs under a node
+ * @node: An SKC node.
+ * @knode: Iterated key node
+ * @value: Iterated value string
+ *
+ * Iterate key-value pairs under @node. Each key node and value string are
+ * stored in @knode and @value respectively.
+ */
+#define skc_node_for_each_key_value(node, knode, value)			\
+	for (knode = NULL, value = skc_node_find_next_key_value(node, &knode);\
+	     knode != NULL; value = skc_node_find_next_key_value(node, &knode))
+
+/**
+ * skc_for_each_key_value() - Iterate key-value pairs
+ * @knode: Iterated key node
+ * @value: Iterated value string
+ *
+ * Iterate key-value pairs in whole SKC tree. Each key node and value string
+ * are stored in @knode and @value respectively.
+ */
+#define skc_for_each_key_value(knode, value)				\
+	skc_node_for_each_key_value(NULL, knode, value)
+
+/* Compose complete key */
+int __init skc_node_compose_key(struct skc_node *node, char *buf, size_t size);
+
+/* SKC node initializer */
+int __init skc_init(char *buf);
+
+/* Debug dump functions */
+void __init skc_debug_dump(void);
+
+#endif
diff --git a/lib/Kconfig b/lib/Kconfig
index f33d66fc0e86..97a53f400a7c 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -568,6 +568,9 @@ config DIMLIB
 config LIBFDT
 	bool
 
+config LIBSKC
+	bool
+
 config OID_REGISTRY
 	tristate
 	help
diff --git a/lib/Makefile b/lib/Makefile
index 29c02a924973..52132d0d8ff2 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -229,6 +229,8 @@ $(foreach file, $(libfdt_files), \
 	$(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt))
 lib-$(CONFIG_LIBFDT) += $(libfdt_files)
 
+lib-$(CONFIG_LIBSKC) += skc.o
+
 obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o
 obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o
 
diff --git a/lib/skc.c b/lib/skc.c
new file mode 100644
index 000000000000..bbcc81724ec4
--- /dev/null
+++ b/lib/skc.c
@@ -0,0 +1,694 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Supplemental Kernel Commandline
+ * Masami Hiramatsu <mhiramat@kernel.org>
+ */
+
+#define pr_fmt(fmt)    "skc: " fmt
+
+#include <linux/bug.h>
+#include <linux/ctype.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/printk.h>
+#include <linux/skc.h>
+#include <linux/string.h>
+
+/*
+ * Supplemental Kernel Commandline (SKC) is given as tree-structured ascii
+ * text of key-value pairs on memory.
+ * skc_parse() parses the text to build a simple tree. Each tree node is
+ * simply a key word or a value. A key node may have a next key node or/and
+ * a child node (both key and value). A value node may have a next value
+ * node (for array).
+ */
+
+static struct skc_node skc_nodes[SKC_NODE_MAX] __initdata;
+static int skc_node_num __initdata;
+static char *skc_data __initdata;
+static size_t skc_data_size __initdata;
+static struct skc_node *last_parent __initdata;
+
+static int __init skc_parse_error(const char *msg, const char *p)
+{
+	int line = 0, col = 0;
+	int i, pos = p - skc_data;
+
+	for (i = 0; i < pos; i++) {
+		if (skc_data[i] == '\n') {
+			line++;
+			col = pos - i;
+		}
+	}
+	pr_err("Parse error at line %d, col %d: %s\n", line + 1, col + 1, msg);
+	return -EINVAL;
+}
+
+/**
+ * skc_root_node() - Get the root node of supplemental kernel cmdline
+ *
+ * Return the address of root node of supplemental kernel cmdline. If the
+ * supplemental kernel cmdline is not initiized, return NULL.
+ */
+struct skc_node * __init skc_root_node(void)
+{
+	if (unlikely(!skc_data))
+		return NULL;
+
+	return skc_nodes;
+}
+
+/**
+ * skc_node_index() - Get the index of SKC node
+ * @node: A target node of getting index.
+ *
+ * Return the index number of @node in SKC node list.
+ */
+int __init skc_node_index(struct skc_node *node)
+{
+	return node - &skc_nodes[0];
+}
+
+/**
+ * skc_node_get_parent() - Get the parent SKC node
+ * @node: An SKC node.
+ *
+ * Return the parent node of @node. If the node is top node of the tree,
+ * return NULL.
+ */
+struct skc_node * __init skc_node_get_parent(struct skc_node *node)
+{
+	return node->parent == SKC_NODE_MAX ? NULL : &skc_nodes[node->parent];
+}
+
+/**
+ * skc_node_get_child() - Get the child SKC node
+ * @node: An SKC node.
+ *
+ * Return the first child node of @node. If the node has no child, return
+ * NULL.
+ */
+struct skc_node * __init skc_node_get_child(struct skc_node *node)
+{
+	return node->child ? &skc_nodes[node->child] : NULL;
+}
+
+/**
+ * skc_node_get_next() - Get the next sibling SKC node
+ * @node: An SKC node.
+ *
+ * Return the NEXT sibling node of @node. If the node has no next sibling,
+ * return NULL. Note that even if this returns NULL, it doesn't mean @node
+ * has no siblings. (You also has to check whether the parent's child node
+ * is @node or not.)
+ */
+struct skc_node * __init skc_node_get_next(struct skc_node *node)
+{
+	return node->next ? &skc_nodes[node->next] : NULL;
+}
+
+/**
+ * skc_node_get_data() - Get the data of SKC node
+ * @node: An SKC node.
+ *
+ * Return the data (which is always a null terminated string) of @node.
+ * If the node has invalid data, warn and return NULL.
+ */
+const char * __init skc_node_get_data(struct skc_node *node)
+{
+	int offset = node->data & ~SKC_VALUE;
+
+	if (WARN_ON(offset >= skc_data_size))
+		return NULL;
+
+	return skc_data + offset;
+}
+
+static bool __init
+skc_node_match_prefix(struct skc_node *node, const char **prefix)
+{
+	const char *p = skc_node_get_data(node);
+	int len = strlen(p);
+
+	if (strncmp(*prefix, p, len))
+		return false;
+
+	p = *prefix + len;
+	if (*p == '.')
+		p++;
+	else if (*p != '\0')
+		return false;
+	*prefix = p;
+
+	return true;
+}
+
+/**
+ * skc_node_find_child() - Find a child node which matches given key
+ * @parent: An SKC node.
+ * @key: A key string.
+ *
+ * Search a node under @parent which matches @key. The @key can contain
+ * several words jointed with '.'. If @parent is NULL, this searches the
+ * node from whole tree. Return NULL if no node is matched.
+ */
+struct skc_node * __init
+skc_node_find_child(struct skc_node *parent, const char *key)
+{
+	struct skc_node *node;
+
+	if (parent)
+		node = skc_node_get_child(parent);
+	else
+		node = skc_root_node();
+
+	while (node && skc_node_is_key(node)) {
+		if (!skc_node_match_prefix(node, &key))
+			node = skc_node_get_next(node);
+		else if (*key != '\0')
+			node = skc_node_get_child(node);
+		else
+			break;
+	}
+
+	return node;
+}
+
+/**
+ * skc_node_find_value() - Find a value node which matches given key
+ * @parent: An SKC node.
+ * @key: A key string.
+ * @vnode: A container pointer of found SKC node.
+ *
+ * Search a value node under @parent whose (parent) key node matches @key,
+ * store it in *@vnode, and returns the value string.
+ * The @key can contain several words jointed with '.'. If @parent is NULL,
+ * this searches the node from whole tree. Return the value string if a
+ * matched key found, return NULL if no node is matched.
+ * Note that this returns 0-length string and stores NULL in *@vnode if the
+ * key has no value. And also it will return the value of the first entry if
+ * the value is an array.
+ */
+const char * __init
+skc_node_find_value(struct skc_node *parent, const char *key,
+		    struct skc_node **vnode)
+{
+	struct skc_node *node = skc_node_find_child(parent, key);
+
+	if (!node || !skc_node_is_key(node))
+		return NULL;
+
+	node = skc_node_get_child(node);
+	if (node && !skc_node_is_value(node))
+		return NULL;
+
+	if (vnode)
+		*vnode = node;
+
+	return node ? skc_node_get_data(node) : "";
+}
+
+/**
+ * skc_node_compose_key() - Compose key string of the SKC node
+ * @node: An SKC node.
+ * @buf: A buffer to store the key.
+ * @size: The size of the @buf.
+ *
+ * Compose the full-length key of the @node into @buf. Returns the total
+ * length of the key stored in @buf. Or returns -EINVAL if @node is NULL,
+ * and -ERANGE if the key depth is deeper than max depth.
+ */
+int __init skc_node_compose_key(struct skc_node *node, char *buf, size_t size)
+{
+	u16 keys[SKC_DEPTH_MAX];
+	int depth = 0, ret = 0, total = 0;
+
+	if (!node)
+		return -EINVAL;
+
+	if (skc_node_is_value(node))
+		node = skc_node_get_parent(node);
+
+	while (node) {
+		keys[depth++] = skc_node_index(node);
+		if (depth == SKC_DEPTH_MAX)
+			return -ERANGE;
+		node = skc_node_get_parent(node);
+	}
+
+	while (--depth >= 0) {
+		node = skc_nodes + keys[depth];
+		ret = snprintf(buf, size, "%s%s", skc_node_get_data(node),
+			       depth ? "." : "");
+		if (ret < 0)
+			return ret;
+		if (ret > size) {
+			size = 0;
+		} else {
+			size -= ret;
+			buf += ret;
+		}
+		total += ret;
+	}
+
+	return total;
+}
+
+/**
+ * skc_node_find_next_leaf() - Find the next leaf node under given node
+ * @root: An SKC root node
+ * @node: An SKC node which starts from.
+ *
+ * Search the next leaf node (which means the terminal key node) of @node
+ * under @root node (including @root node itself).
+ * Return the next node or NULL if next leaf node is not found.
+ */
+struct skc_node * __init skc_node_find_next_leaf(struct skc_node *root,
+						 struct skc_node *node)
+{
+	if (unlikely(!skc_data))
+		return NULL;
+
+	if (!node) {	/* First try */
+		node = root;
+		if (!node)
+			node = skc_nodes;
+	} else {
+		if (node == root)	/* @root was a leaf, no child node. */
+			return NULL;
+
+		while (!node->next) {
+			node = skc_node_get_parent(node);
+			if (node == root)
+				return NULL;
+			/* User passed a node which is not uder parent */
+			if (WARN_ON(!node))
+				return NULL;
+		}
+		node = skc_node_get_next(node);
+	}
+
+	while (node && !skc_node_is_leaf(node))
+		node = skc_node_get_child(node);
+
+	return node;
+}
+
+/**
+ * skc_node_find_next_key_value() - Find the next key-value pair nodes
+ * @root: An SKC root node
+ * @leaf: A container pointer of SKC node which starts from.
+ *
+ * Search the next leaf node (which means the terminal key node) of *@leaf
+ * under @root node. Returns the value and update *@leaf if next leaf node
+ * is found, or NULL if no next leaf node is found.
+ * Note that this returns 0-length string if the key has no value, or
+ * the value of the first entry if the value is an array.
+ */
+const char * __init skc_node_find_next_key_value(struct skc_node *root,
+						 struct skc_node **leaf)
+{
+	/* tip must be passed */
+	if (WARN_ON(!leaf))
+		return NULL;
+
+	*leaf = skc_node_find_next_leaf(root, *leaf);
+	if (!*leaf)
+		return NULL;
+	if ((*leaf)->child)
+		return skc_node_get_data(skc_node_get_child(*leaf));
+	else
+		return "";	/* No value key */
+}
+
+/* SKC parse and tree build */
+
+static struct skc_node * __init skc_add_node(char *data, u32 flag)
+{
+	struct skc_node *node;
+	unsigned long offset;
+
+	if (skc_node_num == SKC_NODE_MAX)
+		return NULL;
+
+	node = &skc_nodes[skc_node_num++];
+	offset = data - skc_data;
+	node->data = (u16)offset;
+	if (WARN_ON(offset >= SKC_DATA_MAX))
+		return NULL;
+	node->data |= flag;
+	node->child = 0;
+	node->next = 0;
+
+	return node;
+}
+
+static inline __init struct skc_node *skc_last_sibling(struct skc_node *node)
+{
+	while (node->next)
+		node = skc_node_get_next(node);
+
+	return node;
+}
+
+static struct skc_node * __init skc_add_sibling(char *data, u32 flag)
+{
+	struct skc_node *sib, *node = skc_add_node(data, flag);
+
+	if (node) {
+		if (!last_parent) {
+			node->parent = SKC_NODE_MAX;
+			sib = skc_last_sibling(skc_nodes);
+			sib->next = skc_node_index(node);
+		} else {
+			node->parent = skc_node_index(last_parent);
+			if (!last_parent->child) {
+				last_parent->child = skc_node_index(node);
+			} else {
+				sib = skc_node_get_child(last_parent);
+				sib = skc_last_sibling(sib);
+				sib->next = skc_node_index(node);
+			}
+		}
+	}
+
+	return node;
+}
+
+static inline __init struct skc_node *skc_add_child(char *data, u32 flag)
+{
+	struct skc_node *node = skc_add_sibling(data, flag);
+
+	if (node)
+		last_parent = node;
+
+	return node;
+}
+
+static inline __init bool skc_valid_keyword(char *key)
+{
+	if (key[0] == '\0')
+		return false;
+
+	while (isalnum(*key) || *key == '-' || *key == '_')
+		key++;
+
+	return *key == '\0';
+}
+
+static inline __init char *find_ending_quote(char *p)
+{
+	do {
+		p = strchr(p + 1, '"');
+		if (!p)
+			break;
+	} while (*(p - 1) == '\\');
+
+	return p;
+}
+
+/* Return delimiter or error, no node added */
+static int __init __skc_parse_value(char **__v, char **__n)
+{
+	char *p, *v = *__v;
+	int c;
+
+	v = skip_spaces(v);
+	if (*v == '"') {
+		v++;
+		p = find_ending_quote(v);
+		if (!p)
+			return skc_parse_error("No closing quotation", v);
+		*p++ = '\0';
+		p = skip_spaces(p);
+		if (*p != ',' && *p != ';')
+			return skc_parse_error("No delimiter for value", v);
+		c = *p;
+		*p++ = '\0';
+	} else {
+		p = strpbrk(v, ",;");
+		if (!p)
+			return skc_parse_error("No delimiter for value", v);
+		c = *p;
+		*p++ = '\0';
+		v = strim(v);
+	}
+	*__v = v;
+	*__n = p;
+
+	return c;
+}
+
+static int __init skc_parse_array(char **__v)
+{
+	struct skc_node *node;
+	char *next;
+	int c = 0;
+
+	do {
+		c = __skc_parse_value(__v, &next);
+		if (c < 0)
+			return c;
+
+		node = skc_add_sibling(*__v, SKC_VALUE);
+		if (!node)
+			return -ENOMEM;
+		*__v = next;
+	} while (c != ';');
+	node->next = 0;
+
+	return 0;
+}
+
+static inline __init
+struct skc_node *find_match_node(struct skc_node *node, char *k)
+{
+	while (node) {
+		if (!strcmp(skc_node_get_data(node), k))
+			break;
+		node = skc_node_get_next(node);
+	}
+	return node;
+}
+
+static int __init __skc_add_key(char *k)
+{
+	struct skc_node *node;
+
+	if (!skc_valid_keyword(k))
+		return skc_parse_error("Invalid keyword", k);
+
+	if (unlikely(skc_node_num == 0))
+		goto add_node;
+
+	if (!last_parent)	/* the first level */
+		node = find_match_node(skc_nodes, k);
+	else
+		node = find_match_node(skc_node_get_child(last_parent), k);
+
+	if (node)
+		last_parent = node;
+	else {
+add_node:
+		node = skc_add_child(k, SKC_KEY);
+		if (!node)
+			return -ENOMEM;
+	}
+	return 0;
+}
+
+static int __init __skc_parse_keys(char *k)
+{
+	char *p;
+	int ret;
+
+	k = strim(k);
+	while ((p = strchr(k, '.'))) {
+		*p++ = '\0';
+		ret = __skc_add_key(k);
+		if (ret)
+			return ret;
+		k = p;
+	}
+
+	return __skc_add_key(k);
+}
+
+static int __init skc_parse_kv(char **k, char *v)
+{
+	struct skc_node *prev_parent = last_parent;
+	struct skc_node *node;
+	char *next;
+	int c, ret;
+
+	ret = __skc_parse_keys(*k);
+	if (ret)
+		return ret;
+
+	c = __skc_parse_value(&v, &next);
+	if (c < 0)
+		return c;
+
+	node = skc_add_sibling(v, SKC_VALUE);
+	if (!node)
+		return -ENOMEM;
+
+	if (c == ',') {	/* Array */
+		ret = skc_parse_array(&next);
+		if (ret < 0)
+			return ret;
+	}
+
+	last_parent = prev_parent;
+
+	*k = next;
+
+	return 0;
+}
+
+static int __init skc_parse_key(char **k, char *n)
+{
+	struct skc_node *prev_parent = last_parent;
+	int ret;
+
+	*k = strim(*k);
+	if (**k != '\0') {
+		ret = __skc_parse_keys(*k);
+		if (ret)
+			return ret;
+		last_parent = prev_parent;
+	}
+
+	*k = n;
+
+	return 0;
+}
+
+static int __init skc_open_brace(char **k, char *n)
+{
+	int ret;
+
+	ret = __skc_parse_keys(*k);
+	if (ret)
+		return ret;
+
+	/* Mark the last key as open brace */
+	last_parent->next = SKC_NODE_MAX;
+
+	*k = n;
+
+	return 0;
+}
+
+static int __init skc_close_brace(char **k, char *n)
+{
+	struct skc_node *node;
+
+	*k = strim(*k);
+	if (**k != '\0')
+		return skc_parse_error("Unexpected key, maybe forgot ;?", *k);
+
+	if (!last_parent || last_parent->next != SKC_NODE_MAX)
+		return skc_parse_error("Unexpected closing brace", *k);
+
+	node = last_parent;
+	node->next = 0;
+	do {
+		node = skc_node_get_parent(node);
+	} while (node && node->next != SKC_NODE_MAX);
+	last_parent = node;
+
+	*k = n;
+
+	return 0;
+}
+
+static int __init skc_verify_tree(void)
+{
+	int i;
+
+	for (i = 0; i < skc_node_num; i++) {
+		if (skc_nodes[i].next > skc_node_num) {
+			return skc_parse_error("No closing brace",
+				skc_node_get_data(skc_nodes + i));
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * skc_init() - Parse given SKC file and build SKC internal tree
+ * @buf: Supplemental kernel cmdline text
+ *
+ * This parses the supplemental kernel cmdline text in @buf. @buf must be a
+ * null terminated string and smaller than SKC_DATA_MAX.
+ * Return 0 if succeeded, or -errno if there is any error.
+ */
+int __init skc_init(char *buf)
+{
+	char *p, *q;
+	int ret, c;
+
+	if (skc_data)
+		return -EBUSY;
+
+	ret = strlen(buf);
+	if (ret > SKC_DATA_MAX - 1 || ret == 0)
+		return -ERANGE;
+
+	skc_data = buf;
+	skc_data_size = ret + 1;
+
+	p = buf;
+	do {
+		q = strpbrk(p, "{}=;");
+		if (!q)
+			break;
+		c = *q;
+		*q++ = '\0';
+		switch (c) {
+		case '=':
+			ret = skc_parse_kv(&p, q);
+			break;
+		case '{':
+			ret = skc_open_brace(&p, q);
+			break;
+		case ';':
+			ret = skc_parse_key(&p, q);
+			break;
+		case '}':
+			ret = skc_close_brace(&p, q);
+			break;
+		}
+	} while (ret == 0);
+
+	if (ret < 0)
+		return ret;
+
+	if (!q) {
+		p = skip_spaces(p);
+		if (*p != '\0')
+			return skc_parse_error("No delimiter", p);
+	}
+
+	return skc_verify_tree();
+}
+
+/**
+ * skc_debug_dump() - Dump current SKC node list
+ *
+ * Dump the current SKC node list on printk buffer for debug.
+ */
+void __init skc_debug_dump(void)
+{
+	int i;
+
+	for (i = 0; i < skc_node_num; i++) {
+		pr_debug("[%d] %s (%s) .next=%d, .child=%d .parent=%d\n", i,
+			skc_node_get_data(skc_nodes + i),
+			skc_node_is_value(skc_nodes + i) ? "value" : "key",
+			skc_nodes[i].next, skc_nodes[i].child,
+			skc_nodes[i].parent);
+	}
+}


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 02/19] skc: Add /proc/sup_cmdline to show SKC key-value list
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
  2019-08-26  3:15 ` [RFC PATCH v3 01/19] skc: Add supplemental kernel cmdline support Masami Hiramatsu
@ 2019-08-26  3:16 ` Masami Hiramatsu
  2019-08-26  3:16 ` [RFC PATCH v3 03/19] skc: Add a boot setup routine from cmdline Masami Hiramatsu
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:16 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add /proc/sup_cmdline which shows the list of key-value pairs
in SKC data. Since after boot, all SKC data and tree are
removed, this interface just keep a copy of key-value
pairs in text.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 MAINTAINERS           |    1 
 fs/proc/Makefile      |    1 
 fs/proc/sup_cmdline.c |  106 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 fs/proc/sup_cmdline.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 67590c0e37c5..10dd38311d96 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15366,6 +15366,7 @@ SUPPLEMENTAL KERNEL CMDLINE
 M:	Masami Hiramatsu <mhiramat@kernel.org>
 S:	Maintained
 F:	lib/skc.c
+F:	fs/proc/sup_cmdline.c
 F:	include/linux/skc.h
 
 SUN3/3X
diff --git a/fs/proc/Makefile b/fs/proc/Makefile
index ead487e80510..a5d018f9422c 100644
--- a/fs/proc/Makefile
+++ b/fs/proc/Makefile
@@ -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_SKC)	+= sup_cmdline.o
diff --git a/fs/proc/sup_cmdline.c b/fs/proc/sup_cmdline.c
new file mode 100644
index 000000000000..97bc40f0c9dd
--- /dev/null
+++ b/fs/proc/sup_cmdline.c
@@ -0,0 +1,106 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * /proc/sup_cmdline - Supplemental kernel command line
+ */
+#include <linux/fs.h>
+#include <linux/init.h>
+#include <linux/printk.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <linux/skc.h>
+#include <linux/slab.h>
+
+static char *saved_sup_cmdline;
+
+static int skc_proc_show(struct seq_file *m, void *v)
+{
+	if (saved_sup_cmdline)
+		seq_puts(m, saved_sup_cmdline);
+	else
+		seq_putc(m, '\n');
+	return 0;
+}
+
+static int __init update_snprintf(char **dstp, size_t *sizep,
+				  const char *fmt, ...)
+{
+	va_list args;
+	int ret;
+
+	va_start(args, fmt);
+	ret = vsnprintf(*dstp, *sizep, fmt, args);
+	va_end(args);
+
+	if (*sizep && ret > 0) {
+		*sizep -= ret;
+		*dstp += ret;
+	}
+
+	return ret;
+}
+
+/* Return the needed total length if @size is 0 */
+static int __init copy_skc_key_value_list(char *dst, size_t size)
+{
+	struct skc_node *leaf, *vnode;
+	const char *val;
+	int len = 0, ret = 0;
+	char *key;
+
+	key = kzalloc(SKC_KEYLEN_MAX, GFP_KERNEL);
+
+	skc_for_each_key_value(leaf, val) {
+		ret = skc_node_compose_key(leaf, key, SKC_KEYLEN_MAX);
+		if (ret < 0)
+			break;
+		ret = update_snprintf(&dst, &size, "%s = ", key);
+		if (ret < 0)
+			break;
+		len += ret;
+		vnode = skc_node_get_child(leaf);
+		if (vnode && skc_node_is_array(vnode)) {
+			skc_array_for_each_value(vnode, val) {
+				ret = update_snprintf(&dst, &size, "\"%s\"%s",
+					val, vnode->next ? ", " : ";\n");
+				if (ret < 0)
+					goto out;
+				len += ret;
+			}
+		} else {
+			ret = update_snprintf(&dst, &size, "\"%s\";\n", val);
+			if (ret < 0)
+				break;
+			len += ret;
+		}
+	}
+out:
+	kfree(key);
+
+	return ret < 0 ? ret : len;
+}
+
+static int __init proc_skc_init(void)
+{
+	int len;
+
+	len = copy_skc_key_value_list(NULL, 0);
+	if (len < 0)
+		return len;
+
+	if (len > 0) {
+		saved_sup_cmdline = kzalloc(len + 1, GFP_KERNEL);
+		if (!saved_sup_cmdline)
+			return -ENOMEM;
+
+		len = copy_skc_key_value_list(saved_sup_cmdline, len + 1);
+		if (len < 0) {
+			kfree(saved_sup_cmdline);
+			return len;
+		}
+	}
+
+	proc_create_single("sup_cmdline", 0, NULL, skc_proc_show);
+
+	return 0;
+}
+fs_initcall(proc_skc_init);


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 03/19] skc: Add a boot setup routine from cmdline
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
  2019-08-26  3:15 ` [RFC PATCH v3 01/19] skc: Add supplemental kernel cmdline support Masami Hiramatsu
  2019-08-26  3:16 ` [RFC PATCH v3 02/19] skc: Add /proc/sup_cmdline to show SKC key-value list Masami Hiramatsu
@ 2019-08-26  3:16 ` Masami Hiramatsu
  2019-08-26  3:16 ` [RFC PATCH v3 04/19] Documentation: skc: Add a doc for supplemental kernel cmdline Masami Hiramatsu
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:16 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add a boot setup routine from cmdline option "skc=ADDR,SIZE".
Bootloader has to setup this cmdline option when it loads
the skc file on memory. The ADDR must be a physical address.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 Documentation/admin-guide/kernel-parameters.txt |    5 ++
 init/main.c                                     |   54 +++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 47d981a86e2f..9a955b1bd1bf 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4273,6 +4273,11 @@
 	simeth=		[IA-64]
 	simscsi=
 
+	skc=paddr,size	[SKC]
+			Pass the physical memory address and size of loaded
+			supplemental kernel cmdline (SKC) text. This will
+			be treated by bootloader which loads the SKC file.
+
 	slram=		[HW,MTD]
 
 	slab_nomerge	[MM]
diff --git a/init/main.c b/init/main.c
index 96f8d5af52d6..d06eb3d63b77 100644
--- a/init/main.c
+++ b/init/main.c
@@ -36,6 +36,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/start_kernel.h>
 #include <linux/security.h>
+#include <linux/skc.h>
 #include <linux/smp.h>
 #include <linux/profile.h>
 #include <linux/rcupdate.h>
@@ -245,6 +246,58 @@ static int __init loglevel(char *str)
 
 early_param("loglevel", loglevel);
 
+#ifdef CONFIG_SKC
+__initdata unsigned long initial_skc;
+__initdata unsigned long initial_skc_len;
+
+static int __init save_skc_address(char *str)
+{
+	char *p;
+
+	p = strchr(str, ',');
+	if (!p)
+		return -EINVAL;
+	*p++ = '\0';
+	/* First options should be physical address - int is not enough */
+	if (kstrtoul(str, 0, &initial_skc) < 0)
+		return -EINVAL;
+	if (kstrtoul(p, 0, &initial_skc_len) < 0)
+		return -EINVAL;
+	if (initial_skc_len > SKC_DATA_MAX)
+		return -E2BIG;
+	/* Reserve it for protection */
+	memblock_reserve(initial_skc, initial_skc_len);
+
+	return 0;
+}
+early_param("skc", save_skc_address);
+
+static void __init setup_skc(void)
+{
+	u32 size;
+	char *data, *copy;
+
+	if (!initial_skc)
+		return;
+
+	data = early_memremap(initial_skc, initial_skc_len);
+	size = initial_skc_len + 1;
+
+	copy = memblock_alloc(size, SMP_CACHE_BYTES);
+	if (!copy) {
+		pr_err("Failed to allocate memory for structured kernel cmdline\n");
+		goto end;
+	}
+	memcpy(copy, data, initial_skc_len);
+	copy[size - 1] = '\0';
+
+	skc_init(copy);
+end:
+	early_memunmap(data, initial_skc_len);
+}
+#else
+#define setup_skc()	do { } while (0)
+#endif
 /* Change NUL term back to "=", to make "param" the whole string. */
 static int __init repair_env_string(char *param, char *val,
 				    const char *unused, void *arg)
@@ -596,6 +649,7 @@ asmlinkage __visible void __init start_kernel(void)
 	setup_arch(&command_line);
 	mm_init_cpumask(&init_mm);
 	setup_command_line(command_line);
+	setup_skc();
 	setup_nr_cpu_ids();
 	setup_per_cpu_areas();
 	smp_prepare_boot_cpu();	/* arch-specific boot-cpu hooks */


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 04/19] Documentation: skc: Add a doc for supplemental kernel cmdline
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (2 preceding siblings ...)
  2019-08-26  3:16 ` [RFC PATCH v3 03/19] skc: Add a boot setup routine from cmdline Masami Hiramatsu
@ 2019-08-26  3:16 ` Masami Hiramatsu
  2019-08-26  3:16 ` [RFC PATCH v3 05/19] tracing: Apply soft-disabled and filter to tracepoints printk Masami Hiramatsu
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:16 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add a documentation for supplemental kernel cmdline under
admin-guide, since it is including the syntax of SKC file.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 Documentation/admin-guide/index.rst             |    1 
 Documentation/admin-guide/kernel-parameters.txt |    1 
 Documentation/admin-guide/skc.rst               |  123 +++++++++++++++++++++++
 MAINTAINERS                                     |    1 
 4 files changed, 126 insertions(+)
 create mode 100644 Documentation/admin-guide/skc.rst

diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guide/index.rst
index 33feab2f4084..44b4cb61003a 100644
--- a/Documentation/admin-guide/index.rst
+++ b/Documentation/admin-guide/index.rst
@@ -106,6 +106,7 @@ configure specific aspects of kernel behavior to your liking.
    rtc
    svga
    video-output
+   skc
 
 .. only::  subproject and html
 
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 9a955b1bd1bf..334ce59de23a 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4277,6 +4277,7 @@
 			Pass the physical memory address and size of loaded
 			supplemental kernel cmdline (SKC) text. This will
 			be treated by bootloader which loads the SKC file.
+			See Documentation/admin-guide/skc.rst.
 
 	slram=		[HW,MTD]
 
diff --git a/Documentation/admin-guide/skc.rst b/Documentation/admin-guide/skc.rst
new file mode 100644
index 000000000000..dc6f7ba8e1d7
--- /dev/null
+++ b/Documentation/admin-guide/skc.rst
@@ -0,0 +1,123 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+================================
+Supplemental Kernel Commandline
+================================
+
+:Author: Masami Hiramatsu <mhiramat@kernel.org>
+
+Overview
+========
+
+Supplemental Kernel Commandline (SKC) is expanding current kernel cmdline
+to support additional key-value data when boot the kernel in efficient way.
+This allows adoministrators to pass a tree-structured key-value text file
+(SKC file) via bootloaders.
+
+SKC File Syntax
+===============
+
+SKC basic syntax is simple. Each key consists of dot-connected-words, and
+key and value are connected by "=". The value has to be terminated by semi-
+colon (";"). For array value, array entries are separated by comma (",").
+
+KEY[.WORD[...]] = VALUE[, VALUE2[...]];
+
+Each key word only contains alphabet, number, dash ("-") or underscore ("_").
+If a value need to contain the delimiters, you can use double-quotes to
+quote it. A double quote in VALUE can be escaped by backslash. 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).
+
+Tree Structure
+--------------
+
+SKC 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;
+}
+
+In both style, same key words are automatically merged when parsing it
+at boot time. So you can append similar trees or key-values.
+
+SKC File Limitation
+===================
+
+Currently the maximum SKC file size is 32KB and the total key-words (not
+key-value entries) must be under 512 nodes.
+
+/proc/sup_cmdline
+=================
+
+/proc/sup_cmdline is the user-space interface of supplemental kernel
+cmdline. 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"...];
+
+How to Pass at Boot
+===================
+
+SKC file is passed to kernel via memory, so the boot loader must support
+loading SKC file. After loading the SKC file on memory, the boot loader
+has to add "skc=PADDR,SIZE" argument to kernel cmdline, where the PADDR
+is the physical address of the memory block and SIZE is the size of SKC
+file.
+
+SKC 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 skc_find_value(). If you want to know what keys exist in the SKC
+tree, you can use skc_for_each_key_value() to iterate key-value pairs.
+Note that you need to use skc_array_for_each_value() for accessing
+each arraies value, e.g.
+
+::
+
+ vnode = NULL;
+ skc_find_value("key.word", &vnode);
+ if (vnode && skc_node_is_array(vnode))
+    skc_array_for_each_value(vnode, value) {
+      printk("%s ", value);
+    }
+
+If you want to focus on keys which has a prefix string, you can use
+skc_find_node() to find a node which prefix key words, and iterate
+keys under the prefix node with skc_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 = skc_find_node("key.prefix");
+ value = skc_node_find_value(root, "option", &vnode);
+ ...
+ skc_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, SKC becomes readonly.
+All data and keys must be copied if you need to modify it.
+
+
+Functions and structures
+========================
+
+.. kernel-doc:: include/linux/skc.h
+.. kernel-doc:: lib/skc.c
+
diff --git a/MAINTAINERS b/MAINTAINERS
index 10dd38311d96..9c0b97643515 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15368,6 +15368,7 @@ S:	Maintained
 F:	lib/skc.c
 F:	fs/proc/sup_cmdline.c
 F:	include/linux/skc.h
+F:	Documentation/admin-guide/skc.rst
 
 SUN3/3X
 M:	Sam Creasey <sammy@sammy.net>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 05/19] tracing: Apply soft-disabled and filter to tracepoints printk
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (3 preceding siblings ...)
  2019-08-26  3:16 ` [RFC PATCH v3 04/19] Documentation: skc: Add a doc for supplemental kernel cmdline Masami Hiramatsu
@ 2019-08-26  3:16 ` Masami Hiramatsu
  2019-08-26  3:16 ` [RFC PATCH v3 06/19] tracing: kprobes: Output kprobe event to printk buffer Masami Hiramatsu
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:16 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Apply 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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 525a97fbbc60..ead3a9faa584 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2502,6 +2502,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;
@@ -2515,6 +2516,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);


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 06/19] tracing: kprobes: Output kprobe event to printk buffer
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (4 preceding siblings ...)
  2019-08-26  3:16 ` [RFC PATCH v3 05/19] tracing: Apply soft-disabled and filter to tracepoints printk Masami Hiramatsu
@ 2019-08-26  3:16 ` Masami Hiramatsu
  2019-08-26  3:17 ` [RFC PATCH v3 07/19] tracing: Expose EXPORT_SYMBOL_GPL symbol Masami Hiramatsu
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:16 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Since 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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 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(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 5150436783e8..8912ccdb3d4b 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -211,6 +211,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,
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index ead3a9faa584..605faf584164 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2572,9 +2572,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);
 
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index c7506bc81b75..22cf08bd2317 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -271,6 +271,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;
 }
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 9d483ad9bb6c..6c5145525f90 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -988,10 +988,8 @@ __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs,
 		    struct trace_event_file *trace_file)
 {
 	struct kprobe_trace_entry_head *entry;
-	struct ring_buffer_event *event;
-	struct ring_buffer *buffer;
-	int size, dsize, pc;
-	unsigned long irq_flags;
+	struct trace_event_buffer fbuffer;
+	int dsize;
 	struct trace_event_call *call = trace_probe_event_call(&tk->tp);
 
 	WARN_ON(call != trace_file->event_call);
@@ -999,24 +997,26 @@ __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs,
 	if (trace_trigger_soft_disabled(trace_file))
 		return;
 
-	local_save_flags(irq_flags);
-	pc = preempt_count();
+	local_save_flags(fbuffer.flags);
+	fbuffer.pc = preempt_count();
+	fbuffer.trace_file = trace_file;
 
 	dsize = __get_data_size(&tk->tp, regs);
-	size = sizeof(*entry) + tk->tp.size + dsize;
 
-	event = trace_event_buffer_lock_reserve(&buffer, trace_file,
-						call->event.type,
-						size, irq_flags, pc);
-	if (!event)
+	fbuffer.event =
+		trace_event_buffer_lock_reserve(&fbuffer.buffer, trace_file,
+					call->event.type,
+					sizeof(*entry) + tk->tp.size + dsize,
+					fbuffer.flags, fbuffer.pc);
+	if (!fbuffer.event)
 		return;
 
-	entry = ring_buffer_event_data(event);
+	fbuffer.regs = regs;
+	entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event);
 	entry->ip = (unsigned long)tk->rp.kp.addr;
 	store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize);
 
-	event_trigger_unlock_commit_regs(trace_file, buffer, event,
-					 entry, irq_flags, pc, regs);
+	trace_event_buffer_commit(&fbuffer);
 }
 
 static void
@@ -1036,10 +1036,8 @@ __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
 		       struct trace_event_file *trace_file)
 {
 	struct kretprobe_trace_entry_head *entry;
-	struct ring_buffer_event *event;
-	struct ring_buffer *buffer;
-	int size, pc, dsize;
-	unsigned long irq_flags;
+	struct trace_event_buffer fbuffer;
+	int dsize;
 	struct trace_event_call *call = trace_probe_event_call(&tk->tp);
 
 	WARN_ON(call != trace_file->event_call);
@@ -1047,25 +1045,26 @@ __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
 	if (trace_trigger_soft_disabled(trace_file))
 		return;
 
-	local_save_flags(irq_flags);
-	pc = preempt_count();
+	local_save_flags(fbuffer.flags);
+	fbuffer.pc = preempt_count();
+	fbuffer.trace_file = trace_file;
 
 	dsize = __get_data_size(&tk->tp, regs);
-	size = sizeof(*entry) + tk->tp.size + dsize;
-
-	event = trace_event_buffer_lock_reserve(&buffer, trace_file,
-						call->event.type,
-						size, irq_flags, pc);
-	if (!event)
+	fbuffer.event =
+		trace_event_buffer_lock_reserve(&fbuffer.buffer, trace_file,
+					call->event.type,
+					sizeof(*entry) + tk->tp.size + dsize,
+					fbuffer.flags, fbuffer.pc);
+	if (!fbuffer.event)
 		return;
 
-	entry = ring_buffer_event_data(event);
+	fbuffer.regs = regs;
+	entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event);
 	entry->func = (unsigned long)tk->rp.kp.addr;
 	entry->ret_ip = (unsigned long)ri->ret_addr;
 	store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize);
 
-	event_trigger_unlock_commit_regs(trace_file, buffer, event,
-					 entry, irq_flags, pc, regs);
+	trace_event_buffer_commit(&fbuffer);
 }
 
 static void


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 07/19] tracing: Expose EXPORT_SYMBOL_GPL symbol
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (5 preceding siblings ...)
  2019-08-26  3:16 ` [RFC PATCH v3 06/19] tracing: kprobes: Output kprobe event to printk buffer Masami Hiramatsu
@ 2019-08-26  3:17 ` Masami Hiramatsu
  2019-08-26  3:17 ` [RFC PATCH v3 08/19] tracing: kprobes: Register to dynevent earlier stage Masami Hiramatsu
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:17 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Since ftrace_set_clr_event is already exported by EXPORT_SYMBOL_GPL,
it should not be static.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace_events.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 22cf08bd2317..c2d38048edae 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -788,7 +788,7 @@ static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
 	return ret;
 }
 
-static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
+int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
 {
 	char *event = NULL, *sub = NULL, *match;
 	int ret;


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 08/19] tracing: kprobes: Register to dynevent earlier stage
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (6 preceding siblings ...)
  2019-08-26  3:17 ` [RFC PATCH v3 07/19] tracing: Expose EXPORT_SYMBOL_GPL symbol Masami Hiramatsu
@ 2019-08-26  3:17 ` Masami Hiramatsu
  2019-08-26  3:17 ` [RFC PATCH v3 09/19] tracing: Accept different type for synthetic event fields Masami Hiramatsu
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:17 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Register 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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace_kprobe.c |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 6c5145525f90..5135c07b6557 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1484,11 +1484,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);
@@ -1498,6 +1499,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;


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 09/19] tracing: Accept different type for synthetic event fields
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (7 preceding siblings ...)
  2019-08-26  3:17 ` [RFC PATCH v3 08/19] tracing: kprobes: Register to dynevent earlier stage Masami Hiramatsu
@ 2019-08-26  3:17 ` Masami Hiramatsu
  2019-08-26  3:17 ` [RFC PATCH v3 10/19] tracing: Add NULL trace-array check in print_synth_event() Masami Hiramatsu
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:17 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Make the synthetic event accepts a different type field to record.
However, the size and signed flag must be same.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace_events_hist.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index ca6b0dff60c5..a7f447195143 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -4063,8 +4063,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;
 }


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 10/19] tracing: Add NULL trace-array check in print_synth_event()
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (8 preceding siblings ...)
  2019-08-26  3:17 ` [RFC PATCH v3 09/19] tracing: Accept different type for synthetic event fields Masami Hiramatsu
@ 2019-08-26  3:17 ` Masami Hiramatsu
  2019-08-26  3:17 ` [RFC PATCH v3 11/19] tracing/boot: Add boot-time tracing by supplemental kernel cmdline Masami Hiramatsu
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:17 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add NULL trace-array check in print_synth_event(), because
if we enable tp_printk option, iter->tr can be NULL.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace_events_hist.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index a7f447195143..db973928e580 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -822,7 +822,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);


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 11/19] tracing/boot: Add boot-time tracing by supplemental kernel cmdline
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (9 preceding siblings ...)
  2019-08-26  3:17 ` [RFC PATCH v3 10/19] tracing: Add NULL trace-array check in print_synth_event() Masami Hiramatsu
@ 2019-08-26  3:17 ` Masami Hiramatsu
  2019-08-26  3:18 ` [RFC PATCH v3 12/19] tracing/boot: Add per-event settings Masami Hiramatsu
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:17 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Setup tracing options by supplemental kernel cmdline (skc) in addition
to kernel parameters. In this patch, add following commands support

 - ftrace.options = OPT1[,OPT2...];
   Enable given ftrace options.

 - ftrace.trace_clock = CLOCK;
   Set given CLOCK to ftrace's trace_clock.

 - ftrace.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.

 - ftrace.traceoff_on_warning;
   Stop tracing if WARN_ON() occurs.

 - ftrace.tp_printk;
   Output trace-event data on printk buffer too.

 - ftrace.buffer_size = SIZE;
   Configure ftrace buffer size to SIZE. You can use "KB" or "MB"
   for that SIZE.

 - ftrace.alloc_snapshot;
   Allocate snapshot buffer.

 - 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)

Since the kernel parameter is limited length, sometimes there is
no space to setup the tracing options. This will read the tracing
options from skc "ftrace" prefix and setup tracers at boot.

Note that this is not replacing the kernel parameters, because
this skc based setting is later than that. If you want to
trace earlier boot events, you still need kernel parameters.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/Kconfig      |    9 +++
 kernel/trace/Makefile     |    1 
 kernel/trace/trace.c      |   38 ++++++++----
 kernel/trace/trace_boot.c |  137 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 172 insertions(+), 13 deletions(-)
 create mode 100644 kernel/trace/trace_boot.c

diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index 98da8998c25c..0f831adb4e4a 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -797,6 +797,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 SKC && 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
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index c2b2148bb1d2..f9d3c2c72fb5 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -82,6 +82,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
 
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 605faf584164..69400a87e48f 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -158,7 +158,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);
 
@@ -178,6 +178,11 @@ static int __init set_cmdline_ftrace(char *str)
 }
 __setup("ftrace=", set_cmdline_ftrace);
 
+void __init trace_init_dump_on_oops(int mode)
+{
+	ftrace_dump_on_oops = mode;
+}
+
 static int __init set_ftrace_dump_on_oops(char *str)
 {
 	if (*str++ != '=' || !*str) {
@@ -4614,7 +4619,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;
@@ -5505,8 +5510,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;
 
@@ -5585,7 +5590,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
@@ -9170,16 +9175,23 @@ __init static int tracer_alloc_buffers(void)
 	return ret;
 }
 
+void __init trace_init_tracepoint_printk(void)
+{
+	tracepoint_printk = 1;
+
+	tracepoint_print_iter =
+		kmalloc(sizeof(*tracepoint_print_iter), GFP_KERNEL);
+	if (WARN_ON(!tracepoint_print_iter))
+		tracepoint_printk = 0;
+	else
+		static_key_enable(&tracepoint_printk_key.key);
+}
+
 void __init early_trace_init(void)
 {
-	if (tracepoint_printk) {
-		tracepoint_print_iter =
-			kmalloc(sizeof(*tracepoint_print_iter), GFP_KERNEL);
-		if (WARN_ON(!tracepoint_print_iter))
-			tracepoint_printk = 0;
-		else
-			static_key_enable(&tracepoint_printk_key.key);
-	}
+	if (tracepoint_printk)
+		trace_init_tracepoint_printk();
+
 	tracer_alloc_buffers();
 }
 
diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c
new file mode 100644
index 000000000000..cc5e81368065
--- /dev/null
+++ b/kernel/trace/trace_boot.c
@@ -0,0 +1,137 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * trace_boot.c
+ * Tracing kernel boot-time
+ */
+
+#define pr_fmt(fmt)	"trace_boot: " fmt
+
+#include <linux/ftrace.h>
+#include <linux/init.h>
+#include <linux/skc.h>
+
+#include "trace.h"
+
+#define MAX_BUF_LEN 256
+
+extern int trace_set_options(struct trace_array *tr, char *option);
+extern enum ftrace_dump_mode ftrace_dump_on_oops;
+extern int __disable_trace_on_warning;
+extern int tracing_set_tracer(struct trace_array *tr, const char *buf);
+extern void __init trace_init_tracepoint_printk(void);
+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 skc_node *node)
+{
+	struct skc_node *anode;
+	const char *p;
+	char buf[MAX_BUF_LEN];
+	unsigned long v = 0;
+	int err;
+
+	/* Common ftrace options */
+	skc_node_for_each_array_value(node, "options", anode, p) {
+		if (strlcpy(buf, p, ARRAY_SIZE(buf)) >= ARRAY_SIZE(buf)) {
+			pr_err("String is too long: %s\n", p);
+			continue;
+		}
+
+		if (trace_set_options(tr, buf) < 0)
+			pr_err("Failed to set option: %s\n", buf);
+	}
+
+	p = skc_node_find_value(node, "trace_clock", NULL);
+	if (p && *p != '\0') {
+		if (tracing_set_clock(tr, p) < 0)
+			pr_err("Failed to set trace clock: %s\n", p);
+	}
+
+	/* Command line boot options */
+	p = skc_node_find_value(node, "dump_on_oops", NULL);
+	if (p) {
+		err = kstrtoul(p, 0, &v);
+		if (err || v == 1)
+			ftrace_dump_on_oops = DUMP_ALL;
+		else if (!err && v == 2)
+			ftrace_dump_on_oops = DUMP_ORIG;
+	}
+
+	if (skc_node_find_value(node, "traceoff_on_warning", NULL))
+		__disable_trace_on_warning = 1;
+
+	if (skc_node_find_value(node, "tp_printk", NULL))
+		trace_init_tracepoint_printk();
+
+	p = skc_node_find_value(node, "buffer_size", NULL);
+	if (p && *p != '\0') {
+		v = memparse(p, NULL);
+		if (v < PAGE_SIZE)
+			pr_err("Buffer size is too small: %s\n", p);
+		if (tracing_resize_ring_buffer(tr, v, RING_BUFFER_ALL_CPUS) < 0)
+			pr_err("Failed to resize trace buffer to %s\n", p);
+	}
+
+	if (skc_node_find_value(node, "alloc_snapshot", NULL))
+		if (tracing_alloc_snapshot() < 0)
+			pr_err("Failed to allocate snapshot buffer\n");
+}
+
+#ifdef CONFIG_EVENT_TRACING
+extern int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
+
+static void __init
+trace_boot_enable_events(struct trace_array *tr, struct skc_node *node)
+{
+	struct skc_node *anode;
+	char buf[MAX_BUF_LEN];
+	const char *p;
+
+	skc_node_for_each_array_value(node, "events", anode, p) {
+		if (strlcpy(buf, p, ARRAY_SIZE(buf)) >= ARRAY_SIZE(buf)) {
+			pr_err("String is too long: %s\n", p);
+			continue;
+		}
+
+		if (ftrace_set_clr_event(tr, buf, 1) < 0)
+			pr_err("Failed to enable event: %s\n", p);
+	}
+}
+#else
+#define trace_boot_enable_events(tr, node) do {} while (0)
+#endif
+
+static void __init
+trace_boot_enable_tracer(struct trace_array *tr, struct skc_node *node)
+{
+	const char *p;
+
+	p = skc_node_find_value(node, "tracer", NULL);
+	if (p && *p != '\0') {
+		if (tracing_set_tracer(tr, p) < 0)
+			pr_err("Failed to set given tracer: %s\n", p);
+	}
+}
+
+static int __init trace_boot_init(void)
+{
+	struct skc_node *trace_node;
+	struct trace_array *tr;
+
+	trace_node = skc_find_node("ftrace");
+	if (!trace_node)
+		return 0;
+
+	tr = top_trace_array();
+	if (!tr)
+		return 0;
+
+	trace_boot_set_ftrace_options(tr, trace_node);
+	trace_boot_enable_events(tr, trace_node);
+	trace_boot_enable_tracer(tr, trace_node);
+
+	return 0;
+}
+
+fs_initcall(trace_boot_init);


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 12/19] tracing/boot: Add per-event settings
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (10 preceding siblings ...)
  2019-08-26  3:17 ` [RFC PATCH v3 11/19] tracing/boot: Add boot-time tracing by supplemental kernel cmdline Masami Hiramatsu
@ 2019-08-26  3:18 ` Masami Hiramatsu
  2019-08-26  3:18 ` [RFC PATCH v3 13/19] tracing/boot Add kprobe event support Masami Hiramatsu
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:18 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add 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
commands.

 - 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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace_boot.c           |   60 +++++++++++++++++++++++++++++++++++
 kernel/trace/trace_events_trigger.c |    2 +
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c
index cc5e81368065..cfd628c16761 100644
--- a/kernel/trace/trace_boot.c
+++ b/kernel/trace/trace_boot.c
@@ -80,6 +80,7 @@ trace_boot_set_ftrace_options(struct trace_array *tr, struct skc_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 skc_node *node)
@@ -98,8 +99,66 @@ trace_boot_enable_events(struct trace_array *tr, struct skc_node *node)
 			pr_err("Failed to enable event: %s\n", p);
 	}
 }
+
+static void __init
+trace_boot_init_one_event(struct trace_array *tr, struct skc_node *gnode,
+			  struct skc_node *enode)
+{
+	struct trace_event_file *file;
+	struct skc_node *anode;
+	char buf[MAX_BUF_LEN];
+	const char *p, *group, *event;
+
+	group = skc_node_get_data(gnode);
+	event = skc_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 = skc_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);
+	}
+
+	skc_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 (skc_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 skc_node *node)
+{
+	struct skc_node *gnode, *enode;
+
+	node = skc_node_find_child(node, "event");
+	if (!node)
+		return;
+	/* per-event key starts with "event.GROUP.EVENT" */
+	skc_node_for_each_child(node, gnode)
+		skc_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
@@ -128,6 +187,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);
 
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index 2a2912cb4533..74a19c18219f 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -208,7 +208,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;


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 13/19] tracing/boot Add kprobe event support
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (11 preceding siblings ...)
  2019-08-26  3:18 ` [RFC PATCH v3 12/19] tracing/boot: Add per-event settings Masami Hiramatsu
@ 2019-08-26  3:18 ` Masami Hiramatsu
  2019-08-26  3:18 ` [RFC PATCH v3 14/19] tracing/boot: Add synthetic " Masami Hiramatsu
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:18 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add kprobe event support on event node. If the group name of event
is "kprobes", boottime trace 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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace_boot.c   |   46 +++++++++++++++++++++++++++++++++++++++++++
 kernel/trace/trace_kprobe.c |    5 +++++
 2 files changed, 51 insertions(+)

diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c
index cfd628c16761..40c89c7ceee0 100644
--- a/kernel/trace/trace_boot.c
+++ b/kernel/trace/trace_boot.c
@@ -100,6 +100,48 @@ trace_boot_enable_events(struct trace_array *tr, struct skc_node *node)
 	}
 }
 
+#ifdef CONFIG_KPROBE_EVENTS
+extern int trace_kprobe_run_command(const char *command);
+
+static int __init
+trace_boot_add_kprobe_event(struct skc_node *node, const char *event)
+{
+	struct skc_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;
+
+	skc_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 skc_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 skc_node *gnode,
 			  struct skc_node *enode)
@@ -112,6 +154,10 @@ trace_boot_init_one_event(struct trace_array *tr, struct skc_node *gnode,
 	group = skc_node_get_data(gnode);
 	event = skc_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) {
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 5135c07b6557..03ce60928c18 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -728,6 +728,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);


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 14/19] tracing/boot: Add synthetic event support
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (12 preceding siblings ...)
  2019-08-26  3:18 ` [RFC PATCH v3 13/19] tracing/boot Add kprobe event support Masami Hiramatsu
@ 2019-08-26  3:18 ` Masami Hiramatsu
  2019-08-26  3:18 ` [RFC PATCH v3 15/19] tracing/boot: Add instance node support Masami Hiramatsu
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:18 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add synthetic event node support. 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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace_boot.c        |   47 ++++++++++++++++++++++++++++++++++++++
 kernel/trace/trace_events_hist.c |    5 ++++
 2 files changed, 52 insertions(+)

diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c
index 40c89c7ceee0..2e9fddff660f 100644
--- a/kernel/trace/trace_boot.c
+++ b/kernel/trace/trace_boot.c
@@ -142,6 +142,50 @@ trace_boot_add_kprobe_event(struct skc_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 skc_node *node, const char *event)
+{
+	struct skc_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;
+
+	skc_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 skc_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 skc_node *gnode,
 			  struct skc_node *enode)
@@ -157,6 +201,9 @@ trace_boot_init_one_event(struct trace_array *tr, struct skc_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);
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index db973928e580..e7f5d0a353e2 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -1343,6 +1343,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];


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 15/19] tracing/boot: Add instance node support
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (13 preceding siblings ...)
  2019-08-26  3:18 ` [RFC PATCH v3 14/19] tracing/boot: Add synthetic " Masami Hiramatsu
@ 2019-08-26  3:18 ` Masami Hiramatsu
  2019-08-26  3:18 ` [RFC PATCH v3 16/19] tracing/boot: Add cpu_mask option support Masami Hiramatsu
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:18 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add instance node support to boottime 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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace_boot.c |   72 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 57 insertions(+), 15 deletions(-)

diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c
index 2e9fddff660f..74cffecd12a4 100644
--- a/kernel/trace/trace_boot.c
+++ b/kernel/trace/trace_boot.c
@@ -21,15 +21,15 @@ extern int tracing_set_tracer(struct trace_array *tr, const char *buf);
 extern void __init trace_init_tracepoint_printk(void);
 extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
 					  unsigned long size, int cpu_id);
+extern struct trace_array *trace_array_create(const char *name);
 
 static void __init
-trace_boot_set_ftrace_options(struct trace_array *tr, struct skc_node *node)
+trace_boot_set_instance_options(struct trace_array *tr, struct skc_node *node)
 {
 	struct skc_node *anode;
 	const char *p;
 	char buf[MAX_BUF_LEN];
 	unsigned long v = 0;
-	int err;
 
 	/* Common ftrace options */
 	skc_node_for_each_array_value(node, "options", anode, p) {
@@ -48,6 +48,23 @@ trace_boot_set_ftrace_options(struct trace_array *tr, struct skc_node *node)
 			pr_err("Failed to set trace clock: %s\n", p);
 	}
 
+	p = skc_node_find_value(node, "buffer_size", NULL);
+	if (p && *p != '\0') {
+		v = memparse(p, NULL);
+		if (v < PAGE_SIZE)
+			pr_err("Buffer size is too small: %s\n", p);
+		if (tracing_resize_ring_buffer(tr, v, RING_BUFFER_ALL_CPUS) < 0)
+			pr_err("Failed to resize trace buffer to %s\n", p);
+	}
+}
+
+static void __init
+trace_boot_set_global_options(struct trace_array *tr, struct skc_node *node)
+{
+	unsigned long v = 0;
+	const char *p;
+	int err;
+
 	/* Command line boot options */
 	p = skc_node_find_value(node, "dump_on_oops", NULL);
 	if (p) {
@@ -64,15 +81,6 @@ trace_boot_set_ftrace_options(struct trace_array *tr, struct skc_node *node)
 	if (skc_node_find_value(node, "tp_printk", NULL))
 		trace_init_tracepoint_printk();
 
-	p = skc_node_find_value(node, "buffer_size", NULL);
-	if (p && *p != '\0') {
-		v = memparse(p, NULL);
-		if (v < PAGE_SIZE)
-			pr_err("Buffer size is too small: %s\n", p);
-		if (tracing_resize_ring_buffer(tr, v, RING_BUFFER_ALL_CPUS) < 0)
-			pr_err("Failed to resize trace buffer to %s\n", p);
-	}
-
 	if (skc_node_find_value(node, "alloc_snapshot", NULL))
 		if (tracing_alloc_snapshot() < 0)
 			pr_err("Failed to allocate snapshot buffer\n");
@@ -266,6 +274,40 @@ trace_boot_enable_tracer(struct trace_array *tr, struct skc_node *node)
 	}
 }
 
+static void __init
+trace_boot_init_one_instance(struct trace_array *tr, struct skc_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 skc_node *node)
+{
+	struct skc_node *inode;
+	struct trace_array *tr;
+	const char *p;
+
+	node = skc_node_find_child(node, "instance");
+	if (!node)
+		return;
+
+	skc_node_for_each_child(node, inode) {
+		p = skc_node_get_data(inode);
+		if (!p || *p == '\0')
+			continue;
+
+		tr = trace_array_create(p);
+		if (IS_ERR(tr)) {
+			pr_err("Failed to create instance %s\n", p);
+			continue;
+		}
+		trace_boot_init_one_instance(tr, inode);
+	}
+}
+
 static int __init trace_boot_init(void)
 {
 	struct skc_node *trace_node;
@@ -279,10 +321,10 @@ 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);
+	trace_boot_set_global_options(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;
 }


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 16/19] tracing/boot: Add cpu_mask option support
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (14 preceding siblings ...)
  2019-08-26  3:18 ` [RFC PATCH v3 15/19] tracing/boot: Add instance node support Masami Hiramatsu
@ 2019-08-26  3:18 ` Masami Hiramatsu
  2019-08-26  3:18 ` [RFC PATCH v3 17/19] tracing/boot: Add function tracer filter options Masami Hiramatsu
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:18 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add ftrace.cpumask option support for setting trace
cpumask.

 - ftrace.[instance.INSTANCE.]cpumask = CPUMASK;
   Set the trace cpumask. Note that the CPUMASK should be a string
   which <tracefs>/tracing_cpumask can accepts.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace.c      |   41 ++++++++++++++++++++++++++++-------------
 kernel/trace/trace_boot.c |   14 ++++++++++++++
 2 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 69400a87e48f..bfe513e472d2 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -4437,20 +4437,12 @@ 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);
@@ -4474,11 +4466,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;
diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c
index 74cffecd12a4..755a2040aebf 100644
--- a/kernel/trace/trace_boot.c
+++ b/kernel/trace/trace_boot.c
@@ -22,6 +22,8 @@ extern void __init trace_init_tracepoint_printk(void);
 extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
 					  unsigned long size, int cpu_id);
 extern struct trace_array *trace_array_create(const char *name);
+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 skc_node *node)
@@ -56,6 +58,18 @@ trace_boot_set_instance_options(struct trace_array *tr, struct skc_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 = skc_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);
+		}
+	}
 }
 
 static void __init


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 17/19] tracing/boot: Add function tracer filter options
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (15 preceding siblings ...)
  2019-08-26  3:18 ` [RFC PATCH v3 16/19] tracing/boot: Add cpu_mask option support Masami Hiramatsu
@ 2019-08-26  3:18 ` Masami Hiramatsu
  2019-08-26  3:19 ` [RFC PATCH v3 18/19] tracing/boot: Add function-graph tracer options Masami Hiramatsu
  2019-08-26  3:19 ` [RFC PATCH v3 19/19] Documentation: tracing: Add boot-time tracing document Masami Hiramatsu
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:18 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add below function-tracer filter options to boottime tracer.

 - 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

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/trace_boot.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c
index 755a2040aebf..942ca8d3fcc8 100644
--- a/kernel/trace/trace_boot.c
+++ b/kernel/trace/trace_boot.c
@@ -276,11 +276,51 @@ trace_boot_init_events(struct trace_array *tr, struct skc_node *node)
 #define trace_boot_init_events(tr, node) do {} while (0)
 #endif
 
+#ifdef CONFIG_FUNCTION_TRACER
+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 skc_node *node)
+{
+	struct skc_node *anode;
+	const char *p;
+	char *q;
+
+	skc_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);
+	}
+	skc_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 skc_node *node)
 {
 	const char *p;
 
+	trace_boot_set_ftrace_filter(tr, node);
+
 	p = skc_node_find_value(node, "tracer", NULL);
 	if (p && *p != '\0') {
 		if (tracing_set_tracer(tr, p) < 0)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 18/19] tracing/boot: Add function-graph tracer options
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (16 preceding siblings ...)
  2019-08-26  3:18 ` [RFC PATCH v3 17/19] tracing/boot: Add function tracer filter options Masami Hiramatsu
@ 2019-08-26  3:19 ` Masami Hiramatsu
  2019-08-26  3:19 ` [RFC PATCH v3 19/19] Documentation: tracing: Add boot-time tracing document Masami Hiramatsu
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:19 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add following function-graph tracer related options

 - ftrace.fgraph.filters = FILTER[, FILTER2...];
   Add fgraph tracing function filters.

 - ftrace.fgraph.notraces = FILTER[, FILTER2...];
   Add fgraph non tracing function filters.

 - ftrace.fgraph.max_depth = MAX_DEPTH;
   Set MAX_DEPTH to maximum depth of fgraph tracer.

Note that these properties are available on ftrace global node
only, because these filters are globally applied.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/trace/ftrace.c     |   85 +++++++++++++++++++++++++++++----------------
 kernel/trace/trace_boot.c |   71 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+), 30 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index eca34503f178..e016ce12e60a 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1241,7 +1241,7 @@ static void clear_ftrace_mod_list(struct list_head *head)
 	mutex_unlock(&ftrace_lock);
 }
 
-static void free_ftrace_hash(struct ftrace_hash *hash)
+void free_ftrace_hash(struct ftrace_hash *hash)
 {
 	if (!hash || hash == EMPTY_HASH)
 		return;
@@ -4897,7 +4897,7 @@ __setup("ftrace_filter=", set_ftrace_filter);
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 static char ftrace_graph_buf[FTRACE_FILTER_SIZE] __initdata;
 static char ftrace_graph_notrace_buf[FTRACE_FILTER_SIZE] __initdata;
-static int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);
+int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);
 
 static int __init set_graph_function(char *str)
 {
@@ -5226,6 +5226,26 @@ __ftrace_graph_open(struct inode *inode, struct file *file,
 	return ret;
 }
 
+struct ftrace_hash *ftrace_graph_copy_hash(bool enable)
+{
+	struct ftrace_hash *hash;
+
+	mutex_lock(&graph_lock);
+
+	if (enable)
+		hash = rcu_dereference_protected(ftrace_graph_hash,
+					lockdep_is_held(&graph_lock));
+	else
+		hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
+					lockdep_is_held(&graph_lock));
+
+	hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, hash);
+
+	mutex_unlock(&graph_lock);
+
+	return hash;
+}
+
 static int
 ftrace_graph_open(struct inode *inode, struct file *file)
 {
@@ -5282,11 +5302,40 @@ ftrace_graph_notrace_open(struct inode *inode, struct file *file)
 	return ret;
 }
 
+int ftrace_graph_apply_hash(struct ftrace_hash *hash, bool enable)
+{
+	struct ftrace_hash *old_hash, *new_hash;
+
+	new_hash = __ftrace_hash_move(hash);
+	if (!new_hash)
+		return -ENOMEM;
+
+	mutex_lock(&graph_lock);
+
+	if (enable) {
+		old_hash = rcu_dereference_protected(ftrace_graph_hash,
+				lockdep_is_held(&graph_lock));
+		rcu_assign_pointer(ftrace_graph_hash, new_hash);
+	} else {
+		old_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
+				lockdep_is_held(&graph_lock));
+		rcu_assign_pointer(ftrace_graph_notrace_hash, new_hash);
+	}
+
+	mutex_unlock(&graph_lock);
+
+	/* Wait till all users are no longer using the old hash */
+	synchronize_rcu();
+
+	free_ftrace_hash(old_hash);
+
+	return 0;
+}
+
 static int
 ftrace_graph_release(struct inode *inode, struct file *file)
 {
 	struct ftrace_graph_data *fgd;
-	struct ftrace_hash *old_hash, *new_hash;
 	struct trace_parser *parser;
 	int ret = 0;
 
@@ -5311,41 +5360,17 @@ ftrace_graph_release(struct inode *inode, struct file *file)
 
 		trace_parser_put(parser);
 
-		new_hash = __ftrace_hash_move(fgd->new_hash);
-		if (!new_hash) {
-			ret = -ENOMEM;
-			goto out;
-		}
-
-		mutex_lock(&graph_lock);
-
-		if (fgd->type == GRAPH_FILTER_FUNCTION) {
-			old_hash = rcu_dereference_protected(ftrace_graph_hash,
-					lockdep_is_held(&graph_lock));
-			rcu_assign_pointer(ftrace_graph_hash, new_hash);
-		} else {
-			old_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
-					lockdep_is_held(&graph_lock));
-			rcu_assign_pointer(ftrace_graph_notrace_hash, new_hash);
-		}
-
-		mutex_unlock(&graph_lock);
-
-		/* Wait till all users are no longer using the old hash */
-		synchronize_rcu();
-
-		free_ftrace_hash(old_hash);
+		ret = ftrace_graph_apply_hash(fgd->new_hash,
+					fgd->type == GRAPH_FILTER_FUNCTION);
 	}
 
- out:
 	free_ftrace_hash(fgd->new_hash);
 	kfree(fgd);
 
 	return ret;
 }
 
-static int
-ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer)
+int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer)
 {
 	struct ftrace_glob func_g;
 	struct dyn_ftrace *rec;
diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c
index 942ca8d3fcc8..b32688032d36 100644
--- a/kernel/trace/trace_boot.c
+++ b/kernel/trace/trace_boot.c
@@ -72,6 +72,75 @@ trace_boot_set_instance_options(struct trace_array *tr, struct skc_node *node)
 	}
 }
 
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+extern unsigned int fgraph_max_depth;
+extern struct ftrace_hash *ftrace_graph_copy_hash(bool enable);
+extern int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);
+extern int ftrace_graph_apply_hash(struct ftrace_hash *hash, bool enable);
+extern void free_ftrace_hash(struct ftrace_hash *hash);
+
+static void __init
+trace_boot_set_fgraph_filter(struct skc_node *node, const char *option,
+			     bool enable)
+{
+	struct ftrace_hash *hash;
+	struct skc_node *anode;
+	const char *p;
+	char *q;
+	int err;
+	bool updated = false;
+
+	hash = ftrace_graph_copy_hash(enable);
+	if (!hash) {
+		pr_err("Failed to copy fgraph hash\n");
+		return;
+	}
+	skc_node_for_each_array_value(node, option, anode, p) {
+		q = kstrdup(p, GFP_KERNEL);
+		if (!q)
+			goto free_hash;
+		err = ftrace_graph_set_hash(hash, q);
+		kfree(q);
+		if (err)
+			pr_err("Failed to add %s: %s\n", option, p);
+		else
+			updated = true;
+	}
+	if (!updated)
+		goto free_hash;
+
+	if (ftrace_graph_apply_hash(hash, enable) < 0)
+		pr_err("Failed to apply new fgraph hash\n");
+	else {
+		/* If succeeded to apply new hash, old hash is released */
+		return;
+	}
+
+free_hash:
+	free_ftrace_hash(hash);
+}
+
+static void __init
+trace_boot_set_fgraph_options(struct skc_node *node)
+{
+	const char *p;
+	unsigned long v;
+
+	node = skc_node_find_child(node, "fgraph");
+	if (!node)
+		return;
+
+	trace_boot_set_fgraph_filter(node, "filters", true);
+	trace_boot_set_fgraph_filter(node, "notraces", false);
+
+	p = skc_node_find_value(node, "max_depth", NULL);
+	if (p && *p != '\0' && !kstrtoul(p, 0, &v))
+		fgraph_max_depth = (unsigned int)v;
+}
+#else
+#define trace_boot_set_fgraph_options(node)	do {} while (0)
+#endif
+
 static void __init
 trace_boot_set_global_options(struct trace_array *tr, struct skc_node *node)
 {
@@ -98,6 +167,8 @@ trace_boot_set_global_options(struct trace_array *tr, struct skc_node *node)
 	if (skc_node_find_value(node, "alloc_snapshot", NULL))
 		if (tracing_alloc_snapshot() < 0)
 			pr_err("Failed to allocate snapshot buffer\n");
+
+	trace_boot_set_fgraph_options(node);
 }
 
 #ifdef CONFIG_EVENT_TRACING


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH v3 19/19] Documentation: tracing: Add boot-time tracing document
  2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
                   ` (17 preceding siblings ...)
  2019-08-26  3:19 ` [RFC PATCH v3 18/19] tracing/boot: Add function-graph tracer options Masami Hiramatsu
@ 2019-08-26  3:19 ` Masami Hiramatsu
  18 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-26  3:19 UTC (permalink / raw)
  To: Steven Rostedt, Frank Rowand
  Cc: Ingo Molnar, Namhyung Kim, Tim Bird, Jiri Olsa,
	Arnaldo Carvalho de Melo, Tom Zanussi, Rob Herring,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds, linux-doc,
	linux-fsdevel, linux-kernel

Add a documentation about boot-time tracing options for
SKC file.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 Documentation/trace/boottime-trace.rst |  185 ++++++++++++++++++++++++++++++++
 1 file changed, 185 insertions(+)
 create mode 100644 Documentation/trace/boottime-trace.rst

diff --git a/Documentation/trace/boottime-trace.rst b/Documentation/trace/boottime-trace.rst
new file mode 100644
index 000000000000..fc074afd014e
--- /dev/null
+++ b/Documentation/trace/boottime-trace.rst
@@ -0,0 +1,185 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=================
+Boot-time tracing
+=================
+
+:Author: Masami Hiramatsu <mhiramat@kernel.org>
+
+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 supplemental kernel cmdline (SKC) to describe tracing
+feature programming.
+
+Options in Supplemental Kernel Cmdline
+======================================
+
+Here is the list of available options list for boot time tracing in
+supplemental kenrel cmdline file [1]_. All options are under "ftrace."
+prefix to isolate from other subsystems.
+
+.. [1] See Documentation/admin-guide/skc.rst for details.
+
+Ftrace Global Options
+---------------------
+
+These options are only for global ftrace node since these are globally
+applied.
+
+ftrace.tp_printk;
+   Output trace-event data on printk buffer too.
+
+ftrace.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.
+
+ftrace.traceoff_on_warning;
+   Stop tracing if WARN_ON() occurs.
+
+ftrace.fgraph.filters = FILTER[, FILTER2...];
+   Add fgraph tracing function filters.
+
+ftrace.fgraph.notraces = FILTER[, FILTER2...];
+   Add fgraph non tracing function filters.
+
+ftrace.fgraph.max_depth = MAX_DEPTH;
+   Set MAX_DEPTH to maximum depth of fgraph tracer.
+
+
+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.]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
+
+ftrace.[instance.INSTANCE.]ftrace.notraces
+   This will take an array of NON-tracing function filter rules
+
+
+Ftrace Per-Event Options
+------------------------
+
+These options are setting per-event options.
+
+ftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable;
+   Enables GROUP:EVENT tracing.
+
+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 SKC 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, boottime tracing supports "instance" node, which allows us to run
+several tracers for different purpose at once. For example, one tracer
+is for tracing functions in module alpha, and others tracing module beta,
+you can write as below.
+
+::
+
+  ftrace.instance {
+        foo {
+                tracer = "function";
+                ftrace-filters = "*:mod:alpha";
+        }
+        bar {
+                tracer = "function";
+                ftrace-filters = "*:mod:beta";
+        }
+  }
+
+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*"
+
+This can be written in SKC 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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [RFC PATCH v3 01/19] skc: Add supplemental kernel cmdline support
  2019-08-26  3:15 ` [RFC PATCH v3 01/19] skc: Add supplemental kernel cmdline support Masami Hiramatsu
@ 2019-08-26 13:27   ` Rob Herring
  2019-08-27  2:37     ` Masami Hiramatsu
  0 siblings, 1 reply; 22+ messages in thread
From: Rob Herring @ 2019-08-26 13:27 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Steven Rostedt, Frank Rowand, Ingo Molnar, Namhyung Kim,
	Tim Bird, Jiri Olsa, Arnaldo Carvalho de Melo, Tom Zanussi,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds,
	Linux Doc Mailing List, linux-fsdevel, linux-kernel

On Sun, Aug 25, 2019 at 10:15 PM Masami Hiramatsu <mhiramat@kernel.org> wrote:
>
> Supplemental kernel command line (SKC) allows admin to pass a
> tree-structured supplemental kernel commandline file (SKC file)
> when boot up kernel. This expands the kernel command line in
> efficient way.
>
> SKC file 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";
> }

Why invent a custom file format? You could use YAML (or JSON):

key:
 word1:
  setting1: data
  setting2: true
 word2:
  - val1
  - val2


That would allow you to define a schema for defined options and can
easily be manipulated with python (or any language with dictionaries
and lists). That does imply adding a YAML parser to the kernel which
I'm not sure is a great idea. There is a C parser lib, but working
with YAML in C is not that great compared to python.

Another option would be using the DTS format, but as a separate file.
That's not unprecedented as u-boot FIT image is a DTB. Then the kernel
already has the parser. And you could still have schema now.

A new interface will take a lot of bootloader work to make it easy to
use given the user has to manually load some file in the bootloader
and know a good address to load it to. Between that and rebuilding the
kernel with the configuration, I'd pick rebuilding the kernel. Perhaps
this version will highlight that the original proposal was not so bad.


Another thought, maybe you could process the configuration file that's
in a readable/editable format into a flat representation that could
simply be added to the kernel command line:

key.word1.setting1=data key.word1.setting2 key.word2=val1,val2

That would then use an existing interface and probably simplify the
kernel parsing.

Rob

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [RFC PATCH v3 01/19] skc: Add supplemental kernel cmdline support
  2019-08-26 13:27   ` Rob Herring
@ 2019-08-27  2:37     ` Masami Hiramatsu
  0 siblings, 0 replies; 22+ messages in thread
From: Masami Hiramatsu @ 2019-08-27  2:37 UTC (permalink / raw)
  To: Rob Herring
  Cc: Steven Rostedt, Frank Rowand, Ingo Molnar, Namhyung Kim,
	Tim Bird, Jiri Olsa, Arnaldo Carvalho de Melo, Tom Zanussi,
	Andrew Morton, Thomas Gleixner, Greg Kroah-Hartman,
	Alexey Dobriyan, Jonathan Corbet, Linus Torvalds,
	Linux Doc Mailing List, linux-fsdevel, linux-kernel

Hi Rob,

Thank you for your comment!

On Mon, 26 Aug 2019 08:27:48 -0500
Rob Herring <robh+dt@kernel.org> wrote:

> On Sun, Aug 25, 2019 at 10:15 PM Masami Hiramatsu <mhiramat@kernel.org> wrote:
> >
> > Supplemental kernel command line (SKC) allows admin to pass a
> > tree-structured supplemental kernel commandline file (SKC file)
> > when boot up kernel. This expands the kernel command line in
> > efficient way.
> >
> > SKC file 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";
> > }
> 
> Why invent a custom file format? You could use YAML (or JSON):

Yeah, actually my early idea was using JSON, since it is widely used and
many good tools. However, I thought that is not human friendly format :(.
I would like to give an easy to read/write but structured interface.

> 
> key:
>  word1:
>   setting1: data
>   setting2: true
>  word2:
>   - val1
>   - val2

(Ah, in above example "array" is just a part of key, and is not
a reserved word.)

> That would allow you to define a schema for defined options and can
> easily be manipulated with python (or any language with dictionaries
> and lists). That does imply adding a YAML parser to the kernel which
> I'm not sure is a great idea. There is a C parser lib, but working
> with YAML in C is not that great compared to python.

Yes, using plain YAML maybe requires user-space coverter to some
other format.

> 
> Another option would be using the DTS format, but as a separate file.
> That's not unprecedented as u-boot FIT image is a DTB. Then the kernel
> already has the parser. And you could still have schema now.

Yeah, that is what I consider at first. I discussed it with Frank at
OSSJ, but he suggested to not use DTS, nor touch current parser in kernel.
So I finally convinced not using DTS.

> A new interface will take a lot of bootloader work to make it easy to
> use given the user has to manually load some file in the bootloader
> and know a good address to load it to.

Right, that is what I have to do next if this is accepted. As I shown, I
modified Qemu and Grub. (Since U-Boot is very flexible, it is easy to
load skc file and modify bootargs by manual.)
What I found was, since the bootloaders already supported loading DTB,
it would not be so hard to add loading another file :)  (curiously, the
most complicated part was modifying kernel cmdline)

> Between that and rebuilding the
> kernel with the configuration, I'd pick rebuilding the kernel. Perhaps
> this version will highlight that the original proposal was not so bad.

Maybe for embedded, yes. For admins who use vendor kernel, no.

> Another thought, maybe you could process the configuration file that's
> in a readable/editable format into a flat representation that could
> simply be added to the kernel command line:

(BTW, it is easy to make a flat representation data as you can see
in /proc/sup_cmdline, which is added by [2/19])

> 
> key.word1.setting1=data key.word1.setting2 key.word2=val1,val2
> 
> That would then use an existing interface and probably simplify the
> kernel parsing.

Hmm, if it is just for passing extended arguments, that will be enough
(that was my first version of SKC, here 
https://github.com/mhiramat/skc/tree/5f0429c244d1c9f8f84711bc33e1e6f90df62df8 )

But I found that was not enough flexible for my usage. For expressing
complex ftrace settings (e.g. nesting options, some options related to
other options etc.), I need tree-structured data, something like Devicetree. 

Thank you,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2019-08-27  2:37 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-26  3:15 [RFC PATCH v3 00/19] tracing: skc: Boot-time tracing and Supplemental Kernel Cmdline Masami Hiramatsu
2019-08-26  3:15 ` [RFC PATCH v3 01/19] skc: Add supplemental kernel cmdline support Masami Hiramatsu
2019-08-26 13:27   ` Rob Herring
2019-08-27  2:37     ` Masami Hiramatsu
2019-08-26  3:16 ` [RFC PATCH v3 02/19] skc: Add /proc/sup_cmdline to show SKC key-value list Masami Hiramatsu
2019-08-26  3:16 ` [RFC PATCH v3 03/19] skc: Add a boot setup routine from cmdline Masami Hiramatsu
2019-08-26  3:16 ` [RFC PATCH v3 04/19] Documentation: skc: Add a doc for supplemental kernel cmdline Masami Hiramatsu
2019-08-26  3:16 ` [RFC PATCH v3 05/19] tracing: Apply soft-disabled and filter to tracepoints printk Masami Hiramatsu
2019-08-26  3:16 ` [RFC PATCH v3 06/19] tracing: kprobes: Output kprobe event to printk buffer Masami Hiramatsu
2019-08-26  3:17 ` [RFC PATCH v3 07/19] tracing: Expose EXPORT_SYMBOL_GPL symbol Masami Hiramatsu
2019-08-26  3:17 ` [RFC PATCH v3 08/19] tracing: kprobes: Register to dynevent earlier stage Masami Hiramatsu
2019-08-26  3:17 ` [RFC PATCH v3 09/19] tracing: Accept different type for synthetic event fields Masami Hiramatsu
2019-08-26  3:17 ` [RFC PATCH v3 10/19] tracing: Add NULL trace-array check in print_synth_event() Masami Hiramatsu
2019-08-26  3:17 ` [RFC PATCH v3 11/19] tracing/boot: Add boot-time tracing by supplemental kernel cmdline Masami Hiramatsu
2019-08-26  3:18 ` [RFC PATCH v3 12/19] tracing/boot: Add per-event settings Masami Hiramatsu
2019-08-26  3:18 ` [RFC PATCH v3 13/19] tracing/boot Add kprobe event support Masami Hiramatsu
2019-08-26  3:18 ` [RFC PATCH v3 14/19] tracing/boot: Add synthetic " Masami Hiramatsu
2019-08-26  3:18 ` [RFC PATCH v3 15/19] tracing/boot: Add instance node support Masami Hiramatsu
2019-08-26  3:18 ` [RFC PATCH v3 16/19] tracing/boot: Add cpu_mask option support Masami Hiramatsu
2019-08-26  3:18 ` [RFC PATCH v3 17/19] tracing/boot: Add function tracer filter options Masami Hiramatsu
2019-08-26  3:19 ` [RFC PATCH v3 18/19] tracing/boot: Add function-graph tracer options Masami Hiramatsu
2019-08-26  3:19 ` [RFC PATCH v3 19/19] Documentation: tracing: Add boot-time tracing document Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).