From: Shivansh Dhiman <shivansh.dhiman@amd.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <kvm@vger.kernel.org>, Shivansh Dhiman <shivansh.dhiman@amd.com>
Subject: Re: [PATCH v2 04/12] KVM: SVM: Enable hardware-assisted LBRv2 virtualization
Date: Mon, 30 Nov 2026 12:06:43 +0530 [thread overview]
Message-ID: <5a8d8763-346e-4e38-b707-c91f67e0bcb2@amd.com> (raw)
In-Reply-To: <sashiko-outbox-178262@kernel.org>
On 20-10-26 03:03, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] KVM: SVM: Missing VMCB_LBR dirty mark when toggling V_LBR in svm_update_lbrv()
> --
>
> commit 46b5fce40fe2fd2edafbeb3ed6f81f7158c27cba
> Author: Shivansh Dhiman <shivansh.dhiman@amd.com>
>
> KVM: SVM: Enable hardware-assisted LBRv2 virtualization
>
> This commit enables V_LBR when LBRv2 is active in the guest and passes
> the LBRv2 MSRs through to the guest by disabling their intercepts while
> branch recording is enabled.
>
>> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
>> index 428c95d7ef21b..69f9ea746bb6f 100644
>> --- a/arch/x86/kvm/svm/svm.c
>> +++ b/arch/x86/kvm/svm/svm.c
>
> [ ... ]
>
>> @@ -897,6 +935,9 @@ static bool svm_need_lbr_virtualization(struct kvm_vcpu *vcpu)
>> if (svm->vmcb->save.dbgctl & (DEBUGCTLMSR_LBR | DEBUGCTLMSR_BUS_LOCK_DETECT))
>> return true;
>>
>> + if (svm_lbrv2_active(vcpu))
>> + return true;
>> +
>> return is_guest_mode(vcpu) &&
>> (svm->nested.ctl.misc_ctl2 & SVM_MISC2_ENABLE_V_LBR);
>> }
>> @@ -919,6 +960,7 @@ void svm_update_lbrv(struct kvm_vcpu *vcpu)
>> * do, so always recalculate the intercepts here.
>> */
>> svm_recalc_lbr_msr_intercepts(vcpu);
>> + svm_recalc_lbrv2_msr_intercepts(vcpu);
>> }
>
[...]
> Per the AMD APM, VMCB clean bit 10 (VMCB_LBR) covers the LBR virtualization
> enable bit (SVM_MISC2_ENABLE_V_LBR) in addition to DBGCTL and the legacy LBR
> MSRs. Unlike the MSR_IA32_DEBUGCTLMSR path in svm_set_msr(), neither the
> MSR_AMD_DBG_EXTN_CFG handler nor __svm_enable_lbrv() / __svm_disable_lbrv()
> marks VMCB_LBR dirty.
The VMCB clean bit 10 (LBR) doesn't cover V_LBR bit, as per APM.
>
> After a previous VMRUN has marked VMCB_LBR clean via vmcb_mark_all_clean()
> in svm_vcpu_run(), can toggling DBG_EXTN_CFG_LBRV2EN leave VMCB_LBR clean in
> svm->vmcb->control.clean, causing the CPU to use a stale cached value for
> SVM_MISC2_ENABLE_V_LBR and DBGCTL on VMRUN while KVM stops manually
> switching DEBUGCTL and disables the LBR MSR intercepts?
Good point, the stale DBGCTL maybe possible. VMRUN loads DBGCTL from the
VMCB only while V_LBR is set. A DBG_EXTN_CFG write can set V_LBR without a
DEBUGCTL write, so VMCB_LBR can stay clean and VMRUN can use a stale cached
DBGCTL.
>
> Should __svm_enable_lbrv() and __svm_disable_lbrv() call
> vmcb_mark_dirty(svm->vmcb, VMCB_LBR)?
I think it is better to mark VMCB_LBR dirty in the MSR_AMD_DBG_EXTN_CFG
case of svm_set_msr(), the same as commit dc55b3c3f612 ("KVM: SVM: Mark
VMCB_LBR dirty when MSR_IA32_DEBUGCTLMSR is updated").
next prev parent reply other threads:[~2026-11-30 6:36 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 21:05 [PATCH v2 00/12] KVM: SVM: Add support for AMD LBR Extension v2 Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 01/12] KVM: SVM: Add VMCB fields for LBRv2 virtualization Shivansh Dhiman
2026-10-19 22:09 ` Jim Mattson
2026-10-24 14:13 ` Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 02/12] KVM: SVM: Add the LbrExtV2 CPUID feature bit Shivansh Dhiman
2026-10-19 22:15 ` Jim Mattson
2026-10-24 14:15 ` Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 03/12] KVM: SVM: Emulate guest accesses to LBRv2 MSRs Shivansh Dhiman
2026-10-19 23:26 ` Jim Mattson
2026-11-15 20:34 ` Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 04/12] KVM: SVM: Enable hardware-assisted LBRv2 virtualization Shivansh Dhiman
2026-10-19 21:33 ` sashiko-bot
2026-11-30 6:36 ` Shivansh Dhiman [this message]
2026-10-21 23:34 ` Jim Mattson
2026-11-15 20:32 ` Shivansh Dhiman
2026-11-19 21:56 ` Jim Mattson
2026-11-24 6:22 ` Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 05/12] KVM: x86: Add support for Live Migration Shivansh Dhiman
2026-10-21 23:42 ` Jim Mattson
2026-10-24 14:21 ` Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 06/12] perf/x86: Expose the LBR stack depth via x86_pmu_capability Shivansh Dhiman
2026-10-21 23:44 ` Jim Mattson
2026-11-15 20:37 ` Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 07/12] KVM: SVM: Advertise LbrExtV2 to userspace Shivansh Dhiman
2026-10-19 21:27 ` sashiko-bot
2026-11-30 6:46 ` Shivansh Dhiman
2026-10-21 23:49 ` Jim Mattson
2026-11-05 6:42 ` Shivansh Dhiman
2026-11-19 21:58 ` Jim Mattson
2026-11-24 6:25 ` Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 08/12] KVM: SVM: Support LBRv2 virtualization for SEV-ES guests Shivansh Dhiman
2026-10-21 23:53 ` Jim Mattson
2026-11-05 6:33 ` Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 09/12] KVM: nSVM: Propagate LBRv2 state across nested transitions Shivansh Dhiman
2026-10-19 21:31 ` sashiko-bot
2026-11-19 22:28 ` Jim Mattson
2026-10-19 21:05 ` [PATCH v2 10/12] KVM: nSVM: Pass through LBRv2 MSRs to L2 Shivansh Dhiman
2026-10-19 21:36 ` sashiko-bot
2026-11-19 22:30 ` Jim Mattson
2026-11-26 6:37 ` Shivansh Dhiman
2026-10-19 21:05 ` [PATCH v2 11/12] KVM: SVM: Add LBR/PMC freeze support Shivansh Dhiman
2026-10-19 21:27 ` sashiko-bot
2026-11-19 22:36 ` Jim Mattson
2026-10-19 21:05 ` [PATCH v2 12/12] KVM: x86: Use SCATTERED_F() for PERFMON_V2 Shivansh Dhiman
2026-10-21 23:56 ` Jim Mattson
2026-11-15 20:37 ` Shivansh Dhiman
2026-10-20 19:23 ` [PATCH v2 00/12] KVM: SVM: Add support for AMD LBR Extension v2 Jim Mattson
2026-11-15 20:33 ` Shivansh Dhiman
2026-11-19 21:40 ` Jim Mattson
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=5a8d8763-346e-4e38-b707-c91f67e0bcb2@amd.com \
--to=shivansh.dhiman@amd.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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