Skip to content

Commit c631a2d

Browse files
sean-jcPeter Zijlstra
authored andcommitted
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]
1 parent 47a973f commit c631a2d

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
@@ -5042,8 +5042,11 @@ static void intel_pmu_cpu_starting(int cpu)
50425042

50435043
init_debug_store_on_cpu(cpu);
50445044
/*
5045-
* Deal with CPUs that don't clear their LBRs on power-up.
5045+
* Deal with CPUs that don't clear their LBRs on power-up, and that may
5046+
* even boot with LBRs enabled.
50465047
*/
5048+
if (!static_cpu_has(X86_FEATURE_ARCH_LBR) && x86_pmu.lbr_nr)
5049+
msr_clear_bit(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR_BIT);
50475050
intel_pmu_lbr_reset();
50485051

50495052
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
@@ -395,7 +395,8 @@
395395
#define MSR_IA32_PASID_VALID BIT_ULL(31)
396396

397397
/* DEBUGCTLMSR bits (others vary by model): */
398-
#define DEBUGCTLMSR_LBR (1UL << 0) /* last branch recording */
398+
#define DEBUGCTLMSR_LBR_BIT 0 /* last branch recording */
399+
#define DEBUGCTLMSR_LBR (1UL << DEBUGCTLMSR_LBR_BIT)
399400
#define DEBUGCTLMSR_BTF_SHIFT 1
400401
#define DEBUGCTLMSR_BTF (1UL << 1) /* single-step on branches */
401402
#define DEBUGCTLMSR_BUS_LOCK_DETECT (1UL << 2)

0 commit comments

Comments
 (0)