From: sashiko-bot@kernel.org
To: "Shivansh Dhiman" <shivansh.dhiman@amd.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 6/7] KVM: SVM: Add LBR/PMC freeze support
Date: Fri, 24 Jul 2026 20:13:43 +0000 [thread overview]
Message-ID: <20260724201344.3816C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724195040.630468-7-shivansh.dhiman@amd.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] KVM incorrectly advertises AMD_LBR_PMC_FREEZE to the guest even when prerequisite features (mediated PMU or LBR virtualization) are disabled, leading to broken PMU state.
- [High] An L1 hypervisor can bypass CPUID capability checks and enable LBR/PMC freeze bits for L2 by injecting them via VMCB12's DEBUGCTL.
--
--- Patch [6]: [PATCH 6/7] KVM: SVM: Add LBR/PMC freeze support ---
commit 8a4ef61c23eb3f96d674c17183bad9ad198a18dd
Author: Shivansh Dhiman <shivansh.dhiman@amd.com>
KVM: SVM: Add LBR/PMC freeze support
This commit adds support for the LBR and PMC freeze-on-PMI feature.
It updates CPUID initialization and allows the guest to set the
corresponding bits in DEBUGCTL if the feature is advertised.
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index d450a5b2499d9..03501b3145eb0 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -1268,6 +1268,7 @@ void kvm_initialize_cpu_caps(void)
> kvm_cpu_cap_init(CPUID_8000_0022_EAX,
> F(PERFMON_V2),
> SCATTERED_F(AMD_LBR_V2),
> + SCATTERED_F(AMD_LBR_PMC_FREEZE),
> );
[Severity: High]
Will this feature remain advertised to the guest even when prerequisite
features like mediated PMU or LBR virtualization are disabled?
Looking at svm_hardware_setup() in arch/x86/kvm/svm/svm.c,
X86_FEATURE_AMD_LBR_V2 is dynamically cleared when prerequisites are missing:
if (!lbrv || !enable_mediated_pmu ||
!kvm_cpu_cap_has(X86_FEATURE_PERFMON_V2))
kvm_cpu_cap_clear(X86_FEATURE_AMD_LBR_V2);
If X86_FEATURE_AMD_LBR_PMC_FREEZE is not cleared similarly, a guest might
see the feature in CPUID and attempt to use it. If the host administrator
configured KVM with lbrv=0, svm_set_msr() silently ignores writes to
MSR_IA32_DEBUGCTLMSR without injecting a #GP, which could break guest PMU
functionality.
[ ... ]
> diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
> index 01dae3828a7aa..105a71d69d68a 100644
> --- a/arch/x86/kvm/svm/svm.h
> +++ b/arch/x86/kvm/svm/svm.h
> @@ -784,7 +784,9 @@ BUILD_SVM_MSR_BITMAP_HELPERS(bool, test, test)
> BUILD_SVM_MSR_BITMAP_HELPERS(void, clear, __clear)
> BUILD_SVM_MSR_BITMAP_HELPERS(void, set, __set)
>
> -#define DEBUGCTL_RESERVED_BITS (~DEBUGCTLMSR_LBR)
> +#define DEBUGCTL_LBR_PMC_FREEZE_BITS (DEBUGCTLMSR_FREEZE_LBRS_ON_PMI | \
> + DEBUGCTLMSR_FREEZE_PERFMON_ON_PMI)
> +#define DEBUGCTL_RESERVED_BITS (~(DEBUGCTLMSR_LBR | DEBUGCTL_LBR_PMC_FREEZE_BITS))
[Severity: High]
Does modifying this macro globally allow an L1 hypervisor to bypass CPUID
capability checks for its L2 guest?
In arch/x86/kvm/svm/nested.c:nested_vmcb02_prepare_save(), VMCB12's dbgctl
is masked directly against DEBUGCTL_RESERVED_BITS:
vmcb02->save.dbgctl &= ~DEBUGCTL_RESERVED_BITS;
By unreserving the freeze bits globally here, an unprivileged L1 hypervisor
with LBRV enabled could write DEBUGCTL_LBR_PMC_FREEZE_BITS into its
vmcb12->save.dbgctl. Since KVM copies this to L2's VMCB without checking if
L1 actually possesses the X86_FEATURE_AMD_LBR_PMC_FREEZE capability, this
appears to allow a nested capability bypass.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724195040.630468-1-shivansh.dhiman@amd.com?part=6
next prev parent reply other threads:[~2026-07-24 20:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 19:50 [PATCH 0/7] KVM: SVM: Add support for AMD LBR Extension v2 Shivansh Dhiman
2026-07-24 19:50 ` [PATCH 1/7] KVM: SVM: Add VMCB fields for LBR v2 virtualization Shivansh Dhiman
2026-07-24 20:08 ` sashiko-bot
2026-07-24 19:50 ` [PATCH 2/7] KVM: SVM: Add capability for LbrExtV2 Shivansh Dhiman
2026-07-24 19:50 ` [PATCH 3/7] KVM: SVM: Emulate guest accesses to LBR v2 MSRs Shivansh Dhiman
2026-07-24 20:13 ` sashiko-bot
2026-07-24 19:50 ` [PATCH 4/7] KVM: SVM: Enable hardware-assisted LBR v2 virtualization Shivansh Dhiman
2026-07-24 20:17 ` sashiko-bot
2026-07-24 19:50 ` [PATCH 5/7] KVM: SVM: Advertise LbrExtV2 to userspace Shivansh Dhiman
2026-07-24 20:06 ` sashiko-bot
2026-07-24 19:50 ` [PATCH 6/7] KVM: SVM: Add LBR/PMC freeze support Shivansh Dhiman
2026-07-24 20:13 ` sashiko-bot [this message]
2026-07-24 19:50 ` [PATCH 7/7] KVM: x86: Use SCATTERED_F() for PERFMON_V2 Shivansh Dhiman
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=20260724201344.3816C1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shivansh.dhiman@amd.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