From patchwork Tue Jun 14 09:03:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9175259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ADC8F6048C for ; Tue, 14 Jun 2016 09:05:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E835280E0 for ; Tue, 14 Jun 2016 09:05:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 934E62824A; Tue, 14 Jun 2016 09:05:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E79E280E0 for ; Tue, 14 Jun 2016 09:05:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCkFi-0004mw-2P; Tue, 14 Jun 2016 09:03:18 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCkFg-0004ml-LR for xen-devel@lists.xenproject.org; Tue, 14 Jun 2016 09:03:16 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id 63/88-04210-358CF575; Tue, 14 Jun 2016 09:03:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRWlGSWpSXmKPExsXS6fjDSzfoRHy 4wYnLQhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8be/XOYCi7qVvTsvsDWwPhLuYuRk0NIIE9i 6Zar7CA2r4CdRNPcr8wgtoSAocS++avYQGwWAVWJC/vOgNWwCahLtD3bztrFyMEhImAgce5oE kiYWcBaon/mP7ByYQFfiRXL9jGClPAKCEr83SEMUWIncXFqI+MERq5ZCJlZSDIQtpbEw1+3WC BsbYllC18zg5QzC0hLLP/HARE2lJj4YCc7qhIQ20biUOsj9gWMHKsYNYpTi8pSi3QNTfSSijL TM0pyEzNzdA0NTPVyU4uLE9NTcxKTivWS83M3MQKDjwEIdjCePe15iFGSg0lJlPf2xPhwIb6k /JTKjMTijPii0pzU4kOMMhwcShK8oseBcoJFqempFWmZOcA4gElLcPAoifC+PQaU5i0uSMwtz kyHSJ1iVJQS510NkhAASWSU5sG1wWLvEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5v4JM4c nMK4Gb/gpoMRPQYpvpYItLEhFSUg2MSzbKfHq8vq22VebJg/MvONlFwuSWnfxypnKL6JufzKV 7Ts9ZMDU101+r6vRjxe9bA1pvcEZa2fzfevpKbU/VM7mQwudfWFee/bSUZeI/+3Te7nC/zWsu MhTO2Cw9t++Sm3us/tllYW8VBD9nvOPcYrW8gsOnXDFqSd1jiZ/5l14usufu7pOQUmIpzkg01 GIuKk4EANCWrwK4AgAA X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1465894991!8356661!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20382 invoked from network); 14 Jun 2016 09:03:12 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-12.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Jun 2016 09:03:12 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Tue, 14 Jun 2016 03:03:10 -0600 Message-Id: <575FE46D02000078000F4A8F@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Tue, 14 Jun 2016 03:03:09 -0600 From: "Jan Beulich" To: "xen-devel" Mime-Version: 1.0 Cc: Suravee Suthikulpanit Subject: [Xen-devel] [PATCH] AMD IOMMU: correctly propagate errors from amd_iommu_init() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP ... 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 Signed-off-by: Jan Beulich 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 Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -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) Reviewed-by: Andrew Cooper Reviewed-by: Suravee Suthikulpanit Tested-by: Suravee Suthikulpanit --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -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)