Skip to contentSkip to conversation

iommu: add rmrr Xen command line option

PATCH Superseded [email protected] 2 participants 7 messages Jun 2, 2015 – Jun 5, 2015

v7 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v7 cover iommu: add rmrr Xen command line option

From: Elena Ufimtseva <[email protected]>

v7 of rmrr comman line patches.
Thank you for comments on v6.

Add Xen command line option rmrr to specify RMRR regions for devices that are not defined in ACPI thus causing IO Page Fault while booting dom0 in PVH mode. These additional regions will be added to the list of RMRR regions parsed from ACPI.

Changes in v7:
- make sure RMRRs ranges are being checked correctly;
- dont interrupt RMRRs checking if some of checks fails, instead continue to next RMRR;
- make rmrr variable names more obvious;
- fix debug output formatting to match type of rmrr range;
- fix typos in rmrr command line document and in comments;

Changes in v6:
- make __parse_pci return correct result and error codes;
- move add_extra_rmrr
- previous patch was missing RMRR addresses in range check, add it here;
- add overlap check and range boundaries check;
- moved extra rmrr structure definition to dmar.c;
- change def_seg in __parse_pci type from int to bool_t;
- change name for extra rmrr range to reflect they hold now pfns;

Changes in v5:
- make parse_pci a wrapper and add __parse_pci with additional def_seg param to identify if segment was specified;
- make possible not to define segment for each device within same rmrr;
- limit number of pages for one RMRR by 16;
- run mfn_valid check for every address in RMRR range;
- add PCI_SBDF macro;
- remove list for extra rmrrs as they are kept in static array;

Changes in v4 after comments by Jan Beulich:
- keep sbdf per device instead of bdf and one segment per RMRR when parsing and compare later;
- add check for segment values and make sure they are same for one RMRR;
- move RMRR parameters checks and add error messages if RMRRs are incorrect;
- make relevant variables and functions static;
- mention requirement for segment values in rmrr documentation;

Changes in v3:
- use ';' instead of '#' in command line and add proper notes for grub ';' special treatment;

Changes in v2:
- move rmrr parser to dmar.c and make it custom_param;
- change of rmrr command line oprion format; since adding multiple device per range support needs to utilize more special characters and offered from the previous review ';' is not supported, '[' ']' are reserved, ':' and used in pci format, range and devices are separated by '#'; Suggestions are welcome;
- added support for multiple devices per range;
- moved adding misc RMRRs before ACPI RMRR parsing;
- make parser fail if pci device is specified incorrectly;

Elena Ufimtseva (4):
pci: add PCI_SBDF and PCI_SEG macros
iommu VT-d: separate rmrr addition function
pci: add wrapper for parse_pci
iommu: add rmrr Xen command line option for extra rmrrs

 docs/misc/xen-command-line.markdown |  12 ++
 xen/drivers/passthrough/vtd/dmar.c  | 313 +++++++++++++++++++++++++++++-------
 xen/drivers/pci/pci.c               |  11 ++
 xen/include/xen/pci.h               |   5 +
 4 files changed, 279 insertions(+), 62 deletions(-)
Signature · 1 line
2.1.3
#1 lore raw

PATCH v7 1/4 pci: add PCI_SBDF and PCI_SEG macros

From: Elena Ufimtseva <[email protected]>

---
 xen/include/xen/pci.h | 2 ++
 1 file changed, 2 insertions(+)
xen/include/xen/pci.h +2 -0
index 3908146..414106a 100644
@@ -33,6 +33,8 @@
 #define PCI_DEVFN2(bdf) ((bdf) & 0xff)
 #define PCI_BDF(b,d,f)  ((((b) & 0xff) << 8) | PCI_DEVFN(d,f))
 #define PCI_BDF2(b,df)  ((((b) & 0xff) << 8) | ((df) & 0xff))
+#define PCI_SBDF(s,b,d,f) ((((s) & 0xffff) << 16) | PCI_BDF(b,d,f))
+#define PCI_SEG(sbdf) (((sbdf) >> 16) & 0xffff)
 
 struct pci_dev_info {
     bool_t is_extfn;
Signature · 1 line
2.1.3
#2 lore raw

PATCH v7 2/4 iommu VT-d: separate rmrr addition function

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

In preparation for auxiliary RMRR data provided on Xen command line, make RMRR adding a separate function. Also free memery for rmrr device scope in error path.

---
 xen/drivers/passthrough/vtd/dmar.c | 130 ++++++++++++++++++++-----------------
 1 file changed, 69 insertions(+), 61 deletions(-)
xen/drivers/passthrough/vtd/dmar.c +69 -61
index a675bf7..5d78a37 100644
@@ -581,6 +581,72 @@ out:
     return ret;
 }
 
+static int register_one_rmrr(struct acpi_rmrr_unit *rmrru)
+{
+    bool_t ignore = 0;
+    unsigned int i = 0;
+    int ret = 0;
+
+    /* Skip checking if segment is not accessible yet. */
+    if ( !pci_known_segment(rmrru->segment) )
+    {
+        dprintk(XENLOG_WARNING VTDPREFIX, "UNKNOWN Prefix! %04x", rmrru->segment);
+        i = UINT_MAX;
+    }
+
+    for ( ; i < rmrru->scope.devices_cnt; i++ )
+    {
+        u8 b = PCI_BUS(rmrru->scope.devices[i]);
+        u8 d = PCI_SLOT(rmrru->scope.devices[i]);
+        u8 f = PCI_FUNC(rmrru->scope.devices[i]);
+
+        if ( pci_device_detect(rmrru->segment, b, d, f) == 0 )
+        {
+            dprintk(XENLOG_WARNING VTDPREFIX,
+                    " Non-existent device (%04x:%02x:%02x.%u) is reported"
+                    " in RMRR (%"PRIx64", %"PRIx64")'s scope!\n",
+                    rmrru->segment, b, d, f,
+                    rmrru->base_address, rmrru->end_address);
+            ignore = 1;
+        }
+        else
+        {
+            ignore = 0;
+            break;
+        }
+    }
+
+    if ( ignore )
+    {
+        dprintk(XENLOG_WARNING VTDPREFIX,
+            "  Ignore the RMRR (%"PRIx64", %"PRIx64") due to "
+            "devices under its scope are not PCI discoverable!\n",
+            rmrru->base_address, rmrru->end_address);
+        scope_devices_free(&rmrru->scope);
+        xfree(rmrru);
+    }
+    else if ( rmrru->base_address > rmrru->end_address )
+    {
+        dprintk(XENLOG_WARNING VTDPREFIX,
+            "  The RMRR (%"PRIx64", %"PRIx64") is incorrect!\n",
+            rmrru->base_address, rmrru->end_address);
+        scope_devices_free(&rmrru->scope);
+        xfree(rmrru);
+        ret = -EFAULT;
+    }
+    else
+    {
+        if ( iommu_verbose )
+            dprintk(VTDPREFIX,
+                    "  RMRR region: base_addr %"PRIx64
+                    " end_address %"PRIx64"\n",
+                    rmrru->base_address, rmrru->end_address);
+        acpi_register_rmrr_unit(rmrru);
+    }
+
+    return ret;
+}
+
 static int __init
 acpi_parse_one_rmrr(struct acpi_dmar_header *header)
 {
@@ -631,68 +697,10 @@ acpi_parse_one_rmrr(struct acpi_dmar_header *header)
     ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
                                &rmrru->scope, RMRR_TYPE, rmrr->segment);
 
-    if ( ret || (rmrru->scope.devices_cnt == 0) )
-        xfree(rmrru);
+    if ( !ret && (rmrru->scope.devices_cnt != 0) )
+        register_one_rmrr(rmrru);
     else
-    {
-        u8 b, d, f;
-        bool_t ignore = 0;
-        unsigned int i = 0;
-
-        /* Skip checking if segment is not accessible yet. */
-        if ( !pci_known_segment(rmrr->segment) )
-            i = UINT_MAX;
-
-        for ( ; i < rmrru->scope.devices_cnt; i++ )
-        {
-            b = PCI_BUS(rmrru->scope.devices[i]);
-            d = PCI_SLOT(rmrru->scope.devices[i]);
-            f = PCI_FUNC(rmrru->scope.devices[i]);
-
-            if ( !pci_device_detect(rmrr->segment, b, d, f) )
-            {
-                dprintk(XENLOG_WARNING VTDPREFIX,
-                        " Non-existent device (%04x:%02x:%02x.%u) is reported"
-                        " in RMRR (%"PRIx64", %"PRIx64")'s scope!\n",
-                        rmrr->segment, b, d, f,
-                        rmrru->base_address, rmrru->end_address);
-                ignore = 1;
-            }
-            else
-            {
-                ignore = 0;
-                break;
-            }
-        }
-
-        if ( ignore )
-        {
-            dprintk(XENLOG_WARNING VTDPREFIX,
-                "  Ignore the RMRR (%"PRIx64", %"PRIx64") due to "
-                "devices under its scope are not PCI discoverable!\n",
-                rmrru->base_address, rmrru->end_address);
-            scope_devices_free(&rmrru->scope);
-            xfree(rmrru);
-        }
-        else if ( base_addr > end_addr )
-        {
-            dprintk(XENLOG_WARNING VTDPREFIX,
-                "  The RMRR (%"PRIx64", %"PRIx64") is incorrect!\n",
-                rmrru->base_address, rmrru->end_address);
-            scope_devices_free(&rmrru->scope);
-            xfree(rmrru);
-            ret = -EFAULT;
-        }
-        else
-        {
-            if ( iommu_verbose )
-                dprintk(VTDPREFIX,
-                        "  RMRR region: base_addr %"PRIx64
-                        " end_address %"PRIx64"\n",
-                        rmrru->base_address, rmrru->end_address);
-            acpi_register_rmrr_unit(rmrru);
-        }
-    }
+        xfree(rmrru);
 
     return ret;
 }
Signature · 1 line
2.1.3
#3 lore raw

Re: [PATCH v7 2/4] iommu VT-d: separate rmrr addition function

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 02.06.15 at 23:14, <[email protected]> wrote:
xen/drivers/passthrough/vtd/dmar.c +0 -0
@@ -581,6 +581,72 @@ out:
     return ret;
 }
 

xen/drivers/passthrough/vtd/dmar.c out: · line 593

Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +10 -0
+static int register_one_rmrr(struct acpi_rmrr_unit *rmrru)
+{
+    bool_t ignore = 0;
+    unsigned int i = 0;
+    int ret = 0;
+
+    /* Skip checking if segment is not accessible yet. */
+    if ( !pci_known_segment(rmrru->segment) )
+    {
+        dprintk(XENLOG_WARNING VTDPREFIX, "UNKNOWN Prefix! %04x", rmrru->segment);

Apart from lacking a newline character, this has no counterpart in the original code, and I don't think the message text comes even close to describe what the issue is. May I please ask you once again that in patches that are intended to be only code movement you either clearly spell out what other changes you make, or that you omit any such changes (other than possible formatting cleanup) in the first place?

Quoted 4 lines
xen/drivers/passthrough/vtd/dmar.c +4 -0
+        i = UINT_MAX;
+    }
+
+    for ( ; i < rmrru->scope.devices_cnt; i++ )

xen/drivers/passthrough/vtd/dmar.c out: · line 607

Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +10 -0
+    {
+        u8 b = PCI_BUS(rmrru->scope.devices[i]);
+        u8 d = PCI_SLOT(rmrru->scope.devices[i]);
+        u8 f = PCI_FUNC(rmrru->scope.devices[i]);
+
+        if ( pci_device_detect(rmrru->segment, b, d, f) == 0 )
+        {
+            dprintk(XENLOG_WARNING VTDPREFIX,
+                    " Non-existent device (%04x:%02x:%02x.%u) is reported"
+                    " in RMRR (%"PRIx64", %"PRIx64")'s scope!\n",

An acceptable no-functional-change adjustment would e.g. be to un-line-break format strings (this one's particularly long so it may remain as is, but there are shorter ones below) to ease grep-ing for them based on observed log contents.

xen/drivers/passthrough/vtd/dmar.c out: · line 632

Quoted 5 lines
xen/drivers/passthrough/vtd/dmar.c +5 -0
+    else if ( rmrru->base_address > rmrru->end_address )
+    {
+        dprintk(XENLOG_WARNING VTDPREFIX,
+            "  The RMRR (%"PRIx64", %"PRIx64") is incorrect!\n",
+            rmrru->base_address, rmrru->end_address);

Indentation.

Jan

#4 lore raw

PATCH v7 3/4 pci: add wrapper for parse_pci

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

For sbdf'si parsing in rmrr command line add __parse_pci with addtional parameter def_seg. __parse_pci will help to identify if segment was found
in string being parsed or default segment was used.
Make a wrapper parse_pci so the rest of the callers are not affected.

---
 xen/drivers/pci/pci.c | 11 +++++++++++
 xen/include/xen/pci.h |  3 +++
 2 files changed, 14 insertions(+)
xen/drivers/pci/pci.c +11 -0
index ca07ed0..788a356 100644
@@ -119,11 +119,21 @@ const char *__init parse_pci(const char *s, unsigned int *seg_p,
                              unsigned int *bus_p, unsigned int *dev_p,
                              unsigned int *func_p)
 {
+    bool_t def_seg;
+
+    return __parse_pci(s, seg_p, bus_p, dev_p, func_p, &def_seg);
+}
+
+const char *__init __parse_pci(const char *s, unsigned int *seg_p,
+                             unsigned int *bus_p, unsigned int *dev_p,
+                             unsigned int *func_p, bool_t *def_seg)
+{
     unsigned long seg = simple_strtoul(s, &s, 16), bus, dev, func;
 
     if ( *s != ':' )
         return NULL;
     bus = simple_strtoul(s + 1, &s, 16);
+    *def_seg = 0;
     if ( *s == ':' )
         dev = simple_strtoul(s + 1, &s, 16);
     else
@@ -131,6 +141,7 @@ const char *__init parse_pci(const char *s, unsigned int *seg_p,
         dev = bus;
         bus = seg;
         seg = 0;
+        *def_seg = 1;
     }
     if ( func_p )
     {
xen/include/xen/pci.h +3 -0
index 414106a..d66ecab 100644
@@ -150,6 +150,9 @@ int pci_find_ext_capability(int seg, int bus, int devfn, int cap);
 int pci_find_next_ext_capability(int seg, int bus, int devfn, int pos, int cap);
 const char *parse_pci(const char *, unsigned int *seg, unsigned int *bus,
                       unsigned int *dev, unsigned int *func);
+const char *__parse_pci(const char *, unsigned int *seg, unsigned int *bus,
+                      unsigned int *dev, unsigned int *func, bool_t *def_seg);
+
 
 bool_t pcie_aer_get_firmware_first(const struct pci_dev *);
 
Signature · 1 line
2.1.3
#5 lore raw

PATCH v7 4/4 iommu: add rmrr Xen command line option for extra rmrrs

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

From: Elena Ufimtseva <[email protected]>

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.

---
 docs/misc/xen-command-line.markdown |  12 +++
 xen/drivers/passthrough/vtd/dmar.c  | 183 +++++++++++++++++++++++++++++++++++-
 2 files changed, 194 insertions(+), 1 deletion(-)
docs/misc/xen-command-line.markdown +12 -0
index 4889e27..d2f0668 100644
@@ -1185,6 +1185,18 @@ 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 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 segments are specified for every device and not equal, 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
 > `= <boolean>`
 
xen/drivers/passthrough/vtd/dmar.c +182 -1

204 lines not on this page · raw message

Signature · 1 line
2.1.3
#6 lore raw

Re: [PATCH v7 4/4] iommu: add rmrr Xen command line option for extra rmrrs

docs/misc/xen-command-line.markdown Specify the host reboot method. · line 1191

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 02.06.15 at 23:14, <[email protected]> wrote:
docs/misc/xen-command-line.markdown +4 -0
@@ -1185,6 +1185,18 @@ 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

"RMRR units" or "RMRRs"

docs/misc/xen-command-line.markdown Specify the host reboot method. · line 1196

Quoted 5 lines
docs/misc/xen-command-line.markdown +5 -0
+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 segments are specified for every device and not equal, an error will be reported.

This isn't precise enough: "If a segment is specified for other than the first device and it doesn't match that specified for the first one, ..."

Quoted 5 lines
xen/drivers/passthrough/vtd/dmar.c +0 -0
@@ -869,6 +869,120 @@ out:
     return ret;
 }

xen/drivers/passthrough/vtd/dmar.c out: · line 880

Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +9 -0
 
+#define MAX_EXTRA_RMRR_PAGES 16
+#define MAX_EXTRA_RMRR 10
+
+/* RMRR units derived from command line rmrr option */
+#define MAX_EXTRA_RMRR_DEV 20
+struct extra_rmrr_unit {
+    struct list_head list;
+    unsigned long base_pfn, end_pfn;
+    u16    dev_count;

Pointless (afaict) use of fixed width type - use "unsigned int" instead.

xen/drivers/passthrough/vtd/dmar.c out: · line 886

Quoted 6 lines
xen/drivers/passthrough/vtd/dmar.c +6 -0
+    u32    sbdf[MAX_EXTRA_RMRR_DEV];
+};
+static __initdata unsigned int nr_rmrr;
+static struct __initdata extra_rmrr_unit extra_rmrr_units[MAX_EXTRA_RMRR];
+
+#define PRI_RMRRL "[%lx - %lx]"

If you do this, then you also want a macro for the paired arguments. Otherwise the number of format specifiers and the number of value to be formatted will appear to disagree to the reader.

Further please use usual mathematical range representation, i.e. [x,y] for inclusive ranges and [x,y) for ranges inclusive at the beginning, but not inclusive at their end. And avoid spaces here, they're not really helpful but eat serial line bandwidth.

Also, what's the L standing for?

xen/drivers/passthrough/vtd/dmar.c out: · line 899

Quoted 13 lines
xen/drivers/passthrough/vtd/dmar.c +13 -0
+static void __init add_extra_rmrr(void)
+{
+    struct acpi_rmrr_unit *acpi_rmrr;
+    unsigned int dev, seg, i, j;
+    unsigned long pfn;
+
+    for ( i = 0; i < nr_rmrr; i++ )
+    {
+        if ( extra_rmrr_units[i].base_pfn > extra_rmrr_units[i].end_pfn )
+        {
+            printk(XENLOG_ERR VTDPREFIX
+                   "Start pfn > end pfn for RMRR range "PRI_RMRRL"\n",
+                   extra_rmrr_units[i].base_pfn, extra_rmrr_units[i].end_pfn);

How about just "Invalid RMRR range ..."?

xen/drivers/passthrough/vtd/dmar.c out: · line 903

Quoted 4 lines
xen/drivers/passthrough/vtd/dmar.c +4 -0
+            continue;
+        }
+
+        if ( extra_rmrr_units[i].end_pfn - extra_rmrr_units[i].base_pfn >= MAX_EXTRA_RMRR_PAGES )

Long line.

xen/drivers/passthrough/vtd/dmar.c out: · line 906

Quoted 3 lines
xen/drivers/passthrough/vtd/dmar.c +3 -0
+        {
+            printk(XENLOG_ERR VTDPREFIX
+                   "RMRR range exceeds %s pages "PRI_RMRRL"\n",__stringify(MAX_EXTRA_RMRR_PAGES),

You don't need %s for a string literal - simply embed the literal just like you also embed PRI_RMRRL. And please print the range after the word "range", not at the end of the message.

Quoted 9 lines
xen/drivers/passthrough/vtd/dmar.c +9 -0
+                   extra_rmrr_units[i].base_pfn, extra_rmrr_units[i].end_pfn);
+            continue;
+        }
+
+        for ( j = 0; j < nr_rmrr; j++ )
+        {
+            if ( i != j && extra_rmrr_units[i].base_pfn <= extra_rmrr_units[j].end_pfn &&
+                 extra_rmrr_units[j].base_pfn <= extra_rmrr_units[i].end_pfn )
+            {

xen/drivers/passthrough/vtd/dmar.c out: · line 925

Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +10 -0
+                printk(XENLOG_ERR VTDPREFIX
+                      "Overlapping RMRRs "PRI_RMRRL" and "PRI_RMRRL"\n",
+                      extra_rmrr_units[i].base_pfn, extra_rmrr_units[i].end_pfn,
+                      extra_rmrr_units[j].base_pfn, extra_rmrr_units[j].end_pfn);
+                break;
+            }
+        }
+        /* Broke out of the overlap loop check, continue with next rmrr. */
+        if ( j < nr_rmrr )
+            continue;

Now this only checks for overlaps amongst the extra RMRRs, while you should also check for overlaps with ACPI provided ones.

xen/drivers/passthrough/vtd/dmar.c out: · line 937

Quoted 11 lines
xen/drivers/passthrough/vtd/dmar.c +11 -0
+        for ( pfn = extra_rmrr_units[i].base_pfn; pfn <= extra_rmrr_units[i].end_pfn; pfn++ )
+        {
+            if ( !mfn_valid(pfn) )
+            {
+                if ( iommu_verbose )
+                    printk(XENLOG_ERR VTDPREFIX
+                           "Invalid mfn in RMRR range "PRI_RMRRL"\n",
+                           extra_rmrr_units[i].base_pfn, extra_rmrr_units[i].end_pfn);
+                break;
+            }
+        }

Even if an admin error, could you please avoid making this an infinite loop when .end_pfn is ~0UL? I.e.

	pfn = ...;
	do {
		...
	} while ( pfn++ < ... );

Or, perhaps even better, reject PFNs out of range for PADDR_BITS.

Quoted 25 lines
xen/drivers/passthrough/vtd/dmar.c +25 -0
+        /* The range had invalid mfn as the loop was broken out before reaching end_pfn. */
+        if ( pfn <= extra_rmrr_units[i].end_pfn )
+            continue;
+
+        acpi_rmrr = xzalloc(struct acpi_rmrr_unit);
+        if ( !acpi_rmrr )
+            return;
+
+        acpi_rmrr->scope.devices = xmalloc_array(u16,
+                                                 extra_rmrr_units[i].dev_count);
+        if ( !acpi_rmrr->scope.devices )
+        {
+            xfree(acpi_rmrr);
+            return;
+        }
+
+        seg = 0;
+        for ( dev = 0; dev < extra_rmrr_units[i].dev_count; dev++ )
+        {
+            acpi_rmrr->scope.devices[dev] = extra_rmrr_units[i].sbdf[dev];
+            seg = seg | PCI_SEG(extra_rmrr_units[i].sbdf[dev]);
+        }
+        if ( seg != PCI_SEG(extra_rmrr_units[i].sbdf[0]) )
+        {
+            printk(XENLOG_ERR VTDPREFIX

xen/drivers/passthrough/vtd/dmar.c out: · line 972

Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +10 -0
+                   "Segments are not equal for RMRR range "PRI_RMRRL"\n",
+                   extra_rmrr_units[i].base_pfn, extra_rmrr_units[i].end_pfn);
+            scope_devices_free(&acpi_rmrr->scope);
+            xfree(acpi_rmrr);
+            continue;
+        }
+
+        acpi_rmrr->segment = seg;
+        acpi_rmrr->base_address = extra_rmrr_units[i].base_pfn << PAGE_SHIFT;
+        acpi_rmrr->end_address = (extra_rmrr_units[i].end_pfn + 1) << PAGE_SHIFT;

pfn_to_paddr()

Quoted 28 lines
xen/drivers/passthrough/vtd/dmar.c +28 -0
+static void __init parse_rmrr_param(const char *str)
+{
+    const char *s = str, *cur, *stmp;
+    unsigned int seg, bus, dev, func;
+    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;
+
+        extra_rmrr_units[nr_rmrr].base_pfn = start;
+        extra_rmrr_units[nr_rmrr].end_pfn = end;
+        extra_rmrr_units[nr_rmrr].dev_count = 0;
+
+        if ( *s != '=' )
+            continue;
+
+        do {

xen/drivers/passthrough/vtd/dmar.c int platform_supports_x2apic(void) · line 1087

Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +10 -0
+            bool_t default_segment = 0;
+
+            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 ( extra_rmrr_units[nr_rmrr].dev_count > 0 && default_segment )

Using > 0 here and ...

xen/drivers/passthrough/vtd/dmar.c int platform_supports_x2apic(void) · line 1094

Quoted 7 lines
xen/drivers/passthrough/vtd/dmar.c +7 -0
+                seg = PCI_SEG(extra_rmrr_units[nr_rmrr].sbdf[0]);
+
+            /* Keep sbdf's even if they differ and later report error. */
+            extra_rmrr_units[nr_rmrr].sbdf[extra_rmrr_units[nr_rmrr].dev_count] = PCI_SBDF(seg, bus, dev, func);
+            extra_rmrr_units[nr_rmrr].dev_count++;
+            s = stmp;
+        } while ( (*s == ',' || *s || !s) &&

This looks broken: The first condition is redundant with the second one, and !s implies that you'll crash on the next iteration.

xen/drivers/passthrough/vtd/dmar.c int platform_supports_x2apic(void) · line 1097

Quoted 3 lines
xen/drivers/passthrough/vtd/dmar.c +3 -0
+                  extra_rmrr_units[nr_rmrr].dev_count < MAX_EXTRA_RMRR_DEV );
+
+        if ( extra_rmrr_units[nr_rmrr].dev_count )

no comparison operator here - please be consistent (personally I prefer the latter).

Jan