From mboxrd@z Thu Jan 1 00:00:00 1970 From: Balbir Singh Subject: [KVMTOOL][PATCH 4/5] Fix a race during exit processing Date: Sun, 3 Apr 2016 20:38:01 +1000 Message-ID: <1459679882-30382-5-git-send-email-bsingharora@gmail.com> References: <1459679882-30382-1-git-send-email-bsingharora@gmail.com> Cc: mpe@ellerman.id.au, mikey@neuling.org, aik@ozlabs.ru, Balbir Singh To: will.deacon@arm.com, kvm@vger.kernel.org Return-path: Received: from mail-pf0-f176.google.com ([209.85.192.176]:35805 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752138AbcDCKiK (ORCPT ); Sun, 3 Apr 2016 06:38:10 -0400 Received: by mail-pf0-f176.google.com with SMTP id n1so18618343pfn.2 for ; Sun, 03 Apr 2016 03:38:09 -0700 (PDT) In-Reply-To: <1459679882-30382-1-git-send-email-bsingharora@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: Fix a race, described below lkvm stop ... handle_stop kvm_cpu__reboot kvm_cmd_run_exit vcpus exit ... dev_exit ... ioport__unregister ..serial... kvm__pause --> br_write_lock pthread_kill But the thread is already dead above. We mark the cpus as dying so that kvm_pause does nothing. This should not break any semantics Signed-off-by: Balbir Singh Acked-by: Michael Ellerman --- builtin-run.c | 3 +++ kvm.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/builtin-run.c b/builtin-run.c index 17b1428..cdc7158 100644 --- a/builtin-run.c +++ b/builtin-run.c @@ -58,6 +58,7 @@ __thread struct kvm_cpu *current_kvm_cpu; static int kvm_run_wrapper; bool do_debug_print = false; +int kvm_cmd_exit; static const char * const run_usage[] = { "lkvm run [] []", @@ -648,6 +649,7 @@ static void kvm_cmd_run_exit(struct kvm *kvm, int guest_ret) { compat__print_all_messages(); + kvm_cmd_exit = 1; init_list__exit(kvm); if (guest_ret == 0 && do_debug_print) @@ -659,6 +661,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) int ret = -EFAULT; struct kvm *kvm; + kvm_cmd_exit = 0; kvm = kvm_cmd_run_init(argc, argv); if (IS_ERR(kvm)) return PTR_ERR(kvm); diff --git a/kvm.c b/kvm.c index 1081072..53cf0e2 100644 --- a/kvm.c +++ b/kvm.c @@ -33,6 +33,8 @@ #define DEFINE_KVM_EXIT_REASON(reason) [reason] = #reason +extern int kvm_cmd_exit; + const char *kvm_exit_reasons[] = { DEFINE_KVM_EXIT_REASON(KVM_EXIT_UNKNOWN), DEFINE_KVM_EXIT_REASON(KVM_EXIT_EXCEPTION), @@ -435,6 +437,9 @@ void kvm__pause(struct kvm *kvm) if (!kvm->cpus[0] || kvm->cpus[0]->thread == 0) return; + if (kvm_cmd_exit) + return; + mutex_lock(&pause_lock); pause_event = eventfd(0, 0); -- 2.5.5