]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: nSVM: Refactor checking LBRV enablement in vmcb12 into a helper
authorYosry Ahmed <yosry@kernel.org>
Tue, 3 Mar 2026 00:34:00 +0000 (00:34 +0000)
committerSean Christopherson <seanjc@google.com>
Thu, 5 Mar 2026 00:08:46 +0000 (16:08 -0800)
Refactor the vCPU cap and vmcb12 flag checks into a helper. The
unlikely() annotation is dropped, it's unlikely (huh) to make a
difference and the CPU will probably predict it better on its own.

CC: stable@vger.kernel.org
Co-developed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Yosry Ahmed <yosry@kernel.org>
Link: https://patch.msgid.link/20260303003421.2185681-7-yosry@kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/nested.c

index 7a472d7c6e9892e2fb8fd1072dd97de838c70788..d419fd516fa95c977d1caba9be9af41f8fd9a3a7 100644 (file)
@@ -640,6 +640,12 @@ void nested_vmcb02_compute_g_pat(struct vcpu_svm *svm)
        svm->nested.vmcb02.ptr->save.g_pat = svm->vmcb01.ptr->save.g_pat;
 }
 
+static bool nested_vmcb12_has_lbrv(struct kvm_vcpu *vcpu)
+{
+       return guest_cpu_cap_has(vcpu, X86_FEATURE_LBRV) &&
+               (to_svm(vcpu)->nested.ctl.virt_ext & LBR_CTL_ENABLE_MASK);
+}
+
 static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12)
 {
        bool new_vmcb12 = false;
@@ -704,8 +710,7 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12
                vmcb_mark_dirty(vmcb02, VMCB_DR);
        }
 
-       if (unlikely(guest_cpu_cap_has(vcpu, X86_FEATURE_LBRV) &&
-                    (svm->nested.ctl.virt_ext & LBR_CTL_ENABLE_MASK))) {
+       if (nested_vmcb12_has_lbrv(vcpu)) {
                /*
                 * Reserved bits of DEBUGCTL are ignored.  Be consistent with
                 * svm_set_msr's definition of reserved bits.
@@ -1233,8 +1238,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
        if (!nested_exit_on_intr(svm))
                kvm_make_request(KVM_REQ_EVENT, &svm->vcpu);
 
-       if (unlikely(guest_cpu_cap_has(vcpu, X86_FEATURE_LBRV) &&
-                    (svm->nested.ctl.virt_ext & LBR_CTL_ENABLE_MASK))) {
+       if (nested_vmcb12_has_lbrv(vcpu)) {
                svm_copy_lbrs(&vmcb12->save, &vmcb02->save);
        } else {
                svm_copy_lbrs(&vmcb01->save, &vmcb02->save);