Skip to content

Commit 799af9a

Browse files
sean-jcgregkh
authored andcommitted
perf/x86/intel: Ensure LBRs are disabled when a CPU is starting
commit c631a2d upstream. 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/c9d8269bff69f6359731d758e3b1135dedd7cc61.camel@redhat.com Reported-by: Maxim Levitsky <mlevitsk@redhat.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20250131010721.470503-1-seanjc@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8443372 commit 799af9a

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

50255025
init_debug_store_on_cpu(cpu);
50265026
/*
5027-
* Deal with CPUs that don't clear their LBRs on power-up.
5027+
* Deal with CPUs that don't clear their LBRs on power-up, and that may
5028+
* even boot with LBRs enabled.
50285029
*/
5030+
if (!static_cpu_has(X86_FEATURE_ARCH_LBR) && x86_pmu.lbr_nr)
5031+
msr_clear_bit(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR_BIT);
50295032
intel_pmu_lbr_reset();
50305033

50315034
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)