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

[Xen-changelog] [xen-unstable] hvmloader: Fix memory relocation loop.



# HG changeset patch
# User Keir Fraser <keir@xxxxxxx>
# Date 1321910914 0
# Node ID 0a0c02a616768bfab16c072788cb76be1893c37f
# Parent  9c350ab8d3ea64866421de756ab2bf3daaf63187
hvmloader: Fix memory relocation loop.

Signed-off-by: Keir Fraser <keir@xxxxxxx>
---


diff -r 9c350ab8d3ea -r 0a0c02a61676 tools/firmware/hvmloader/pci.c
--- a/tools/firmware/hvmloader/pci.c    Mon Nov 21 09:29:31 2011 +0100
+++ b/tools/firmware/hvmloader/pci.c    Mon Nov 21 21:28:34 2011 +0000
@@ -50,7 +50,6 @@
         uint32_t devfn, bar_reg, bar_sz;
     } *bars = (struct bars *)scratch_start;
     unsigned int i, nr_bars = 0;
-    unsigned long pci_mem_reloc_pg;
 
     /* Program PCI-ISA bridge with appropriate link routes. */
     isa_irq = 0;
@@ -186,25 +185,26 @@
             ((pci_mem_start << 1) != 0) )
         pci_mem_start <<= 1;
 
-    /* Relocate RAM that overlaps (in 64K chunks) */
-    pci_mem_reloc_pg = (pci_mem_start >> PAGE_SHIFT);
-    while (pci_mem_reloc_pg < hvm_info->low_mem_pgend)
+    /* Relocate RAM that overlaps PCI space (in 64k-page chunks). */
+    while ( (pci_mem_start >> PAGE_SHIFT) < hvm_info->low_mem_pgend )
     {
         struct xen_add_to_physmap xatp;
-        unsigned int size = hvm_info->low_mem_pgend - pci_mem_reloc_pg;
+        unsigned int nr_pages = min_t(
+            unsigned int,
+            hvm_info->low_mem_pgend - (pci_mem_start >> PAGE_SHIFT),
+            (1u << 16) - 1);
+        if ( hvm_info->high_mem_pgend == 0 )
+            hvm_info->high_mem_pgend = 1ull << (32 - PAGE_SHIFT);
+        hvm_info->low_mem_pgend -= nr_pages;
         xatp.domid = DOMID_SELF;
         xatp.space = XENMAPSPACE_gmfn_range;
-        xatp.idx = pci_mem_reloc_pg;
-        xatp.gpfn = hvm_info->high_mem_pgend;
-        size = size > ((1 << 16) - 1) ? ((1 << 16) - 1) : size;
-        xatp.size = size;
-
+        xatp.idx   = hvm_info->low_mem_pgend;
+        xatp.gpfn  = hvm_info->high_mem_pgend;
+        xatp.size  = nr_pages;
         if ( hypercall_memory_op(XENMEM_add_to_physmap, &xatp) != 0 )
             BUG();
-        pci_mem_reloc_pg += size;
-        hvm_info->high_mem_pgend += size;
+        hvm_info->high_mem_pgend += nr_pages;
     }
-    hvm_info->low_mem_pgend = pci_mem_start >> PAGE_SHIFT;
 
     mem_resource.base = pci_mem_start;
     mem_resource.max = pci_mem_end;
diff -r 9c350ab8d3ea -r 0a0c02a61676 tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h   Mon Nov 21 09:29:31 2011 +0100
+++ b/tools/firmware/hvmloader/util.h   Mon Nov 21 21:28:34 2011 +0000
@@ -31,6 +31,11 @@
 #define BUG_ON(p) do { if (p) BUG(); } while (0)
 #define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
 
+#define min_t(type,x,y) \
+        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
+#define max_t(type,x,y) \
+        ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
+
 static inline int test_bit(unsigned int b, void *p)
 {
     return !!(((uint8_t *)p)[b>>3] & (1u<<(b&7)));

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


 


Rackspace

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