[PATCH 2/3] KVM: x86: Reject enabling KVM_CAP_X86_BUS_LOCK_EXIT when !kvm_caps.has_bus_lock_exit

Xiaoyao Li <[email protected]>
Newsgroups org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Return -EINVAL to reject the enabling of KVM_CAP_X86_BUS_LOCK_EXIT from
userspace when kvm_caps.has_bus_lock_exit is false.

For KVM_BUS_LOCK_DETECTION_EXIT, if KVM doesn't support BUS LOCK EXIT,
return error to userspace instead of success.

For KVM_BUS_LOCK_DETECTION_OFF, it seems OK to allow it when KVM doesn't
support bus_lock_exit. But from an API perspective, it implies
inconsistency that KVM_CAP_X86_BUS_LOCK_EXIT reports 0 but setting
KVM_BUS_LOCK_DETECTION_OFF is allowed. To keep it consistent, also
return error for KVM_BUS_LOCK_DETECTION_OFF when KVM doesn't support
BUS LOCK EXIT.

Fixes: fe6b6bc802b4 ("KVM: VMX: Enable bus lock VM exit")
Signed-off-by: Xiaoyao Li <[email protected]>
---
---
 arch/x86/kvm/x86.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d94b59140c45..3d8422d1cd04 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4058,8 +4058,10 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
 		    (cap->args[0] & KVM_BUS_LOCK_DETECTION_EXIT))
 			break;
 
-		if (kvm_caps.has_bus_lock_exit &&
-		    cap->args[0] & KVM_BUS_LOCK_DETECTION_EXIT)
+		if (!kvm_caps.has_bus_lock_exit)
+			break;
+
+		if (cap->args[0] & KVM_BUS_LOCK_DETECTION_EXIT)
 			kvm->arch.bus_lock_detection_enabled = true;
 		r = 0;
 		break;
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.