From patchwork Fri Aug 11 16:43:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 9896307 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 E2F5B60351 for ; Fri, 11 Aug 2017 16:46:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D487628C50 for ; Fri, 11 Aug 2017 16:46:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C972428C55; Fri, 11 Aug 2017 16:46:59 +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.2 required=2.0 tests=BAYES_00, 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 AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6218A28C50 for ; Fri, 11 Aug 2017 16:46:57 +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 1dgD21-0003HT-2U; Fri, 11 Aug 2017 16:43:29 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgD20-0003Gq-2a for xen-devel@lists.xenproject.org; Fri, 11 Aug 2017 16:43:28 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id 54/C4-27137-FAEDD895; Fri, 11 Aug 2017 16:43:27 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrLIsWRWlGSWpSXmKPExsXitHSDve66e72 RBo9umlp83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBmLtq1nKpggV/Hl8gLGBsaZEl2MnBwSAv4S a47tZwex2QR0JC7O3cnWxcjBISKgInF7rwFImFnAV+LHtENsILawQJTErxtnWEBsFgFViU+NF 5lAbF4BS4mex1+YIUbqSbyd+IIRxOYUsJJomvoQzBYCqumdfYUdol5Q4uTMJywQ8zUlWrf/Zo ew5SWat85mhqhXlOif94BtAiPfLCQts5C0zELSsoCReRWjenFqUVlqka6hXlJRZnpGSW5iZo6 uoYGZXm5qcXFiempOYlKxXnJ+7iZGYKAxAMEOxp3PnQ4xSnIwKYnyJvj0RgrxJeWnVGYkFmfE F5XmpBYfYpTh4FCS4O25C5QTLEpNT61Iy8wBhjxMWoKDR0mEdwJImre4IDG3ODMdInWK0Zhjw +r1X5g4Xk34/41JiCUvPy9VSpzXBqRUAKQ0ozQPbhAsFi8xykoJ8zICnSbEU5BalJtZgir/il Gcg1FJmHcGyBSezLwSuH2vgE5hAjqlzwfslJJEhJRUA2OtZkRRu+E/haKQ3C6ViD0q9d/uPUx M5FI9vWjrbtbpf/iCp8+r26kStt5DO01nkZTFjoRfXS9iKx8cmqG3J8TP3mLzJvesKfbW4vp6 cQ90zFk+TWiV+vw9MeP0/JKICRFZrWK/uQ5PFX/dJH5NceNfzaYp1s86JlzJWen34fq0S4xim +a8mKPEUpyRaKjFXFScCADVHghawAIAAA== X-Env-Sender: prvs=389849213=roger.pau@citrix.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1502469805!98991726!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49049 invoked from network); 11 Aug 2017 16:43:26 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 11 Aug 2017 16:43:26 -0000 X-IronPort-AV: E=Sophos;i="5.41,358,1498521600"; d="scan'208";a="443501829" From: Roger Pau Monne To: Date: Fri, 11 Aug 2017 17:43:19 +0100 Message-ID: <20170811164320.92899-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) In-Reply-To: <20170811164320.92899-1-roger.pau@citrix.com> References: <20170811164320.92899-1-roger.pau@citrix.com> MIME-Version: 1.0 Cc: Kevin Tian , Roger Pau Monne Subject: [Xen-devel] [PATCH v2 3/4] x86/vtd: introduce a PVH implementation of iommu_inclusive_mapping 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 On certain Intel systems, as far as I can tell almost all pre-Haswell ones, trying to boot a PVH Dom0 will freeze the box completely, up to the point that not even the watchdog works. The freeze happens exactly when enabling the DMA remapping in the IOMMU, the last line seen is: (XEN) [VT-D]iommu_enable_translation: iommu->reg = ffff82c00021b000 In order to workaround this (which seems to be a lack of proper RMRR entries, plus the IOMMU being unable to generate faults and freezing the entire system) add a PVH specific implementation of iommu_inclusive_mapping, that maps non-RAM, non-unusable regions into Dom0 p2m. Note that care is taken to not map device MMIO regions that Xen is emulating, like the local APIC or the IO APIC. Signed-off-by: Roger Pau Monné --- Cc: Kevin Tian --- xen/drivers/passthrough/vtd/extern.h | 1 + xen/drivers/passthrough/vtd/iommu.c | 2 ++ xen/drivers/passthrough/vtd/x86/vtd.c | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/xen/drivers/passthrough/vtd/extern.h b/xen/drivers/passthrough/vtd/extern.h index fb7edfaef9..0eaf8956ff 100644 --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -100,5 +100,6 @@ bool_t platform_supports_intremap(void); bool_t platform_supports_x2apic(void); void vtd_set_hwdom_mapping(struct domain *d); +void vtd_set_pvh_hwdom_mapping(struct domain *d); #endif // _VTD_EXTERN_H_ diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index daaed0abbd..8ed28defe2 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1303,6 +1303,8 @@ static void __hwdom_init intel_iommu_hwdom_init(struct domain *d) /* Set up 1:1 page table for hardware domain. */ vtd_set_hwdom_mapping(d); } + else if ( is_hvm_domain(d) ) + vtd_set_pvh_hwdom_mapping(d); setup_hwdom_pci_devices(d, setup_hwdom_device); setup_hwdom_rmrr(d); diff --git a/xen/drivers/passthrough/vtd/x86/vtd.c b/xen/drivers/passthrough/vtd/x86/vtd.c index 88a60b3307..79c9b0526f 100644 --- a/xen/drivers/passthrough/vtd/x86/vtd.c +++ b/xen/drivers/passthrough/vtd/x86/vtd.c @@ -21,10 +21,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include "../iommu.h" #include "../dmar.h" @@ -159,3 +161,40 @@ void __hwdom_init vtd_set_hwdom_mapping(struct domain *d) } } +void __hwdom_init vtd_set_pvh_hwdom_mapping(struct domain *d) +{ + unsigned long pfn; + + BUG_ON(!is_hardware_domain(d)); + + if ( !iommu_inclusive_mapping ) + return; + + /* NB: the low 1MB is already mapped in pvh_setup_p2m. */ + for ( pfn = PFN_DOWN(MB(1)); pfn < PFN_DOWN(GB(4)); pfn++ ) + { + p2m_access_t a; + int rc; + + if ( !(pfn & 0xfff) ) + process_pending_softirqs(); + + /* Skip RAM, ACPI and unusable regions. */ + if ( page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL) || + page_is_ram_type(pfn, RAM_TYPE_UNUSABLE) || + page_is_ram_type(pfn, RAM_TYPE_ACPI) || + !iomem_access_permitted(d, pfn, pfn) ) + continue; + + ASSERT(!xen_in_range(pfn)); + + a = rangeset_contains_range(mmio_ro_ranges, pfn, pfn) ? p2m_access_r + : p2m_access_rw; + rc = set_identity_p2m_entry(d, pfn, a, 0); + if ( rc ) + printk(XENLOG_WARNING VTDPREFIX + " d%d: IOMMU mapping failed pfn %#lx: %d\n", + d->domain_id, pfn, rc); + } +} +