From patchwork Mon Jan 23 18:20:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venu Busireddy X-Patchwork-Id: 9533319 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 2478960434 for ; Mon, 23 Jan 2017 18:23:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1567F28365 for ; Mon, 23 Jan 2017 18:23:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A1A528442; Mon, 23 Jan 2017 18:23:49 +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, UNPARSEABLE_RELAY 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 E079A28365 for ; Mon, 23 Jan 2017 18:23:47 +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 1cVjFQ-0007J3-8f; Mon, 23 Jan 2017 18:21:44 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cVjFP-0007Hl-2g for xen-devel@lists.xen.org; Mon, 23 Jan 2017 18:21:43 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id 61/A7-25093-6B946885; Mon, 23 Jan 2017 18:21:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42KZM10+UHerZ1u EwbSdehZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a0728YC84FVly/MI+5gXG9dRcjF4eQwEQm iW9Hl7NCOL8ZJZYteMoM4WxglDi89zUbhNPJKHFo1mfGLkZODjYBA4mjh3tYQWwRATOJqW37W ECKmAVuMkr0vj7IDpIQFgiQ+PR1GpjNIqAqcfBML1gDr4CHxN+V65hBbAkBOYmb5zqBbA4OTg FPiWktiiBhIaCS7UvOMEGUGEqcfriNcQIj3wJGhlWMGsWpRWWpRbpGlnpJRZnpGSW5iZk5uoY GZnq5qcXFiempOYlJxXrJ+bmbGIHBwgAEOxgPLAo8xCjJwaQkynsjviVCiC8pP6UyI7E4I76o NCe1+BCjDAeHkgRvu0dbhJBgUWp6akVaZg4wbGHSEhw8SiK8ViBp3uKCxNzizHSI1ClGY45TN 06/ZOL4svPMSyYhlrz8vFQpcV43kFIBkNKM0jy4QbB4usQoKyXMywh0mhBPQWpRbmYJqvwrRn EORiVh3mCQKTyZeSVw+14BncIEdIqsRDPIKSWJCCmpBsaDx3+/k7FcKBDnm2HA/evc3UWNK3x 0NDlezCmfUnBxjcAnvRzN9gQ1xv8rDrfNETRYvHNFV6Gho+jJhoU3vj6SEZtv4S54RJqvK5Z5 /6SLfIcW+Zyfc/i7/qX9SRKZX068/q2eIXRX+dxj1VvsTivkntw6ol7ZyXduUuCM0skWTtfnc DfUqy5SYinOSDTUYi4qTgQAGY2xl6ICAAA= X-Env-Sender: venu.busireddy@oracle.com X-Msg-Ref: server-5.tower-27.messagelabs.com!1485195700!77835438!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46193 invoked from network); 23 Jan 2017 18:21:41 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-5.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Jan 2017 18:21:41 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v0NILZW9031355 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Jan 2017 18:21:35 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v0NILZC5000646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Jan 2017 18:21:35 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v0NILYP6014313; Mon, 23 Jan 2017 18:21:34 GMT Received: from lenovo.localdomain (/24.55.20.143) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 23 Jan 2017 10:21:34 -0800 From: Venu Busireddy To: venu.busireddy@oracle.com, xen-devel@lists.xen.org Date: Mon, 23 Jan 2017 12:20:39 -0600 Message-Id: <1485195639-1996-4-git-send-email-venu.busireddy@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485195639-1996-1-git-send-email-venu.busireddy@oracle.com> References: <1485195639-1996-1-git-send-email-venu.busireddy@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: Elena Ufimtseva , Kevin Tian , Feng Wu , Jan Beulich Subject: [Xen-devel] [PATCH v14 3/3] iommu: add rmrr Xen command line option for extra rmrrs 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On some platforms firmware fails to specify RMRR regions in ACPI tables and thus those regions will not be mapped in dom0 or guests and may cause IO Page Faults and prevent dom0 from booting if "iommu=dom0-strict" option is specified on the Xen command line. New Xen command line option rmrr allows to specify such devices and memory regions. These regions are added to the list of RMRR defined in ACPI if the device is present in system. As a result, additional RMRRs will be mapped 1:1 in dom0 with correct permissions. The above mentioned problems were discovered during the PVH work with ThinkCentre M and Dell 5600T. No official documentation was found so far in regards to what devices and why cause this. Experiments show that ThinkCentre M USB devices with enabled debug port generate DMA read transactions to the regions of memory marked reserved in host e820 map. For Dell 5600T the device and faulting addresses are not found yet. For detailed history of the discussion please check following threads: http://lists.Xen.org/archives/html/xen-devel/2015-02/msg01724.html http://lists.Xen.org/archives/html/xen-devel/2015-01/msg02513.html Format for rmrr Xen command line option: rmrr=start<-end>=[s1]bdf1[,[s1]bdf2[,...]];start<-end>=[s2]bdf1[,[s2]bdf2[,...]] For example, for Lenovo ThinkCentre M, use: rmrr=0xd5d45=0:0:1d.0;0xd5d46=0:0:1a.0 If grub2 used and multiple ranges are specified, ';' should be quoted/escaped, refer to grub2 manual for more information. Signed-off-by: Elena Ufimtseva Signed-off-by: Venu Busireddy Acked-by: Kevin Tian Reviewed-by: Jan Beulich Acked-by: Kevin Tian --- docs/misc/xen-command-line.markdown | 13 +++ xen/drivers/passthrough/vtd/dmar.c | 203 +++++++++++++++++++++++++++++++++++- 2 files changed, 215 insertions(+), 1 deletion(-) Changes in v14: - Implement Jan's feedback. Rename some #defines and take care of boundary conditions. diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-command-line.markdown index 0138978..a11fdf9 100644 --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -1377,6 +1377,19 @@ Specify the host reboot method. 'efi' instructs Xen to reboot using the EFI reboot call (in EFI mode by default it will use that method first). +### rmrr +> '= start<-end>=[s1]bdf1[,[s1]bdf2[,...]];start<-end>=[s2]bdf1[,[s2]bdf2[,...]] + +Define RMRR units that are missing from ACPI table along with device they +belong to and use them for 1:1 mapping. End addresses can be omitted and one +page will be mapped. The ranges are inclusive when start and end are specified. +If segment of the first device is not specified, segment zero will be used. +If other segments are not specified, first device segment will be used. +If a segment is specified for other than the first device and it does not match +the one specified for the first one, an error will be reported. +Note: grub2 requires to escape or use quotations if special characters are used, +namely ';', refer to the grub2 documentation if multiple ranges are specified. + ### ro-hpet > `= ` diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c index 3c7c9b2..7c12b17 100644 --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -859,6 +859,134 @@ out: return ret; } +#define MAX_USER_RMRR_PAGES 16 +#define MAX_USER_RMRR 10 + +/* RMRR units derived from command line rmrr option. */ +#define MAX_USER_RMRR_DEV 20 +struct user_rmrr { + struct list_head list; + unsigned long base_pfn, end_pfn; + unsigned int dev_count; + u32 sbdf[MAX_USER_RMRR_DEV]; +}; + +static __initdata unsigned int nr_rmrr; +static struct __initdata user_rmrr user_rmrrs[MAX_USER_RMRR]; + +/* Macro for RMRR inclusive range formatting. */ +#define ERMRRU_FMT "[%lx-%lx]" +#define ERMRRU_ARG(eru) eru.base_pfn, eru.end_pfn + +static int __init add_user_rmrr(void) +{ + struct acpi_rmrr_unit *rmrr, *rmrru; + unsigned int idx, seg, i; + unsigned long base, end; + bool overlap; + + for ( i = 0; i < nr_rmrr; i++ ) + { + base = user_rmrrs[i].base_pfn; + end = user_rmrrs[i].end_pfn; + + if ( base > end ) + { + printk(XENLOG_ERR VTDPREFIX + "Invalid RMRR Range "ERMRRU_FMT"\n", + ERMRRU_ARG(user_rmrrs[i])); + continue; + } + + if ( (end - base) >= MAX_USER_RMRR_PAGES ) + { + printk(XENLOG_ERR VTDPREFIX + "RMRR range "ERMRRU_FMT" exceeds "\ + __stringify(MAX_USER_RMRR_PAGES)" pages\n", + ERMRRU_ARG(user_rmrrs[i])); + continue; + } + + overlap = false; + list_for_each_entry(rmrru, &acpi_rmrr_units, list) + { + if ( pfn_to_paddr(base) <= rmrru->end_address && + rmrru->base_address <= pfn_to_paddr(end) ) + { + printk(XENLOG_ERR VTDPREFIX + "Overlapping RMRRs: "ERMRRU_FMT" and [%lx-%lx]\n", + ERMRRU_ARG(user_rmrrs[i]), + paddr_to_pfn(rmrru->base_address), + paddr_to_pfn(rmrru->end_address)); + overlap = true; + break; + } + } + /* Don't add overlapping RMRR. */ + if ( overlap ) + continue; + + do + { + if ( !mfn_valid(base) ) + { + printk(XENLOG_ERR VTDPREFIX + "Invalid pfn in RMRR range "ERMRRU_FMT"\n", + ERMRRU_ARG(user_rmrrs[i])); + break; + } + } while ( base++ < end ); + + /* Invalid pfn in range as the loop ended before end_pfn was reached. */ + if ( base <= end ) + continue; + + rmrr = xzalloc(struct acpi_rmrr_unit); + if ( !rmrr ) + return -ENOMEM; + + rmrr->scope.devices = xmalloc_array(u16, user_rmrrs[i].dev_count); + if ( !rmrr->scope.devices ) + { + xfree(rmrr); + return -ENOMEM; + } + + seg = 0; + for ( idx = 0; idx < user_rmrrs[i].dev_count; idx++ ) + { + rmrr->scope.devices[idx] = user_rmrrs[i].sbdf[idx]; + seg |= PCI_SEG(user_rmrrs[i].sbdf[idx]); + } + if ( seg != PCI_SEG(user_rmrrs[i].sbdf[0]) ) + { + printk(XENLOG_ERR VTDPREFIX + "Segments are not equal for RMRR range "ERMRRU_FMT"\n", + ERMRRU_ARG(user_rmrrs[i])); + scope_devices_free(&rmrr->scope); + xfree(rmrr); + continue; + } + + rmrr->segment = seg; + rmrr->base_address = pfn_to_paddr(user_rmrrs[i].base_pfn); + /* Align the end_address to the end of the page */ + rmrr->end_address = pfn_to_paddr(user_rmrrs[i].end_pfn) | ~PAGE_MASK_4K; + rmrr->scope.devices_cnt = user_rmrrs[i].dev_count; + + if ( register_one_rmrr(rmrr) ) + { + printk(XENLOG_ERR VTDPREFIX + "Could not register RMMR range "ERMRRU_FMT"\n", + ERMRRU_ARG(user_rmrrs[i])); + scope_devices_free(&rmrr->scope); + xfree(rmrr); + } + } + + return 0; +} + #include /* ACPI tables may not be DMA protected by tboot, so use DMAR copy */ /* SINIT saved in SinitMleData in TXT heap (which is DMA protected) */ @@ -868,6 +996,7 @@ int __init acpi_dmar_init(void) { acpi_physical_address dmar_addr; acpi_native_uint dmar_len; + int ret; if ( ACPI_SUCCESS(acpi_get_table_phys(ACPI_SIG_DMAR, 0, &dmar_addr, &dmar_len)) ) @@ -878,7 +1007,12 @@ int __init acpi_dmar_init(void) dmar_table = __va(dmar_addr); } - return parse_dmar_table(acpi_parse_dmar); + ret = parse_dmar_table(acpi_parse_dmar); + + if ( !ret ) + return add_user_rmrr(); + + return ret; } void acpi_dmar_reinstate(void) @@ -937,3 +1071,70 @@ int intel_iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt) return 0; } + +/* + * Parse rmrr Xen command line options and add parsed devices and regions into + * acpi_rmrr_unit list to mapped as RMRRs parsed from ACPI. + * Format: + * rmrr=start<-end>=[s1]bdf1[,[s1]bdf2[,...]];start<-end>=[s2]bdf1[,[s2]bdf2[,...]] + * If the segment of the first device is not specified, + * segment zero will be used. + * If other segments are not specified, first device segment will be used. + * If a segment is specified for other than the first device, and it does not + * match the one specified for the first one, an error will be reported. + */ +static void __init parse_rmrr_param(const char *str) +{ + const char *s = str, *cur, *stmp; + unsigned int seg, bus, dev, func, dev_count; + unsigned long start, end; + + do { + start = simple_strtoul(cur = s, &s, 0); + if ( cur == s ) + break; + + if ( *s == '-' ) + { + end = simple_strtoul(cur = s + 1, &s, 0); + if ( cur == s ) + break; + } + else + end = start; + + user_rmrrs[nr_rmrr].base_pfn = start; + user_rmrrs[nr_rmrr].end_pfn = end; + + if ( *s != '=' ) + continue; + + do { + bool def_seg = false; + + stmp = parse_pci_seg(s + 1, &seg, &bus, &dev, &func, &def_seg); + if ( !stmp ) + break; + + /* + * Not specified. + * Segment will be replaced with one from first device. + */ + if ( user_rmrrs[nr_rmrr].dev_count && def_seg ) + seg = PCI_SEG(user_rmrrs[nr_rmrr].sbdf[0]); + + /* Keep sbdf's even if they differ and later report an error. */ + dev_count = user_rmrrs[nr_rmrr].dev_count; + user_rmrrs[nr_rmrr].sbdf[dev_count] = PCI_SBDF(seg, bus, dev, func); + + user_rmrrs[nr_rmrr].dev_count++; + s = stmp; + } while ( *s == ',' && + user_rmrrs[nr_rmrr].dev_count < MAX_USER_RMRR_DEV ); + + if ( user_rmrrs[nr_rmrr].dev_count ) + nr_rmrr++; + + } while ( *s++ == ';' && nr_rmrr < MAX_USER_RMRR ); +} +custom_param("rmrr", parse_rmrr_param);