Skip to content

Commit b8a8605

Browse files
sean-jcjfvogel
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> (cherry picked from commit 71762f455a81141b5412b25d5edfb71f01e68bcf) Signed-off-by: Jack Vogel <jack.vogel@oracle.com>
1 parent 9dab220 commit b8a8605

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

49944994
init_debug_store_on_cpu(cpu);
49954995
/*
4996-
* Deal with CPUs that don't clear their LBRs on power-up.
4996+
* Deal with CPUs that don't clear their LBRs on power-up, and that may
4997+
* even boot with LBRs enabled.
49974998
*/
4999+
if (!static_cpu_has(X86_FEATURE_ARCH_LBR) && x86_pmu.lbr_nr)
5000+
msr_clear_bit(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR_BIT);
49985001
intel_pmu_lbr_reset();
49995002

50005003
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
@@ -398,7 +398,8 @@
398398
#define MSR_IA32_PASID_VALID BIT_ULL(31)
399399

400400
/* DEBUGCTLMSR bits (others vary by model): */
401-
#define DEBUGCTLMSR_LBR (1UL << 0) /* last branch recording */
401+
#define DEBUGCTLMSR_LBR_BIT 0 /* last branch recording */
402+
#define DEBUGCTLMSR_LBR (1UL << DEBUGCTLMSR_LBR_BIT)
402403
#define DEBUGCTLMSR_BTF_SHIFT 1
403404
#define DEBUGCTLMSR_BTF (1UL << 1) /* single-step on branches */
404405
#define DEBUGCTLMSR_BUS_LOCK_DETECT (1UL << 2)

0 commit comments

Comments
 (0)