From: "Jan Beulich" Subject: [PATCH] AMD IOMMU: only translate remapped IO-APIC RTEs Date: Fri, 17 Apr 2015 16:27:40 +0100 Message-ID: <5531428C02000078000735A8@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part56623F7C.2__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yj8BD-0005ee-8U for xen-devel@lists.xenproject.org; Fri, 17 Apr 2015 15:27:43 +0000 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: Sander Eikelenboom , Aravind Gopalakrishnan , suravee.suthikulpanit@amd.com 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. --=__Part56623F7C.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 1aeb1156fa ("x86 don't change affinity with interrupt unmasked") introducing RTE reads prior to the respective interrupt having got enabled for the first time uncovered a bug in 2ca9fbd739 ("AMD IOMMU: allocate IRTE entries instead of using a static mapping"): We obviously shouldn't be translating RTEs for which remapping didn't get set up yet. Reported-by: Sander Eikelenboom Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/amd/iommu_intr.c +++ b/xen/drivers/passthrough/amd/iommu_intr.c @@ -365,15 +365,17 @@ unsigned int amd_iommu_read_ioapic_from_ unsigned int apic, unsigned int reg) { unsigned int val =3D __io_apic_read(apic, reg); + unsigned int pin =3D (reg - 0x10) / 2; + unsigned int offset =3D ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx[pin]; =20 - if ( !(reg & 1) ) + if ( !(reg & 1) && offset < INTREMAP_ENTRIES ) { - unsigned int offset =3D val & (INTREMAP_ENTRIES - 1); u16 bdf =3D ioapic_sbdf[IO_APIC_ID(apic)].bdf; u16 seg =3D ioapic_sbdf[IO_APIC_ID(apic)].seg; u16 req_id =3D get_intremap_requestor_id(seg, bdf); const u32 *entry =3D get_intremap_entry(seg, req_id, offset); =20 + ASSERT(offset =3D=3D (val & (INTREMAP_ENTRIES - 1))); val &=3D ~(INTREMAP_ENTRIES - 1); val |=3D get_field_from_reg_u32(*entry, INT_REMAP_ENTRY_INTTYPE_MASK, --=__Part56623F7C.2__= Content-Type: text/plain; name="AMD-IOMMU-read-unmapped-IO-APIC-RTE.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="AMD-IOMMU-read-unmapped-IO-APIC-RTE.patch" AMD IOMMU: only translate remapped IO-APIC RTEs=0A=0A1aeb1156fa ("x86 = don't change affinity with interrupt unmasked")=0Aintroducing RTE reads = prior to the respective interrupt having got=0Aenabled for the first time = uncovered a bug in 2ca9fbd739 ("AMD IOMMU:=0Aallocate IRTE entries instead = of using a static mapping"): We obviously=0Ashouldn't be translating RTEs = for which remapping didn't get set up=0Ayet.=0A=0AReported-by: Sander = Eikelenboom =0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/drivers/passthrough/amd/iommu_intr.c=0A+++ = b/xen/drivers/passthrough/amd/iommu_intr.c=0A@@ -365,15 +365,17 @@ = unsigned int amd_iommu_read_ioapic_from_=0A unsigned int apic, = unsigned int reg)=0A {=0A unsigned int val =3D __io_apic_read(apic, = reg);=0A+ unsigned int pin =3D (reg - 0x10) / 2;=0A+ unsigned int = offset =3D ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx[pin];=0A =0A- if ( = !(reg & 1) )=0A+ if ( !(reg & 1) && offset < INTREMAP_ENTRIES )=0A = {=0A- unsigned int offset =3D val & (INTREMAP_ENTRIES - 1);=0A = u16 bdf =3D ioapic_sbdf[IO_APIC_ID(apic)].bdf;=0A u16 seg =3D = ioapic_sbdf[IO_APIC_ID(apic)].seg;=0A u16 req_id =3D get_intremap_r= equestor_id(seg, bdf);=0A const u32 *entry =3D get_intremap_entry(s= eg, req_id, offset);=0A =0A+ ASSERT(offset =3D=3D (val & (INTREMAP_E= NTRIES - 1)));=0A val &=3D ~(INTREMAP_ENTRIES - 1);=0A val = |=3D get_field_from_reg_u32(*entry,=0A = INT_REMAP_ENTRY_INTTYPE_MASK,=0A --=__Part56623F7C.2__= 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 --=__Part56623F7C.2__=--