xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] VT-d: improve RMRR validity checking
@ 2010-01-21  2:46 Han, Weidong
  2010-01-21  8:25 ` Noboru Iwamatsu
  0 siblings, 1 reply; 76+ messages in thread
From: Han, Weidong @ 2010-01-21  2:46 UTC (permalink / raw)
  To: xen-devel@lists.xensource.com; +Cc: Keir Fraser

[-- Attachment #1: Type: text/plain, Size: 580 bytes --]

Currently, Xen checks RMRR range and disables VT-d if RMRR range is set incorrectly in BIOS rigorously. But, actually we can ignore the RMRR if the device under its scope are not pci discoverable, because the RMRR won't be used by non-existed or disabled devices. 

This patch ignores the RMRR if the device under its scope are not pci discoverable, and only checks the validity of RMRRs that are actually used. In order to avoid duplicate pci device detection code, this patch defines a function pci_device_detect for it.

Signed-off-by: Weidong Han <weidong.han@intel.com>

[-- Attachment #2: rmrr.patch --]
[-- Type: application/octet-stream, Size: 4672 bytes --]

diff -r 104110651ff6 xen/drivers/passthrough/pci.c
--- a/xen/drivers/passthrough/pci.c	Wed Jan 20 22:50:09 2010 +0800
+++ b/xen/drivers/passthrough/pci.c	Thu Jan 21 10:17:52 2010 +0800
@@ -362,6 +362,21 @@ out:
 }
 
 /*
+ * detect pci device, return 0 if it exists, or return 0
+ */
+int pci_device_detect(u8 bus, u8 dev, u8 func)
+{
+    u32 vendor;
+
+    vendor = pci_conf_read32(bus, dev, func, PCI_VENDOR_ID);
+    /* some broken boards return 0 or ~0 if a slot is empty: */
+    if ( (vendor == 0xffffffff) || (vendor == 0x00000000) ||
+         (vendor == 0x0000ffff) || (vendor == 0xffff0000) )
+        return 0;
+    return 1;
+}
+
+/*
  * scan pci devices to add all existed PCI devices to alldevs_list,
  * and setup pci hierarchy in array bus2bridge. This function is only
  * called in VT-d hardware setup
@@ -372,7 +387,6 @@ int __init scan_pci_devices(void)
     int bus, dev, func;
     u8 sec_bus, sub_bus;
     int type;
-    u32 l;
 
     spin_lock(&pcidevs_lock);
     for ( bus = 0; bus < 256; bus++ )
@@ -381,10 +395,7 @@ int __init scan_pci_devices(void)
         {
             for ( func = 0; func < 8; func++ )
             {
-                l = pci_conf_read32(bus, dev, func, PCI_VENDOR_ID);
-                /* some broken boards return 0 or ~0 if a slot is empty: */
-                if ( (l == 0xffffffff) || (l == 0x00000000) ||
-                     (l == 0x0000ffff) || (l == 0xffff0000) )
+                if ( pci_device_detect(bus, dev, func) == 0 )
                     continue;
 
                 pdev = alloc_pdev(bus, PCI_DEVFN(dev, func));
diff -r 104110651ff6 xen/drivers/passthrough/vtd/dmar.c
--- a/xen/drivers/passthrough/vtd/dmar.c	Wed Jan 20 22:50:09 2010 +0800
+++ b/xen/drivers/passthrough/vtd/dmar.c	Thu Jan 21 17:51:45 2010 +0800
@@ -410,14 +410,6 @@ acpi_parse_one_rmrr(struct acpi_dmar_ent
     u64 base_addr = rmrr->base_address, end_addr = rmrr->end_address;
     int ret = 0;
 
-    if ( base_addr >= end_addr )
-    {
-        dprintk(XENLOG_ERR VTDPREFIX,
-                "RMRR error: base_addr %"PRIx64" end_address %"PRIx64"\n",
-                base_addr, end_addr);
-        return -EFAULT;
-    }
-
 #ifdef CONFIG_X86
     /* This check is here simply to detect when RMRR values are
      * not properly represented in the system memory map and
@@ -441,9 +433,6 @@ acpi_parse_one_rmrr(struct acpi_dmar_ent
 
     rmrru->base_address = base_addr;
     rmrru->end_address = end_addr;
-    dprintk(XENLOG_INFO VTDPREFIX,
-            "  RMRR region: base_addr %"PRIx64" end_address %"PRIx64"\n",
-            rmrru->base_address, rmrru->end_address);
 
     dev_scope_start = (void *)(rmrr + 1);
     dev_scope_end   = ((void *)rmrr) + header->length;
@@ -453,7 +442,50 @@ acpi_parse_one_rmrr(struct acpi_dmar_ent
     if ( ret || (rmrru->scope.devices_cnt == 0) )
         xfree(rmrru);
     else
-        acpi_register_rmrr_unit(rmrru);
+    {
+        u8 b, d, f;
+        int i, ignore = 0;
+
+        for ( i = 0; 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(b, d, f) == 0 )
+                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);
+            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);
+            xfree(rmrru);
+            ret = -EFAULT;
+        }
+        else
+        {
+            dprintk(XENLOG_INFO VTDPREFIX,
+                "  RMRR region: base_addr %"PRIx64" end_address %"PRIx64"\n",
+                rmrru->base_address, rmrru->end_address);
+            acpi_register_rmrr_unit(rmrru);
+        }
+    }
+
     return ret;
 }
 
diff -r 104110651ff6 xen/include/xen/pci.h
--- a/xen/include/xen/pci.h	Wed Jan 20 22:50:09 2010 +0800
+++ b/xen/include/xen/pci.h	Thu Jan 21 17:39:27 2010 +0800
@@ -74,6 +74,7 @@ enum {
     DEV_TYPE_PCI,
 };
 
+int pci_device_detect(u8 bus, u8 dev, u8 func);
 int scan_pci_devices(void);
 int pdev_type(u8 bus, u8 devfn);
 int find_upstream_bridge(u8 *bus, u8 *devfn, u8 *secbus);

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 76+ messages in thread

end of thread, other threads:[~2010-03-11  8:30 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-21  2:46 [PATCH] VT-d: improve RMRR validity checking Han, Weidong
2010-01-21  8:25 ` Noboru Iwamatsu
2010-01-21  8:38   ` Han, Weidong
2010-01-21 10:03     ` Noboru Iwamatsu
2010-01-21 10:08       ` Noboru Iwamatsu
2010-01-21 10:19         ` Weidong Han
2010-01-21 10:27           ` Keir Fraser
2010-01-21 10:49             ` Weidong Han
2010-01-21 12:19               ` Noboru Iwamatsu
2010-01-21 12:46                 ` Weidong Han
2010-01-21 14:01                   ` Keir Fraser
2010-01-21 14:17                   ` Sander Eikelenboom
2010-01-21 14:33                     ` Keir Fraser
2010-01-22  2:12                       ` Weidong Han
2010-01-22  2:38                         ` Noboru Iwamatsu
2010-01-22  2:53                           ` Weidong Han
2010-01-22  3:16                             ` Noboru Iwamatsu
2010-01-22  8:47                               ` Weidong Han
2010-01-22  9:19                                 ` Sander Eikelenboom
2010-01-22 12:15                                   ` Weidong Han
2010-01-22 12:32                                     ` Pasi Kärkkäinen
2010-01-23 12:40                                       ` Weidong Han
2010-01-23 13:08                                         ` Pasi Kärkkäinen
2010-01-23 14:33                                           ` Sander Eikelenboom
2010-01-23 14:54                                             ` [PATCH] VT-d: improve RMRR validity checking, documenting boot options Pasi Kärkkäinen
2010-01-25 16:40                                               ` Stephen Spector
2010-01-25 16:58                                                 ` Documentation Xen-hypervisor and Dom0 xen-related boot options (was Re: [PATCH] VT-d: improve RMRR validity checking, documenting boot options) Sander Eikelenboom
2010-01-25 20:56                                                   ` Stephen Spector
2010-01-27 11:33                                                     ` Pasi Kärkkäinen
2010-01-25  7:06                                 ` [PATCH] VT-d: improve RMRR validity checking Noboru Iwamatsu
2010-01-25  7:56                                   ` Weidong Han
2010-01-25  9:02                                     ` Sander Eikelenboom
2010-01-25  9:11                                       ` Weidong Han
2010-01-25  9:22                                     ` Noboru Iwamatsu
2010-01-25 10:08                                       ` Weidong Han
2010-01-25 10:45                                         ` Sander Eikelenboom
2010-01-25 13:43                                           ` Keir Fraser
2010-01-25 13:57                                             ` Christian Tramnitz
2010-01-25 14:10                                             ` Weidong Han
2010-01-26  1:16                                               ` Noboru Iwamatsu
2010-01-26  5:51                                                 ` Weidong Han
2010-01-26  6:38                                                   ` Noboru Iwamatsu
2010-01-26  6:42                                                     ` Weidong Han
2010-01-25 14:12                                             ` Weidong Han
2010-01-25 14:13                                             ` Han, Weidong
2010-03-09 21:39                                 ` Alex Williamson
2010-03-09 21:30                                   ` Konrad Rzeszutek Wilk
2010-03-09 21:57                                     ` Alex Williamson
2010-03-09 22:22                                       ` Konrad Rzeszutek Wilk
2010-03-09 23:05                                         ` Alex Williamson
2010-03-09 23:25                                           ` Alex Williamson
2010-03-10  2:13                                             ` Alex Williamson
2010-03-10  2:40                                   ` Weidong Han
2010-03-10  3:18                                     ` Alex Williamson
2010-03-10  3:28                                       ` Weidong Han
2010-03-10  3:37                                         ` Alex Williamson
2010-03-10  4:25                                           ` Weidong Han
2010-03-10  4:47                                             ` Alex Williamson
2010-03-10  7:03                                               ` Weidong Han
2010-03-10 13:56                                                 ` Alex Williamson
2010-03-10 18:06                                                   ` Alex Williamson
2010-03-11  2:11                                                     ` Weidong Han
2010-03-11  2:32                                                       ` Alex Williamson
2010-03-11  3:44                                                         ` Weidong Han
2010-03-11  4:52                                                           ` Alex Williamson
2010-03-11  8:30                                                             ` Weidong Han
2010-01-21 15:28                     ` Andrew Lyon
2010-01-21 15:04                 ` Keir Fraser
2010-01-22  1:35                   ` Noboru Iwamatsu
2010-01-21 10:13       ` Weidong Han
2010-01-21 12:09         ` Noboru Iwamatsu
2010-01-21 12:38           ` Weidong Han
2010-01-22  0:23             ` Noboru Iwamatsu
2010-01-21  8:45   ` Andrew Lyon
2010-01-21 10:03     ` Weidong Han
2010-01-21  9:15   ` Keir Fraser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).