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 <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-ID: <20240404121327.3107131-9-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
517987e3fb
commit
2a955c4db1
2 changed files with 8 additions and 6 deletions
|
@ -94,6 +94,7 @@
|
||||||
|
|
||||||
struct kvm_caps kvm_caps __read_mostly = {
|
struct kvm_caps kvm_caps __read_mostly = {
|
||||||
.supported_mce_cap = MCG_CTL_P | MCG_SER_P,
|
.supported_mce_cap = MCG_CTL_P | MCG_SER_P,
|
||||||
|
.supported_vm_types = BIT(KVM_X86_DEFAULT_VM),
|
||||||
};
|
};
|
||||||
EXPORT_SYMBOL_GPL(kvm_caps);
|
EXPORT_SYMBOL_GPL(kvm_caps);
|
||||||
|
|
||||||
|
@ -4629,9 +4630,7 @@ static int kvm_ioctl_get_supported_hv_cpuid(struct kvm_vcpu *vcpu,
|
||||||
|
|
||||||
static bool kvm_is_vm_type_supported(unsigned long type)
|
static bool kvm_is_vm_type_supported(unsigned long type)
|
||||||
{
|
{
|
||||||
return type == KVM_X86_DEFAULT_VM ||
|
return type < 32 && (kvm_caps.supported_vm_types & BIT(type));
|
||||||
(type == KVM_X86_SW_PROTECTED_VM &&
|
|
||||||
IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_mmu_enabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
|
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)
|
||||||
r = kvm_caps.has_notify_vmexit;
|
r = kvm_caps.has_notify_vmexit;
|
||||||
break;
|
break;
|
||||||
case KVM_CAP_VM_TYPES:
|
case KVM_CAP_VM_TYPES:
|
||||||
r = BIT(KVM_X86_DEFAULT_VM);
|
r = kvm_caps.supported_vm_types;
|
||||||
if (kvm_is_vm_type_supported(KVM_X86_SW_PROTECTED_VM))
|
|
||||||
r |= BIT(KVM_X86_SW_PROTECTED_VM);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -9824,6 +9821,9 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
|
||||||
|
|
||||||
kvm_register_perf_callbacks(ops->handle_intel_pt_intr);
|
kvm_register_perf_callbacks(ops->handle_intel_pt_intr);
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_mmu_enabled)
|
||||||
|
kvm_caps.supported_vm_types |= BIT(KVM_X86_SW_PROTECTED_VM);
|
||||||
|
|
||||||
if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES))
|
if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES))
|
||||||
kvm_caps.supported_xss = 0;
|
kvm_caps.supported_xss = 0;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ struct kvm_caps {
|
||||||
bool has_bus_lock_exit;
|
bool has_bus_lock_exit;
|
||||||
/* notify VM exit supported? */
|
/* notify VM exit supported? */
|
||||||
bool has_notify_vmexit;
|
bool has_notify_vmexit;
|
||||||
|
/* bit mask of VM types */
|
||||||
|
u32 supported_vm_types;
|
||||||
|
|
||||||
u64 supported_mce_cap;
|
u64 supported_mce_cap;
|
||||||
u64 supported_xcr0;
|
u64 supported_xcr0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue