From patchwork Thu Jan 24 11:16:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 10778757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F05DC13B5 for ; Thu, 24 Jan 2019 11:17:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E033C2E974 for ; Thu, 24 Jan 2019 11:17:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4B452EA87; Thu, 24 Jan 2019 11:17:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 791EF2E974 for ; Thu, 24 Jan 2019 11:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727682AbfAXLRG (ORCPT ); Thu, 24 Jan 2019 06:17:06 -0500 Received: from foss.arm.com ([217.140.101.70]:54800 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbfAXLRG (ORCPT ); Thu, 24 Jan 2019 06:17:06 -0500 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 86CD91596; Thu, 24 Jan 2019 03:17:05 -0800 (PST) Received: from login12.euhpc.arm.com (login12.euhpc.arm.com [10.6.27.168]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 77A373F237; Thu, 24 Jan 2019 03:17:04 -0800 (PST) From: Alexandru Elisei To: kvm@vger.kernel.org Cc: drjones@redhat.com, kvmarm@lists.cs.columbia.edu, andre.przywara@arm.com, vladimir.murzin@arm.com Subject: [kvm-unit-tests PATCH 5/7] lib: arm: Fallback to psci_system_off() in exit() Date: Thu, 24 Jan 2019 11:16:32 +0000 Message-Id: <20190124111634.4727-6-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190124111634.4727-1-alexandru.elisei@arm.com> References: <20190124111634.4727-1-alexandru.elisei@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On arm and arm64, kvm-unit-tests uses the QEMU chr-testdev device to shut down the virtual machine at the end of a test. The function psci_system_off() provides another mechanism for terminating the virtual machine. If the chr-testdev device hasn't been initialized successfully, then use psci_system_off() to terminate the test instead of chr_testdev_exit(). chr-testdev is implemented on top of virtio console. This patch makes it possible for a virtual machine manager which doesn't have support for chr-testdev, but has been configured not to emulate a virtio console, to gracefully terminate a virtual machine after a test has been completed. There is one limitation to using psci_system_off() to terminate a test: chr-testdev allows kvm-unit-tests to specify an exit code; psci_system_off() has no such mechanism. Signed-off-by: Alexandru Elisei --- lib/arm/io.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/arm/io.c b/lib/arm/io.c index 87435150f73e..9fe9bd0bf659 100644 --- a/lib/arm/io.c +++ b/lib/arm/io.c @@ -11,6 +11,7 @@ #include #include #include +#include "arm/asm/psci.h" #include #include @@ -18,6 +19,8 @@ extern void halt(int code); +static bool testdev_enabled; + /* * Use this guess for the pl011 base in order to make an attempt at * having earlier printf support. We'll overwrite it with the real @@ -65,8 +68,12 @@ static void uart0_init(void) void io_init(void) { + int err; + uart0_init(); - chr_testdev_init(); + err = chr_testdev_init(); + if (!err) + testdev_enabled = true; } void puts(const char *s) @@ -79,7 +86,10 @@ void puts(const char *s) void exit(int code) { - chr_testdev_exit(code); + if (testdev_enabled) + chr_testdev_exit(code); + else + psci_system_off(); halt(code); __builtin_unreachable(); }