The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Maxim Levitsky <mlevitsk@redhat.com>
Subject: Re: [PATCH] perf/x86/intel: Ensure LBRs are disabled when a CPU is starting
Date: Mon, 3 Feb 2025 12:43:10 +0100	[thread overview]
Message-ID: <20250203114310.GF505@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20250131010721.470503-1-seanjc@google.com>

On Thu, Jan 30, 2025 at 05:07:21PM -0800, Sean Christopherson wrote:
> 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.
> 
> Reported-by: Maxim Levitsky <mlevitsk@redhat.com>
> Closes: https://lore.kernel.org/all/c9d8269bff69f6359731d758e3b1135dedd7cc61.camel@redhat.com
> Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>  arch/x86/events/intel/core.c     | 5 ++++-
>  arch/x86/include/asm/msr-index.h | 3 ++-
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index e76e892f44cd..efd069bc9c28 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -5038,8 +5038,11 @@ static void intel_pmu_cpu_starting(int cpu)
>  
>  	init_debug_store_on_cpu(cpu);
>  	/*
> -	 * Deal with CPUs that don't clear their LBRs on power-up.
> +	 * Deal with CPUs that don't clear their LBRs on power-up, and that may
> +	 * even boot with LBRs enabled.
>  	 */
> +	if (!static_cpu_has(X86_FEATURE_ARCH_LBR) && x86_pmu.lbr_nr)
> +		msr_clear_bit(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR_BIT);
>  	intel_pmu_lbr_reset();

Gotta love this stuff.

Thanks!

  reply	other threads:[~2025-02-03 11:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-31  1:07 [PATCH] perf/x86/intel: Ensure LBRs are disabled when a CPU is starting Sean Christopherson
2025-02-03 11:43 ` Peter Zijlstra [this message]
2025-02-11 15:05 ` [tip: perf/urgent] " tip-bot2 for Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250203114310.GF505@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mlevitsk@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox