From patchwork Thu Oct 10 11:03:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 11183103 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F09F5139A for ; Thu, 10 Oct 2019 11:05:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC8E6208C3 for ; Thu, 10 Oct 2019 11:05:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="DY3aoiQl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC8E6208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Inumbo-ID: a9b20bf6-eb4d-11e9-80e3-bc764e2007e4 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) 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 (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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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é --- 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(); - restore_IO_APIC_setup(ioapic_entries); + restore_IO_APIC_setup(ioapic_entries, true); unmask_8259A(); out: @@ -887,6 +887,7 @@ void __init x2apic_bsp_setup(void) { struct IO_APIC_route_entry **ioapic_entries = NULL; const char *orig_name; + bool iommu_enabled = true; 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 = false; goto restore_out; } /* fall through */ @@ -944,6 +946,7 @@ void __init x2apic_bsp_setup(void) printk(XENLOG_ERR "Failed to enable Interrupt Remapping: Will not enable x2APIC.\n"); + iommu_enabled = false; goto restore_out; } @@ -961,7 +964,12 @@ void __init x2apic_bsp_setup(void) printk("Switched to APIC driver %s\n", genapic.name); 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 translated + * and added to the remapping table in that case. + */ + restore_IO_APIC_setup(ioapic_entries, !iommu_enabled); unmask_8259A(); 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 **ioapic_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; @@ -394,7 +395,7 @@ int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries) return -ENOMEM; for (pin = 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]); } 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_entries(void); extern void free_ioapic_entries(struct IO_APIC_route_entry **ioapic_entries); 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_entries); +extern int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries, + bool raw); unsigned highest_gsi(void);