Linux Trace Kernel
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Tomas Glozar <tglozar@redhat.com>
Cc: John Kacur <jkacur@redhat.com>,
	Luis Goncalves <lgoncalv@redhat.com>,
	Crystal Wood <crwood@redhat.com>,
	Costa Shulyupin <costa.shul@redhat.com>,
	Wander Lairson Costa <wander@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-trace-kernel <linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH 0/5] rtla: Implement more robust nr_cpus handling
Date: Fri, 14 Aug 2026 10:30:45 -0400	[thread overview]
Message-ID: <20260814103045.6efc2514@gandalf.local.home> (raw)
In-Reply-To: <20260814135511.2207190-1-tglozar@redhat.com>

On Fri, 14 Aug 2026 15:55:06 +0200
Tomas Glozar <tglozar@redhat.com> wrote:

> RTLA is an interface to the kernel osnoise and timerlat tracers, and as
> such, operates on all CPUs seen by the kernel, regardless of any applied
> user space CPU isolation. Currently, it uses libc's get_nprocs_conf()
> function to get the total number of valid (configured) CPUs on the
> system.
> 
> The number reported by the function may vary depending on both the
> libc implementation and the environment. This can cause discrepancies,
> including:
> 
> - RTLA crashing because of out-of-bounds access and/or memory
>   corruption, as a result of reading kernel events with cpu >= nr_cpus
>   and using it to index an nr_cpus-length buffer.
> - nr_cpus mismatching the return value of libbpf_num_possible_cpus(),
>   which is used in the per-CPU map size check, leading RTLA to fail to
>   read BPF data.
> 
> To address both issues, this patchset switches RTLA to unconditionally
> use the CPU count exposed through sysfs
> (/sys/devices/system/cpu/possible) - the same interface through which
> the tracers are accessed. As several places in RTLA assume the CPU count
> correlates with the maximum CPU (pre-existing limitation), the new
> mechanism also rejects possible CPU lists with holes or starting with
> non-zero CPU.
> 
> As a safety measure, trace events are further validated and rejected
> if their cpu field is greater or equal to nr_cpus. nr_cpus is
> additionally validated for equality against osnoise's "all" cpu setting.
> This is done to catch environments where sysfs is virtualized and
> reports a different number of CPUs than the kernel.
> 
> Note: As an alternative approach - reading only the osnoise cpu "all"
> setting and using it for nr_cpus - was considered. While it would make
> patch 3 unnecessary and make RTLA compatible with environments with
> virtualized sysfs, it would require separate handling of userspace and
> kernel CPU number, as nr_cpus is also used to guard -H/--housekeeping
> option argument. That does not appear to me to be worth it just to cover
> for a very rare corner case; if such use case appears in the future, RTLA
> can always be fixed.
> 
> Tomas Glozar (5):
>   rtla: Replace get_nprocs_conf() with sysfs possible cpus
>   rtla: Discard trace entries with cpu >= nr_cpus
>   rtla: Abort on nr_cpus mismatch with tracer
>   rtla/tests: Add unit test for cpu_list_iterate()
>   rtla/tests: Add unit test for get_max_cpu_from_list()
> 
>  tools/tracing/rtla/src/common.c        |  29 +++-
>  tools/tracing/rtla/src/common.h        |   3 +-
>  tools/tracing/rtla/src/osnoise.c       |  70 +++++++++-
>  tools/tracing/rtla/src/osnoise.h       |   2 +
>  tools/tracing/rtla/src/osnoise_hist.c  |   1 +
>  tools/tracing/rtla/src/osnoise_top.c   |   1 +
>  tools/tracing/rtla/src/timerlat_hist.c |   1 +
>  tools/tracing/rtla/src/timerlat_top.c  |   1 +
>  tools/tracing/rtla/src/trace.c         |   7 +
>  tools/tracing/rtla/src/trace.h         |   1 +
>  tools/tracing/rtla/src/utils.c         | 181 +++++++++++++++++++++----
>  tools/tracing/rtla/src/utils.h         |   6 +
>  tools/tracing/rtla/tests/unit/utils.c  |  71 ++++++++++
>  13 files changed, 342 insertions(+), 32 deletions(-)
> 

Note, the merge window will likely open next week (Sunday) (and of course,
I'll be traveling). If you want this in the next release, please send a pull
request today. Otherwise it will likely not be able to go into Linus's tree
until 7.4.

-- Steve


      parent reply	other threads:[~2026-08-14 14:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 13:55 [PATCH 0/5] rtla: Implement more robust nr_cpus handling Tomas Glozar
2026-08-14 13:55 ` [PATCH 1/5] rtla: Replace get_nprocs_conf() with sysfs possible cpus Tomas Glozar
2026-08-14 13:55 ` [PATCH 2/5] rtla: Discard trace entries with cpu >= nr_cpus Tomas Glozar
2026-08-14 14:02   ` sashiko-bot
2026-08-14 13:55 ` [PATCH 3/5] rtla: Abort on nr_cpus mismatch with tracer Tomas Glozar
2026-08-14 13:55 ` [PATCH 4/5] rtla/tests: Add unit test for cpu_list_iterate() Tomas Glozar
2026-08-14 13:55 ` [PATCH 5/5] rtla/tests: Add unit test for get_max_cpu_from_list() Tomas Glozar
2026-08-14 14:30 ` Steven Rostedt [this message]

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=20260814103045.6efc2514@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=costa.shul@redhat.com \
    --cc=crwood@redhat.com \
    --cc=jkacur@redhat.com \
    --cc=lgoncalv@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=tglozar@redhat.com \
    --cc=wander@redhat.com \
    /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