kvm tools: teach guest_flat_to_host about memory banks starting above 0

Running a guest with multiple banks of memory based above 0 causes the
guest_flat_to_host address conversion to fail, as it is assumed that
guest memory addresses are offset linearly from 0.

This patch changes the translation function so that the kvm_mem_bank
structures registered by kvm__register_mem are used to translate guest
addresses, rather than use an offset from the start of host memory.

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:15 +00:00
parent d82350d3bc
commit f412251f98
4 changed files with 26 additions and 14 deletions
+2 -5
View File
@@ -105,6 +105,8 @@ int kvm__arch_free_firmware(struct kvm *kvm);
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);
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);
@@ -120,11 +122,6 @@ static inline bool host_ptr_in_ram(struct kvm *kvm, void *p)
return kvm->ram_start <= p && p < (kvm->ram_start + kvm->ram_size);
}
static inline void *guest_flat_to_host(struct kvm *kvm, unsigned long offset)
{
return kvm->ram_start + offset;
}
bool kvm__supports_extension(struct kvm *kvm, unsigned int extension);
static inline void kvm__set_thread_name(const char *name)
+17
View File
@@ -184,6 +184,23 @@ int kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace
return 0;
}
void *guest_flat_to_host(struct kvm *kvm, u64 offset)
{
struct kvm_mem_bank *bank;
list_for_each_entry(bank, &kvm->mem_banks, list) {
u64 bank_start = bank->guest_phys_addr;
u64 bank_end = bank_start + bank->size;
if (offset >= bank_start && offset < bank_end)
return bank->host_addr + (offset - bank_start);
}
pr_warning("unable to translate guest address 0x%llx to host",
(unsigned long long)offset);
return NULL;
}
int kvm__recommended_cpus(struct kvm *kvm)
{
int ret;
-9
View File
@@ -33,13 +33,4 @@ struct kvm_arch {
struct interrupt_table interrupt_table;
};
static inline void *guest_flat_to_host(struct kvm *kvm, unsigned long offset); /* In kvm.h */
static inline void *guest_real_to_host(struct kvm *kvm, u16 selector, u16 offset)
{
unsigned long flat = segment_to_flat(selector, offset);
return guest_flat_to_host(kvm, flat);
}
#endif /* KVM__KVM_ARCH_H */
+7
View File
@@ -199,6 +199,13 @@ void kvm__irq_trigger(struct kvm *kvm, int irq)
#define BOOT_PROTOCOL_REQUIRED 0x206
#define LOAD_HIGH 0x01
static inline void *guest_real_to_host(struct kvm *kvm, u16 selector, u16 offset)
{
unsigned long flat = segment_to_flat(selector, offset);
return guest_flat_to_host(kvm, flat);
}
int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline)
{
void *p;