Introduce kvm_check_extension to check if KVM extensions are supported

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Anthony Liguori 2009-05-08 15:33:24 -05:00
parent 4a794a626d
commit ad7b8b3310
2 changed files with 24 additions and 17 deletions

View File

@ -320,6 +320,18 @@ int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size)
return ret; return ret;
} }
int kvm_check_extension(KVMState *s, unsigned int extension)
{
int ret;
ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, extension);
if (ret < 0) {
ret = 0;
}
return ret;
}
int kvm_init(int smp_cpus) int kvm_init(int smp_cpus)
{ {
KVMState *s; KVMState *s;
@ -368,10 +380,8 @@ int kvm_init(int smp_cpus)
* just use a user allocated buffer so we can use regular pages * just use a user allocated buffer so we can use regular pages
* unmodified. Make sure we have a sufficiently modern version of KVM. * unmodified. Make sure we have a sufficiently modern version of KVM.
*/ */
ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY); if (!kvm_check_extension(s, KVM_CAP_USER_MEMORY)) {
if (ret <= 0) { ret = -EINVAL;
if (ret == 0)
ret = -EINVAL;
fprintf(stderr, "kvm does not support KVM_CAP_USER_MEMORY\n"); fprintf(stderr, "kvm does not support KVM_CAP_USER_MEMORY\n");
goto err; goto err;
} }
@ -379,11 +389,8 @@ int kvm_init(int smp_cpus)
/* There was a nasty bug in < kvm-80 that prevents memory slots from being /* There was a nasty bug in < kvm-80 that prevents memory slots from being
* destroyed properly. Since we rely on this capability, refuse to work * destroyed properly. Since we rely on this capability, refuse to work
* with any kernel without this capability. */ * with any kernel without this capability. */
ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, if (!kvm_check_extension(s, KVM_CAP_DESTROY_MEMORY_REGION_WORKS)) {
KVM_CAP_DESTROY_MEMORY_REGION_WORKS); ret = -EINVAL;
if (ret <= 0) {
if (ret == 0)
ret = -EINVAL;
fprintf(stderr, fprintf(stderr,
"KVM kernel module broken (DESTROY_MEMORY_REGION)\n" "KVM kernel module broken (DESTROY_MEMORY_REGION)\n"
@ -391,11 +398,10 @@ int kvm_init(int smp_cpus)
goto err; goto err;
} }
s->coalesced_mmio = 0;
#ifdef KVM_CAP_COALESCED_MMIO #ifdef KVM_CAP_COALESCED_MMIO
ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_COALESCED_MMIO); s->coalesced_mmio = kvm_check_extension(s, KVM_CAP_COALESCED_MMIO);
if (ret > 0) #else
s->coalesced_mmio = ret; s->coalesced_mmio = 0;
#endif #endif
ret = kvm_arch_init(s, smp_cpus); ret = kvm_arch_init(s, smp_cpus);
@ -766,11 +772,10 @@ int kvm_has_sync_mmu(void)
#ifdef KVM_CAP_SYNC_MMU #ifdef KVM_CAP_SYNC_MMU
KVMState *s = kvm_state; KVMState *s = kvm_state;
if (kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_SYNC_MMU) > 0) return kvm_check_extension(s, KVM_CAP_SYNC_MMU);
return 1; #else
#endif
return 0; return 0;
#endif
} }
void kvm_setup_guest_memory(void *start, size_t size) void kvm_setup_guest_memory(void *start, size_t size)

2
kvm.h
View File

@ -118,6 +118,8 @@ void kvm_arch_remove_all_hw_breakpoints(void);
void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg); void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg);
int kvm_check_extension(KVMState *s, unsigned int extension);
/* generic hooks - to be moved/refactored once there are more users */ /* generic hooks - to be moved/refactored once there are more users */
static inline void cpu_synchronize_state(CPUState *env, int modified) static inline void cpu_synchronize_state(CPUState *env, int modified)