Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'trace-v6.14-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull tracing fixes from Steven Rostedt:

- Fix crash from bad histogram entry

An error path in the histogram creation could leave an entry in a
link list that gets freed. Then when a new entry is added it can
cause a u-a-f bug. This is fixed by restructuring the code so that
the histogram is consistent on failure and everything is cleaned up
appropriately.

- Fix fprobe self test

The fprobe self test relies on no function being attached by ftrace.
BPF programs can attach to functions via ftrace and systemd now does
so. This causes those functions to appear in the enabled_functions
list which holds all functions attached by ftrace. The selftest also
uses that file to see if functions are being connected correctly. It
counts the functions in the file, but if there's already functions in
the file, it fails. Instead, add the number of functions in the file
at the start of the test to all the calculations during the test.

- Fix potential division by zero of the function profiler stddev

The calculated divisor that calculates the standard deviation of the
function times can overflow. If the overflow happens to land on zero,
that can cause a division by zero. Check for zero from the
calculation before doing the division.

TODO: Catch when it ever overflows and report it accordingly. For
now, just prevent the system from crashing.

* tag 'trace-v6.14-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
ftrace: Avoid potential division by zero in function_stat_show()
selftests/ftrace: Let fprobe test consider already enabled functions
tracing: Fix bad hist from corrupting named_triggers list

+40 -39
+12 -15
kernel/trace/ftrace.c
··· 540 540 static struct trace_seq s; 541 541 unsigned long long avg; 542 542 unsigned long long stddev; 543 + unsigned long long stddev_denom; 543 544 #endif 544 545 guard(mutex)(&ftrace_profile_lock); 545 546 ··· 560 559 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 561 560 seq_puts(m, " "); 562 561 563 - /* Sample standard deviation (s^2) */ 564 - if (rec->counter <= 1) 565 - stddev = 0; 566 - else { 567 - /* 568 - * Apply Welford's method: 569 - * s^2 = 1 / (n * (n-1)) * (n * \Sum (x_i)^2 - (\Sum x_i)^2) 570 - */ 562 + /* 563 + * Variance formula: 564 + * s^2 = 1 / (n * (n-1)) * (n * \Sum (x_i)^2 - (\Sum x_i)^2) 565 + * Maybe Welford's method is better here? 566 + * Divide only by 1000 for ns^2 -> us^2 conversion. 567 + * trace_print_graph_duration will divide by 1000 again. 568 + */ 569 + stddev = 0; 570 + stddev_denom = rec->counter * (rec->counter - 1) * 1000; 571 + if (stddev_denom) { 571 572 stddev = rec->counter * rec->time_squared - 572 573 rec->time * rec->time; 573 - 574 - /* 575 - * Divide only 1000 for ns^2 -> us^2 conversion. 576 - * trace_print_graph_duration will divide 1000 again. 577 - */ 578 - stddev = div64_ul(stddev, 579 - rec->counter * (rec->counter - 1) * 1000); 574 + stddev = div64_ul(stddev, stddev_denom); 580 575 } 581 576 582 577 trace_seq_init(&s);
+17 -17
kernel/trace/trace_events_hist.c
··· 6724 6724 if (existing_hist_update_only(glob, trigger_data, file)) 6725 6725 goto out_free; 6726 6726 6727 + if (!get_named_trigger_data(trigger_data)) { 6728 + 6729 + ret = create_actions(hist_data); 6730 + if (ret) 6731 + goto out_free; 6732 + 6733 + if (has_hist_vars(hist_data) || hist_data->n_var_refs) { 6734 + ret = save_hist_vars(hist_data); 6735 + if (ret) 6736 + goto out_free; 6737 + } 6738 + 6739 + ret = tracing_map_init(hist_data->map); 6740 + if (ret) 6741 + goto out_free; 6742 + } 6743 + 6727 6744 ret = event_trigger_register(cmd_ops, file, glob, trigger_data); 6728 6745 if (ret < 0) 6729 6746 goto out_free; 6730 6747 6731 - if (get_named_trigger_data(trigger_data)) 6732 - goto enable; 6733 - 6734 - ret = create_actions(hist_data); 6735 - if (ret) 6736 - goto out_unreg; 6737 - 6738 - if (has_hist_vars(hist_data) || hist_data->n_var_refs) { 6739 - ret = save_hist_vars(hist_data); 6740 - if (ret) 6741 - goto out_unreg; 6742 - } 6743 - 6744 - ret = tracing_map_init(hist_data->map); 6745 - if (ret) 6746 - goto out_unreg; 6747 - enable: 6748 6748 ret = hist_trigger_enable(trigger_data, file); 6749 6749 if (ret) 6750 6750 goto out_unreg;
+11 -7
tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
··· 10 10 PLACE2="kmem_cache_free" 11 11 PLACE3="schedule_timeout" 12 12 13 + # Some functions may have BPF programs attached, therefore 14 + # count already enabled_functions before tests start 15 + ocnt=`cat enabled_functions | wc -l` 16 + 13 17 echo "f:myevent1 $PLACE" >> dynamic_events 14 18 15 19 # Make sure the event is attached and is the only one 16 20 grep -q $PLACE enabled_functions 17 21 cnt=`cat enabled_functions | wc -l` 18 - if [ $cnt -ne 1 ]; then 22 + if [ $cnt -ne $((ocnt + 1)) ]; then 19 23 exit_fail 20 24 fi 21 25 ··· 27 23 28 24 # It should till be the only attached function 29 25 cnt=`cat enabled_functions | wc -l` 30 - if [ $cnt -ne 1 ]; then 26 + if [ $cnt -ne $((ocnt + 1)) ]; then 31 27 exit_fail 32 28 fi 33 29 ··· 36 32 37 33 grep -q $PLACE2 enabled_functions 38 34 cnt=`cat enabled_functions | wc -l` 39 - if [ $cnt -ne 2 ]; then 35 + if [ $cnt -ne $((ocnt + 2)) ]; then 40 36 exit_fail 41 37 fi 42 38 ··· 53 49 54 50 # should still have 2 left 55 51 cnt=`cat enabled_functions | wc -l` 56 - if [ $cnt -ne 2 ]; then 52 + if [ $cnt -ne $((ocnt + 2)) ]; then 57 53 exit_fail 58 54 fi 59 55 ··· 61 57 62 58 # Should have none left 63 59 cnt=`cat enabled_functions | wc -l` 64 - if [ $cnt -ne 0 ]; then 60 + if [ $cnt -ne $ocnt ]; then 65 61 exit_fail 66 62 fi 67 63 ··· 69 65 70 66 # Should only have one enabled 71 67 cnt=`cat enabled_functions | wc -l` 72 - if [ $cnt -ne 1 ]; then 68 + if [ $cnt -ne $((ocnt + 1)) ]; then 73 69 exit_fail 74 70 fi 75 71 ··· 77 73 78 74 # Should have none left 79 75 cnt=`cat enabled_functions | wc -l` 80 - if [ $cnt -ne 0 ]; then 76 + if [ $cnt -ne $ocnt ]; then 81 77 exit_fail 82 78 fi 83 79