All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][libxc] xc_translate_foreign_address with additional parameter
@ 2007-01-05 14:19 Tomas Kouba
  2007-01-05 14:36 ` Keir Fraser
  0 siblings, 1 reply; 3+ messages in thread
From: Tomas Kouba @ 2007-01-05 14:19 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 384 bytes --]

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

-- 
Tomas Kouba


[-- Attachment #2: xc_translate_foreign_address_cr3.patch --]
[-- Type: text/x-patch, Size: 2831 bytes --]

# HG changeset patch
# User tomas@jikos.cz
# Date 1168005525 -3600
# Node ID cde6908125f925d15a5a6680730fdd9f1bd0b850
# Parent  d04ff58bbe18b40807c1f4fe0c29843333573f05
Added xc_translate_foreign_address_cr3 so the translation can be done with
custom page tables.

diff -r d04ff58bbe18 -r cde6908125f9 tools/libxc/xc_pagetab.c
--- a/tools/libxc/xc_pagetab.c  Fri Jan 05 10:40:19 2007 +0000
+++ b/tools/libxc/xc_pagetab.c  Fri Jan 05 14:58:45 2007 +0100
@@ -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 */

diff -r d04ff58bbe18 -r cde6908125f9 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h     Fri Jan 05 10:40:19 2007 +0000
+++ b/tools/libxc/xenctrl.h     Fri Jan 05 14:58:45 2007 +0100
@@ -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);



[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

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

* Re: [PATCH][libxc] xc_translate_foreign_address with additional parameter
  2007-01-05 14:19 [PATCH][libxc] xc_translate_foreign_address with additional parameter Tomas Kouba
@ 2007-01-05 14:36 ` Keir Fraser
  2007-01-05 16:32   ` Bryan D. Payne
  0 siblings, 1 reply; 3+ messages in thread
From: Keir Fraser @ 2007-01-05 14:36 UTC (permalink / raw)
  To: Tomas Kouba, xen-devel




On 5/1/07 14:19, "Tomas Kouba" <tomas@jikos.cz> wrote:

> 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

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

* Re: [PATCH][libxc] xc_translate_foreign_address with additional parameter
  2007-01-05 14:36 ` Keir Fraser
@ 2007-01-05 16:32   ` Bryan D. Payne
  0 siblings, 0 replies; 3+ messages in thread
From: Bryan D. Payne @ 2007-01-05 16:32 UTC (permalink / raw)
  To: Keir Fraser; +Cc: xen-devel, Tomas Kouba

> 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

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

end of thread, other threads:[~2007-01-05 16:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-05 14:19 [PATCH][libxc] xc_translate_foreign_address with additional parameter Tomas Kouba
2007-01-05 14:36 ` Keir Fraser
2007-01-05 16:32   ` Bryan D. Payne

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.