kvm tools: provide a mechanism for translating host to guest addresses

When generating a device tree for a guest, it is useful to have a helper
for converting host addresses to guest addresses in order to populate
the device nodes correctly.

This patch adds such a helper, following a similar implementation to the
reverse translation function that already exists.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Will Deacon
2012-11-22 15:58:16 +00:00
parent f412251f98
commit 0cb419900f
2 changed files with 17 additions and 0 deletions
+1
View File
@@ -106,6 +106,7 @@ bool kvm__arch_cpu_supports_vm(void);
void kvm__arch_periodic_poll(struct kvm *kvm);
void *guest_flat_to_host(struct kvm *kvm, u64 offset);
u64 host_to_guest_flat(struct kvm *kvm, void *ptr);
int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline);
bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline, u16 vidmode);
+16
View File
@@ -201,6 +201,22 @@ void *guest_flat_to_host(struct kvm *kvm, u64 offset)
return NULL;
}
u64 host_to_guest_flat(struct kvm *kvm, void *ptr)
{
struct kvm_mem_bank *bank;
list_for_each_entry(bank, &kvm->mem_banks, list) {
void *bank_start = bank->host_addr;
void *bank_end = bank_start + bank->size;
if (ptr >= bank_start && ptr < bank_end)
return bank->guest_phys_addr + (ptr - bank_start);
}
pr_warning("unable to translate host address %p to guest", ptr);
return 0;
}
int kvm__recommended_cpus(struct kvm *kvm)
{
int ret;