AMD IOMMU fixes for 2.6.34
cover AMD IOMMU fixes for 2.6.34
Hi,
here are some fixes I queued up for the amd iommu driver. I plan to send them to Linus together with the other driver and iommu-api updates in my tree. If there are any objections against the patches in this set please let me know.
Thanks,
Joerg
PATCH 1/4 x86/amd-iommu: Remove double NULL check in check_device
From: Julia Lawall <[email protected]>
dev was tested just above, so drop the second test.
--- arch/x86/kernel/amd_iommu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/amd_iommu.c +1 -1
@@ -118,7 +118,7 @@ static bool check_device(struct device *dev)return false;/* No device or no PCI device */ -if (!dev || dev->bus != &pci_bus_type) +if (dev->bus != &pci_bus_type)return false; devid =get_device_id (dev);
Signature · 1 line
1.7.0
PATCH 2/4 x86/amd-iommu: Protect IOMMU-API map/unmap path
In reply to Joerg RoedelThis patch introduces a mutex to lock page table updates in the IOMMU-API path. We can't use the spin_lock here because this patch might sleep.
--- arch/x86/include/asm/amd_iommu_types.h | 2 ++ arch/x86/kernel/amd_iommu.c | 9 +++++++++ 2 files changed, 11 insertions(+), 0 deletions(-)
arch/x86/include/asm/amd_iommu_types.h +2 -0
@@ -21,6 +21,7 @@#define _ASM_X86_AMD_IOMMU_TYPES_H#include <linux/types.h> +#include <linux/mutex.h> #include <linux/list.h> #include <linux/spinlock.h>
@@ -237,6 +238,7 @@ struct protection_domain {struct list_head list;/* for list of all protection domains */ struct list_head dev_list;/* List of all devices in this domain */ spinlock_t lock;/* mostly used to lock the page table*/ +struct mutex api_lock;/* protect page tables in the iommu-api path */ u16 id;/* the domain id written to the device table */ int mode;/* paging mode (0-6 levels) */ u64 *pt_root;/* page table root pointer */
arch/x86/kernel/amd_iommu.c +9 -0
@@ -2327,6 +2327,7 @@ static struct protection_domain *protection_domain_alloc(void)return NULL ;spin_lock_init (&domain->lock); +mutex_init (&domain->api_lock); domain->id =domain_id_alloc ();if (!domain->id) goto out_err;
@@ -2456,6 +2457,8 @@ static int amd_iommu_map_range(struct iommu_domain *dom, iova &=PAGE_MASK ; paddr &=PAGE_MASK ; +mutex_lock (&domain->api_lock); +for (i =0 ; i < npages; ++i) { ret =iommu_map_page (domain, iova, paddr, prot, PM_MAP_4k);if (ret)
@@ -2465,6 +2468,8 @@ static int amd_iommu_map_range(struct iommu_domain *dom, paddr +=PAGE_SIZE ; } +mutex_unlock (&domain->api_lock); +return 0 ; }
@@ -2477,12 +2482,16 @@ static void amd_iommu_unmap_range(struct iommu_domain *dom, iova &=PAGE_MASK ; +mutex_lock (&domain->api_lock); +for (i =0 ; i < npages; ++i) {iommu_unmap_page (domain, iova, PM_MAP_4k); iova +=PAGE_SIZE ; }iommu_flush_tlb_pde (domain); + +mutex_unlock (&domain->api_lock); } static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
Signature · 1 line
1.7.0
PATCH 3/4 x86/amd-iommu: Pt mode fix for domain_destroy
In reply to Joerg RoedelFrom: Chris Wright <[email protected]>
After a guest is shutdown, assigned devices are not properly returned to the pt domain. This can leave the device using stale cached IOMMU data, and result in a non-functional device after it's re-bound to the host driver. For example, I see this upon rebinding:
AMD-Vi: Event logged [IO_PAGE_FAULT device=02:00.0 domain=0x0000 address=0x000000007e2a8000 flags=0x0050]
AMD-Vi: Event logged [IO_PAGE_FAULT device=02:00.0 domain=0x0000 address=0x000000007e2a8040 flags=0x0050]
AMD-Vi: Event logged [IO_PAGE_FAULT device=02:00.0 domain=0x0000 address=0x000000007e2a8080 flags=0x0050]
AMD-Vi: Event logged [IO_PAGE_FAULT device=02:00.0 domain=0x0000 address=0x000000007e2a80c0 flags=0x0050] 0000:02:00.0: eth2: Detected Hardware Unit Hang:
...
The amd_iommu_destroy_domain() function calls do_detach() which doesn't reattach the pt domain to the device. Use __detach_device() instead.
--- arch/x86/kernel/amd_iommu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/amd_iommu.c +1 -1
@@ -2298,7 +2298,7 @@ static void cleanup_domain(struct protection_domain *domain)list_for_each_entry_safe (dev_data, next, &domain->dev_list, list) {struct device *dev = dev_data->dev; -do_detach (dev); +__detach_device (dev);atomic_set (&dev_data->bind,0 ); }
Signature · 1 line
1.7.0
PATCH 4/4 x86/amd-iommu: Report errors in acpi parsing functions upstream
In reply to Joerg RoedelSince acpi_table_parse ignores the return values of the parsing function this patch introduces a workaround and reports these errors upstream via a global variable.
--- arch/x86/kernel/amd_iommu_init.c | 38 +++++++++++++++++++++++++++----------- 1 files changed, 27 insertions(+), 11 deletions(-)
arch/x86/kernel/amd_iommu_init.c +27 -11
@@ -138,9 +138,9 @@ int amd_iommus_present;bool amd_iommu_np_cache__read_mostly ;/* -* Set to true if ACPI table parsing and hardware intialization went properly +* The ACPI table parsing functions set this variable on an error */ -static bool amd_iommu_initialized; +static int __initdata amd_iommu_init_err;/* * List of protection domains - used during resume
@@ -391,9 +391,11 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table)*/ for (i =0 ; i < table->length; ++i) checksum += p[i]; -if (checksum !=0 ) +if (checksum !=0 ) {/* ACPI table corrupt */ -return -ENODEV ; + amd_iommu_init_err = -ENODEV ; +return 0 ; + } p +=IVRS_HEADER_LENGTH ;
@@ -920,11 +922,16 @@ static int __init init_iommu_all(struct acpi_table_header *table) h->mmio_phys); iommu =kzalloc (sizeof (struct amd_iommu ),GFP_KERNEL ); -if (iommu ==NULL ) -return -ENOMEM ; +if (iommu ==NULL ) { + amd_iommu_init_err = -ENOMEM ; +return 0 ; + } + ret =init_iommu_one (iommu, h); -if (ret) -return ret; +if (ret) { + amd_iommu_init_err = ret; +return 0 ; + }break ;default :break ;
@@ -934,8 +941,6 @@ static int __init init_iommu_all(struct acpi_table_header *table) }WARN_ON (p != end); - amd_iommu_initialized = true; -return 0 ; }
@@ -1211,6 +1216,10 @@ static int __init amd_iommu_init(void)if (acpi_table_parse ("IVRS" , find_last_devid_acpi) !=0 )return -ENODEV ; + ret = amd_iommu_init_err; +if (ret) + goto out; + dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE ); alias_table_size =tbl_size (ALIAS_TABLE_ENTRY_SIZE ); rlookup_table_size =tbl_size (RLOOKUP_TABLE_ENTRY_SIZE );
@@ -1270,12 +1279,19 @@ static int __init amd_iommu_init(void)if (acpi_table_parse ("IVRS" , init_iommu_all) !=0 ) goto free; -if (!amd_iommu_initialized) +if (amd_iommu_init_err) { + ret = amd_iommu_init_err; goto free; + }if (acpi_table_parse ("IVRS" , init_memory_definitions) !=0 ) goto free; +if (amd_iommu_init_err) { + ret = amd_iommu_init_err; + goto free; + } + ret =sysdev_class_register (&amd_iommu_sysdev_class);if (ret) goto free;
Signature · 1 line
1.7.0