[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-3.4-testing] vtd: A few cleanups to avoid dereferencing NULL drhd pointers.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1256024996 -3600
# Node ID 66fac72877aa5cd3448c9d3fe5b565a94309a12a
# Parent  e744bd84ff3d65856868a081023db4dbe9df0f99
vtd: A few cleanups to avoid dereferencing NULL drhd pointers.

In most cases I simply remove the reference since it is never actually
used.

Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
xen-unstable changeset:   20341:ea34183c5c11
xen-unstable date:        Mon Oct 19 13:31:21 2009 +0100

vtd: Disable VT-d if no DRHD units are probed.

Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
xen-unstable changeset:   20342:1c928c3566e0
xen-unstable date:        Mon Oct 19 16:50:14 2009 +0100
---
 xen/drivers/passthrough/iommu.c     |    8 +++++---
 xen/drivers/passthrough/vtd/iommu.c |   31 ++++++-------------------------
 2 files changed, 11 insertions(+), 28 deletions(-)

diff -r e744bd84ff3d -r 66fac72877aa xen/drivers/passthrough/iommu.c
--- a/xen/drivers/passthrough/iommu.c   Mon Oct 19 13:04:11 2009 +0100
+++ b/xen/drivers/passthrough/iommu.c   Tue Oct 20 08:49:56 2009 +0100
@@ -266,9 +266,11 @@ static int iommu_setup(void)
     if ( !iommu_enabled )
         goto out;
 
-    rc = iommu_hardware_setup();
-
-    iommu_enabled = (rc == 0);
+    if ( iommu_enabled )
+    {
+        rc = iommu_hardware_setup();
+        iommu_enabled = (rc == 0);
+    }
 
  out:
     if ( force_iommu && !iommu_enabled )
diff -r e744bd84ff3d -r 66fac72877aa xen/drivers/passthrough/vtd/iommu.c
--- a/xen/drivers/passthrough/vtd/iommu.c       Mon Oct 19 13:04:11 2009 +0100
+++ b/xen/drivers/passthrough/vtd/iommu.c       Tue Oct 20 08:49:56 2009 +0100
@@ -982,11 +982,8 @@ static int intel_iommu_domain_init(struc
 static int intel_iommu_domain_init(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
-    struct iommu *iommu = NULL;
+    struct iommu *iommu;
     struct acpi_drhd_unit *drhd;
-
-    drhd = list_entry(acpi_drhd_units.next, typeof(*drhd), list);
-    iommu = drhd->iommu;
 
     hd->agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH);
 
@@ -1082,10 +1079,6 @@ static int domain_context_mapping_one(
         spin_unlock(&hd->mapping_lock);
     }
 
-    /*
-     * domain_id 0 is not valid on Intel's IOMMU, force domain_id to
-     * be 1 based as required by intel's iommu hw.
-     */
     context_set_domain_id(context, domain);
     context_set_address_width(*context, agaw);
     context_set_fault_enable(*context);
@@ -1464,9 +1457,6 @@ int intel_iommu_map_page(
     u64 pg_maddr;
     int pte_present;
 
-    drhd = list_entry(acpi_drhd_units.next, typeof(*drhd), list);
-    iommu = drhd->iommu;
-
     /* do nothing if dom0 and iommu supports pass thru */
     if ( iommu_passthrough && (d->domain_id == 0) )
         return 0;
@@ -1515,13 +1505,7 @@ int intel_iommu_map_page(
 
 int intel_iommu_unmap_page(struct domain *d, unsigned long gfn)
 {
-    struct acpi_drhd_unit *drhd;
-    struct iommu *iommu;
-
-    drhd = list_entry(acpi_drhd_units.next, typeof(*drhd), list);
-    iommu = drhd->iommu;
-
-    /* do nothing if dom0 and iommu supports pass thru */
+    /* Do nothing if dom0 and iommu supports pass thru. */
     if ( iommu_passthrough && (d->domain_id == 0) )
         return 0;
 
@@ -1768,7 +1752,7 @@ int intel_vtd_setup(void)
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
 
-    if ( !vtd_enabled )
+    if ( !vtd_enabled || list_empty(&acpi_drhd_units) )
         return -ENODEV;
 
     platform_quirks();
@@ -1814,18 +1798,15 @@ int intel_vtd_setup(void)
     P(iommu_intremap, "Interrupt Remapping");
 #undef P
 
-    /* Allocate IO page directory page for the domain. */
+    /* Allocate domain id bitmap, and set bit 0 as reserved. */
     drhd = list_entry(acpi_drhd_units.next, typeof(*drhd), list);
-    iommu = drhd->iommu;
-
-    /* Allocate domain id bitmap, and set bit 0 as reserved */
-    domid_bitmap_size = cap_ndoms(iommu->cap);
+    domid_bitmap_size = cap_ndoms(drhd->iommu->cap);
     domid_bitmap = xmalloc_array(unsigned long,
                                  BITS_TO_LONGS(domid_bitmap_size));
     if ( domid_bitmap == NULL )
         goto error;
     memset(domid_bitmap, 0, domid_bitmap_size / 8);
-    set_bit(0, domid_bitmap);
+    __set_bit(0, domid_bitmap);
 
     if ( init_vtd_hw() )
         goto error;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.