IOMMU: don't BUG() on exotic hardware
authorJan Beulich <jbeulich@suse.com>
Mon, 9 May 2016 11:21:06 +0000 (13:21 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 9 May 2016 11:21:06 +0000 (13:21 +0200)
On x86, iommu_get_ops() BUG()s when running on non-Intel, non-AMD
hardware. While, with our current code, that's a correct prerequisite
assumption for IOMMU presence, this is wrong on systems without IOMMU.
Hence iommu_enabled (and alike) checks should be done prior to calling
that function, not after.

Also move iommu_suspend() next to iommu_resume() - it escapes me why
iommu_do_domctl() had got put between the two.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
Release-acked-by: Wei Liu <wei.liu2@citrix.com>
xen/drivers/passthrough/iommu.c
xen/drivers/passthrough/pci.c

index c59b2abe219ef8a918168c0d7be2c100c941353e..9d104d28a4e37dffe7b44c4de7af32f8f6a8e80a 100644 (file)
@@ -337,11 +337,16 @@ int __init iommu_setup(void)
     return rc;
 }
 
+void iommu_suspend()
+{
+    if ( iommu_enabled )
+        iommu_get_ops()->suspend();
+}
+
 void iommu_resume()
 {
-    const struct iommu_ops *ops = iommu_get_ops();
     if ( iommu_enabled )
-        ops->resume();
+        iommu_get_ops()->resume();
 }
 
 int iommu_do_domctl(
@@ -365,34 +370,28 @@ int iommu_do_domctl(
     return ret;
 }
 
-void iommu_suspend()
-{
-    const struct iommu_ops *ops = iommu_get_ops();
-    if ( iommu_enabled )
-        ops->suspend();
-}
-
 void iommu_share_p2m_table(struct domain* d)
 {
-    const struct iommu_ops *ops = iommu_get_ops();
-
     if ( iommu_enabled && iommu_use_hap_pt(d) )
-        ops->share_p2m(d);
+        iommu_get_ops()->share_p2m(d);
 }
 
 void iommu_crash_shutdown(void)
 {
-    const struct iommu_ops *ops = iommu_get_ops();
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        iommu_get_ops()->crash_shutdown();
     iommu_enabled = iommu_intremap = iommu_intpost = 0;
 }
 
 int iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt)
 {
-    const struct iommu_ops *ops = iommu_get_ops();
+    const struct iommu_ops *ops;
 
-    if ( !iommu_enabled || !ops->get_reserved_device_memory )
+    if ( !iommu_enabled )
+        return 0;
+
+    ops = iommu_get_ops();
+    if ( !ops->get_reserved_device_memory )
         return 0;
 
     return ops->get_reserved_device_memory(func, ctxt);
index 4acbc76655b81db86f8c15f39c0ca5a7926af503..98936f55cbb08c6e8a6c0ad57eeb3e3834382f49 100644 (file)
@@ -1241,16 +1241,15 @@ __initcall(setup_dump_pcidevs);
 int iommu_update_ire_from_msi(
     struct msi_desc *msi_desc, struct msi_msg *msg)
 {
-    const struct iommu_ops *ops = iommu_get_ops();
-    return iommu_intremap ? ops->update_ire_from_msi(msi_desc, msg) : 0;
+    return iommu_intremap
+           ? iommu_get_ops()->update_ire_from_msi(msi_desc, msg) : 0;
 }
 
 void iommu_read_msi_from_ire(
     struct msi_desc *msi_desc, struct msi_msg *msg)
 {
-    const struct iommu_ops *ops = iommu_get_ops();
     if ( iommu_intremap )
-        ops->read_msi_from_ire(msi_desc, msg);
+        iommu_get_ops()->read_msi_from_ire(msi_desc, msg);
 }
 
 int iommu_add_device(struct pci_dev *pdev)