KVM: Retry KVM_CREATE_VM on EINTR

Upstreaming this change from Android (https://android-review.googlesource.com/54211).

On heavily loaded machines with many VM instances we see KVM_CREATE_VM
failing with EINTR on this path:

kvm_dev_ioctl_create_vm -> kvm_create_vm -> kvm_init_mmu_notifier -> mmu_notifier_register ->  do_mmu_notifier_register -> mm_take_all_locks

which checks if any signals have been raised while it was attaining locks
and returns EINTR.  Retrying the system call greatly improves reliability.

Cc: qemu-stable@nongnu.org
Signed-off-by: thomas knych <thomaswk@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
thomas knych 2014-01-09 13:14:23 -08:00 committed by Paolo Bonzini
parent 2ba8285289
commit 94ccff1338
1 changed files with 9 additions and 3 deletions

View File

@ -1442,16 +1442,22 @@ int kvm_init(void)
nc++; nc++;
} }
s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0); do {
if (s->vmfd < 0) { ret = kvm_ioctl(s, KVM_CREATE_VM, 0);
} while (ret == -EINTR);
if (ret < 0) {
fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -s->vmfd,
strerror(-ret));
#ifdef TARGET_S390X #ifdef TARGET_S390X
fprintf(stderr, "Please add the 'switch_amode' kernel parameter to " fprintf(stderr, "Please add the 'switch_amode' kernel parameter to "
"your host kernel command line\n"); "your host kernel command line\n");
#endif #endif
ret = s->vmfd;
goto err; goto err;
} }
s->vmfd = ret;
missing_cap = kvm_check_extension_list(s, kvm_required_capabilites); missing_cap = kvm_check_extension_list(s, kvm_required_capabilites);
if (!missing_cap) { if (!missing_cap) {
missing_cap = missing_cap =