xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/5] hvmloader: Correct bug in low mmio region accounting
@ 2013-06-18 16:46 George Dunlap
  2013-06-18 16:46 ` [PATCH v2 2/5] hvmloader: Load large devices into high MMIO space as needed George Dunlap
                   ` (6 more replies)
  0 siblings, 7 replies; 38+ messages in thread
From: George Dunlap @ 2013-06-18 16:46 UTC (permalink / raw)
  To: xen-devel
  Cc: George Dunlap, Ian Jackson, Stefano Stabellini, Ian Campbell,
	Hanweidong

When deciding whether to map a device in low MMIO space (<4GiB),
hvmloader compares it with "mmio_left", which is set to the size of
the low MMIO range (pci_mem_end - pci_mem_start).  However, even if it
does map a device in high MMIO space, it still removes the size of its
BAR from mmio_left.

This patch first changes the name of this variable to "low_mmio_left"
to distinguish it from generic MMIO, and corrects the logic to only
subtract the size of the BAR for devices maped in the low MMIO region.

Also make low_mmio_left unsigned, and don't allow it to go negative.
Since its main use is to be compared to a 64-bit unsigned int, this
may have undefined (and in practice almost certainly incorrect)
results.  Not subtracting is OK because if there's not enough room, it
won't actually be mapped.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
CC: Ian Jackson <ian.jackson@citrix.com>
CC: Ian Campbell <ian.campbell@citrix.com>
CC: Stefano Stabellini <stefano.stabellini@citrix.com>
CC: Hanweidong <hanweidong@huawei.com>
---
 tools/firmware/hvmloader/pci.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index c78d4d3..8691a19 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -38,11 +38,10 @@ void pci_setup(void)
 {
     uint8_t is_64bar, using_64bar, bar64_relocate = 0;
     uint32_t devfn, bar_reg, cmd, bar_data, bar_data_upper;
-    uint64_t base, bar_sz, bar_sz_upper, mmio_total = 0;
+    uint64_t base, bar_sz, bar_sz_upper, low_mmio_left, mmio_total = 0;
     uint32_t vga_devfn = 256;
     uint16_t class, vendor_id, device_id;
     unsigned int bar, pin, link, isa_irq;
-    int64_t mmio_left;
 
     /* Resources assignable to PCI devices via BARs. */
     struct resource {
@@ -244,7 +243,7 @@ void pci_setup(void)
     io_resource.base = 0xc000;
     io_resource.max = 0x10000;
 
-    mmio_left = pci_mem_end - pci_mem_start;
+    low_mmio_left = pci_mem_end - pci_mem_start;
 
     /* Assign iomem and ioport resources in descending order of size. */
     for ( i = 0; i < nr_bars; i++ )
@@ -253,7 +252,7 @@ void pci_setup(void)
         bar_reg = bars[i].bar_reg;
         bar_sz  = bars[i].bar_sz;
 
-        using_64bar = bars[i].is_64bar && bar64_relocate && (mmio_left < bar_sz);
+        using_64bar = bars[i].is_64bar && bar64_relocate && (low_mmio_left < bar_sz);
         bar_data = pci_readl(devfn, bar_reg);
 
         if ( (bar_data & PCI_BASE_ADDRESS_SPACE) ==
@@ -273,9 +272,10 @@ void pci_setup(void)
             } 
             else {
                 resource = &mem_resource;
+                if ( bar_sz <= low_mmio_left )
+                    low_mmio_left -= bar_sz;
                 bar_data &= ~PCI_BASE_ADDRESS_MEM_MASK;
             }
-            mmio_left -= bar_sz;
         }
         else
         {
-- 
1.7.9.5

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

end of thread, other threads:[~2013-06-25 10:15 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-18 16:46 [PATCH v2 1/5] hvmloader: Correct bug in low mmio region accounting George Dunlap
2013-06-18 16:46 ` [PATCH v2 2/5] hvmloader: Load large devices into high MMIO space as needed George Dunlap
2013-06-19 17:18   ` Stefano Stabellini
2013-06-20  9:23     ` George Dunlap
2013-06-20  9:47   ` Jan Beulich
2013-06-18 16:46 ` [PATCH v2 3/5] hvmloader: Remove minimum size for BARs to relocate to 64-bit space George Dunlap
2013-06-19 17:18   ` Stefano Stabellini
2013-06-19 21:14   ` Wei Liu
2013-06-20  9:01     ` George Dunlap
2013-06-20  9:48   ` Jan Beulich
2013-06-18 16:46 ` [PATCH v2 4/5] hvmloader: Fix check for needing a 64-bit bar George Dunlap
2013-06-19 17:18   ` Stefano Stabellini
2013-06-20 10:01   ` Jan Beulich
2013-06-20 10:21     ` George Dunlap
2013-06-18 16:46 ` [PATCH v2 5/5] libxl, hvmloader: Don't relocate memory for MMIO hole George Dunlap
2013-06-18 17:16   ` George Dunlap
2013-06-19 17:18   ` Stefano Stabellini
2013-06-20  9:22     ` George Dunlap
2013-06-20 10:12       ` Jan Beulich
2013-06-20 10:20         ` George Dunlap
2013-06-20 10:29           ` Stefano Stabellini
2013-06-20 10:56             ` Jan Beulich
2013-06-20 10:59               ` George Dunlap
2013-06-20 11:01             ` George Dunlap
2013-06-20 13:35               ` Ian Jackson
2013-06-20 14:06                 ` George Dunlap
2013-06-20 10:37           ` Ian Jackson
2013-06-20 10:44             ` George Dunlap
2013-06-20 10:52           ` Jan Beulich
2013-06-20 10:49       ` Stefano Stabellini
2013-06-25  9:56       ` Ian Campbell
2013-06-25 10:15         ` George Dunlap
2013-06-18 16:53 ` [PATCH v2 1/5] hvmloader: Correct bug in low mmio region accounting George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-20  8:56   ` George Dunlap
2013-06-20 10:40     ` Stefano Stabellini
2013-06-20 10:43       ` George Dunlap
2013-06-20  9:36 ` Jan Beulich

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).