From: "Jan Beulich" Subject: [PATCH v2 3/4] x86/EPT: IOMMU snoop capability should not affect memory type selection Date: Fri, 28 Mar 2014 13:18:22 +0000 Message-ID: <533584AE0200007800003693@nat28.tlf.novell.com> References: <533583C5020000780000367B@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartF6C49D8E.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 1WTWfw-0008DT-0K for xen-devel@lists.xenproject.org; Fri, 28 Mar 2014 13:18:24 +0000 In-Reply-To: <533583C5020000780000367B@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: Keir Fraser , Kevin Tian , Eddie Dong , Jun Nakajima , Tim Deegan 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. --=__PartF6C49D8E.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This capability solely makes a statement on cache coherency guarantees by the IOMMU. It does specifically not imply any further guarantees implied by certain memory types (cachability, ordering). Signed-off-by: Jan Beulich --- This already drops a few bits of the changes done for XSA-60. I think that if the earlier patches (and particularly the use of the EPT_MISCONFIG VM exit) are being accepted, we should switch that hole mechanism, avoiding the need to play games with the guest's PAT MSR. --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1950,6 +1950,7 @@ static void hvm_update_cr(struct vcpu *v int hvm_set_cr0(unsigned long value) { struct vcpu *v =3D current; + struct domain *d =3D v->domain; unsigned long gfn, old_value =3D v->arch.hvm_vcpu.guest_cr[0]; struct page_info *page; =20 @@ -1973,8 +1974,8 @@ int hvm_set_cr0(unsigned long value) goto gpf; =20 /* A pvh is not expected to change to real mode. */ - if ( is_pvh_vcpu(v) - && (value & (X86_CR0_PE | X86_CR0_PG)) !=3D (X86_CR0_PG | = X86_CR0_PE) ) + if ( is_pvh_domain(d) && + (value & (X86_CR0_PE | X86_CR0_PG)) !=3D (X86_CR0_PG | X86_CR0_PE= ) ) { printk(XENLOG_G_WARNING "PVH attempting to turn off PE/PG. CR0:%lx\n", value); @@ -1996,16 +1997,16 @@ int hvm_set_cr0(unsigned long value) hvm_update_guest_efer(v); } =20 - if ( !paging_mode_hap(v->domain) ) + if ( !paging_mode_hap(d) ) { /* The guest CR3 must be pointing to the guest physical. */ gfn =3D v->arch.hvm_vcpu.guest_cr[3]>>PAGE_SHIFT; - page =3D get_page_from_gfn(v->domain, gfn, NULL, P2M_ALLOC); + page =3D get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); if ( !page ) { gdprintk(XENLOG_ERR, "Invalid CR3 value =3D %lx\n", v->arch.hvm_vcpu.guest_cr[3]); - domain_crash(v->domain); + domain_crash(d); return X86EMUL_UNHANDLEABLE; } =20 @@ -2032,24 +2033,18 @@ int hvm_set_cr0(unsigned long value) hvm_update_guest_efer(v); } =20 - if ( !paging_mode_hap(v->domain) ) + if ( !paging_mode_hap(d) ) { put_page(pagetable_get_page(v->arch.guest_table)); v->arch.guest_table =3D pagetable_null(); } } =20 - /* - * When cr0.cd setting - * 1. For guest w/o VT-d, and for guest with VT-d but snooped, Xen = need not - * do anything, since hardware snoop mechanism has ensured cache = coherency; - * 2. For guest with VT-d but non-snooped, cache coherency cannot be - * guaranteed by h/w so need emulate UC memory type to guest. - */ if ( ((value ^ old_value) & X86_CR0_CD) && - has_arch_pdevs(v->domain) && - iommu_enabled && !iommu_snoop && - hvm_funcs.handle_cd ) + iommu_enabled && hvm_funcs.handle_cd && + (!rangeset_is_empty(d->iomem_caps) || + !rangeset_is_empty(d->arch.ioport_caps) || + has_arch_pdevs(d)) ) hvm_funcs.handle_cd(v, value); =20 hvm_update_cr(v, 0, value); --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -713,7 +713,7 @@ HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save =20 void memory_type_changed(struct domain *d) { - if ( iommu_enabled && !iommu_snoop && d->vcpu && d->vcpu[0] ) + if ( iommu_enabled && d->vcpu && d->vcpu[0] ) p2m_memory_type_changed(d); } =20 @@ -754,12 +754,6 @@ int epte_get_entry_emt(struct domain *d, return MTRR_TYPE_WRBACK; } =20 - if ( iommu_snoop ) - { - *ipat =3D 1; - return MTRR_TYPE_WRBACK; - } - gmtrr_mtype =3D is_hvm_domain(d) && v ? get_mtrr_type(&v->arch.hvm_vcpu.mtrr, gfn << PAGE_SHIFT, order) : --=__PartF6C49D8E.1__= Content-Type: text/plain; name="EPT-drop-snoop-dependency.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="EPT-drop-snoop-dependency.patch" x86/EPT: IOMMU snoop capability should not affect memory type selection=0A= =0AThis capability solely makes a statement on cache coherency guarantees= =0Aby the IOMMU. It does specifically not imply any further guarantees=0Aim= plied by certain memory types (cachability, ordering).=0A=0ASigned-off-by: = Jan Beulich =0A---=0AThis already drops a few bits of = the changes done for XSA-60. I think=0Athat if the earlier patches (and = particularly the use of the=0AEPT_MISCONFIG VM exit) are being accepted, = we should switch that hole=0Amechanism, avoiding the need to play games = with the guest's PAT MSR.=0A=0A--- a/xen/arch/x86/hvm/hvm.c=0A+++ = b/xen/arch/x86/hvm/hvm.c=0A@@ -1950,6 +1950,7 @@ static void hvm_update_cr(= struct vcpu *v=0A int hvm_set_cr0(unsigned long value)=0A {=0A struct = vcpu *v =3D current;=0A+ struct domain *d =3D v->domain;=0A = unsigned long gfn, old_value =3D v->arch.hvm_vcpu.guest_cr[0];=0A = struct page_info *page;=0A =0A@@ -1973,8 +1974,8 @@ int hvm_set_cr0(unsigne= d long value)=0A goto gpf;=0A =0A /* A pvh is not expected to = change to real mode. */=0A- if ( is_pvh_vcpu(v)=0A- && (value & = (X86_CR0_PE | X86_CR0_PG)) !=3D (X86_CR0_PG | X86_CR0_PE) )=0A+ if ( = is_pvh_domain(d) &&=0A+ (value & (X86_CR0_PE | X86_CR0_PG)) !=3D = (X86_CR0_PG | X86_CR0_PE) )=0A {=0A printk(XENLOG_G_WARNING=0A = "PVH attempting to turn off PE/PG. CR0:%lx\n", value);=0A@@ = -1996,16 +1997,16 @@ int hvm_set_cr0(unsigned long value)=0A = hvm_update_guest_efer(v);=0A }=0A =0A- if ( !paging_mode_hap= (v->domain) )=0A+ if ( !paging_mode_hap(d) )=0A {=0A = /* The guest CR3 must be pointing to the guest physical. */=0A = gfn =3D v->arch.hvm_vcpu.guest_cr[3]>>PAGE_SHIFT;=0A- page = =3D get_page_from_gfn(v->domain, gfn, NULL, P2M_ALLOC);=0A+ = page =3D get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);=0A if ( = !page )=0A {=0A gdprintk(XENLOG_ERR, "Invalid = CR3 value =3D %lx\n",=0A v->arch.hvm_vcpu.guest_cr= [3]);=0A- domain_crash(v->domain);=0A+ = domain_crash(d);=0A return X86EMUL_UNHANDLEABLE;=0A = }=0A =0A@@ -2032,24 +2033,18 @@ int hvm_set_cr0(unsigned long = value)=0A hvm_update_guest_efer(v);=0A }=0A =0A- = if ( !paging_mode_hap(v->domain) )=0A+ if ( !paging_mode_hap(d) = )=0A {=0A put_page(pagetable_get_page(v->arch.guest_tab= le));=0A v->arch.guest_table =3D pagetable_null();=0A = }=0A }=0A =0A- /*=0A- * When cr0.cd setting=0A- * 1. For = guest w/o VT-d, and for guest with VT-d but snooped, Xen need not=0A- = * do anything, since hardware snoop mechanism has ensured cache coherency;= =0A- * 2. For guest with VT-d but non-snooped, cache coherency cannot = be=0A- * guaranteed by h/w so need emulate UC memory type to guest.=0A-= */=0A if ( ((value ^ old_value) & X86_CR0_CD) &&=0A- = has_arch_pdevs(v->domain) &&=0A- iommu_enabled && !iommu_snoop = &&=0A- hvm_funcs.handle_cd )=0A+ iommu_enabled && = hvm_funcs.handle_cd &&=0A+ (!rangeset_is_empty(d->iomem_caps) = ||=0A+ !rangeset_is_empty(d->arch.ioport_caps) ||=0A+ = has_arch_pdevs(d)) )=0A hvm_funcs.handle_cd(v, value);=0A =0A = hvm_update_cr(v, 0, value);=0A--- a/xen/arch/x86/hvm/mtrr.c=0A+++ = b/xen/arch/x86/hvm/mtrr.c=0A@@ -713,7 +713,7 @@ HVM_REGISTER_SAVE_RESTORE(M= TRR, hvm_save=0A =0A void memory_type_changed(struct domain *d)=0A {=0A- = if ( iommu_enabled && !iommu_snoop && d->vcpu && d->vcpu[0] )=0A+ if ( = iommu_enabled && d->vcpu && d->vcpu[0] )=0A p2m_memory_type_changed= (d);=0A }=0A =0A@@ -754,12 +754,6 @@ int epte_get_entry_emt(struct domain = *d,=0A return MTRR_TYPE_WRBACK;=0A }=0A =0A- if ( iommu_snoo= p )=0A- {=0A- *ipat =3D 1;=0A- return MTRR_TYPE_WRBACK;=0A= - }=0A-=0A gmtrr_mtype =3D is_hvm_domain(d) && v ?=0A = get_mtrr_type(&v->arch.hvm_vcpu.mtrr,=0A = gfn << PAGE_SHIFT, order) :=0A --=__PartF6C49D8E.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 --=__PartF6C49D8E.1__=--