]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Drop redundant call to kvm_deliver_exception_payload()
authorYosry Ahmed <yosry@kernel.org>
Mon, 2 Mar 2026 15:42:49 +0000 (15:42 +0000)
committerSean Christopherson <seanjc@google.com>
Tue, 3 Mar 2026 20:26:12 +0000 (12:26 -0800)
In kvm_check_and_inject_events(), kvm_deliver_exception_payload() is
called for pending #DB exceptions. However, shortly after, the
per-vendor inject_exception callbacks are made. Both
vmx_inject_exception() and svm_inject_exception() unconditionally call
kvm_deliver_exception_payload(), so the call in
kvm_check_and_inject_events() is redundant.

Note that the extra call for pending #DB exceptions is harmless, as
kvm_deliver_exception_payload() clears exception.has_payload after the
first call.

The call in kvm_check_and_inject_events() was added in commit
f10c729ff965 ("kvm: vmx: Defer setting of DR6 until #DB delivery"). At
that point, the call was likely needed because svm_queue_exception()
checked whether an exception for L2 is intercepted by L1 before calling
kvm_deliver_exception_payload(), as SVM did not have a
check_nested_events callback. Since DR6 is updated before the #DB
intercept in SVM (unlike VMX), it was necessary to deliver the DR6
payload before calling svm_queue_exception().

After that, commit 7c86663b68ba ("KVM: nSVM: inject exceptions via
svm_check_nested_events") added a check_nested_events callback for SVM,
which checked for L1 intercepts for L2's exceptions, and delivered the
the payload appropriately before the intercept. At that point,
svm_queue_exception() started calling kvm_deliver_exception_payload()
unconditionally, and the call to kvm_deliver_exception_payload() from
its caller became redundant.

No functional change intended.

Signed-off-by: Yosry Ahmed <yosry@kernel.org>
Link: https://patch.msgid.link/20260302154249.784529-1-yosry@kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/x86.c

index 658476815b6a6ccf2cd94e87cdea76629bec490a..d5731499f4c2c89d3509a51f9e4d5c4a372c0b3e 100644 (file)
@@ -10736,12 +10736,10 @@ static int kvm_check_and_inject_events(struct kvm_vcpu *vcpu,
                        __kvm_set_rflags(vcpu, kvm_get_rflags(vcpu) |
                                             X86_EFLAGS_RF);
 
-               if (vcpu->arch.exception.vector == DB_VECTOR) {
-                       kvm_deliver_exception_payload(vcpu, &vcpu->arch.exception);
-                       if (vcpu->arch.dr7 & DR7_GD) {
-                               vcpu->arch.dr7 &= ~DR7_GD;
-                               kvm_update_dr7(vcpu);
-                       }
+               if (vcpu->arch.exception.vector == DB_VECTOR &&
+                   vcpu->arch.dr7 & DR7_GD) {
+                       vcpu->arch.dr7 &= ~DR7_GD;
+                       kvm_update_dr7(vcpu);
                }
 
                kvm_inject_exception(vcpu);