Page MenuHomeFreeBSD

hwpmc: fix false runcount assertion in user callchain capture
ClosedPublic

Authored by afscoelho_gmail.com on Jul 31 2026, 2:21 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Aug 30, 6:13 PM
Unknown Object (File)
Sun, Aug 30, 6:10 PM
Unknown Object (File)
Sat, Aug 29, 5:01 PM
Unknown Object (File)
Fri, Aug 28, 9:06 PM
Unknown Object (File)
Fri, Aug 28, 9:02 PM
Unknown Object (File)
Fri, Aug 28, 12:36 PM
Unknown Object (File)
Thu, Aug 27, 4:49 PM
Unknown Object (File)
Thu, Aug 27, 12:07 PM
Subscribers

Details

Summary

pmc_capture_user_callchain() checks a PMC's runcount before walking
the user stack, but reads it without holding the spinlock that
protects it. hardclock() can run on the same CPU during the capture
and drop the runcount to zero in between, tripping the assertion and
panicking INVARIANTS kernels under load.

Move the check inside the existing spinlock, right where the code
already confirms the sample is still valid. No functional change on
kernels built without INVARIANTS.

Signed-off-by: Andre Silva <andasilv@amd.com>
Sponsored by: AMD

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 75313
Build 72196: arc lint + arc unit

Event Timeline

spinlock_enter() is weird, and a somewhat confusing name. I believe it is the disabling of interrupts that really prevents hardclock() from interfering. It is somewhat misleading to say that pm->pm_runcount is "protected" by a spinlock.

Regardless, code change LGTM.

This revision is now accepted and ready to land.Wed, Aug 5, 4:58 PM