[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v5 4/4] iommu: add rmrr Xen command line option for extra rmrrs



From: Elena Ufimtseva <elena.ufimtseva@xxxxxxxxxx>

On some platforms RMRR regions may be not specified
in ACPI and thus will not be mapped 1:1 in dom0. This
causes IO Page Faults and prevents dom0 from booting
in PVH mode.
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.

Mentioned above problems were discovered during 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[,...]]
If grub2 used and multiple ranges are specified, ';' should be
quoted/escaped, refer to grub2 manual for more information.

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@xxxxxxxxxx>
---
 docs/misc/xen-command-line.markdown |  13 ++++
 xen/drivers/passthrough/vtd/dmar.c  | 140 ++++++++++++++++++++++++++++++++++++
 xen/drivers/passthrough/vtd/dmar.h  |  10 +++
 3 files changed, 163 insertions(+)

diff --git a/docs/misc/xen-command-line.markdown 
b/docs/misc/xen-command-line.markdown
index 4889e27..2132863 100644
--- a/docs/misc/xen-command-line.markdown
+++ b/docs/misc/xen-command-line.markdown
@@ -1185,6 +1185,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 RMRRs 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 segement of the first device is not specified, the default 
segment will be used.
+If other segments are not specified, first device segment will be used.
+If segments are specified for every device and not equal, 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
 > `= <boolean>`
 
diff --git a/xen/drivers/passthrough/vtd/dmar.c 
b/xen/drivers/passthrough/vtd/dmar.c
index fa19ba7..ce26026 100644
--- a/xen/drivers/passthrough/vtd/dmar.c
+++ b/xen/drivers/passthrough/vtd/dmar.c
@@ -50,6 +50,7 @@ static LIST_HEAD_READ_MOSTLY(acpi_rhsa_units);
 static struct acpi_table_header *__read_mostly dmar_table;
 static int __read_mostly dmar_flags;
 static u64 __read_mostly igd_drhd_address;
+static void __init add_extra_rmrr(void);
 
 static void __init dmar_scope_add_buses(struct dmar_scope *scope, u16 sec_bus,
                                         u16 sub_bus)
@@ -856,6 +857,78 @@ out:
     return ret;
 }
 
+#define MAX_EXTRA_RMRR_PAGES 16
+#define MAX_EXTRA_RMRR 10
+static __initdata unsigned int nr_rmrr;
+static struct __initdata extra_rmrr_unit rmrru[MAX_EXTRA_RMRR];
+
+static void __init add_extra_rmrr(void)
+{
+    struct acpi_rmrr_unit *rmrrn;
+    unsigned int dev, seg, addr;
+
+    for (unsigned int i = 0; i < nr_rmrr; i++ )
+    {
+        rmrrn = xmalloc(struct acpi_rmrr_unit);
+        if ( !rmrrn )
+            return;
+
+        rmrrn->scope.devices = xmalloc_array(typeof(*rmrrn->scope.devices),
+                                             rmrru[i].dev_count);
+        if ( !rmrrn->scope.devices )
+        {
+            xfree(rmrrn);
+            return;
+        }
+
+        if ( rmrru[i].end_address - rmrru[i].base_address > 
MAX_EXTRA_RMRR_PAGES )
+        {
+            printk(XENLOG_ERR VTDPREFIX
+                   "RMRR range exceeds 16 pages [%"PRIx64" - %"PRIx64"]\n",
+                   rmrru[i].base_address, rmrru[i].end_address);
+            xfree(rmrrn->scope.devices);
+            xfree(rmrrn);
+            return;
+        }
+
+        for ( addr = rmrru[i].base_address; addr <= rmrru[i].end_address; 
addr++ )
+        {
+            if ( iommu_verbose )
+                printk(XENLOG_ERR VTDPREFIX
+                       "Invalid mfn in RMRR range [%"PRIx64" - %"PRIx64"]\n",
+                       rmrru[i].base_address, rmrru[i].end_address);
+            xfree(rmrrn->scope.devices);
+            xfree(rmrrn);
+            return;
+        }
+
+        seg = 0;
+        for ( dev = 0; dev < rmrru->dev_count; dev++ )
+        {
+            rmrrn->scope.devices[dev] = rmrru->sbdf[dev];
+            seg = seg | (rmrru->sbdf[dev] >> 16);
+        }
+        if ( seg != (rmrru->sbdf[0] >> 16) )
+        {
+            printk(XENLOG_ERR VTDPREFIX
+                   "Segments are not equal for RMRR range  [%"PRIx64" - 
%"PRIx64"]\n",
+                   rmrru->base_address, rmrru->end_address);
+            xfree(rmrrn->scope.devices);
+            xfree(rmrrn);
+            continue;
+        }
+        rmrrn->segment = seg;
+        rmrrn->base_address = rmrru[i].base_address << PAGE_SHIFT;
+        rmrrn->end_address = (rmrru[i].end_address + 1) << PAGE_SHIFT;
+        rmrrn->scope.devices_cnt = rmrru[i].dev_count;
+
+        if ( register_one_rmrr(rmrrn) )
+            printk(XENLOG_ERR VTDPREFIX
+                   "Could not register RMMR range  [%"PRIx64" - %"PRIx64"]\n",
+                   rmrru[i].base_address, rmrru[i].end_address);
+    }
+}
+
 #include <asm/tboot.h>
 /* ACPI tables may not be DMA protected by tboot, so use DMAR copy */
 /* SINIT saved in SinitMleData in TXT heap (which is DMA protected) */
@@ -874,6 +947,7 @@ int __init acpi_dmar_init(void)
                          PAGE_HYPERVISOR);
         dmar_table = __va(dmar_addr);
     }
+    add_extra_rmrr();
 
     return parse_dmar_table(acpi_parse_dmar);
 }
@@ -906,3 +980,69 @@ int platform_supports_x2apic(void)
     unsigned int mask = ACPI_DMAR_INTR_REMAP | ACPI_DMAR_X2APIC_OPT_OUT;
     return cpu_has_x2apic && ((dmar_flags & mask) == ACPI_DMAR_INTR_REMAP);
 }
+
+/*
+ * Parse rmrr Xen command line options and add parsed
+ * device and region into apci_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 segement of the first device is not specified, the default segment will 
be used.
+ * If other segments are not specified, first device segment will be used.
+ * If segments are specified for every device and not equal, 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;
+    int default_segment = 0;
+    u64 start, end;
+
+    do {
+        start = simple_strtoull(cur = s, &s, 0);
+        if ( cur == s )
+            break;
+
+        if ( *s == '-' )
+        {
+            end = simple_strtoull(cur = s + 1, &s, 0);
+            if ( cur == s )
+                break;
+        }
+        else
+            end = start;
+        if ( nr_rmrr < MAX_EXTRA_RMRR )
+        {
+            rmrru[nr_rmrr].base_address = start;
+            rmrru[nr_rmrr].end_address = end;
+            rmrru[nr_rmrr].dev_count = 0;
+        }
+        else
+            break;
+
+        if ( *s != '=' )
+            continue;
+
+        do {
+            if ( rmrru[nr_rmrr].dev_count >= MAX_EXTRA_RMRR_DEV )
+                break;
+            if ( *s == ';' )
+                break;
+            stmp = __parse_pci(s + 1, &seg, &bus, &dev, &func, 
&default_segment);
+            if ( !stmp )
+                break;
+            /* Not specified segment will be replaced with one from first 
device. */
+            if ( rmrru[nr_rmrr].dev_count > 0 && (seg != 
(rmrru[nr_rmrr].sbdf[0] >> 16)) )
+                if ( default_segment )
+                    seg = rmrru[nr_rmrr].sbdf[0] >> 16;
+            /* Keep sbdf's even if they differ and later report error. */
+            rmrru[nr_rmrr].sbdf[rmrru[nr_rmrr].dev_count] = PCI_SBDF(seg, bus, 
dev, func);
+            rmrru[nr_rmrr].dev_count++;
+            s = stmp;
+        } while ( *s == ',' || *s || !s );
+
+        if ( rmrru[nr_rmrr].dev_count )
+            nr_rmrr++;
+    } while ( *s++ == ';' );
+}
+custom_param("rmrr", parse_rmrr_param);
diff --git a/xen/drivers/passthrough/vtd/dmar.h 
b/xen/drivers/passthrough/vtd/dmar.h
index af1feef..edc9602 100644
--- a/xen/drivers/passthrough/vtd/dmar.h
+++ b/xen/drivers/passthrough/vtd/dmar.h
@@ -132,4 +132,14 @@ void disable_pmr(struct iommu *iommu);
 int is_usb_device(u16 seg, u8 bus, u8 devfn);
 int is_igd_drhd(struct acpi_drhd_unit *drhd);
 
+/* RMRR units derived from command line rmrr option */
+#define MAX_EXTRA_RMRR_DEV 20
+struct extra_rmrr_unit {
+    struct list_head list;
+    u64    base_address;
+    u64    end_address;
+    u16    dev_count;
+    u32    sbdf[MAX_EXTRA_RMRR_DEV];
+};
+
 #endif /* _DMAR_H_ */
-- 
2.1.3


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.