amd-iommu debug patches for 2.6.31
cover amd-iommu debug patches for 2.6.31
This patchset contains updates to the debugging code in the AMD IOMMU driver for Linux. It introduces two additional features:
* A new command line parameter to let the driver dump the parsed contents of the IVRS ACPI table to dmesg. This is a debug feature to make it easier to find the bug for problems reported to me
* A new Kconfig entry to enable IOMMU stress testing code. I made this Kconfig entry generic because other IOMMU implementations may pick this up as well.
Please review.
diffstat:
arch/x86/Kconfig.debug | 8 +++ arch/x86/include/asm/amd_iommu_types.h | 6 ++ arch/x86/kernel/amd_iommu.c | 10 ++- arch/x86/kernel/amd_iommu_init.c | 109 ++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 4 deletions(-)
shortlog:
Joerg Roedel (7):
amd-iommu: add amd_iommu_dump parameter
amd-iommu: add dump for iommus described in ivrs table
amd-iommu: print ivhd information to dmesg when requested
amd-iommu: print ivmd information to dmesg when requested
amd-iommu: move protection domain printk to dump code x86/iommu: add IOMMU_STRESS Kconfig entry
amd-iommu: disable device isolation with CONFIG_IOMMU_STRESS
PATCH 1/7 amd-iommu: add amd_iommu_dump parameter
[ impact: add parameter to dump the ACPI table for AMD IOMMU ]
--- arch/x86/include/asm/amd_iommu_types.h | 6 ++++++ arch/x86/kernel/amd_iommu_init.c | 10 ++++++++++ 2 files changed, 16 insertions(+), 0 deletions(-)
arch/x86/include/asm/amd_iommu_types.h +6 -0
@@ -194,6 +194,12 @@#define PD_DMA_OPS_MASK (1UL << 0)/* domain used for dma_ops */ #define PD_DEFAULT_MASK (1UL << 1)/* domain is a default dma_ops domain for an IOMMU */ +extern bool amd_iommu_dump; +#define DUMP_printk(format, arg...) \ + do { \ + if (amd_iommu_dump) \ + printk(KERN_INFO "AMD IOMMU: " format, ## arg); \ + } while(0);/* * This structure contains generic data for IOMMU protection domains
arch/x86/kernel/amd_iommu_init.c +10 -0
@@ -115,6 +115,8 @@ struct ivmd_header {u64 range_length; } __attribute__((packed)); +bool amd_iommu_dump; +static int __initdata amd_iommu_detected;u16 amd_iommu_last_bdf;/* largest PCI device id we have
@@ -1211,6 +1213,13 @@ void __init amd_iommu_detect(void)* ****************************************************************************/ +static int __init parse_amd_iommu_dump (char *str) +{ + amd_iommu_dump = true; + +return 1 ; +} +static int __init parse_amd_iommu_options (char *str) {for (; *str; ++str) {
@@ -1235,5 +1244,6 @@ static int __init parse_amd_iommu_size_options(char *str)return 1 ; } +__setup ("amd_iommu_dump" , parse_amd_iommu_dump);__setup ("amd_iommu=" , parse_amd_iommu_options);__setup ("amd_iommu_size=" , parse_amd_iommu_size_options);
Signature · 1 line
1.6.3.1
PATCH 2/7 amd-iommu: add dump for iommus described in ivrs table
In reply to Joerg Roedel[ impact: get information about iommus described in the ivrs acpi table ]
--- arch/x86/kernel/amd_iommu_init.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
arch/x86/kernel/amd_iommu_init.c +9 -0
@@ -748,6 +748,15 @@ static int __init init_iommu_all(struct acpi_table_header *table) h = (struct ivhd_header *)p;switch (*p) {case ACPI_IVHD_TYPE : + +DUMP_printk ("IOMMU: device: %02x:%02x.%01x cap: %04x " +"seg: %d flags: %01x info %04x\n" , +PCI_BUS (h->devid),PCI_SLOT (h->devid), +PCI_FUNC (h->devid), h->cap_ptr, + h->pci_seg, h->flags, h->info); +DUMP_printk (" mmio-addr: %016llx\n" , + h->mmio_phys); + iommu =kzalloc (sizeof (struct amd_iommu ),GFP_KERNEL );if (iommu ==NULL )return -ENOMEM ;
Signature · 1 line
1.6.3.1
PATCH 3/7 amd-iommu: print ivhd information to dmesg when requested
In reply to Joerg Roedel[ impact: be able to show in dmesg whats in the acpi ivhd fields ]
--- arch/x86/kernel/amd_iommu_init.c | 73 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-)
arch/x86/kernel/amd_iommu_init.c +73 -0
@@ -598,32 +598,83 @@ static void __init init_iommu_from_acpi(struct amd_iommu *iommu, p +=sizeof (struct ivhd_header ); end += h->length; +while (p < end) { e = (struct ivhd_entry *)p;switch (e->type) {case IVHD_DEV_ALL : + +DUMP_printk (" DEV_ALL\t\t\t first devid: %02x:%02x.%x" +" last device %02x:%02x.%x flags: %02x\n" , +PCI_BUS (iommu->first_device), +PCI_SLOT (iommu->first_device), +PCI_FUNC (iommu->first_device), +PCI_BUS (iommu->last_device), +PCI_SLOT (iommu->last_device), +PCI_FUNC (iommu->last_device), + e->flags); +for (dev_i = iommu->first_device; dev_i <= iommu->last_device; ++dev_i)set_dev_entry_from_acpi (iommu, dev_i, e->flags,0 );break ;case IVHD_DEV_SELECT : + +DUMP_printk (" DEV_SELECT\t\t\t devid: %02x:%02x.%x " +"flags: %02x\n" , +PCI_BUS (e->devid), +PCI_SLOT (e->devid), +PCI_FUNC (e->devid), + e->flags); + devid = e->devid;set_dev_entry_from_acpi (iommu, devid, e->flags,0 );break ;case IVHD_DEV_SELECT_RANGE_START : + +DUMP_printk (" DEV_SELECT_RANGE_START\t " +"devid: %02x:%02x.%x flags: %02x\n" , +PCI_BUS (e->devid), +PCI_SLOT (e->devid), +PCI_FUNC (e->devid), + e->flags); + devid_start = e->devid; flags = e->flags; ext_flags =0 ; alias = false;break ;case IVHD_DEV_ALIAS : + +DUMP_printk (" DEV_ALIAS\t\t\t devid: %02x:%02x.%x " +"flags: %02x devid_to: %02x:%02x.%x\n" , +PCI_BUS (e->devid), +PCI_SLOT (e->devid), +PCI_FUNC (e->devid), + e->flags, +PCI_BUS (e->ext >>8 ), +PCI_SLOT (e->ext >>8 ), +PCI_FUNC (e->ext >>8 )); + devid = e->devid; devid_to = e->ext >>8 ;set_dev_entry_from_acpi (iommu, devid, e->flags,0 ); amd_iommu_alias_table[devid] = devid_to;break ;case IVHD_DEV_ALIAS_RANGE : + +DUMP_printk (" DEV_ALIAS_RANGE\t\t " +"devid: %02x:%02x.%x flags: %02x " +"devid_to: %02x:%02x.%x\n" , +PCI_BUS (e->devid), +PCI_SLOT (e->devid), +PCI_FUNC (e->devid), + e->flags, +PCI_BUS (e->ext >>8 ), +PCI_SLOT (e->ext >>8 ), +PCI_FUNC (e->ext >>8 )); + devid_start = e->devid; flags = e->flags; devid_to = e->ext >>8 ;
@@ -631,17 +682,39 @@ static void __init init_iommu_from_acpi(struct amd_iommu *iommu, alias = true;break ;case IVHD_DEV_EXT_SELECT : + +DUMP_printk (" DEV_EXT_SELECT\t\t devid: %02x:%02x.%x " +"flags: %02x ext: %08x\n" , +PCI_BUS (e->devid), +PCI_SLOT (e->devid), +PCI_FUNC (e->devid), + e->flags, e->ext); + devid = e->devid;set_dev_entry_from_acpi (iommu, devid, e->flags, e->ext);break ;case IVHD_DEV_EXT_SELECT_RANGE : + +DUMP_printk (" DEV_EXT_SELECT_RANGE\t devid: " +"%02x:%02x.%x flags: %02x ext: %08x\n" , +PCI_BUS (e->devid), +PCI_SLOT (e->devid), +PCI_FUNC (e->devid), + e->flags, e->ext); + devid_start = e->devid; flags = e->flags; ext_flags = e->ext; alias = false;break ;case IVHD_DEV_RANGE_END : + +DUMP_printk (" DEV_RANGE_END\t\t devid: %02x:%02x.%x\n" , +PCI_BUS (e->devid), +PCI_SLOT (e->devid), +PCI_FUNC (e->devid)); + devid = e->devid;for (dev_i = devid_start; dev_i <= devid; ++dev_i) {if (alias)
Signature · 1 line
1.6.3.1
PATCH 4/7 amd-iommu: print ivmd information to dmesg when requested
In reply to Joerg Roedel[ impact: be able to show in dmesg whats in the acpi ivmd fields ]
--- arch/x86/kernel/amd_iommu_init.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
arch/x86/kernel/amd_iommu_init.c +11 -0
@@ -983,6 +983,7 @@ static int __init init_exclusion_range(struct ivmd_header *m)static int __init init_unity_map_range (struct ivmd_header *m) {struct unity_map_entry *e =0 ; +char *s; e =kzalloc (sizeof (*e),GFP_KERNEL );if (e ==NULL )
@@ -991,13 +992,16 @@ static int __init init_unity_map_range(struct ivmd_header *m)switch (m->type) {default :case ACPI_IVMD_TYPE : + s ="IVMD_TYPEi\t\t\t" ; e->devid_start = e->devid_end = m->devid;break ;case ACPI_IVMD_TYPE_ALL : + s ="IVMD_TYPE_ALL\t\t" ; e->devid_start =0 ; e->devid_end = amd_iommu_last_bdf;break ;case ACPI_IVMD_TYPE_RANGE : + s ="IVMD_TYPE_RANGE\t\t" ; e->devid_start = m->devid; e->devid_end = m->aux;break ;
@@ -1006,6 +1010,13 @@ static int __init init_unity_map_range(struct ivmd_header *m) e->address_end = e->address_start +PAGE_ALIGN (m->range_length); e->prot = m->flags >>1 ; +DUMP_printk ("%s devid_start: %02x:%02x.%x devid_end: %02x:%02x.%x" +" range_start: %016llx range_end: %016llx flags: %x\n" , s, +PCI_BUS (e->devid_start),PCI_SLOT (e->devid_start), +PCI_FUNC (e->devid_start),PCI_BUS (e->devid_end), +PCI_SLOT (e->devid_end),PCI_FUNC (e->devid_end), + e->address_start, e->address_end, m->flags); +list_add_tail (&e->list, &amd_iommu_unity_map);return 0 ;
Signature · 1 line
1.6.3.1
PATCH 5/7 amd-iommu: move protection domain printk to dump code
In reply to Joerg Roedel[ impact: only printk protection-domain relations if requested ]
This information is only helpful for debugging. Don't print it anymore unless explicitly requested.
--- arch/x86/kernel/amd_iommu.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
arch/x86/kernel/amd_iommu.c +6 -4
@@ -1009,8 +1009,9 @@ static int device_change_notifier(struct notifier_block *nb,if (!dma_domain) dma_domain = iommu->default_dom;attach_device (iommu, &dma_domain->domain, devid); -printk (KERN_INFO "AMD IOMMU: Using protection domain %d for " -"device %s\n" , dma_domain->domain.id,dev_name (dev)); +DUMP_printk (KERN_INFO "AMD IOMMU: Using protection domain " +"%d for device %s\n" , + dma_domain->domain.id,dev_name (dev));break ;case BUS_NOTIFY_UNBIND_DRIVER :if (!domain)
@@ -1133,8 +1134,9 @@ static int get_device_resources(struct device *dev, dma_dom = (*iommu)->default_dom; *domain = &dma_dom->domain;attach_device (*iommu, *domain, *bdf); -printk (KERN_INFO "AMD IOMMU: Using protection domain %d for " -"device %s\n" , (*domain)->id,dev_name (dev)); +DUMP_printk (KERN_INFO "AMD IOMMU: Using protection domain " +"%d for device %s\n" , + (*domain)->id,dev_name (dev)); }if (domain_for_device (_bdf) ==NULL )
Signature · 1 line
1.6.3.1
PATCH 6/7 x86/iommu: add IOMMU_STRESS Kconfig entry
In reply to Joerg Roedel[ impact: add a Kconfig option to enable stress-test code im iommu drivers ]
--- arch/x86/Kconfig.debug | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
arch/x86/Kconfig.debug +8 -0
@@ -159,6 +159,14 @@ config IOMMU_DEBUG options. See Documentation/x86_64/boot-options.txt for more details. +config IOMMU_STRESS + bool "Enable IOMMU stress-test mode" + ---help--- + This option disables various optimizations in IOMMU related + code to do real stress testing of the IOMMU code. This option + will cause a performance drop and should only be enabled for + testing. + config IOMMU_LEAK bool "IOMMU leak tracing" depends on IOMMU_DEBUG && DMA_API_DEBUG
Signature · 1 line
1.6.3.1
PATCH 7/7 amd-iommu: disable device isolation with CONFIG_IOMMU_STRESS
In reply to Joerg Roedel[ impact: test for race conditions in dma_ops related code ]
--- arch/x86/kernel/amd_iommu_init.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/kernel/amd_iommu_init.c +6 -0
@@ -124,8 +124,14 @@ u16 amd_iommu_last_bdf; /* largest PCI device id we haveLIST_HEAD (amd_iommu_unity_map);/* a list of required unity mappings we find in ACPI */ unsigned amd_iommu_aperture_order =26 ;/* size of aperture in power of 2 */ + +#ifdef CONFIG_IOMMU_STRESS +bool amd_iommu_isolate = false; +#else bool amd_iommu_isolate = true;/* if true, device isolation is enabled */ +#endif +bool amd_iommu_unmap_flush;/* if true, flush on every unmap */ LIST_HEAD (amd_iommu_list);/* list of all AMD IOMMUs in the
Signature · 1 line
1.6.3.1