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

[Xen-devel] [PATCH] libxc/arm: Correctly handle the difference between virtual and physical address



xc_dom_alloc_page deals with virtual address not physical address. When
an ELF is loaded, virtual address and physical address may be different.

Signed-off-by: Julien Grall <julien.grall@xxxxxxxxxx>
---
 tools/libxc/xc_dom_arm.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c
index a40e04d..75a6f1c 100644
--- a/tools/libxc/xc_dom_arm.c
+++ b/tools/libxc/xc_dom_arm.c
@@ -108,13 +108,15 @@ static int shared_info_arm(struct xc_dom_image *dom, void 
*ptr)
 static int vcpu_arm32(struct xc_dom_image *dom, void *ptr)
 {
     vcpu_guest_context_t *ctxt = ptr;
+    uint32_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
+    uint32_t offset = dom->parms.virt_base - rambase;
 
     DOMPRINTF_CALLED(dom->xch);
 
     /* clear everything */
     memset(ctxt, 0, sizeof(*ctxt));
 
-    ctxt->user_regs.pc32 = dom->parms.virt_entry;
+    ctxt->user_regs.pc32 = dom->parms.virt_entry - offset;
 
     /* Linux boot protocol. See linux.Documentation/arm/Booting. */
     ctxt->user_regs.r0_usr = 0; /* SBZ */
@@ -125,7 +127,7 @@ static int vcpu_arm32(struct xc_dom_image *dom, void *ptr)
      * like a valid pointer to a set of ATAGS or a DTB.
      */
     ctxt->user_regs.r2_usr = dom->devicetree_blob ?
-        dom->devicetree_seg.vstart : 0xffffffff;
+        (dom->devicetree_seg.vstart - offset) : 0xffffffff;
 
     ctxt->sctlr = SCTLR_GUEST_INIT;
 
@@ -280,15 +282,15 @@ int arch_setup_meminit(struct xc_dom_image *dom)
 
     if ( dom->devicetree_blob )
     {
-        const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
-        const uint64_t ramend = rambase + ( dom->total_pages << XC_PAGE_SHIFT 
);
+        const uint64_t virtbase = dom->parms.virt_base;
+        const uint64_t virtend = virtbase + ( dom->total_pages << 
XC_PAGE_SHIFT );
         const uint64_t dtbsize = ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT);
 
         /* Place at 128MB if there is sufficient RAM */
-        if ( ramend >= rambase + 128*1024*1024 + dtbsize )
-            dom->devicetree_seg.vstart = rambase + 128*1024*1024;
+        if ( virtend >= virtbase + 128*1024*1024 + dtbsize )
+            dom->devicetree_seg.vstart = virtbase + 128*1024*1024;
         else /* otherwise at top of RAM */
-            dom->devicetree_seg.vstart = ramend - dtbsize;
+            dom->devicetree_seg.vstart = virtend - dtbsize;
 
         dom->devicetree_seg.vend =
             dom->devicetree_seg.vstart + dom->devicetree_size;
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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