opnsense-src/sys/dev/hwpmc
Jessica Clarke 5272c66a00 hwpmc: Fix amd/arm64/armv7/uncore sampling overflow race
If a counter more than overflows just as we read it on switch out then,
if using sampling mode, we will negate this small value to give a huge
reload count, and if we later switch back in that context we will
validate that value against pm_reloadcount and panic an INVARIANTS
kernel with:

  panic: [pmc,1470] pmcval outside of expected range cpu=2 ri=16 pmcval=fffff292 pm_reloadcount=10000

or similar. Presumably in a non-INVARIANTS kernel we will instead just
use the provided value as the reload count, which would lead to the
overflow not happing for a very long time (e.g. 78 minutes for a 48-bit
counter incrementing at an averate rate of 1GHz).

Instead, clamp the reload count to 0 (which corresponds precisely to the
value we would compute if it had just overflowed and no more), which
will result in hwpmc using the full original reload count again. This is
the approach used by core for Intel (for both fixed and programmable
counters).

As part of this, armv7 and arm64 are made conceptually simpler; rather
than skipping modifying the overflow count for sampling mode counters so
it's always kept as ~0, those special cases are removed so it's always
applicable and the concatentation of it and the hardware counter can
always be viewed as a 64-bit counter, which also makes them look more
like other architectures.

Whilst here, fix an instance of UB (shifting a 1 into the sign bit) for
amd in its sign-extension code.

Reviewed by:	andrew, mhorne, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33654

(cherry picked from commit e74c7ffcb1)
2022-01-25 00:00:01 +00:00
..
hwpmc_amd.c hwpmc: Fix amd/arm64/armv7/uncore sampling overflow race 2022-01-25 00:00:01 +00:00
hwpmc_amd.h hwpmc : fix AMD perf counter MSR access 2019-11-07 19:54:24 +00:00
hwpmc_arm.c hwpmc: remove dangling references to hwpmc_xscale 2018-06-08 20:39:49 +00:00
hwpmc_arm64.c hwpmc: Fix amd/arm64/armv7/uncore sampling overflow race 2022-01-25 00:00:01 +00:00
hwpmc_arm64.h arm64: Fix finding the pmc event ID 2021-07-29 12:00:37 -03:00
hwpmc_arm64_md.c Add Performance Monitoring Counters support for AArch64. 2015-05-19 15:25:47 +00:00
hwpmc_armv7.c hwpmc: Fix amd/arm64/armv7/uncore sampling overflow race 2022-01-25 00:00:01 +00:00
hwpmc_armv7.h o Rework ARMv7 events list using aliases - same way as we have for arm64. 2015-06-10 12:42:30 +00:00
hwpmc_beri.c Add support for BERI statcounters. 2019-09-18 16:13:50 +00:00
hwpmc_beri.h Add support for BERI statcounters. 2019-09-18 16:13:50 +00:00
hwpmc_core.c hwpmc: Add IDs for Intel Comet/Ice/Tiger/Rocketlake CPUs. 2021-12-25 19:47:16 -05:00
hwpmc_core.h hwpmc: ABI fixes 2018-06-04 02:05:48 +00:00
hwpmc_e500.c [PowerPC] hwpmc: add support for POWER8/9 PMCs 2020-11-05 16:36:39 +00:00
hwpmc_intel.c hwpmc: Add IDs for Intel Comet/Ice/Tiger/Rocketlake CPUs. 2021-12-25 19:47:16 -05:00
hwpmc_logging.c Update a sysctl name to nbuffers_pcpu in hwpmc.4 and pmcstat.c 2021-09-25 10:34:38 +02:00
hwpmc_mips.c hwpmc: update files missed by r334827 2018-06-08 17:41:49 +00:00
hwpmc_mips24k.c sys/dev: further adoption of SPDX licensing ID tags. 2017-11-27 14:52:40 +00:00
hwpmc_mips74k.c sys: use our nitems() macro when param.h is available. 2016-04-21 19:40:10 +00:00
hwpmc_mod.c hwpmc: Remove CTLFLAG_NEEDGIANT from sysctl. 2022-01-08 20:23:58 -05:00
hwpmc_mpc7xxx.c [PowerPC] hwpmc: add support for POWER8/9 PMCs 2020-11-05 16:36:39 +00:00
hwpmc_octeon.c sys/dev: further adoption of SPDX licensing ID tags. 2017-11-27 14:52:40 +00:00
hwpmc_power8.c [PowerPC] hwpmc: add support for POWER8/9 PMCs 2020-11-05 16:36:39 +00:00
hwpmc_powerpc.c [PowerPC] hwpmc: add support for POWER8/9 PMCs 2020-11-05 16:36:39 +00:00
hwpmc_powerpc.h [PowerPC] hwpmc: add support for POWER8/9 PMCs 2020-11-05 16:36:39 +00:00
hwpmc_ppc970.c [PowerPC] hwpmc: add support for POWER8/9 PMCs 2020-11-05 16:36:39 +00:00
hwpmc_riscv.h Welcome the RISC-V 64-bit kernel. 2016-01-29 15:12:31 +00:00
hwpmc_soft.c hwpmc: mostly clean up cc --analyze 2021-07-25 07:00:05 +00:00
hwpmc_soft.h sys/dev: further adoption of SPDX licensing ID tags. 2017-11-27 14:52:40 +00:00
hwpmc_tsc.c hwpmc: mostly clean up cc --analyze 2021-07-25 07:00:05 +00:00
hwpmc_tsc.h sys/dev: further adoption of SPDX licensing ID tags. 2017-11-27 14:52:40 +00:00
hwpmc_uncore.c hwpmc: Fix amd/arm64/armv7/uncore sampling overflow race 2022-01-25 00:00:01 +00:00
hwpmc_uncore.h hwpmc: remove unused pre-table driven bits for intel 2018-05-31 22:41:07 +00:00
hwpmc_x86.c hwpmc: Disable KASAN in pmc_save_kernel_callchain() 2021-11-01 10:06:47 -04:00
pmc_events.h libpmc: fix the 'cycles' event alias on x86 2021-10-15 12:21:35 -03:00