Nested Virtualization: interrupts (svm specific)
PATCH 10/13 Nested Virtualization: interrupts (svm specific)
Signature · 7 lines
-- ---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
# HG changeset patch
# User cegger
# Date 1289584012 -3600
Implement SVM specific interrupt handling
xen/arch/x86/hvm/svm/intr.c +52 -4
@@ -33,6 +33,7 @@#include <asm/hvm/vlapic.h> #include <asm/hvm/svm/svm.h> #include <asm/hvm/svm/intr.h> +#include <asm/hvm/nestedhvm.h> /* for nestedhvm_vcpu_in_guestmode */ #include <xen/event.h> #include <xen/kernel.h> #include <public/hvm/ioreq.h>
@@ -58,7 +59,7 @@ static void svm_inject_nmi(struct vcpu **/ vmcb->general1_intercepts |=GENERAL1_INTERCEPT_IRET ; } - +static void svm_inject_extint (struct vcpu *v,int vector) {struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
@@ -72,7 +73,7 @@ static void svm_inject_extint(struct vcpASSERT (vmcb->eventinj.fields.v ==0 ); vmcb->eventinj = event; } - +static void enable_intr_window (struct vcpu *v,struct hvm_intack intack) {struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
@@ -80,6 +81,20 @@ static void enable_intr_window(struct vcASSERT (intack.source != hvm_intsrc_none); +if (nestedhvm_enabled (v->domain) ) { +struct nestedvcpu *nv = &vcpu_nestedhvm (v); +if ( nv->nv_hostflags.fields.vmentry_pending ) { +struct vmcb_struct *gvmcb = nv->nv_vmcx; + +/* check if l1 guest injects interrupt into l2 guest via vintr. +* return here or l2 guest looses interrupts, otherwise. +*/ +ASSERT (gvmcb !=NULL ); +if ( gvmcb->vintr.fields.irq ) +return ; + } + } +HVMTRACE_3D (INTR_WINDOW , intack.vector, intack.source, vmcb->eventinj.fields.v?vmcb->eventinj.fields.vector:-1 );
@@ -117,6 +132,7 @@ asmlinkage void svm_intr_assist(void)struct vcpu *v = current;struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;struct hvm_intack intack; +enum hvm_intblk intblk;/* Crank the handle on interrupt state. */ pt_update_irq (v);
@@ -126,6 +142,39 @@ asmlinkage void svm_intr_assist(void)if (likely (intack.source == hvm_intsrc_none) )return ; + intblk =hvm_interrupt_blocked (v, intack); +if ( intblk == hvm_intblk_svm_gif ) { +ASSERT (nestedhvm_enabled (v->domain)); +return ; + } + +/* Interrupts for the nested guest are already +* in the vmcb. +*/ +if (nestedhvm_enabled (v->domain) &&nestedhvm_vcpu_in_guestmode (v) ) + { +int rc; + +/* l2 guest was running when an interrupt for +* the l1 guest occured. +*/ + rc =nestedsvm_vcpu_interrupt (v, intack); +switch (rc) { +case NSVM_INTR_NOTINTERCEPTED : +/* Inject interrupt into 2nd level guest directly. */ +break ; +case NSVM_INTR_NOTHANDLED : +case NSVM_INTR_FORCEVMEXIT : +return ; +case NSVM_INTR_MASKED : +/* Guest already enabled an interrupt window. */ +return ; +default : +panic ("%s: nestedsvm_vcpu_interrupt can't handle value 0x%x\n" , + __func__, rc); + } + } +/* * Pending IRQs must be delayed if: * 1. An event is already pending. This is despite the fact that SVM
@@ -140,8 +189,7 @@ asmlinkage void svm_intr_assist(void)* have cleared the interrupt out of the IRR. * 2. The IRQ is masked. */ -if (unlikely (vmcb->eventinj.fields.v) || -hvm_interrupt_blocked (v, intack) ) +if (unlikely (vmcb->eventinj.fields.v) || intblk ) {enable_intr_window (v, intack);return ;
xen/arch/x86/hvm/svm/nestedsvm.c +161 -1
196 lines not on this page · raw message
xen/arch/x86/hvm/svm/svm.c +6 -2
@@ -78,8 +78,7 @@ static DEFINE_PER_CPU_READ_MOSTLY(void *static bool_t amd_erratum383_found__read_mostly ; -static void inline __update_guest_eip ( -struct cpu_user_regs *regs,unsigned int inst_len) +void __update_guest_eip (struct cpu_user_regs *regs,unsigned int inst_len) {struct vcpu *curr = current;
@@ -1540,6 +1539,7 @@ static struct hvm_function_table __read_ .nhvm_vcpu_asid = nsvm_vcpu_asid, .nhvm_vmcx_guest_intercepts_trap = nsvm_vmcb_guest_intercepts_trap, .nhvm_vmcx_hap_enabled = nsvm_vmcb_hap_enabled, + .nhvm_intr_blocked = nsvm_intr_blocked, }; asmlinkage void svm_vmexit_handler(struct cpu_user_regs *regs)
@@ -1805,7 +1805,11 @@ asmlinkage void svm_vmexit_handler(strucsvm_vmexit_do_vmsave (vmcb, regs, v, regs->eax);break ;case VMEXIT_STGI : +svm_vmexit_do_stgi (regs, v); +break ;case VMEXIT_CLGI : +svm_vmexit_do_clgi (regs, v); +break ;case VMEXIT_SKINIT :hvm_inject_exception (TRAP_invalid_op,HVM_DELIVER_NO_ERROR_CODE ,0 );break ;
xen/include/asm-x86/hvm/svm/nestedsvm.h +17 -0
@@ -23,7 +23,12 @@#include <asm/hvm/hvm.h> #include <asm/hvm/svm/vmcb.h> +enum hvm_intblk_svm { + hvm_intblk_svm_gif = hvm_intblk_arch,/* GIF cleared */ +}; +struct nestedsvm { +bool_t ns_gif;uint64_t ns_msr_hsavepa;/* MSR HSAVE_PA value */ /* Cached real intercepts of the nested guest */
@@ -101,11 +106,23 @@ int nsvm_vmcb_guest_intercepts_exitcode( struct cpu_user_regs *regs, uint64_t exitcode);int nsvm_vmcb_guest_intercepts_trap (struct vcpu *v,unsigned int trapnr);bool_t nsvm_vmcb_hap_enabled (struct vcpu *v); +enum hvm_intblk nsvm_intr_blocked (struct vcpu *v);/* MSRs */ int nsvm_rdmsr (struct vcpu *v,unsigned int msr,uint64_t *msr_content);int nsvm_wrmsr (struct vcpu *v,unsigned int msr,uint64_t msr_content); +/* Interrupts, vGIF */ +void svm_vmexit_do_clgi (struct cpu_user_regs *regs,struct vcpu *v); +void svm_vmexit_do_stgi (struct cpu_user_regs *regs,struct vcpu *v); +bool_t nestedsvm_gif_isset (struct vcpu *v); + +#define NSVM_INTR_NOTHANDLED 3 +#define NSVM_INTR_NOTINTERCEPTED 2 +#define NSVM_INTR_FORCEVMEXIT 1 +#define NSVM_INTR_MASKED 0 +int nestedsvm_vcpu_interrupt (struct vcpu *v,const struct hvm_intack intack); +#endif /* ASM_X86_HVM_SVM_NESTEDSVM_H__ */ /*
xen/include/asm-x86/hvm/svm/svm.h +1 -0
@@ -61,6 +61,7 @@ static inline void svm_vmsave(void *vmcb }unsigned long *svm_msrbit (unsigned long *msr_bitmap,uint32_t msr); +void __update_guest_eip (struct cpu_user_regs *regs,unsigned int inst_len);extern u32 svm_feature_flags;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 7 lines · Christoph Egger
diff -r
3bfc06e2e41a-rb18448601670xen/arch/x86/hvm/svm/nestedsvm.cxen/arch/x86/hvm/svm/nestedsvm.c +0
-0@@ -24,6 +24,30 @@#include <asm/hvm/svm/nestedsvm.h> #include <asm/hvm/svm/svmdebug.h> #include <asm/paging.h> /* paging_mode_hap */
xen/arch/x86/hvm/svm/nestedsvm.c line 36
Quoted 10 lines
xen/arch/x86/hvm/svm/nestedsvm.c +10
-0+#include <asm/event.h> /* for local_event_delivery_(en|dis)able */ + +static int +nestedsvm_vcpu_clgi (struct vcpu *v) +{ +struct nestedsvm *svm = &vcpu_nestedsvm (v); + +/* clear gif flag */ + svm->ns_gif =0 ; +local_event_delivery_disable ();/* mask events for PV drivers */
This function, and the stgi one below, can only operate safely on current; if you want to keep the argument for performance then maybe ASSERT(v == current) for sanity.
xen/arch/x86/hvm/svm/nestedsvm.c line 37
Quoted 1 line
xen/arch/x86/hvm/svm/nestedsvm.c +1
-0+return 0 ;
Also, since they only ever return 0, please make them return void instead.
Quoted 21 lines
xen/arch/x86/hvm/svm/nestedsvm.c +20
-0+} + +static int +nestedsvm_vcpu_stgi (struct vcpu *v) +{ +struct nestedsvm *svm = &vcpu_nestedsvm (v); + +/* Always set the GIF to make hvm_interrupt_blocked work. */ + svm->ns_gif =1 ; + +local_event_delivery_enable ();/* unmask events for PV drivers */ +return 0 ; +} +void svm_vmexit_do_stgi (struct cpu_user_regs *regs,struct vcpu *v) +{ +int ret; +unsigned int inst_len; + +if ( !nestedhvm_enabled (v->domain) ) { +hvm_inject_exception (TRAP_invalid_op,HVM_DELIVER_NO_ERROR_CODE ,0 );
xen/arch/x86/hvm/svm/nestedsvm.c
Quoted 10 lines
xen/arch/x86/hvm/svm/nestedsvm.c +10
-0+return ; + } + +if ( (inst_len =__get_instruction_length (v,INSTR_STGI )) ==0 ) +return ; + + ret =nestedsvm_vcpu_stgi (v); +if (ret) +/* On failure, nestedsvm_vcpu_stgi injected an exception, +* almost a #GP or #UD.
No, it never fails and always returns 0. :) Likewise below.
Cheers,
Tim.
Quoted 33 lines
xen/arch/x86/hvm/svm/nestedsvm.c +33
-0+*/ +return ; + +__update_guest_eip (regs, inst_len); +} + +void svm_vmexit_do_clgi (struct cpu_user_regs *regs,struct vcpu *v) +{ +int ret; +struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb; +unsigned int inst_len; + +if ( !nestedhvm_enabled (v->domain) ) { +hvm_inject_exception (TRAP_invalid_op,HVM_DELIVER_NO_ERROR_CODE ,0 ); +return ; + } + +if ( (inst_len =__get_instruction_length (v,INSTR_CLGI )) ==0 ) +return ; + + ret =nestedsvm_vcpu_clgi (v); +if (ret) +/* On failure, nestedsvm_vcpu_clgi injected an exception, +* almost a #GP or #UD. +*/ +return ; + +/* After a CLGI no interrupts should come */ + vmcb->vintr.fields.irq =0 ; + vmcb->general1_intercepts &= ~GENERAL1_INTERCEPT_VINTR ; + +__update_guest_eip (regs, inst_len); +}
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)
Quoted 4 lines · Tim Deegan
Quoted 4 lines
xen/arch/x86/hvm/svm/nestedsvm.c +4
-0+static int +nestedsvm_vcpu_clgi (struct vcpu *v) +{ +struct nestedsvm *svm = &vcpu_nestedsvm (v);
Quoted 8 lines
xen/arch/x86/hvm/svm/nestedsvm.c line 36
Quoted 4 lines
xen/arch/x86/hvm/svm/nestedsvm.c +4
-0+ +/* clear gif flag */ + svm->ns_gif =0 ; +local_event_delivery_disable ();/* mask events for PV drivers */ This function, and the stgi one below, can only operate safely on current; if you want to keep the argument for performance then maybe ASSERT(v == current) for sanity.
I don't believe in the performance win. Functions which act correctly only on current should not be passed a vcpu parameter.
-- Keir
Quoted 14 lines · On Tuesday 16 November 2010 16:06:45 Tim Deegan wrote:
Quoted 13 lines · Christoph Egger
diff -r
3bfc06e2e41a-rb18448601670xen/arch/x86/hvm/svm/nestedsvm.cxen/arch/x86/hvm/svm/nestedsvm.c +6
-0@@ -24,6 +24,30 @@#include <asm/hvm/svm/nestedsvm.h> #include <asm/hvm/svm/svmdebug.h> #include <asm/paging.h> /* paging_mode_hap */ +#include <asm/event.h> /* for local_event_delivery_(en|dis)able */ + +static int +nestedsvm_vcpu_clgi (struct vcpu *v) +{ +struct nestedsvm *svm = &vcpu_nestedsvm (v);
Quoted 8 lines
xen/arch/x86/hvm/svm/nestedsvm.c line 36
Quoted 4 lines
xen/arch/x86/hvm/svm/nestedsvm.c +4
-0+ +/* clear gif flag */ + svm->ns_gif =0 ; +local_event_delivery_disable ();/* mask events for PV drivers */ This function, and the stgi one below, can only operate safely on current; if you want to keep the argument for performance then maybe ASSERT(v == current) for sanity.
No, it's not about performance. It's about consistency. Do you want me to remove the parameter?
Quoted 4 lines
xen/arch/x86/hvm/svm/nestedsvm.c line 37
Quoted 1 line
xen/arch/x86/hvm/svm/nestedsvm.c +1
-0+return 0 ;Also, since they only ever return 0, please make them return void instead.
Fixed.
Quoted 26 lines
Quoted 26 lines
xen/arch/x86/hvm/svm/nestedsvm.c +20
-0+} + +static int +nestedsvm_vcpu_stgi (struct vcpu *v) +{ +struct nestedsvm *svm = &vcpu_nestedsvm (v); + +/* Always set the GIF to make hvm_interrupt_blocked work. */ + svm->ns_gif =1 ; + +local_event_delivery_enable ();/* unmask events for PV drivers */ +return 0 ; +} +void svm_vmexit_do_stgi (struct cpu_user_regs *regs,struct vcpu *v) +{ +int ret; +unsigned int inst_len; + +if ( !nestedhvm_enabled (v->domain) ) { + hvm_inject_exception(TRAP_invalid_op, HVM_DELIVER_NO_ERROR_CODE,0); + return;
xen/arch/x86/hvm/svm/nestedsvm.c +3
-0+ } + +if ( (inst_len =__get_instruction_length (v,INSTR_STGI )) ==0 )
Quoted 8 lines
xen/arch/x86/hvm/svm/nestedsvm.c asmlinkage void nsvm_vcpu_switch(struct · line 1312
Quoted 6 lines
xen/arch/x86/hvm/svm/nestedsvm.c +6
-0+return ; + + ret =nestedsvm_vcpu_stgi (v); +if (ret) +/* On failure, nestedsvm_vcpu_stgi injected an exception, +* almost a #GP or #UD. No, it never fails and always returns 0. :) Likewise below.
Both fixed.
Christoph
Quoted 38 lines
Cheers,
Tim.
Quoted 33 lines
xen/arch/x86/hvm/svm/nestedsvm.c +14
-0+*/ +return ; + +__update_guest_eip (regs, inst_len); +} + +void svm_vmexit_do_clgi (struct cpu_user_regs *regs,struct vcpu *v) +{ +int ret; +struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb; +unsigned int inst_len; + +if ( !nestedhvm_enabled (v->domain) ) { + hvm_inject_exception(TRAP_invalid_op, HVM_DELIVER_NO_ERROR_CODE,0); + return;
xen/arch/x86/hvm/svm/nestedsvm.c +18
-0+ } + +if ( (inst_len =__get_instruction_length (v,INSTR_CLGI )) ==0 ) +return ; + + ret =nestedsvm_vcpu_clgi (v); +if (ret) +/* On failure, nestedsvm_vcpu_clgi injected an exception, +* almost a #GP or #UD. +*/ +return ; + +/* After a CLGI no interrupts should come */ + vmcb->vintr.fields.irq =0 ; + vmcb->general1_intercepts &= ~GENERAL1_INTERCEPT_VINTR ; + +__update_guest_eip (regs, inst_len); +}
Signature · 6 lines
---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632