Add support for nested SVM (kernel) v6
cover Add support for nested SVM (kernel) v6
The current generation of virtualization extensions only supports one VM layer. While we can't change that, it is pretty easy to emulate the CPU's behavior and implement the virtualization opcodes ourselves.
This patchset does exactly this for SVM. Using it, KVM can run within a VM. Since we're emulating the real CPU's behavior, this should also enable other VMMs to run within KVM.
So far I've only tested to run KVM inside the VM though.
As always, comments and suggestions are highly welcome.
v2 takes most comments from Avi into account.
v3 addresses Joergs comments, including
- V_INTR_MASKING support
- a generic permission checking helper
v4 addresses even more comments from Joerg, including
- don't use the guest's hsave to store the guest's vmcb in
- add nested=<int> flag for kvm-amd.ko, defaults to 0 (off)
- include Joerg's VM_CR MSR patch
v5 removes the IOPM merging code
v6 addresses comments from Joerg and Anthony:
- don't flood the host's log with printks
- export SVM capability to userspace (SVM CPUID capability)
- prettify nsvm_printk
- pass an error code on inject_gp (0)
- always close interrupt_window if GIF=0
- fix 32-bit l1 guests
- warn in syslog if nested=1 on module load
- huge speed improvements
To be usable, this patchset requires simple changes in the userspace part. For now you can easily use the patches I sent to the list when I sent the first version if you comment out the new svm masking in qemu/target-i386/helper.c.
I will submit a newer version of the userspace patch once the kernel parts are OK.
Known issues:
- TODO: #VMEXIT on save/restore
- SMP l2 guests break with in-kernel-apic
Thanks for reviewing!
Alex
Alexander Graf (11):
Clean up VINTR setting v6
Move EFER and MSR constants to generic x86 code v6 Add helper functions for nested SVM v6 Implement GIF, clgi and stgi v6
Implement hsave v6
Add VMLOAD and VMSAVE handlers v6
Add VMRUN handler v6
Add VMEXIT handler and intercepts v6
Allow setting the SVME bit v6
Only allow setting of EFER_SVME when CPUID SVM is set v6 Accelerate nested SVM by emulating parts of GIF=0 v6
Joerg Roedel (1):
Allow read access to MSR_VM_VR v6
arch/x86/include/asm/kvm_host.h | 6 + arch/x86/include/asm/msr-index.h | 7 + arch/x86/kvm/kvm_svm.h | 10 + arch/x86/kvm/svm.c | 763 +++++++++++++++++++++++++++++++++++++- arch/x86/kvm/svm.h | 4 - arch/x86/kvm/x86.c | 60 +++- 6 files changed, 811 insertions(+), 39 deletions(-)
PATCH 1/12 Clean up VINTR setting v6
The current VINTR intercept setters don't look clean to me. To make the code easier to read and enable the possibilty to trap on a VINTR set, this uses a helper function to set the VINTR intercept.
v2 uses two distinct functions for setting and clearing the bit
--- arch/x86/kvm/svm.c | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-)
arch/x86/kvm/svm.c +15 -5
@@ -731,6 +731,16 @@ static void svm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)to_svm (vcpu)->vmcb->save.rflags = rflags; } +static void svm_set_vintr (struct vcpu_svm *svm) +{ + svm->vmcb->control.intercept |=1ULL <<INTERCEPT_VINTR ; +} + +static void svm_clear_vintr (struct vcpu_svm *svm) +{ + svm->vmcb->control.intercept &= ~(1ULL <<INTERCEPT_VINTR ); +} +static struct vmcb_seg *svm_seg (struct kvm_vcpu *vcpu,int seg) {struct vmcb_save_area *save = &to_svm (vcpu)->vmcb->save;
@@ -1393,7 +1403,7 @@ static int interrupt_window_interception(struct vcpu_svm *svm, {KVMTRACE_0D (PEND_INTR , &svm->vcpu, handler); - svm->vmcb->control.intercept &= ~(1ULL <<INTERCEPT_VINTR ); +svm_clear_vintr (svm); svm->vmcb->control.int_ctl &= ~V_IRQ_MASK ;/* * If the user space waits to inject interrupts, exit as soon as
@@ -1606,7 +1616,7 @@ static void svm_intr_assist(struct kvm_vcpu *vcpu) (vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) || (vmcb->control.event_inj & SVM_EVTINJ_VALID)) {/* unable to deliver irq, set pending irq */ - vmcb->control.intercept |= (1ULL <<INTERCEPT_VINTR ); +svm_set_vintr (svm);svm_inject_irq (svm,0x0 ); goto out; }
@@ -1666,9 +1676,9 @@ static void do_interrupt_requests(struct kvm_vcpu *vcpu,*/ if (!svm->vcpu.arch.interrupt_window_open && (svm->vcpu.arch.irq_summary || kvm_run->request_interrupt_window)) - control->intercept |=1ULL <<INTERCEPT_VINTR ; -else - control->intercept &= ~(1ULL <<INTERCEPT_VINTR ); +svm_set_vintr (svm); +else +svm_clear_vintr (svm); }static int svm_set_tss_addr (struct kvm *kvm,unsigned int addr)
Signature · 1 line
1.5.6
PATCH 2/12 Move EFER and MSR constants to generic x86 code v6
MSR_EFER_SVME_MASK, MSR_VM_CR and MSR_VM_HSAVE_PA are set in KVM specific headers. Linux does have nice header files to collect EFER bits and MSR IDs, so IMHO we should put them there.
While at it, I also changed the naming scheme to match that of the other defines.
(introduced in v6)
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/include/asm/msr-index.h | 7 +++++++ arch/x86/kvm/svm.c | 8 ++++---- arch/x86/kvm/svm.h | 4 ---- 4 files changed, 12 insertions(+), 8 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -22,6 +22,7 @@#include <asm/pvclock-abi.h> #include <asm/desc.h> #include <asm/mtrr.h> +#include <asm/msr-index.h> #define KVM_MAX_VCPUS 16#define KVM_MEMORY_SLOTS 32
arch/x86/include/asm/msr-index.h +7 -0
@@ -18,11 +18,13 @@#define _EFER_LME 8/* Long mode enable */ #define _EFER_LMA 10/* Long mode active (read-only) */ #define _EFER_NX 11/* No execute enable */ +#define _EFER_SVME 12/* Enable virtualization */ #define EFER_SCE (1<<_EFER_SCE)#define EFER_LME (1<<_EFER_LME)#define EFER_LMA (1<<_EFER_LMA)#define EFER_NX (1<<_EFER_NX) +#define EFER_SVME (1<<_EFER_SVME)/* Intel MSRs. Some also available on other CPUs */ #define MSR_IA32_PERFCTR0 0x000000c1
@@ -329,4 +331,9 @@#define MSR_IA32_VMX_PROCBASED_CTLS2 0x0000048b#define MSR_IA32_VMX_EPT_VPID_CAP 0x0000048c +/* AMD-V MSRs */ + +#define MSR_VM_CR 0xc0010114 +#define MSR_VM_HSAVE_PA 0xc0010117 +#endif /* _ASM_X86_MSR_INDEX_H */
arch/x86/kvm/svm.c +4 -4
@@ -196,7 +196,7 @@ static void svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)if (!npt_enabled && !(efer &EFER_LMA )) efer &= ~EFER_LME ; -to_svm (vcpu)->vmcb->save.efer = efer |MSR_EFER_SVME_MASK ; +to_svm (vcpu)->vmcb->save.efer = efer |EFER_SVME ; vcpu->arch.shadow_efer = efer; }
@@ -272,7 +272,7 @@ static void svm_hardware_disable(void *garbage)wrmsrl (MSR_VM_HSAVE_PA ,0 );rdmsrl (MSR_EFER , efer); -wrmsrl (MSR_EFER , efer & ~MSR_EFER_SVME_MASK ); +wrmsrl (MSR_EFER , efer & ~EFER_SVME ); }static void svm_hardware_enable (void *garbage)
@@ -305,7 +305,7 @@ static void svm_hardware_enable(void *garbage) svm_data->tss_desc = (struct kvm_ldttss_desc *)(gdt +GDT_ENTRY_TSS );rdmsrl (MSR_EFER , efer); -wrmsrl (MSR_EFER , efer |MSR_EFER_SVME_MASK ); +wrmsrl (MSR_EFER , efer |EFER_SVME );wrmsrl (MSR_VM_HSAVE_PA ,page_to_pfn (svm_data->save_area) <<PAGE_SHIFT );
@@ -572,7 +572,7 @@ static void init_vmcb(struct vcpu_svm *svm)init_sys_seg (&save->ldtr,SEG_TYPE_LDT );init_sys_seg (&save->tr,SEG_TYPE_BUSY_TSS16 ); - save->efer =MSR_EFER_SVME_MASK ; + save->efer =EFER_SVME ; save->dr6 =0xffff0ff0 ; save->dr7 =0x400 ; save->rflags =2 ;
arch/x86/kvm/svm.h +0 -4
@@ -174,10 +174,6 @@ struct __attribute__ ((__packed__)) vmcb {#define SVM_CPUID_FEATURE_SHIFT 2#define SVM_CPUID_FUNC 0x8000000a -#define MSR_EFER_SVME_MASK (1ULL << 12) -#define MSR_VM_CR 0xc0010114 -#define MSR_VM_HSAVE_PA 0xc0010117ULL -#define SVM_VM_CR_SVM_DISABLE 4#define SVM_SELECTOR_S_SHIFT 4
Signature · 1 line
1.5.6
PATCH 3/12 Add helper functions for nested SVM v6
These are helpers for the nested SVM implementation.
- nsvm_printk implements a debug printk variant
- nested_svm_do calls a handler that can accesses gpa-based memory
v3 makes use of the new permission checker
v6 changes:
- streamline nsvm_debug()
- remove printk(KERN_ERR)
- SVME check before CPL check
- give GP error code
- use new EFER constant
--- arch/x86/kvm/svm.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 85 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +85 -0
@@ -48,6 +48,15 @@ MODULE_LICENSE("GPL");#define DEBUGCTL_RESERVED_BITS (~(0x3fULL)) +/* Turn on to get debugging output*/ +/* #define NESTED_DEBUG */ + +#ifdef NESTED_DEBUG +#define nsvm_printk(fmt, args...) printk(KERN_INFO fmt, ## args) +#else +#define nsvm_printk(fmt, args...) do {} while(0) +#endif +/* enable NPT for AMD64 and X86 with PAE */ #if defined(CONFIG_X86_64 ) || defined(CONFIG_X86_PAE )static bool npt_enabled = true;
@@ -1162,6 +1171,82 @@ static int vmmcall_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)return 1 ; } +static int nested_svm_check_permissions (struct vcpu_svm *svm) +{ +if (!(svm->vcpu.arch.shadow_efer &EFER_SVME ) + || !is_paging (&svm->vcpu)) { +kvm_queue_exception (&svm->vcpu,UD_VECTOR ); +return 1 ; + } + +if (svm->vmcb->save.cpl) { +kvm_inject_gp (&svm->vcpu,0 ); +return 1 ; + } + +return 0 ; +} + +static struct page *nested_svm_get_page (struct vcpu_svm *svm,u64 gpa) +{ +struct page *page; + +down_read (¤t->mm->mmap_sem); + page =gfn_to_page (svm->vcpu.kvm, gpa >>PAGE_SHIFT ); +up_read (¤t->mm->mmap_sem); + +if (is_error_page (page)) { +printk (KERN_INFO "%s: could not find page at 0x%llx\n" , + __func__, gpa); +kvm_release_page_clean (page); +kvm_inject_gp (&svm->vcpu,0 ); +return NULL ; + } +return page; +} + +static int nested_svm_do (struct vcpu_svm *svm, +u64 arg1_gpa,u64 arg2_gpa,void *opaque, +int (*handler)(struct vcpu_svm *svm, +void *arg1, +void *arg2, +void *opaque)) +{ +struct page *arg1_page; +struct page *arg2_page =NULL ; +void *arg1; +void *arg2 =NULL ; +int retval; + + arg1_page =nested_svm_get_page (svm, arg1_gpa); +if (arg1_page ==NULL ) +return 1 ; + +if (arg2_gpa) { + arg2_page =nested_svm_get_page (svm, arg2_gpa); +if (arg2_page ==NULL ) { +kvm_release_page_clean (arg1_page); +return 1 ; + } + } + + arg1 =kmap_atomic (arg1_page,KM_USER0 ); +if (arg2_gpa) + arg2 =kmap_atomic (arg2_page,KM_USER1 ); + + retval =handler (svm, arg1, arg2, opaque); + +kunmap_atomic (arg1,KM_USER0 ); +if (arg2_gpa) +kunmap_atomic (arg2,KM_USER1 ); + +kvm_release_page_dirty (arg1_page); +if (arg2_gpa) +kvm_release_page_dirty (arg2_page); + +return retval; +} +static int invalid_op_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) {
Signature · 1 line
1.5.6
PATCH 4/12 Implement GIF, clgi and stgi v6
This patch implements the GIF flag and the clgi and stgi instructions that set this flag. Only if the flag is set (default), interrupts can be received by the CPU.
To keep the information about that somewhere, this patch adds a new hidden flags vector. that is used to store information that does not go into the vmcb, but is SVM specific.
I tried to write some code to make -no-kvm-irqchip work too, but the first level guest won't even boot with that atm, so I ditched it.
v2 moves the hflags to x86 generic code
v3 makes use of the new permission helper
v6 only enables interrupt_window if GIF=1
--- arch/x86/include/asm/kvm_host.h | 3 ++ arch/x86/kvm/svm.c | 47 ++++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 5 deletions(-)
arch/x86/include/asm/kvm_host.h +3 -0
@@ -256,6 +256,7 @@ struct kvm_vcpu_arch {unsigned long cr3;unsigned long cr4;unsigned long cr8; +u32 hflags;u64 pdptrs[4 ];/* pae */ u64 shadow_efer;u64 apic_base;
@@ -743,6 +744,8 @@ enum { TASK_SWITCH_GATE = 3, }; +#define HF_GIF_MASK (1 << 0) +/* * Hardware virtualization extension instructions may fault if a * reboot turns off virtualization while processes are running.
arch/x86/kvm/svm.c +42 -5
89 lines not on this page · raw message
Signature · 1 line
1.5.6
PATCH 5/12 Implement hsave v6
Implement the hsave MSR, that gives the VCPU a GPA to save the old guest state in.
v2 allows userspace to save/restore hsave v4 dummys out the hsave MSR, so we use a host page v6 remembers the guest's hsave and exports the MSR
--- arch/x86/kvm/kvm_svm.h | 2 ++ arch/x86/kvm/svm.c | 13 +++++++++++++ arch/x86/kvm/x86.c | 2 +- 3 files changed, 16 insertions(+), 1 deletions(-)
arch/x86/kvm/kvm_svm.h +2 -0
@@ -41,6 +41,8 @@ struct vcpu_svm {unsigned long host_dr7;u32 *msrpm; +struct vmcb *hsave; + u64 hsave_msr; };#endif
arch/x86/kvm/svm.c +13 -0
@@ -639,6 +639,7 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)struct vcpu_svm *svm;struct page *page;struct page *msrpm_pages; +struct page *hsave_page;int err; svm =kmem_cache_zalloc (kvm_vcpu_cache,GFP_KERNEL );
@@ -664,6 +665,11 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id) svm->msrpm =page_address (msrpm_pages);svm_vcpu_init_msrpm (svm->msrpm); + hsave_page =alloc_page (GFP_KERNEL ); +if (!hsave_page) + goto uninit; + svm->hsave =page_address (hsave_page); + svm->vmcb =page_address (page);clear_page (svm->vmcb); svm->vmcb_pa =page_to_pfn (page) <<PAGE_SHIFT ;
@@ -693,6 +699,7 @@ static void svm_free_vcpu(struct kvm_vcpu *vcpu)__free_page (pfn_to_page (svm->vmcb_pa >>PAGE_SHIFT ));__free_pages (virt_to_page (svm->msrpm),MSRPM_ALLOC_ORDER ); +__free_page (virt_to_page (svm->hsave));kvm_vcpu_uninit (vcpu);kmem_cache_free (kvm_vcpu_cache, svm); }
@@ -1390,6 +1397,9 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)case MSR_IA32_LASTINTTOIP : *data = svm->vmcb->save.last_excp_to;break ; +case MSR_VM_HSAVE_PA : + *data = svm->hsave_msr; +break ;default :return kvm_get_msr_common (vcpu, ecx, data); }
@@ -1484,6 +1494,9 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)pr_unimpl (vcpu,"unimplemented perfctr wrmsr: 0x%x data 0x%llx\n" , ecx, data);break ; +case MSR_VM_HSAVE_PA : + svm->hsave_msr = data; +break ;default :return kvm_set_msr_common (vcpu, ecx, data); }
arch/x86/kvm/x86.c +1 -1
@@ -452,7 +452,7 @@ static u32 msrs_to_save[] = {MSR_CSTAR ,MSR_KERNEL_GS_BASE ,MSR_SYSCALL_MASK ,MSR_LSTAR , #endifMSR_IA32_TIME_STAMP_COUNTER ,MSR_KVM_SYSTEM_TIME ,MSR_KVM_WALL_CLOCK , -MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT +MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA };static unsigned num_msrs_to_save;
Signature · 1 line
1.5.6
PATCH 6/12 Add VMLOAD and VMSAVE handlers v6
This implements the VMLOAD and VMSAVE instructions, that usually surround the VMRUN instructions. Both instructions load / restore the same elements, so we only need to implement them once.
v2 fixes CPL checking and replaces memcpy by assignments v3 makes use of the new permission checking
--- arch/x86/kvm/svm.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 58 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +58 -2
@@ -1256,6 +1256,62 @@ static int nested_svm_do(struct vcpu_svm *svm,return retval; } +static int nested_svm_vmloadsave (struct vmcb *from_vmcb,struct vmcb *to_vmcb) +{ + to_vmcb->save.fs = from_vmcb->save.fs; + to_vmcb->save.gs = from_vmcb->save.gs; + to_vmcb->save.tr = from_vmcb->save.tr; + to_vmcb->save.ldtr = from_vmcb->save.ldtr; + to_vmcb->save.kernel_gs_base = from_vmcb->save.kernel_gs_base; + to_vmcb->save.star = from_vmcb->save.star; + to_vmcb->save.lstar = from_vmcb->save.lstar; + to_vmcb->save.cstar = from_vmcb->save.cstar; + to_vmcb->save.sfmask = from_vmcb->save.sfmask; + to_vmcb->save.sysenter_cs = from_vmcb->save.sysenter_cs; + to_vmcb->save.sysenter_esp = from_vmcb->save.sysenter_esp; + to_vmcb->save.sysenter_eip = from_vmcb->save.sysenter_eip; + +return 1 ; +} + +static int nested_svm_vmload (struct vcpu_svm *svm,void *nested_vmcb, +void *arg2,void *opaque) +{ +return nested_svm_vmloadsave ((struct vmcb *)nested_vmcb, svm->vmcb); +} + +static int nested_svm_vmsave (struct vcpu_svm *svm,void *nested_vmcb, +void *arg2,void *opaque) +{ +return nested_svm_vmloadsave (svm->vmcb, (struct vmcb *)nested_vmcb); +} + +static int vmload_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) +{ +if (nested_svm_check_permissions (svm)) +return 1 ; + + svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; +skip_emulated_instruction (&svm->vcpu); + +nested_svm_do (svm, svm->vmcb->save.rax,0 ,NULL , nested_svm_vmload); + +return 1 ; +} + +static int vmsave_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) +{ +if (nested_svm_check_permissions (svm)) +return 1 ; + + svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; +skip_emulated_instruction (&svm->vcpu); + +nested_svm_do (svm, svm->vmcb->save.rax,0 ,NULL , nested_svm_vmsave); + +return 1 ; +} +static int stgi_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) {if (nested_svm_check_permissions (svm))
@@ -1591,8 +1647,8 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm, [SVM_EXIT_SHUTDOWN] = shutdown_interception, [SVM_EXIT_VMRUN] = invalid_op_interception, [SVM_EXIT_VMMCALL] = vmmcall_interception, - [SVM_EXIT_VMLOAD] = invalid_op_interception, - [SVM_EXIT_VMSAVE] = invalid_op_interception, + [SVM_EXIT_VMLOAD] = vmload_interception, + [SVM_EXIT_VMSAVE] = vmsave_interception, [SVM_EXIT_STGI] = stgi_interception, [SVM_EXIT_CLGI] = clgi_interception, [SVM_EXIT_SKINIT] = invalid_op_interception,
Signature · 1 line
1.5.6
PATCH 7/12 Add VMRUN handler v6
This patch implements VMRUN. VMRUN enters a virtual CPU and runs that in the same context as the normal guest CPU would run.
So basically it is implemented the same way, a normal CPU would do it.
We also prepare all intercepts that get OR'ed with the original intercepts, as we do not allow a level 2 guest to be intercepted less than the first level guest.
v2 implements the following improvements:
- fixes the CPL check
- does not allocate iopm when not used
- remembers the host's IF in the HIF bit in the hflags
v3:
- make use of the new permission checking
- add support for V_INTR_MASKING_MASK
v4:
- use host page backed hsave
v5:
- remove IOPM merging code
v6:
- save cr4 so PAE l1 guests work
--- arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/kvm_svm.h | 8 ++ arch/x86/kvm/svm.c | 157 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 165 insertions(+), 2 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -745,6 +745,8 @@ enum { };#define HF_GIF_MASK (1 << 0) +#define HF_HIF_MASK (1 << 1) +#define HF_VINTR_MASK (1 << 2)/* * Hardware virtualization extension instructions may fault if a
arch/x86/kvm/kvm_svm.h +8 -0
@@ -43,6 +43,14 @@ struct vcpu_svm {u32 *msrpm;struct vmcb *hsave;u64 hsave_msr; + +u64 nested_vmcb; + +/* These are the merged vectors */ +u32 *nested_msrpm; + +/* gpa pointers to the real vectors */ + u64 nested_vmcb_msrpm; };#endif
arch/x86/kvm/svm.c +155 -2
217 lines not on this page · raw message
Signature · 1 line
1.5.6
PATCH 8/12 Add VMEXIT handler and intercepts v6
This adds the #VMEXIT intercept, so we return to the level 1 guest when something happens in the level 2 guest that should return to the level 1 guest.
v2 implements HIF handling and cleans up exception interception v3 adds support for V_INTR_MASKING_MASK
v4 uses the host page hsave
v5 removes IOPM merging code
v6 moves mmu code out of the atomic section
--- arch/x86/kvm/svm.c | 293 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 293 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +293 -0
@@ -70,6 +70,13 @@ module_param(npt, int, S_IRUGO);static void kvm_reput_irq (struct vcpu_svm *svm);static void svm_flush_tlb (struct kvm_vcpu *vcpu); +static int nested_svm_exit_handled (struct vcpu_svm *svm,bool kvm_override); +static int nested_svm_vmexit (struct vcpu_svm *svm); +static int nested_svm_vmsave (struct vcpu_svm *svm,void *nested_vmcb, +void *arg2,void *opaque); +static int nested_svm_check_exception (struct vcpu_svm *svm,unsigned nr, +bool has_error_code,u32 error_code); +static inline struct vcpu_svm *to_svm (struct kvm_vcpu *vcpu) { return container_of(vcpu, struct vcpu_svm, vcpu);
@@ -219,6 +226,11 @@ static void svm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr, {struct vcpu_svm *svm =to_svm (vcpu); +/* If we are within a nested VM we'd better #VMEXIT and let the +guest handle the exception */ +if (nested_svm_check_exception (svm, nr, has_error_code, error_code)) +return ; + svm->vmcb->control.event_inj = nr |SVM_EVTINJ_VALID | (has_error_code ?SVM_EVTINJ_VALID_ERR :0 )
@@ -1211,6 +1223,46 @@ static int nested_svm_check_permissions(struct vcpu_svm *svm)return 0 ; } +static int nested_svm_check_exception (struct vcpu_svm *svm,unsigned nr, +bool has_error_code,u32 error_code) +{ +if (is_nested (svm)) { + svm->vmcb->control.exit_code =SVM_EXIT_EXCP_BASE + nr; + svm->vmcb->control.exit_code_hi =0 ; + svm->vmcb->control.exit_info_1 = error_code; + svm->vmcb->control.exit_info_2 = svm->vcpu.arch.cr2; +if (nested_svm_exit_handled (svm, false)) { +nsvm_printk ("VMexit -> EXCP 0x%x\n" , nr); + +nested_svm_vmexit (svm); +return 1 ; + } + } + +return 0 ; +} + +static inline int nested_svm_intr (struct vcpu_svm *svm) +{ +if (is_nested (svm)) { +if (!(svm->vcpu.arch.hflags &HF_VINTR_MASK )) +return 0 ; + +if (!(svm->vcpu.arch.hflags &HF_HIF_MASK )) +return 0 ; + + svm->vmcb->control.exit_code =SVM_EXIT_INTR ; + +if (nested_svm_exit_handled (svm, false)) { +nsvm_printk ("VMexit -> INTR\n" ); +nested_svm_vmexit (svm); +return 1 ; + } + } + +return 0 ; +} +static struct page *nested_svm_get_page (struct vcpu_svm *svm,u64 gpa) {struct page *page;
@@ -1271,6 +1323,228 @@ static int nested_svm_do(struct vcpu_svm *svm,return retval; } +static int nested_svm_exit_handled_real (struct vcpu_svm *svm, +void *arg1, +void *arg2, +void *opaque) +{ +struct vmcb *nested_vmcb = (struct vmcb *)arg1; +bool kvm_overrides = *(bool *)opaque; +u32 exit_code = svm->vmcb->control.exit_code; + +if (kvm_overrides) { +switch (exit_code) { +case SVM_EXIT_INTR : +case SVM_EXIT_NMI : +return 0 ; +/* For now we are always handling NPFs when using them */ +case SVM_EXIT_NPF : +if (npt_enabled) +return 0 ; +break ; +/* When we're shadowing, trap PFs */ +case SVM_EXIT_EXCP_BASE +PF_VECTOR : +if (!npt_enabled) +return 0 ; +break ; +default : +break ; + } + } + +switch (exit_code) { + case SVM_EXIT_READ_CR0 ... SVM_EXIT_READ_CR8: { +u32 cr_bits =1 << (exit_code -SVM_EXIT_READ_CR0 ); +if (nested_vmcb->control.intercept_cr_read & cr_bits) +return 1 ; +break ; + } + case SVM_EXIT_WRITE_CR0 ... SVM_EXIT_WRITE_CR8: { +u32 cr_bits =1 << (exit_code -SVM_EXIT_WRITE_CR0 ); +if (nested_vmcb->control.intercept_cr_write & cr_bits) +return 1 ; +break ; + } + case SVM_EXIT_READ_DR0 ... SVM_EXIT_READ_DR7: { +u32 dr_bits =1 << (exit_code -SVM_EXIT_READ_DR0 ); +if (nested_vmcb->control.intercept_dr_read & dr_bits) +return 1 ; +break ; + } + case SVM_EXIT_WRITE_DR0 ... SVM_EXIT_WRITE_DR7: { +u32 dr_bits =1 << (exit_code -SVM_EXIT_WRITE_DR0 ); +if (nested_vmcb->control.intercept_dr_write & dr_bits) +return 1 ; +break ; + } + case SVM_EXIT_EXCP_BASE ... SVM_EXIT_EXCP_BASE + 0x1f: { +u32 excp_bits =1 << (exit_code -SVM_EXIT_EXCP_BASE ); +if (nested_vmcb->control.intercept_exceptions & excp_bits) +return 1 ; +break ; + } +default : { +u64 exit_bits =1ULL << (exit_code -SVM_EXIT_INTR ); +nsvm_printk ("exit code: 0x%x\n" , exit_code); +if (nested_vmcb->control.intercept & exit_bits) +return 1 ; + } + } + +return 0 ; +} + +static int nested_svm_exit_handled_msr (struct vcpu_svm *svm, +void *arg1,void *arg2, +void *opaque) +{ +struct vmcb *nested_vmcb = (struct vmcb *)arg1; +u8 *msrpm = (u8 *)arg2; +u32 t0, t1; +u32 msr = svm->vcpu.arch.regs[VCPU_REGS_RCX ]; +u32 param = svm->vmcb->control.exit_info_1 &1 ; + +if (!(nested_vmcb->control.intercept & (1ULL <<INTERCEPT_MSR_PROT ))) +return 0 ; + +switch (msr) { + case 0 ... 0x1fff: + t0 = (msr *2 ) %8 ; + t1 = msr /8 ; +break ; + case 0xc0000000 ... 0xc0001fff: + t0 = (8192 + msr -0xc0000000 ) *2 ; + t1 = (t0 /8 ); + t0 %=8 ; +break ; + case 0xc0010000 ... 0xc0011fff: + t0 = (16384 + msr -0xc0010000 ) *2 ; + t1 = (t0 /8 ); + t0 %=8 ; +break ; +default : +return 1 ; +break ; + } +if (msrpm[t1] & ((1 << param) << t0)) +return 1 ; + +return 0 ; +} + +static int nested_svm_exit_handled (struct vcpu_svm *svm,bool kvm_override) +{ +bool k = kvm_override; + +switch (svm->vmcb->control.exit_code) { +case SVM_EXIT_MSR : +return nested_svm_do (svm, svm->nested_vmcb, + svm->nested_vmcb_msrpm,NULL , + nested_svm_exit_handled_msr); +default :break ; + } + +return nested_svm_do (svm, svm->nested_vmcb,0 , &k, + nested_svm_exit_handled_real); +} + +static int nested_svm_vmexit_real (struct vcpu_svm *svm,void *arg1, +void *arg2,void *opaque) +{ +struct vmcb *nested_vmcb = (struct vmcb *)arg1; +struct vmcb *hsave = svm->hsave; +u64 nested_save[] = { nested_vmcb->save.cr0, + nested_vmcb->save.cr3, + nested_vmcb->save.cr4, + nested_vmcb->save.efer, + nested_vmcb->control.intercept_cr_read, + nested_vmcb->control.intercept_cr_write, + nested_vmcb->control.intercept_dr_read, + nested_vmcb->control.intercept_dr_write, + nested_vmcb->control.intercept_exceptions, + nested_vmcb->control.intercept, + nested_vmcb->control.msrpm_base_pa, + nested_vmcb->control.iopm_base_pa, + nested_vmcb->control.tsc_offset }; + +/* Give the current vmcb to the guest */ +memcpy (nested_vmcb, svm->vmcb,sizeof (struct vmcb )); + nested_vmcb->save.cr0 = nested_save[0 ]; +if (!npt_enabled) + nested_vmcb->save.cr3 = nested_save[1 ]; + nested_vmcb->save.cr4 = nested_save[2 ]; + nested_vmcb->save.efer = nested_save[3 ]; + nested_vmcb->control.intercept_cr_read = nested_save[4 ]; + nested_vmcb->control.intercept_cr_write = nested_save[5 ]; + nested_vmcb->control.intercept_dr_read = nested_save[6 ]; + nested_vmcb->control.intercept_dr_write = nested_save[7 ]; + nested_vmcb->control.intercept_exceptions = nested_save[8 ]; + nested_vmcb->control.intercept = nested_save[9 ]; + nested_vmcb->control.msrpm_base_pa = nested_save[10 ]; + nested_vmcb->control.iopm_base_pa = nested_save[11 ]; + nested_vmcb->control.tsc_offset = nested_save[12 ]; + +/* We always set V_INTR_MASKING and remember the old value in hflags */ +if (!(svm->vcpu.arch.hflags &HF_VINTR_MASK )) + nested_vmcb->control.int_ctl &= ~V_INTR_MASKING_MASK ; + +if ((nested_vmcb->control.int_ctl &V_IRQ_MASK ) && + (nested_vmcb->control.int_vector)) { +nsvm_printk ("WARNING: IRQ 0x%x still enabled on #VMEXIT\n" , + nested_vmcb->control.int_vector); + } + +/* Restore the original control entries */ + svm->vmcb->control = hsave->control; + +/* Kill any pending exceptions */ +if (svm->vcpu.arch.exception.pending == true) +nsvm_printk ("WARNING: Pending Exception\n" ); + svm->vcpu.arch.exception.pending = false; + +/* Restore selected save entries */ + svm->vmcb->save.es = hsave->save.es; + svm->vmcb->save.cs = hsave->save.cs; + svm->vmcb->save.ss = hsave->save.ss; + svm->vmcb->save.ds = hsave->save.ds; + svm->vmcb->save.gdtr = hsave->save.gdtr; + svm->vmcb->save.idtr = hsave->save.idtr; + svm->vmcb->save.rflags = hsave->save.rflags; +svm_set_efer (&svm->vcpu, hsave->save.efer); +svm_set_cr0 (&svm->vcpu, hsave->save.cr0 |X86_CR0_PE ); +svm_set_cr4 (&svm->vcpu, hsave->save.cr4); +if (npt_enabled) { + svm->vmcb->save.cr3 = hsave->save.cr3; + svm->vcpu.arch.cr3 = hsave->save.cr3; + }else { +kvm_set_cr3 (&svm->vcpu, hsave->save.cr3); + } +kvm_register_write (&svm->vcpu,VCPU_REGS_RAX , hsave->save.rax); +kvm_register_write (&svm->vcpu,VCPU_REGS_RSP , hsave->save.rsp); +kvm_register_write (&svm->vcpu,VCPU_REGS_RIP , hsave->save.rip); + svm->vmcb->save.dr7 =0 ; + svm->vmcb->save.cpl =0 ; + svm->vmcb->control.exit_int_info =0 ; + + svm->vcpu.arch.hflags &= ~HF_GIF_MASK ; +/* Exit nested SVM mode */ + svm->nested_vmcb =0 ; + +return 0 ; +} + +static int nested_svm_vmexit (struct vcpu_svm *svm) +{ +nsvm_printk ("VMexit\n" ); +if (nested_svm_do (svm, svm->nested_vmcb,0 , +NULL , nested_svm_vmexit_real)) +return 1 ; + +kvm_mmu_reset_context (&svm->vcpu); +kvm_mmu_load (&svm->vcpu); + +return 0 ; +}static int nested_svm_vmrun_msrpm (struct vcpu_svm *svm,void *arg1,void *arg2,void *opaque)
@@ -1818,6 +2092,17 @@ static int handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)KVMTRACE_3D (VMEXIT , vcpu, exit_code, (u32 )svm->vmcb->save.rip, (u32)((u64 )svm->vmcb->save.rip >>32 ), entryexit); +if (is_nested (svm)) { +nsvm_printk ("nested handle_exit: 0x%x | 0x%lx | 0x%lx | 0x%lx\n" , + exit_code, svm->vmcb->control.exit_info_1, + svm->vmcb->control.exit_info_2, svm->vmcb->save.rip); +if (nested_svm_exit_handled (svm, true)) { +nested_svm_vmexit (svm); +nsvm_printk ("-> #VMEXIT\n" ); +return 1 ; + } + } +if (npt_enabled) {int mmu_reload =0 ;if ((vcpu->arch.cr0 ^ svm->vmcb->save.cr0) &X86_CR0_PG ) {
@@ -1905,6 +2190,8 @@ static void svm_set_irq(struct kvm_vcpu *vcpu, int irq) {struct vcpu_svm *svm =to_svm (vcpu); +nested_svm_intr (svm); +svm_inject_irq (svm, irq); }
@@ -1950,6 +2237,9 @@ static void svm_intr_assist(struct kvm_vcpu *vcpu)if (!kvm_cpu_has_interrupt (vcpu)) goto out; +if (nested_svm_intr (svm)) + goto out; +if (!(svm->vcpu.arch.hflags &HF_GIF_MASK )) goto out;
@@ -2003,6 +2293,9 @@ static void do_interrupt_requests(struct kvm_vcpu *vcpu,struct vcpu_svm *svm =to_svm (vcpu);struct vmcb_control_area *control = &svm->vmcb->control; +if (nested_svm_intr (svm)) +return ; + svm->vcpu.arch.interrupt_window_open = (!(control->int_state & SVM_INTERRUPT_SHADOW_MASK) && (svm->vmcb->save.rflags & X86_EFLAGS_IF) &&
Signature · 1 line
1.5.6
PATCH 9/12 Allow read access to MSR_VM_VR v6
From: Joerg Roedel <[email protected]>
KVM tries to read the VM_CR MSR to find out if SVM was disabled by the BIOS. So implement read support for this MSR to make nested SVM running.
--- arch/x86/kvm/svm.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +3 -0
@@ -1882,6 +1882,9 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)case MSR_VM_HSAVE_PA : *data = svm->hsave_msr;break ; +case MSR_VM_CR : + *data =0 ; +break ;default :return kvm_get_msr_common (vcpu, ecx, data); }
Signature · 1 line
1.5.6
PATCH 10/12 Allow setting the SVME bit v6
Normally setting the SVME bit in EFER is not allowed, as we did not support SVM. Not since we do, we should also allow enabling SVM mode.
v2 comes as last patch, so we don't enable half-ready code v4 introduces a module option to enable SVM
v6 warns that nesting is enabled
--- arch/x86/kvm/svm.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +8 -0
@@ -67,6 +67,9 @@ static int npt = 1;module_param (npt, int,S_IRUGO ); +static int nested =0 ; +module_param (nested, int,S_IRUGO ); +static void kvm_reput_irq (struct vcpu_svm *svm);static void svm_flush_tlb (struct kvm_vcpu *vcpu);
@@ -456,6 +459,11 @@ static __init int svm_hardware_setup(void)if (boot_cpu_has (X86_FEATURE_NX ))kvm_enable_efer_bits (EFER_NX ); +if (nested) { +printk (KERN_INFO "kvm: Nested Virtualization enabled\n" ); +kvm_enable_efer_bits (EFER_SVME ); + } +for_each_online_cpu (cpu) { r =svm_cpu_init (cpu);if (r)
Signature · 1 line
1.5.6
PATCH 11/12 Only allow setting of EFER_SVME when CPUID SVM is set v6
Userspace has to tell the kernel module somehow that nested SVM should be used. The easiest way that doesn't break anything I could think of is to implement
if (cpuid & svm)
allow write to efer
else
deny write to efer
Old userspaces mask the SVM capability bit, so they don't break. In order to find out that the SVM capability is set, I had to split the kvm_emulate_cpuid into a finding and an emulating part.
(introduced in v6)
--- arch/x86/kvm/x86.c | 58 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 42 insertions(+), 16 deletions(-)
arch/x86/kvm/x86.c +42 -16
@@ -68,6 +68,8 @@ static u64 __read_mostly efer_reserved_bits = 0xfffffffffffffffeULL;static int kvm_dev_ioctl_get_supported_cpuid (struct kvm_cpuid2 *cpuid,struct kvm_cpuid_entry2 __user *entries); +struct kvm_cpuid_entry2 *kvm_find_cpuid_entry (struct kvm_vcpu *vcpu, +u32 function,u32 index);struct kvm_x86_ops *kvm_x86_ops;EXPORT_SYMBOL_GPL (kvm_x86_ops);
@@ -171,6 +173,7 @@ void kvm_inject_page_fault(struct kvm_vcpu *vcpu, unsigned long addr, u32 error_code) { ++vcpu->stat.pf_guest; +if (vcpu->arch.exception.pending) {if (vcpu->arch.exception.nr ==PF_VECTOR ) { printk(KERN_DEBUG "kvm: inject_page_fault:"
@@ -438,6 +441,11 @@ unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu) }EXPORT_SYMBOL_GPL (kvm_get_cr8); +static inline u32 bit (int bitno) +{ +return 1 << (bitno &31 ); +} +/* * List of msr numbers which we expose to userspace through KVM_GET_MSRS * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
@@ -477,6 +485,17 @@ static void set_efer(struct kvm_vcpu *vcpu, u64 efer)return ; } +if (efer &EFER_SVME ) { +struct kvm_cpuid_entry2 *feat; + + feat =kvm_find_cpuid_entry (vcpu,0x80000001 ,0 ); +if (!feat || !(feat->ecx &bit (X86_FEATURE_SVM ))) { +printk (KERN_DEBUG "set_efer: #GP, enable SVM w/o SVM\n" ); +kvm_inject_gp (vcpu,0 ); +return ; + } + } + kvm_x86_ops->set_efer (vcpu, efer); efer &= ~EFER_LMA ;
@@ -1176,11 +1195,6 @@ out:return r; } -static inline u32 bit (int bitno) -{ -return 1 << (bitno &31 ); -} -static void do_cpuid_1_ent (struct kvm_cpuid_entry2 *entry,u32 function,u32 index) {
@@ -1223,7 +1237,8 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,const u32 kvm_supported_word3_x86_features =bit (X86_FEATURE_XMM3 ) |bit (X86_FEATURE_CX16 );const u32 kvm_supported_word6_x86_features = -bit (X86_FEATURE_LAHF_LM ) |bit (X86_FEATURE_CMP_LEGACY ); +bit (X86_FEATURE_LAHF_LM ) |bit (X86_FEATURE_CMP_LEGACY ) | +bit (X86_FEATURE_SVM );/* all func 2 cpuid_count() should be called on the same cpu */ get_cpu ();
@@ -2827,20 +2842,15 @@ static int is_matching_cpuid_entry(struct kvm_cpuid_entry2 *e,return 1 ; } -void kvm_emulate_cpuid (struct kvm_vcpu *vcpu) +struct kvm_cpuid_entry2 *kvm_find_cpuid_entry (struct kvm_vcpu *vcpu, +u32 function,u32 index) {int i; -u32 function, index; -struct kvm_cpuid_entry2 *e, *best; +struct kvm_cpuid_entry2 *best =NULL ; - function =kvm_register_read (vcpu,VCPU_REGS_RAX ); - index =kvm_register_read (vcpu,VCPU_REGS_RCX ); -kvm_register_write (vcpu,VCPU_REGS_RAX ,0 ); -kvm_register_write (vcpu,VCPU_REGS_RBX ,0 ); -kvm_register_write (vcpu,VCPU_REGS_RCX ,0 ); -kvm_register_write (vcpu,VCPU_REGS_RDX ,0 ); - best =NULL ;for (i =0 ; i < vcpu->arch.cpuid_nent; ++i) { +struct kvm_cpuid_entry2 *e; + e = &vcpu->arch.cpuid_entries[i];if (is_matching_cpuid_entry (e, function, index)) {if (e->flags &KVM_CPUID_FLAG_STATEFUL_FUNC )
@@ -2855,6 +2865,22 @@ void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)if (!best || e->function > best->function) best = e; } + +return best; +} + +void kvm_emulate_cpuid (struct kvm_vcpu *vcpu) +{ +u32 function, index; +struct kvm_cpuid_entry2 *best; + + function =kvm_register_read (vcpu,VCPU_REGS_RAX ); + index =kvm_register_read (vcpu,VCPU_REGS_RCX ); +kvm_register_write (vcpu,VCPU_REGS_RAX ,0 ); +kvm_register_write (vcpu,VCPU_REGS_RBX ,0 ); +kvm_register_write (vcpu,VCPU_REGS_RCX ,0 ); +kvm_register_write (vcpu,VCPU_REGS_RDX ,0 ); + best =kvm_find_cpuid_entry (vcpu, function, index);if (best) {kvm_register_write (vcpu,VCPU_REGS_RAX , best->eax);kvm_register_write (vcpu,VCPU_REGS_RBX , best->ebx);
Signature · 1 line
1.5.6
PATCH 12/12 Accelerate nested SVM by emulating parts of GIF=0 v6
Until this patch we bounced between the VM and the VMM for a couple of instructions after CLGI, only to find out that yet another SVM instruction follows.
Since roundtrips are really expensive, it's a lot faster to emulate these few instructions. Now we can execute CLGI/VMLOAD/VMRUN on one intercept and VMEXIT/VMSAVE on another. This is a major speed improvement!
(introduced in v6, optional)
--- arch/x86/kvm/svm.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 69 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +69 -0
@@ -79,6 +79,11 @@ static int nested_svm_vmsave(struct vcpu_svm *svm, void *nested_vmcb, void *arg2, void *opaque);static int nested_svm_check_exception (struct vcpu_svm *svm,unsigned nr,bool has_error_code,u32 error_code); +static int vmload_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run); +static int vmsave_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run); +static int vmrun_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run); +static int stgi_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run); +static inline struct vcpu_svm *to_svm (struct kvm_vcpu *vcpu) {
@@ -1456,6 +1461,50 @@ static int nested_svm_exit_handled(struct vcpu_svm *svm, bool kvm_override) nested_svm_exit_handled_real); } +static int nested_svm_emulate (struct vcpu_svm *svm,struct kvm_run *kvm_run) +{ +int er; +u32 opcode =0 ; +unsigned long rip; +unsigned long rip_linear; + + svm->vmcb->save.rax = svm->vcpu.arch.regs[VCPU_REGS_RAX ]; + svm->vmcb->save.rsp = svm->vcpu.arch.regs[VCPU_REGS_RSP ]; + svm->vmcb->save.rip = svm->vcpu.arch.regs[VCPU_REGS_RIP ]; + rip = svm->vcpu.arch.regs[VCPU_REGS_RIP ]; + rip_linear = rip +svm_seg (&svm->vcpu,VCPU_SREG_CS )->base; + + er =emulator_read_std (rip_linear, (void *)&opcode,3 , &svm->vcpu); +if (er !=X86EMUL_CONTINUE ) +return er; + er =EMULATE_FAIL ; + +switch (opcode) { +case 0xda010f : +vmload_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +case 0xd8010f : +vmrun_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +case 0xdb010f : +vmsave_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +case 0xdc010f : +stgi_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +default : +nsvm_printk ("NSVM: Opcode %x unknown\n" , opcode); + } + +nsvm_printk ("NSVM: svm emul at 0x%lx -> %d\n" , rip, er); + +return er; +} +static int nested_svm_vmexit_real (struct vcpu_svm *svm,void *arg1,void *arg2,void *opaque) {
@@ -1551,6 +1600,9 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)kvm_mmu_reset_context (&svm->vcpu);kvm_mmu_load (&svm->vcpu); +/* KVM calls vmsave after vmrun, so let's run it now if we can */ +nested_svm_emulate (svm,NULL ); +return 0 ; }
@@ -1773,6 +1825,23 @@ static int clgi_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)svm_clear_vintr (svm); svm->vmcb->control.int_ctl &= ~V_IRQ_MASK ; +/* Let's try to emulate as many instructions as possible in GIF=0 */ + +while (true) { +int er; + + er =emulate_instruction (&svm->vcpu, kvm_run,0 ,0 ,0 ); +nsvm_printk ("NSVM: emulating at 0x%lx -> %d\n" , svm->vcpu.arch.regs[VCPU_REGS_RIP ], er); + +/* So we can now emulate the SVM instructions that most probably +occur at the end of the codepath */ +if (er !=EMULATE_DONE ) { +while (true) +if (nested_svm_emulate (svm, kvm_run) ==EMULATE_FAIL ) +break ; +break ; + } + }return 1 ; }
Signature · 1 line
1.5.6
Re: [PATCH 12/12] Accelerate nested SVM by emulating parts of GIF=0 v6
Quoted 9 lines · Alexander Graf
Until this patch we bounced between the VM and the VMM for a couple of instructions after CLGI, only to find out that yet another SVM instruction follows.
Since roundtrips are really expensive, it's a lot faster to emulate these few instructions. Now we can execute CLGI/VMLOAD/VMRUN on one intercept and VMEXIT/VMSAVE on another. This is a major speed improvement!
Neat trick. Have you looked at svm.c to see if we can cut out extraneous instructions (or move them out of the gif=0 area)? Could mean big savings.
Quoted 35 lines
arch/x86/kvm/svm.c +34
-0+static int nested_svm_emulate (struct vcpu_svm *svm,struct kvm_run *kvm_run) +{ +int er; +u32 opcode =0 ; +unsigned long rip; +unsigned long rip_linear; + + svm->vmcb->save.rax = svm->vcpu.arch.regs[VCPU_REGS_RAX ]; + svm->vmcb->save.rsp = svm->vcpu.arch.regs[VCPU_REGS_RSP ]; + svm->vmcb->save.rip = svm->vcpu.arch.regs[VCPU_REGS_RIP ]; + rip = svm->vcpu.arch.regs[VCPU_REGS_RIP ]; + rip_linear = rip +svm_seg (&svm->vcpu,VCPU_SREG_CS )->base; + + er =emulator_read_std (rip_linear, (void *)&opcode,3 , &svm->vcpu); +if (er !=X86EMUL_CONTINUE ) +return er; + er =EMULATE_FAIL ; + +switch (opcode) { +case 0xda010f : +vmload_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +case 0xd8010f : +vmrun_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +case 0xdb010f : +vmsave_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +case 0xdc010f : +stgi_interception (svm, kvm_run); + er =EMULATE_DONE ;
arch/x86/kvm/svm.c static int nested_svm_exit_handled(struct vcpu_svm *svm, bool kvm_override) · line 1507
Quoted 10 lines
arch/x86/kvm/svm.c +10
-0+break ; +default : +nsvm_printk ("NSVM: Opcode %x unknown\n" , opcode); + } + +nsvm_printk ("NSVM: svm emul at 0x%lx -> %d\n" , rip, er); + +return er; +} +
Move to the regular x86 emulator, so if we extend it with debug flag support, privilege checking, etc, we get that for svm as well.
arch/x86/kvm/svm.c static int nested_svm_vmexit(struct vcpu_svm *svm) · line 1606
Quoted 11 lines
static int nested_svm_vmexit_real(struct
vcpu_svm*svm, void *arg1,arch/x86/kvm/svm.c +3
-0void *arg2, void *opaque) {@@ -1551,6 +1600,9 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)kvm_mmu_reset_context (&svm->vcpu);kvm_mmu_load (&svm->vcpu); +/* KVM calls vmsave after vmrun, so let's run it now if we can */ +nested_svm_emulate (svm,NULL ); +
Will also call stgi eventually, so it may make sense to loop here too.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Re: [PATCH 12/12] Accelerate nested SVM by emulating parts of GIF=0 v6
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Alexander Graf
Until this patch we bounced between the VM and the VMM for a couple of instructions after CLGI, only to find out that yet another SVM instruction follows.
Since roundtrips are really expensive, it's a lot faster to emulate these few instructions. Now we can execute CLGI/VMLOAD/VMRUN on one intercept and VMEXIT/VMSAVE on another. This is a major speed improvement!
Quoted 1 line
Neat trick. Have you looked at
svm.cto see if we can cut out extraneous instructions (or move them out of the gif=0 area)? Could mean big savings.
Well for now I only emulate pre-vmrun and vmsave, because the emulator breaks on lldt and set dr6 and ltr and ...
Quoted 42 lines
Quoted 42 lines
+static int
nested_svm_emulate(struct vcpu_svm *svm, struct kvm_run *kvm_run)arch/x86/kvm/svm.c +38
-0+{ +int er; +u32 opcode =0 ; +unsigned long rip; +unsigned long rip_linear; + + svm->vmcb->save.rax = svm->vcpu.arch.regs[VCPU_REGS_RAX ]; + svm->vmcb->save.rsp = svm->vcpu.arch.regs[VCPU_REGS_RSP ]; + svm->vmcb->save.rip = svm->vcpu.arch.regs[VCPU_REGS_RIP ]; + rip = svm->vcpu.arch.regs[VCPU_REGS_RIP ]; + rip_linear = rip +svm_seg (&svm->vcpu,VCPU_SREG_CS )->base; + + er =emulator_read_std (rip_linear, (void *)&opcode,3 , &svm->vcpu); +if (er !=X86EMUL_CONTINUE ) +return er; + er =EMULATE_FAIL ; + +switch (opcode) { +case 0xda010f : +vmload_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +case 0xd8010f : +vmrun_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +case 0xdb010f : +vmsave_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +case 0xdc010f : +stgi_interception (svm, kvm_run); + er =EMULATE_DONE ; +break ; +default : +nsvm_printk ("NSVM: Opcode %x unknown\n" , opcode); + } +
Quoted 8 lines
arch/x86/kvm/svm.c static int nested_svm_exit_handled(struct vcpu_svm *svm, bool kvm_override) · line 1507
Quoted 6 lines
arch/x86/kvm/svm.c +5
-0+nsvm_printk ("NSVM: svm emul at 0x%lx -> %d\n" , rip, er); + +return er; +} +Move to the regular x86 emulator, so if we extend it with debug flag support, privilege checking, etc, we get that for svm as well.
Do you seriously want to have a callback to svm specific code in the x86 emulator? I was thinking of doing that, but this way looked way cleaner to me. I would actually rather use prefixes as hint on pattern matching. So e.g. if we find a clgi instruction with some random prefix (or somehow marked in other ways) we could just run a pattern that does what the entry code would do. This way no emulation would be needed.
Quoted 15 lines
arch/x86/kvm/svm.c static int nested_svm_vmexit(struct vcpu_svm · line 1606
Quoted 13 lines
static int nested_svm_vmexit_real(struct
vcpu_svm*svm, void *arg1,
void *arg2, void *opaque)
{arch/x86/kvm/svm.c +3
-0@@ -1551,6 +1600,9 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)kvm_mmu_reset_context (&svm->vcpu);kvm_mmu_load (&svm->vcpu); +/* KVM calls vmsave after vmrun, so let's run it now if we can */ +nested_svm_emulate (svm,NULL ); +Will also call stgi eventually, so it may make sense to loop here too.
See above - I did that, it broke, I tried to debug it for ~2 days and just figured I'll leave it as is for now. The current version gives _huge_ savings already.
Alex
Re: [PATCH 12/12] Accelerate nested SVM by emulating parts of GIF=0 v6
Quoted 5 lines · Alexander Graf
Quoted 2 lines
Neat trick. Have you looked at
svm.cto see if we can cut out extraneous instructions (or move them out of the gif=0 area)? Could mean big savings.Well for now I only emulate pre-vmrun and vmsave, because the emulator breaks on lldt and set dr6 and ltr and ...
Yeah. We could move some of these out, and emulate the rest (ltr I think is needed).
Quoted 4 lines
Quoted 2 lines
Move to the regular x86 emulator, so if we extend it with debug flag support, privilege checking, etc, we get that for svm as well.
Do you seriously want to have a callback to svm specific code in the x86 emulator?
That's what kvm_x86_ops is for. We already emulate vendor specific instructions (vmcall and vmmcall).
Quoted 2 lines
I was thinking of doing that, but this way looked way cleaner to me. I would actually rather use prefixes as hint on pattern matching.
So e.g. if we find a clgi instruction with some random prefix (or somehow marked in other ways) we could just run a pattern that does what the entry code would do. This way no emulation would be needed.
Smells like dynamic translation to me. I don't see how you could do that generically -- it might work for one version of kvm, but not for other hypervisors.
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
static int nested_svm_vmexit_real(struct
vcpu_svm*svm, void *arg1,
void *arg2, void *opaque)
{(quoted diff) +0
-0@@ -1551,6 +1600,9 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)Quoted 8 lines
arch/x86/kvm/svm.c static int nested_svm_vmexit(struct vcpu_svm *svm) · line 1608
Quoted 6 lines
arch/x86/kvm/svm.c +3
-0kvm_mmu_reset_context (&svm->vcpu);kvm_mmu_load (&svm->vcpu); +/* KVM calls vmsave after vmrun, so let's run it now if we can */ +nested_svm_emulate (svm,NULL ); +Will also call stgi eventually, so it may make sense to loop here too.
Quoted 1 line
See above - I did that, it broke, I tried to debug it for ~2 days and just figured I'll leave it as is for now.
Certainly, we can leave it for later.
Quoted 1 line
The current version gives _huge_ savings already.
Can you quantify?
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Re: [PATCH 12/12] Accelerate nested SVM by emulating parts of GIF=0 v6
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Alexander Graf
Quoted 2 lines
Neat trick. Have you looked at
svm.cto see if we can cut out extraneous instructions (or move them out of the gif=0 area)? Could mean big savings.Well for now I only emulate pre-vmrun and vmsave, because the emulator breaks on lldt and set dr6 and ltr and ...
Yeah. We could move some of these out, and emulate the rest (ltr I think is needed).
Then older versions of kvm would still break and other hypervisors have a high chance of failing as well. It would be better to implement the instructions in the emulator first, but I'm somewhat lost in that code base.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Move to the regular x86 emulator, so if we extend it with debug flag support, privilege checking, etc, we get that for svm as well.
Do you seriously want to have a callback to svm specific code in the x86 emulator?
That's what
kvm_x86_opsis for. We already emulate vendor specific instructions (vmcall and vmmcall).
From what I can tell kvm_x86_ops tries to multiplex calls that happen to be different on svm/vmx, but existent on both. SVM instructions usually don't appear on VMX ;-).
Quoted 4 lines
Quoted 2 lines
I was thinking of doing that, but this way looked way cleaner to me. I would actually rather use prefixes as hint on pattern matching.
So e.g. if we find a clgi instruction with some random prefix (or somehow marked in other ways) we could just run a pattern that does what the entry code would do. This way no emulation would be needed.Smells like dynamic translation to me. I don't see how you could do that generically -- it might work for one version of kvm, but not for other hypervisors.
Yes, this would require one pattern for one series of kvm revisions. As long as that particular code path doesn't change too much, we should be fine. And usually it doesn't. We just have to take paravirt_ops and the like from the equation.
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 12 lines
static int nested_svm_vmexit_real(struct
vcpu_svm*svm, void *arg1,
void *arg2, void *opaque)
{arch/x86/kvm/svm.c +1
-0@@ -1551,6 +1600,9 @@ static int nested_svm_vmexit(struct vcpu_svm *svm) kvm_mmu_reset_context(&svm->vcpu);kvm_mmu_load (&svm->vcpu); +/* KVM calls vmsave after vmrun, so let's run it now if we can */
arch/x86/kvm/svm.c static int nested_svm_vmexit(struct vcpu_svm *svm) · line 1605
Quoted 2 lines
arch/x86/kvm/svm.c +2
-0+nested_svm_emulate (svm,NULL ); +Will also call stgi eventually, so it may make sense to loop here too.
Quoted 7 lines
Quoted 1 line
See above - I did that, it broke, I tried to debug it for ~2 days and just figured I'll leave it as is for now.
Certainly, we can leave it for later.
Quoted 1 line
The current version gives _huge_ savings already.
Can you quantify?
Subjective speedup was like three times. But I could be wrong. I haven't measured it, since I wanted to have a "full GIF=0 emulation" (which I failed on) for measurement.
I'm off for a short weekend vacation - and be back on tuesday. I probably will be mostly offline in between.
Alex
Re: [PATCH 12/12] Accelerate nested SVM by emulating parts of GIF=0 v6
Quoted 4 lines · Alexander Graf
Quoted 2 lines
Yeah. We could move some of these out, and emulate the rest (ltr I think is needed).
Then older versions of kvm would still break
If emulation fails, go back to virtualization. Or am I missing something?
Quoted 4 lines
Quoted 2 lines
That's what
kvm_x86_opsis for. We already emulate vendor specific instructions (vmcall and vmmcall).From what I can tell
kvm_x86_opstries to multiplex calls that happen to be different on svm/vmx, but existent on both. SVM instructions usually don't appear on VMX ;-).
Right. But so what? I don't want to lose any future improvements the emulator may have (like traps on debug register, etc).
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Re: [PATCH 12/12] Accelerate nested SVM by emulating parts of GIF=0 v6
Quoted 8 lines · Avi Kivity
Quoted 4 lines · Alexander Graf
Quoted 2 lines
Yeah. We could move some of these out, and emulate the rest (ltr I think is needed).
Then older versions of kvm would still break
If emulation fails, go back to virtualization. Or am I missing something?
Yes, and exactly that part broke for me too. I just gave up at one point.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
That's what
kvm_x86_opsis for. We already emulate vendor specific instructions (vmcall and vmmcall).From what I can tell
kvm_x86_opstries to multiplex calls that happen to be different on svm/vmx, but existent on both. SVM instructions usually don't appear on VMX ;-).Right. But so what? I don't want to lose any future improvements the emulator may have (like traps on debug register, etc).
Hum, makes sense.
Quoted 7 lines
Signature · 3 lines
-- I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Re: [PATCH 07/12] Add VMRUN handler v6
In reply to Alexander GrafQuoted 6 lines · Alexander Graf
arch/x86/kvm/svm.c +6
-0+static int vmrun_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) +{ +nsvm_printk ("VMrun\n" ); +if (nested_svm_check_permissions (svm)) +return 1 ; +
arch/x86/kvm/svm.c static int vmsave_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) · line 1462
Quoted 10 lines
arch/x86/kvm/svm.c +10
-0+ svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; +skip_emulated_instruction (&svm->vcpu); + +if (nested_svm_do (svm, svm->vmcb->save.rax,0 , +NULL , nested_svm_vmrun)) +return 1 ; + +if (nested_svm_do (svm, svm->vmcb->control.msrpm_base_pa,0 , +NULL , nested_svm_vmrun_msrpm)) +return 1 ;
nested_svm_vmrun returns 1 unconditionally, so we never call nested_svm_vmrun_msrpm.
Cheers,
Muli
Signature · 5 lines
The First Workshop on I/O Virtualization (WIOV '08)
Dec 2008, San Diego, CA, http://www.usenix.org/wiov08/
<->
SYSTOR 2009---The Israeli Experimental Systems Conference
http://www.haifa.il.ibm.com/conferences/systor2009/Re: [PATCH 07/12] Add VMRUN handler v6
Quoted 15 lines · Muli Ben-Yehuda
Quoted 12 lines · Alexander Graf
arch/x86/kvm/svm.c +12
-0+static int vmrun_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) +{ +nsvm_printk ("VMrun\n" ); +if (nested_svm_check_permissions (svm)) +return 1 ; + + svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; +skip_emulated_instruction (&svm->vcpu); + +if (nested_svm_do (svm, svm->vmcb->save.rax,0 , +NULL , nested_svm_vmrun)) +return 1 ;
Quoted 9 lines
arch/x86/kvm/svm.c static int vmsave_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) · line 1462
Quoted 5 lines
arch/x86/kvm/svm.c +4
-0+ +if (nested_svm_do (svm, svm->vmcb->control.msrpm_base_pa,0 , +NULL , nested_svm_vmrun_msrpm)) +return 1 ;
nested_svm_vmrunreturns 1 unconditionally, so we never callnested_svm_vmrun_msrpm.
Wow the one thing you pointed out earlier. I must've missed to write that on my TODO list.
I'll fix this right now :). Await v7 any second now.
Alex
Re: [PATCH 07/12] Add VMRUN handler v6
Quoted 29 lines · Alexander Graf
Quoted 16 lines · Muli Ben-Yehuda
Quoted 12 lines · Alexander Graf
arch/x86/kvm/svm.c +12
-0+static int vmrun_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) +{ +nsvm_printk ("VMrun\n" ); +if (nested_svm_check_permissions (svm)) +return 1 ; + + svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; +skip_emulated_instruction (&svm->vcpu); + +if (nested_svm_do (svm, svm->vmcb->save.rax,0 , +NULL , nested_svm_vmrun)) +return 1 ;Quoted 10 lines
arch/x86/kvm/svm.c static int vmsave_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) · line 1462
Quoted 6 lines
arch/x86/kvm/svm.c +4
-0+ +if (nested_svm_do (svm, svm->vmcb->control.msrpm_base_pa,0 , +NULL , nested_svm_vmrun_msrpm)) +return 1 ;
nested_svm_vmrunreturns 1 unconditionally, so we never callnested_svm_vmrun_msrpm.
Quoted 4 lines
Wow the one thing you pointed out earlier. I must've missed to write that on my TODO list.
I'll fix this right now :). Await v7 any second now.
Wow this is more tricky than I thought. I gotta go now, but I'll look into it in more detail on Tuesday. I promise :-). For now please just don't use the MSR check.
Alex
Re: [PATCH 07/12] Add VMRUN handler v6
Quoted 30 lines · Alexander Graf
Quoted 29 lines · Alexander Graf
Quoted 26 lines · Muli Ben-Yehuda
Quoted 8 lines · Alexander Graf
arch/x86/kvm/svm.c +6
-0+static int vmrun_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) +{ +nsvm_printk ("VMrun\n" ); +if (nested_svm_check_permissions (svm)) +return 1 ; +arch/x86/kvm/svm.c static int vmsave_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) · line 1462
Quoted 10 lines
arch/x86/kvm/svm.c +10
-0+ svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; +skip_emulated_instruction (&svm->vcpu); + +if (nested_svm_do (svm, svm->vmcb->save.rax,0 , +NULL , nested_svm_vmrun)) +return 1 ; + +if (nested_svm_do (svm, svm->vmcb->control.msrpm_base_pa,0 , +NULL , nested_svm_vmrun_msrpm)) +return 1 ;
nested_svm_vmrunreturns 1 unconditionally, so we never callnested_svm_vmrun_msrpm.
Quoted 8 lines
Quoted 4 lines
Wow the one thing you pointed out earlier. I must've missed to write that on my TODO list.
I'll fix this right now :). Await v7 any second now.Wow this is more tricky than I thought. I gotta go now, but I'll look into it in more detail on Tuesday. I promise :-). For now please just don't use the MSR check.
No problem. While you are looking at it, another question: In the vmrun handler, we call kvm_mmu_reset_context() in the SPT case only. In the vmexit handler, we call kvm_mmu_reset_context() for both SPT and NPT. Why the discrepancy?
Cheers,
Muli
Signature · 5 lines
The First Workshop on I/O Virtualization (WIOV '08)
Dec 2008, San Diego, CA, http://www.usenix.org/wiov08/
<->
SYSTOR 2009---The Israeli Experimental Systems Conference
http://www.haifa.il.ibm.com/conferences/systor2009/Re: [PATCH 07/12] Add VMRUN handler v6
Quoted 37 lines · Muli Ben-Yehuda
Quoted 36 lines · Alexander Graf
Quoted 34 lines · Alexander Graf
Quoted 17 lines · Muli Ben-Yehuda
Quoted 13 lines · Alexander Graf
+static int
vmrun_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)arch/x86/kvm/svm.c +11
-0+{ +nsvm_printk ("VMrun\n" ); +if (nested_svm_check_permissions (svm)) +return 1 ; + + svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; +skip_emulated_instruction (&svm->vcpu); + +if (nested_svm_do (svm, svm->vmcb->save.rax,0 , +NULL , nested_svm_vmrun)) +return 1 ;Quoted 10 lines
arch/x86/kvm/svm.c static int vmsave_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) · line 1462
Quoted 6 lines
arch/x86/kvm/svm.c +4
-0+ +if (nested_svm_do (svm, svm->vmcb->control.msrpm_base_pa,0 , +NULL , nested_svm_vmrun_msrpm)) +return 1 ;
nested_svm_vmrunreturns 1 unconditionally, so we never callnested_svm_vmrun_msrpm.Wow the one thing you pointed out earlier. I must've missed to write that on my TODO list.
I'll fix this right now :). Await v7 any second now.
Quoted 8 lines
Quoted 3 lines
Wow this is more tricky than I thought. I gotta go now, but I'll look into it in more detail on Tuesday. I promise :-). For now please just don't use the MSR check.
No problem. While you are looking at it, another question: In the vmrun handler, we call
kvm_mmu_reset_context()in the SPT case only. In the vmexit handler, we callkvm_mmu_reset_context()for both SPT and NPT. Why the discrepancy?
It should only be necessary on the SPT case, because with NPT our mmu stays the same. We still only convert from host to l1 guest.
IIRC npt broke for me without that reset though and thus I put it in :-/.
Alex
Quoted 10 lines
Cheers,
MuliSignature · 5 lines
The First Workshop on I/O Virtualization (WIOV '08) Dec 2008, San Diego, CA, http://www.usenix.org/wiov08/ <-> SYSTOR 2009---The Israeli Experimental Systems Conference http://www.haifa.il.ibm.com/conferences/systor2009/
Re: [PATCH 07/12] Add VMRUN handler v6
Quoted 5 lines · Alexander Graf
It should only be necessary on the SPT case, because with NPT our mmu stays the same. We still only convert from host to l1 guest.
IIRC npt broke for me without that reset though and thus I put it in :-/.
I think that merits a comment, if not an actual resolution ;-)
Cheers,
Muli
Signature · 5 lines
The First Workshop on I/O Virtualization (WIOV '08)
Dec 2008, San Diego, CA, http://www.usenix.org/wiov08/
<->
SYSTOR 2009---The Israeli Experimental Systems Conference
http://www.haifa.il.ibm.com/conferences/systor2009/