aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNishanth Aravamudan <nacc@linux.vnet.ibm.com>2015-02-21 14:00:50 -0500
committerMichael Ellerman <mpe@ellerman.id.au>2015-03-03 21:19:33 -0500
commit4ad04e5987115ece5fa8a0cf1dc72fcd4707e33e (patch)
tree61b5a9fa79e15af596924997068e2c69edd965ca
parent875ebe940d77a41682c367ad799b4f39f128d3fa (diff)
powerpc/iommu: Remove IOMMU device references via bus notifier
After d905c5df9aef ("PPC: POWERNV: move iommu_add_device earlier"), the refcnt on the kobject backing the IOMMU group for a PCI device is elevated by each call to pci_dma_dev_setup_pSeriesLP() (via set_iommu_table_base_and_group). When we go to dlpar a multi-function PCI device out: iommu_reconfig_notifier -> iommu_free_table -> iommu_group_put BUG_ON(tbl->it_group) We trip this BUG_ON, because there are still references on the table, so it is not freed. Fix this by moving the powernv bus notifier to common code and calling it for both powernv and pseries. Fixes: d905c5df9aef ("PPC: POWERNV: move iommu_add_device earlier") Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com> Tested-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--arch/powerpc/include/asm/iommu.h6
-rw-r--r--arch/powerpc/kernel/iommu.c26
-rw-r--r--arch/powerpc/platforms/powernv/pci.c26
-rw-r--r--arch/powerpc/platforms/pseries/iommu.c2
4 files changed, 34 insertions, 26 deletions
diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
index 9cfa3706a1b8..f1ea5972f6ec 100644
--- a/arch/powerpc/include/asm/iommu.h
+++ b/arch/powerpc/include/asm/iommu.h
@@ -113,6 +113,7 @@ extern void iommu_register_group(struct iommu_table *tbl,
113 int pci_domain_number, unsigned long pe_num); 113 int pci_domain_number, unsigned long pe_num);
114extern int iommu_add_device(struct device *dev); 114extern int iommu_add_device(struct device *dev);
115extern void iommu_del_device(struct device *dev); 115extern void iommu_del_device(struct device *dev);
116extern int __init tce_iommu_bus_notifier_init(void);
116#else 117#else
117static inline void iommu_register_group(struct iommu_table *tbl, 118static inline void iommu_register_group(struct iommu_table *tbl,
118 int pci_domain_number, 119 int pci_domain_number,
@@ -128,6 +129,11 @@ static inline int iommu_add_device(struct device *dev)
128static inline void iommu_del_device(struct device *dev) 129static inline void iommu_del_device(struct device *dev)
129{ 130{
130} 131}
132
133static inline int __init tce_iommu_bus_notifier_init(void)
134{
135 return 0;
136}
131#endif /* !CONFIG_IOMMU_API */ 137#endif /* !CONFIG_IOMMU_API */
132 138
133static inline void set_iommu_table_base_and_group(struct device *dev, 139static inline void set_iommu_table_base_and_group(struct device *dev,
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index 5d3968c4d799..b054f33ab1fb 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -1175,4 +1175,30 @@ void iommu_del_device(struct device *dev)
1175} 1175}
1176EXPORT_SYMBOL_GPL(iommu_del_device); 1176EXPORT_SYMBOL_GPL(iommu_del_device);
1177 1177
1178static int tce_iommu_bus_notifier(struct notifier_block *nb,
1179 unsigned long action, void *data)
1180{
1181 struct device *dev = data;
1182
1183 switch (action) {
1184 case BUS_NOTIFY_ADD_DEVICE:
1185 return iommu_add_device(dev);
1186 case BUS_NOTIFY_DEL_DEVICE:
1187 if (dev->iommu_group)
1188 iommu_del_device(dev);
1189 return 0;
1190 default:
1191 return 0;
1192 }
1193}
1194
1195static struct notifier_block tce_iommu_bus_nb = {
1196 .notifier_call = tce_iommu_bus_notifier,
1197};
1198
1199int __init tce_iommu_bus_notifier_init(void)
1200{
1201 bus_register_notifier(&pci_bus_type, &tce_iommu_bus_nb);
1202 return 0;
1203}
1178#endif /* CONFIG_IOMMU_API */ 1204#endif /* CONFIG_IOMMU_API */
diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
index e69142f4af08..54323d6b5166 100644
--- a/arch/powerpc/platforms/powernv/pci.c
+++ b/arch/powerpc/platforms/powernv/pci.c
@@ -836,30 +836,4 @@ void __init pnv_pci_init(void)
836#endif 836#endif
837} 837}
838 838
839static int tce_iommu_bus_notifier(struct notifier_block *nb,
840 unsigned long action, void *data)
841{
842 struct device *dev = data;
843
844 switch (action) {
845 case BUS_NOTIFY_ADD_DEVICE:
846 return iommu_add_device(dev);
847 case BUS_NOTIFY_DEL_DEVICE:
848 if (dev->iommu_group)
849 iommu_del_device(dev);
850 return 0;
851 default:
852 return 0;
853 }
854}
855
856static struct notifier_block tce_iommu_bus_nb = {
857 .notifier_call = tce_iommu_bus_notifier,
858};
859
860static int __init tce_iommu_bus_notifier_init(void)
861{
862 bus_register_notifier(&pci_bus_type, &tce_iommu_bus_nb);
863 return 0;
864}
865machine_subsys_initcall_sync(powernv, tce_iommu_bus_notifier_init); 839machine_subsys_initcall_sync(powernv, tce_iommu_bus_notifier_init);
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index 1d3d52dc3ff3..7803a19adb31 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -1340,3 +1340,5 @@ static int __init disable_multitce(char *str)
1340} 1340}
1341 1341
1342__setup("multitce=", disable_multitce); 1342__setup("multitce=", disable_multitce);
1343
1344machine_subsys_initcall_sync(pseries, tce_iommu_bus_notifier_init);