Skip to contentSkip to conversation

KVM: VMX: Remove redundant handling of bus lock vmexit

PATCH Superseded Hao Xiang 1 participant 1 message Sep 27, 2021

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Hao Xiang

author
#0 lore raw

PATCH 1/1 KVM: VMX: Remove redundant handling of bus lock vmexit

exit_reason.bus_lock_detected may or may not be set when exit reason is EXIT_REASON_BUS_LOCK. It is non-deterministic hardware behavior. Dealing with KVM_RUN_X86_BUS_LOCK in handle_bus_lock_vmexit could be redundant when exit_reason.basic is EXIT_REASON_BUS_LOCK.

We can remove redundant handling of bus lock vmexit. Set exit_reason.bus_lock_detected (bit 26) unconditionally, and deal with KVM_RUN_X86_BUS_LOCK only in vmx_handle_exit.

---
 arch/x86/kvm/vmx/vmx.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
arch/x86/kvm/vmx/vmx.c +9 -6
index 0c2c0d5..f993c38 100644
@@ -5561,9 +5561,13 @@ static int handle_encls(struct kvm_vcpu *vcpu)
 
 static int handle_bus_lock_vmexit(struct kvm_vcpu *vcpu)
 {
-	vcpu->run->exit_reason = KVM_EXIT_X86_BUS_LOCK;
-	vcpu->run->flags |= KVM_RUN_X86_BUS_LOCK;
-	return 0;
+	struct vcpu_vmx *vmx = to_vmx(vcpu);
+
+	/* The dedicated flag (bit 26 of exit reason in vmcs field) may or may
+	 * not be set by hardware.
+	 */
+	vmx->exit_reason.bus_lock_detected = true;
+	return 1;
 }
 
 /*
@@ -6050,9 +6054,8 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
 	int ret = __vmx_handle_exit(vcpu, exit_fastpath);
 
 	/*
-	 * Even when current exit reason is handled by KVM internally, we
-	 * still need to exit to user space when bus lock detected to inform
-	 * that there is a bus lock in guest.
+	 * Exit to user space when bus lock detected to inform that there is
+	 * a bus lock in guest.
 	 */
 	if (to_vmx(vcpu)->exit_reason.bus_lock_detected) {
 		if (ret > 0)
Signature · 1 line
1.8.3.1