From: Mingwei Zhang <mizhang@google.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, Jim Mattson <jmattson@google.com>
Subject: Re: [PATCH 3/3] KVM: VMX: Disable LBR virtualization if the CPU doesn't support LBR callstacks
Date: Mon, 18 Mar 2024 22:51:03 +0000 [thread overview]
Message-ID: <ZfjFV0W6-OCgugJl@google.com> (raw)
In-Reply-To: <20240307011344.835640-4-seanjc@google.com>
On Wed, Mar 06, 2024, Sean Christopherson wrote:
> Disable LBR virtualization if the CPU doesn't support callstacks, which
> were introduced in HSW (see commit e9d7f7cd97c4 ("perf/x86/intel: Add
> basic Haswell LBR call stack support"), as KVM unconditionally configures
> the perf LBR event with PERF_SAMPLE_BRANCH_CALL_STACK, i.e. LBR
> virtualization always fails on pre-HSW CPUs.
>
> Simply disable LBR support on such CPUs, as it has never worked, i.e.
> there is no risk of breaking an existing setup, and figuring out a way
> to performantly context switch LBRs on old CPUs is not worth the effort.
>
> Fixes: be635e34c284 ("KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES")
> Cc: Mingwei Zhang <mizhang@google.com>
> Cc: Jim Mattson <jmattson@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Tested-by: Mingwei Zhang <mizhang@google.com>
> ---
> arch/x86/kvm/vmx/vmx.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 2a7cd66988a5..25a7652bee7c 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -7859,7 +7859,15 @@ static __init u64 vmx_get_perf_capabilities(void)
>
> if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR)) {
> x86_perf_get_lbr(&vmx_lbr_caps);
> - if (vmx_lbr_caps.nr)
> +
> + /*
> + * KVM requires LBR callstack support, as the overhead due to
> + * context switching LBRs without said support is too high.
> + * See intel_pmu_create_guest_lbr_event() for more info.
> + */
> + if (!vmx_lbr_caps.has_callstack)
> + memset(&vmx_lbr_caps, 0, sizeof(vmx_lbr_caps));
> + else if (vmx_lbr_caps.nr)
> perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
> }
>
> --
> 2.44.0.278.ge034bb2e1d-goog
>
next prev parent reply other threads:[~2024-03-18 22:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 1:13 [PATCH 0/3] KVM: VMX: Disable LBRs if CPU doesn't have callstacks Sean Christopherson
2024-03-07 1:13 ` [PATCH 1/3] KVM: VMX: Snapshot LBR capabilities during module initialization Sean Christopherson
2024-03-18 22:50 ` Mingwei Zhang
2024-03-07 1:13 ` [PATCH 2/3] perf/x86/intel: Expose existence of callback support to KVM Sean Christopherson
2024-03-18 22:50 ` Mingwei Zhang
2024-03-07 1:13 ` [PATCH 3/3] KVM: VMX: Disable LBR virtualization if the CPU doesn't support LBR callstacks Sean Christopherson
2024-03-18 22:51 ` Mingwei Zhang [this message]
2024-04-09 2:01 ` [PATCH 0/3] KVM: VMX: Disable LBRs if CPU doesn't have callstacks 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=ZfjFV0W6-OCgugJl@google.com \
--to=mizhang@google.com \
--cc=acme@kernel.org \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
/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;
as well as URLs for NNTP newsgroup(s).