From patchwork Mon Aug 26 03:15:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113879 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 046B91399 for ; Mon, 26 Aug 2019 03:16:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C21A3217F4 for ; Mon, 26 Aug 2019 03:16:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789364; bh=WApMu4IzCmVOqPZbcJjG/bv6yJlRpBTvkgNG2RqhNIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=G4DDnBB/JiUUtEY1GMdU9xaGwYp4Bhd6UrFXwEUWj8RYNZUbojRx4dr0xg7q8D0xa /MCeGnB76iyZ4XNtss1hCYhfDqHtv5otpWAmRfwhmwrgBMldWzWop25DYR7AS5MlKH a2rf9fQ80iOgsD3bsxscWQJvHcyBOIY8bMmvtggo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729431AbfHZDP7 (ORCPT ); Sun, 25 Aug 2019 23:15:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:35162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDP7 (ORCPT ); Sun, 25 Aug 2019 23:15:59 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 407652168B; Mon, 26 Aug 2019 03:15:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789356; bh=WApMu4IzCmVOqPZbcJjG/bv6yJlRpBTvkgNG2RqhNIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mOM4at3W5ZtdeEGw90sUEzAR/KQ8hojSppOTmC/WP6XSw79T12HZl98PRIvIQ70v9 4PYKVXGluZFo3oMo50TPTWKCDQ7z/gMSv9whgejplPtj3UPDx7FaGijf+HoWzw24VR zlDS003Ac3RzM2vERwtZcrCAUwXrIl3JKvwZQ+vA= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 01/19] skc: Add supplemental kernel cmdline support Date: Mon, 26 Aug 2019 12:15:50 +0900 Message-Id: <156678934990.21459.10847677747264952252.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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 +S: Maintained +F: lib/skc.c +F: include/linux/skc.h + SUN3/3X M: Sam Creasey 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 + */ + +#include +#include + +/* 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 + */ + +#define pr_fmt(fmt) "skc: " fmt + +#include +#include +#include +#include +#include +#include +#include + +/* + * 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); + } +} From patchwork Mon Aug 26 03:16:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F1D0D1399 for ; Mon, 26 Aug 2019 03:16:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D08782190F for ; Mon, 26 Aug 2019 03:16:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789373; bh=wXFjl0zCbPJZwn2CEfUDC+aWkXCG/asIDm0k7WxJxXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=XByINzJls9PTggle0I7xV3bJKDYe0fBg5BotZW9fJcL2xaWOBEH902pdPZLGHRlOa da+YF7JEJn3HeWEllUgdU6X7plnpYYOuNV7GG9/iJec5bET2ovBkovcgNI5BHZgB5+ ghekbrXoRrKGPW7JTqm8fOwRLS1rdRmlEoK+Jo6Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729443AbfHZDQJ (ORCPT ); Sun, 25 Aug 2019 23:16:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:35356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726606AbfHZDQJ (ORCPT ); Sun, 25 Aug 2019 23:16:09 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2274A21744; Mon, 26 Aug 2019 03:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789368; bh=wXFjl0zCbPJZwn2CEfUDC+aWkXCG/asIDm0k7WxJxXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CrHbAvOKb8sl5AtIIw8tSiWwAZ9CXJtXpmAfUUfZAtvlh5j1VDF5sDwpCTHlGbPuD RRb0XGrjL6SkBuzlQ4DMUaAP0fNmY7nvKHn/ZZH8nlYIrC4ORmzFQPirseye23qfTk 9pmg9mELNZTxjRK3hq2kBZgpG3jVmZkzbq3bTqfw= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 02/19] skc: Add /proc/sup_cmdline to show SKC key-value list Date: Mon, 26 Aug 2019 12:16:01 +0900 Message-Id: <156678936178.21459.13301820262182543136.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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 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 +#include +#include +#include +#include +#include +#include + +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); From patchwork Mon Aug 26 03:16:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113883 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B468A14DE for ; Mon, 26 Aug 2019 03:16:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 917AB21848 for ; Mon, 26 Aug 2019 03:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789385; bh=D2J2yFbNfuX9EmYpsOlxL/yhHWHvzg/hw54VGoYgnN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=t32rPFN1wSUsPegvBBL0lgJj3/VPKxqAsXQ8Zo812Ja74DeM//Dz2PR37edBcc5KS VAS2ceuCg9C8wsIU8eavbTdv3H9+Muohez2zC/bA9B+j21+iq32T1k/OXAPWe2MCM6 SfKf3MNV8vTf0CT2+gy3H/hRK5p+HR/a6YHWxg+s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729465AbfHZDQV (ORCPT ); Sun, 25 Aug 2019 23:16:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:35576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDQV (ORCPT ); Sun, 25 Aug 2019 23:16:21 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C73AF217F4; Mon, 26 Aug 2019 03:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789380; bh=D2J2yFbNfuX9EmYpsOlxL/yhHWHvzg/hw54VGoYgnN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pl6imcvKxaV3bep6DFK/+9RlMhgAZn6LLoDPEBksO06VfD6S8PaeLdwFkGJzLPob/ KdcZS1riYtxTSx3BR4doPcddoz2Aw5kKTwG9AvseKeJ6wAJwZTNtW10XAxVmrftRAr KWPGkaLR1QL2zgW8MkUeonANezK7Swu703yRVv6g= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 03/19] skc: Add a boot setup routine from cmdline Date: Mon, 26 Aug 2019 12:16:13 +0900 Message-Id: <156678937345.21459.4178076251522180375.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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 #include #include +#include #include #include #include @@ -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 */ From patchwork Mon Aug 26 03:16:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113885 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAF6E1813 for ; Mon, 26 Aug 2019 03:16:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7EC04217F4 for ; Mon, 26 Aug 2019 03:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789397; bh=uWC/H1l7v6d+/MwTfG766K9JXtMKh6YTaqA+3BYw+7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=2XPLVzVP+XOuGAAbvCwWpPiuyAXU/IcrzZIPyDLtk/HVi4Hf9Gvqlr4/E3uqzd5t9 1+S7EJHqVzxHsPmXK7C5Yn23wF84cadZebPNFXYLusCgqa0/gnMeSnkhesIadETA42 jqcKcaXvvP/zDi6cwuUNlY4fLLWUAk9h9c+64fYY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729485AbfHZDQd (ORCPT ); Sun, 25 Aug 2019 23:16:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:35766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDQd (ORCPT ); Sun, 25 Aug 2019 23:16:33 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C2A1F2168B; Mon, 26 Aug 2019 03:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789391; bh=uWC/H1l7v6d+/MwTfG766K9JXtMKh6YTaqA+3BYw+7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LY8BlqA7MeEPLijQUsaoCM5739rOMHUHX8tuJTSV1xWTYqHVPwt4LXiU9F5SPf1z7 A/8GRdiGRwkfvOFaUkmuc3x7JRamQ6mk5CoblNiWYzcwusDUpaq9ZKAxP3PNG+gTHI IGDBnjQuz+aYkrql7nqEiNeNYkug3LQwmxVgKuRA= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 04/19] Documentation: skc: Add a doc for supplemental kernel cmdline Date: Mon, 26 Aug 2019 12:16:25 +0900 Message-Id: <156678938543.21459.628373407524491520.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a documentation for supplemental kernel cmdline under admin-guide, since it is including the syntax of SKC file. Signed-off-by: Masami Hiramatsu --- 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 + +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 From patchwork Mon Aug 26 03:16:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113887 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 319D3184E for ; Mon, 26 Aug 2019 03:16:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10218217F4 for ; Mon, 26 Aug 2019 03:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789409; bh=2KXefGGEbWZIuaONJPAxtXMECnSf0wCC1mBwVxRYIfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GJGJwdthQPNameDZIz00sxmGUBLYBSi3C7QnJSRyTvnouqSdtb+lywInxCIfooXxZ UHy5hkhaPymkhv0humCy74XrwggnjpGUkon54Ie5YWNb5V6Yb1+22rw07UXQNyUKTZ iXziUd2yRFq/wUeRMpjaanA7LwlT9Xk9Ss6D39OY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729498AbfHZDQo (ORCPT ); Sun, 25 Aug 2019 23:16:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:35902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDQo (ORCPT ); Sun, 25 Aug 2019 23:16:44 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F04D12173E; Mon, 26 Aug 2019 03:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789403; bh=2KXefGGEbWZIuaONJPAxtXMECnSf0wCC1mBwVxRYIfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PRWAMOsjGhV8t1Vxn5Mee8c4QWL5HxiR0OHr9LKGSOI4l7+ghu0D2MWxls1fvKzXX XPVmVvDpNjhts+zZTWh8urCuA4tjRghxCI9qj5YwwkIFUIoM5vKVDOaoZmNXG/B8fq prdZhS+s/WXzTJjNta/ELZ6g40L0wmk3CQoGmbjA= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 05/19] tracing: Apply soft-disabled and filter to tracepoints printk Date: Mon, 26 Aug 2019 12:16:37 +0900 Message-Id: <156678939711.21459.14981591663181807734.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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); From patchwork Mon Aug 26 03:16:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113889 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C5441813 for ; Mon, 26 Aug 2019 03:17:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1023A2190F for ; Mon, 26 Aug 2019 03:17:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789420; bh=i1sp1BbzKL5yrHW27AdY2EkJgx+nFs+u0ymGWoaZnoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=S18hmRHmzykSvUHC+osSbGU7GRe28+TVTMsk1QgTj4XyaUJOYruPQgmfOYG6LHSsg pCiVRatS+0hlzgjCn7AfFB1hAzeItrWAhFFjyNVdae1fhKpTw5ZVKsdp6AHRTjEnN5 jpeGEwxW9+MPHmT8Eq88wE00XsiA53JAKPE0z7vQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729516AbfHZDQ4 (ORCPT ); Sun, 25 Aug 2019 23:16:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:36076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDQz (ORCPT ); Sun, 25 Aug 2019 23:16:55 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A010621744; Mon, 26 Aug 2019 03:16:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789415; bh=i1sp1BbzKL5yrHW27AdY2EkJgx+nFs+u0ymGWoaZnoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XfxJLv8Ehend5oNP3Te5VYWfudAIv9P86IvvQCbVWXJUuoVse9WUQjHqCSQEE6xzN R8SL19VsIfHDWKWuWHAwlX/S57Lkw1P14H+xtKfw46+3zg9ULb8XQAfiTvazb2/Y3w 8mysXYFo6ObK/LoLbbiAAmI/7F3tfjWxqsWLP6Oo= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 06/19] tracing: kprobes: Output kprobe event to printk buffer Date: Mon, 26 Aug 2019 12:16:49 +0900 Message-Id: <156678940919.21459.18266384720385228733.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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 From patchwork Mon Aug 26 03:17:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113891 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E0A41813 for ; Mon, 26 Aug 2019 03:17:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B68E2190F for ; Mon, 26 Aug 2019 03:17:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789431; bh=8RzbIez3/gV7djsGVGljsi9n/uUzLTL1tlAOyhS3Cmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ly8g3lzGFz6LRN3hMZz6wGz61XRjSLnuCvpc0+uZJTy+zEd6k9xuPPXikp3vBEi59 2QHtinfSWziUupmwGoF6oAHqaADcXO/o0mWTMy+aU4JXiwUud1qRhLWINUG2dqFv+X KWFuKHmzSnJlE9TSbQazKelcol1I8HoGJzj5/ncc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729379AbfHZDRH (ORCPT ); Sun, 25 Aug 2019 23:17:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:36180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDRH (ORCPT ); Sun, 25 Aug 2019 23:17:07 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E07DC2168B; Mon, 26 Aug 2019 03:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789427; bh=8RzbIez3/gV7djsGVGljsi9n/uUzLTL1tlAOyhS3Cmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b4wmwFNgY+/8VTmajXrij1vDg3ji9OW113jOcdKvDeoFTZK0H8LZjUbYRlxUmuUgS QWCCDwqoiQKrCS8MMJp2u6JBalwG0usrcfctdpz8RmPKtNYHfYiCstVAgTU9hVnuWe 6L9+yk59t1szGt8FJaaqASqv1AbPf6RxZpQSTh2c= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 07/19] tracing: Expose EXPORT_SYMBOL_GPL symbol Date: Mon, 26 Aug 2019 12:17:00 +0900 Message-Id: <156678942047.21459.8827037624340615081.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Since ftrace_set_clr_event is already exported by EXPORT_SYMBOL_GPL, it should not be static. Signed-off-by: Masami Hiramatsu --- 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; From patchwork Mon Aug 26 03:17:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113893 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E79CF1800 for ; Mon, 26 Aug 2019 03:17:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C544821848 for ; Mon, 26 Aug 2019 03:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789443; bh=pZzkhwcBJfs0QtEtXuJLrkB89zQzll96XuQ1G/Is+0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gCMWNSnT7LE5rJzQMgBsT3Bnq84I3kzcLdJU/dezd6bOGz1xP/PsfAIDr6ExZ7hXr 4AkpPfxF29mzYLhxVJLhXuGfH8SZef7D1M8rqALP4EluK4dnybCE+tia2Ga6apHPrE GNoyZHqV6IyEr93n6SGx4NdrQk1aO2gp4XDttRJ4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729376AbfHZDRU (ORCPT ); Sun, 25 Aug 2019 23:17:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:36320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDRT (ORCPT ); Sun, 25 Aug 2019 23:17:19 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C36342173E; Mon, 26 Aug 2019 03:17:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789438; bh=pZzkhwcBJfs0QtEtXuJLrkB89zQzll96XuQ1G/Is+0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P1q6ynV4eXb20bwoW+OZ+DkHDdintCvMuzhPd8biapLRfC/+ps+VIQwFXQK6TrjZD dKlWQppXhMlmJMSGpi7bgbKhwKC8sEVFdBJDBhk4ceZ7QchgXh3nEITBxhtqnONxm7 vcOG40PwdgVdbpTMkyzhU5rGKEIKzbiw4BrhBFR4= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 08/19] tracing: kprobes: Register to dynevent earlier stage Date: Mon, 26 Aug 2019 12:17:12 +0900 Message-Id: <156678943243.21459.6275766489688267737.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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; From patchwork Mon Aug 26 03:17:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113895 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 706C91800 for ; Mon, 26 Aug 2019 03:17:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4DFBF21744 for ; Mon, 26 Aug 2019 03:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789455; bh=FEs3TMM0ZYwBf3dusmpCVE/U5ogVTBo5jlcOMzlVOu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=uIuFM2NH8z5EhghChBzrmLMLhhsAQMVkCpEZbOEvNRB9sb0ne6VmwGfII7/0QjqT0 RBRtouwi4m+AH7LrI6yLLbhQYsux4qbtTO7sIdvcrUM7bSPb9NL5MBEj3es5inA2Lo GD54Dygex7P8ixXM/8kcuN1P3NnTqZNnecUEVomE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729543AbfHZDRc (ORCPT ); Sun, 25 Aug 2019 23:17:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:36446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDRb (ORCPT ); Sun, 25 Aug 2019 23:17:31 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D77822070B; Mon, 26 Aug 2019 03:17:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789451; bh=FEs3TMM0ZYwBf3dusmpCVE/U5ogVTBo5jlcOMzlVOu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P41uJw4iE7hZ+m44x3YjIMRFxcJ++9sqqHDpeKMVvJWSF9iiZmumFg6D183qYHE8Y 7Uu/k4e4N6U76zbJ0wzPx74ARm8hLSjGLsBGAq0DxzkLcFxHwb6bg+4w69oWLUCw5f 6eZTcvH6z9Zoxsr6lxc15DnXLOHpMrWGzWHLQhZE= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 09/19] tracing: Accept different type for synthetic event fields Date: Mon, 26 Aug 2019 12:17:24 +0900 Message-Id: <156678944420.21459.11193086089601225256.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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; } From patchwork Mon Aug 26 03:17:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113897 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F7C21398 for ; Mon, 26 Aug 2019 03:17:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D4402173E for ; Mon, 26 Aug 2019 03:17:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789467; bh=1MgpH1r23u2tqpsRDhiOww76XSTOfo2+LJaAlGqRg44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZnGPkl1iP5OlhlwkxuYLS8bKA2sEEvTLk2vBEsupw6UbNba8fk0YzSM8uTvNp9UvH pXmpQgJp1Xj1Dt9dFLMyrriNmKnDmwGwF4LdqKqQWGnrReJeSCnHSta9s5sA414So5 gkk7+d6NbzdUXus55ICrJ0IToNOHv3xYrzVkrbA0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729557AbfHZDRo (ORCPT ); Sun, 25 Aug 2019 23:17:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:36574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729292AbfHZDRn (ORCPT ); Sun, 25 Aug 2019 23:17:43 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D19562168B; Mon, 26 Aug 2019 03:17:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789462; bh=1MgpH1r23u2tqpsRDhiOww76XSTOfo2+LJaAlGqRg44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zaXDSbi+ox96xhO+enb6+FyW0JgXbUv/q9TK5OX23mUY4QpkElBk/cXC27VH7vYVf RzJL/bmO8P70DmL5emCXieC+1JmaG7s/2SrvORkwT5FrYa8UuDIakmLHJt/oJGec45 99i9dgUyMrLHFoagWS0qJq6+rMHbyrDJOCwK0cdk= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 10/19] tracing: Add NULL trace-array check in print_synth_event() Date: Mon, 26 Aug 2019 12:17:36 +0900 Message-Id: <156678945659.21459.15789978012125587066.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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); From patchwork Mon Aug 26 03:17:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113899 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B6561399 for ; Mon, 26 Aug 2019 03:18:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F21821744 for ; Mon, 26 Aug 2019 03:18:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789482; bh=G/qyW272NUfoEDDIFCzOPjWsNmGzvP4vyJnf2Deq0nc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ffBuPsRSLKwO6leun48v9yWekiNyYbbURBGZ2i8KS9k25w14JpJe68oszpNZvXddW jk2GptLnbNe3F/egqKeabdbRzuqHxm2CtxR8R7y+1fWCUBWm2KdOKce93IKxCIgHDI b7NMus5U6o9o4UrhjO7AAzMpId1hOrdhoB0ErsYo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729407AbfHZDR5 (ORCPT ); Sun, 25 Aug 2019 23:17:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:36690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726215AbfHZDR4 (ORCPT ); Sun, 25 Aug 2019 23:17:56 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E6C842173E; Mon, 26 Aug 2019 03:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789474; bh=G/qyW272NUfoEDDIFCzOPjWsNmGzvP4vyJnf2Deq0nc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ffQlKwF42ln7Cshrpieg6v9bZuPeW3eFetJYLHFyRvjwmZQrGP5GVJSBpZSr3Iqpf S+9bpaT+F2gITjF2waiMVjgLo4WQBj1axwqn6D0qj9W1b20HtHEKLJZF/c8b+w6R01 5NQN6A3gRbQV1fLQBjHN5mKF78L3OEJyqmhX47fs= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 11/19] tracing/boot: Add boot-time tracing by supplemental kernel cmdline Date: Mon, 26 Aug 2019 12:17:48 +0900 Message-Id: <156678946837.21459.17052750937661704310.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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 +#include +#include + +#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); From patchwork Mon Aug 26 03:18:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113901 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF0C91399 for ; Mon, 26 Aug 2019 03:18:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8134D2168B for ; Mon, 26 Aug 2019 03:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789492; bh=ICuWmK4ZyGjBiw83BcImptVaBmrjkJy1XTmFQ1gPbnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=oqO6ryeOlfGPB0hfTZtRqzw6KjE63q1/qhMUtDQNAImWKU67soTWYavWZAtOcgSVE WDgMPwZnICJPw8trh59kKOhfz2mpaULLEFfS4eMN+HxWL33Ud1xYDTOzdGgawb2fwK l79bYyVRsbI4fP1lt186vbXpYOTBtdh0VH5rnfcU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729225AbfHZDSI (ORCPT ); Sun, 25 Aug 2019 23:18:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:36806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDSI (ORCPT ); Sun, 25 Aug 2019 23:18:08 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AAD972070B; Mon, 26 Aug 2019 03:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789486; bh=ICuWmK4ZyGjBiw83BcImptVaBmrjkJy1XTmFQ1gPbnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q9OBvZnNPTKKgua28v62Sv95I3gKvJxXx8bV9qybIst5UpQ3NvH/C+HUqg0yMP5sp 6+bXKi9Irl/VL3WlIfdqj5CAMPnjE+sfwqVetOyBw9lga98pzmI4cZjx5rb2I/vqn5 YQul7ggrPcCg4D7ICnfy/NYbz+E7y++duWZeTDWA= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 12/19] tracing/boot: Add per-event settings Date: Mon, 26 Aug 2019 12:18:00 +0900 Message-Id: <156678948034.21459.12734081118923661873.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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; From patchwork Mon Aug 26 03:18:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113903 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16A4A1398 for ; Mon, 26 Aug 2019 03:18:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E7A3C2070B for ; Mon, 26 Aug 2019 03:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789504; bh=dx782LyP2EgLfV+vRh1Ur2mO8lwlNqwkIa/BZqJBJxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=uPcHLm934WTyJgGibVUyoAbA6zm8rxmd2J975sGSBFcxga8zcGu/CFNF5CIrGrylv cu42tBIyj7BAgGpWV0m/+puoEfFH0MK+Mdu9Ht+LCzr1155AY/Pw2+RIDWZwrYlHwe XEB1cl4N2uGHJ5g38rsb3FTEGj+XD8cW9NiEpMms= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729438AbfHZDST (ORCPT ); Sun, 25 Aug 2019 23:18:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:36924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDST (ORCPT ); Sun, 25 Aug 2019 23:18:19 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C504B20578; Mon, 26 Aug 2019 03:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789498; bh=dx782LyP2EgLfV+vRh1Ur2mO8lwlNqwkIa/BZqJBJxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXcpyIqNs+T7m7w0pBY+ECIHhxlP6ylvuzP4iG4jpOUQVJyIvN3uQpkz3gl7+3ibD 3W/EoJYHOpKcpMcL8fryRKU8Wbg18qgGsXzJyJOQXevZdI0nMgaqrAke8zRe8xkanA e0MSCBLjfx77GdTD0i2oM2whk3FjlZpoFW1U5Kas= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 13/19] tracing/boot Add kprobe event support Date: Mon, 26 Aug 2019 12:18:12 +0900 Message-Id: <156678949243.21459.7280617203512175739.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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); From patchwork Mon Aug 26 03:18:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113905 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3AAD1399 for ; Mon, 26 Aug 2019 03:18:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A024F20578 for ; Mon, 26 Aug 2019 03:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789515; bh=P7oPsfV6A0jtk+MZWB9QHUi0b3uNU8xu4OT8knJjVa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Rl2zFYHm3oRIw+myzEvwCMeUrFgfHDGOMabLwsKB5wVEISjomDamLQRm2n603cPM7 Et3m4/INwoqPU+PO5xm4yzNKwM+0QuSnwH4hvD7hOl6ukzskd3O8taO6BshALogKVc VHOJ2w5CHyPHgjULnwZZRdyppHYDdJODALpKCDo0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729468AbfHZDSb (ORCPT ); Sun, 25 Aug 2019 23:18:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:37046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfHZDSb (ORCPT ); Sun, 25 Aug 2019 23:18:31 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C25A2070B; Mon, 26 Aug 2019 03:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789510; bh=P7oPsfV6A0jtk+MZWB9QHUi0b3uNU8xu4OT8knJjVa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1K7Herj2qVxuRZLdPAV/Cv9TvLbxJbtCpuG0CWOHV0lL3dB+sSx4aZJtbypAx7O9g VOTCVwzOmNcB1vLQP/IvyW1uOZIMqZCre7rRHOzGNMa0xcWmf0fOY/VBUAk4BbAqX1 4NZcjANnRUM+4zIKKwzJbDo6p9wpVEISMhcFmhqM= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 14/19] tracing/boot: Add synthetic event support Date: Mon, 26 Aug 2019 12:18:24 +0900 Message-Id: <156678950390.21459.4719180337950500537.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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]; From patchwork Mon Aug 26 03:18:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F4B31399 for ; Mon, 26 Aug 2019 03:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5203021744 for ; Mon, 26 Aug 2019 03:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789527; bh=4fPsr18xxsuPXL9Lp95SiJ4t2t8JicrM5cKgfBo8bzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=FeYeckMQcsL4u9qLv5j7tpL6q91GmyNSE+MIzBdPlCN98pSr0+X8Ym4Ha26H/mVf+ 3rEdHY7NTtcVbT12YqgxfAzxRKwOuVyZHToSfq2tWrFrxdisED6IE4ZlN3rnJMPCkj i9WqMaZMKRJnbsaRazIey71X602xPUi700RCqyLA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729503AbfHZDSn (ORCPT ); Sun, 25 Aug 2019 23:18:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:37172 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726215AbfHZDSn (ORCPT ); Sun, 25 Aug 2019 23:18:43 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CEEB42173E; Mon, 26 Aug 2019 03:18:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789521; bh=4fPsr18xxsuPXL9Lp95SiJ4t2t8JicrM5cKgfBo8bzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aEB3nHWwf/t9MBjXiLCsEp6Oma7ti9w0hA6d1bWHYcUicvSfyl4HI+PknJbkMczOs Z2agX/TnNrmW4g1BzAfKPUVdedqPspbdIR02ez1lrDXiwnNx5DC3UmLsWnZRaWh1sL Do1KKclTJO2U2ZvWyI65VTCYCs7Vj+tCaYAqsjmc= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 15/19] tracing/boot: Add instance node support Date: Mon, 26 Aug 2019 12:18:35 +0900 Message-Id: <156678951557.21459.13013581523042678676.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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; } From patchwork Mon Aug 26 03:18:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2104C1398 for ; Mon, 26 Aug 2019 03:18:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F27FD21744 for ; Mon, 26 Aug 2019 03:18:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789537; bh=KZucuPNaFyRUaxEnWFtoud2RPq4vc5t+1we+rVn+daI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Mq6J2eJG/tYCKHY3xbWvSfKsALgJI7yhkkyu2iYlJqvIN/gWWtMCWNk0HGuMbBigo mg4dCzAtL2SWj16XCc624OCVGXkM587/TM5r2+JS9PEKh4ndB878a21nRSGd/KOJ+U G+uOpOC5Cb3GTIUbFgAmH6mpCKMLZipdx4OJ+3lA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729635AbfHZDS4 (ORCPT ); Sun, 25 Aug 2019 23:18:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:37316 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729625AbfHZDSz (ORCPT ); Sun, 25 Aug 2019 23:18:55 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 07EED2070B; Mon, 26 Aug 2019 03:18:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789534; bh=KZucuPNaFyRUaxEnWFtoud2RPq4vc5t+1we+rVn+daI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Czv3i715OAeOfl43xR9vjk4FosmSDAjZRHMhZqMgz/8T9OGLV2/UaD2diJd5E6RxH MIqCAbAiKyuBk8zAZiAEBkoabWCaEElJfN2lhT8s4te/TuviURsdnXs/kn2l+U7fDs fbJoW3/GdxbVmwQDb4LfPVb0gEb3ocJDJ8IPOQMo= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 16/19] tracing/boot: Add cpu_mask option support Date: Mon, 26 Aug 2019 12:18:47 +0900 Message-Id: <156678952725.21459.13151153295760559536.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 /tracing_cpumask can accepts. Signed-off-by: Masami Hiramatsu --- 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 From patchwork Mon Aug 26 03:18:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113919 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA4961398 for ; Mon, 26 Aug 2019 03:19:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 87DDD2173E for ; Mon, 26 Aug 2019 03:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789550; bh=w3J2cJs2crg8gGwITUaTLh45R8avn+V3leFR9667rmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=JSLdAM/yVJFs/rEEZogjNRdzx1A074uuPXTAG8QdkNNOUk7DqY1Qo7tyhku86Y/a8 g6wjaJ1Mcr8+6iSKMCXgvtZ4LrGFAqgTimVUNm0BX1JeZMQN28ZkUmIxyn3u8XivS5 eG4nghNHmJsiAXFvgFwOHzPqNoJzcV2uLgThCY0I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729698AbfHZDTJ (ORCPT ); Sun, 25 Aug 2019 23:19:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:37548 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729518AbfHZDTG (ORCPT ); Sun, 25 Aug 2019 23:19:06 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AC48C2168B; Mon, 26 Aug 2019 03:19:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789546; bh=w3J2cJs2crg8gGwITUaTLh45R8avn+V3leFR9667rmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GNnd1gLuTIZqShGN9uAV4YnJ3H+rZCzocE2nuMiFOKrJwxxQ6+v2qHmYsFOIaIsww fRmxeKW8QimVp1MS8N/nLqSCiS8J3kjlcA4Q85UJK1MDH28zkCdveUv19BZdS6VHqi Ao9hsnDFsd1dyEiRMZ48inf+a8z2tGiL0iVXBOBw= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 17/19] tracing/boot: Add function tracer filter options Date: Mon, 26 Aug 2019 12:18:59 +0900 Message-Id: <156678953942.21459.2531310402301118028.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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) From patchwork Mon Aug 26 03:19:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113925 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03C6D1398 for ; Mon, 26 Aug 2019 03:19:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC02021744 for ; Mon, 26 Aug 2019 03:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789561; bh=2hqvqjb4JRbv59jAzcU+dKYGR+NXhgzGBeJ3dWiVhdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NNws7mLVb3oXnKjIn+m1SjvpoGHtldRFL8+wzxlw3eNSPNW6DlkpBGHWxjQ1KluMf 43MNPauB+N644L568RFZ41ZmGpwM7hSw8tefUtBNX05SiA+2YTgxgmuAyAo0G2jf/E RW1Y3A3vAUAaWGebP7LX1AOHDx8lHgvkdhGim9eE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729716AbfHZDTU (ORCPT ); Sun, 25 Aug 2019 23:19:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:37774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729437AbfHZDTT (ORCPT ); Sun, 25 Aug 2019 23:19:19 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D93F62070B; Mon, 26 Aug 2019 03:19:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789558; bh=2hqvqjb4JRbv59jAzcU+dKYGR+NXhgzGBeJ3dWiVhdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sv3Fvm/tvtHGU71iCv0m7liX43HCg8VeHCygpsU35XNGDMcGKWwzDKrdw0yE++5e9 4zMTqUPTQEVCGxT8rerpMrq4uDWrQflAwvew7Hfec2BvYNDOU8449nhhOMEIJMLIof lpS7xvOCoO9y4pwtelBgIa7XhQD2W53kVMkXZ8jE= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 18/19] tracing/boot: Add function-graph tracer options Date: Mon, 26 Aug 2019 12:19:11 +0900 Message-Id: <156678955140.21459.9556721429972023089.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- 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 From patchwork Mon Aug 26 03:19:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11113927 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21F941399 for ; Mon, 26 Aug 2019 03:19:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E8F052173E for ; Mon, 26 Aug 2019 03:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789575; bh=uHqfn9peEd3ORIM3wsSJk2LrEw61/eQUGWlnaFOeCsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=G4ReR49OhqqIlJZf2QeoMCPQRZTVsCjLEtRp069AIqbimCYfR7KZfbOAxj5D3mofu oIRWZ8PVE4AK0mBi0UMdjeV4xyhKcKNfsbwJ3bosYxXSNodaIYzwmZUTjAXFwXzqVr 3/g2dua1UTKUWAdQPwRdM54asIpwugCebgMTseO4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729563AbfHZDTb (ORCPT ); Sun, 25 Aug 2019 23:19:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:37918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729378AbfHZDTa (ORCPT ); Sun, 25 Aug 2019 23:19:30 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ED8022168B; Mon, 26 Aug 2019 03:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566789569; bh=uHqfn9peEd3ORIM3wsSJk2LrEw61/eQUGWlnaFOeCsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OwKoveKLdrVY+N9Mn6VFT/RfjDs8u4C7XtkqDlc9V8drC8GIXQz9Dd3PJjCJKkSFV QDHc4BUijUjNWntQI5+6xAqZqxe3utIc0hcV5vz4ogz8CsD9weJqDPTL2g9+KMh8l+ j6sqbdG6g1+i06wePcS2bqqwWZh0xRfuWtJargtg= From: Masami Hiramatsu 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@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 19/19] Documentation: tracing: Add boot-time tracing document Date: Mon, 26 Aug 2019 12:19:23 +0900 Message-Id: <156678956359.21459.7183859111623533121.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156678933823.21459.4100380582025186209.stgit@devnote2> References: <156678933823.21459.4100380582025186209.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a documentation about boot-time tracing options for SKC file. Signed-off-by: Masami Hiramatsu --- 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 + +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.