amd/iommu: Fix infinite loop due to ivrs_bdf_entries larger than 16-bit value
PATCH v2 1/1 amd/iommu: Fix infinite loop due to ivrs_bdf_entries larger than 16-bit value
From: Suravee Suthikulpanit <[email protected]>
Certain AMD systems could have upto 0x10000 ivrs_bdf_entries. However, the loop variable (bdf) is declared as u16 which causes inifinite loop when parsing IOMMU event log with IO_PAGE_FAULT event. This patch changes the variable to u32 instead.
---
V2:
- Fix in more places as pointed out by Andrew
xen/drivers/passthrough/amd/iommu_acpi.c | 5 +++-- xen/drivers/passthrough/amd/iommu_init.c | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
xen/drivers/passthrough/amd/iommu_acpi.c +3 -2
@@ -159,7 +159,7 @@ static int __init register_exclusion_range_for_all_devices(int seg =0 ;/* XXX */ unsigned long range_top, iommu_top, length;struct amd_iommu *iommu; -u16 bdf; +u32 bdf;/* is part of exclusion range inside of IOMMU virtual address space? */ /* note: 'limit' parameter is assumed to be page-aligned */
@@ -237,7 +237,8 @@ static int __init register_exclusion_range_for_iommu_devices( unsigned long base, unsigned long limit, u8 iw, u8 ir) { unsigned long range_top, iommu_top, length; -u16 bdf, req; +u32 bdf; +u16 req;/* is part of exclusion range inside of IOMMU virtual address space? */ /* note: 'limit' parameter is assumed to be page-aligned */
xen/drivers/passthrough/amd/iommu_init.c +7 -6
@@ -524,8 +524,8 @@ static hw_irq_controller iommu_maskable_msi_type = {static void parse_event_log_entry (struct amd_iommu *iommu,u32 entry[]) { -u16 domain_id, device_id, bdf, flags; -u32 code; +u16 domain_id, device_id, flags; +u32 code, bdf;u64 *addr;int count =0 ;static const char *const event_str[] = {
@@ -1103,7 +1103,7 @@ int iterate_ivrs_entries(int (*handler)(u16 seg, struct ivrs_mappings *)) do { struct ivrs_mappings *map; - int bdf; + u32 bdf; if ( !radix_tree_gang_lookup(&ivrs_maps, (void **)&map, seg, 1) ) break;
@@ -1118,7 +1118,7 @@ int iterate_ivrs_entries(int (*handler)(u16 seg, struct ivrs_mappings *))static int __init alloc_ivrs_mappings (u16 seg) {struct ivrs_mappings *ivrs_mappings; -int bdf; +u32 bdf;BUG_ON ( !ivrs_bdf_entries );
@@ -1156,7 +1156,7 @@ static int __init alloc_ivrs_mappings(u16 seg)static int __init amd_iommu_setup_device_table (u16 seg,struct ivrs_mappings *ivrs_mappings) { -int bdf; +u32 bdf;void *intr_tb, *dte;BUG_ON ( (ivrs_bdf_entries ==0 ) );
@@ -1306,7 +1306,8 @@ static void invalidate_all_domain_pages(void)static int _invalidate_all_devices (u16 seg,struct ivrs_mappings *ivrs_mappings) { -int bdf, req_id; +u32 bdf; +u16 req_id;unsigned long flags;struct amd_iommu *iommu;
Signature · 1 line
1.7.10.4
Quoted 9 lines · On 29/12/2013 16:38, [email protected] wrote:
From: Suravee Suthikulpanit <[email protected]>
Certain AMD systems could have upto
0x10000ivrs_bdf_entries. However, the loop variable (bdf) is declared as u16 which causes inifinite loop when parsing IOMMU event log withIO_PAGE_FAULTevent. This patch changes the variable to u32 instead.
---
V2:
- Fix in more places as pointed out by Andrew
You are missing a Signed-off-by on this patch,
However, for the content,
Quoted 80 lines
xen/drivers/passthrough/amd/iommu_acpi.c | 5 +++-- xen/drivers/passthrough/amd/iommu_init.c | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)xen/drivers/passthrough/amd/iommu_acpi.c +3
-2@@ -159,7 +159,7 @@ static int __init register_exclusion_range_for_all_devices(int seg =0 ;/* XXX */ unsigned long range_top, iommu_top, length;struct amd_iommu *iommu; -u16 bdf; +u32 bdf;/* is part of exclusion range inside of IOMMU virtual address space? */ /* note: 'limit' parameter is assumed to be page-aligned */ @@ -237,7 +237,8 @@ static int __init register_exclusion_range_for_iommu_devices( unsigned long base, unsigned long limit, u8 iw, u8 ir) { unsigned long range_top, iommu_top, length; -u16 bdf, req; +u32 bdf; +u16 req;/* is part of exclusion range inside of IOMMU virtual address space? */ /* note: 'limit' parameter is assumed to be page-aligned */ xen/drivers/passthrough/amd/iommu_init.c +7
-6@@ -524,8 +524,8 @@ static hw_irq_controller iommu_maskable_msi_type = {static void parse_event_log_entry (struct amd_iommu *iommu,u32 entry[]) { -u16 domain_id, device_id, bdf, flags; -u32 code; +u16 domain_id, device_id, flags; +u32 code, bdf;u64 *addr;int count =0 ;static const char *const event_str[] = {@@ -1103,7 +1103,7 @@ int iterate_ivrs_entries(int (*handler)(u16 seg, struct ivrs_mappings *)) do { struct ivrs_mappings *map; - int bdf; + u32 bdf; if ( !radix_tree_gang_lookup(&ivrs_maps, (void **)&map, seg, 1) ) break;@@ -1118,7 +1118,7 @@ int iterate_ivrs_entries(int (*handler)(u16 seg, struct ivrs_mappings *))static int __init alloc_ivrs_mappings (u16 seg) {struct ivrs_mappings *ivrs_mappings; -int bdf; +u32 bdf;BUG_ON ( !ivrs_bdf_entries );@@ -1156,7 +1156,7 @@ static int __init alloc_ivrs_mappings(u16 seg)static int __init amd_iommu_setup_device_table (u16 seg,struct ivrs_mappings *ivrs_mappings) { -int bdf; +u32 bdf;void *intr_tb, *dte;BUG_ON ( (ivrs_bdf_entries ==0 ) );@@ -1306,7 +1306,8 @@ static void invalidate_all_domain_pages(void)static int _invalidate_all_devices (u16 seg,struct ivrs_mappings *ivrs_mappings) { -int bdf, req_id; +u32 bdf; +u16 req_id;unsigned long flags;struct amd_iommu *iommu;