From patchwork Tue Aug 6 13:09:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11078891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3370F1399 for ; Tue, 6 Aug 2019 13:11:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21726266F3 for ; Tue, 6 Aug 2019 13:11:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15A3B287BD; Tue, 6 Aug 2019 13:11:07 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B0DCF28866 for ; Tue, 6 Aug 2019 13:11:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1huzDR-0003c3-0p; Tue, 06 Aug 2019 13:09:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1huzDQ-0003bf-6x for xen-devel@lists.xenproject.org; Tue, 06 Aug 2019 13:09:24 +0000 X-Inumbo-ID: 67bf5ab2-b84b-11e9-a701-8fff05ca96a2 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 67bf5ab2-b84b-11e9-a701-8fff05ca96a2; Tue, 06 Aug 2019 13:09:21 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2E054B638; Tue, 6 Aug 2019 13:09:21 +0000 (UTC) From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: <5a4d4a61-a543-c657-8458-cbc6b5a8a633@suse.com> Message-ID: Date: Tue, 6 Aug 2019 15:09:21 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <5a4d4a61-a543-c657-8458-cbc6b5a8a633@suse.com> Content-Language: en-US Subject: [Xen-devel] [PATCH v5 05/10] AMD/IOMMU: let callers of amd_iommu_alloc_intremap_table() handle errors X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Brian Woods , Suravee Suthikulpanit Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Additional users of the function will want to handle errors more gracefully. Remove the BUG_ON()s and make the current caller panic() instead. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- v5: New. --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -86,6 +86,10 @@ static void __init add_ivrs_mapping_entr ivrs_mappings[alias_id].intremap_table = shared_intremap_table; ivrs_mappings[alias_id].intremap_inuse = shared_intremap_inuse; } + + if ( !ivrs_mappings[alias_id].intremap_table ) + panic("No memory for %04x:%02x:%02x.%u's IRT\n", iommu->seg, + PCI_BUS(alias_id), PCI_SLOT(alias_id), PCI_FUNC(alias_id)); } ivrs_mappings[alias_id].valid = true; --- a/xen/drivers/passthrough/amd/iommu_intr.c +++ b/xen/drivers/passthrough/amd/iommu_intr.c @@ -817,12 +817,22 @@ int __init amd_iommu_free_intremap_table void *__init amd_iommu_alloc_intremap_table( const struct amd_iommu *iommu, unsigned long **inuse_map) { - void *tb = __alloc_amd_iommu_tables(intremap_table_order(iommu)); + unsigned int order = intremap_table_order(iommu); + void *tb = __alloc_amd_iommu_tables(order); + + if ( tb ) + { + *inuse_map = xzalloc_array(unsigned long, + BITS_TO_LONGS(INTREMAP_ENTRIES)); + if ( *inuse_map ) + memset(tb, 0, PAGE_SIZE << order); + else + { + __free_amd_iommu_tables(tb, order); + tb = NULL; + } + } - BUG_ON(tb == NULL); - memset(tb, 0, PAGE_SIZE << intremap_table_order(iommu)); - *inuse_map = xzalloc_array(unsigned long, BITS_TO_LONGS(INTREMAP_ENTRIES)); - BUG_ON(*inuse_map == NULL); return tb; }