From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5G5n-0004MG-QA for qemu-devel@nongnu.org; Mon, 20 Jan 2014 09:44:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W5G5h-0006FS-BB for qemu-devel@nongnu.org; Mon, 20 Jan 2014 09:44:47 -0500 From: Paolo Bonzini Date: Mon, 20 Jan 2014 15:44:09 +0100 Message-Id: <1390229051-28635-8-git-send-email-pbonzini@redhat.com> In-Reply-To: <1390229051-28635-1-git-send-email-pbonzini@redhat.com> References: <1390229051-28635-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 7/9] KVM: Retry KVM_CREATE_VM on EINTR List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: gleb@kernel.org, thomas knych , mtosatti@redhat.com, qemu-stable@nongnu.org From: thomas knych 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 Signed-off-by: Paolo Bonzini --- kvm-all.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 3937754..6df2ee1 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1442,16 +1442,22 @@ int kvm_init(void) nc++; } - s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0); - if (s->vmfd < 0) { + do { + 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 fprintf(stderr, "Please add the 'switch_amode' kernel parameter to " "your host kernel command line\n"); #endif - ret = s->vmfd; goto err; } + s->vmfd = ret; missing_cap = kvm_check_extension_list(s, kvm_required_capabilites); if (!missing_cap) { missing_cap = -- 1.8.3.1