From patchwork Tue Aug 6 13:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11078885 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 B2EAD13AC for ; Tue, 6 Aug 2019 13:10:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A461428783 for ; Tue, 6 Aug 2019 13:10:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9888D2892B; Tue, 6 Aug 2019 13:10:24 +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 3C52E28783 for ; Tue, 6 Aug 2019 13:10:24 +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 1huzD3-0003X6-LG; Tue, 06 Aug 2019 13:09:01 +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 1huzD2-0003Wq-G0 for xen-devel@lists.xenproject.org; Tue, 06 Aug 2019 13:09:00 +0000 X-Inumbo-ID: 5a1afd12-b84b-11e9-8433-c7ba757adeb9 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5a1afd12-b84b-11e9-8433-c7ba757adeb9; Tue, 06 Aug 2019 13:08:59 +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 4A2D4B637; Tue, 6 Aug 2019 13:08:58 +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:58 +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 04/10] AMD/IOMMU: introduce a "valid" flag for IVRS mappings 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 For us to no longer blindly allocate interrupt remapping tables for everything the ACPI tables name, we can't use struct ivrs_mappings' intremap_table field anymore to also have the meaning of "this entry is valid". Add a separate boolean field 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 @@ -88,6 +88,8 @@ static void __init add_ivrs_mapping_entr } } + ivrs_mappings[alias_id].valid = true; + /* Assign IOMMU hardware. */ ivrs_mappings[bdf].iommu = iommu; } --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -1244,7 +1244,6 @@ static int __init amd_iommu_setup_device u16 seg, struct ivrs_mappings *ivrs_mappings) { unsigned int bdf; - void *intr_tb, *dte; BUG_ON( (ivrs_bdf_entries == 0) ); @@ -1264,16 +1263,17 @@ static int __init amd_iommu_setup_device /* Add device table entries */ for ( bdf = 0; bdf < ivrs_bdf_entries; bdf++ ) { - intr_tb = ivrs_mappings[bdf].intremap_table; - - if ( intr_tb ) + if ( ivrs_mappings[bdf].valid ) { + void *dte; + /* add device table entry */ dte = device_table.buffer + (bdf * IOMMU_DEV_TABLE_ENTRY_SIZE); iommu_dte_add_device_entry(dte, &ivrs_mappings[bdf]); amd_iommu_set_intremap_table( - dte, (u64)virt_to_maddr(intr_tb), iommu_intremap); + dte, virt_to_maddr(ivrs_mappings[bdf].intremap_table), + iommu_intremap); } } --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -69,8 +69,8 @@ struct amd_iommu *find_iommu_for_device( * table and I/O page table respectively. Such devices will have * both alias entry and select entry in IVRS structure. * - * Return original device id, if device has valid interrupt remapping - * table setup for both select entry and alias entry. + * Return original device id if both the specific entry and the alias entry + * have been marked valid. */ int get_dma_requestor_id(uint16_t seg, uint16_t bdf) { @@ -79,8 +79,7 @@ int get_dma_requestor_id(uint16_t seg, u BUG_ON ( bdf >= ivrs_bdf_entries ); req_id = ivrs_mappings[bdf].dte_requestor_id; - if ( (ivrs_mappings[bdf].intremap_table != NULL) && - (ivrs_mappings[req_id].intremap_table != NULL) ) + if ( ivrs_mappings[bdf].valid && ivrs_mappings[req_id].valid ) req_id = bdf; return req_id; --- a/xen/include/asm-x86/amd-iommu.h +++ b/xen/include/asm-x86/amd-iommu.h @@ -111,6 +111,7 @@ struct ivrs_mappings { u8 unity_map_enable; u8 write_permission; u8 read_permission; + bool valid; unsigned long addr_range_start; unsigned long addr_range_length; struct amd_iommu *iommu;