From patchwork Thu Sep 3 14:47:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 7116971 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 57DF5BEEC1 for ; Thu, 3 Sep 2015 14:48:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83B752086B for ; Thu, 3 Sep 2015 14:48:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A3B52076D for ; Thu, 3 Sep 2015 14:48:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756464AbbICOsB (ORCPT ); Thu, 3 Sep 2015 10:48:01 -0400 Received: from foss.arm.com ([217.140.101.70]:40295 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755599AbbICOsA (ORCPT ); Thu, 3 Sep 2015 10:48:00 -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 5017975; Thu, 3 Sep 2015 07:48:05 -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 5E2063F23A; Thu, 3 Sep 2015 07:47:59 -0700 (PDT) From: Mark Rutland To: kvm@vger.kernel.org Cc: Mark Rutland , Marc Zyngier , Suzuki Poulose , Will Deacon Subject: [KVMTOOL][PATCHv2] Handle KVM_EXIT_SYSTEM_EVENT on any VCPU Date: Thu, 3 Sep 2015 15:47:47 +0100 Message-Id: <1441291667-13374-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=ham 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 tearing down all CPUs upon a system event, regardless of the CPU on which the event occurred. While this means the VCPU thread will signal itself, and VCPU #0 will signal all other VCPU threads a second time, these are harmless. Signed-off-by: Mark Rutland Cc: Marc Zyngier Cc: Suzuki Poulose Cc: Will Deacon --- kvm-cpu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) Since v1: * Per Suzuki's suggestion, use kvm_cpu__reboot() to tear down all CPUs, as PPC does for RTAS power off and reboot. diff --git a/kvm-cpu.c b/kvm-cpu.c index 5d90664..664795f 100644 --- a/kvm-cpu.c +++ b/kvm-cpu.c @@ -166,13 +166,18 @@ 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 all VCPUs are torn down, + * regardless of which CPU generated the event. + */ + kvm_cpu__reboot(cpu->kvm); goto exit_kvm; }; break;