Skip to content

Commit 04cd8f8

Browse files
committed
KVM: x86: Disallow KVM_CAP_X86_DISABLE_EXITS after vCPU creation
Reject KVM_CAP_X86_DISABLE_EXITS if vCPUs have been created, as disabling PAUSE/MWAIT/HLT exits after vCPUs have been created is broken and useless, e.g. except for PAUSE on SVM, the relevant intercepts aren't updated after vCPU creation. vCPUs may also end up with an inconsistent configuration if exits are disabled between creation of multiple vCPUs. Cc: Hou Wenlong <houwenlong.hwl@antgroup.com> Link: https://lore.kernel.org/all/9227068821b275ac547eb2ede09ec65d2281fe07.1680179693.git.houwenlong.hwl@antgroup.com Link: https://lore.kernel.org/all/20230121020738.2973-2-kechenl@nvidia.com Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Link: https://lore.kernel.org/r/20241128013424.4096668-14-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 21d7f06 commit 04cd8f8

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7670,6 +7670,7 @@ branch to guests' 0x200 interrupt vector.
76707670
:Architectures: x86
76717671
:Parameters: args[0] defines which exits are disabled
76727672
:Returns: 0 on success, -EINVAL when args[0] contains invalid exits
7673+
or if any vCPUs have already been created
76737674

76747675
Valid bits in args[0] are::
76757676

arch/x86/kvm/x86.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6531,6 +6531,10 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
65316531
if (cap->args[0] & ~KVM_X86_DISABLE_VALID_EXITS)
65326532
break;
65336533

6534+
mutex_lock(&kvm->lock);
6535+
if (kvm->created_vcpus)
6536+
goto disable_exits_unlock;
6537+
65346538
if (cap->args[0] & KVM_X86_DISABLE_EXITS_PAUSE)
65356539
kvm->arch.pause_in_guest = true;
65366540

@@ -6552,6 +6556,8 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
65526556
}
65536557

65546558
r = 0;
6559+
disable_exits_unlock:
6560+
mutex_unlock(&kvm->lock);
65556561
break;
65566562
case KVM_CAP_MSR_PLATFORM_INFO:
65576563
kvm->arch.guest_can_read_msr_platform_info = cap->args[0];

0 commit comments

Comments
 (0)