From 7f6db1717235bd45d265766dad53c10d30899d41 Mon Sep 17 00:00:00 2001 From: Shuah Khan Date: Thu, 15 Aug 2013 11:59:23 -0600 Subject: 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 Signed-off-by: Shuah Khan Signed-off-by: Joerg Roedel --- include/trace/events/iommu.h | 129 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 include/trace/events/iommu.h (limited to 'include') diff --git a/include/trace/events/iommu.h b/include/trace/events/iommu.h new file mode 100644 index 0000000..86bcc5a --- /dev/null +++ b/include/trace/events/iommu.h @@ -0,0 +1,129 @@ +/* + * iommu trace points + * + * Copyright (C) 2013 Shuah Khan + * + */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM iommu + +#if !defined(_TRACE_IOMMU_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_IOMMU_H + +#include +#include + +struct device; + +DECLARE_EVENT_CLASS(iommu_group_event, + + TP_PROTO(int group_id, struct device *dev), + + TP_ARGS(group_id, dev), + + TP_STRUCT__entry( + __field(int, gid) + __string(device, dev_name(dev)) + ), + + TP_fast_assign( + __entry->gid = group_id; + __assign_str(device, dev_name(dev)); + ), + + TP_printk("IOMMU: groupID=%d device=%s", + __entry->gid, __get_str(device) + ) +); + +DEFINE_EVENT(iommu_group_event, add_device_to_group, + + TP_PROTO(int group_id, struct device *dev), + + TP_ARGS(group_id, dev) + +); + +DEFINE_EVENT(iommu_group_event, remove_device_from_group, + + TP_PROTO(int group_id, struct device *dev), + + TP_ARGS(group_id, dev) +); + +DECLARE_EVENT_CLASS(iommu_device_event, + + TP_PROTO(struct device *dev), + + TP_ARGS(dev), + + TP_STRUCT__entry( + __string(device, dev_name(dev)) + ), + + TP_fast_assign( + __assign_str(device, dev_name(dev)); + ), + + TP_printk("IOMMU: device=%s", __get_str(device) + ) +); + +DEFINE_EVENT(iommu_device_event, attach_device_to_domain, + + TP_PROTO(struct device *dev), + + TP_ARGS(dev) +); + +DEFINE_EVENT(iommu_device_event, detach_device_from_domain, + + TP_PROTO(struct device *dev), + + TP_ARGS(dev) +); + +DECLARE_EVENT_CLASS(iommu_map_unmap, + + TP_PROTO(unsigned long iova, phys_addr_t paddr, size_t size), + + TP_ARGS(iova, paddr, size), + + TP_STRUCT__entry( + __field(u64, iova) + __field(u64, paddr) + __field(int, size) + ), + + TP_fast_assign( + __entry->iova = iova; + __entry->paddr = paddr; + __entry->size = size; + ), + + TP_printk("IOMMU: iova=0x%016llx paddr=0x%016llx size=0x%x", + __entry->iova, __entry->paddr, __entry->size + ) +); + +DEFINE_EVENT(iommu_map_unmap, map, + + TP_PROTO(unsigned long iova, phys_addr_t paddr, size_t size), + + TP_ARGS(iova, paddr, size) +); + +DEFINE_EVENT_PRINT(iommu_map_unmap, unmap, + + TP_PROTO(unsigned long iova, phys_addr_t paddr, size_t size), + + TP_ARGS(iova, paddr, size), + + TP_printk("IOMMU: iova=0x%016llx size=0x%x", + __entry->iova, __entry->size + ) +); +#endif /* _TRACE_IOMMU_H */ + +/* This part must be outside protection */ +#include -- cgit v1.1 From 04fa2f7f837601903e5fe0f93bc2af8559d8c035 Mon Sep 17 00:00:00 2001 From: Shuah Khan Date: Tue, 24 Sep 2013 15:21:19 -0600 Subject: iommu: Add iommu_error class event to iommu trace iommu_error class event can be enabled to trigger when an iommu error occurs. This trace event is intended to be called to report the error information. Trace information includes driver name, device name, iova, and flags. iommu_error:io_page_fault Signed-off-by: Shuah Khan Signed-off-by: Joerg Roedel --- include/trace/events/iommu.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include') diff --git a/include/trace/events/iommu.h b/include/trace/events/iommu.h index 86bcc5a..a8f5c32 100644 --- a/include/trace/events/iommu.h +++ b/include/trace/events/iommu.h @@ -123,6 +123,39 @@ DEFINE_EVENT_PRINT(iommu_map_unmap, unmap, __entry->iova, __entry->size ) ); + +DECLARE_EVENT_CLASS(iommu_error, + + TP_PROTO(struct device *dev, unsigned long iova, int flags), + + TP_ARGS(dev, iova, flags), + + TP_STRUCT__entry( + __string(device, dev_name(dev)) + __string(driver, dev_driver_string(dev)) + __field(u64, iova) + __field(int, flags) + ), + + TP_fast_assign( + __assign_str(device, dev_name(dev)); + __assign_str(driver, dev_driver_string(dev)); + __entry->iova = iova; + __entry->flags = flags; + ), + + TP_printk("IOMMU:%s %s iova=0x%016llx flags=0x%04x", + __get_str(driver), __get_str(device), + __entry->iova, __entry->flags + ) +); + +DEFINE_EVENT(iommu_error, io_page_fault, + + TP_PROTO(struct device *dev, unsigned long iova, int flags), + + TP_ARGS(dev, iova, flags) +); #endif /* _TRACE_IOMMU_H */ /* This part must be outside protection */ -- cgit v1.1 From 56fa484969c367e3ae43a012a7b99f75bb4f3bdb Mon Sep 17 00:00:00 2001 From: Shuah Khan Date: Tue, 24 Sep 2013 15:21:20 -0600 Subject: iommu: Change iommu driver to call io_page_fault trace event Change iommu driver call io_page_fault trace event. This iommu_error class event can be enabled to trigger when an iommu error occurs. Trace information includes driver name, device name, iova, and flags. 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] .... 2.003774: io_page_fault: IOMMU:pci 0000:00:02.0 iova=0x00000000cb800000 flags=0x0002 swapper/0-1 [003] .... 2.004098: io_page_fault: IOMMU:pci 0000:00:1d.0 iova=0x00000000cadc6000 flags=0x0002 swapper/0-1 [003] .... 2.004115: io_page_fault: IOMMU:pci 0000:00:1a.0 iova=0x00000000cadc6000 flags=0x0002 swapper/0-1 [003] .... 2.004129: io_page_fault: IOMMU:pci 0000:00:1f.0 iova=0x0000000000000000 flags=0x0002 Signed-off-by: Shuah Khan Signed-off-by: Joerg Roedel --- include/linux/iommu.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 7ea319e..a444c79 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -22,6 +22,7 @@ #include #include #include +#include #define IOMMU_READ (1) #define IOMMU_WRITE (2) @@ -227,6 +228,7 @@ static inline int report_iommu_fault(struct iommu_domain *domain, ret = domain->handler(domain, dev, iova, flags, domain->handler_token); + trace_io_page_fault(dev, iova, flags); return ret; } -- cgit v1.1