From patchwork Tue Aug 6 13:08:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11078883 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 E97C913AC for ; Tue, 6 Aug 2019 13:10:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB08B28958 for ; Tue, 6 Aug 2019 13:10:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D95782897D; Tue, 6 Aug 2019 13:10:19 +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 7E04E28958 for ; Tue, 6 Aug 2019 13:10:19 +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 1huzCe-0003Rd-At; Tue, 06 Aug 2019 13:08:36 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1huzCc-0003RP-Nk for xen-devel@lists.xenproject.org; Tue, 06 Aug 2019 13:08:34 +0000 X-Inumbo-ID: 4ad8cf75-b84b-11e9-8980-bc764e045a96 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 4ad8cf75-b84b-11e9-8980-bc764e045a96; Tue, 06 Aug 2019 13:08:33 +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 9BD71B11B; Tue, 6 Aug 2019 13:08:32 +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:08:32 +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 03/10] AMD/IOMMU: don't free shared IRT multiple times 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 Calling amd_iommu_free_intremap_table() for every IVRS entry is correct only in per-device-IRT mode. Use a NULL 2nd argument to indicate that the shared table should be freed, and call the function exactly once in shared mode. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- v5: New. --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -1106,6 +1106,15 @@ static void __init amd_iommu_init_cleanu { struct amd_iommu *iommu, *next; + /* free interrupt remapping table */ + if ( amd_iommu_perdev_intremap ) + iterate_ivrs_entries(amd_iommu_free_intremap_table); + else if ( shared_intremap_table ) + amd_iommu_free_intremap_table(list_first_entry(&amd_iommu_head, + struct amd_iommu, + list), + NULL); + /* free amd iommu list */ list_for_each_entry_safe ( iommu, next, &amd_iommu_head, list ) { @@ -1128,9 +1137,6 @@ static void __init amd_iommu_init_cleanu xfree(iommu); } - /* free interrupt remapping table */ - iterate_ivrs_entries(amd_iommu_free_intremap_table); - /* free device table */ deallocate_device_table(&device_table); --- a/xen/drivers/passthrough/amd/iommu_intr.c +++ b/xen/drivers/passthrough/amd/iommu_intr.c @@ -792,14 +792,23 @@ void amd_iommu_read_msi_from_ire( int __init amd_iommu_free_intremap_table( const struct amd_iommu *iommu, struct ivrs_mappings *ivrs_mapping) { - void *tb = ivrs_mapping->intremap_table; + void **tblp; - XFREE(ivrs_mapping->intremap_inuse); + if ( ivrs_mapping ) + { + XFREE(ivrs_mapping->intremap_inuse); + tblp = &ivrs_mapping->intremap_table; + } + else + { + XFREE(shared_intremap_inuse); + tblp = &shared_intremap_table; + } - if ( tb ) + if ( *tblp ) { - __free_amd_iommu_tables(tb, intremap_table_order(iommu)); - ivrs_mapping->intremap_table = NULL; + __free_amd_iommu_tables(*tblp, intremap_table_order(iommu)); + *tblp = NULL; } return 0;