Skip to contentSkip to conversation

xc_translate_foreign_address with additional parameter

PATCH In review Tomas Kouba 3 participants 3 messages Jan 5, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xc_translate_foreign_address with additional parameter

Hi,

I think it would be handy(*) to have additional function xc_translate_foreign_address_cr3 that does the same as xc_translate_foreign_address but with explicit cr3 register. The actual xc_translate_foreign_address takes its cr3 from vcpu context.

This is my first patch/post so please excuse me if I misfollowed some procedure.

(*) handy for xenaccess library

Signature · 1 line
Tomas Kouba

# HG changeset patch
# User [email protected]
# Date 1168005525 -3600
# Node ID cde6908125f925d15a5a6680730fdd9f1bd0b850
# Parent d04ff58bbe18b40807c1f4fe0c29843333573f05
Added xc_translate_foreign_address_cr3 so the translation can be done with custom page tables.

tools/libxc/xc_pagetab.c Fri Jan 05 14:58:45 2007 +0100 renamed from tools/libxc/xc_pagetab.c Fri Jan 05 10:40:19 2007 +0000 +15 -6
diff -r d04ff58bbe18 -r cde6908125f9 tools/libxc/xc_pagetab.c
@@ -50,6 +50,21 @@ unsigned long xc_translate_foreign_addre
 {
     vcpu_guest_context_t ctx;
     unsigned long long cr3;
+
+    if (xc_vcpu_getcontext(xc_handle, dom, vcpu, &ctx) != 0) {
+        DPRINTF("failed to retreive vcpu context\n");
+        return 0;
+    }
+    cr3 = ((unsigned long long)xen_cr3_to_pfn(ctx.ctrlreg[3])) << PAGE_SHIFT;
+
+    return xc_translate_foreign_address_cr3(xc_handle, dom, vcpu, virt, cr3);
+}
+
+
+unsigned long xc_translate_foreign_address_cr3(int xc_handle, uint32_t dom,
+                                           int vcpu, unsigned long long virt,
+                                           unsigned long long cr3)
+{
     void *pd, *pt, *pdppage = NULL, *pdp, *pml = NULL;
     unsigned long long pde, pte, pdpe, pmle;
     unsigned long mfn = 0;
@@ -73,12 +88,6 @@ unsigned long xc_translate_foreign_addre
 #elif defined (__x86_64__)
 #define pt_levels 4
 #endif
-
-    if (xc_vcpu_getcontext(xc_handle, dom, vcpu, &ctx) != 0) {
-        DPRINTF("failed to retreive vcpu context\n");
-        goto out;
-    }
-    cr3 = ((unsigned long long)xen_cr3_to_pfn(ctx.ctrlreg[3])) << PAGE_SHIFT;
 
     /* Page Map Level 4 */
 
tools/libxc/xenctrl.h Fri Jan 05 14:58:45 2007 +0100 renamed from tools/libxc/xenctrl.h Fri Jan 05 10:40:19 2007 +0000 +15 -0
diff -r d04ff58bbe18 -r cde6908125f9 tools/libxc/xenctrl.h
@@ -513,6 +513,21 @@ unsigned long xc_translate_foreign_addre
 unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom,
                                            int vcpu, unsigned long long virt);
 
+/**
+ * Translates a virtual address in the context of a given domain and
+ * memory management tables. Returns the machine page frame number of the associated
+ * page.
+ *
+ * @parm xc_handle a handle on an open hypervisor interface
+ * @parm dom the domain to perform the translation in
+ * @parm vcpu the vcpu to perform the translation on
+ * @parm virt the virtual address to translate
+ * @parm cr3 pointer to MM tables (identifies userland process)
+ */
+unsigned long xc_translate_foreign_address_cr3(int xc_handle, uint32_t dom,
+                                           int vcpu, unsigned long long virt,
+                                           unsigned long long cr3);
+
 int xc_get_pfn_list(int xc_handle, uint32_t domid, xen_pfn_t *pfn_buf,
                     unsigned long max_pfns);
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 5 lines · Tomas Kouba

I think it would be handy(*) to have additional function xc_translate_foreign_address_cr3 that does the same as xc_translate_foreign_address but with explicit cr3 register. The actual xc_translate_foreign_address takes its cr3 from vcpu context.

Even better would be to accept cr3, cr4 and efer msr. That's sufficient to work out the execution mode (non-pae, pae, 64-bit). Or the caller could work out the mode and pass it in as an enumeration value (perhaps with a fallback default of 'whatever is most likely').

-- Keir

#2 lore raw
Quoted 2 lines

Even better would be to accept cr3, cr4 and efer msr. That's sufficient to work out the execution mode (non-pae, pae, 64-bit). Or the caller could work

Execution mode is one thing. But the other problem is that sometimes you want to translate a virtual address for a process that is not currently running. In this case, the register values would not hold the correct page table base address and it would be nice to specify your own (e.g., taken from the task struct).

-bryan

-
Bryan D. Payne
Graduate Student, Computer Science
Georgia Tech Information Security Center
http://www.bryanpayne.org