Skip to content

Commit 2a955c4

Browse files
committed
KVM: x86: Add supported_vm_types to kvm_caps
This simplifies the implementation of KVM_CHECK_EXTENSION(KVM_CAP_VM_TYPES), and also allows the vendor module to specify which VM types are supported. Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 517987e commit 2a955c4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

arch/x86/kvm/x86.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494

9595
struct kvm_caps kvm_caps __read_mostly = {
9696
.supported_mce_cap = MCG_CTL_P | MCG_SER_P,
97+
.supported_vm_types = BIT(KVM_X86_DEFAULT_VM),
9798
};
9899
EXPORT_SYMBOL_GPL(kvm_caps);
99100

@@ -4629,9 +4630,7 @@ static int kvm_ioctl_get_supported_hv_cpuid(struct kvm_vcpu *vcpu,
46294630

46304631
static bool kvm_is_vm_type_supported(unsigned long type)
46314632
{
4632-
return type == KVM_X86_DEFAULT_VM ||
4633-
(type == KVM_X86_SW_PROTECTED_VM &&
4634-
IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_mmu_enabled);
4633+
return type < 32 && (kvm_caps.supported_vm_types & BIT(type));
46354634
}
46364635

46374636
int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
@@ -4832,9 +4831,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
48324831
r = kvm_caps.has_notify_vmexit;
48334832
break;
48344833
case KVM_CAP_VM_TYPES:
4835-
r = BIT(KVM_X86_DEFAULT_VM);
4836-
if (kvm_is_vm_type_supported(KVM_X86_SW_PROTECTED_VM))
4837-
r |= BIT(KVM_X86_SW_PROTECTED_VM);
4834+
r = kvm_caps.supported_vm_types;
48384835
break;
48394836
default:
48404837
break;
@@ -9824,6 +9821,9 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
98249821

98259822
kvm_register_perf_callbacks(ops->handle_intel_pt_intr);
98269823

9824+
if (IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_mmu_enabled)
9825+
kvm_caps.supported_vm_types |= BIT(KVM_X86_SW_PROTECTED_VM);
9826+
98279827
if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES))
98289828
kvm_caps.supported_xss = 0;
98299829

arch/x86/kvm/x86.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct kvm_caps {
2424
bool has_bus_lock_exit;
2525
/* notify VM exit supported? */
2626
bool has_notify_vmexit;
27+
/* bit mask of VM types */
28+
u32 supported_vm_types;
2729

2830
u64 supported_mce_cap;
2931
u64 supported_xcr0;

0 commit comments

Comments
 (0)