From: "Suthikulpanit, Suravee" Subject: Re: [PATCH] AMD IOMMU: only translate remapped IO-APIC RTEs Date: Thu, 23 Apr 2015 13:31:34 +0000 Message-ID: References: <5531428C02000078000735A8@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YlHEG-0005d6-Ny for xen-devel@lists.xenproject.org; Thu, 23 Apr 2015 13:31:45 +0000 In-Reply-To: <5531428C02000078000735A8@mail.emea.novell.com> Content-Language: en-US Content-ID: <6A31422EE078B04D983856A775DD9654@amd.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: Jan Beulich , xen-devel Cc: Sander Eikelenboom , "Gopalakrishnan, Aravind" List-Id: xen-devel@lists.xenproject.org On 4/17/15, 10:27, "Jan Beulich" wrote: >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 = __io_apic_read(apic, reg); >+ unsigned int pin = (reg - 0x10) / 2; >+ unsigned int offset = ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx[pin]; > >- if ( !(reg & 1) ) >+ if ( !(reg & 1) && offset < INTREMAP_ENTRIES ) > { >- unsigned int offset = val & (INTREMAP_ENTRIES - 1); > u16 bdf = ioapic_sbdf[IO_APIC_ID(apic)].bdf; > u16 seg = ioapic_sbdf[IO_APIC_ID(apic)].seg; > u16 req_id = get_intremap_requestor_id(seg, bdf); > const u32 *entry = get_intremap_entry(seg, req_id, offset); > >+ ASSERT(offset == (val & (INTREMAP_ENTRIES - 1))); Jan, could you please explain why the ASSERT is needed here? Thanks, Suravee > val &= ~(INTREMAP_ENTRIES - 1); > val |= get_field_from_reg_u32(*entry, > INT_REMAP_ENTRY_INTTYPE_MASK, > > >