Skip to content

Commit 2c803a1

Browse files
Maxim Levitskybonzini
authored andcommitted
perf/x86/intel: Ensure LBRs are disabled when a CPU is starting
JIRA: https://issues.redhat.com/browse/RHEL-95318 commit c631a2d Author: Sean Christopherson <[email protected]> Date: Thu Jan 30 17:07:21 2025 -0800 perf/x86/intel: Ensure LBRs are disabled when a CPU is starting Explicitly clear DEBUGCTL.LBR when a CPU is starting, prior to purging the LBR MSRs themselves, as at least one system has been found to transfer control to the kernel with LBRs enabled (it's unclear whether it's a BIOS flaw or a CPU goof). Because the kernel preserves the original DEBUGCTL, even when toggling LBRs, leaving DEBUGCTL.LBR as is results in running with LBRs enabled at all times. Closes: https://lore.kernel.org/all/[email protected] Reported-by: Maxim Levitsky <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Maxim Levitsky <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Maxim Levitsky <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 12f2478 commit 2c803a1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

arch/x86/events/intel/core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5069,8 +5069,11 @@ static void intel_pmu_cpu_starting(int cpu)
50695069

50705070
init_debug_store_on_cpu(cpu);
50715071
/*
5072-
* Deal with CPUs that don't clear their LBRs on power-up.
5072+
* Deal with CPUs that don't clear their LBRs on power-up, and that may
5073+
* even boot with LBRs enabled.
50735074
*/
5075+
if (!static_cpu_has(X86_FEATURE_ARCH_LBR) && x86_pmu.lbr_nr)
5076+
msr_clear_bit(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR_BIT);
50745077
intel_pmu_lbr_reset();
50755078

50765079
cpuc->lbr_sel = NULL;

arch/x86/include/asm/msr-index.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@
372372
#define MSR_IA32_PASID_VALID BIT_ULL(31)
373373

374374
/* DEBUGCTLMSR bits (others vary by model): */
375-
#define DEBUGCTLMSR_LBR (1UL << 0) /* last branch recording */
375+
#define DEBUGCTLMSR_LBR_BIT 0 /* last branch recording */
376+
#define DEBUGCTLMSR_LBR (1UL << DEBUGCTLMSR_LBR_BIT)
376377
#define DEBUGCTLMSR_BTF_SHIFT 1
377378
#define DEBUGCTLMSR_BTF (1UL << 1) /* single-step on branches */
378379
#define DEBUGCTLMSR_BUS_LOCK_DETECT (1UL << 2)

0 commit comments

Comments
 (0)