IOMMU: add crash_shutdown iommu_op The kdump kernel has problems booting with interrupt/dma remapping enabled, so we need a new iommu_ops called crash_shutdown which is basically suspend but doesn't need to bother saving state. We make sure that crash_shutdown is called on the kexec path. Signed-off-by: Andrew Cooper diff -r 09344e4f7cde xen/arch/x86/crash.c --- a/xen/arch/x86/crash.c Thu May 26 16:51:35 2011 +0100 +++ b/xen/arch/x86/crash.c Thu May 26 17:00:40 2011 +0100 @@ -89,6 +89,10 @@ void machine_crash_shutdown(void) nmi_shootdown_cpus(); + /* Crash shutdown any IOMMU functionality as the crashdump kernel is not + * happy when booting if interrupt/dma remapping is still enabled */ + iommu_crash_shutdown(); + info = kexec_crash_save_info(); info->xen_phys_start = xen_phys_start; info->dom0_pfn_to_mfn_frame_list_list = diff -r 09344e4f7cde xen/drivers/passthrough/amd/iommu_init.c --- a/xen/drivers/passthrough/amd/iommu_init.c Thu May 26 16:51:35 2011 +0100 +++ b/xen/drivers/passthrough/amd/iommu_init.c Thu May 26 17:00:40 2011 +0100 @@ -923,6 +923,14 @@ void amd_iommu_suspend(void) disable_iommu(iommu); } +void amd_iommu_crash_shutdown(void) +{ + struct amd_iommu *iommu; + + for_each_amd_iommu ( iommu ) + disable_iommu(iommu); +} + void amd_iommu_resume(void) { struct amd_iommu *iommu; diff -r 09344e4f7cde xen/drivers/passthrough/amd/pci_amd_iommu.c --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c Thu May 26 16:51:35 2011 +0100 +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c Thu May 26 17:00:40 2011 +0100 @@ -455,4 +455,5 @@ const struct iommu_ops amd_iommu_ops = { .read_msi_from_ire = amd_iommu_read_msi_from_ire, .suspend = amd_iommu_suspend, .resume = amd_iommu_resume, + .crash_shutdown = amd_iommu_crash_shutdown, }; diff -r 09344e4f7cde xen/drivers/passthrough/iommu.c --- a/xen/drivers/passthrough/iommu.c Thu May 26 16:51:35 2011 +0100 +++ b/xen/drivers/passthrough/iommu.c Thu May 26 17:00:40 2011 +0100 @@ -419,6 +419,15 @@ void iommu_suspend(void) ops->suspend(); } +void iommu_crash_shutdown(void) +{ + const struct iommu_ops *ops = iommu_get_ops(); + if ( ops && ops->crash_shutdown ) + ops->crash_shutdown(); +} + + + /* * Local variables: * mode: C diff -r 09344e4f7cde xen/drivers/passthrough/vtd/iommu.c --- a/xen/drivers/passthrough/vtd/iommu.c Thu May 26 16:51:35 2011 +0100 +++ b/xen/drivers/passthrough/vtd/iommu.c Thu May 26 17:00:40 2011 +0100 @@ -2261,6 +2261,25 @@ static void vtd_suspend(void) } } +static void vtd_crash_shutdown(void) +{ + struct acpi_drhd_unit *drhd; + struct iommu *iommu; + + if ( !iommu_enabled ) + return; + + iommu_flush_all(); + + for_each_drhd_unit ( drhd ) + { + iommu = drhd->iommu; + iommu_disable_translation(iommu); + } + + iommu_disable_IR(); +} + static void vtd_resume(void) { struct acpi_drhd_unit *drhd; @@ -2311,6 +2330,7 @@ const struct iommu_ops intel_iommu_ops = .read_msi_from_ire = msi_msg_read_remap_rte, .suspend = vtd_suspend, .resume = vtd_resume, + .crash_shutdown = vtd_crash_shutdown, }; /* diff -r 09344e4f7cde xen/include/asm-x86/hvm/svm/amd-iommu-proto.h --- a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h Thu May 26 16:51:35 2011 +0100 +++ b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h Thu May 26 17:00:40 2011 +0100 @@ -91,6 +91,7 @@ unsigned int amd_iommu_read_ioapic_from_ /* power management support */ void amd_iommu_resume(void); void amd_iommu_suspend(void); +void amd_iommu_crash_shutdown(void); static inline u32 get_field_from_reg_u32(u32 reg_value, u32 mask, u32 shift) { diff -r 09344e4f7cde xen/include/xen/iommu.h --- a/xen/include/xen/iommu.h Thu May 26 16:51:35 2011 +0100 +++ b/xen/include/xen/iommu.h Thu May 26 17:00:40 2011 +0100 @@ -133,6 +133,7 @@ struct iommu_ops { unsigned int (*read_apic_from_ire)(unsigned int apic, unsigned int reg); void (*suspend)(void); void (*resume)(void); + void (*crash_shutdown)(void); }; void iommu_update_ire_from_apic(unsigned int apic, unsigned int reg, unsigned int value); @@ -142,6 +143,7 @@ unsigned int iommu_read_apic_from_ire(un void iommu_suspend(void); void iommu_resume(void); +void iommu_crash_shutdown(void); void iommu_set_dom0_mapping(struct domain *d);