Skip to content

perf/x86/intel/pt: Fix tracing across kexec, kdump and suspend

Adrian Hunter driver-core linux-perf-users linux-pm lkml sashiko-reviews 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 22 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6irq_work: Re-raise pending irq_work after system resumedrivers/base/syscore.c include/linux/irq_work.h kernel/irq_work.c+24 -07 replies
2/6perf/x86/intel/pt: Stop tracing if VMXON has not yet happenedarch/x86/events/intel/pt.c+15 -13 replies
3/6perf/x86/intel/pt: Stop tracing at syscore shutdownarch/x86/events/intel/pt.c+43 -37 replies
4/6perf/x86/intel/pt: Clear TraceEn in hardware in cpu_emergency_stop_pt()arch/x86/events/intel/pt.c+9 -02 replies
5/6perf/x86/intel/pt: Reset stale MSR state on CPU start and resumearch/x86/events/intel/core.c arch/x86/events/intel/pt.c arch/x86/events/intel/pt.h +4 more+57 -130 replies
6/6perf/x86/intel/pt: Stop tracing across system suspendarch/x86/events/intel/pt.c+60 -01 reply

Reviews trailers per patch

None of the 6 patches has a Reviewed-by or Acked-by.

PatchJulian Vetter
1/6T-b
2/6
3/6
4/6
5/6
6/6

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/6] perf/x86/intel/pt: Fix tracing across kexec, kdump and suspend

Hi

Intel PT writes trace data directly to physical memory, so tracing must be stopped whenever the trace buffers or the hardware state describing them can no longer be relied on. This series fixes several cases where that does not currently happen:

- tracing can survive kexec and kdump. After kexec, Intel PT continues writing into buffers configured by the old kernel, corrupting memory that the new kernel may have reused

- suspend-related state loss can leave the driver's cached PT MSR state out of sync with hardware, allowing tracing to restart with reset output registers and corrupt memory (typically beginning at page 0)

- races can leave TraceEn set in hardware after perf believes tracing has stopped, preventing tracing from being reliably disabled and potentially causing subsequent PT MSR accesses to #GP

The fixes stop relying solely on perf's software state where it is not
authoritative: TraceEn is cleared directly in hardware during shutdown and emergency-stop paths, tracing is prevented from restarting once shutdown begins, cached PT MSR state is invalidated whenever hardware state may have been lost, and active tracing is stopped and restarted across suspend on the CPU that remains online.

The first patch is a general irq_work fix, not specific to Intel PT. It re-raises a lost irq_work self-interrupt after resume, preventing irq_work from remaining permanently pending if the interrupt state is lost across suspend. The final Intel PT suspend fix depends on it.

All patches are marked for stable. The last patch also depends on commit 2e17bf3a469a ("perf/x86/intel/pt: Fix stop/start with no update") and its two preparatory patches.

An alternative to the last patch would be for perf core to schedule out all active events from a syscore suspend callback, and schedule them back in from the syscore resume callback. That would be a more general change, but the last patch keeps the fix within the Intel PT driver.

AI disclosure: all issues addressed by this series were identified using AI assistance, and AI was also used in development of the patches. Problems described with reproducer examples in the individual changelogs were reproduced and fixes validated. The race fixed by "perf/x86/intel/pt: Clear TraceEn in hardware in cpu_emergency_stop_pt()" was identified by analysis and has not been reproduced.

Adrian Hunter (6):
irq_work: Re-raise pending irq_work after system resume perf/x86/intel/pt: Stop tracing if VMXON has not yet happened perf/x86/intel/pt: Stop tracing at syscore shutdown perf/x86/intel/pt: Clear TraceEn in hardware in cpu_emergency_stop_pt() perf/x86/intel/pt: Reset stale MSR state on CPU start and resume perf/x86/intel/pt: Stop tracing across system suspend

 arch/x86/events/intel/core.c      |   9 ++
 arch/x86/events/intel/pt.c        | 170 ++++++++++++++++++++++++++++++++++++--
 arch/x86/events/intel/pt.h        |   6 +-
 arch/x86/events/perf_event.h      |   4 +
 arch/x86/include/asm/perf_event.h |   3 +
 arch/x86/power/cpu.c              |   3 +-
 drivers/base/syscore.c            |  10 +++
 include/linux/irq_work.h          |   2 +
 include/linux/perf_event.h        |   6 --
 kernel/irq_work.c                 |  12 +++
 10 files changed, 208 insertions(+), 17 deletions(-)

base-commit: f96ebf32b3135db4c9eeb868e4cb98e5dfe79ac0

Regards
Adrian