From: Michael Petlan <mpetlan@redhat.com>
To: linux-perf-users@vger.kernel.org, irogers@google.com,
acme@redhat.com, namhyung@kernel.org
Subject: [PATCH] perf trace: Fix potential u64 underflow in duration calculation
Date: Tue, 31 Mar 2026 12:10:20 +0200 [thread overview]
Message-ID: <20260331101020.1270363-1-mpetlan@redhat.com> (raw)
Although it happens very rarely, in case of out-of-order events (i.e.
due to CPU migration when a syscall is executed), the calculation of
event duration might underflow and thus a bogus value is printed:
2.804 ( 0.001 ms): :49553/49553 rt_sigaction(sig: QUIT, act: 0x7fff403ed6e0, oact: 0x7fff403ed780, sigsetsize: 8) = 0
2.807 ( 0.001 ms): :49553/49553 rt_sigaction(sig: CHLD, act: 0x7fff403ed6e0, oact: 0x7fff403ed780, sigsetsize: 8) = 0
2.815 (18446744073709.438 ms): :49553/49553 execve(filename: 0xbb173a30, argv: 0x55aabb171930, envp: 0x55aabb171120) = 0
2.815 ( 0.534 ms): pwd/49553 ... [continued]: execve()) = 0
Check for possible underflow first and in case of a bogus value, do
not print it.
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
tools/perf/builtin-trace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index f487fbaa0ad6..c9de6bb9b0ea 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2956,7 +2956,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel,
++trace->stats.vfs_getname;
}
- if (ttrace->entry_time) {
+ if (ttrace->entry_time && sample->time > ttrace->entry_time) {
duration = sample->time - ttrace->entry_time;
if (trace__filter_duration(trace, duration))
goto out;
--
2.47.3
next reply other threads:[~2026-03-31 10:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 10:10 Michael Petlan [this message]
2026-03-31 17:15 ` [PATCH] perf trace: Fix potential u64 underflow in duration calculation Ian Rogers
2026-04-02 14:31 ` Michael Petlan
2026-04-02 14:51 ` [PATCH v2] " Michael Petlan
2026-04-02 15:09 ` Ian Rogers
2026-04-03 1:40 ` Namhyung Kim
2026-04-04 0:15 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260331101020.1270363-1-mpetlan@redhat.com \
--to=mpetlan@redhat.com \
--cc=acme@redhat.com \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox