<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/kernel/trace/tracing_map.c, branch v4.14.328</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.14.328</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.14.328'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2021-12-22T08:17:58Z</updated>
<entry>
<title>tracing: Fix a kmemleak false positive in tracing_map</title>
<updated>2021-12-22T08:17:58Z</updated>
<author>
<name>Chen Jun</name>
<email>chenjun102@huawei.com</email>
</author>
<published>2021-11-24T14:08:01Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=06f629fc209e1c7668d7ddec391d19a56b3ebd11'/>
<id>urn:sha1:06f629fc209e1c7668d7ddec391d19a56b3ebd11</id>
<content type='text'>
[ Upstream commit f25667e5980a4333729cac3101e5de1bb851f71a ]

Doing the command:
  echo 'hist:key=common_pid.execname,common_timestamp' &gt; /sys/kernel/debug/tracing/events/xxx/trigger

Triggers many kmemleak reports:

unreferenced object 0xffff0000c7ea4980 (size 128):
  comm "bash", pid 338, jiffies 4294912626 (age 9339.324s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [&lt;00000000f3469921&gt;] kmem_cache_alloc_trace+0x4c0/0x6f0
    [&lt;0000000054ca40c3&gt;] hist_trigger_elt_data_alloc+0x140/0x178
    [&lt;00000000633bd154&gt;] tracing_map_init+0x1f8/0x268
    [&lt;000000007e814ab9&gt;] event_hist_trigger_func+0xca0/0x1ad0
    [&lt;00000000bf8520ed&gt;] trigger_process_regex+0xd4/0x128
    [&lt;00000000f549355a&gt;] event_trigger_write+0x7c/0x120
    [&lt;00000000b80f898d&gt;] vfs_write+0xc4/0x380
    [&lt;00000000823e1055&gt;] ksys_write+0x74/0xf8
    [&lt;000000008a9374aa&gt;] __arm64_sys_write+0x24/0x30
    [&lt;0000000087124017&gt;] do_el0_svc+0x88/0x1c0
    [&lt;00000000efd0dcd1&gt;] el0_svc+0x1c/0x28
    [&lt;00000000dbfba9b3&gt;] el0_sync_handler+0x88/0xc0
    [&lt;00000000e7399680&gt;] el0_sync+0x148/0x180
unreferenced object 0xffff0000c7ea4980 (size 128):
  comm "bash", pid 338, jiffies 4294912626 (age 9339.324s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [&lt;00000000f3469921&gt;] kmem_cache_alloc_trace+0x4c0/0x6f0
    [&lt;0000000054ca40c3&gt;] hist_trigger_elt_data_alloc+0x140/0x178
    [&lt;00000000633bd154&gt;] tracing_map_init+0x1f8/0x268
    [&lt;000000007e814ab9&gt;] event_hist_trigger_func+0xca0/0x1ad0
    [&lt;00000000bf8520ed&gt;] trigger_process_regex+0xd4/0x128
    [&lt;00000000f549355a&gt;] event_trigger_write+0x7c/0x120
    [&lt;00000000b80f898d&gt;] vfs_write+0xc4/0x380
    [&lt;00000000823e1055&gt;] ksys_write+0x74/0xf8
    [&lt;000000008a9374aa&gt;] __arm64_sys_write+0x24/0x30
    [&lt;0000000087124017&gt;] do_el0_svc+0x88/0x1c0
    [&lt;00000000efd0dcd1&gt;] el0_svc+0x1c/0x28
    [&lt;00000000dbfba9b3&gt;] el0_sync_handler+0x88/0xc0
    [&lt;00000000e7399680&gt;] el0_sync+0x148/0x180

The reason is elts-&gt;pages[i] is alloced by get_zeroed_page.
and kmemleak will not scan the area alloced by get_zeroed_page.
The address stored in elts-&gt;pages will be regarded as leaked.

That is, the elts-&gt;pages[i] will have pointers loaded onto it as well, and
without telling kmemleak about it, those pointers will look like memory
without a reference.

To fix this, call kmemleak_alloc to tell kmemleak to scan elts-&gt;pages[i]

Link: https://lkml.kernel.org/r/20211124140801.87121-1-chenjun102@huawei.com

Signed-off-by: Chen Jun &lt;chenjun102@huawei.com&gt;
Signed-off-by: Steven Rostedt (VMware) &lt;rostedt@goodmis.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>tracing/cfi: Fix cmp_entries_* functions signature mismatch</title>
<updated>2021-11-26T10:40:28Z</updated>
<author>
<name>Kalesh Singh</name>
<email>kaleshsingh@google.com</email>
</author>
<published>2021-10-14T04:52:17Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=cb4301a9b4b348e8ab3d0a49677b922edbf6e106'/>
<id>urn:sha1:cb4301a9b4b348e8ab3d0a49677b922edbf6e106</id>
<content type='text'>
[ Upstream commit 7ce1bb83a14019f8c396d57ec704d19478747716 ]

If CONFIG_CFI_CLANG=y, attempting to read an event histogram will cause
the kernel to panic due to failed CFI check.

    1. echo 'hist:keys=common_pid' &gt;&gt; events/sched/sched_switch/trigger
    2. cat events/sched/sched_switch/hist
    3. kernel panics on attempting to read hist

This happens because the sort() function expects a generic
int (*)(const void *, const void *) pointer for the compare function.
To prevent this CFI failure, change tracing map cmp_entries_* function
signatures to match this.

Also, fix the build error reported by the kernel test robot [1].

[1] https://lore.kernel.org/r/202110141140.zzi4dRh4-lkp@intel.com/

Link: https://lkml.kernel.org/r/20211014045217.3265162-1-kaleshsingh@google.com

Signed-off-by: Kalesh Singh &lt;kaleshsingh@google.com&gt;
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: Steven Rostedt (VMware) &lt;rostedt@goodmis.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>tracing: Have the histogram compare functions convert to u64 first</title>
<updated>2020-01-09T09:17:56Z</updated>
<author>
<name>Steven Rostedt (VMware)</name>
<email>rostedt@goodmis.org</email>
</author>
<published>2019-12-11T20:44:22Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=bc5e8a8a58be3e7414fb5abdbe49d731cbd26f2f'/>
<id>urn:sha1:bc5e8a8a58be3e7414fb5abdbe49d731cbd26f2f</id>
<content type='text'>
commit 106f41f5a302cb1f36c7543fae6a05de12e96fa4 upstream.

The compare functions of the histogram code would be specific for the size
of the value being compared (byte, short, int, long long). It would
reference the value from the array via the type of the compare, but the
value was stored in a 64 bit number. This is fine for little endian
machines, but for big endian machines, it would end up comparing zeros or
all ones (depending on the sign) for anything but 64 bit numbers.

To fix this, first derference the value as a u64 then convert it to the type
being compared.

Link: http://lkml.kernel.org/r/20191211103557.7bed6928@gandalf.local.home

Cc: stable@vger.kernel.org
Fixes: 08d43a5fa063e ("tracing: Add lock-free tracing_map")
Acked-by: Tom Zanussi &lt;zanussi@kernel.org&gt;
Reported-by: Sven Schnelle &lt;svens@stackframe.org&gt;
Signed-off-by: Steven Rostedt (VMware) &lt;rostedt@goodmis.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>tracing: Fix kmemleak in tracing_map_array_free()</title>
<updated>2017-08-24T14:05:51Z</updated>
<author>
<name>Chunyu Hu</name>
<email>chuhu@redhat.com</email>
</author>
<published>2017-08-14T10:18:17Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=475bb3c69ab05df2a6ecef6acc2393703d134180'/>
<id>urn:sha1:475bb3c69ab05df2a6ecef6acc2393703d134180</id>
<content type='text'>
kmemleak reported the below leak when I was doing clear of the hist
trigger. With this patch, the kmeamleak is gone.

unreferenced object 0xffff94322b63d760 (size 32):
  comm "bash", pid 1522, jiffies 4403687962 (age 2442.311s)
  hex dump (first 32 bytes):
    00 01 00 00 04 00 00 00 08 00 00 00 ff 00 00 00  ................
    10 00 00 00 00 00 00 00 80 a8 7a f2 31 94 ff ff  ..........z.1...
  backtrace:
    [&lt;ffffffff9e96c27a&gt;] kmemleak_alloc+0x4a/0xa0
    [&lt;ffffffff9e424cba&gt;] kmem_cache_alloc_trace+0xca/0x1d0
    [&lt;ffffffff9e377736&gt;] tracing_map_array_alloc+0x26/0x140
    [&lt;ffffffff9e261be0&gt;] kretprobe_trampoline+0x0/0x50
    [&lt;ffffffff9e38b935&gt;] create_hist_data+0x535/0x750
    [&lt;ffffffff9e38bd47&gt;] event_hist_trigger_func+0x1f7/0x420
    [&lt;ffffffff9e38893d&gt;] event_trigger_write+0xfd/0x1a0
    [&lt;ffffffff9e44dfc7&gt;] __vfs_write+0x37/0x170
    [&lt;ffffffff9e44f552&gt;] vfs_write+0xb2/0x1b0
    [&lt;ffffffff9e450b85&gt;] SyS_write+0x55/0xc0
    [&lt;ffffffff9e203857&gt;] do_syscall_64+0x67/0x150
    [&lt;ffffffff9e977ce7&gt;] return_from_SYSCALL_64+0x0/0x6a
    [&lt;ffffffffffffffff&gt;] 0xffffffffffffffff
unreferenced object 0xffff9431f27aa880 (size 128):
  comm "bash", pid 1522, jiffies 4403687962 (age 2442.311s)
  hex dump (first 32 bytes):
    00 00 8c 2a 32 94 ff ff 00 f0 8b 2a 32 94 ff ff  ...*2......*2...
    00 e0 8b 2a 32 94 ff ff 00 d0 8b 2a 32 94 ff ff  ...*2......*2...
  backtrace:
    [&lt;ffffffff9e96c27a&gt;] kmemleak_alloc+0x4a/0xa0
    [&lt;ffffffff9e425348&gt;] __kmalloc+0xe8/0x220
    [&lt;ffffffff9e3777c1&gt;] tracing_map_array_alloc+0xb1/0x140
    [&lt;ffffffff9e261be0&gt;] kretprobe_trampoline+0x0/0x50
    [&lt;ffffffff9e38b935&gt;] create_hist_data+0x535/0x750
    [&lt;ffffffff9e38bd47&gt;] event_hist_trigger_func+0x1f7/0x420
    [&lt;ffffffff9e38893d&gt;] event_trigger_write+0xfd/0x1a0
    [&lt;ffffffff9e44dfc7&gt;] __vfs_write+0x37/0x170
    [&lt;ffffffff9e44f552&gt;] vfs_write+0xb2/0x1b0
    [&lt;ffffffff9e450b85&gt;] SyS_write+0x55/0xc0
    [&lt;ffffffff9e203857&gt;] do_syscall_64+0x67/0x150
    [&lt;ffffffff9e977ce7&gt;] return_from_SYSCALL_64+0x0/0x6a
    [&lt;ffffffffffffffff&gt;] 0xffffffffffffffff

Link: http://lkml.kernel.org/r/1502705898-27571-1-git-send-email-chuhu@redhat.com

Cc: stable@vger.kernel.org
Fixes: 08d43a5fa063 ("tracing: Add lock-free tracing_map")
Signed-off-by: Chunyu Hu &lt;chuhu@redhat.com&gt;
Signed-off-by: Steven Rostedt (VMware) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Handle tracing_map_alloc_elts() error path correctly</title>
<updated>2016-04-26T13:40:30Z</updated>
<author>
<name>Tom Zanussi</name>
<email>tom.zanussi@linux.intel.com</email>
</author>
<published>2016-04-25T19:01:28Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=6e4cf657defa8fb06dbf9ed91adb78414758f259'/>
<id>urn:sha1:6e4cf657defa8fb06dbf9ed91adb78414758f259</id>
<content type='text'>
If tracing_map_elt_alloc() fails, it will return ERR_PTR() instead of
NULL, so change the check to IS_ERROR().  We also need to set the
failed entry in the map-&gt;elts array to NULL instead of ERR_PTR() so
tracing_map_free_elts() doesn't try freeing an ERR_PTR().

tracing_map_free_elts() should also zero out what it frees so a
reentrant call won't find previously freed elements.

Link: http://lkml.kernel.org/r/f29d03b00bce3aac8cf151a8a30e6c83e5fee66d.1461610073.git.tom.zanussi@linux.intel.com

Signed-off-by: Tom Zanussi &lt;tom.zanussi@linux.intel.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: checking for NULL instead of IS_ERR()</title>
<updated>2016-04-26T13:40:20Z</updated>
<author>
<name>Dan Carpenter</name>
<email>dan.carpenter@oracle.com</email>
</author>
<published>2016-04-23T10:23:47Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=4812952f9c94f67b3cc78ad0a6482bf182aa5a44'/>
<id>urn:sha1:4812952f9c94f67b3cc78ad0a6482bf182aa5a44</id>
<content type='text'>
tracing_map_elt_alloc() returns ERR_PTRs on error, never NULL.

Fixes: 08d43a5fa063 ('tracing: Add lock-free tracing_map')
Link: http://lkml.kernel.org/r/20160423102347.GA11136@mwanda

Acked-by: Tom Zanussi &lt;tom.zanussi@linux.intel.com&gt;
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Update some tracing_map constants and comments</title>
<updated>2016-04-19T16:16:06Z</updated>
<author>
<name>Tom Zanussi</name>
<email>tom.zanussi@linux.intel.com</email>
</author>
<published>2016-03-03T18:54:41Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=3b772b96b8338bca2532839b2cd7802800e66037'/>
<id>urn:sha1:3b772b96b8338bca2532839b2cd7802800e66037</id>
<content type='text'>
Make it clear exactly how many keys and values are supported through
better defines, and add 1 to the vals count, since normally clients
want support for at least a hitcount and two other values.

Also, note the error return value for tracing_map_add_key/val_field()
in the comments.

Link: http://lkml.kernel.org/r/6696fa02ebc716aa344c27a571a2afaa25e5b4d4.1457029949.git.tom.zanussi@linux.intel.com

Signed-off-by: Tom Zanussi &lt;tom.zanussi@linux.intel.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing: Add lock-free tracing_map</title>
<updated>2016-04-19T16:04:59Z</updated>
<author>
<name>Tom Zanussi</name>
<email>tom.zanussi@linux.intel.com</email>
</author>
<published>2015-12-10T18:50:50Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=08d43a5fa063e03c860f2f391a30c388bcbc948e'/>
<id>urn:sha1:08d43a5fa063e03c860f2f391a30c388bcbc948e</id>
<content type='text'>
Add tracing_map, a special-purpose lock-free map for tracing.

tracing_map is designed to aggregate or 'sum' one or more values
associated with a specific object of type tracing_map_elt, which
is associated by the map to a given key.

It provides various hooks allowing per-tracer customization and is
separated out into a separate file in order to allow it to be shared
between multiple tracers, but isn't meant to be generally used outside
of that context.

The tracing_map implementation was inspired by lock-free map
algorithms originated by Dr. Cliff Click:

 http://www.azulsystems.com/blog/cliff/2007-03-26-non-blocking-hashtable
 http://www.azulsystems.com/events/javaone_2007/2007_LockFreeHash.pdf

Link: http://lkml.kernel.org/r/b43d68d1add33582a396f553c8ef705a33a6a748.1449767187.git.tom.zanussi@linux.intel.com

Signed-off-by: Tom Zanussi &lt;tom.zanussi@linux.intel.com&gt;
Tested-by: Masami Hiramatsu &lt;masami.hiramatsu.pt@hitachi.com&gt;
Reviewed-by: Namhyung Kim &lt;namhyung@kernel.org&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
</feed>
