<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/kernel/trace/trace_events_hist.c, branch v6.0</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v6.0</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.0'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2022-07-12T21:35:11Z</updated>
<entry>
<title>tracing/histograms: Simplify create_hist_fields()</title>
<updated>2022-07-12T21:35:11Z</updated>
<author>
<name>Zheng Yejian</name>
<email>zhengyejian1@huawei.com</email>
</author>
<published>2022-06-30T01:31:52Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=fb991f1942334b0cbf6aa6a88faa586ba22d3550'/>
<id>urn:sha1:fb991f1942334b0cbf6aa6a88faa586ba22d3550</id>
<content type='text'>
When I look into implements of create_hist_fields(), I think there can be
following two simplifications:
  1. If something wrong happened in parse_var_defs(), free_var_defs() would
     have been called in it, so no need goto free again after calling it;
  2. After calling create_key_fields(), regardless of the value of 'ret', it
     then always runs into 'out: ', so the judge of 'ret' is redundant.

Link: https://lkml.kernel.org/r/20220630013152.164871-1-zhengyejian1@huawei.com

Signed-off-by: Zheng Yejian &lt;zhengyejian1@huawei.com&gt;
Reviewed-by: Tom Rix &lt;trix@redhat.com&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/histograms: Fix memory leak problem</title>
<updated>2022-07-12T20:35:42Z</updated>
<author>
<name>Zheng Yejian</name>
<email>zhengyejian1@huawei.com</email>
</author>
<published>2022-07-11T01:47:31Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=7edc3945bdce9c39198a10d6129377a5c53559c2'/>
<id>urn:sha1:7edc3945bdce9c39198a10d6129377a5c53559c2</id>
<content type='text'>
This reverts commit 46bbe5c671e06f070428b9be142cc4ee5cedebac.

As commit 46bbe5c671e0 ("tracing: fix double free") said, the
"double free" problem reported by clang static analyzer is:
  &gt; In parse_var_defs() if there is a problem allocating
  &gt; var_defs.expr, the earlier var_defs.name is freed.
  &gt; This free is duplicated by free_var_defs() which frees
  &gt; the rest of the list.

However, if there is a problem allocating N-th var_defs.expr:
  + in parse_var_defs(), the freed 'earlier var_defs.name' is
    actually the N-th var_defs.name;
  + then in free_var_defs(), the names from 0th to (N-1)-th are freed;

                        IF ALLOCATING PROBLEM HAPPENED HERE!!! -+
                                                                 \
                                                                  |
          0th           1th                 (N-1)-th      N-th    V
          +-------------+-------------+-----+-------------+-----------
var_defs: | name | expr | name | expr | ... | name | expr | name | ///
          +-------------+-------------+-----+-------------+-----------

These two frees don't act on same name, so there was no "double free"
problem before. Conversely, after that commit, we get a "memory leak"
problem because the above "N-th var_defs.name" is not freed.

If enable CONFIG_DEBUG_KMEMLEAK and inject a fault at where the N-th
var_defs.expr allocated, then execute on shell like:
  $ echo 'hist:key=call_site:val=$v1,$v2:v1=bytes_req,v2=bytes_alloc' &gt; \
/sys/kernel/debug/tracing/events/kmem/kmalloc/trigger

Then kmemleak reports:
  unreferenced object 0xffff8fb100ef3518 (size 8):
    comm "bash", pid 196, jiffies 4295681690 (age 28.538s)
    hex dump (first 8 bytes):
      76 31 00 00 b1 8f ff ff                          v1......
    backtrace:
      [&lt;0000000038fe4895&gt;] kstrdup+0x2d/0x60
      [&lt;00000000c99c049a&gt;] event_hist_trigger_parse+0x206f/0x20e0
      [&lt;00000000ae70d2cc&gt;] trigger_process_regex+0xc0/0x110
      [&lt;0000000066737a4c&gt;] event_trigger_write+0x75/0xd0
      [&lt;000000007341e40c&gt;] vfs_write+0xbb/0x2a0
      [&lt;0000000087fde4c2&gt;] ksys_write+0x59/0xd0
      [&lt;00000000581e9cdf&gt;] do_syscall_64+0x3a/0x80
      [&lt;00000000cf3b065c&gt;] entry_SYSCALL_64_after_hwframe+0x46/0xb0

Link: https://lkml.kernel.org/r/20220711014731.69520-1-zhengyejian1@huawei.com

Cc: stable@vger.kernel.org
Fixes: 46bbe5c671e0 ("tracing: fix double free")
Reported-by: Hulk Robot &lt;hulkci@huawei.com&gt;
Suggested-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
Reviewed-by: Tom Zanussi &lt;tom.zanussi@linux.intel.com&gt;
Signed-off-by: Zheng Yejian &lt;zhengyejian1@huawei.com&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Change "char *" string form to "char []"</title>
<updated>2022-05-27T01:13:00Z</updated>
<author>
<name>liqiong</name>
<email>liqiong@nfschina.com</email>
</author>
<published>2022-05-12T14:32:30Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=2d601b98643dd2846e2958d931826e7b7af44969'/>
<id>urn:sha1:2d601b98643dd2846e2958d931826e7b7af44969</id>
<content type='text'>
The "char []" string form declares a single variable. It is better
than "char *" which creates two variables in the final assembly.

Link: https://lkml.kernel.org/r/20220512143230.28796-1-liqiong@nfschina.com

Signed-off-by: liqiong &lt;liqiong@nfschina.com&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Fix potential double free in create_var_ref()</title>
<updated>2022-05-27T01:12:59Z</updated>
<author>
<name>Keita Suzuki</name>
<email>keitasuzuki.park@sslab.ics.keio.ac.jp</email>
</author>
<published>2022-04-25T06:37:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=99696a2592bca641eb88cc9a80c90e591afebd0f'/>
<id>urn:sha1:99696a2592bca641eb88cc9a80c90e591afebd0f</id>
<content type='text'>
In create_var_ref(), init_var_ref() is called to initialize the fields
of variable ref_field, which is allocated in the previous function call
to create_hist_field(). Function init_var_ref() allocates the
corresponding fields such as ref_field-&gt;system, but frees these fields
when the function encounters an error. The caller later calls
destroy_hist_field() to conduct error handling, which frees the fields
and the variable itself. This results in double free of the fields which
are already freed in the previous function.

Fix this by storing NULL to the corresponding fields when they are freed
in init_var_ref().

Link: https://lkml.kernel.org/r/20220425063739.3859998-1-keitasuzuki.park@sslab.ics.keio.ac.jp

Fixes: 067fe038e70f ("tracing: Add variable reference handling to hist triggers")
CC: stable@vger.kernel.org
Reviewed-by: Masami Hiramatsu &lt;mhiramat@kernel.org&gt;
Reviewed-by: Tom Zanussi &lt;zanussi@kernel.org&gt;
Signed-off-by: Keita Suzuki &lt;keitasuzuki.park@sslab.ics.keio.ac.jp&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Replace usage of found with dedicated list iterator variable</title>
<updated>2022-04-27T21:19:31Z</updated>
<author>
<name>Jakob Koschel</name>
<email>jakobkoschel@gmail.com</email>
</author>
<published>2022-04-27T17:07:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=45e333ce2ad5cbb0ee05686336de09058c6af8ca'/>
<id>urn:sha1:45e333ce2ad5cbb0ee05686336de09058c6af8ca</id>
<content type='text'>
To move the list iterator variable into the list_for_each_entry_*()
macro in the future it should be avoided to use the list iterator
variable after the loop body.

To *never* use the list iterator variable after the loop it was
concluded to use a separate iterator variable instead of a
found boolean [1].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lkml.kernel.org/r/20220427170734.819891-4-jakobkoschel@gmail.com

Cc: Ingo Molnar &lt;mingo@redhat.com&gt;
Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
Signed-off-by: Jakob Koschel &lt;jakobkoschel@gmail.com&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Change `if (strlen(glob))` to `if (glob[0])`</title>
<updated>2022-04-26T21:58:52Z</updated>
<author>
<name>Ammar Faizi</name>
<email>ammarfaizi2@gnuweeb.org</email>
</author>
<published>2022-04-17T18:56:30Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=69686fcbdcc0b6fed3b8d0907e641f282df2f827'/>
<id>urn:sha1:69686fcbdcc0b6fed3b8d0907e641f282df2f827</id>
<content type='text'>
No need to traverse to the end of string. If the first byte is not a NUL
char, it's guaranteed `if (strlen(glob))` is true.

Link: https://lkml.kernel.org/r/20220417185630.199062-3-ammarfaizi2@gnuweeb.org

Cc: Ingo Molnar &lt;mingo@redhat.com&gt;
Cc: GNU/Weeb Mailing List &lt;gwml@vger.gnuweeb.org&gt;
Signed-off-by: Ammar Faizi &lt;ammarfaizi2@gnuweeb.org&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Return -EINVAL if WARN_ON(!glob) triggered in event_hist_trigger_parse()</title>
<updated>2022-04-26T21:58:52Z</updated>
<author>
<name>Ammar Faizi</name>
<email>ammarfaizi2@gnuweeb.org</email>
</author>
<published>2022-04-17T18:56:29Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=97a5d2e5e35f119b6d7a37c7538773ae7af82dd5'/>
<id>urn:sha1:97a5d2e5e35f119b6d7a37c7538773ae7af82dd5</id>
<content type='text'>
If `WARN_ON(!glob)` is ever triggered, we will still continue executing
the next lines. This will trigger the more serious problem, a NULL
pointer dereference bug.

Just return -EINVAL if @glob is NULL.

Link: https://lkml.kernel.org/r/20220417185630.199062-2-ammarfaizi2@gnuweeb.org

Cc: Ingo Molnar &lt;mingo@redhat.com&gt;
Cc: GNU/Weeb Mailing List &lt;gwml@vger.gnuweeb.org&gt;
Signed-off-by: Ammar Faizi &lt;ammarfaizi2@gnuweeb.org&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Separate hist state updates from hist registration</title>
<updated>2022-04-26T21:58:50Z</updated>
<author>
<name>Tom Zanussi</name>
<email>zanussi@kernel.org</email>
</author>
<published>2022-02-04T22:12:07Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=a7e6b7dcfb19988ad2968a1fafd29b600abbf133'/>
<id>urn:sha1:a7e6b7dcfb19988ad2968a1fafd29b600abbf133</id>
<content type='text'>
hist_register_trigger() handles both new hist registration as well as
existing hist registration through event_command.reg().

Adding a new function, existing_hist_update_only(), that checks and
updates existing histograms and exits after doing so allows the
confusing logic in event_hist_trigger_parse() to be simplified.

Link: https://lkml.kernel.org/r/211b2cd3e3d7e00f4f8ad45ef8b33063da6a7e05.1644010576.git.zanussi@kernel.org

Signed-off-by: Tom Zanussi &lt;zanussi@kernel.org&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Have existing event_command.parse() implementations use helpers</title>
<updated>2022-04-26T21:58:50Z</updated>
<author>
<name>Tom Zanussi</name>
<email>zanussi@kernel.org</email>
</author>
<published>2022-02-04T22:12:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e1f187d09e11f50a50cbb02ae277d4e8bdfc7db8'/>
<id>urn:sha1:e1f187d09e11f50a50cbb02ae277d4e8bdfc7db8</id>
<content type='text'>
Simplify the existing event_command.parse() implementations by having
them make use of the helper functions previously introduced.

Link: https://lkml.kernel.org/r/b353e3427a81f9d3adafd98fd7d73e78a8209f43.1644010576.git.zanussi@kernel.org

Signed-off-by: Tom Zanussi &lt;zanussi@kernel.org&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Remove redundant trigger_ops params</title>
<updated>2022-04-26T21:58:50Z</updated>
<author>
<name>Tom Zanussi</name>
<email>zanussi@kernel.org</email>
</author>
<published>2022-02-04T22:12:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=476705419518a2f383b6695782ba1f285a2959b9'/>
<id>urn:sha1:476705419518a2f383b6695782ba1f285a2959b9</id>
<content type='text'>
Since event_trigger_data contains the .ops trigger_ops field, there's
no reason to pass the trigger_ops separately. Remove it as a param
from functions whenever event_trigger_data is passed.

Link: https://lkml.kernel.org/r/9856c9bc81bde57077f5b8d6f8faa47156c6354a.1644010575.git.zanussi@kernel.org

Signed-off-by: Tom Zanussi &lt;zanussi@kernel.org&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
</feed>
