From: "Jan Beulich" Subject: [PATCH 7/8] x86/EPT: split super pages upon mismatching memory types Date: Wed, 26 Mar 2014 15:36:58 +0000 Message-ID: <5333022A02000078000027FB@nat28.tlf.novell.com> References: <5332FF1902000078000027A2@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartF7C59B0A.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WSpt0-0001we-P6 for xen-devel@lists.xenproject.org; Wed, 26 Mar 2014 15:37:03 +0000 In-Reply-To: <5332FF1902000078000027A2@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Kevin Tian , Keir Fraser , Tim Deegan , Eddie Dong , Jun Nakajima , Yang Z Zhang List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartF7C59B0A.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... between constituent pages. To indicate such, the page order is being passed down to the vMTRR routines, with a negative return value (possible only on order-non-zero pages) indicating such collisions. Some code redundancy reduction is being done to ept_set_entry() along the way, allowing the new handling to be centralized to a single place there. In order to keep ept_set_entry() fast and simple, the actual splitting is being deferred to the EPT_MISCONFIG VM exit handler. Signed-off-by: Jan Beulich --- One open question is whether it is okay for memory allocation (for an intermediate page table) failure to be fatal to the domain. If it isn't, then deferring the splitting work from ept_set_entry() to ept_handle_misconfig() is not an option. But even with that eliminated there's then still potential for ept_handle_misconfig() needing to split pages, and it would then need to be determined how to gracefully handle that. --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -222,30 +222,40 @@ void hvm_vcpu_cacheattr_destroy(struct v =20 /* * Get MTRR memory type for physical address pa. + * + * May return a negative value when order > 0, indicating to the caller + * that the respective mapping needs splitting. */ -static uint8_t get_mtrr_type(struct mtrr_state *m, paddr_t pa) +static int get_mtrr_type(const struct mtrr_state *m, + paddr_t pa, unsigned int order) { - int32_t addr, seg, index; uint8_t overlap_mtrr =3D 0; uint8_t overlap_mtrr_pos =3D 0; - uint64_t phys_base; - uint64_t phys_mask; - uint8_t num_var_ranges =3D m->mtrr_cap & 0xff; + uint64_t mask =3D -(uint64_t)PAGE_SIZE << order; + unsigned int seg, num_var_ranges =3D m->mtrr_cap & 0xff; =20 if ( unlikely(!(m->enabled & 0x2)) ) return MTRR_TYPE_UNCACHABLE; =20 + pa &=3D mask; if ( (pa < 0x100000) && (m->enabled & 1) ) { - /* Fixed range MTRR takes effective */ - addr =3D (uint32_t) pa; + /* Fixed range MTRR takes effect. */ + uint32_t addr =3D (uint32_t)pa, index; + if ( addr < 0x80000 ) { + /* 0x00000 ... 0x7FFFF in 64k steps */ + if ( order > 4 ) + return -1; seg =3D (addr >> 16); return m->fixed_ranges[seg]; } else if ( addr < 0xc0000 ) { + /* 0x80000 ... 0xBFFFF in 16k steps */ + if ( order > 2 ) + return -1; seg =3D (addr - 0x80000) >> 14; index =3D (seg >> 3) + 1; seg &=3D 7; /* select 0-7 segments */ @@ -253,7 +263,9 @@ static uint8_t get_mtrr_type(struct mtrr } else { - /* 0xC0000 --- 0x100000 */ + /* 0xC0000 ... 0xFFFFF in 4k steps */ + if ( order ) + return -1; seg =3D (addr - 0xc0000) >> 12; index =3D (seg >> 3) + 3; seg &=3D 7; /* select 0-7 segments */ @@ -264,14 +276,15 @@ static uint8_t get_mtrr_type(struct mtrr /* Match with variable MTRRs. */ for ( seg =3D 0; seg < num_var_ranges; seg++ ) { - phys_base =3D ((uint64_t*)m->var_ranges)[seg*2]; - phys_mask =3D ((uint64_t*)m->var_ranges)[seg*2 + 1]; + uint64_t phys_base =3D m->var_ranges[seg].base; + uint64_t phys_mask =3D m->var_ranges[seg].mask; + if ( phys_mask & MTRR_PHYSMASK_VALID ) { - if ( ((uint64_t) pa & phys_mask) >> MTRR_PHYSMASK_SHIFT =3D=3D - (phys_base & phys_mask) >> MTRR_PHYSMASK_SHIFT ) + phys_mask &=3D mask; + if ( (pa & phys_mask) =3D=3D (phys_base & phys_mask) ) { - if ( unlikely(m->overlapped) ) + if ( unlikely(m->overlapped) || order ) { overlap_mtrr |=3D 1 << (phys_base & MTRR_PHYSBASE_TYPE= _MASK); overlap_mtrr_pos =3D phys_base & MTRR_PHYSBASE_TYPE_MA= SK; @@ -285,23 +298,24 @@ static uint8_t get_mtrr_type(struct mtrr } } =20 - /* Overlapped or not found. */ + /* Not found? */ if ( unlikely(overlap_mtrr =3D=3D 0) ) return m->def_type; =20 - if ( likely(!(overlap_mtrr & ~( ((uint8_t)1) << overlap_mtrr_pos ))) ) - /* Covers both one variable memory range matches and - * two or more identical match. - */ + /* One match, or multiple identical ones? */ + if ( likely(overlap_mtrr =3D=3D (1 << overlap_mtrr_pos)) ) return overlap_mtrr_pos; =20 + if ( order ) + return -1; + + /* Two or more matches, one being UC? */ if ( overlap_mtrr & (1 << MTRR_TYPE_UNCACHABLE) ) - /* Two or more match, one is UC. */ return MTRR_TYPE_UNCACHABLE; =20 - if ( !(overlap_mtrr & - ~((1 << MTRR_TYPE_WRTHROUGH) | (1 << MTRR_TYPE_WRBACK))) ) - /* Two or more match, WT and WB. */ + /* Two or more matches, all of them WT and WB? */ + if ( overlap_mtrr =3D=3D + ((1 << MTRR_TYPE_WRTHROUGH) | (1 << MTRR_TYPE_WRBACK)) ) return MTRR_TYPE_WRTHROUGH; =20 /* Behaviour is undefined, but return the last overlapped type. */ @@ -341,7 +355,7 @@ static uint8_t effective_mm_type(struct=20 * just use it */=20 if ( gmtrr_mtype =3D=3D NO_HARDCODE_MEM_TYPE ) - mtrr_mtype =3D get_mtrr_type(m, gpa); + mtrr_mtype =3D get_mtrr_type(m, gpa, 0); else mtrr_mtype =3D gmtrr_mtype; =20 @@ -370,7 +384,7 @@ uint32_t get_pat_flags(struct vcpu *v, guest_eff_mm_type =3D effective_mm_type(g, pat, gpaddr,=20 gl1e_flags, gmtrr_mtype); /* 2. Get the memory type of host physical address, with MTRR */ - shadow_mtrr_type =3D get_mtrr_type(&mtrr_state, spaddr); + shadow_mtrr_type =3D get_mtrr_type(&mtrr_state, spaddr, 0); =20 /* 3. Find the memory type in PAT, with host MTRR memory type * and guest effective memory type. @@ -703,10 +717,10 @@ void memory_type_changed(struct domain * p2m_memory_type_changed(d); } =20 -uint8_t epte_get_entry_emt(struct domain *d, unsigned long gfn, mfn_t = mfn, - uint8_t *ipat, bool_t direct_mmio) +int epte_get_entry_emt(struct domain *d, unsigned long gfn, mfn_t mfn, + unsigned int order, uint8_t *ipat, bool_t = direct_mmio) { - uint8_t gmtrr_mtype, hmtrr_mtype; + int gmtrr_mtype, hmtrr_mtype; uint32_t type; struct vcpu *v =3D current; =20 @@ -747,10 +761,12 @@ uint8_t epte_get_entry_emt(struct domain } =20 gmtrr_mtype =3D is_hvm_domain(d) && v ? - get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn << PAGE_SHIFT= )) : + get_mtrr_type(&v->arch.hvm_vcpu.mtrr, + gfn << PAGE_SHIFT, order) : MTRR_TYPE_WRBACK; - - hmtrr_mtype =3D get_mtrr_type(&mtrr_state, (mfn_x(mfn) << PAGE_SHIFT))= ; + hmtrr_mtype =3D get_mtrr_type(&mtrr_state, mfn_x(mfn) << PAGE_SHIFT, = order); + if ( gmtrr_mtype < 0 || hmtrr_mtype < 0 ) + return -1; =20 /* If both types match we're fine. */ if ( likely(gmtrr_mtype =3D=3D hmtrr_mtype) ) --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -289,6 +289,7 @@ ept_set_entry(struct p2m_domain *p2m, un int vtd_pte_present =3D 0; int needs_sync =3D 1; ept_entry_t old_entry =3D { .epte =3D 0 }; + ept_entry_t new_entry =3D { .epte =3D 0 }; struct ept_data *ept =3D &p2m->ept; struct domain *d =3D p2m->domain; =20 @@ -338,7 +339,6 @@ ept_set_entry(struct p2m_domain *p2m, un if ( i =3D=3D target ) { /* We reached the target level. */ - ept_entry_t new_entry =3D { .epte =3D 0 }; =20 /* No need to flush if the old entry wasn't valid */ if ( !is_epte_present(ept_entry) ) @@ -349,35 +349,11 @@ ept_set_entry(struct p2m_domain *p2m, un * * Read-then-write is OK because we hold the p2m lock. */ old_entry =3D *ept_entry; - - if ( mfn_valid(mfn_x(mfn)) || direct_mmio || p2m_is_paged(p2mt) = || - (p2mt =3D=3D p2m_ram_paging_in) ) - { - /* Construct the new entry, and then write it once */ - new_entry.emt =3D epte_get_entry_emt(p2m->domain, gfn, mfn, = &ipat, - direct_mmio); - - new_entry.ipat =3D ipat; - new_entry.sp =3D !!order; - new_entry.sa_p2mt =3D p2mt; - new_entry.access =3D p2ma; - new_entry.rsvd2_snp =3D (iommu_enabled && iommu_snoop); - - new_entry.mfn =3D mfn_x(mfn); - - if ( old_entry.mfn =3D=3D new_entry.mfn ) - need_modify_vtd_table =3D 0; - - ept_p2m_type_to_flags(&new_entry, p2mt, p2ma); - } - - atomic_write_ept_entry(ept_entry, new_entry); } else { /* We need to split the original page. */ ept_entry_t split_ept_entry; - ept_entry_t new_entry =3D { .epte =3D 0 }; =20 ASSERT(is_epte_superpage(ept_entry)); =20 @@ -401,8 +377,19 @@ ept_set_entry(struct p2m_domain *p2m, un ASSERT(i =3D=3D target); =20 ept_entry =3D table + (gfn_remainder >> (i * EPT_TABLE_ORDER)); + } + + if ( mfn_valid(mfn_x(mfn)) || direct_mmio || p2m_is_paged(p2mt) || + (p2mt =3D=3D p2m_ram_paging_in) ) + { + int emt =3D epte_get_entry_emt(p2m->domain, gfn, mfn, + i * EPT_TABLE_ORDER, &ipat, = direct_mmio); + + if ( emt >=3D 0 ) + new_entry.emt =3D emt; + else /* ept_handle_misconfig() will need to take care of this. */ + new_entry.emt =3D MTRR_NUM_TYPES; =20 - new_entry.emt =3D epte_get_entry_emt(d, gfn, mfn, &ipat, = direct_mmio); new_entry.ipat =3D ipat; new_entry.sp =3D !!i; new_entry.sa_p2mt =3D p2mt; @@ -417,10 +404,10 @@ ept_set_entry(struct p2m_domain *p2m, un need_modify_vtd_table =3D 0; =20 ept_p2m_type_to_flags(&new_entry, p2mt, p2ma); - - atomic_write_ept_entry(ept_entry, new_entry); } =20 + atomic_write_ept_entry(ept_entry, new_entry); + /* Track the highest gfn for which we have ever had a valid mapping = */ if ( p2mt !=3D p2m_invalid && (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) ) @@ -737,7 +724,7 @@ bool_t ept_handle_misconfig(uint64_t gpa if ( !is_epte_valid(&e) || !is_epte_present(&e) ) continue; e.emt =3D epte_get_entry_emt(p2m->domain, gfn + i, - _mfn(e.mfn), &ipat, + _mfn(e.mfn), 0, &ipat, e.sa_p2mt =3D=3D p2m_mmio_d= irect); e.ipat =3D ipat; atomic_write_ept_entry(&epte[i], e); @@ -745,9 +732,22 @@ bool_t ept_handle_misconfig(uint64_t gpa } else { - e.emt =3D epte_get_entry_emt(p2m->domain, gfn, _mfn(e.mfn)= , - &ipat, - e.sa_p2mt =3D=3D p2m_mmio_direc= t); + int emt =3D epte_get_entry_emt(p2m->domain, gfn, = _mfn(e.mfn), + level * EPT_TABLE_ORDER, = &ipat, + e.sa_p2mt =3D=3D p2m_mmio_dir= ect); + if ( unlikely(emt < 0) ) + { + unmap_domain_page(epte); + if ( ept_split_super_page(p2m, &e, level, level - 1) = ) + { + mfn =3D e.mfn; + continue; + } + ept_free_entry(p2m, &e, level); + okay =3D 0; + break; + } + e.emt =3D emt; e.ipat =3D ipat; atomic_write_ept_entry(&epte[i], e); } --- a/xen/include/asm-x86/mtrr.h +++ b/xen/include/asm-x86/mtrr.h @@ -72,8 +72,9 @@ extern int mtrr_del_page(int reg, unsign extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi); extern u32 get_pat_flags(struct vcpu *v, u32 gl1e_flags, paddr_t gpaddr, paddr_t spaddr, uint8_t gmtrr_mtype); -extern uint8_t epte_get_entry_emt(struct domain *d, unsigned long gfn, - mfn_t mfn, uint8_t *ipat, bool_t = direct_mmio); +extern int epte_get_entry_emt(struct domain *, unsigned long gfn, mfn_t = mfn, + unsigned int order, uint8_t *ipat, + bool_t direct_mmio); extern void ept_change_entry_emt_with_range( struct domain *d, unsigned long start_gfn, unsigned long end_gfn); extern unsigned char pat_type_2_pte_flags(unsigned char pat_type); --=__PartF7C59B0A.1__= Content-Type: text/plain; name="EPT-split-on-mixed-memory-types.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="EPT-split-on-mixed-memory-types.patch" x86/EPT: split super pages upon mismatching memory types=0A=0A... between = constituent pages. To indicate such, the page order is=0Abeing passed down = to the vMTRR routines, with a negative return value=0A(possible only on = order-non-zero pages) indicating such collisions.=0A=0ASome code redundancy= reduction is being done to ept_set_entry() along=0Athe way, allowing the = new handling to be centralized to a single place=0Athere.=0A=0AIn order to = keep ept_set_entry() fast and simple, the actual splitting=0Ais being = deferred to the EPT_MISCONFIG VM exit handler.=0A=0ASigned-off-by: Jan = Beulich =0A---=0AOne open question is whether it is = okay for memory allocation (for an=0Aintermediate page table) failure to = be fatal to the domain. If it=0Aisn't, then deferring the splitting work = from ept_set_entry() to=0Aept_handle_misconfig() is not an option. But = even with that eliminated=0Athere's then still potential for ept_handle_mis= config() needing to=0Asplit pages, and it would then need to be determined = how to gracefully=0Ahandle that.=0A=0A--- a/xen/arch/x86/hvm/mtrr.c=0A+++ = b/xen/arch/x86/hvm/mtrr.c=0A@@ -222,30 +222,40 @@ void hvm_vcpu_cacheattr_d= estroy(struct v=0A =0A /*=0A * Get MTRR memory type for physical address = pa.=0A+ *=0A+ * May return a negative value when order > 0, indicating to = the caller=0A+ * that the respective mapping needs splitting.=0A = */=0A-static uint8_t get_mtrr_type(struct mtrr_state *m, paddr_t pa)=0A+sta= tic int get_mtrr_type(const struct mtrr_state *m,=0A+ = paddr_t pa, unsigned int order)=0A {=0A- int32_t addr, seg, = index;=0A uint8_t overlap_mtrr =3D 0;=0A uint8_t overlap_mtrr= _pos =3D 0;=0A- uint64_t phys_base;=0A- uint64_t phys_mask;=0A- = uint8_t num_var_ranges =3D m->mtrr_cap & 0xff;=0A+ uint64_t mask = =3D -(uint64_t)PAGE_SIZE << order;=0A+ unsigned int seg, num_var_ranges = =3D m->mtrr_cap & 0xff;=0A =0A if ( unlikely(!(m->enabled & 0x2)) )=0A = return MTRR_TYPE_UNCACHABLE;=0A =0A+ pa &=3D mask;=0A if ( (pa = < 0x100000) && (m->enabled & 1) )=0A {=0A- /* Fixed range MTRR = takes effective */=0A- addr =3D (uint32_t) pa;=0A+ /* Fixed = range MTRR takes effect. */=0A+ uint32_t addr =3D (uint32_t)pa, = index;=0A+=0A if ( addr < 0x80000 )=0A {=0A+ /* = 0x00000 ... 0x7FFFF in 64k steps */=0A+ if ( order > 4 )=0A+ = return -1;=0A seg =3D (addr >> 16);=0A = return m->fixed_ranges[seg];=0A }=0A else if ( addr < = 0xc0000 )=0A {=0A+ /* 0x80000 ... 0xBFFFF in 16k steps = */=0A+ if ( order > 2 )=0A+ return -1;=0A = seg =3D (addr - 0x80000) >> 14;=0A index =3D (seg >> 3) + = 1;=0A seg &=3D 7; /* select 0-7 segments */=0A@@ = -253,7 +263,9 @@ static uint8_t get_mtrr_type(struct mtrr=0A }=0A = else=0A {=0A- /* 0xC0000 --- 0x100000 */=0A+ = /* 0xC0000 ... 0xFFFFF in 4k steps */=0A+ if ( order )=0A+ = return -1;=0A seg =3D (addr - 0xc0000) >> 12;=0A = index =3D (seg >> 3) + 3;=0A seg &=3D 7; /* = select 0-7 segments */=0A@@ -264,14 +276,15 @@ static uint8_t get_mtrr_type= (struct mtrr=0A /* Match with variable MTRRs. */=0A for ( seg =3D 0; = seg < num_var_ranges; seg++ )=0A {=0A- phys_base =3D ((uint64_t*)m= ->var_ranges)[seg*2];=0A- phys_mask =3D ((uint64_t*)m->var_ranges)[se= g*2 + 1];=0A+ uint64_t phys_base =3D m->var_ranges[seg].base;=0A+ = uint64_t phys_mask =3D m->var_ranges[seg].mask;=0A+=0A if ( = phys_mask & MTRR_PHYSMASK_VALID )=0A {=0A- if ( ((uint64_t= ) pa & phys_mask) >> MTRR_PHYSMASK_SHIFT =3D=3D=0A- = (phys_base & phys_mask) >> MTRR_PHYSMASK_SHIFT )=0A+ phys_mask = &=3D mask;=0A+ if ( (pa & phys_mask) =3D=3D (phys_base & = phys_mask) )=0A {=0A- if ( unlikely(m->overlapped)= )=0A+ if ( unlikely(m->overlapped) || order )=0A = {=0A overlap_mtrr |=3D 1 << (phys_base & MTRR_PHYSB= ASE_TYPE_MASK);=0A overlap_mtrr_pos =3D phys_base & = MTRR_PHYSBASE_TYPE_MASK;=0A@@ -285,23 +298,24 @@ static uint8_t get_mtrr_ty= pe(struct mtrr=0A }=0A }=0A =0A- /* Overlapped or not found. = */=0A+ /* Not found? */=0A if ( unlikely(overlap_mtrr =3D=3D 0) )=0A = return m->def_type;=0A =0A- if ( likely(!(overlap_mtrr & ~( = ((uint8_t)1) << overlap_mtrr_pos ))) )=0A- /* Covers both one = variable memory range matches and=0A- * two or more identical = match.=0A- */=0A+ /* One match, or multiple identical ones? = */=0A+ if ( likely(overlap_mtrr =3D=3D (1 << overlap_mtrr_pos)) )=0A = return overlap_mtrr_pos;=0A =0A+ if ( order )=0A+ return = -1;=0A+=0A+ /* Two or more matches, one being UC? */=0A if ( = overlap_mtrr & (1 << MTRR_TYPE_UNCACHABLE) )=0A- /* Two or more = match, one is UC. */=0A return MTRR_TYPE_UNCACHABLE;=0A =0A- if ( = !(overlap_mtrr &=0A- ~((1 << MTRR_TYPE_WRTHROUGH) | (1 << = MTRR_TYPE_WRBACK))) )=0A- /* Two or more match, WT and WB. */=0A+ = /* Two or more matches, all of them WT and WB? */=0A+ if ( overlap_mtrr = =3D=3D=0A+ ((1 << MTRR_TYPE_WRTHROUGH) | (1 << MTRR_TYPE_WRBACK)) = )=0A return MTRR_TYPE_WRTHROUGH;=0A =0A /* Behaviour is = undefined, but return the last overlapped type. */=0A@@ -341,7 +355,7 @@ = static uint8_t effective_mm_type(struct =0A * just use it=0A */ = =0A if ( gmtrr_mtype =3D=3D NO_HARDCODE_MEM_TYPE )=0A- = mtrr_mtype =3D get_mtrr_type(m, gpa);=0A+ mtrr_mtype =3D get_mtrr_ty= pe(m, gpa, 0);=0A else=0A mtrr_mtype =3D gmtrr_mtype;=0A =0A@@ = -370,7 +384,7 @@ uint32_t get_pat_flags(struct vcpu *v,=0A guest_eff_mm= _type =3D effective_mm_type(g, pat, gpaddr, =0A = gl1e_flags, gmtrr_mtype);=0A /* 2. Get the memory type = of host physical address, with MTRR */=0A- shadow_mtrr_type =3D = get_mtrr_type(&mtrr_state, spaddr);=0A+ shadow_mtrr_type =3D get_mtrr_ty= pe(&mtrr_state, spaddr, 0);=0A =0A /* 3. Find the memory type in PAT, = with host MTRR memory type=0A * and guest effective memory type.=0A@@ = -703,10 +717,10 @@ void memory_type_changed(struct domain *=0A = p2m_memory_type_changed(d);=0A }=0A =0A-uint8_t epte_get_entry_emt(struct = domain *d, unsigned long gfn, mfn_t mfn,=0A- = uint8_t *ipat, bool_t direct_mmio)=0A+int epte_get_entry_emt(struct domain = *d, unsigned long gfn, mfn_t mfn,=0A+ unsigned int = order, uint8_t *ipat, bool_t direct_mmio)=0A {=0A- uint8_t gmtrr_mtype, = hmtrr_mtype;=0A+ int gmtrr_mtype, hmtrr_mtype;=0A uint32_t type;=0A = struct vcpu *v =3D current;=0A =0A@@ -747,10 +761,12 @@ uint8_t = epte_get_entry_emt(struct domain=0A }=0A =0A gmtrr_mtype =3D = is_hvm_domain(d) && v ?=0A- get_mtrr_type(&v->arch.hvm_vcp= u.mtrr, (gfn << PAGE_SHIFT)) :=0A+ get_mtrr_type(&v->arch.= hvm_vcpu.mtrr,=0A+ gfn << PAGE_SHIFT, = order) :=0A MTRR_TYPE_WRBACK;=0A-=0A- hmtrr_mtype =3D = get_mtrr_type(&mtrr_state, (mfn_x(mfn) << PAGE_SHIFT));=0A+ hmtrr_mtype = =3D get_mtrr_type(&mtrr_state, mfn_x(mfn) << PAGE_SHIFT, order);=0A+ if = ( gmtrr_mtype < 0 || hmtrr_mtype < 0 )=0A+ return -1;=0A =0A /* = If both types match we're fine. */=0A if ( likely(gmtrr_mtype =3D=3D = hmtrr_mtype) )=0A--- a/xen/arch/x86/mm/p2m-ept.c=0A+++ b/xen/arch/x86/mm/p2= m-ept.c=0A@@ -289,6 +289,7 @@ ept_set_entry(struct p2m_domain *p2m, un=0A = int vtd_pte_present =3D 0;=0A int needs_sync =3D 1;=0A = ept_entry_t old_entry =3D { .epte =3D 0 };=0A+ ept_entry_t new_entry = =3D { .epte =3D 0 };=0A struct ept_data *ept =3D &p2m->ept;=0A = struct domain *d =3D p2m->domain;=0A =0A@@ -338,7 +339,6 @@ ept_set_entry(s= truct p2m_domain *p2m, un=0A if ( i =3D=3D target )=0A {=0A = /* We reached the target level. */=0A- ept_entry_t new_entry =3D { = .epte =3D 0 };=0A =0A /* No need to flush if the old entry wasn't = valid */=0A if ( !is_epte_present(ept_entry) )=0A@@ -349,35 = +349,11 @@ ept_set_entry(struct p2m_domain *p2m, un=0A *=0A = * Read-then-write is OK because we hold the p2m lock. */=0A = old_entry =3D *ept_entry;=0A-=0A- if ( mfn_valid(mfn_x(mfn)) || = direct_mmio || p2m_is_paged(p2mt) ||=0A- (p2mt =3D=3D = p2m_ram_paging_in) )=0A- {=0A- /* Construct the new = entry, and then write it once */=0A- new_entry.emt =3D = epte_get_entry_emt(p2m->domain, gfn, mfn, &ipat,=0A- = direct_mmio);=0A-=0A- new_entry.ipat = =3D ipat;=0A- new_entry.sp =3D !!order;=0A- = new_entry.sa_p2mt =3D p2mt;=0A- new_entry.access =3D p2ma;=0A- = new_entry.rsvd2_snp =3D (iommu_enabled && iommu_snoop);=0A-=0A- = new_entry.mfn =3D mfn_x(mfn);=0A-=0A- if ( old_entry.m= fn =3D=3D new_entry.mfn )=0A- need_modify_vtd_table =3D = 0;=0A-=0A- ept_p2m_type_to_flags(&new_entry, p2mt, p2ma);=0A- = }=0A-=0A- atomic_write_ept_entry(ept_entry, new_entry);=0A = }=0A else=0A {=0A /* We need to split the original page. = */=0A ept_entry_t split_ept_entry;=0A- ept_entry_t = new_entry =3D { .epte =3D 0 };=0A =0A ASSERT(is_epte_superpage(ept_= entry));=0A =0A@@ -401,8 +377,19 @@ ept_set_entry(struct p2m_domain *p2m, = un=0A ASSERT(i =3D=3D target);=0A =0A ept_entry =3D table = + (gfn_remainder >> (i * EPT_TABLE_ORDER));=0A+ }=0A+=0A+ if ( = mfn_valid(mfn_x(mfn)) || direct_mmio || p2m_is_paged(p2mt) ||=0A+ = (p2mt =3D=3D p2m_ram_paging_in) )=0A+ {=0A+ int emt =3D = epte_get_entry_emt(p2m->domain, gfn, mfn,=0A+ = i * EPT_TABLE_ORDER, &ipat, direct_mmio);=0A+=0A+ if ( emt = >=3D 0 )=0A+ new_entry.emt =3D emt;=0A+ else /* = ept_handle_misconfig() will need to take care of this. */=0A+ = new_entry.emt =3D MTRR_NUM_TYPES;=0A =0A- new_entry.emt =3D = epte_get_entry_emt(d, gfn, mfn, &ipat, direct_mmio);=0A new_entry.i= pat =3D ipat;=0A new_entry.sp =3D !!i;=0A new_entry.sa_p2mt= =3D p2mt;=0A@@ -417,10 +404,10 @@ ept_set_entry(struct p2m_domain *p2m, = un=0A need_modify_vtd_table =3D 0;=0A =0A ept_p2m_type= _to_flags(&new_entry, p2mt, p2ma);=0A-=0A- atomic_write_ept_entry(ep= t_entry, new_entry);=0A }=0A =0A+ atomic_write_ept_entry(ept_entry, = new_entry);=0A+=0A /* Track the highest gfn for which we have ever had = a valid mapping */=0A if ( p2mt !=3D p2m_invalid &&=0A (gfn + = (1UL << order) - 1 > p2m->max_mapped_pfn) )=0A@@ -737,7 +724,7 @@ bool_t = ept_handle_misconfig(uint64_t gpa=0A if ( !is_epte_vali= d(&e) || !is_epte_present(&e) )=0A continue;=0A = e.emt =3D epte_get_entry_emt(p2m->domain, gfn + i,=0A- = _mfn(e.mfn), &ipat,=0A+ = _mfn(e.mfn), 0, &ipat,=0A = e.sa_p2mt =3D=3D p2m_mmio_direct);=0A = e.ipat =3D ipat;=0A atomic_write_ept= _entry(&epte[i], e);=0A@@ -745,9 +732,22 @@ bool_t ept_handle_misconfig(uin= t64_t gpa=0A }=0A else=0A {=0A- = e.emt =3D epte_get_entry_emt(p2m->domain, gfn, _mfn(e.mfn),=0A- = &ipat,=0A- = e.sa_p2mt =3D=3D p2m_mmio_direct);=0A+ int = emt =3D epte_get_entry_emt(p2m->domain, gfn, _mfn(e.mfn),=0A+ = level * EPT_TABLE_ORDER, &ipat,=0A+ = e.sa_p2mt =3D=3D p2m_mmio_direct);=0A+ = if ( unlikely(emt < 0) )=0A+ {=0A+ = unmap_domain_page(epte);=0A+ if ( ept_split_sup= er_page(p2m, &e, level, level - 1) )=0A+ {=0A+ = mfn =3D e.mfn;=0A+ continue;=0A+ = }=0A+ ept_free_entry(p2m, &e, level);=0A+ = okay =3D 0;=0A+ break;=0A+ = }=0A+ e.emt =3D emt;=0A e.ipat =3D = ipat;=0A atomic_write_ept_entry(&epte[i], e);=0A = }=0A--- a/xen/include/asm-x86/mtrr.h=0A+++ b/xen/include/asm-x86/mtrr.h= =0A@@ -72,8 +72,9 @@ extern int mtrr_del_page(int reg, unsign=0A extern = void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);=0A extern u32 = get_pat_flags(struct vcpu *v, u32 gl1e_flags, paddr_t gpaddr,=0A = paddr_t spaddr, uint8_t gmtrr_mtype);=0A-extern uint8_t epte_get_en= try_emt(struct domain *d, unsigned long gfn,=0A- = mfn_t mfn, uint8_t *ipat, bool_t direct_mmio);=0A+extern int = epte_get_entry_emt(struct domain *, unsigned long gfn, mfn_t mfn,=0A+ = unsigned int order, uint8_t *ipat,=0A+ = bool_t direct_mmio);=0A extern void ept_change_entry_emt_w= ith_range(=0A struct domain *d, unsigned long start_gfn, unsigned long = end_gfn);=0A extern unsigned char pat_type_2_pte_flags(unsigned char = pat_type);=0A --=__PartF7C59B0A.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartF7C59B0A.1__=--