ia64/xen-unstable

changeset 19177:ab514cfbcdc5

Cleanup IOMMU interrupt setup
- Check for errors when allocating interrupt vectors
- Clean up if interrupt allocation failed
- Make sure that the allocated vector is not reused

Signed-off-by: Espen Skoglund <espen.skoglund@netronome.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Feb 06 10:36:23 2009 +0000 (2009-02-06)
parents 191643d4307c
children 9dacc3722159
files xen/drivers/passthrough/amd/iommu_init.c xen/drivers/passthrough/vtd/iommu.c
line diff
     1.1 --- a/xen/drivers/passthrough/amd/iommu_init.c	Thu Feb 05 15:28:09 2009 +0000
     1.2 +++ b/xen/drivers/passthrough/amd/iommu_init.c	Fri Feb 06 10:36:23 2009 +0000
     1.3 @@ -480,15 +480,9 @@ static int set_iommu_interrupt_handler(s
     1.4      int vector, ret;
     1.5  
     1.6      vector = assign_irq_vector(AUTO_ASSIGN);
     1.7 -    vector_to_iommu[vector] = iommu;
     1.8 -
     1.9 -    /* make irq == vector */
    1.10 -    irq_vector[vector] = vector;
    1.11 -    vector_irq[vector] = vector;
    1.12 -
    1.13 -    if ( !vector )
    1.14 +    if ( vector <= 0 )
    1.15      {
    1.16 -        amd_iov_error("no vectors\n");
    1.17 +        gdprintk(XENLOG_ERR VTDPREFIX, "IOMMU: no vectors\n");
    1.18          return 0;
    1.19      }
    1.20  
    1.21 @@ -496,9 +490,15 @@ static int set_iommu_interrupt_handler(s
    1.22      ret = request_irq(vector, amd_iommu_page_fault, 0, "amd_iommu", iommu);
    1.23      if ( ret )
    1.24      {
    1.25 +        irq_desc[vector].handler = &no_irq_type;
    1.26 +        free_irq_vector(vector);
    1.27          amd_iov_error("can't request irq\n");
    1.28          return 0;
    1.29      }
    1.30 +
    1.31 +    /* Make sure that vector is never re-used. */
    1.32 +    vector_irq[vector] = NEVER_ASSIGN;
    1.33 +    vector_to_iommu[vector] = iommu;
    1.34      iommu->vector = vector;
    1.35      return vector;
    1.36  }
     2.1 --- a/xen/drivers/passthrough/vtd/iommu.c	Thu Feb 05 15:28:09 2009 +0000
     2.2 +++ b/xen/drivers/passthrough/vtd/iommu.c	Fri Feb 06 10:36:23 2009 +0000
     2.3 @@ -875,13 +875,7 @@ int iommu_set_interrupt(struct iommu *io
     2.4      int vector, ret;
     2.5  
     2.6      vector = assign_irq_vector(AUTO_ASSIGN);
     2.7 -    vector_to_iommu[vector] = iommu;
     2.8 -
     2.9 -    /* VT-d fault is a MSI, make irq == vector */
    2.10 -    irq_vector[vector] = vector;
    2.11 -    vector_irq[vector] = vector;
    2.12 -
    2.13 -    if ( !vector )
    2.14 +    if ( vector <= 0 )
    2.15      {
    2.16          gdprintk(XENLOG_ERR VTDPREFIX, "IOMMU: no vectors\n");
    2.17          return -EINVAL;
    2.18 @@ -890,7 +884,17 @@ int iommu_set_interrupt(struct iommu *io
    2.19      irq_desc[vector].handler = &dma_msi_type;
    2.20      ret = request_irq(vector, iommu_page_fault, 0, "dmar", iommu);
    2.21      if ( ret )
    2.22 +    {
    2.23 +        irq_desc[vector].handler = &no_irq_type;
    2.24 +        free_irq_vector(vector);
    2.25          gdprintk(XENLOG_ERR VTDPREFIX, "IOMMU: can't request irq\n");
    2.26 +        return ret;
    2.27 +    }
    2.28 +
    2.29 +    /* Make sure that vector is never re-used. */
    2.30 +    vector_irq[vector] = NEVER_ASSIGN;
    2.31 +    vector_to_iommu[vector] = iommu;
    2.32 +
    2.33      return vector;
    2.34  }
    2.35  
    2.36 @@ -1677,6 +1681,11 @@ static int init_vtd_hw(void)
    2.37          }
    2.38  
    2.39          vector = iommu_set_interrupt(iommu);
    2.40 +        if ( vector < 0 )
    2.41 +        {
    2.42 +            gdprintk(XENLOG_ERR VTDPREFIX, "IOMMU: interrupt setup failed\n");
    2.43 +            return vector;
    2.44 +        }
    2.45          dma_msi_data_init(iommu, vector);
    2.46          dma_msi_addr_init(iommu, cpu_physical_id(first_cpu(cpu_online_map)));
    2.47          iommu->vector = vector;