Skip to contentSkip to conversation

iommu: Add event tracing feature to iommu

PATCH Applied Shuah Khan 2 participants 9 messages Aug 15, 2013 – Sep 24, 2013

Subsystems (2)
lore
Share & tools
lore

Shuah Khan

author
#0 lore raw

cover iommu: Add event tracing feature to iommu

This patch set adds tracing feature to iommu driver to report various iommu events. Classes iommu_group, iommu_device, and iommu_map_unmap are defined.

iommu_group class events can be enabled to trigger when devices get added to and removed from an iommu group. Trace information includes iommu group id and device name.

iommu:add_device_to_group
iommu:remove_device_from_group

iommu_device class events can be enabled to trigger when devices are attached to and detached from a domain. Trace information includes device name.

iommu:attach_device_to_domain
iommu:detach_device_from_domain

iommu_map_unmap class events can be enabled to trigger when iommu map and unmap iommu ops complete. Trace information includes iova, physical address (map event only), and size.

iommu:map
iommu:unmap

In addition to defining the new traces, iommu driver is changed to call trace events.

Changes since the last patch set:
- Addressed feedback: removed iommu_amd_event class.
- Generated patch with the new trace event defines.
- Generated individual patches for each trace event call in iommu driver

Shuah Khan (7):
iommu: Add event tracing feature to iommu
iommu: Change iommu driver to call add_device_to_group trace event
iommu: Change iommu driver to call remove_device_to_group trace event
iommu: Change iommu driver to call attach_device_to_domain trace
event
iommu: Change iommu driver to call detach_device_to_domain trace
event
iommu: Change iommu driver to call map trace event
iommu: Change iommu driver to call unmap trace event

 drivers/iommu/Makefile       |    1 +
 drivers/iommu/iommu-traces.c |   24 ++++++++
 drivers/iommu/iommu.c        |   15 ++++-
 include/trace/events/iommu.h |  129 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 168 insertions(+), 1 deletion(-)
 create mode 100644 drivers/iommu/iommu-traces.c
 create mode 100644 include/trace/events/iommu.h
Signature · 1 line
1.7.10.4
author
#1 lore raw

PATCH 1/7 iommu: Add event tracing feature to iommu

Add tracing feature to iommu to report various iommu events. Classes iommu_group, iommu_device, and iommu_map_unmap are defined.

iommu_group class events can be enabled to trigger when devices get added to and removed from an iommu group. Trace information includes iommu group id and device name.

iommu:add_device_to_group
iommu:remove_device_from_group

iommu_device class events can be enabled to trigger when devices are attached to and detached from a domain. Trace information includes device name.

iommu:attach_device_to_domain
iommu:detach_device_from_domain

iommu_map_unmap class events can be enabled to trigger when iommu map and unmap iommu ops. Trace information includes iova, physical address (map event only), and size.

iommu:map
iommu:unmap

---
 drivers/iommu/Makefile       |    1 +
 drivers/iommu/iommu-traces.c |   24 ++++++++
 drivers/iommu/iommu.c        |    1 +
 include/trace/events/iommu.h |  129 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 155 insertions(+)
 create mode 100644 drivers/iommu/iommu-traces.c
 create mode 100644 include/trace/events/iommu.h
drivers/iommu/Makefile +1 -0
index bbe7041..9015c45 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_IOMMU_API) += iommu.o
+obj-$(CONFIG_IOMMU_API) += iommu-traces.o
 obj-$(CONFIG_OF_IOMMU)	+= of_iommu.o
 obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o msm_iommu_dev.o
 obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o
drivers/iommu/iommu-traces.c new file +24 -0
new file mode 100644
index 0000000..a2af60f
@@ -0,0 +1,24 @@
+/*
+ * iommu trace points
+ *
+ * Copyright (C) 2013 Shuah Khan <[email protected]>
+ *
+ */
+
+#include <linux/string.h>
+#include <linux/types.h>
+
+#define CREATE_TRACE_POINTS
+#include <trace/events/iommu.h>
+
+/* iommu_group_event */
+EXPORT_TRACEPOINT_SYMBOL_GPL(add_device_to_group);
+EXPORT_TRACEPOINT_SYMBOL_GPL(remove_device_from_group);
+
+/* iommu_device_event */
+EXPORT_TRACEPOINT_SYMBOL_GPL(attach_device_to_domain);
+EXPORT_TRACEPOINT_SYMBOL_GPL(detach_device_from_domain);
+
+/* iommu_map_unmap */
+EXPORT_TRACEPOINT_SYMBOL_GPL(map);
+EXPORT_TRACEPOINT_SYMBOL_GPL(unmap);
drivers/iommu/iommu.c +1 -0
index fbe9ca7..58f6a16 100644
@@ -29,6 +29,7 @@
 #include <linux/idr.h>
 #include <linux/notifier.h>
 #include <linux/err.h>
+#include <trace/events/iommu.h>
 
 static struct kset *iommu_group_kset;
 static struct ida iommu_group_ida;
include/trace/events/iommu.h new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#2 lore raw

PATCH 2/7 iommu: Change iommu driver to call add_device_to_group trace event

In reply to Shuah Khan

Change iommu driver to call add_device_to_group trace event. This iommu_group class event can be enabled to trigger when devices get added to an iommu group. Trace information includes iommu group id and device name.

Testing:
The following is trace is generated when intel-iommu driver adds devices to to iommu groups during boot-time during its initialization:

       swapper/0-1     [003] ....     1.854793: add_device_to_group: IOMMU: groupID=0 device=0000:00:00.0
       swapper/0-1     [003] ....     1.854797: add_device_to_group: IOMMU: groupID=1 device=0000:00:02.0
---
 drivers/iommu/iommu.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/iommu.c +2 -0
index 58f6a16..349c92d 100644
@@ -364,6 +364,8 @@ rename:
 	/* Notify any listeners about change to group. */
 	blocking_notifier_call_chain(&group->notifier,
 				     IOMMU_GROUP_NOTIFY_ADD_DEVICE, dev);
+
+	trace_add_device_to_group(group->id, dev);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(iommu_group_add_device);
Signature · 1 line
1.7.10.4
author
#3 lore raw

PATCH 3/7 iommu: Change iommu driver to call remove_device_to_group trace event

In reply to Shuah Khan

Change iommu driver to call remove_device_to_group trace event. This iommu_group class event can be enabled to trigger when devices get removed from an iommu group. Trace information includes iommu group id and device name.

Testing:
Added trace calls to iommu_prepare_identity_map() for testing some of the conditions that are hard to trigger. Here is the trace from the testing:

       swapper/0-1     [003] ....     1.854101: remove_device_from_group: IOMMU: groupID=0 device=0000:00:02.0
---
 drivers/iommu/iommu.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/iommu.c +2 -0
index 349c92d..278055b 100644
@@ -402,6 +402,8 @@ void iommu_group_remove_device(struct device *dev)
 	sysfs_remove_link(group->devices_kobj, device->name);
 	sysfs_remove_link(&dev->kobj, "iommu_group");
 
+	trace_remove_device_from_group(group->id, dev);
+
 	kfree(device->name);
 	kfree(device);
 	dev->iommu_group = NULL;
Signature · 1 line
1.7.10.4
author
#4 lore raw

PATCH 4/7 iommu: Change iommu driver to call attach_device_to_domain trace event

In reply to Shuah Khan

Change iommu driver to call attach_device_to_domain trace event. This iommu_device class event can be enabled to trigger when devices are attached to a domain. Trace information includes device name.

Testing:
Added trace calls to iommu_prepare_identity_map() for testing some of the conditions that are hard to trigger. Here is the trace from the testing:

      swapper/0-1     [003] ....     1.854102: attach_device_to_domain: IOMMU: device=0000:00:02.0
---
 drivers/iommu/iommu.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iommu/iommu.c +5 -1
index 278055b..74c371c 100644
@@ -685,10 +685,14 @@ EXPORT_SYMBOL_GPL(iommu_domain_free);
 
 int iommu_attach_device(struct iommu_domain *domain, struct device *dev)
 {
+	int ret;
 	if (unlikely(domain->ops->attach_dev == NULL))
 		return -ENODEV;
 
-	return domain->ops->attach_dev(domain, dev);
+	ret = domain->ops->attach_dev(domain, dev);
+	if (!ret)
+		trace_attach_device_to_domain(dev);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(iommu_attach_device);
 
Signature · 1 line
1.7.10.4
author
#5 lore raw

PATCH 5/7 iommu: Change iommu driver to call detach_device_to_domain trace event

In reply to Shuah Khan

Change iommu driver to call detach_device_to_domain trace event. This iommu_device class event can be enabled to trigger when devices are detached from a domain. Trace information includes device name.

Testing:
Added trace calls to iommu_prepare_identity_map() for testing some of the conditions that are hard to trigger. Here is the trace from the testing:

       swapper/0-1     [003] ....     1.854102: detach_device_from_domain: IOMMU: device=0000:00:02.0
---
 drivers/iommu/iommu.c |    1 +
 1 file changed, 1 insertion(+)
drivers/iommu/iommu.c +1 -0
index 74c371c..b630754 100644
@@ -702,6 +702,7 @@ void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
 		return;
 
 	domain->ops->detach_dev(domain, dev);
+	trace_detach_device_from_domain(dev);
 }
 EXPORT_SYMBOL_GPL(iommu_detach_device);
 
Signature · 1 line
1.7.10.4
author
#6 lore raw

PATCH 6/7 iommu: Change iommu driver to call map trace event

In reply to Shuah Khan

Change iommu driver to call map trace event. This iommu_map_unmap class event can be enabled to trigger when iommu map iommu ops is called. Trace information includes iova, physical address (map event only), and size.

Testing:
Added trace calls to iommu_prepare_identity_map() for testing some of the conditions that are hard to trigger. Here is the trace from the testing:

       swapper/0-1     [003] ....     1.854102: map: IOMMU: iova=0x00000000cb800000 paddr=0x00000000cf9fffff size=0x400
---
 drivers/iommu/iommu.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/iommu.c +2 -0
index b630754..ea49fe8 100644
@@ -842,6 +842,8 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova,
 	/* unroll mapping in case something went wrong */
 	if (ret)
 		iommu_unmap(domain, orig_iova, orig_size - size);
+	else
+		trace_map(iova, paddr, size);
 
 	return ret;
 }
Signature · 1 line
1.7.10.4
author
#7 lore raw

PATCH 7/7 iommu: Change iommu driver to call unmap trace event

In reply to Shuah Khan

Change iommu driver to call unmap trace event. This iommu_map_unmap class event can be enabled to trigger when iommu unmap iommu ops is called. Trace information includes iova, physical address (map event only), and size.

Testing:
Added trace calls to iommu_prepare_identity_map() for testing some of the conditions that are hard to trigger. Here is the trace from the testing:

       swapper/0-1     [003] ....     1.854102: unmap: IOMMU: iova=0x00000000cb800000 size=0x400
---
 drivers/iommu/iommu.c |    1 +
 1 file changed, 1 insertion(+)
drivers/iommu/iommu.c +1 -0
index ea49fe8..d8c53c7 100644
@@ -892,6 +892,7 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
 		unmapped += unmapped_page;
 	}
 
+	trace_unmap(iova, 0, size);
 	return unmapped;
 }
 EXPORT_SYMBOL_GPL(iommu_unmap);
Signature · 1 line
1.7.10.4
maintainer Applied
#8 lore raw
In reply to Shuah Khan
Quoted 10 lines · Shuah Khan

Shuah Khan (7):
iommu: Add event tracing feature to iommu
iommu: Change iommu driver to call add_device_to_group trace event
iommu: Change iommu driver to call remove_device_to_group trace event
iommu: Change iommu driver to call attach_device_to_domain trace
event
iommu: Change iommu driver to call detach_device_to_domain trace
event
iommu: Change iommu driver to call map trace event
iommu: Change iommu driver to call unmap trace event

Applied to tracing branch, thanks Shuah.