From patchwork Thu Dec 1 11:04:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 9455859 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 B30DD60515 for ; Thu, 1 Dec 2016 11:08:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A51AA2847F for ; Thu, 1 Dec 2016 11:08:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 987FC284D3; Thu, 1 Dec 2016 11:08: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=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 776D92847F for ; Thu, 1 Dec 2016 11:08:23 +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 1cCPBT-0002uO-DY; Thu, 01 Dec 2016 11:05:47 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cCPBR-0002uI-UT for xen-devel@lists.xen.org; Thu, 01 Dec 2016 11:05:46 +0000 Received: from [193.109.254.147] by server-10.bemta-6.messagelabs.com id FA/69-28971-90400485; Thu, 01 Dec 2016 11:05:45 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNKsWRWlGSWpSXmKPExsWSoa/pr8vB4hB h8KRFyGLJx8UsDoweR3f/ZgpgjGLNzEvKr0hgzThy7xh7wbrkisYbN1gbGE+7dTFycbAItDBL 9C19xdzFyMnBKBAv8e7+AlaQhJBAE5PE312HWEESbALWEq/m3GEHsUUEZCVWd81hByliFuhgl Fh7cyJYkbCAncTbHf0sXYwcQGNVJHpOxoOEeQV8JDqev2MCsSUE5CROHpvMChEXlDg58wkLiM 0sICFx8MULZogaBYnt37+zQditjBJXNtmA2EICWhKXjxyEivtK/J91hQnGPvG2hxnkHgmBlWw S7W/fskMkLrFJzN1gCnKPhECOxLPrHBCmp8T5bS4Q5VOYJI6ufs0G4TxklWj5dp0VoldG4tbp JUwQidcsEp9/HmED6RYCBtGvOc4Q8e3cEs1fZrBDOAfYJPa+bGSEhISUxPsdJ6FsGYkNM+awQ BRNZJN4t+Mz1N0SEvNPNzJPYFSehRQcs5CCYwEj0ypGjeLUorLUIl0jA72kosz0jJLcxMwcXU MDM73c1OLixPTUnMSkYr3k/NxNjMCEwAAEOxh/LQs4xCjJwaQkyltWYh8hxJeUn1KZkVicEV9 UmpNafIhRg4NDoGfT6guMUix5+XmpShK8fMwOEUKCRanpqRVpmTnAlAVTKsHBoyTCG8YElOYt LkjMLc5Mh0idYlSUEuftAUkIgCQySvPg2mBp8hKjrJQwLyPQUUI8BalFuZklqPKvGMU5GJWEe S+CTOHJzCuBm/4KaDET0OKO6/Ygi0sSEVJSDYyirz7LtYUcqpl1vix9Dr/bkU+5AWsq/ug8/h zE82dJm9QTpu/ZV+9vV7slUK5StiDmrI6BlJd7w97YOfJ1Jr7K0RvMM3xauzudn177Ynnl61T VdsPLtv+iS3lDP092O7hD5E/kubnZS6a4eOW9MBPxumm45/mt/sNJP77Xb6o+OMFHu1QhL1KJ pTgj0VCLuag4EQC1oHWDjgMAAA== X-Env-Sender: Suravee.Suthikulpanit@amd.com X-Msg-Ref: server-5.tower-27.messagelabs.com!1480590342!75152477!1 X-Originating-IP: [104.47.41.79] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33997 invoked from network); 1 Dec 2016 11:05:44 -0000 Received: from mail-dm3nam03on0079.outbound.protection.outlook.com (HELO NAM03-DM3-obe.outbound.protection.outlook.com) (104.47.41.79) by server-5.tower-27.messagelabs.com with AES256-SHA256 encrypted SMTP; 1 Dec 2016 11:05:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=LDWGLG0vTiDovlSotf2G1nJEttFAK6ULLBGy7xBMc1I=; b=MkpMtRZHIgRq+SwscRWyDHKbyg19howfdzLSJcp3PerYj5cxHWWdk/T67zthTYAPV+Y39e1CQkjoZUXGulVOQZ6Rm6yFBAYMTqYYFAk/cPt7siqXfrcO9wADa6PfGr0GhvqIQm1LDjiJJelkRnhPdgLesIM/Xsl41dNZ6br3FSI= Received: from ssuthiku-ubuntu-zp.amd.com (165.204.77.1) by BN6PR12MB1444.namprd12.prod.outlook.com (10.172.24.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.761.9; Thu, 1 Dec 2016 11:05:40 +0000 From: Suravee Suthikulpanit To: Date: Thu, 1 Dec 2016 05:04:56 -0600 Message-ID: <1480590296-2534-1-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR12CA0060.namprd12.prod.outlook.com (10.175.83.150) To BN6PR12MB1444.namprd12.prod.outlook.com (10.172.24.21) X-MS-Office365-Filtering-Correlation-Id: 95702436-5d24-4805-0ee3-08d419d9fd21 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; R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y+UsyTEc9WHroWXYX0+aJvFsTQnKArEfhSoEftbd/WDvXAah+LwdwhMUFNQnpMtbT1hwZQ==; 20:AyK2sfCZfS1biikPzVfDf0cfY/MlQ3Kc0Mk3RFNQ564e+EYTrvjjpgeADtO8rqII/UYO0gquDwWWgBMfmP3Met6FJfgeWOD1g0lWcDEaNaftRXs9bMc/ndayEDLgDzP8GHc/NDkS5rEDbeBZwObvxofdhE6LfDWNlwJXU4V/MOX1CvPIF9HmUdENvYcteeiP3Xt360AHhCwwgIIn9OECzNgqp03rDJrH0+UjTNNtekhiliMpmVLDWAySsuFMpElK9gviaEdnHCR4HFcbho+UoDWn7PcgYm+453O5XiOMYW99JQUXfCDQKDNrl6bSmvEqygKkAEaNQX/0xxT84qVdhU1dL+ITNZq7Ghc1EimeUrkU+HVxAjBFN1yoFrriVsvC4caoKVzXpR1dBnGKiG9s4Bv4i2fG6KVrAbcHsKRLt1eN+hf2vBSmfPQ+5HqlNI1MxYLkXdDPHSUoZpxPBclh9KwkED9YQ3yEvlIMbPBnmlJdrGQd2++MKRNpoFCaYbys X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(146099531331640); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(20161123560025)(20161123562025)(20161123555025)(6072148); SRVR:BN6PR12MB1444; BCL:0; PCL:0; RULEID:; SRVR:BN6PR12MB1444; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1444; 4:vJKQHRJP+K2EGoYHOmyE37ESYQQ6eOm6fwP55S+j2QNDGYDf+my1dwyXQW0AgJTxv0McUsbOMlUzwWKiFHR3wTMsQkHI9FxKpDbygI44/PMITOZA6wCxWChqCZeW2qVBCc31o3caH8Mz99WjOEg1PuCLgecAjRl9UxgBKtfPnY8iqPq6V+8b+JvyG7zzd+OX3RUVBQ2aMV2+e9biE8jkl2AC7rnz6bkF/vEYZxSsRdAA/aigKapXR/RzL23f4RlbUE2qtx5dhvrcG6LhFu9r7tYlP/JBbozWgFSsyAwxw3qYvy6GiFuRdzAH/ifPKJlDsEhOOxftofz792NTcuWFuWt25w4eyoQ7ESiyMy9+rFTXHDGsgMELgVU8X7j1XnWvZOYttJQFrEBRDkAqMhE++EUBkCfikCSKH8Nj9Hl8uxbde6gjC4zMbDcwd+QIPdNNMJQNKpuZiB0qDbGQsu5EHQOj4xIEWBOiI6WALwHIj++4TSBEQSX0vEywZW2ZvoGQjizxWjtTUeY2+GZByDUxwxAApcpQ4K5IkQOFT8msEd3lY699StcH2jPgG+wQuI+YPzpHyg1SmKpV4P3PFLi+o51LrS733hg2td/RZinrRyvGi55fgBWIkPvc/tJtlBhhLlj7ydlnm9gzsZaDVsJEjCDwKC+xcBhuvcWUFiAZ2r0= X-Forefront-PRVS: 014304E855 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(199003)(189002)(6116002)(86362001)(39410400001)(92566002)(2906002)(47776003)(66066001)(105586002)(189998001)(106356001)(53416004)(2351001)(3846002)(7736002)(5003940100001)(7846002)(305945005)(50226002)(101416001)(48376002)(50466002)(36756003)(50986999)(81156014)(5660300001)(81166006)(4326007)(8676002)(97736004)(110136003)(6916009)(38730400001)(6486002)(33646002)(39450400002)(42186005)(733004)(68736007)(6666003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1444; H:ssuthiku-ubuntu-zp.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR12MB1444; 23:1ctFwdXkY2e/9wuD9TzuWaRJMgDUx6xn1qNpL2p6b?= =?us-ascii?Q?ORfOw01jMgTIVVjD1kdOSAX4qoN78SZCcut2YQFHAuIj6pi+eD/gKrz0p4k2?= =?us-ascii?Q?fb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D8KvdNfGmaGM7y7gv75uy+kw?= =?us-ascii?Q?Q2VRqgSKsPTkcXk4vVyx0OF9q9g8nQwx98v10mLeOm8vjHV4K/Z4s+M+hYPu?= =?us-ascii?Q?XWCMccTzpgBcPVXchG9nHFxM/dp?= X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1444; 6:W1hEcN8aebHV0l23WTTsENxtMDynbu6M+i3rJBdBML7rKEbN6XIVH0W6pirhqoqZvv7kLYYDJffql2OeEu05MTVxvquDuzYmZrjzxd5Y8c4ttrSzBktWqg7jQOYAp55I81be9UKj94FG4wkKvh6TNLJtcBAvNUI9J7F9c2M3NMU3kgF/7z1moq5Ua70MwVQP8FRTIjbJN6UXfXRsX1/5GoyS2ImZ1bZ76Fo+J9tXVquvoH3jqnkWzjhRNJ8HN5RvyrclSyF6celk8nSfFJsCUqAwfJ5qNAiar0MlS7zyWha6SDD66rTo6BellBDxXNW4Wh0luqZ8F1RxCzuS46wZiEi02lAKclFuq4x6xUKc1y2aGMvCSnNUAoFaZSD2UuzYQtVYuQOECJOdKrfJbC3UB1KXKgyDlI4BTuGdLAjVgttAPm0tuztBOECK4VLMDjkDZTwP2+bPIBtjgg7SfMNWzwefy2R0wmzI6vfg+PF6xz4=; 5:qoSx8bqJ2DPRO5FRJvVwPIGeEjlng3leBANmKQvOUngSPt+dJIVBFrvoPOjBr4qlICgo2br1YsXkiSfW9Ej84sjlop+SWdL2cIYZ6uZ8taCiSTSeKZQEBgRRL4NWw35+CN+EhKTSsMuxknN2ARRGxS4AnLWUbKex/UWUjvtZ8Pc=; 24:bcU2Ls/firOEtijmrI97SJjjGVF/5BNGSJrJOmJnvcoLmOn6NUaPkicxy16C7OIt6Q/JPA2BNGvi5I8/YKK9bRArx0f82xWaVLX5wzyH8y0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1444; 7:4w+pXq4P6eXv0a9knDFBMyT0pDT/iEc5+VGfEsSjrY0OWd+FAIPzqQpjlknJ3h92m5rLPYxBbb9yKE3LodIRvybFS83kv5cyp3PByLh3PE0TGJloB3T27EZOeueHY+Wim3Yuy8ETEv1DLlM/yl4vhWrI1xTeqlyti+WIefaXkPu4Eu21dC6bUgYruePiROaIiPcyTCyWSjng0z7oEEQHfJXXVciebgQNV8dHsOI+EV/LAORF/qxzJkMdT17hEywEoDmmAHMscVsnRdGK3kZijKUd+I/u95nzJL499/V9m3WX8esOncQ8ORT98xVpNBnvYMvoN54rfdLBTl+3eRObJ0HMD0E10NojSIisU84ufP+tg/hKo2BX3EUgtJNS3ObHXrsJnHAvsB0yqeTKjrLiKxGlwmZrY2Qprtim1L4a86h24imiZRKhP5/VBEOOA2wFL7oZgQ8ixXfyh7PU6LiGkA==; 20:VJSpZC/ivXfzXIpIeYiY+X8J2O3EbDEe/MsA2A0feJIngqOR73iucWAXswGQhd2jyhYPW2+NOG2TjJHh3KqX9psEU6WPMlAGSzGsdx8l9Aoy16JslUoGhRBvZoMiw4cFEsKNIMYgV276cJoRfmpL1vpDmpAokZ+nPXzQkyVCqwyBXf/q/0bVOxXGZtdTmVY0BSm8g1p0B3dhm6fdeI8Q228boPxp93ismBRu/btlWxgCdBQ9VWT969r6nd3yUNmA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2016 11:05:40.6268 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1444 Cc: boris.ostrovsky@oracle.com, Suravee Suthikulpanit , jbeulich@suse.com, sherry.hurwitz@amd.com Subject: [Xen-devel] [PATCH] AMD IOMMU: Support IOAPIC IDs larger than 128 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 Currently, the driver uses the APIC ID to index into the ioapic_sbdf array. The current MAX_IO_APICS is 128, which causes the driver initialization to fail on the system with IOAPIC ID >= 128. Instead, this patch adds APIC ID in the struct ioapic_sbdf, which is used to match the entry when searching through the array. Also, this patch removes the use of ioapic_cmdline bit-map, which is used to track the ivrs_ioapic options via command line. Instead, it introduces the cmd flag in the struct ioapic_cmdline, to identify if the entry is created during ivrs_ioapic command-line parsing. Signed-off-by: Suravee Suthikulpanit Cc: Jan Beulich Cc: Boris Ostrovsky --- xen/drivers/passthrough/amd/iommu_acpi.c | 80 +++++++++++++++------------ xen/drivers/passthrough/amd/iommu_intr.c | 65 ++++++++++++++++++---- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 6 ++ 3 files changed, 105 insertions(+), 46 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_acpi.c b/xen/drivers/passthrough/amd/iommu_acpi.c index b92c8ad..8c13471 100644 --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -633,26 +633,36 @@ static u16 __init parse_ivhd_device_extended_range( return dev_length; } -static DECLARE_BITMAP(ioapic_cmdline, ARRAY_SIZE(ioapic_sbdf)) __initdata; - static void __init parse_ivrs_ioapic(char *str) { const char *s = str; unsigned long id; unsigned int seg, bus, dev, func; + int idx; ASSERT(*s == '['); id = simple_strtoul(s + 1, &s, 0); - if ( id >= ARRAY_SIZE(ioapic_sbdf) || *s != ']' || *++s != '=' ) + + if ( *s != ']' || *++s != '=' ) + return; + + idx = ioapic_id_to_index(id); + /* If the entry exist, just ignore the option. */ + if ( idx >= 0 ) return; s = parse_pci(s + 1, &seg, &bus, &dev, &func); if ( !s || *s ) return; - ioapic_sbdf[id].bdf = PCI_BDF(bus, dev, func); - ioapic_sbdf[id].seg = seg; - __set_bit(id, ioapic_cmdline); + idx = get_next_ioapic_bdf_index(); + if ( idx < 0 ) + return; + + ioapic_sbdf[idx].bdf = PCI_BDF(bus, dev, func); + ioapic_sbdf[idx].seg = seg; + ioapic_sbdf[idx].id = id; + ioapic_sbdf[idx].cmd = true; } custom_param("ivrs_ioapic[", parse_ivrs_ioapic); @@ -714,43 +724,36 @@ static u16 __init parse_ivhd_device_special( * consistency here --- whether entry's IOAPIC ID is valid and * whether there are conflicting/duplicated entries. */ - apic = find_first_bit(ioapic_cmdline, ARRAY_SIZE(ioapic_sbdf)); - while ( apic < ARRAY_SIZE(ioapic_sbdf) ) + for ( apic = 0 ; apic < nr_ioapic_sbdf; apic++ ) { if ( ioapic_sbdf[apic].bdf == bdf && ioapic_sbdf[apic].seg == seg ) break; - apic = find_next_bit(ioapic_cmdline, ARRAY_SIZE(ioapic_sbdf), - apic + 1); } - if ( apic < ARRAY_SIZE(ioapic_sbdf) ) + if ( apic < nr_ioapic_sbdf ) { AMD_IOMMU_DEBUG("IVHD: Command line override present for IO-APIC %#x" "(IVRS: %#x devID %04x:%02x:%02x.%u)\n", - apic, special->handle, seg, PCI_BUS(bdf), - PCI_SLOT(bdf), PCI_FUNC(bdf)); + ioapic_sbdf[apic].id, special->handle, seg, + PCI_BUS(bdf), PCI_SLOT(bdf), PCI_FUNC(bdf)); break; } for ( apic = 0; apic < nr_ioapics; apic++ ) { + int idx; + if ( IO_APIC_ID(apic) != special->handle ) continue; - if ( special->handle >= ARRAY_SIZE(ioapic_sbdf) ) - { - printk(XENLOG_ERR "IVHD Error: IO-APIC %#x entry beyond bounds\n", - special->handle); - return 0; - } - - if ( test_bit(special->handle, ioapic_cmdline) ) + idx = ioapic_id_to_index(special->handle); + if ( idx >= 0 && ioapic_sbdf[idx].cmd ) AMD_IOMMU_DEBUG("IVHD: Command line override present for IO-APIC %#x\n", special->handle); - else if ( ioapic_sbdf[special->handle].pin_2_idx ) + else if ( idx >= 0 && ioapic_sbdf[idx].pin_2_idx ) { - if ( ioapic_sbdf[special->handle].bdf == bdf && - ioapic_sbdf[special->handle].seg == seg ) + if ( ioapic_sbdf[idx].bdf == bdf && + ioapic_sbdf[idx].seg == seg ) AMD_IOMMU_DEBUG("IVHD Warning: Duplicate IO-APIC %#x entries\n", special->handle); else @@ -763,19 +766,24 @@ static u16 __init parse_ivhd_device_special( } else { + idx = get_next_ioapic_bdf_index(); + if ( idx < 0 ) + return 0; + /* set device id of ioapic */ - ioapic_sbdf[special->handle].bdf = bdf; - ioapic_sbdf[special->handle].seg = seg; + ioapic_sbdf[idx].bdf = bdf; + ioapic_sbdf[idx].seg = seg; + ioapic_sbdf[idx].id = special->handle; - ioapic_sbdf[special->handle].pin_2_idx = xmalloc_array( + ioapic_sbdf[idx].pin_2_idx = xmalloc_array( u16, nr_ioapic_entries[apic]); if ( nr_ioapic_entries[apic] && - !ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx ) + !ioapic_sbdf[idx].pin_2_idx ) { printk(XENLOG_ERR "IVHD Error: Out of memory\n"); return 0; } - memset(ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx, -1, + memset(ioapic_sbdf[idx].pin_2_idx, -1, nr_ioapic_entries[apic] * sizeof(*ioapic_sbdf->pin_2_idx)); } @@ -1028,15 +1036,15 @@ static int __init parse_ivrs_table(struct acpi_table_header *table) if ( !nr_ioapic_entries[apic] ) continue; - if ( !ioapic_sbdf[IO_APIC_ID(apic)].seg && + if ( !ioapic_sbdf[apic].seg && /* SB IO-APIC is always on this device in AMD systems. */ - ioapic_sbdf[IO_APIC_ID(apic)].bdf == PCI_BDF(0, 0x14, 0) ) + ioapic_sbdf[apic].bdf == PCI_BDF(0, 0x14, 0) ) sb_ioapic = 1; - if ( ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx ) + if ( ioapic_sbdf[apic].pin_2_idx ) continue; - if ( !test_bit(IO_APIC_ID(apic), ioapic_cmdline) ) + if ( ioapic_id_to_index(IO_APIC_ID(apic)) < 0 ) { printk(XENLOG_ERR "IVHD Error: no information for IO-APIC %#x\n", IO_APIC_ID(apic)); @@ -1044,10 +1052,10 @@ static int __init parse_ivrs_table(struct acpi_table_header *table) return -ENXIO; } - ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx = xmalloc_array( + ioapic_sbdf[apic].pin_2_idx = xmalloc_array( u16, nr_ioapic_entries[apic]); - if ( ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx ) - memset(ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx, -1, + if ( ioapic_sbdf[apic].pin_2_idx ) + memset(ioapic_sbdf[apic].pin_2_idx, -1, nr_ioapic_entries[apic] * sizeof(*ioapic_sbdf->pin_2_idx)); else { diff --git a/xen/drivers/passthrough/amd/iommu_intr.c b/xen/drivers/passthrough/amd/iommu_intr.c index 0a9f22f..438c78f 100644 --- a/xen/drivers/passthrough/amd/iommu_intr.c +++ b/xen/drivers/passthrough/amd/iommu_intr.c @@ -32,9 +32,36 @@ struct hpet_sbdf hpet_sbdf; void *shared_intremap_table; unsigned long *shared_intremap_inuse; static DEFINE_SPINLOCK(shared_intremap_lock); +unsigned int nr_ioapic_sbdf; static void dump_intremap_tables(unsigned char key); +int ioapic_id_to_index(unsigned int apic_id) +{ + int idx; + + if ( !nr_ioapic_sbdf ) + return -EINVAL; + + for ( idx = 0 ; idx < nr_ioapic_sbdf; idx++ ) + if ( ioapic_sbdf[idx].id == apic_id ) + break; + + if ( idx == nr_ioapic_sbdf ) + return -EINVAL; + + return idx; +} + +int get_next_ioapic_bdf_index(void) +{ + if ( nr_ioapic_sbdf < MAX_IO_APICS ) + return nr_ioapic_sbdf++; + + printk(XENLOG_ERR "IVHD Error: Too many IO APICs.\n"); + return -EINVAL; +} + static spinlock_t* get_intremap_lock(int seg, int req_id) { return (amd_iommu_perdev_intremap ? @@ -218,13 +245,19 @@ int __init amd_iommu_setup_ioapic_remapping(void) { for ( pin = 0; pin < nr_ioapic_entries[apic]; pin++ ) { + int idx; + rte = __ioapic_read_entry(apic, pin, 1); if ( rte.mask == 1 ) continue; /* get device id of ioapic devices */ - bdf = ioapic_sbdf[IO_APIC_ID(apic)].bdf; - seg = ioapic_sbdf[IO_APIC_ID(apic)].seg; + idx = ioapic_id_to_index(IO_APIC_ID(apic)); + if ( idx < 0 ) + return -EINVAL; + + bdf = ioapic_sbdf[idx].bdf; + seg = ioapic_sbdf[idx].seg; iommu = find_iommu_for_device(seg, bdf); if ( !iommu ) { @@ -250,7 +283,7 @@ int __init amd_iommu_setup_ioapic_remapping(void) spin_unlock_irqrestore(lock, flags); set_rte_index(&rte, offset); - ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx[pin] = offset; + ioapic_sbdf[idx].pin_2_idx[pin] = offset; __ioapic_write_entry(apic, pin, 1, rte); if ( iommu->enabled ) @@ -277,6 +310,7 @@ void amd_iommu_ioapic_update_ire( unsigned int pin = (reg - 0x10) / 2; int saved_mask, seg, bdf, rc; struct amd_iommu *iommu; + int idx; if ( !iommu_intremap ) { @@ -284,9 +318,13 @@ void amd_iommu_ioapic_update_ire( return; } + idx = ioapic_id_to_index(IO_APIC_ID(apic)); + if ( idx < 0 ) + return; + /* get device id of ioapic devices */ - bdf = ioapic_sbdf[IO_APIC_ID(apic)].bdf; - seg = ioapic_sbdf[IO_APIC_ID(apic)].seg; + bdf = ioapic_sbdf[idx].bdf; + seg = ioapic_sbdf[idx].seg; iommu = find_iommu_for_device(seg, bdf); if ( !iommu ) { @@ -313,7 +351,7 @@ void amd_iommu_ioapic_update_ire( } if ( new_rte.mask && - ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx[pin] >= INTREMAP_ENTRIES ) + ioapic_sbdf[idx].pin_2_idx[pin] >= INTREMAP_ENTRIES ) { ASSERT(saved_mask); __io_apic_write(apic, reg, value); @@ -330,7 +368,7 @@ void amd_iommu_ioapic_update_ire( /* Update interrupt remapping entry */ rc = update_intremap_entry_from_ioapic( bdf, iommu, &new_rte, reg == rte_lo, - &ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx[pin]); + &ioapic_sbdf[idx].pin_2_idx[pin]); __io_apic_write(apic, reg, ((u32 *)&new_rte)[reg != rte_lo]); @@ -357,14 +395,21 @@ void amd_iommu_ioapic_update_ire( unsigned int amd_iommu_read_ioapic_from_ire( unsigned int apic, unsigned int reg) { + int idx; + unsigned int offset; unsigned int val = __io_apic_read(apic, reg); unsigned int pin = (reg - 0x10) / 2; - unsigned int offset = ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx[pin]; + + idx = ioapic_id_to_index(IO_APIC_ID(apic)); + if ( idx < 0 ) + return -EINVAL; + + offset = ioapic_sbdf[idx].pin_2_idx[pin]; if ( !(reg & 1) && offset < INTREMAP_ENTRIES ) { - u16 bdf = ioapic_sbdf[IO_APIC_ID(apic)].bdf; - u16 seg = ioapic_sbdf[IO_APIC_ID(apic)].seg; + u16 bdf = ioapic_sbdf[idx].bdf; + u16 seg = ioapic_sbdf[idx].seg; u16 req_id = get_intremap_requestor_id(seg, bdf); const u32 *entry = get_intremap_entry(seg, req_id, offset); diff --git a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h index 6c702e8..d3db8f1 100644 --- a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +++ b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h @@ -104,8 +104,14 @@ int amd_setup_hpet_msi(struct msi_desc *msi_desc); extern struct ioapic_sbdf { u16 bdf, seg; u16 *pin_2_idx; + u8 id; + bool cmd; } ioapic_sbdf[MAX_IO_APICS]; +extern unsigned int nr_ioapic_sbdf; +int ioapic_id_to_index(unsigned int apic_id); +int get_next_ioapic_bdf_index(void); + extern struct hpet_sbdf { u16 bdf, seg, id; enum {