From patchwork Wed Sep 2 10:50:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 7111241 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7B2459F32B for ; Wed, 2 Sep 2015 10:51:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 95588203AC for ; Wed, 2 Sep 2015 10:51:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A49A1203AA for ; Wed, 2 Sep 2015 10:51:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754474AbbIBKu7 (ORCPT ); Wed, 2 Sep 2015 06:50:59 -0400 Received: from foss.arm.com ([217.140.101.70]:35994 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754469AbbIBKu5 (ORCPT ); Wed, 2 Sep 2015 06:50:57 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8006D75; Wed, 2 Sep 2015 03:51:01 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BD5B93F5D5; Wed, 2 Sep 2015 03:50:56 -0700 (PDT) From: Mark Rutland To: kvm@vger.kernel.org Cc: Mark Rutland , Will Deacon , Marc Zyngier Subject: [KVMTOOL][PATCH] Handle KVM_EXIT_SYSTEM_EVENT on any VCPU Date: Wed, 2 Sep 2015 11:50:44 +0100 Message-Id: <1441191044-18777-1-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When VCPU #0 exits (e.g. due to KVM_EXIT_SYSTEM_EVENT), it sends SIGKVMEXIT to all other VCPUs, waits for them to exit, then tears down any remaining context. The signalling of SIGKVMEXIT is critical to forcing VCPUs to shut down in response to a system event (e.g. PSCI SYSTEM_OFF). VCPUs other that VCPU #0 simply exit in kvm_cpu_thread without forcing other CPUs to shut down. Thus if a system event is taken on a VCPU other than VCPU #0, the remaining CPUs are left online. This results in KVM tool not exiting as expected when a system event is taken on a VCPU other than VCPU #0 (as may happen if the guest panics). Fix this by signalling SIGKVMEXIT to VCPU #0 when a system event is taken on other CPUs, so that it may tear things down as usual. Signed-off-by: Mark Rutland Cc: Will Deacon Cc: Marc Zyngier --- kvm-cpu.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kvm-cpu.c b/kvm-cpu.c index 5d90664..f47e3db 100644 --- a/kvm-cpu.c +++ b/kvm-cpu.c @@ -166,13 +166,20 @@ int kvm_cpu__start(struct kvm_cpu *cpu) * treat all system events as shutdown request. */ switch (cpu->kvm_run->system_event.type) { - case KVM_SYSTEM_EVENT_RESET: - /* Fall through for now */ - case KVM_SYSTEM_EVENT_SHUTDOWN: - goto exit_kvm; default: pr_warning("unknown system event type %d", cpu->kvm_run->system_event.type); + /* fall through for now */ + case KVM_SYSTEM_EVENT_RESET: + /* Fall through for now */ + case KVM_SYSTEM_EVENT_SHUTDOWN: + /* + * Ensure that VCPU #0 tears everything down if + * the event was taken on a different VCPU. + */ + if (cpu->cpu_id != 0) + pthread_kill(cpu->kvm->cpus[0]->thread, + SIGKVMEXIT); goto exit_kvm; }; break;