From patchwork Thu May 26 14:25:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 821042 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4QEQVul026399 for ; Thu, 26 May 2011 14:26:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932683Ab1EZO0M (ORCPT ); Thu, 26 May 2011 10:26:12 -0400 Received: from mail-ww0-f42.google.com ([74.125.82.42]:41711 "EHLO mail-ww0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932649Ab1EZO0I (ORCPT ); Thu, 26 May 2011 10:26:08 -0400 Received: by wwk4 with SMTP id 4so4506405wwk.1 for ; Thu, 26 May 2011 07:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=cvMfGCtLObDMOwBDE4eaULk1r+76J6N97U92OYPgoCM=; b=jfb7RrAL+xmUHxBuy2Nph7RqqkOJ5jykHIDn1VYj5NjcwzpAQBplIDY7MvgpuNE5M/ ZND1Bz9Dw6Mas906EizJLcsu4ZFo2/39FtBjAcDz6g4aR9UL4q1c5J6KXWOjwwhZ1fIJ 6rBFx+YHTBSVvPe3lWt9gwzu6WSt/pw+LjE8I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=oqn6rMNxJ9N8Aa0le1YB6ypvTf5zhIDhV7vezrI6hzWU6g36+nmtyPolYraK82gVax 0BCe0T2jbv3Ct4aI8+xQJE0j8bnGu0e+qUvyJnke594wDB+t5SUAwKMUzw0LqIlRlMTu qfDqnIp+oKUQo8FITwnIAijBOFu3C2aOOQ9xY= Received: by 10.227.159.136 with SMTP id j8mr894937wbx.99.1306419967632; Thu, 26 May 2011 07:26:07 -0700 (PDT) Received: from localhost.localdomain ([109.66.201.145]) by mx.google.com with ESMTPS id ej7sm506307wbb.19.2011.05.26.07.26.05 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 May 2011 07:26:07 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: john@jfloren.net, kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH 2/6] kvm tools: Exit VCPU thread only when SIGKVMEXIT is received Date: Thu, 26 May 2011 17:25:46 +0300 Message-Id: <1306419950-19064-2-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1306419950-19064-1-git-send-email-levinsasha928@gmail.com> References: <1306419950-19064-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 26 May 2011 14:26:31 +0000 (UTC) Currently the VCPU loop would exit when the thread received any signal. Change behaviour to exit only when SIGKVMEXIT is received. This change prevents from the guest to terminate when unrelated signals are processed by the thread (for example, when attaching a debugger). Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/kvm-cpu.h | 2 ++ tools/kvm/kvm-cpu.c | 15 ++++++++++----- tools/kvm/kvm-run.c | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/kvm/include/kvm/kvm-cpu.h b/tools/kvm/include/kvm/kvm-cpu.h index f241e86..b2b6fce 100644 --- a/tools/kvm/include/kvm/kvm-cpu.h +++ b/tools/kvm/include/kvm/kvm-cpu.h @@ -21,6 +21,8 @@ struct kvm_cpu { struct kvm_fpu fpu; struct kvm_msrs *msrs; /* dynamically allocated */ + + u8 is_running; }; struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id); diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c index 331e025..de0591f 100644 --- a/tools/kvm/kvm-cpu.c +++ b/tools/kvm/kvm-cpu.c @@ -14,6 +14,8 @@ #include #include +extern __thread struct kvm_cpu *current_kvm_cpu; + static inline bool is_in_protected_mode(struct kvm_cpu *vcpu) { return vcpu->sregs.cr0 & 0x01; @@ -87,6 +89,8 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id) if (vcpu->kvm_run == MAP_FAILED) die("unable to mmap vcpu fd"); + vcpu->is_running = true; + return vcpu; } @@ -381,7 +385,10 @@ void kvm_cpu__run(struct kvm_cpu *vcpu) static void kvm_cpu_exit_handler(int signum) { - /* Don't do anything here */ + if (current_kvm_cpu->is_running) { + current_kvm_cpu->is_running = false; + pthread_kill(pthread_self(), SIGKVMEXIT); + } } int kvm_cpu__start(struct kvm_cpu *cpu) @@ -437,10 +444,8 @@ int kvm_cpu__start(struct kvm_cpu *cpu) break; } case KVM_EXIT_INTR: - /* - * Currently we only handle exit signal, which means - * we just exit if KVM_RUN exited due to a signal. - */ + if (cpu->is_running) + break; goto exit_kvm; case KVM_EXIT_SHUTDOWN: goto exit_kvm; diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index adbb25b..d757761 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -48,7 +48,7 @@ static struct kvm *kvm; static struct kvm_cpu *kvm_cpus[KVM_NR_CPUS]; -static __thread struct kvm_cpu *current_kvm_cpu; +__thread struct kvm_cpu *current_kvm_cpu; static u64 ram_size; static u8 image_count;