nestedhvm: handle l2 guest MMIO access
authorTim Deegan <tim@xen.org>
Mon, 24 Oct 2011 10:29:08 +0000 (11:29 +0100)
committerTim Deegan <tim@xen.org>
Mon, 24 Oct 2011 10:29:08 +0000 (11:29 +0100)
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 <Christoph.Egger@amd.com>
Acked-by: Tim Deegan <tim@xen.org>
Committed-by: Tim Deegan <tim@xen.org>
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/svm/nestedsvm.c
xen/arch/x86/mm/hap/nested_hap.c
xen/include/asm-x86/hvm/nestedhvm.h

index 9e24b25e1811d9c2239dbd28a5f27367cb7423f3..ab7763b4ba670909ca03b919fb580bdf8d7e8f3e 100644 (file)
@@ -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;
         }
     }
 
index f7fae0da78b1e2046a4e5613f1072286c235ea69..bc2c50887e2e0d221c605d8e7ae017118e1c0d0b 100644 (file)
@@ -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 ) {
index 972bc059f4a1398fb7b17a1aa8aa59ae6e36c89c..40e7d491d0171c1a9be0c237c5d0de978b0b21b1 100644 (file)
@@ -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;
index d846a8de6bc8cb7d26acb03031486b7f28648a16..7c1c16a601a8d6b1f8e5e30e15ed9cd784d403e2 100644 (file)
@@ -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 */