From: Tim Deegan Date: Mon, 24 Oct 2011 10:29:08 +0000 (+0100) Subject: nestedhvm: handle l2 guest MMIO access X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d740d811925385c09553cbe6dee8e77c1d43b198;p=xen.git nestedhvm: handle l2 guest MMIO access Hyper-V starts a root domain which effectively an l2 guest. Hyper-V passes its devices through to the root domain and let it do the MMIO accesses. The emulation is done by Xen (host) and Hyper-V forwards the interrupts to the l2 guest. Signed-off-by: Christoph Egger Acked-by: Tim Deegan Committed-by: Tim Deegan --- diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 9e24b25e18..ab7763b4ba 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1208,6 +1208,10 @@ int hvm_hap_nested_page_fault(unsigned long gpa, return 0; case NESTEDHVM_PAGEFAULT_INJECT: return -1; + case NESTEDHVM_PAGEFAULT_MMIO: + if ( !handle_mmio() ) + hvm_inject_exception(TRAP_gp_fault, 0, 0); + return 1; } } diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c index f7fae0da78..bc2c50887e 100644 --- a/xen/arch/x86/hvm/svm/nestedsvm.c +++ b/xen/arch/x86/hvm/svm/nestedsvm.c @@ -1161,6 +1161,15 @@ enum hvm_intblk nsvm_intr_blocked(struct vcpu *v) if ( svm->ns_hostflags.fields.vintrmask ) if ( !svm->ns_hostflags.fields.rflagsif ) return hvm_intblk_rflags_ie; + + /* when l1 guest passes its devices through to the l2 guest + * and l2 guest does an MMIO access then we may want to + * inject an VMEXIT(#INTR) exitcode into the l1 guest. + * Delay the injection because this would result in delivering + * an interrupt *within* the execution of an instruction. + */ + if ( v->arch.hvm_vcpu.io_state != HVMIO_none ) + return hvm_intblk_shadow; } if ( nv->nv_vmexit_pending ) { diff --git a/xen/arch/x86/mm/hap/nested_hap.c b/xen/arch/x86/mm/hap/nested_hap.c index 972bc059f4..40e7d491d0 100644 --- a/xen/arch/x86/mm/hap/nested_hap.c +++ b/xen/arch/x86/mm/hap/nested_hap.c @@ -151,6 +151,9 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa, mfn = gfn_to_mfn_type_p2m(p2m, L1_gpa >> PAGE_SHIFT, &p2mt, &p2ma, p2m_query, page_order); + if ( p2m_is_mmio(p2mt) ) + return NESTEDHVM_PAGEFAULT_MMIO; + if ( p2m_is_paging(p2mt) || p2m_is_shared(p2mt) || !p2m_is_ram(p2mt) ) return NESTEDHVM_PAGEFAULT_ERROR; @@ -228,6 +231,8 @@ nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t L2_gpa) return rv; case NESTEDHVM_PAGEFAULT_DONE: break; + case NESTEDHVM_PAGEFAULT_MMIO: + return rv; default: BUG(); break; diff --git a/xen/include/asm-x86/hvm/nestedhvm.h b/xen/include/asm-x86/hvm/nestedhvm.h index d846a8de6b..7c1c16a601 100644 --- a/xen/include/asm-x86/hvm/nestedhvm.h +++ b/xen/include/asm-x86/hvm/nestedhvm.h @@ -50,6 +50,7 @@ bool_t nestedhvm_vcpu_in_guestmode(struct vcpu *v); #define NESTEDHVM_PAGEFAULT_DONE 0 #define NESTEDHVM_PAGEFAULT_INJECT 1 #define NESTEDHVM_PAGEFAULT_ERROR 2 +#define NESTEDHVM_PAGEFAULT_MMIO 3 int nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t L2_gpa); /* IO permission map */