From nobody Fri Apr 26 15:47:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1570705524; cv=none; d=zoho.com; s=zohoarc; b=D7UjSZWealTTFd1AWqzf5edEglKetkd2NrRtCQhuVBhDdNwFiqMMINOgeIcK60I5C6qakq4xDqSO9mQX3mbARdadLzluT/0Ulgmw58kBQ6C/vqPYe8nqR1tppAW7qBzajBDjvSIVdqao0Qaj9+CkOVNVW6SEc8Aq4Y2XsWYfkLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570705524; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6dO3tuIKzBg/LmSmTeLxVyy1GIyYxx1VfYoRydJ9dUM=; b=gUUz6mOsBhnUce3lHSZM4A+uRFdmv8DKeyEYKoX8um2CSgbZ/9EDOaMLrHth4KynHjeZbvcHBa5KCegkXjXlm0ZWuXTpFqAJ9NXZ8haikgYtIOo2EPSAA6jSJg9jqQKEa3vLUwZWfA2kLwDFv4DYzH3dRKEC7UyNb3WnD6GPWmw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1570705523941427.99257467272423; Thu, 10 Oct 2019 04:05:23 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIWEp-0006yv-Re; Thu, 10 Oct 2019 11:04:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIWEo-0006xv-PM for xen-devel@lists.xenproject.org; Thu, 10 Oct 2019 11:04:06 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a9b20bf6-eb4d-11e9-80e3-bc764e2007e4; Thu, 10 Oct 2019 11:04:00 +0000 (UTC) X-Inumbo-ID: a9b20bf6-eb4d-11e9-80e3-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1570705440; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hhRu1nFIWPw7WnQfPcGb340mQo7QXPNxztF11mDjH6A=; b=DY3aoiQlJ/ysiHE7ku7p0zXigNagnVX5XKuENMSQrjUi7k8I/uyeSVBP fUfnfJRO2GgJQEHKVrYpeNeK3Rzw5ucTpytLhFcoGYmtwdRzAndSDw73O gIgm3yET0QBtuoXd0tGQeDkc87vAavwiU6lYpb/x7mcgKf6K2XkPJApE2 Q=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: iEALV9aL7iyaDKnZ9Nwh/8CMJKfaLW7A/sBEVwzoXtacnLKg+CfIQ2+McpjbYd1bgl2Ua9K5cx wDARz6aVaS5YD8p6xR+BUJkfiRXfNJE060dSKAKmfeG3E3lHtEE6e0zy2lTnvtcGnvMXuvHYom KHlmmEtO/L0rfg5Mo/8gcqJdwprm4FcRfF1AfFMBBMVPWl2H9QZ/9hgwcaup4565dKmx0KhvlM 7eS0Yac0eno9rECd/FSOoo0pUHwZV4ZM1UJUxW7gI1vYqkIMDRj1Z1vbRyU4e59nhWQlcLlTr3 i50= X-SBRS: 2.7 X-MesageID: 6972754 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.67,279,1566878400"; d="scan'208";a="6972754" From: Roger Pau Monne To: Date: Thu, 10 Oct 2019 13:03:38 +0200 Message-ID: <20191010110339.6447-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010110339.6447-1-roger.pau@citrix.com> References: <20191010110339.6447-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/2] x2APIC: translate IO-APIC entries when enabling the IOMMU 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: Juergen Gross , Andrew Cooper , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) When interrupt remapping is enabled as part of enabling x2APIC the IO-APIC entries also need to be translated to the new format and added to the interrupt remapping table. This prevents IOMMU interrupt remapping faults when booting on hardware that has unmasked IO-APIC pins. Reported-by: Andrew Cooper Signed-off-by: Roger Pau Monn=C3=A9 --- Cc: Juergen Gross --- xen/arch/x86/apic.c | 12 ++++++++++-- xen/arch/x86/io_apic.c | 5 +++-- xen/include/asm-x86/io_apic.h | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/apic.c b/xen/arch/x86/apic.c index 6cdb50cf41..9810de7473 100644 --- a/xen/arch/x86/apic.c +++ b/xen/arch/x86/apic.c @@ -515,7 +515,7 @@ static void resume_x2apic(void) iommu_enable_x2apic(); __enable_x2apic(); =20 - restore_IO_APIC_setup(ioapic_entries); + restore_IO_APIC_setup(ioapic_entries, true); unmask_8259A(); =20 out: @@ -887,6 +887,7 @@ void __init x2apic_bsp_setup(void) { struct IO_APIC_route_entry **ioapic_entries =3D NULL; const char *orig_name; + bool iommu_enabled =3D true; =20 if ( !cpu_has_x2apic ) return; @@ -934,6 +935,7 @@ void __init x2apic_bsp_setup(void) if ( !x2apic_enabled ) { printk("Not enabling x2APIC (upon firmware request)\n"); + iommu_enabled =3D false; goto restore_out; } /* fall through */ @@ -944,6 +946,7 @@ void __init x2apic_bsp_setup(void) =20 printk(XENLOG_ERR "Failed to enable Interrupt Remapping: Will not enable x2AP= IC.\n"); + iommu_enabled =3D false; goto restore_out; } =20 @@ -961,7 +964,12 @@ void __init x2apic_bsp_setup(void) printk("Switched to APIC driver %s\n", genapic.name); =20 restore_out: - restore_IO_APIC_setup(ioapic_entries); + /* + * NB: do not use raw mode when restoring entries if the iommu has been + * enabled during the process, because the entries need to be translat= ed + * and added to the remapping table in that case. + */ + restore_IO_APIC_setup(ioapic_entries, !iommu_enabled); unmask_8259A(); =20 out: diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c index 5d25862bd8..37eabc16c9 100644 --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -379,7 +379,8 @@ void mask_IO_APIC_setup(struct IO_APIC_route_entry **io= apic_entries) /* * Restore IO APIC entries which was saved in ioapic_entries. */ -int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries) +int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries, + bool raw) { int apic, pin; =20 @@ -394,7 +395,7 @@ int restore_IO_APIC_setup(struct IO_APIC_route_entry **= ioapic_entries) return -ENOMEM; =20 for (pin =3D 0; pin < nr_ioapic_entries[apic]; pin++) - ioapic_write_entry(apic, pin, 1, ioapic_entries[apic][pin]); + ioapic_write_entry(apic, pin, raw, ioapic_entries[apic][pin]); } =20 return 0; diff --git a/xen/include/asm-x86/io_apic.h b/xen/include/asm-x86/io_apic.h index 0b041f0565..998905186b 100644 --- a/xen/include/asm-x86/io_apic.h +++ b/xen/include/asm-x86/io_apic.h @@ -197,7 +197,8 @@ extern struct IO_APIC_route_entry **alloc_ioapic_entrie= s(void); extern void free_ioapic_entries(struct IO_APIC_route_entry **ioapic_entrie= s); extern int save_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries); extern void mask_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries= ); -extern int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entri= es); +extern int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entri= es, + bool raw); =20 unsigned highest_gsi(void); =20 --=20 2.23.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 15:47:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1570705524; cv=none; d=zoho.com; s=zohoarc; b=N51GyDP0E3wi+eypBOKEmZxdS7pmCLVJY3CiI2q1t2EVKlfLksqt0g0VVm2LFbKUSL5lTAha1rN6gHm9n5djOUlx4/m6cIwm1wANXCYiF8sfLlLWBNl5tQOtqjn3BCTUdXbtigsU7Cb5oAPKaeZHOcS7gYNSAlJ0W5xRi5v1lzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570705524; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6MMJX251P2JE4HmfOv5uAwbI4BL/rd+wf1J1FNrB7Yg=; b=H1F7nd+fWS9oAMoiIhOLP6LxAf4JnXkohRYl1rPH35UUHSjDLi2RjED6h1vjxzMCSkxI7wDS+O9iyIQSR4o+QXguxmF1zTe0Kn7Wq4W1DRhTEsu3bvk3Kp1vikgcu3S0nIKW8NsSfXCtvY6kWf5jhArGkonqy+Wd3TMNPmeKYRc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1570705524907438.8302176650129; Thu, 10 Oct 2019 04:05:24 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIWEp-0006yf-CJ; Thu, 10 Oct 2019 11:04:07 +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 1iIWEn-0006xq-TZ for xen-devel@lists.xenproject.org; Thu, 10 Oct 2019 11:04:05 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id abded814-eb4d-11e9-9800-12813bfff9fa; Thu, 10 Oct 2019 11:04:04 +0000 (UTC) X-Inumbo-ID: abded814-eb4d-11e9-9800-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1570705444; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VJ+eNzJg3w6G9LgrbYkzOMKvORC0WkpX/C+Ntg/gB28=; b=R0Pf56u45rMIebFgvYc3d80HdPWEdMq660rfxagtuXfblNdqMotEVVOd H95RQNOKKqHAwwVWPhd5O1VxR7sQ4+DYL0H5jjSQQKWEPrQQX+VPJhBh9 l1OsSeewrgogcBQHG4WJkSPZbRZwxQwxI00PHkp4OvhruQZWB4aP2yASx M=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: mF1CA1AWAbHUHk4MlTKuqzGUAsELROpk4KzZ60p5x0ipNdshNZz76ayx8ydzkiCF6Oe9Y5oNBu TYIjjbC0vgd+6N0a2sMyN79n+Y2uxSbYGZ4W+uns/c5af7U5nNMAfOG1LCaNYgwK3E7TJrRKbO c9pG4EAwzbDCnYtgEUTCQnie6Gk4e96vp6H4g+79AviPmzgiH/1Rmw28R9AOYuT3RSIDelI6q3 rE9Bpgls6selSdFKYQDk9+DgjUewe6wyyoUvJWFAweSI6SPziWwATJ8PteJiIJoW6VWddO4hC+ S9U= X-SBRS: 2.7 X-MesageID: 6708681 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.67,279,1566878400"; d="scan'208";a="6708681" From: Roger Pau Monne To: Date: Thu, 10 Oct 2019 13:03:39 +0200 Message-ID: <20191010110339.6447-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010110339.6447-1-roger.pau@citrix.com> References: <20191010110339.6447-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/2] iommu: translate IO-APIC pins when enabling interrupt remapping 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: Juergen Gross , Suravee Suthikulpanit , Wei Liu , Andrew Cooper , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) On Intel hardware there's currently no translation of already enabled IO-APIC pins when interrupt remapping is enabled on the IOMMU, hence introduce a logic similar to the one used in x2apic_bsp_setup in order to save and mask all IO-APIC pins, and then translate and restore them after interrupt remapping has been enabled. With this change the AMD specific logic to deal with enabled pins (amd_iommu_setup_ioapic_remapping) can be removed, thus unifying the handling of IO-APIC when enabling interrupt remapping regardless of the IOMMU vendor. Reported-by: Andrew Cooper Signed-off-by: Roger Pau Monn=C3=A9 --- Cc: Juergen Gross --- xen/drivers/passthrough/amd/iommu_init.c | 11 ++- xen/drivers/passthrough/amd/iommu_intr.c | 90 +------------------ xen/drivers/passthrough/x86/iommu.c | 34 ++++++- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 1 + 4 files changed, 40 insertions(+), 96 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_init.c b/xen/drivers/passthr= ough/amd/iommu_init.c index 6f53c7ec08..3c244619b9 100644 --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -19,6 +19,7 @@ =20 #include #include +#include #include #include #include @@ -1435,12 +1436,6 @@ int __init amd_iommu_init(bool xt) if ( rc ) goto error_out; =20 - /* initialize io-apic interrupt remapping entries */ - if ( iommu_intremap ) - rc =3D amd_iommu_setup_ioapic_remapping(); - if ( rc ) - goto error_out; - /* Allocate and initialize device table(s). */ pci_init =3D !xt; rc =3D iterate_ivrs_mappings(amd_iommu_setup_device_table); @@ -1469,6 +1464,10 @@ int __init amd_iommu_init(bool xt) goto error_out; } =20 + if ( iommu_intremap ) + register_keyhandler('V', &amd_iommu_dump_intremap_tables, + "dump IOMMU intremap tables", 0); + return 0; =20 error_out: diff --git a/xen/drivers/passthrough/amd/iommu_intr.c b/xen/drivers/passthr= ough/amd/iommu_intr.c index fb71073c84..1eed60f265 100644 --- a/xen/drivers/passthrough/amd/iommu_intr.c +++ b/xen/drivers/passthrough/amd/iommu_intr.c @@ -21,7 +21,6 @@ #include #include #include -#include #include =20 union irte32 { @@ -79,8 +78,6 @@ unsigned long *shared_intremap_inuse; static DEFINE_SPINLOCK(shared_intremap_lock); unsigned int nr_ioapic_sbdf; =20 -static void dump_intremap_tables(unsigned char key); - #define intremap_page_order(irt) PFN_ORDER(virt_to_page(irt)) =20 unsigned int amd_iommu_intremap_table_order( @@ -354,91 +351,6 @@ static int update_intremap_entry_from_ioapic( return 0; } =20 -int __init amd_iommu_setup_ioapic_remapping(void) -{ - struct IO_APIC_route_entry rte; - unsigned long flags; - union irte_ptr entry; - int apic, pin; - u8 delivery_mode, dest, vector, dest_mode; - u16 seg, bdf, req_id; - struct amd_iommu *iommu; - spinlock_t *lock; - unsigned int offset; - - /* Read ioapic entries and update interrupt remapping table accordingl= y */ - for ( apic =3D 0; apic < nr_ioapics; apic++ ) - { - for ( pin =3D 0; pin < nr_ioapic_entries[apic]; pin++ ) - { - unsigned int idx; - - rte =3D __ioapic_read_entry(apic, pin, 1); - if ( rte.mask =3D=3D 1 ) - continue; - - /* get device id of ioapic devices */ - idx =3D ioapic_id_to_index(IO_APIC_ID(apic)); - if ( idx =3D=3D MAX_IO_APICS ) - return -EINVAL; - - bdf =3D ioapic_sbdf[idx].bdf; - seg =3D ioapic_sbdf[idx].seg; - iommu =3D find_iommu_for_device(seg, bdf); - if ( !iommu ) - { - AMD_IOMMU_DEBUG("Fail to find iommu for ioapic " - "device id =3D %04x:%04x\n", seg, bdf); - continue; - } - - req_id =3D get_intremap_requestor_id(iommu->seg, bdf); - lock =3D get_intremap_lock(iommu->seg, req_id); - - delivery_mode =3D rte.delivery_mode; - vector =3D rte.vector; - dest_mode =3D rte.dest_mode; - dest =3D rte.dest.logical.logical_dest; - - if ( iommu->ctrl.xt_en ) - { - /* - * In x2APIC mode we have no way of discovering the high 24 - * bits of the destination of an already enabled interrupt. - * We come here earlier than for xAPIC mode, so no interru= pts - * should have been set up before. - */ - AMD_IOMMU_DEBUG("Unmasked IO-APIC#%u entry %u in x2APIC mo= de\n", - IO_APIC_ID(apic), pin); - } - - spin_lock_irqsave(lock, flags); - offset =3D alloc_intremap_entry(iommu, req_id, 1); - BUG_ON(offset >=3D INTREMAP_MAX_ENTRIES); - entry =3D get_intremap_entry(iommu, req_id, offset); - update_intremap_entry(iommu, entry, vector, - delivery_mode, dest_mode, dest); - spin_unlock_irqrestore(lock, flags); - - set_rte_index(&rte, offset); - ioapic_sbdf[idx].pin_2_idx[pin] =3D offset; - __ioapic_write_entry(apic, pin, 1, rte); - - if ( iommu->enabled ) - { - spin_lock_irqsave(&iommu->lock, flags); - amd_iommu_flush_intremap(iommu, req_id); - spin_unlock_irqrestore(&iommu->lock, flags); - } - } - } - - register_keyhandler('V', &dump_intremap_tables, - "dump IOMMU intremap tables", 0); - - return 0; -} - void amd_iommu_ioapic_update_ire( unsigned int apic, unsigned int reg, unsigned int value) { @@ -982,7 +894,7 @@ static int dump_intremap_mapping(const struct amd_iommu= *iommu, return 0; } =20 -static void dump_intremap_tables(unsigned char key) +void amd_iommu_dump_intremap_tables(unsigned char key) { if ( !shared_intremap_table ) { diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/= x86/iommu.c index 59905629e1..2cf528e760 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -21,6 +21,7 @@ #include =20 #include +#include #include =20 const struct iommu_init_ops *__initdata iommu_init_ops; @@ -28,6 +29,7 @@ struct iommu_ops __read_mostly iommu_ops; =20 int __init iommu_hardware_setup(void) { + struct IO_APIC_route_entry **ioapic_entries =3D NULL; int rc; =20 if ( !iommu_init_ops ) @@ -43,7 +45,37 @@ int __init iommu_hardware_setup(void) /* x2apic setup may have previously initialised the struct. */ ASSERT(iommu_ops.init =3D=3D iommu_init_ops->ops->init); =20 - return iommu_init_ops->setup(); + if ( !x2apic_enabled && iommu_intremap ) + { + /* + * If x2APIC is enabled interrupt remapping is already enabled, so + * there's no need to mess with the IO-APIC because the remapping + * entries are already correctly setup by x2apic_bsp_setup. + */ + ioapic_entries =3D alloc_ioapic_entries(); + if ( !ioapic_entries ) + return -ENOMEM; + rc =3D save_IO_APIC_setup(ioapic_entries); + if ( rc ) + { + free_ioapic_entries(ioapic_entries); + return rc; + } + + mask_8259A(); + mask_IO_APIC_setup(ioapic_entries); + } + + rc =3D iommu_init_ops->setup(); + + if ( ioapic_entries ) + { + restore_IO_APIC_setup(ioapic_entries, rc); + unmask_8259A(); + free_ioapic_entries(ioapic_entries); + } + + return rc; } =20 int iommu_enable_x2apic(void) diff --git a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h b/xen/include/as= m-x86/hvm/svm/amd-iommu-proto.h index 07d25a585d..8ed9482791 100644 --- a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +++ b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h @@ -114,6 +114,7 @@ int amd_iommu_msi_msg_update_ire( void amd_iommu_read_msi_from_ire( struct msi_desc *msi_desc, struct msi_msg *msg); int amd_setup_hpet_msi(struct msi_desc *msi_desc); +void amd_iommu_dump_intremap_tables(unsigned char key); =20 extern struct ioapic_sbdf { u16 bdf, seg; --=20 2.23.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel