AMD IOMMU fixes for 3.0-rc2
Hi Ingo,
The following changes since commit 59c5f46fbe01a00eedf54a23789634438bb80603:
Linux 3.0-rc2 (2011-06-06 18:06:33 +0900)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu.git amd-iommu/fixes
Joerg Roedel (3):
x86/amd-iommu: Fix 3 possible endless loops x86/amd-iommu: Use only per-device dma_ops x86/amd-iommu: Fix boot crash with hidden PCI devices
arch/x86/kernel/amd_iommu.c | 48 +++++++++++++++++++++++++++++++++++-- arch/x86/kernel/amd_iommu_init.c | 8 +++--- 2 files changed, 49 insertions(+), 7 deletions(-)
These patches fix serious issues which were discovered recently like a boot-stall and a boot crash when a device has an alias which does not exist a pci_dev. Please pull.
Joerg
PATCH 1/3 x86/amd-iommu: Fix 3 possible endless loops
The driver contains several loops counting on an u16 value where the exit-condition is checked against variables that can have values up to 0xffff. In this case the loops will never exit. This patch fixed 3 such loops.
--- arch/x86/kernel/amd_iommu_init.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/amd_iommu_init.c +4 -4
@@ -731,8 +731,8 @@ static void __init init_iommu_from_acpi(struct amd_iommu *iommu, {u8 *p = (u8 *)h;u8 *end = p, flags =0 ; -u16 dev_i, devid =0 , devid_start =0 , devid_to =0 ; -u32 ext_flags =0 ; +u16 devid =0 , devid_start =0 , devid_to =0 ; +u32 dev_i, ext_flags =0 ;bool alias = false;struct ivhd_entry *e;
@@ -887,7 +887,7 @@ static void __init init_iommu_from_acpi(struct amd_iommu *iommu,/* Initializes the device->iommu mapping for the driver */ static int __init init_iommu_devices (struct amd_iommu *iommu) { -u16 i; +u32 i;for (i = iommu->first_device; i <= iommu->last_device; ++i)set_iommu_for_device (iommu, i);
@@ -1177,7 +1177,7 @@ static int __init init_memory_definitions(struct acpi_table_header *table)*/ static void init_device_table (void ) { -u16 devid; +u32 devid;for (devid =0 ; devid <= amd_iommu_last_bdf; ++devid) {set_dev_entry_bit (devid,DEV_ENTRY_VALID );
Signature · 1 line
1.7.4.1
PATCH 2/3 x86/amd-iommu: Use only per-device dma_ops
In reply to Joerg RoedelUnfortunatly there are systems where the AMD IOMMU does not cover all devices. This breaks with the current driver as it initializes the global dma_ops variable. This patch limits the AMD IOMMU to the devices listed in the IVRS table fixing DMA for devices not covered by the IOMMU.
--- arch/x86/kernel/amd_iommu.c | 26 ++++++++++++++++++++++++-- 1 files changed, 24 insertions(+), 2 deletions(-)
arch/x86/kernel/amd_iommu.c +24 -2
@@ -30,6 +30,7 @@#include <asm/proto.h> #include <asm/iommu.h> #include <asm/gart.h> +#include <asm/dma.h> #include <asm/amd_iommu_proto.h> #include <asm/amd_iommu_types.h> #include <asm/amd_iommu.h>
@@ -2383,6 +2384,23 @@ static struct dma_map_ops amd_iommu_dma_ops = { .dma_supported = amd_iommu_dma_supported, }; +static unsigned device_dma_ops_init (void ) +{ +struct pci_dev *pdev =NULL ; +unsigned unhandled =0 ; + +for_each_pci_dev (pdev) { +if (!check_device (&pdev->dev)) { + unhandled +=1 ; +continue ; + } + + pdev->dev.archdata.dma_ops = &amd_iommu_dma_ops; + } + +return unhandled; +} +/* * The function which clues the AMD IOMMU driver into dma_ops. */
@@ -2395,7 +2413,7 @@ void __init amd_iommu_init_api(void)int __init amd_iommu_init_dma_ops (void ) {struct amd_iommu *iommu; -int ret; +int ret, unhandled;/* * first allocate a default protection domain for every IOMMU we
@@ -2421,7 +2439,11 @@ int __init amd_iommu_init_dma_ops(void) swiotlb =0 ;/* Make the driver finally visible to the drivers */ - dma_ops = &amd_iommu_dma_ops; + unhandled =device_dma_ops_init (); +if (unhandled && max_pfn >MAX_DMA32_PFN ) { +/* There are unhandled devices - initialize swiotlb for them */ + swiotlb =1 ; + }amd_iommu_stats_init ();
Signature · 1 line
1.7.4.1
PATCH 3/3 x86/amd-iommu: Fix boot crash with hidden PCI devices
In reply to Joerg RoedelSome PCIe cards ship with a PCI-PCIe bridge which is not visible as a PCI device in Linux. But the device-id of the bridge is present in the IOMMU tables which causes a boot crash in the IOMMU driver.
This patch fixes by removing these cards from the IOMMU handling. This is a pure -stable fix, a real fix to handle this situation appriatly will follow for the next merge window.
--- arch/x86/kernel/amd_iommu.c | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-)
arch/x86/kernel/amd_iommu.c +21 -1
@@ -155,6 +155,10 @@ static int iommu_init_device(struct device *dev) pdev =pci_get_bus_and_slot (PCI_BUS (alias), alias &0xff );if (pdev) dev_data->alias = &pdev->dev; +else { +kfree (dev_data); +return -ENOTSUPP ; + }atomic_set (&dev_data->bind,0 );
@@ -164,6 +168,20 @@ static int iommu_init_device(struct device *dev)return 0 ; } +static void iommu_ignore_device (struct device *dev) +{ +u16 devid, alias; + + devid =get_device_id (dev); + alias = amd_iommu_alias_table[devid]; + +memset (&amd_iommu_dev_table[devid],0 ,sizeof (struct dev_table_entry )); +memset (&amd_iommu_dev_table[alias],0 ,sizeof (struct dev_table_entry )); + + amd_iommu_rlookup_table[devid] =NULL ; + amd_iommu_rlookup_table[alias] =NULL ; +} +static void iommu_uninit_device (struct device *dev) {kfree (dev->archdata.iommu);
@@ -193,7 +211,9 @@ int __init amd_iommu_init_devices(void)continue ; ret =iommu_init_device (&pdev->dev); -if (ret) +if (ret == -ENOTSUPP ) +iommu_ignore_device (&pdev->dev); +else if (ret) goto out_free; }
Signature · 1 line
1.7.4.1
Quoted 14 lines · Joerg Roedel
Hi Ingo,
The following changes since commit
59c5f46fbe01a00eedf54a23789634438bb80603:Linux 3.0-rc2 (2011-06-06 18:06:33 +0900)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu.gitamd-iommu/fixesJoerg Roedel (3):
x86/amd-iommu: Fix 3 possible endless loops x86/amd-iommu: Use only per-devicedma_opsx86/amd-iommu: Fix boot crash with hidden PCI devices
Quoted 7 lines
arch/x86/kernel/amd_iommu.c | 48 +++++++++++++++++++++++++++++++++++-- arch/x86/kernel/amd_iommu_init.c | 8 +++--- 2 files changed, 49 insertions(+), 7 deletions(-)These patches fix serious issues which were discovered recently like a boot-stall and a boot crash when a device has an alias which does not exist a
pci_dev. Please pull.
Pulled, thanks a lot Joerg!
Ingo