tracing: Last minute fixes for this merge window
Subsystems (8)
Steven Rostedt
maintainercover tracing: Last minute fixes for this merge window
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: c58b46cba71750c6e969625abb1cf3ddabb15e06
Chengming Zhou (2):
ftrace: Setup correct FTRACE_FL_REGS flags for module
ftrace: Do not let direct or IPMODIFY ftrace_ops be added to module and set trampolines
Josef Bacik (1):
ftrace: Fix ftrace_trace_task return value
Kevin Hao (2):
tracing/hwlat: Drop the duplicate assignment in start_kthread() tracing/hwlat: Honor the tracing_cpumask
Masami Hiramatsu (4):
kprobes: Remove show_registers() function prototype lib/bootconfig: Add override operator support tools/bootconfig: Add testcases for value override operator
Documentation: bootconfig: Add bootconfig override operator
Muchun Song (1):
kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler
Nick Desaulniers (2):
tracepoint: Mark __tracepoint_string's __used
tracepoint: Use __used attribute definitions from compiler_attributes.h
Peng Fan (1):
tracing/uprobe: Remove dead code in trace_uprobe_register()
Vincent Whitchurch (1):
tracing: Remove outdated comment in stack handling
Wei Yang (2):
tracing: Simplify defining of the next event id
tracing: Save one trace_event->type by using __TRACE_LAST_TYPE
Zhaoyang Huang (1):
trace : Have tracing buffer info use kvzalloc instead of kzalloc
----
Documentation/admin-guide/bootconfig.rst | 11 ++++++++++ include/linux/kprobes.h | 1 - include/linux/tracepoint.h | 11 +++++----- kernel/kprobes.c | 7 ++++++ kernel/trace/ftrace.c | 22 +++++++++++++------ kernel/trace/trace.c | 10 ++------- kernel/trace/trace.h | 7 +++++- kernel/trace/trace_hwlat.c | 6 ++--- kernel/trace/trace_output.c | 14 ++++++------ kernel/trace/trace_uprobe.c | 1 - lib/bootconfig.c | 33 +++++++++++++++++++--------- tools/bootconfig/samples/bad-override.bconf | 3 +++ tools/bootconfig/samples/bad-override2.bconf | 3 +++ tools/bootconfig/samples/good-override.bconf | 6 +++++ tools/bootconfig/test-bootconfig.sh | 13 +++++++++++ 15 files changed, 104 insertions(+), 44 deletions(-) create mode 100644 tools/bootconfig/samples/bad-override.bconf create mode 100644 tools/bootconfig/samples/bad-override2.bconf create mode 100644 tools/bootconfig/samples/good-override.bconf
Steven Rostedt
maintainerPATCH 1/17 tracing: Simplify defining of the next event id
From: Wei Yang <[email protected]>
The value to be used and compared in trace_search_list() is "last + 1". Let's just define next to be "last + 1" instead of doing the addition each time.
--- kernel/trace/trace_output.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
kernel/trace/trace_output.c +6 -6
@@ -675,11 +675,11 @@ static LIST_HEAD(ftrace_event_list);static int trace_search_list (struct list_head **list) {struct trace_event *e; -int last = __TRACE_LAST_TYPE; +int next = __TRACE_LAST_TYPE +1 ;if (list_empty (&ftrace_event_list)) { *list = &ftrace_event_list; -return last +1 ; +return next; }/*
@@ -687,17 +687,17 @@ static int trace_search_list(struct list_head **list)* lets see if somebody freed one. */ list_for_each_entry (e, &ftrace_event_list, list) { -if (e->type != last +1 ) +if (e->type != next)break ; - last++; + next++; }/* Did we used up all 65 thousand events??? */ -if ((last +1 ) >TRACE_EVENT_TYPE_MAX ) +if (next >TRACE_EVENT_TYPE_MAX )return 0 ; *list = &e->list; -return last +1 ; +return next; }void trace_event_read_lock (void )
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 2/17 tracing: Save one trace_event->type by using __TRACE_LAST_TYPE
In reply to Steven RostedtFrom: Wei Yang <[email protected]>
Static defined trace_event->type stops at (__TRACE_LAST_TYPE - 1) and dynamic trace_event->type starts from (__TRACE_LAST_TYPE + 1).
To save one trace_event->type index, let's use __TRACE_LAST_TYPE.
--- kernel/trace/trace_output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +2 -2
@@ -20,7 +20,7 @@ DECLARE_RWSEM(trace_event_sem);static struct hlist_head event_hash[EVENT_HASHSIZE ]__read_mostly ; -static int next_event_type = __TRACE_LAST_TYPE +1 ; +static int next_event_type = __TRACE_LAST_TYPE;enum print_line_t trace_print_bputs_msg_only (struct trace_iterator *iter) {
@@ -675,7 +675,7 @@ static LIST_HEAD(ftrace_event_list);static int trace_search_list (struct list_head **list) {struct trace_event *e; -int next = __TRACE_LAST_TYPE +1 ; +int next = __TRACE_LAST_TYPE;if (list_empty (&ftrace_event_list)) { *list = &ftrace_event_list;
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 3/17 tracing/hwlat: Drop the duplicate assignment in start_kthread()
In reply to Steven RostedtFrom: Kevin Hao <[email protected]>
We have set 'current_mask' to '&save_cpumask' in its declaration, so there is no need to assign again.
--- kernel/trace/trace_hwlat.c | 1 - 1 file changed, 1 deletion(-)
kernel/trace/trace_hwlat.c +0 -1
@@ -371,7 +371,6 @@ static int start_kthread(struct trace_array *tr)return 0 ;/* Just pick the first CPU on first iteration */ - current_mask = &save_cpumask;get_online_cpus ();cpumask_and (current_mask, cpu_online_mask, tracing_buffer_mask);put_online_cpus ();
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 4/17 tracing/hwlat: Honor the tracing_cpumask
In reply to Steven RostedtFrom: Kevin Hao <[email protected]>
In calculation of the cpu mask for the hwlat kernel thread, the wrong cpu mask is used instead of the tracing_cpumask, this causes the tracing/tracing_cpumask useless for hwlat tracer. Fixes it.
--- kernel/trace/trace_hwlat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/trace/trace_hwlat.c +3 -2
@@ -283,6 +283,7 @@ static bool disable_migrate;static void move_to_next_cpu (void ) {struct cpumask *current_mask = &save_cpumask; +struct trace_array *tr = hwlat_trace;int next_cpu;if (disable_migrate)
@@ -296,7 +297,7 @@ static void move_to_next_cpu(void) goto disable;get_online_cpus (); -cpumask_and (current_mask, cpu_online_mask, tracing_buffer_mask); +cpumask_and (current_mask, cpu_online_mask, tr->tracing_cpumask); next_cpu =cpumask_next (smp_processor_id (), current_mask);put_online_cpus ();
@@ -372,7 +373,7 @@ static int start_kthread(struct trace_array *tr)/* Just pick the first CPU on first iteration */ get_online_cpus (); -cpumask_and (current_mask, cpu_online_mask, tracing_buffer_mask); +cpumask_and (current_mask, cpu_online_mask, tr->tracing_cpumask);put_online_cpus (); next_cpu =cpumask_first (current_mask);
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 5/17 ftrace: Setup correct FTRACE_FL_REGS flags for module
In reply to Steven RostedtFrom: Chengming Zhou <[email protected]>
When module loaded and enabled, we will use __ftrace_replace_code for module if any ftrace_ops referenced it found. But we will get wrong ftrace_addr for module rec in ftrace_get_addr_new, because rec->flags has not been setup correctly. It can cause the callback function of a ftrace_ops has FTRACE_OPS_FL_SAVE_REGS to be called with pt_regs set to NULL.
So setup correct FTRACE_FL_REGS flags for rec when we call referenced_filters to find ftrace_ops references it.
--- kernel/trace/ftrace.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
kernel/trace/ftrace.c +7 -4
@@ -6198,8 +6198,11 @@ static int referenced_filters(struct dyn_ftrace *rec)int cnt =0 ;for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) { -if (ops_references_rec (ops, rec)) - cnt++; +if (ops_references_rec (ops, rec)) { + cnt++; +if (ops->flags &FTRACE_OPS_FL_SAVE_REGS ) + rec->flags |=FTRACE_FL_REGS ; + } }return cnt;
@@ -6378,8 +6381,8 @@ void ftrace_module_enable(struct module *mod)if (ftrace_start_up) cnt +=referenced_filters (rec); -/* This clears FTRACE_FL_DISABLED */ - rec->flags = cnt; + rec->flags &= ~FTRACE_FL_DISABLED ; + rec->flags += cnt;if (ftrace_start_up && cnt) {int failed =__ftrace_replace_code (rec,1 );
Signature · 1 line
2.26.2
Sasha Levin
maintainerRe: [for-linus][PATCH 05/17] ftrace: Setup correct FTRACE_FL_REGS flags for module
Hi
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag
fixing commit: 8c4f3c3fa968 ("ftrace: Check module functions being traced on reload").
The bot has tested the following trees: v5.8, v5.7.13, v5.4.56, v4.19.137, v4.14.192, v4.9.232, v4.4.232.
v5.8: Build OK!
v5.7.13: Build OK!
v5.4.56: Build OK!
v4.19.137: Build OK!
v4.14.192: Build OK!
v4.9.232: Build OK!
v4.4.232: Failed to apply! Possible dependencies:
02a392a0439f ("ftrace: Add new type to distinguish what kind of ftrace_bug()") 97e9b4fca52b ("ftrace: Clean up ftrace_module_init() code") b6b71f66a16a ("ftrace: Join functions ftrace_module_init() and ftrace_init_module()") b7ffffbb46f2 ("ftrace: Add infrastructure for delayed enabling of module functions")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
Signature · 2 lines
Thanks Sasha
Steven Rostedt
maintainerPATCH 6/17 ftrace: Do not let direct or IPMODIFY ftrace_ops be added to module and set trampolines
In reply to Steven RostedtFrom: Chengming Zhou <[email protected]>
When inserting a module, we find all ftrace_ops referencing it on the ftrace_ops_list. But FTRACE_OPS_FL_DIRECT and FTRACE_OPS_FL_IPMODIFY flags are special, and should not be set automatically. So warn and skip ftrace_ops that have these two flags set and adding new code. Also check if only one ftrace_ops references the module, in which case we can use a trampoline as an optimization.
--- kernel/trace/ftrace.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/trace/ftrace.c +8 -0
@@ -6199,9 +6199,17 @@ static int referenced_filters(struct dyn_ftrace *rec)for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) {if (ops_references_rec (ops, rec)) { +if (WARN_ON_ONCE (ops->flags &FTRACE_OPS_FL_DIRECT )) +continue ; +if (WARN_ON_ONCE (ops->flags &FTRACE_OPS_FL_IPMODIFY )) +continue ; cnt++;if (ops->flags &FTRACE_OPS_FL_SAVE_REGS ) rec->flags |=FTRACE_FL_REGS ; +if (cnt ==1 && ops->trampoline) + rec->flags |=FTRACE_FL_TRAMP ; +else + rec->flags &= ~FTRACE_FL_TRAMP ; } }
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 7/17 tracing: Remove outdated comment in stack handling
In reply to Steven RostedtFrom: Vincent Whitchurch <[email protected]>
This comment describes the behaviour before commit 2a820bf74918 ("tracing: Use percpu stack trace buffer more intelligently"). Since that commit, interrupts and NMIs do use the per-cpu stacks so the comment is no longer correct. Remove it.
(Note that the FTRACE_STACK_SIZE mentioned in the comment has never existed, it probably should have said FTRACE_STACK_ENTRIES.)
--- kernel/trace/trace.c | 6 ------ 1 file changed, 6 deletions(-)
kernel/trace/trace.c +0 -6
@@ -2930,12 +2930,6 @@ static void __ftrace_trace_stack(struct trace_buffer *buffer, skip++;#endif -/* -* Since events can happen in NMIs there's no safe way to -* use the per cpu ftrace_stacks. We reserve it and if an interrupt -* or NMI comes in, it will just have to use the default -* FTRACE_STACK_SIZE. -*/ preempt_disable_notrace (); stackidx =__this_cpu_inc_return (ftrace_stack_reserve) -1 ;
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 9/17 tracepoint: Mark __tracepoint_strings __used
In reply to Steven RostedtFrom: Nick Desaulniers <[email protected]>
__tracepoint_string's have their string data stored in .rodata, and an address to that data stored in the "__tracepoint_str" section. Functions that refer to those strings refer to the symbol of the address. Compiler optimization can replace those address references with references directly to the string data. If the address doesn't appear to have other uses, then it appears dead to the compiler and is removed. This can break the /tracing/printk_formats sysfs node which iterates the addresses stored in the "__tracepoint_str" section.
Like other strings stored in custom sections in this header, mark these __used to inform the compiler that there are other non-obvious users of the address, so they should still be emitted.
--- include/linux/tracepoint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/tracepoint.h +1 -1
@@ -361,7 +361,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p) static const char *___tp_str __tracepoint_string = str; \ ___tp_str; \ }) -#define __tracepoint_string __attribute__((section("__tracepoint_str"))) +#define __tracepoint_string __attribute__((section("__tracepoint_str"), used))#else /* * tracepoint_string() is used to save the string address for userspace
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 10/17 tracepoint: Use __used attribute definitions from compiler_attributes.h
In reply to Steven RostedtFrom: Nick Desaulniers <[email protected]>
Just a small cleanup while I was touching this header. compiler_attributes.h does feature detection of these __attributes__(()) and provides more concise ways to invoke them.
--- include/linux/tracepoint.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
include/linux/tracepoint.h +5 -6
@@ -116,8 +116,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)#define __TRACEPOINT_ENTRY (name) \ static tracepoint_ptr_t __tracepoint_ptr_##name __used \ - __attribute__((section("__tracepoints_ptrs"))) = \ - &__tracepoint_##name + __section(__tracepoints_ptrs) = &__tracepoint_##name#endif #endif /* _LINUX_TRACEPOINT_H */
@@ -280,9 +279,9 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)*/ #define DEFINE_TRACE_FN (name, reg, unreg) \ static const char __tpstrtab_##name[] \ - __attribute__((section("__tracepoints_strings"))) = #name; \ - struct tracepoint __tracepoint_##name \ - __attribute__((section("__tracepoints"), used)) = \ + __section(__tracepoints_strings) = #name; \ + struct tracepoint __tracepoint_##name __used \ + __section(__tracepoints) = \ { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\ __TRACEPOINT_ENTRY(name);
@@ -361,7 +360,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p) static const char *___tp_str __tracepoint_string = str; \ ___tp_str; \ }) -#define __tracepoint_string __attribute__((section("__tracepoint_str"), used)) +#define __tracepoint_string __used __section(__tracepoint_str)#else /* * tracepoint_string() is used to save the string address for userspace
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 11/17 ftrace: Fix ftrace_trace_task return value
In reply to Steven RostedtFrom: Josef Bacik <[email protected]>
I was attempting to use pid filtering with function_graph, but it wasn't allowing anything to make it through. Turns out ftrace_trace_task returns false if ftrace_ignore_pid is not-empty, which isn't correct anymore. We're now setting it to FTRACE_PID_IGNORE if we need to ignore that pid, otherwise it's set to the pid (which is weird considering the name) or to FTRACE_PID_TRACE. Fix the check to check for != FTRACE_PID_IGNORE. With this we can now use function_graph with pid filtering.
--- kernel/trace/ftrace.c | 3 --- kernel/trace/trace.h | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-)
kernel/trace/ftrace.c +0 -3
@@ -139,9 +139,6 @@ static inline void ftrace_ops_init(struct ftrace_ops *ops)#endif } -#define FTRACE_PID_IGNORE -1 -#define FTRACE_PID_TRACE -2 -static void ftrace_pid_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct pt_regs *regs) {
kernel/trace/trace.h +6 -1
@@ -1103,6 +1103,10 @@ print_graph_function_flags(struct trace_iterator *iter, u32 flags)extern struct list_head ftrace_pids; #ifdef CONFIG_FUNCTION_TRACER + +#define FTRACE_PID_IGNORE -1 +#define FTRACE_PID_TRACE -2 + struct ftrace_func_command { struct list_head list; char *name;
@@ -1114,7 +1118,8 @@ struct ftrace_func_command {extern bool ftrace_filter_param__initdata ;static inline int ftrace_trace_task (struct trace_array *tr) { -return !this_cpu_read (tr->array_buffer.data->ftrace_ignore_pid); +return this_cpu_read (tr->array_buffer.data->ftrace_ignore_pid) != +FTRACE_PID_IGNORE ; }extern int ftrace_is_dead (void ); int ftrace_create_function_files(struct trace_array *tr,
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 12/17 kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler
In reply to Steven RostedtFrom: Muchun Song <[email protected]>
We found a case of kernel panic on our server. The stack trace is as follows(omit some irrelevant information):
BUG: kernel NULL pointer dereference, address: 0000000000000080 RIP: 0010:kprobe_ftrace_handler+0x5e/0xe0 RSP: 0018:ffffb512c6550998 EFLAGS: 00010282 RAX: 0000000000000000 RBX: ffff8e9d16eea018 RCX: 0000000000000000 RDX: ffffffffbe1179c0 RSI: ffffffffc0535564 RDI: ffffffffc0534ec0 RBP: ffffffffc0534ec1 R08: ffff8e9d1bbb0f00 R09: 0000000000000004 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 R13: ffff8e9d1f797060 R14: 000000000000bacc R15: ffff8e9ce13eca00 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000080 CR3: 00000008453d0005 CR4: 00000000003606e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <IRQ> ftrace_ops_assist_func+0x56/0xe0 ftrace_call+0x5/0x34 tcpa_statistic_send+0x5/0x130 [ttcp_engine]
The tcpa_statistic_send is the function being kprobed. After analysis, the root cause is that the fourth parameter regs of kprobe_ftrace_handler is NULL. Why regs is NULL? We use the crash tool to analyze the kdump.
crash> dis tcpa_statistic_send -r
<tcpa_statistic_send>: callq 0xffffffffbd8018c0 <ftrace_caller>
The tcpa_statistic_send calls ftrace_caller instead of ftrace_regs_caller. So it is reasonable that the fourth parameter regs of kprobe_ftrace_handler is NULL. In theory, we should call the ftrace_regs_caller instead of the ftrace_caller. After in-depth analysis, we found a reproducible path.
Writing a simple kernel module which starts a periodic timer. The timer's handler is named 'kprobe_test_timer_handler'. The module name is kprobe_test.ko.
1) insmod kprobe_test.ko
2) bpftrace -e 'kretprobe:kprobe_test_timer_handler {}'
3) echo 0 > /proc/sys/kernel/ftrace_enabled
4) rmmod kprobe_test
5) stop step 2) kprobe
6) insmod kprobe_test.ko
7) bpftrace -e 'kretprobe:kprobe_test_timer_handler {}'
We mark the kprobe as GONE but not disarm the kprobe in the step 4). The step 5) also do not disarm the kprobe when unregister kprobe. So we do not remove the ip from the filter. In this case, when the module loads again in the step 6), we will replace the code to ftrace_caller via the ftrace_module_enable(). When we register kprobe again, we will not replace ftrace_caller to ftrace_regs_caller because the ftrace is disabled in the step 3). So the step 7) will trigger kernel panic. Fix this problem by disarming the kprobe when the module is going away.
--- kernel/kprobes.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/kprobes.c +7 -0
@@ -2113,6 +2113,13 @@ static void kill_kprobe(struct kprobe *p)* the original probed function (which will be freed soon) any more. */ arch_remove_kprobe (p); + +/* +* The module is going away. We should disarm the kprobe which +* is using ftrace. +*/ +if (kprobe_ftrace (p)) +disarm_kprobe_ftrace (p); }/* Disable one kprobe */
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 13/17 tracing/uprobe: Remove dead code in trace_uprobe_register()
In reply to Steven RostedtFrom: Peng Fan <[email protected]>
In the function trace_uprobe_register(), the statement "return 0;" out of switch case is dead code, remove it.
--- kernel/trace/trace_uprobe.c | 1 - 1 file changed, 1 deletion(-)
kernel/trace/trace_uprobe.c +0 -1
@@ -1456,7 +1456,6 @@ trace_uprobe_register(struct trace_event_call *event, enum trace_reg type,default :return 0 ; } -return 0 ; }static int uprobe_dispatcher (struct uprobe_consumer *con,struct pt_regs *regs)
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 14/17 kprobes: Remove show_registers() function prototype
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Remove show_registers() function prototype because this function has been renamed by commit 57da8b960b9a ("x86: Avoid double stack traces with show_regs()"), and commit 80006dbee674 ("kprobes/x86:
Remove jprobe implementation") has removed the caller in kprobes. So this doesn't exist anymore.
--- include/linux/kprobes.h | 1 - 1 file changed, 1 deletion(-)
include/linux/kprobes.h +0 -1
@@ -227,7 +227,6 @@ extern int arch_prepare_kprobe(struct kprobe *p);extern void arch_arm_kprobe (struct kprobe *p);extern void arch_disarm_kprobe (struct kprobe *p);extern int arch_init_kprobes (void ); -extern void show_registers (struct pt_regs *regs);extern void kprobes_inc_nmissed_count (struct kprobe *p);extern bool arch_within_kprobe_blacklist (unsigned long addr);extern int arch_populate_kprobe_blacklist (void );
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 15/17 lib/bootconfig: Add override operator support
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add the value override operator (":=") support to the bootconfig.
This value override operator will be useful for the bootloaders which will only update the existing bootconfig according to the bootloader boot options.
Without this override operator, the bootloader needs to parse the existing bootconfig and update it. However, with this assignment, it can just append the updated (partial) bootconfig text at the tail of existing one without parsing it. (Of course, it must update the size, checksum and magic,
but that will be done easily)
--- lib/bootconfig.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
lib/bootconfig.c +23 -10
@@ -329,22 +329,30 @@ const char * __init xbc_node_find_next_key_value(struct xbc_node *root,/* XBC parse and tree build */ +static int __init xbc_init_node (struct xbc_node *node,char *data,u32 flag) +{ +unsigned long offset = data - xbc_data; + +if (WARN_ON (offset >=XBC_DATA_MAX )) +return -EINVAL ; + + node->data = (u16 )offset | flag; + node->child =0 ; + node->next =0 ; + +return 0 ; +} +static struct xbc_node *__init xbc_add_node (char *data,u32 flag) {struct xbc_node *node; -unsigned long offset;if (xbc_node_num ==XBC_NODE_MAX )return NULL ; node = &xbc_nodes[xbc_node_num++]; - offset = data - xbc_data; - node->data = (u16 )offset; -if (WARN_ON (offset >=XBC_DATA_MAX )) +if (xbc_init_node (node, data, flag) <0 )return NULL ; - node->data |= flag; - node->child =0 ; - node->next =0 ;return node; }
@@ -603,7 +611,9 @@ static int __init xbc_parse_kv(char **k, char *v, int op)if (c <0 )return c; -if (!xbc_add_sibling (v,XBC_VALUE )) +if (op ==':' && child) { +xbc_init_node (child, v,XBC_VALUE ); + }else if (!xbc_add_sibling (v,XBC_VALUE ))return -ENOMEM ;if (c ==',' ) {/* Array */
@@ -787,7 +797,7 @@ int __init xbc_init(char *buf, const char **emsg, int *epos) p = buf; do { - q = strpbrk(p, "{}=+;\n#"); + q = strpbrk(p, "{}=+;:\n#"); if (!q) { p = skip_spaces(p); if (*p != '\0')
@@ -798,9 +808,12 @@ int __init xbc_init(char *buf, const char **emsg, int *epos) c = *q; *q++ ='\0' ;switch (c) { +case ':' :case '+' :if (*q++ !='=' ) { - ret =xbc_parse_error ("Wrong '+' operator" , + ret =xbc_parse_error (c =='+' ? +"Wrong '+' operator" : +"Wrong ':' operator" , q -2 );break ; }
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 16/17 tools/bootconfig: Add testcases for value override operator
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add some testcases and examples for value override operator.
--- tools/bootconfig/samples/bad-override.bconf | 3 +++ tools/bootconfig/samples/bad-override2.bconf | 3 +++ tools/bootconfig/samples/good-override.bconf | 6 ++++++ tools/bootconfig/test-bootconfig.sh | 13 +++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 tools/bootconfig/samples/bad-override.bconf create mode 100644 tools/bootconfig/samples/bad-override2.bconf create mode 100644 tools/bootconfig/samples/good-override.bconf
tools/bootconfig/samples/bad-override.bconf new file +3 -0
@@ -0,0 +1,3 @@ +key.subkey = value +# We can not override pre-defined subkeys with value +key := value
tools/bootconfig/samples/bad-override2.bconf new file +3 -0
@@ -0,0 +1,3 @@ +key = value +# We can not override pre-defined value with subkey +key.subkey := value
tools/bootconfig/samples/good-override.bconf new file +6 -0
@@ -0,0 +1,6 @@ +# Override the value +key.word = 1,2,4 +key.word := 2,3 + +# No pre-defined key +key.new.word := "new"
tools/bootconfig/test-bootconfig.sh +13 -0
@@ -117,6 +117,19 @@ xpass grep -q "bar" $OUTFILE xpass grep -q "baz" $OUTFILE xpass grep -q "qux" $OUTFILE +echo "Override same-key values" +cat > $TEMPCONF << EOF +key = bar, baz +key := qux +EOF +echo > $INITRD + +xpass $BOOTCONF -a $TEMPCONF $INITRD +$BOOTCONF $INITRD > $OUTFILE +xfail grep -q "bar" $OUTFILE +xfail grep -q "baz" $OUTFILE +xpass grep -q "qux" $OUTFILE + echo "Double/single quotes test" echo "key = '\"string\"';" > $TEMPCONF $BOOTCONF -a $TEMPCONF $INITRD
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 17/17 Documentation: bootconfig: Add bootconfig override operator
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add a sentence about bootconfig override operator (":=") to bootconfig.rst.
--- Documentation/admin-guide/bootconfig.rst | 11 +++++++++++ 1 file changed, 11 insertions(+)
Documentation/admin-guide/bootconfig.rst +11 -0
@@ -71,6 +71,16 @@ For example,:: foo = bar, baz foo = qux # !ERROR! we can not re-define same key +If you want to update the value, you must use the override operator +``:=`` explicitly. For example:: + + foo = bar, baz + foo := qux + +then, the ``qux`` is assigned to ``foo`` key. This is useful for +overriding the default value by adding (partial) custom bootconfigs +without parsing the default bootconfig. + If you want to append the value to existing key as an array member, you can use ``+=`` operator. For example::
@@ -84,6 +94,7 @@ For example, following config is NOT allowed.:: foo = value1 foo.bar = value2 # !ERROR! subkey "bar" and value "value1" can NOT co-exist + foo.bar := value2 # !ERROR! even with the override operator, this is NOT allowed. Comments
Signature · 1 line
2.26.2