HomeFreeBSD

libdtrace: Fix an off-by-one in CPU ID handling

Description

libdtrace: Fix an off-by-one in CPU ID handling

The illumos-specific _SC_CPUID_MAX is the largest CPU ID in the system. This
was mapped to _SC_NPROCESSORS_CONF, which is the total number of CPUs recognized
by the kernel. If CPU IDs are contiguous, as is the case on amd64 and arm64,
this value is one greater than the maximum ID. As a result, when consuming
per-CPU dtrace buffers, libdtrace tries to fetch from a non-existent CPU. This
is mostly harmless in practice, but still wrong.

As we don't have a sysconf value for the maximum CPU ID, add a wrapper which
fetches it using the kern.smp.maxid sysctl.

MFC after: 2 weeks
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D49243

(cherry picked from commit 9a30c8d347bf9aaa89277b6e5a275f737be8edce)

Details

Provenance
markjAuthored on Mar 10 2025, 3:00 AM
Differential Revision
D49243: libdtrace: Fix an off-by-one in CPU ID handling
Parents
rG294cda7e4e33: dtrace/arm64: Fix dtrace_gethrtime()
Branches
Unknown
Tags
Unknown