Commit ad7b8b33108a6bf610b9492b1f204e660e488e99
1 parent
4a794a62
Introduce kvm_check_extension to check if KVM extensions are supported
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
2 changed files
with
24 additions
and
17 deletions
kvm-all.c
| ... | ... | @@ -320,6 +320,18 @@ int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size) |
| 320 | 320 | return ret; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | +int kvm_check_extension(KVMState *s, unsigned int extension) | |
| 324 | +{ | |
| 325 | + int ret; | |
| 326 | + | |
| 327 | + ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, extension); | |
| 328 | + if (ret < 0) { | |
| 329 | + ret = 0; | |
| 330 | + } | |
| 331 | + | |
| 332 | + return ret; | |
| 333 | +} | |
| 334 | + | |
| 323 | 335 | int kvm_init(int smp_cpus) |
| 324 | 336 | { |
| 325 | 337 | KVMState *s; |
| ... | ... | @@ -368,10 +380,8 @@ int kvm_init(int smp_cpus) |
| 368 | 380 | * just use a user allocated buffer so we can use regular pages |
| 369 | 381 | * unmodified. Make sure we have a sufficiently modern version of KVM. |
| 370 | 382 | */ |
| 371 | - ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY); | |
| 372 | - if (ret <= 0) { | |
| 373 | - if (ret == 0) | |
| 374 | - ret = -EINVAL; | |
| 383 | + if (!kvm_check_extension(s, KVM_CAP_USER_MEMORY)) { | |
| 384 | + ret = -EINVAL; | |
| 375 | 385 | fprintf(stderr, "kvm does not support KVM_CAP_USER_MEMORY\n"); |
| 376 | 386 | goto err; |
| 377 | 387 | } |
| ... | ... | @@ -379,11 +389,8 @@ int kvm_init(int smp_cpus) |
| 379 | 389 | /* There was a nasty bug in < kvm-80 that prevents memory slots from being |
| 380 | 390 | * destroyed properly. Since we rely on this capability, refuse to work |
| 381 | 391 | * with any kernel without this capability. */ |
| 382 | - ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, | |
| 383 | - KVM_CAP_DESTROY_MEMORY_REGION_WORKS); | |
| 384 | - if (ret <= 0) { | |
| 385 | - if (ret == 0) | |
| 386 | - ret = -EINVAL; | |
| 392 | + if (!kvm_check_extension(s, KVM_CAP_DESTROY_MEMORY_REGION_WORKS)) { | |
| 393 | + ret = -EINVAL; | |
| 387 | 394 | |
| 388 | 395 | fprintf(stderr, |
| 389 | 396 | "KVM kernel module broken (DESTROY_MEMORY_REGION)\n" |
| ... | ... | @@ -391,11 +398,10 @@ int kvm_init(int smp_cpus) |
| 391 | 398 | goto err; |
| 392 | 399 | } |
| 393 | 400 | |
| 394 | - s->coalesced_mmio = 0; | |
| 395 | 401 | #ifdef KVM_CAP_COALESCED_MMIO |
| 396 | - ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_COALESCED_MMIO); | |
| 397 | - if (ret > 0) | |
| 398 | - s->coalesced_mmio = ret; | |
| 402 | + s->coalesced_mmio = kvm_check_extension(s, KVM_CAP_COALESCED_MMIO); | |
| 403 | +#else | |
| 404 | + s->coalesced_mmio = 0; | |
| 399 | 405 | #endif |
| 400 | 406 | |
| 401 | 407 | ret = kvm_arch_init(s, smp_cpus); |
| ... | ... | @@ -766,11 +772,10 @@ int kvm_has_sync_mmu(void) |
| 766 | 772 | #ifdef KVM_CAP_SYNC_MMU |
| 767 | 773 | KVMState *s = kvm_state; |
| 768 | 774 | |
| 769 | - if (kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_SYNC_MMU) > 0) | |
| 770 | - return 1; | |
| 771 | -#endif | |
| 772 | - | |
| 775 | + return kvm_check_extension(s, KVM_CAP_SYNC_MMU); | |
| 776 | +#else | |
| 773 | 777 | return 0; |
| 778 | +#endif | |
| 774 | 779 | } |
| 775 | 780 | |
| 776 | 781 | void kvm_setup_guest_memory(void *start, size_t size) | ... | ... |
kvm.h
| ... | ... | @@ -118,6 +118,8 @@ void kvm_arch_remove_all_hw_breakpoints(void); |
| 118 | 118 | |
| 119 | 119 | void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg); |
| 120 | 120 | |
| 121 | +int kvm_check_extension(KVMState *s, unsigned int extension); | |
| 122 | + | |
| 121 | 123 | /* generic hooks - to be moved/refactored once there are more users */ |
| 122 | 124 | |
| 123 | 125 | static inline void cpu_synchronize_state(CPUState *env, int modified) | ... | ... |