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

[Xen-changelog] [xen stable-4.9] hvmloader: use base instead of pci_mem_start for find_next_rmrr()



commit 22ea7316e5440b16965471b5c1026f178ee9683e
Author:     Xiong Zhang <xiong.y.zhang@xxxxxxxxx>
AuthorDate: Fri Oct 6 14:54:24 2017 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Fri Oct 6 14:54:24 2017 +0200

    hvmloader: use base instead of pci_mem_start for find_next_rmrr()
    
    find_next_rmrr(base) is used to find the lowest RMRR ending above base
    but below 4G. Current method couldn't cover the following situation:
    a. two rmrr exist, small gap between them
    b. pci_mem_start and mem_resource.base is below the first rmrr.base
    c. find_next_rmrr(pci_mem_start) will find the first rmrr
    d. After aligning mem_resource.base to bar size,
       first_rmrr.end < new_base < second_rmrr.base and
       new_base + bar_sz > second_rmrr.base.
       So the new bar will overlap with the second rmrr and doesn't overlap
    with the first rmrr.
    But the next_rmrr point to the first rmrr, then check_overlap() couldn't
    find the overlap. Finally assign a wrong address to bar.
    
    This patch using aligned new base to find the next rmrr, could fix the
    above case and find all the overlapped rmrr with new base.
    
    Signed-off-by: Xiong Zhang <xiong.y.zhang@xxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    master commit: ecc607b1851bc27140090da4d6124fd00090ec2b
    master date: 2017-08-28 10:51:24 +0200
---
 tools/firmware/hvmloader/pci.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index 4eb1a31..9543e5a 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -84,7 +84,6 @@ void pci_setup(void)
     uint32_t vga_devfn = 256;
     uint16_t class, vendor_id, device_id;
     unsigned int bar, pin, link, isa_irq;
-    int next_rmrr;
 
     /* Resources assignable to PCI devices via BARs. */
     struct resource {
@@ -403,8 +402,6 @@ void pci_setup(void)
     io_resource.base = 0xc000;
     io_resource.max = 0x10000;
 
-    next_rmrr = find_next_rmrr(pci_mem_start);
-
     /* Assign iomem and ioport resources in descending order of size. */
     for ( i = 0; i < nr_bars; i++ )
     {
@@ -462,15 +459,20 @@ void pci_setup(void)
         base = (resource->base  + bar_sz - 1) & ~(uint64_t)(bar_sz - 1);
 
         /* If we're using mem_resource, check for RMRR conflicts. */
-        while ( resource == &mem_resource &&
-                next_rmrr >= 0 &&
-                check_overlap(base, bar_sz,
+        if ( resource == &mem_resource)
+        {
+            int next_rmrr = find_next_rmrr(base);
+
+            while ( next_rmrr >= 0 &&
+                    check_overlap(base, bar_sz,
                               memory_map.map[next_rmrr].addr,
                               memory_map.map[next_rmrr].size) )
-        {
-            base = memory_map.map[next_rmrr].addr + 
memory_map.map[next_rmrr].size;
-            base = (base + bar_sz - 1) & ~(bar_sz - 1);
-            next_rmrr = find_next_rmrr(base);
+            {
+                base = memory_map.map[next_rmrr].addr +
+                       memory_map.map[next_rmrr].size;
+                base = (base + bar_sz - 1) & ~(bar_sz - 1);
+                next_rmrr = find_next_rmrr(base);
+            }
         }
 
         bar_data |= (uint32_t)base;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.9

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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