* [PATCH 1/4] powerpc: vio: Remove dma not supported warnings
@ 2012-06-25 4:23 Anton Blanchard
2012-06-25 4:24 ` [PATCH 2/4] powerpc: vio: Separate vio bus probe and device probe Anton Blanchard
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Anton Blanchard @ 2012-06-25 4:23 UTC (permalink / raw)
To: benh, paulus, michael, miltonm, nacc, brking, rcj; +Cc: linuxppc-dev
During boot we see a number of these warnings:
vio 30000000: Warning: IOMMU dma not supported: mask 0xffffffffffffffff, table unavailable
The reason for this is that we set IOMMU properties for all VIO
devices even if they are not DMA capable.
Only set DMA ops, table and mask for devices with a DMA window.
Signed-off-by: Anton Blanchard <anton@samba.org>
---
Index: linux-build/arch/powerpc/kernel/vio.c
===================================================================
--- linux-build.orig/arch/powerpc/kernel/vio.c 2012-06-08 14:02:05.548512941 +1000
+++ linux-build/arch/powerpc/kernel/vio.c 2012-06-25 13:49:54.349806390 +1000
@@ -1397,21 +1397,27 @@ struct vio_dev *vio_register_device_node
viodev->name = of_node->name;
viodev->dev.of_node = of_node_get(of_node);
- if (firmware_has_feature(FW_FEATURE_CMO))
- vio_cmo_set_dma_ops(viodev);
- else
- set_dma_ops(&viodev->dev, &dma_iommu_ops);
- set_iommu_table_base(&viodev->dev, vio_build_iommu_table(viodev));
set_dev_node(&viodev->dev, of_node_to_nid(of_node));
/* init generic 'struct device' fields: */
viodev->dev.parent = &vio_bus_device.dev;
viodev->dev.bus = &vio_bus_type;
viodev->dev.release = vio_dev_release;
- /* needed to ensure proper operation of coherent allocations
- * later, in case driver doesn't set it explicitly */
- dma_set_mask(&viodev->dev, DMA_BIT_MASK(64));
- dma_set_coherent_mask(&viodev->dev, DMA_BIT_MASK(64));
+
+ if (of_get_property(viodev->dev.of_node, "ibm,my-dma-window", NULL)) {
+ if (firmware_has_feature(FW_FEATURE_CMO))
+ vio_cmo_set_dma_ops(viodev);
+ else
+ set_dma_ops(&viodev->dev, &dma_iommu_ops);
+
+ set_iommu_table_base(&viodev->dev,
+ vio_build_iommu_table(viodev));
+
+ /* needed to ensure proper operation of coherent allocations
+ * later, in case driver doesn't set it explicitly */
+ dma_set_mask(&viodev->dev, DMA_BIT_MASK(64));
+ dma_set_coherent_mask(&viodev->dev, DMA_BIT_MASK(64));
+ }
/* register with generic device framework */
if (device_register(&viodev->dev)) {
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/4] powerpc: vio: Separate vio bus probe and device probe
2012-06-25 4:23 [PATCH 1/4] powerpc: vio: Remove dma not supported warnings Anton Blanchard
@ 2012-06-25 4:24 ` Anton Blanchard
2012-06-25 4:25 ` [PATCH 3/4] powerpc: call dma_debug_add_bus for PCI and VIO buses Anton Blanchard
2012-06-25 4:26 ` [PATCH 4/4] powerpc: IOMMU fault injection Anton Blanchard
2 siblings, 0 replies; 4+ messages in thread
From: Anton Blanchard @ 2012-06-25 4:24 UTC (permalink / raw)
To: benh, paulus, michael, miltonm, nacc, brking, rcj; +Cc: linuxppc-dev
Similar to PCI, separate the bus probe from device probe. This allows
us to attach bus notifiers for DMA debug and IOMMU fault injection
before devices have been probed.
Signed-off-by: Anton Blanchard <anton@samba.org>
---
Index: linux-build/arch/powerpc/kernel/vio.c
===================================================================
--- linux-build.orig/arch/powerpc/kernel/vio.c 2012-06-08 09:14:19.282098456 +1000
+++ linux-build/arch/powerpc/kernel/vio.c 2012-06-08 09:16:53.856359566 +1000
@@ -1497,12 +1497,18 @@ static int __init vio_bus_init(void)
if (firmware_has_feature(FW_FEATURE_CMO))
vio_cmo_bus_init();
+ return 0;
+}
+postcore_initcall(vio_bus_init);
+
+static int __init vio_device_init(void)
+{
vio_bus_scan_register_devices("vdevice");
vio_bus_scan_register_devices("ibm,platform-facilities");
return 0;
}
-__initcall(vio_bus_init);
+device_initcall(vio_device_init);
static ssize_t name_show(struct device *dev,
struct device_attribute *attr, char *buf)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/4] powerpc: call dma_debug_add_bus for PCI and VIO buses
2012-06-25 4:23 [PATCH 1/4] powerpc: vio: Remove dma not supported warnings Anton Blanchard
2012-06-25 4:24 ` [PATCH 2/4] powerpc: vio: Separate vio bus probe and device probe Anton Blanchard
@ 2012-06-25 4:25 ` Anton Blanchard
2012-06-25 4:26 ` [PATCH 4/4] powerpc: IOMMU fault injection Anton Blanchard
2 siblings, 0 replies; 4+ messages in thread
From: Anton Blanchard @ 2012-06-25 4:25 UTC (permalink / raw)
To: benh, paulus, michael, miltonm, nacc, brking, rcj; +Cc: linuxppc-dev
The DMA API debug code has hooks to verify all DMA entries have been
freed at time of hot unplug. We need to call dma_debug_add_bus for
this to work.
Signed-off-by: Anton Blanchard <anton@samba.org>
---
Index: linux-build/arch/powerpc/kernel/vio.c
===================================================================
--- linux-build.orig/arch/powerpc/kernel/vio.c 2012-06-08 09:16:53.856359566 +1000
+++ linux-build/arch/powerpc/kernel/vio.c 2012-06-08 09:17:43.625089518 +1000
@@ -37,8 +37,6 @@
#include <asm/page.h>
#include <asm/hvcall.h>
-static struct bus_type vio_bus_type;
-
static struct vio_dev vio_bus_device = { /* fake "parent" device */
.name = "vio",
.type = "",
@@ -1580,7 +1578,7 @@ static int vio_hotplug(struct device *de
return 0;
}
-static struct bus_type vio_bus_type = {
+struct bus_type vio_bus_type = {
.name = "vio",
.dev_attrs = vio_dev_attrs,
.uevent = vio_hotplug,
Index: linux-build/arch/powerpc/kernel/dma.c
===================================================================
--- linux-build.orig/arch/powerpc/kernel/dma.c 2012-06-08 09:12:47.356758198 +1000
+++ linux-build/arch/powerpc/kernel/dma.c 2012-06-08 09:17:43.625089518 +1000
@@ -11,6 +11,8 @@
#include <linux/gfp.h>
#include <linux/memblock.h>
#include <linux/export.h>
+#include <linux/pci.h>
+#include <asm/vio.h>
#include <asm/bug.h>
#include <asm/abs_addr.h>
#include <asm/machdep.h>
@@ -205,7 +207,13 @@ EXPORT_SYMBOL_GPL(dma_get_required_mask)
static int __init dma_init(void)
{
- dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
+ dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
+#ifdef CONFIG_PCI
+ dma_debug_add_bus(&pci_bus_type);
+#endif
+#ifdef CONFIG_IBMVIO
+ dma_debug_add_bus(&vio_bus_type);
+#endif
return 0;
}
Index: linux-build/arch/powerpc/include/asm/vio.h
===================================================================
--- linux-build.orig/arch/powerpc/include/asm/vio.h 2012-06-08 09:12:47.344758025 +1000
+++ linux-build/arch/powerpc/include/asm/vio.h 2012-06-08 09:17:43.625089518 +1000
@@ -44,6 +44,8 @@
*/
#define VIO_CMO_MIN_ENT 1562624
+extern struct bus_type vio_bus_type;
+
struct iommu_table;
/*
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 4/4] powerpc: IOMMU fault injection
2012-06-25 4:23 [PATCH 1/4] powerpc: vio: Remove dma not supported warnings Anton Blanchard
2012-06-25 4:24 ` [PATCH 2/4] powerpc: vio: Separate vio bus probe and device probe Anton Blanchard
2012-06-25 4:25 ` [PATCH 3/4] powerpc: call dma_debug_add_bus for PCI and VIO buses Anton Blanchard
@ 2012-06-25 4:26 ` Anton Blanchard
2 siblings, 0 replies; 4+ messages in thread
From: Anton Blanchard @ 2012-06-25 4:26 UTC (permalink / raw)
To: benh, paulus, michael, miltonm, nacc, brking, rcj; +Cc: linuxppc-dev
Add the ability to inject IOMMU faults. We enable this per device
via a fail_iommu sysfs property, similar to fault injection on other
subsystems.
An example:
# lspci
...
0003:01:00.1 Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 02)
To inject one error to this device:
echo 1 > /sys/bus/pci/devices/0003:01:00.1/fail_iommu
echo 1 > /sys/kernel/debug/fail_iommu/probability
echo 1 > /sys/kernel/debug/fail_iommu/times
As feared, the first failure injected on the be3 results in an
unrecoverable error, taking down both functions of the card
permanently:
be2net 0003:01:00.1: Unrecoverable error in the card
Signed-off-by: Anton Blanchard <anton@samba.org>
---
Index: linux-build/arch/powerpc/kernel/iommu.c
===================================================================
--- linux-build.orig/arch/powerpc/kernel/iommu.c 2012-06-08 09:01:02.785709100 +1000
+++ linux-build/arch/powerpc/kernel/iommu.c 2012-06-08 09:01:07.489784856 +1000
@@ -33,7 +33,9 @@
#include <linux/bitmap.h>
#include <linux/iommu-helper.h>
#include <linux/crash_dump.h>
+#include <linux/fault-inject.h>
#include <asm/io.h>
+#include <asm/vio.h>
#include <asm/prom.h>
#include <asm/iommu.h>
#include <asm/pci-bridge.h>
@@ -58,6 +60,94 @@ static int __init setup_iommu(char *str)
__setup("iommu=", setup_iommu);
+#ifdef CONFIG_FAIL_IOMMU
+
+static DECLARE_FAULT_ATTR(fail_iommu);
+
+static int __init setup_fail_iommu(char *str)
+{
+ return setup_fault_attr(&fail_iommu, str);
+}
+__setup("fail_iommu=", setup_fail_iommu);
+
+static bool should_fail_iommu(struct device *dev)
+{
+ return dev->archdata.fail_iommu && should_fail(&fail_iommu, 1);
+}
+
+static int __init fail_iommu_debugfs(void)
+{
+ struct dentry *dir = fault_create_debugfs_attr("fail_iommu",
+ NULL, &fail_iommu);
+
+ return IS_ERR(dir) ? PTR_ERR(dir) : 0;
+}
+late_initcall(fail_iommu_debugfs);
+
+static ssize_t fail_iommu_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ return sprintf(buf, "%d\n", dev->archdata.fail_iommu);
+}
+
+static ssize_t fail_iommu_store(struct device *dev,
+ struct device_attribute *attr, const char *buf,
+ size_t count)
+{
+ int i;
+
+ if (count > 0 && sscanf(buf, "%d", &i) > 0)
+ dev->archdata.fail_iommu = (i == 0) ? 0 : 1;
+
+ return count;
+}
+
+static DEVICE_ATTR(fail_iommu, S_IRUGO|S_IWUSR, fail_iommu_show,
+ fail_iommu_store);
+
+static int fail_iommu_bus_notify(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct device *dev = data;
+
+ if (action == BUS_NOTIFY_ADD_DEVICE) {
+ if (device_create_file(dev, &dev_attr_fail_iommu))
+ pr_warn("Unable to create IOMMU fault injection sysfs "
+ "entries\n");
+ } else if (action == BUS_NOTIFY_DEL_DEVICE) {
+ device_remove_file(dev, &dev_attr_fail_iommu);
+ }
+
+ return 0;
+}
+
+static struct notifier_block fail_iommu_bus_notifier = {
+ .notifier_call = fail_iommu_bus_notify
+};
+
+static int __init fail_iommu_setup(void)
+{
+#ifdef CONFIG_PCI
+ bus_register_notifier(&pci_bus_type, &fail_iommu_bus_notifier);
+#endif
+#ifdef CONFIG_IBMVIO
+ bus_register_notifier(&vio_bus_type, &fail_iommu_bus_notifier);
+#endif
+
+ return 0;
+}
+/*
+ * Must execute after PCI and VIO subsystem have initialised but before
+ * devices are probed.
+ */
+arch_initcall(fail_iommu_setup);
+#else
+static inline bool should_fail_iommu(struct device *dev)
+{
+ return false;
+}
+#endif
+
static unsigned long iommu_range_alloc(struct device *dev,
struct iommu_table *tbl,
unsigned long npages,
@@ -83,6 +173,9 @@ static unsigned long iommu_range_alloc(s
return DMA_ERROR_CODE;
}
+ if (should_fail_iommu(dev))
+ return DMA_ERROR_CODE;
+
if (handle && *handle)
start = *handle;
else
Index: linux-build/arch/powerpc/include/asm/device.h
===================================================================
--- linux-build.orig/arch/powerpc/include/asm/device.h 2012-06-08 09:01:02.765708778 +1000
+++ linux-build/arch/powerpc/include/asm/device.h 2012-06-08 09:01:07.489784856 +1000
@@ -34,6 +34,9 @@ struct dev_archdata {
#ifdef CONFIG_EEH
struct eeh_dev *edev;
#endif
+#ifdef CONFIG_FAIL_IOMMU
+ int fail_iommu;
+#endif
};
struct pdev_archdata {
Index: linux-build/arch/powerpc/Kconfig.debug
===================================================================
--- linux-build.orig/arch/powerpc/Kconfig.debug 2012-06-08 09:01:02.753708585 +1000
+++ linux-build/arch/powerpc/Kconfig.debug 2012-06-08 09:01:07.489784856 +1000
@@ -331,4 +331,13 @@ config STRICT_DEVMEM
If you are unsure, say Y.
+config FAIL_IOMMU
+ bool "Fault-injection capability for IOMMU"
+ depends on FAULT_INJECTION
+ help
+ Provide fault-injection capability for IOMMU. Each device can
+ be selectively enabled via the fail_iommu property.
+
+ If you are unsure, say N.
+
endmenu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-06-25 4:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-25 4:23 [PATCH 1/4] powerpc: vio: Remove dma not supported warnings Anton Blanchard
2012-06-25 4:24 ` [PATCH 2/4] powerpc: vio: Separate vio bus probe and device probe Anton Blanchard
2012-06-25 4:25 ` [PATCH 3/4] powerpc: call dma_debug_add_bus for PCI and VIO buses Anton Blanchard
2012-06-25 4:26 ` [PATCH 4/4] powerpc: IOMMU fault injection Anton Blanchard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).