ia64/xen-unstable

changeset 18981:b3a9bc726241

vtd: avoid redundant context mapping

After changeset 18934 (VT-d: Fix PCI-X device assignment), my assigned
PCI E1000 NIC doesn't work in guest.

The NIC is 03:00.0. Its parent bridge is: 00:1e.0.
In domain_context_mapping():
case DEV_TYPE_PCI:
After we domain_context_mapping_one() 03:00.0 and 00:1e.0, the
'secbus' is 3 and 'bus' is 0, so we domain_context_mapping_one()
03:00.0 again -- this redundant invocation returns -EINVAL because
we have created the mapping but haven't changed pdev->domain from
Dom0 to a new domain at this time and eventually the
XEN_DOMCTL_assign_device hypercall returns a failure.

The attached patch detects this case and avoids the redundant
invocation.

Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jan 05 11:13:22 2009 +0000 (2009-01-05)
parents 9cc632cc6d40
children f76f1294d82c
files xen/drivers/passthrough/vtd/iommu.c
line diff
     1.1 --- a/xen/drivers/passthrough/vtd/iommu.c	Mon Jan 05 11:08:53 2009 +0000
     1.2 +++ b/xen/drivers/passthrough/vtd/iommu.c	Mon Jan 05 11:13:22 2009 +0000
     1.3 @@ -1209,7 +1209,7 @@ static int domain_context_mapping(struct
     1.4      int ret = 0;
     1.5      u16 sec_bus, sub_bus;
     1.6      u32 type;
     1.7 -    u8 secbus;
     1.8 +    u8 secbus, secdevfn;
     1.9  
    1.10      drhd = acpi_find_matched_drhd_unit(bus, devfn);
    1.11      if ( !drhd )
    1.12 @@ -1256,10 +1256,12 @@ static int domain_context_mapping(struct
    1.13             break;
    1.14  
    1.15          secbus = bus;
    1.16 +        secdevfn = devfn;
    1.17          /* dependent devices mapping */
    1.18          while ( bus2bridge[bus].map )
    1.19          {
    1.20              secbus = bus;
    1.21 +            secdevfn = devfn;
    1.22              devfn = bus2bridge[bus].devfn;
    1.23              bus = bus2bridge[bus].bus;
    1.24              ret = domain_context_mapping_one(domain, drhd->iommu, bus, devfn);
    1.25 @@ -1267,7 +1269,7 @@ static int domain_context_mapping(struct
    1.26                  return ret;
    1.27          }
    1.28  
    1.29 -        if ( secbus != bus )
    1.30 +        if ( (secbus != bus) && (secdevfn != 0) )
    1.31              /*
    1.32               * The source-id for transactions on non-PCIe buses seem
    1.33               * to originate from devfn=0 on the secondary bus behind
    1.34 @@ -1333,7 +1335,7 @@ static int domain_context_unmap(struct d
    1.35      struct acpi_drhd_unit *drhd;
    1.36      int ret = 0;
    1.37      u32 type;
    1.38 -    u8 secbus;
    1.39 +    u8 secbus, secdevfn;
    1.40  
    1.41      drhd = acpi_find_matched_drhd_unit(bus, devfn);
    1.42      if ( !drhd )
    1.43 @@ -1362,10 +1364,12 @@ static int domain_context_unmap(struct d
    1.44              break;
    1.45  
    1.46          secbus = bus;
    1.47 +        secdevfn = devfn;
    1.48          /* dependent devices unmapping */
    1.49          while ( bus2bridge[bus].map )
    1.50          {
    1.51              secbus = bus;
    1.52 +            secdevfn = devfn;
    1.53              devfn = bus2bridge[bus].devfn;
    1.54              bus = bus2bridge[bus].bus;
    1.55              ret = domain_context_unmap_one(domain, drhd->iommu, bus, devfn);
    1.56 @@ -1373,7 +1377,7 @@ static int domain_context_unmap(struct d
    1.57                  return ret;
    1.58          }
    1.59  
    1.60 -        if ( bus != secbus )
    1.61 +        if ( (secbus != bus) && (secdevfn != 0) )
    1.62              ret = domain_context_unmap_one(domain, drhd->iommu, secbus, 0);
    1.63          break;
    1.64