<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/tools/tracing/rtla/src/trace.c, branch v7.1-rc5</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v7.1-rc5</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v7.1-rc5'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2026-03-11T14:29:50+00:00</updated>
<entry>
<title>rtla/trace: Fix I/O handling in save_trace_to_file()</title>
<updated>2026-03-11T14:29:50+00:00</updated>
<author>
<name>Wander Lairson Costa</name>
<email>wander@redhat.com</email>
</author>
<published>2026-03-09T19:46:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=47dd74f68c0c068fdd29cdf9fe1860a19209bc1f'/>
<id>urn:sha1:47dd74f68c0c068fdd29cdf9fe1860a19209bc1f</id>
<content type='text'>
The read/write loop in save_trace_to_file() does not correctly handle
errors from the read() and write() system calls. If either call is
interrupted by a signal, it returns -1 with errno set to EINTR, but
the code treats this as a fatal error and aborts the save operation.
Additionally, write() may perform a partial write, returning fewer
bytes than requested, which the code does not handle.

Fix the I/O loop by introducing proper error handling. The return
value of read() is now stored in a ssize_t variable and checked for
errors, with EINTR causing a retry. For write(), an inner loop ensures
all bytes are written, handling both EINTR and partial writes. Error
messages now include strerror() output for better debugging.

This follows the same pattern established in the previous commit that
fixed trace_event_save_hist(), ensuring consistent and robust I/O
handling throughout the trace saving code.

Signed-off-by: Wander Lairson Costa &lt;wander@redhat.com&gt;
Link: https://lore.kernel.org/r/20260309195040.1019085-17-wander@redhat.com
Signed-off-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
</content>
</entry>
<entry>
<title>rtla/trace: Fix write loop in trace_event_save_hist()</title>
<updated>2026-03-11T14:29:50+00:00</updated>
<author>
<name>Wander Lairson Costa</name>
<email>wander@redhat.com</email>
</author>
<published>2026-03-09T19:46:28+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=4bf4ef5292b9253d8607c61a875d9f6b14129976'/>
<id>urn:sha1:4bf4ef5292b9253d8607c61a875d9f6b14129976</id>
<content type='text'>
The write loop in trace_event_save_hist() does not correctly handle
errors from the write() system call. If write() returns -1, this value
is added to the loop index, leading to an incorrect memory access on
the next iteration and potentially an infinite loop. The loop also
fails to handle EINTR.

Fix the write loop by introducing proper error handling. The return
value of write() is now stored in a ssize_t variable and checked for
errors. The loop retries the call if interrupted by a signal and breaks
on any other error after logging it with strerror().

Additionally, change the index variable type from int to size_t to
match the type used for buffer sizes and by strlen(), improving type
safety.

Fixes: 761916fd02c2 ("rtla/trace: Save event histogram output to a file")
Signed-off-by: Wander Lairson Costa &lt;wander@redhat.com&gt;
Link: https://lore.kernel.org/r/20260309195040.1019085-16-wander@redhat.com
Signed-off-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
</content>
</entry>
<entry>
<title>rtla: Use str_has_prefix() for prefix checks</title>
<updated>2026-03-11T14:29:50+00:00</updated>
<author>
<name>Wander Lairson Costa</name>
<email>wander@redhat.com</email>
</author>
<published>2026-03-09T19:46:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=265905df83a4c1e78c1a912e1699d7c81d9540e6'/>
<id>urn:sha1:265905df83a4c1e78c1a912e1699d7c81d9540e6</id>
<content type='text'>
The code currently uses strncmp() combined with strlen() to check if a
string starts with a specific prefix. This pattern is verbose and prone
to errors if the length does not match the prefix string.

Replace this pattern with the str_has_prefix() helper function in both
trace.c and utils.c. This improves code readability and safety by
handling the prefix length calculation automatically.

In addition, remove the unused retval variable from
trace_event_save_hist() in trace.c to clean up the function and
silence potential compiler warnings.

Signed-off-by: Wander Lairson Costa &lt;wander@redhat.com&gt;
Link: https://lore.kernel.org/r/20260309195040.1019085-12-wander@redhat.com
Signed-off-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
</content>
</entry>
<entry>
<title>rtla: Simplify code by caching string lengths</title>
<updated>2026-03-10T09:32:37+00:00</updated>
<author>
<name>Wander Lairson Costa</name>
<email>wander@redhat.com</email>
</author>
<published>2026-03-09T19:46:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f79720e25b793691dcc46e1f1cd64d01578075c2'/>
<id>urn:sha1:f79720e25b793691dcc46e1f1cd64d01578075c2</id>
<content type='text'>
Simplify trace_event_save_hist() and set_comm_cgroup() by computing
string lengths once and storing them in local variables, rather than
calling strlen() multiple times on the same unchanged strings. This
makes the code clearer by eliminating redundant function calls and
improving readability.

In trace_event_save_hist(), the write loop previously called strlen()
on the hist buffer twice per iteration for both the size calculation
and loop condition. Store the length in hist_len before entering the
loop. In set_comm_cgroup(), strlen() was called on cgroup_path up to
three times in succession. Store the result in cg_path_len to use in
both the offset calculation and size parameter for subsequent append
operations.

This simplification makes the code easier to read and maintain without
changing program behavior.

Signed-off-by: Wander Lairson Costa &lt;wander@redhat.com&gt;
Link: https://lore.kernel.org/r/20260309195040.1019085-7-wander@redhat.com
Signed-off-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
</content>
</entry>
<entry>
<title>rtla: Replace magic number with MAX_PATH</title>
<updated>2026-03-10T09:32:37+00:00</updated>
<author>
<name>Wander Lairson Costa</name>
<email>wander@redhat.com</email>
</author>
<published>2026-03-09T19:46:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a29430c2bc86b00e62f74299b866216390c7e418'/>
<id>urn:sha1:a29430c2bc86b00e62f74299b866216390c7e418</id>
<content type='text'>
The trace functions use a buffer to manipulate strings that will be
written to tracefs files. These buffers are defined with a magic number
of 1024, which is a common source of vulnerabilities.

Replace the magic number 1024 with the MAX_PATH macro to make the code
safer and more readable. While at it, replace other instances of the
magic number with ARRAY_SIZE() when the buffer is locally defined.

Signed-off-by: Wander Lairson Costa &lt;wander@redhat.com&gt;
Link: https://lore.kernel.org/r/20260309195040.1019085-6-wander@redhat.com
Signed-off-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
</content>
</entry>
<entry>
<title>rtla: Exit on memory allocation failures during initialization</title>
<updated>2026-03-10T09:32:37+00:00</updated>
<author>
<name>Wander Lairson Costa</name>
<email>wander@redhat.com</email>
</author>
<published>2026-03-09T19:46:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=009a8e681fb003f38dd57a640e11ed826740b5c1'/>
<id>urn:sha1:009a8e681fb003f38dd57a640e11ed826740b5c1</id>
<content type='text'>
Most memory allocations in rtla happen during early initialization
before any resources are acquired that would require cleanup. In these
cases, propagating allocation errors just adds complexity without any
benefit. There's nothing to clean up, and the program must exit anyway.

This patch introduces fatal allocation wrappers (calloc_fatal,
reallocarray_fatal, strdup_fatal) that call fatal() on allocation
failure. These wrappers simplify the code by eliminating unnecessary
error propagation paths.

The patch converts early allocations to use these wrappers in
actions_init() and related action functions, osnoise_context_alloc()
and osnoise_init_tool(), trace_instance_init() and trace event
functions, and parameter structure allocations in main functions.

This simplifies the code while maintaining the same behavior: immediate
exit on allocation failure during initialization. Allocations that
require cleanup, such as those in histogram allocation functions with
goto cleanup paths, are left unchanged and continue to return errors.

Signed-off-by: Wander Lairson Costa &lt;wander@redhat.com&gt;
Link: https://lore.kernel.org/r/20260309195040.1019085-2-wander@redhat.com
Signed-off-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
</content>
</entry>
<entry>
<title>rtla: Remove unused headers</title>
<updated>2026-01-07T14:57:55+00:00</updated>
<author>
<name>Wander Lairson Costa</name>
<email>wander@redhat.com</email>
</author>
<published>2026-01-06T11:49:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f3cc3e4b5116929ebff27c3b0a565b34ae4969b3'/>
<id>urn:sha1:f3cc3e4b5116929ebff27c3b0a565b34ae4969b3</id>
<content type='text'>
Remove unused includes for &lt;errno.h&gt; and &lt;signal.h&gt; to clean up the
code and reduce unnecessary dependencies.

Signed-off-by: Wander Lairson Costa &lt;wander@redhat.com&gt;
Link: https://lore.kernel.org/r/20260106133655.249887-12-wander@redhat.com
Signed-off-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
</content>
</entry>
<entry>
<title>rtla: Fix segfault in save_trace_to_file call</title>
<updated>2025-03-26T14:35:20+00:00</updated>
<author>
<name>Tomas Glozar</name>
<email>tglozar@redhat.com</email>
</author>
<published>2025-03-13T14:10:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c57c58a62e564c615520839742b28d315427a280'/>
<id>urn:sha1:c57c58a62e564c615520839742b28d315427a280</id>
<content type='text'>
Running rtla with exit on threshold, but without saving trace leads to a
segmenetation fault:

$ rtla timerlat hist -T 10
...
Max timerlat IRQ latency from idle: 4.29 us in cpu 0
Segmentation fault

This is caused by null pointer deference in the call of
save_trace_to_file, which attempts to dereference an uninitialized
osnoise_tool variable:

save_trace_to_file(record-&gt;trace.inst, params-&gt;trace_output);
                   ^ this is uninitialized if params-&gt;trace_output is
                     not set

Fix this by not attempting to dereference "record" if it is NULL and
passing NULL instead. As a safety measure, the first field is also
checked for NULL inside save_trace_to_file.

Cc: John Kacur &lt;jkacur@redhat.com&gt;
Cc: Luis Goncalves &lt;lgoncalv@redhat.com&gt;
Cc: Costa Shulyupin &lt;costa.shul@redhat.com&gt;
Link: https://lore.kernel.org/20250313141034.299117-1-tglozar@redhat.com
Fixes: dc4d4e7c72d1 ("rtla: Refactor save_trace_to_file")
Signed-off-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>rtla: Refactor save_trace_to_file</title>
<updated>2025-03-04T19:17:19+00:00</updated>
<author>
<name>Costa Shulyupin</name>
<email>costa.shul@redhat.com</email>
</author>
<published>2025-02-19T11:51:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=dc4d4e7c72d17e6f6bdd9ce0d7a72a085828987f'/>
<id>urn:sha1:dc4d4e7c72d17e6f6bdd9ce0d7a72a085828987f</id>
<content type='text'>
The functions osnoise_hist_main(), osnoise_top_main(),
timerlat_hist_main(), and timerlat_top_main() are lengthy and contain
duplicated code.

Refactor by consolidating the duplicate lines into the
save_trace_to_file() function.

Cc: Daniel Bristot de Oliveira &lt;bristot@kernel.org&gt;
Cc: John Kacur &lt;jkacur@redhat.com&gt;
Cc: "Luis Claudio R. Goncalves" &lt;lgoncalv@redhat.com&gt;
Cc: Eder Zulian &lt;ezulian@redhat.com&gt;
Cc: Dan Carpenter &lt;dan.carpenter@linaro.org&gt;
Cc: Gabriele Monaco &lt;gmonaco@redhat.com&gt;
Link: https://lore.kernel.org/20250219115138.406075-1-costa.shul@redhat.com
Signed-off-by: Costa Shulyupin &lt;costa.shul@redhat.com&gt;
Reviewed-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
Tested-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>rtla: Count all processed events</title>
<updated>2025-01-24T18:46:24+00:00</updated>
<author>
<name>Tomas Glozar</name>
<email>tglozar@redhat.com</email>
</author>
<published>2025-01-23T14:23:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2aee44f721a75daebc55c372271221286efd79ec'/>
<id>urn:sha1:2aee44f721a75daebc55c372271221286efd79ec</id>
<content type='text'>
Add a field processed_events to struct trace_instance and increment it
in collect_registered_events, regardless of whether a handler is
registered for the event.

The purpose is to calculate the percentage of events that were missed
due to tracefs buffer overflow.

Cc: John Kacur &lt;jkacur@redhat.com&gt;
Cc: Luis Goncalves &lt;lgoncalv@redhat.com&gt;
Cc: Gabriele Monaco &lt;gmonaco@redhat.com&gt;
Link: https://lore.kernel.org/20250123142339.990300-3-tglozar@redhat.com
Signed-off-by: Tomas Glozar &lt;tglozar@redhat.com&gt;
Signed-off-by: Steven Rostedt (Google) &lt;rostedt@goodmis.org&gt;
</content>
</entry>
</feed>
