From: Tim Deegan Date: Thu, 15 Mar 2012 11:41:11 +0000 (+0000) Subject: x86/mm: remove 'p2m_guest' lookup type. X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=923d946a0db1e1f6c2523c5d2e210f7ddd7a33af;p=xen.git x86/mm: remove 'p2m_guest' lookup type. 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 Committed-by: Tim Deegan --- diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index d661bb5dd3..362f351599 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -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) ) { diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index bf7d7f7bd9..dd1412dc7c 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -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 ) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 17b4a152aa..1d000c10f0 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -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", diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index ca0e33238f..43f08b3380 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -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 ) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index cf97617eaf..3420a417b2 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -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 diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index 83a581cc00..511a69e586 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -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) ) { diff --git a/xen/arch/x86/mm/shadow/types.h b/xen/arch/x86/mm/shadow/types.h index b81072f796..cec90b188b 100644 --- a/xen/arch/x86/mm/shadow/types.h +++ b/xen/arch/x86/mm/shadow/types.h @@ -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. */ diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index a8be50d52c..4b29e0714c 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -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 */