Skip to contentSkip to conversation

AMD IOMMU: correctly propagate errors from amd_iommu_init()

PATCH In review Jan Beulich 4 participants 6 messages Jun 14, 2016 – Jun 16, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 AMD IOMMU: correctly propagate errors from amd_iommu_init()

... instead of using -ENODEV for any kind of error. It in particular addresses Coverity ID 1362694 (introduced by commit eb48587210 ["AMD
IOMMU: introduce support for IVHD block type 11h"]).

Coverity ID: 1362694

xen/drivers/passthrough/amd/iommu_init.c +25 -10
@@ -1226,6 +1226,7 @@ static bool_t __init amd_sp5100_erratum2
 int __init amd_iommu_init(void)
 {
     struct amd_iommu *iommu;
+    int rc = -ENODEV;
 
     BUG_ON( !iommu_found() );
 
@@ -1237,28 +1238,39 @@ int __init amd_iommu_init(void)
     if ( unlikely(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) )
         goto error_out;
 
-    ivhd_type = amd_iommu_get_supported_ivhd_type();
-    if ( ivhd_type < 0 )
+    rc = amd_iommu_get_supported_ivhd_type();
+    if ( rc < 0 )
         goto error_out;
+    ivhd_type = rc;
 
-    ivrs_bdf_entries = amd_iommu_get_ivrs_dev_entries();
-    if ( !ivrs_bdf_entries )
+    rc = amd_iommu_get_ivrs_dev_entries();
+    if ( !rc )
+        rc = -ENODEV;
+    if ( rc < 0 )
         goto error_out;
+    ivrs_bdf_entries = rc;
 
     radix_tree_init(&ivrs_maps);
     for_each_amd_iommu ( iommu )
-        if ( alloc_ivrs_mappings(iommu->seg) != 0 )
+    {
+        rc = alloc_ivrs_mappings(iommu->seg);
+        if ( rc )
             goto error_out;
+    }
 
-    if ( amd_iommu_update_ivrs_mapping_acpi() != 0 )
+    rc = amd_iommu_update_ivrs_mapping_acpi();
+    if ( rc )
         goto error_out;
 
     /* initialize io-apic interrupt remapping entries */
-    if ( iommu_intremap && amd_iommu_setup_ioapic_remapping() != 0 )
+    if ( iommu_intremap )
+        rc = amd_iommu_setup_ioapic_remapping();
+    if ( rc )
         goto error_out;
 
     /* allocate and initialize a global device table shared by all iommus */
-    if ( iterate_ivrs_mappings(amd_iommu_setup_device_table) != 0 )
+    rc = iterate_ivrs_mappings(amd_iommu_setup_device_table);
+    if ( rc )
         goto error_out;
 
     /*
@@ -1271,14 +1283,17 @@ int __init amd_iommu_init(void)
 
     /* per iommu initialization  */
     for_each_amd_iommu ( iommu )
-        if ( amd_iommu_init_one(iommu) != 0 )
+    {
+        rc = amd_iommu_init_one(iommu);
+        if ( rc )
             goto error_out;
+    }
 
     return 0;
 
 error_out:
     amd_iommu_init_cleanup();
-    return -ENODEV;
+    return rc;
 }
 
 static void disable_iommu(struct amd_iommu *iommu)

AMD IOMMU: correctly propagate errors from amd_iommu_init()

... instead of using -ENODEV for any kind of error. It in particular addresses Coverity ID 1362694 (introduced by commit eb48587210 ["AMD
IOMMU: introduce support for IVHD block type 11h"]).

Coverity ID: 1362694

xen/drivers/passthrough/amd/iommu_init.c +25 -10
@@ -1226,6 +1226,7 @@ static bool_t __init amd_sp5100_erratum2
 int __init amd_iommu_init(void)
 {
     struct amd_iommu *iommu;
+    int rc = -ENODEV;
 
     BUG_ON( !iommu_found() );
 
@@ -1237,28 +1238,39 @@ int __init amd_iommu_init(void)
     if ( unlikely(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) )
         goto error_out;
 
-    ivhd_type = amd_iommu_get_supported_ivhd_type();
-    if ( ivhd_type < 0 )
+    rc = amd_iommu_get_supported_ivhd_type();
+    if ( rc < 0 )
         goto error_out;
+    ivhd_type = rc;
 
-    ivrs_bdf_entries = amd_iommu_get_ivrs_dev_entries();
-    if ( !ivrs_bdf_entries )
+    rc = amd_iommu_get_ivrs_dev_entries();
+    if ( !rc )
+        rc = -ENODEV;
+    if ( rc < 0 )
         goto error_out;
+    ivrs_bdf_entries = rc;
 
     radix_tree_init(&ivrs_maps);
     for_each_amd_iommu ( iommu )
-        if ( alloc_ivrs_mappings(iommu->seg) != 0 )
+    {
+        rc = alloc_ivrs_mappings(iommu->seg);
+        if ( rc )
             goto error_out;
+    }
 
-    if ( amd_iommu_update_ivrs_mapping_acpi() != 0 )
+    rc = amd_iommu_update_ivrs_mapping_acpi();
+    if ( rc )
         goto error_out;
 
     /* initialize io-apic interrupt remapping entries */
-    if ( iommu_intremap && amd_iommu_setup_ioapic_remapping() != 0 )
+    if ( iommu_intremap )
+        rc = amd_iommu_setup_ioapic_remapping();
+    if ( rc )
         goto error_out;
 
     /* allocate and initialize a global device table shared by all iommus */
-    if ( iterate_ivrs_mappings(amd_iommu_setup_device_table) != 0 )
+    rc = iterate_ivrs_mappings(amd_iommu_setup_device_table);
+    if ( rc )
         goto error_out;
 
     /*
@@ -1271,14 +1283,17 @@ int __init amd_iommu_init(void)
 
     /* per iommu initialization  */
     for_each_amd_iommu ( iommu )
-        if ( amd_iommu_init_one(iommu) != 0 )
+    {
+        rc = amd_iommu_init_one(iommu);
+        if ( rc )
             goto error_out;
+    }
 
     return 0;
 
 error_out:
     amd_iommu_init_cleanup();
-    return -ENODEV;
+    return rc;
 }
 
 static void disable_iommu(struct amd_iommu *iommu)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

... instead of using -ENODEV for any kind of error. It in particular addresses Coverity ID 1362694 (introduced by commit eb48587210 ["AMD
IOMMU: introduce support for IVHD block type 11h"]).

Coverity ID: 1362694

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by Tested-by
#2 lore raw
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich

... instead of using -ENODEV for any kind of error. It in particular addresses Coverity ID 1362694 (introduced by commit eb48587210 ["AMD
IOMMU: introduce support for IVHD block type 11h"]).

Quoted 7 lines
Quoted 3 lines

Coverity ID: 1362694

Thank you for the fix up.

Suravee

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
In reply to Jan Beulich

xen/drivers/passthrough/amd/iommu_init.c int __init amd_iommu_init(void) · line 1269

Quoted 11 lines · Jan Beulich
xen/drivers/passthrough/amd/iommu_init.c +5 -2
-    if ( amd_iommu_update_ivrs_mapping_acpi() != 0 )
+    rc = amd_iommu_update_ivrs_mapping_acpi();
+    if ( rc )
         goto error_out;
 
     /* initialize io-apic interrupt remapping entries */
-    if ( iommu_intremap && amd_iommu_setup_ioapic_remapping() != 0 )
+    if ( iommu_intremap )
+        rc = amd_iommu_setup_ioapic_remapping();
+    if ( rc )
         goto error_out;

Is it better to indent this if() here? Then,

+ if ( iommu_intremap )
+ {
+ rc = amd_iommu_setup_ioapic_remapping();
+ if ( rc )
+ goto error_out;
+ }

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 16.06.16 at 04:03, <[email protected]> wrote:

xen/drivers/passthrough/amd/iommu_init.c int __init amd_iommu_init(void) · line 1269

Quoted 11 lines · Jan Beulich
xen/drivers/passthrough/amd/iommu_init.c +5 -2
-    if ( amd_iommu_update_ivrs_mapping_acpi() != 0 )
+    rc = amd_iommu_update_ivrs_mapping_acpi();
+    if ( rc )
         goto error_out;
 
     /* initialize io-apic interrupt remapping entries */
-    if ( iommu_intremap && amd_iommu_setup_ioapic_remapping() != 0 )
+    if ( iommu_intremap )
+        rc = amd_iommu_setup_ioapic_remapping();
+    if ( rc )
         goto error_out;

Is it better to indent this if() here? Then,

xen/drivers/passthrough/amd/iommu_init.c int __init amd_iommu_init(void)

Quoted 6 lines
xen/drivers/passthrough/amd/iommu_init.c +6 -0
+    if ( iommu_intremap )
+    {
+        rc = amd_iommu_setup_ioapic_remapping();
+        if ( rc )
+            goto error_out;
+    }

What would this help (apart from increasing LOC and patch size)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 16.06.16 at 04:03, <[email protected]> wrote:

xen/drivers/passthrough/amd/iommu_init.c int __init amd_iommu_init(void) · line 1269

Quoted 11 lines · Jan Beulich
xen/drivers/passthrough/amd/iommu_init.c +5 -2
-    if ( amd_iommu_update_ivrs_mapping_acpi() != 0 )
+    rc = amd_iommu_update_ivrs_mapping_acpi();
+    if ( rc )
         goto error_out;
 
     /* initialize io-apic interrupt remapping entries */
-    if ( iommu_intremap && amd_iommu_setup_ioapic_remapping() != 0 )
+    if ( iommu_intremap )
+        rc = amd_iommu_setup_ioapic_remapping();
+    if ( rc )
         goto error_out;

Is it better to indent this if() here? Then,

Quoted 9 lines

xen/drivers/passthrough/amd/iommu_init.c int __init amd_iommu_init(void)

Quoted 6 lines
xen/drivers/passthrough/amd/iommu_init.c +6 -0
+    if ( iommu_intremap )
+    {
+        rc = amd_iommu_setup_ioapic_remapping();
+        if ( rc )
+            goto error_out;
+    }

What would this help (apart from increasing LOC and patch size)?

Ah, first of all, it is not a logic issue, but just make the code clear:
- this if( rc ) is called only if ( iommu_intremap ) is true.
- this error is from amd_iommu_setup_ioapic_remapping().

Also from '- if ( iommu_intremap && amd_iommu_setup_ioapic_remapping() != 0 )', I'd like to fix it as my suggestion.

Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel