iommu/pamu: Fix PAMU boot crash
authorJoerg Roedel <jroedel@suse.de>
Wed, 23 Aug 2017 14:28:09 +0000 (16:28 +0200)
committerJoerg Roedel <jroedel@suse.de>
Wed, 23 Aug 2017 14:28:09 +0000 (16:28 +0200)
Commit 68a17f0be6fe introduced an initialization order
problem, where devices are linked against an iommu which is
not yet initialized. Fix it by initializing the iommu-device
before the iommu-ops are registered against the bus.

Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Fixes: 68a17f0be6fe ('iommu/pamu: Add support for generic iommu-device')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/fsl_pamu.c
drivers/iommu/fsl_pamu.h
drivers/iommu/fsl_pamu_domain.c
drivers/iommu/fsl_pamu_domain.h

index 9238a85..9ee8e9e 100644 (file)
@@ -44,8 +44,6 @@ static struct paace *spaact;
 
 static bool probed;                    /* Has PAMU been probed? */
 
-struct iommu_device pamu_iommu;        /* IOMMU core code handle */
-
 /*
  * Table for matching compatible strings, for device tree
  * guts node, for QorIQ SOCs.
@@ -1156,18 +1154,6 @@ static int fsl_pamu_probe(struct platform_device *pdev)
        if (ret)
                goto error_genpool;
 
-       ret = iommu_device_sysfs_add(&pamu_iommu, dev, NULL, "iommu0");
-       if (ret)
-               goto error_genpool;
-
-       iommu_device_set_ops(&pamu_iommu, &fsl_pamu_ops);
-
-       ret = iommu_device_register(&pamu_iommu);
-       if (ret) {
-               dev_err(dev, "Can't register iommu device\n");
-               goto error_sysfs;
-       }
-
        pamubypenr = in_be32(&guts_regs->pamubypenr);
 
        for (pamu_reg_off = 0, pamu_counter = 0x80000000; pamu_reg_off < size;
@@ -1195,9 +1181,6 @@ static int fsl_pamu_probe(struct platform_device *pdev)
 
        return 0;
 
-error_sysfs:
-       iommu_device_sysfs_remove(&pamu_iommu);
-
 error_genpool:
        gen_pool_destroy(spaace_pool);
 
index fa48222..c3434f2 100644 (file)
@@ -391,9 +391,6 @@ struct ome {
 #define EOE_WWSAOL      0x1e    /* Write with stash allocate only and lock */
 #define EOE_VALID       0x80
 
-extern const struct iommu_ops fsl_pamu_ops;
-extern struct iommu_device pamu_iommu; /* IOMMU core code handle */
-
 /* Function prototypes */
 int pamu_domain_init(void);
 int pamu_enable_liodn(int liodn);
index 914953b..e0fcd07 100644 (file)
@@ -33,6 +33,8 @@ static struct kmem_cache *fsl_pamu_domain_cache;
 static struct kmem_cache *iommu_devinfo_cache;
 static DEFINE_SPINLOCK(device_domain_lock);
 
+struct iommu_device pamu_iommu;        /* IOMMU core code handle */
+
 static struct fsl_dma_domain *to_fsl_dma_domain(struct iommu_domain *dom)
 {
        return container_of(dom, struct fsl_dma_domain, iommu_domain);
@@ -1050,7 +1052,7 @@ static u32 fsl_pamu_get_windows(struct iommu_domain *domain)
        return dma_domain->win_cnt;
 }
 
-const struct iommu_ops fsl_pamu_ops = {
+static const struct iommu_ops fsl_pamu_ops = {
        .capable        = fsl_pamu_capable,
        .domain_alloc   = fsl_pamu_domain_alloc,
        .domain_free    = fsl_pamu_domain_free,
@@ -1076,6 +1078,19 @@ int __init pamu_domain_init(void)
        if (ret)
                return ret;
 
+       ret = iommu_device_sysfs_add(&pamu_iommu, NULL, NULL, "iommu0");
+       if (ret)
+               return ret;
+
+       iommu_device_set_ops(&pamu_iommu, &fsl_pamu_ops);
+
+       ret = iommu_device_register(&pamu_iommu);
+       if (ret) {
+               iommu_device_sysfs_remove(&pamu_iommu);
+               pr_err("Can't register iommu device\n");
+               return ret;
+       }
+
        bus_set_iommu(&platform_bus_type, &fsl_pamu_ops);
        bus_set_iommu(&pci_bus_type, &fsl_pamu_ops);
 
index 6d8661e..f2b0f74 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "fsl_pamu.h"
 
-const struct iommu_ops fsl_pamu_ops;
-
 struct dma_window {
        phys_addr_t paddr;
        u64 size;