KVM: SVM: Enable Virtual VMLOAD VMSAVE feature

Enable the Virtual VMLOAD VMSAVE feature. This is done by setting bit 1
at position B8h in the vmcb.

The processor must have nested paging enabled, be in 64-bit mode and
have support for the Virtual VMLOAD VMSAVE feature for the bit to be set
in the vmcb.

Signed-off-by: Janakarajan Natarajan <Janakarajan.Natarajan@amd.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
This commit is contained in:
Janakarajan Natarajan 2017-07-06 15:50:47 -05:00 committed by Radim Krčmář
parent 76ff359249
commit 89c8a4984f
2 changed files with 25 additions and 0 deletions

View File

@ -120,6 +120,7 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
#define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT) #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT)
#define LBR_CTL_ENABLE_MASK BIT_ULL(0) #define LBR_CTL_ENABLE_MASK BIT_ULL(0)
#define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1)
#define SVM_INTERRUPT_SHADOW_MASK 1 #define SVM_INTERRUPT_SHADOW_MASK 1

View File

@ -277,6 +277,10 @@ static int avic;
module_param(avic, int, S_IRUGO); module_param(avic, int, S_IRUGO);
#endif #endif
/* enable/disable Virtual VMLOAD VMSAVE */
static int vls = true;
module_param(vls, int, 0444);
/* AVIC VM ID bit masks and lock */ /* AVIC VM ID bit masks and lock */
static DECLARE_BITMAP(avic_vm_id_bitmap, AVIC_VM_ID_NR); static DECLARE_BITMAP(avic_vm_id_bitmap, AVIC_VM_ID_NR);
static DEFINE_SPINLOCK(avic_vm_id_lock); static DEFINE_SPINLOCK(avic_vm_id_lock);
@ -1093,6 +1097,16 @@ static __init int svm_hardware_setup(void)
} }
} }
if (vls) {
if (!npt_enabled ||
!boot_cpu_has(X86_FEATURE_VIRTUAL_VMLOAD_VMSAVE) ||
!IS_ENABLED(CONFIG_X86_64)) {
vls = false;
} else {
pr_info("Virtual VMLOAD VMSAVE supported\n");
}
}
return 0; return 0;
err: err:
@ -1280,6 +1294,16 @@ static void init_vmcb(struct vcpu_svm *svm)
if (avic) if (avic)
avic_init_vmcb(svm); avic_init_vmcb(svm);
/*
* If hardware supports Virtual VMLOAD VMSAVE then enable it
* in VMCB and clear intercepts to avoid #VMEXIT.
*/
if (vls) {
clr_intercept(svm, INTERCEPT_VMLOAD);
clr_intercept(svm, INTERCEPT_VMSAVE);
svm->vmcb->control.virt_ext |= VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK;
}
mark_all_dirty(svm->vmcb); mark_all_dirty(svm->vmcb);
enable_gif(svm); enable_gif(svm);