From patchwork Thu Jan 24 11:16:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 10778747 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 2D02413BF for ; Thu, 24 Jan 2019 11:17:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CE362EA87 for ; Thu, 24 Jan 2019 11:17:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 112122EB51; Thu, 24 Jan 2019 11:17:02 +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 A65492EA87 for ; Thu, 24 Jan 2019 11:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727587AbfAXLRA (ORCPT ); Thu, 24 Jan 2019 06:17:00 -0500 Received: from foss.arm.com ([217.140.101.70]:54760 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbfAXLRA (ORCPT ); Thu, 24 Jan 2019 06:17:00 -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 4332C1650; Thu, 24 Jan 2019 03:17:00 -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 3400A3F237; Thu, 24 Jan 2019 03:16:59 -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 1/7] lib: arm: Discover ns16550a UART Date: Thu, 24 Jan 2019 11:16:28 +0000 Message-Id: <20190124111634.4727-2-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 Add support for discovering the ns16550a UART from the device tree. This particular UART model is emulated by kvmtool. Signed-off-by: Alexandru Elisei Reviewed-by: Andre Przywara --- lib/arm/io.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/arm/io.c b/lib/arm/io.c index d2c1a07c19ee..35fc05aeb4db 100644 --- a/lib/arm/io.c +++ b/lib/arm/io.c @@ -32,22 +32,26 @@ static volatile u8 *uart0_base = (u8 *)UART_EARLY_BASE; static void uart0_init(void) { - const char *compatible = "arm,pl011"; + const char *compatible[] = {"arm,pl011", "ns16550a"}; struct dt_pbus_reg base; - int ret; + int i, ret; ret = dt_get_default_console_node(); assert(ret >= 0 || ret == -FDT_ERR_NOTFOUND); if (ret == -FDT_ERR_NOTFOUND) { - ret = dt_pbus_get_base_compatible(compatible, &base); - assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); + for (i = 0; i < ARRAY_SIZE(compatible); i++) { + ret = dt_pbus_get_base_compatible(compatible[i], &base); + assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); + + if (ret == 0) + break; + } if (ret) { - printf("%s: %s not found in the device tree, " - "aborting...\n", - __func__, compatible); + printf("%s: Compatible UART not found in the device tree, " + "aborting...\n", __func__); abort(); } From patchwork Thu Jan 24 11:16:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 10778749 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 B64F313BF for ; Thu, 24 Jan 2019 11:17:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6C792EA87 for ; Thu, 24 Jan 2019 11:17:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AB212EB83; Thu, 24 Jan 2019 11:17:05 +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 4E61A2EA87 for ; Thu, 24 Jan 2019 11:17:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727622AbfAXLRC (ORCPT ); Thu, 24 Jan 2019 06:17:02 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:54770 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbfAXLRB (ORCPT ); Thu, 24 Jan 2019 06:17:01 -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 97C5B165C; Thu, 24 Jan 2019 03:17:01 -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 7F8443F237; Thu, 24 Jan 2019 03:17:00 -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 2/7] lib: arm: Remove warning about uart0_base mismatch Date: Thu, 24 Jan 2019 11:16:29 +0000 Message-Id: <20190124111634.4727-3-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 A warning is displayed if uart0_base is different from what the code expects qemu to generate for the pl011 UART in the device tree. However, now we support the ns16550a UART emulated by kvmtool, which has a different address. This leads to the warning being displayed even though the UART is configured and working as expected. Now that we support multiple UARTs, the warning serves no purpose, so remove it. Signed-off-by: Alexandru Elisei --- lib/arm/io.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/arm/io.c b/lib/arm/io.c index 35fc05aeb4db..87435150f73e 100644 --- a/lib/arm/io.c +++ b/lib/arm/io.c @@ -61,12 +61,6 @@ static void uart0_init(void) } uart0_base = ioremap(base.addr, base.size); - - if (uart0_base != (u8 *)UART_EARLY_BASE) { - printf("WARNING: early print support may not work. " - "Found uart at %p, but early base is %p.\n", - uart0_base, (u8 *)UART_EARLY_BASE); - } } void io_init(void) From patchwork Thu Jan 24 11:16:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 10778751 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 E1E3F13B5 for ; Thu, 24 Jan 2019 11:17:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1F7E2E9D4 for ; Thu, 24 Jan 2019 11:17:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C65072EB51; Thu, 24 Jan 2019 11:17:05 +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 6F1062E9D4 for ; Thu, 24 Jan 2019 11:17:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727624AbfAXLRD (ORCPT ); Thu, 24 Jan 2019 06:17:03 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:54778 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727633AbfAXLRD (ORCPT ); Thu, 24 Jan 2019 06:17:03 -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 E52391596; Thu, 24 Jan 2019 03:17:02 -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 D447C3F237; Thu, 24 Jan 2019 03:17:01 -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 3/7] lib: chr-testdev: Make chr_testdev_init() return status Date: Thu, 24 Jan 2019 11:16:30 +0000 Message-Id: <20190124111634.4727-4-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 Make chr_testdev_init() return 0 (success) if the virtio console was initialized properly, otherwise return -1 (failure). Signed-off-by: Alexandru Elisei --- lib/chr-testdev.h | 2 +- lib/chr-testdev.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/chr-testdev.h b/lib/chr-testdev.h index ffd9a851aa9b..fdd0582e2da1 100644 --- a/lib/chr-testdev.h +++ b/lib/chr-testdev.h @@ -9,6 +9,6 @@ * * This work is licensed under the terms of the GNU LGPL, version 2. */ -extern void chr_testdev_init(void); +extern int chr_testdev_init(void); extern void chr_testdev_exit(int code); #endif diff --git a/lib/chr-testdev.c b/lib/chr-testdev.c index 6890f63c8b29..26e14301e3db 100644 --- a/lib/chr-testdev.c +++ b/lib/chr-testdev.c @@ -47,7 +47,7 @@ out: spin_unlock(&lock); } -void chr_testdev_init(void) +int chr_testdev_init(void) { const char *io_names[] = { "input", "output" }; struct virtqueue *vqs[2]; @@ -57,7 +57,7 @@ void chr_testdev_init(void) if (vcon == NULL) { printf("%s: %s: can't find a virtio-console\n", __func__, TESTDEV_NAME); - return; + return -1; } ret = vcon->config->find_vqs(vcon, 2, vqs, NULL, io_names); @@ -65,9 +65,11 @@ void chr_testdev_init(void) printf("%s: %s: can't init virtqueues\n", __func__, TESTDEV_NAME); vcon = NULL; - return; + return -1; } in_vq = vqs[0]; out_vq = vqs[1]; + + return 0; } From patchwork Thu Jan 24 11:16:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 10778753 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 3706213B5 for ; Thu, 24 Jan 2019 11:17:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 271892E9D4 for ; Thu, 24 Jan 2019 11:17:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B60A2EB51; Thu, 24 Jan 2019 11:17:07 +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 BF6C32E9D4 for ; Thu, 24 Jan 2019 11:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727698AbfAXLRE (ORCPT ); Thu, 24 Jan 2019 06:17:04 -0500 Received: from foss.arm.com ([217.140.101.70]:54794 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727661AbfAXLRE (ORCPT ); Thu, 24 Jan 2019 06:17:04 -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 3B1E11650; Thu, 24 Jan 2019 03:17:04 -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 2C2693F237; Thu, 24 Jan 2019 03:17:03 -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 4/7] lib: arm: Implement PSCI SYSTEM_OFF in psci_system_off() Date: Thu, 24 Jan 2019 11:16:31 +0000 Message-Id: <20190124111634.4727-5-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 A new function psci_system_off() is added which implements the PSCI SYSTEM_OFF function. A call causes the hypervisor to terminate the virtual machine. Consumers for the function will be added in a later patch. Signed-off-by: Alexandru Elisei --- lib/arm/asm/psci.h | 1 + lib/arm/psci.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/arm/asm/psci.h b/lib/arm/asm/psci.h index ed51708fd265..93409996349a 100644 --- a/lib/arm/asm/psci.h +++ b/lib/arm/asm/psci.h @@ -9,5 +9,6 @@ extern int psci_cpu_on(unsigned long cpuid, unsigned long entry_point); extern void psci_sys_reset(void); extern int cpu_psci_cpu_boot(unsigned int cpu); extern void cpu_psci_cpu_die(void); +extern void psci_system_off(void); #endif /* _ASMARM_PSCI_H_ */ diff --git a/lib/arm/psci.c b/lib/arm/psci.c index 119f74e57e91..d8dc428e8e8b 100644 --- a/lib/arm/psci.c +++ b/lib/arm/psci.c @@ -48,6 +48,12 @@ void cpu_psci_cpu_die(void) printf("CPU%d unable to power off (error = %d)\n", smp_processor_id(), err); } +void psci_system_off(void) +{ + int err = psci_invoke(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); + printf("CPU%d unable to do system off (error = %d)\n", smp_processor_id(), err); +} + void psci_sys_reset(void) { psci_invoke(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0); 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(); } From patchwork Thu Jan 24 11:16:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 10778755 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 1E04413B5 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 0D35F2E974 for ; Thu, 24 Jan 2019 11:17:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01F2F2E9D4; Thu, 24 Jan 2019 11:17:09 +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 AAAA62EB51 for ; Thu, 24 Jan 2019 11:17:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726105AbfAXLRI (ORCPT ); Thu, 24 Jan 2019 06:17:08 -0500 Received: from foss.arm.com ([217.140.101.70]:54808 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbfAXLRH (ORCPT ); Thu, 24 Jan 2019 06:17:07 -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 DBA941596; Thu, 24 Jan 2019 03:17:06 -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 C37AC3F237; Thu, 24 Jan 2019 03:17:05 -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 6/7] lib: argv: Implement argv_find() for test parameters Date: Thu, 24 Jan 2019 11:16:33 +0000 Message-Id: <20190124111634.4727-7-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 The current behavior when searching for a specific parameter is to exit with an error when the first unexpected parameter is found. The function argv_find() will search for a specific parameter, ignoring all other parameters. Consumers for the function will be added in a later patch. Signed-off-by: Alexandru Elisei --- lib/argv.h | 1 + lib/argv.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/argv.h b/lib/argv.h index 2104dd42748d..efc390ae4fae 100644 --- a/lib/argv.h +++ b/lib/argv.h @@ -8,3 +8,4 @@ extern void __setup_args(void); extern void setup_args_progname(const char *args); extern void setup_env(char *env, int size); +extern int argv_find(const char *needle, int argc, char **argv); diff --git a/lib/argv.c b/lib/argv.c index f0e183a8f02f..6e4593997e0b 100644 --- a/lib/argv.c +++ b/lib/argv.c @@ -144,3 +144,14 @@ void setup_env(char *env, int size) *env++ = '\0'; } } + +int argv_find(const char *needle, int argc, char **argv) +{ + int i; + + for (i = 0; i < argc; i++) + if (strcmp(argv[i], needle) == 0) + return i; + + return -1; +} From patchwork Thu Jan 24 11:16:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 10778759 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 434DE13BF for ; Thu, 24 Jan 2019 11:17:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 328E32E974 for ; Thu, 24 Jan 2019 11:17:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26D0E2EA87; Thu, 24 Jan 2019 11:17:12 +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 A52682E974 for ; Thu, 24 Jan 2019 11:17:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727719AbfAXLRK (ORCPT ); Thu, 24 Jan 2019 06:17:10 -0500 Received: from foss.arm.com ([217.140.101.70]:54822 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727639AbfAXLRI (ORCPT ); Thu, 24 Jan 2019 06:17:08 -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 32D4D1650; Thu, 24 Jan 2019 03:17:08 -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 240073F614; Thu, 24 Jan 2019 03:17:07 -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 7/7] arm/arm64: Use argv_find() for test names Date: Thu, 24 Jan 2019 11:16:34 +0000 Message-Id: <20190124111634.4727-8-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 Instead of aborting the test when an unexpected parameter is found, use argv_find() to search for the desired parameter. On arm and arm64, this allows kvm-unit-tests to be used with virtual machine monitors like kvmtool which automatically adds parameters to the kernel command line. For example, to run the gicv3-ipi test the following command was used: lkvm run -k gic.flat -c 8 -m 410 -p "ipi" --irqchip=gicv3 The resulting kernel command line that was passed to kvm-unit-tests was: "console=ttyS0 rw rootflags=trans=virtio,version=9p2000.L,cache=loose rootfstype=9p init=/virt/init ip=dhcp ipi" Without the patch, the following error occurs: "ABORT: gicv3: Unknown subtest 'console=ttyS0'" With the patch, the test is able to run. Signed-off-by: Alexandru Elisei --- arm/gic.c | 7 ++++--- arm/selftest.c | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/arm/gic.c b/arm/gic.c index ed5642e74f70..f3746de4bfd8 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -12,6 +12,7 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ #include +#include #include #include #include @@ -533,13 +534,13 @@ int main(int argc, char **argv) if (argc < 2) report_abort("no test specified"); - if (strcmp(argv[1], "ipi") == 0) { + if (argv_find("ipi", argc, argv) != -1) { report_prefix_push(argv[1]); nr_cpu_check(2); on_cpus(ipi_test, NULL); - } else if (strcmp(argv[1], "active") == 0) { + } else if (argv_find("active", argc, argv) != -1) { run_active_clear_test(); - } else if (strcmp(argv[1], "mmio") == 0) { + } else if (argv_find("mmio", argc, argv) != -1) { report_prefix_push(argv[1]); gic_test_mmio(); report_prefix_pop(); diff --git a/arm/selftest.c b/arm/selftest.c index ea5101ef7217..44b2f23ca115 100644 --- a/arm/selftest.c +++ b/arm/selftest.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -319,28 +320,32 @@ static void cpu_report(void *data __unused) int main(int argc, char **argv) { + int pos; + report_prefix_push("selftest"); if (argc < 2) report_abort("no test specified"); - report_prefix_push(argv[1]); - - if (strcmp(argv[1], "setup") == 0) { + if ((pos = argv_find("setup", argc, argv)) != -1) { - check_setup(argc-2, &argv[2]); + report_prefix_push("setup"); + check_setup(argc-(pos+1), &argv[pos+1]); - } else if (strcmp(argv[1], "vectors-kernel") == 0) { + } else if (argv_find("vectors-kernel", argc, argv) != -1) { + report_prefix_push("vectors-kernel"); check_vectors(NULL); - } else if (strcmp(argv[1], "vectors-user") == 0) { + } else if (argv_find("vectors-user", argc, argv) != -1) { + report_prefix_push("vectors-user"); start_usr(check_vectors, NULL, (unsigned long)thread_stack_alloc()); - } else if (strcmp(argv[1], "smp") == 0) { + } else if (argv_find("smp", argc, argv) != -1) { + report_prefix_push("smp"); report("PSCI version", psci_check()); on_cpus(cpu_report, NULL);