mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, xiaoyao.li@intel.com
Subject: [PATCH 2/3] KVM: x86: Reject enabling KVM_CAP_X86_BUS_LOCK_EXIT when !kvm_caps.has_bus_lock_exit
Date: Thu,  6 Aug 2026 19:19:22 +0800	[thread overview]
Message-ID: <20260806111923.1990562-3-xiaoyao.li@intel.com> (raw)
In-Reply-To: <20260806111923.1990562-1-xiaoyao.li@intel.com>

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 <xiaoyao.li@intel.com>
---
---
 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


  parent reply	other threads:[~2026-08-06 11:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 11:19 [PATCH 0/3] KVM: x86: BUS_LOCK_EXIT fixes Xiaoyao Li
2026-08-06 11:19 ` [PATCH 1/3] KVM: VMX: Preserve negative return value in vmx_handle_exit() with bus lock detected Xiaoyao Li
2026-08-06 11:19 ` Xiaoyao Li [this message]
2026-08-06 14:31   ` [PATCH 2/3] KVM: x86: Reject enabling KVM_CAP_X86_BUS_LOCK_EXIT when !kvm_caps.has_bus_lock_exit Sean Christopherson
2026-08-06 11:19 ` [PATCH 3/3] KVM: x86: Only allow enabling KVM_BUS_LOCK_DETECTION_EXIT before creating any vCPU Xiaoyao Li

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=20260806111923.1990562-3-xiaoyao.li@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /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

all inboxes | Powered by JetHome®