These are two simple translation helpers, one for converting an arbitrary guest kernel virtual address to a physical address (and hence host process virtual address); and one to return the guest kernel RIP as a physical address (and hence host virtual address).
Currently, they just blow the upper 34 bits of the guest VA to zero, since the high part of the negative address space is low physical memory. Longer term, we may need to walk page tables, but so far there has been no need. Change-Id: I6f3875b03b7b33edd223615bd4678e6f2641d90a Signed-off-by: Ronald G. Minnich <[email protected]> --- user/vmm/include/vmm/vmm.h | 2 ++ user/vmm/vmx.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/user/vmm/include/vmm/vmm.h b/user/vmm/include/vmm/vmm.h index 8dedb28..fbc12b7 100644 --- a/user/vmm/include/vmm/vmm.h +++ b/user/vmm/include/vmm/vmm.h @@ -36,6 +36,8 @@ int decode(struct guest_thread *vm_thread, uint64_t *gpa, uint8_t *destreg, uint64_t **regp, int *store, int *size, int *advance); bool io(struct guest_thread *vm_thread); void showstatus(FILE *f, struct guest_thread *vm_thread); +uint64_t gvatogpa(struct guest_thread *vm_thread, uint64_t va); +uint64_t rippa(struct guest_thread *vm_thread); int msrio(struct guest_thread *vm_thread, struct vmm_gpcore_init *gpci, uint32_t opcode); int do_ioapic(struct guest_thread *vm_thread, uint64_t gpa, diff --git a/user/vmm/vmx.c b/user/vmm/vmx.c index cf3e6fa..d024537 100644 --- a/user/vmm/vmx.c +++ b/user/vmm/vmx.c @@ -57,3 +57,22 @@ void showstatus(FILE *f, struct guest_thread *vm_thread) fprintf(f, " r14 0x%016lx\n", vm_tf->tf_r14); fprintf(f, " r15 0x%016lx\n", vm_tf->tf_r15); } + +/* Convert a kernel guest virtual address to physical address. + * Assumes that the guest VA is in the high negative address space. + * TODO: Takes the vm_thread argument so that we can walk the page tables + * instead of just coercing the pointer. Therefore, this is not in vmm.h + * since it may get complex. */ +uint64_t gvatogpa(struct guest_thread *vm_thread, uint64_t va) +{ + assert(vm_thread != NULL); + assert(va >= 0xffffffffc0000000ULL); + return va & 0x3fffffff; +} + +/* Get the RIP as a physical address. */ +uint64_t rippa(struct guest_thread *vm_thread) +{ + assert(vm_thread != NULL); + return gvatogpa(vm_thread, gth_to_vmtf(vm_thread)->tf_rip); +} -- 2.8.0.rc3.226.g39d4020 -- You received this message because you are subscribed to the Google Groups "Akaros" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
