x86/mm: remove 'p2m_guest' lookup type.
authorTim Deegan <tim@xen.org>
Thu, 15 Mar 2012 11:41:11 +0000 (11:41 +0000)
committerTim Deegan <tim@xen.org>
Thu, 15 Mar 2012 11:41:11 +0000 (11:41 +0000)
It was neither consistently used by callers nor correctly handled by the
lookup code.  Instead, treat any lookup that might allocate or unshare
memory as a 'guest' lookup for the purposes of:
 - detecting the highest pod gfn populated; and
 - crashing the guest on access to a broken page
which were the only things this was used for.

Signed-off-by: Tim Deegan <tim@xen.org>
Committed-by: Tim Deegan <tim@xen.org>
xen/arch/x86/hvm/emulate.c
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/svm/svm.c
xen/arch/x86/mm/p2m-pod.c
xen/arch/x86/mm/p2m.c
xen/arch/x86/mm/shadow/multi.c
xen/arch/x86/mm/shadow/types.h
xen/include/asm-x86/p2m.h

index d661bb5dd3a6b1e393dba0a6c927a222ee0fd64b..362f3515995c524888015e84873c89545b9df095 100644 (file)
@@ -716,7 +716,7 @@ static int hvmemul_rep_movs(
 
     get_two_gfns(current->domain, sgpa >> PAGE_SHIFT, &sp2mt, NULL, NULL,
                  current->domain, dgpa >> PAGE_SHIFT, &dp2mt, NULL, NULL,
-                 p2m_guest, &tg);
+                 p2m_alloc, &tg);
 
     if ( !p2m_is_ram(sp2mt) && !p2m_is_grant(sp2mt) )
     {
index bf7d7f7bd99fb12ddf576c0b3e061eff32653a8f..dd1412dc7ce873dbe7630bee61b263c49fd51532 100644 (file)
@@ -1269,7 +1269,8 @@ int hvm_hap_nested_page_fault(unsigned long gpa,
     }
 
     p2m = p2m_get_hostp2m(v->domain);
-    mfn = get_gfn_type_access(p2m, gfn, &p2mt, &p2ma, p2m_guest, NULL);
+    mfn = get_gfn_type_access(p2m, gfn, &p2mt, &p2ma, 
+                              access_w ? p2m_unshare : p2m_alloc, NULL);
 
     /* Check access permissions first, then handle faults */
     if ( mfn_x(mfn) != INVALID_MFN )
index 17b4a152aa3522f6591d60f71e9a13a4e56fa69b..1d000c10f04e41344f5de3073f73e445ec2f5b11 100644 (file)
@@ -1287,7 +1287,7 @@ static void svm_do_nested_pgfault(struct vcpu *v,
     if ( p2m == NULL )
         p2m = p2m_get_p2m(v);
     /* Everything else is an error. */
-    mfn = get_gfn_type_access(p2m, gfn, &p2mt, &p2ma, p2m_guest, NULL);
+    mfn = get_gfn_type_access(p2m, gfn, &p2mt, &p2ma, p2m_query, NULL);
     __put_gfn(p2m, gfn);
     gdprintk(XENLOG_ERR,
          "SVM violation gpa %#"PRIpaddr", mfn %#lx, type %i\n",
index ca0e33238fc6573b0b7f318af03163b9502f2a99..43f08b3380b1b4f0ac0b247001ee4d47403b3fcc 100644 (file)
@@ -1023,7 +1023,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, unsigned long gfn,
     }
 
     /* Keep track of the highest gfn demand-populated by a guest fault */
-    if ( q == p2m_guest && gfn > p2m->pod.max_guest )
+    if ( gfn > p2m->pod.max_guest )
         p2m->pod.max_guest = gfn;
 
     if ( p2m->pod.count == 0 )
index cf97617eaf95ec9f4b5c887339254f8fc6f58159..3420a417b20f32c201685b59c84cc15245438c57 100644 (file)
@@ -183,7 +183,7 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn,
     {
         /* Return invalid_mfn to avoid caller's access */
         mfn = _mfn(INVALID_MFN);
-        if (q == p2m_guest)
+        if (q != p2m_query)
             domain_crash(p2m->domain);
     }
 #endif
index 83a581cc00c7e671a7821b5a9c5f4c61821c41bc..511a69e58625a65fcb28768bee441ffb66f59cdd 100644 (file)
@@ -3189,7 +3189,7 @@ static int sh_page_fault(struct vcpu *v,
 
     /* What mfn is the guest trying to access? */
     gfn = guest_l1e_get_gfn(gw.l1e);
-    gmfn = get_gfn_guest(d, gfn, &p2mt);
+    gmfn = get_gfn(d, gfn, &p2mt);
 
     if ( shadow_mode_refcounts(d) && 
          ((!p2m_is_valid(p2mt) && !p2m_is_grant(p2mt)) ||
@@ -4840,7 +4840,7 @@ static mfn_t emulate_gva_to_mfn(struct vcpu *v,
 
     /* Translate the GFN to an MFN */
     ASSERT(!paging_locked_by_me(v->domain));
-    mfn = get_gfn_guest(v->domain, _gfn(gfn), &p2mt);
+    mfn = get_gfn(v->domain, _gfn(gfn), &p2mt);
         
     if ( p2m_is_readonly(p2mt) )
     {
index b81072f79671dc3088dc235f7bbe576098efad42..cec90b188bc233bf8ac45c9b262eb197240e1068 100644 (file)
@@ -194,8 +194,6 @@ static inline shadow_l4e_t shadow_l4e_from_mfn(mfn_t mfn, u32 flags)
  /* Override get_gfn to work with gfn_t */
 #undef get_gfn_query
 #define get_gfn_query(d, g, t) get_gfn_type((d), gfn_x(g), (t), p2m_query)
-#undef get_gfn_guest
-#define get_gfn_guest(d, g, t) get_gfn_type((d), gfn_x(g), (t), p2m_guest)
 
 /* The shadow types needed for the various levels. */
 
index a8be50d52c80d27695a00e002faf6621e115b3c9..4b29e0714c2e06632bb577d3bc87be1fa5b5be8c 100644 (file)
@@ -116,11 +116,11 @@ typedef enum {
     /* NOTE: Assumed to be only 4 bits right now */
 } p2m_access_t;
 
+/* Modifiers to the query */
 typedef enum {
     p2m_query,              /* Do not populate a PoD entries      */
     p2m_alloc,              /* Automatically populate PoD entries */
     p2m_unshare,            /* Break c-o-w sharing; implies alloc */
-    p2m_guest,              /* Guest demand-fault; implies alloc  */
 } p2m_query_t;
 
 /* We use bitmaps and maks to handle groups of types */
@@ -334,7 +334,6 @@ static inline mfn_t get_gfn_type(struct domain *d,
  * lock held. */
 #define get_gfn(d, g, t)         get_gfn_type((d), (g), (t), p2m_alloc)
 #define get_gfn_query(d, g, t)   get_gfn_type((d), (g), (t), p2m_query)
-#define get_gfn_guest(d, g, t)   get_gfn_type((d), (g), (t), p2m_guest)
 #define get_gfn_unshare(d, g, t) get_gfn_type((d), (g), (t), p2m_unshare)
 
 /* Compatibility function exporting the old untyped interface */