From patchwork Wed Nov 11 23:29:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1398601 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=MGJDrWpn; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CWgwS2Bfhz9sPB for ; Thu, 12 Nov 2020 10:31:20 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2B6728256D; Thu, 12 Nov 2020 00:30:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="MGJDrWpn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C767782526; Thu, 12 Nov 2020 00:30:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3F34282522 for ; Thu, 12 Nov 2020 00:30:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1605137417; bh=AQ1J36XEe1qZNK/MLba0Na5CVwY2AVVdF9pGxMMpS58=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=MGJDrWpnlSUqlAwIjvPazUo845LLMI2z5QXre5BO8imXoUAOy7AxYWZidkIsj2FlO 55rz+sCpck1TP41tqv3o5bFhw3cM8i5f1SM4/nqWUE6HkHODROJ3FI58iAtGqhdKUz cLxoLJ4R3aUpyfHn4o20s/PUxjHdTMCvi6VZ94xk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([178.202.41.135]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1Mf07E-1k6fxL2A26-00gaZF; Thu, 12 Nov 2020 00:30:17 +0100 From: Heinrich Schuchardt To: Simon Glass Cc: u-boot@lists.denx.de, Alexander Graf , Heinrich Schuchardt Subject: [PATCH v2 1/4] sandbox: add handler for exceptions Date: Thu, 12 Nov 2020 00:29:56 +0100 Message-Id: <20201111232959.11241-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201111232959.11241-1-xypron.glpk@gmx.de> References: <20201111232959.11241-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+npr6DMqH5/ioRyvdwPH80YFj40k0EmefSXC+tra4DOZxphTFPe ln2ZHAh4K7fzzlsBpqnM22JcuuOKqF0ddQaHpCUaLWdfpZhxpBcETeEgBei86fTsYA1jaR7 RKN3t+PNC7ziGAW4pDqF/Pm/iiXGdK/jQdKhTRyizoFBTNtwvXn9q11tfK/Ff1ULhMS3SdG 7dPr7BHyqxmHji1TIrYyg== X-UI-Out-Filterresults: notjunk:1;V03:K0:wEZG28YAFxY=:ds7dS2rlkz+smecxrMOY9Q HiTy3xe+d10vXYGwJsKDCRGdMB0VUYw+CBctTwpNxRqdFHUtDMgZotAamWuM8T1zMVMZHeb6T UPSERBJc6pHmrkAJCu+GKEyJuFIFxS+yA04Z46VzFHS2XFdfFRuUTb/qRJrIbu5Kr+RYEtdLl IHENw5keRnKXczAelcsQ9xbevkgSgfJ3Gfm7SX0DeXJtDHRn99EsDWC28KIDSGjxHpIzfExb7 zMj7UxmSXRZJ1fG6ktZN47wszhkNPS+OCIQa5V8rww2rfDx3t8dJ2DIQhnRz/n3kuZj6tfusj 4n8r4CKs6U0eZBHbWiNqlBveYomfgzd7dn8u+zHSXI3TAlfmTeIzWge9W5/z7ByT7uHJPKE0I 8TJ0kZLj3k8Fj82CLILov3kM4xya+f70A1niq3uTV/7boZ3KGoMBicdSkRCMQu7NZ0HqB0ZUN dWQH/4zj/Dyrme8WYkdsBzHmGMitySlk6+AulBaN2XpUjTBdhkpJJhtlURnGoYx+l92I5+UOy 3UiwmP/IrKQGYPa5neeIenxXAMrAXRpWedf3ZubOR6rD04wOOPAcGlSmcSplJxfrmFoB4KMlW TnWHlM/Dzung2c61+YWLlXSytM07AgVtOK6wCyU1gt+g2kYu00wiRFD+dbEP66aNR5p4gUnTq dZKXP4EvJPr+Cyv2AjVPIKIpAZY9GzT0qy0cHJ1M4H8uc1P55vEwS35KxlhRF860bLfvQFWB/ VmsW90U5rU+N51RhWxdoX6JendR0unzC20+DqW504O/zRnC8p7ZkjFaACvQlSjI2E38+++ueS fvxy7haydEJyhKUOGuOgVTNeZer6GuthUqm3NpMj/b1Vy8VPcF6JsEzG6tqmWo9cLGhHA1LpH RmxvZTXDFfKR2U7Of1Vw== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Add a handler for SIGILL, SIGBUS, SIGSEGV. When an exception occurs print the program counter and the loaded UEFI binaries and reset the system if CONFIG_SANDBOX_CRASH_RESET=y or exit to the OS otherwise. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- v2: add a customizing switch set SA_NODEFER flag for sigaction --- arch/sandbox/Kconfig | 9 ++++++++ arch/sandbox/cpu/os.c | 40 +++++++++++++++++++++++++++++++++++ arch/sandbox/cpu/start.c | 4 ++++ arch/sandbox/lib/interrupts.c | 35 ++++++++++++++++++++++++++++++ include/os.h | 17 +++++++++++++++ 5 files changed, 105 insertions(+) -- 2.28.0 diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig index 65f988e736..f83282d9d5 100644 --- a/arch/sandbox/Kconfig +++ b/arch/sandbox/Kconfig @@ -51,6 +51,15 @@ config HOST_64BIT endchoice +config SANDBOX_CRASH_RESET + bool "Reset on crash" + help + If an illegal instruction or an illegal memory access occurs, the + sandbox by default writes a crash dump and exits. If you set this + flag, the sandbox is reset instead. This may be useful when running + test suites like the UEFI self certification test which continue + with the next test after a crash. + config SANDBOX_BITS_PER_LONG int default 32 if HOST_32BIT diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 0d8efd83f6..b56fa04a34 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -3,6 +3,8 @@ * Copyright (c) 2011 The Chromium OS Authors. */ +#define _GNU_SOURCE + #include #include #include @@ -15,11 +17,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -191,6 +195,42 @@ static void os_sigint_handler(int sig) raise(SIGINT); } +static void os_signal_handler(int sig, siginfo_t *info, void *con) +{ + ucontext_t __maybe_unused *context = con; + unsigned long pc; + +#if defined(__x86_64__) + pc = context->uc_mcontext.gregs[REG_RIP]; +#elif defined(__aarch64__) + pc = context->uc_mcontext.pc; +#elif defined(__riscv) + pc = context->uc_mcontext.__gregs[REG_PC]; +#else + const char msg[] = + "\nUnsupported architecture, cannot read program counter\n"; + + os_write(1, msg, sizeof(msg)); + pc = 0; +#endif + + os_signal_action(sig, pc); +} + +int os_setup_signal_handlers(void) +{ + struct sigaction act; + + act.sa_sigaction = os_signal_handler; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO | SA_NODEFER; + if (sigaction(SIGILL, &act, NULL) || + sigaction(SIGBUS, &act, NULL) || + sigaction(SIGSEGV, &act, NULL)) + return -1; + return 0; +} + /* Put tty into raw mode so and work */ void os_tty_raw(int fd, bool allow_sigs) { diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index a03e5aa0b3..f6c98545e0 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -451,6 +451,10 @@ int main(int argc, char *argv[]) if (ret) goto err; + ret = os_setup_signal_handlers(); + if (ret) + goto err; + #if CONFIG_VAL(SYS_MALLOC_F_LEN) gd->malloc_base = CONFIG_MALLOC_F_ADDR; #endif diff --git a/arch/sandbox/lib/interrupts.c b/arch/sandbox/lib/interrupts.c index 21f761ac3b..9c2c60b8c6 100644 --- a/arch/sandbox/lib/interrupts.c +++ b/arch/sandbox/lib/interrupts.c @@ -6,7 +6,13 @@ */ #include +#include #include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; int interrupt_init(void) { @@ -21,3 +27,32 @@ int disable_interrupts(void) { return 0; } + +void os_signal_action(int sig, unsigned long pc) +{ + efi_restore_gd(); + + switch (sig) { + case SIGILL: + printf("\nIllegal instruction\n"); + break; + case SIGBUS: + printf("\nBus error\n"); + break; + case SIGSEGV: + printf("\nSegmentation violation\n"); + break; + default: + break; + } + printf("pc = 0x%lx, ", pc); + printf("pc_reloc = 0x%lx\n\n", pc - gd->reloc_off); + efi_print_image_infos((void *)pc); + + if (IS_ENABLED(CONFIG_SANDBOX_CRASH_RESET)) { + printf("resetting ...\n\n"); + sandbox_reset(); + } else { + sandbox_exit(); + } +} diff --git a/include/os.h b/include/os.h index 1fe44f3510..0913b47b3a 100644 --- a/include/os.h +++ b/include/os.h @@ -407,4 +407,21 @@ void *os_find_text_base(void); */ void os_relaunch(char *argv[]); +/** + * os_setup_signal_handlers() - setup signal handlers + * + * Install signal handlers for SIGBUS and SIGSEGV. + * + * Return: 0 for success + */ +int os_setup_signal_handlers(void); + +/** + * os_signal_action() - handle a signal + * + * @sig: signal + * @pc: program counter + */ +void os_signal_action(int sig, unsigned long pc); + #endif From patchwork Wed Nov 11 23:29:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1398597 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=ZVNkkV/l; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CWgvX6lq3z9sPB for ; Thu, 12 Nov 2020 10:30:32 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AB3B8823F4; Thu, 12 Nov 2020 00:30:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="ZVNkkV/l"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DAE5B8252A; Thu, 12 Nov 2020 00:30:23 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C141282384 for ; Thu, 12 Nov 2020 00:30:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1605137418; bh=8E52/mQPfeGRIZLULx4Aey+l4P9paSewFTcsvN6qmK8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ZVNkkV/lOphBPN8Lzzavz95QoK2w22dgmfSNrP7jHCI5NYq0Pd0GGP8ZS9yAj4pPx 6cC4D4gpgy6vgima+ETiMpQXBniGEF0voAH9s/METcZ8c194HR+mYuJ5nfi6u8PTDD leT5lCQmJWlUxWjt9dFiUvWrOBk+HKXQmVb1CRL8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([178.202.41.135]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M6llE-1kedCJ3C4E-008MDF; Thu, 12 Nov 2020 00:30:17 +0100 From: Heinrich Schuchardt To: Simon Glass Cc: u-boot@lists.denx.de, Alexander Graf , Heinrich Schuchardt Subject: [PATCH v2 2/4] cmd: sandbox: implement exception command Date: Thu, 12 Nov 2020 00:29:57 +0100 Message-Id: <20201111232959.11241-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201111232959.11241-1-xypron.glpk@gmx.de> References: <20201111232959.11241-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:zVSYCw74B+oNismueI2KGlfKU4/TbcZ9DtmaBn6V3fY9UWWM9H5 hhN22W11N7rHUL2r5GUCTpp90qMTukGUiFEpqYlUX6g+twhlCJOrD8Wv01WVHu2EjV6AF0D CNzzmuGmEdG+uYQS8DpCbjXB/mUJaExy/ho9VGlPkz8tDT11RLSj/feNQdFaLRyperUQYYc qhzicCzYtcjOAHyfkOjNw== X-UI-Out-Filterresults: notjunk:1;V03:K0:cKNPT0cPz9w=:SRvYQNR48H0dXgU4y6qSk9 qv92+PVLOoyAHs1rInoBsOM84o3RjEGMa1Lkl4YYKlz7n+pVLzJZEPTHevAsSkOZligdN6wo7 uwIPj1rqlvg7Pc+lUXmBzRvayRv6ddfe6rcbMjfDql8ryUFshLNeiwOZHgJXFQKElIxNYU+Dm +OZe3MIAfGYZLsKlV49eEidU8kCOkuRHb5vKclI/X6K802e36W0FsTIVL9LU8+6Tut9tWzHpi /Q/qCUbzsMCzE/Lxp6fq2hTUyFpZN3x2KeODieyUM2M5+8nhuOxr1iYzTya2Pn5M31gXCl9qQ v1t9lJqCNqssv34vTgQQxJMPc8nK1CAbspD78drs4g24e0vuAbvVJiZnk5AGu+tu3hsi3o1zI fCCKkJzh7Jl4qC+zhPKVqv8fKGw0fehKcsszmEnCRQgjWAT6X4yJ6DgHyt8Zb5P9NsvMlJT00 cjvUqIzZetAXuTrDd8cpJt+vtmwgi/N/xpTs0Ge3P18PcW64aERUc1CQ141sXWwTd66voKL/F xl/KMoBHKaoTTg4SOm7bPeiT+nwPwBDXpuxZRoH6VfBSbWiv1a88WpZ+gNmmZdCcuoBHHpGM+ G7Bn4faEekWk+eKJqkIHCcB3grSG4qLNfdxUZjR71eHOriHBzbKP+koGAXeqi6QdmztGfUKBq CMALqgEgq0oSNkNB9bp1ZRxa+8hwLTA6tVuqgd7uhUn2Qo3bEmSpR8m7v0CjgBvlv3K5Vfe6/ 9Ls2mm4UToUQhO+U/zrB562nQwD7zpFwbhBIMi0ceRbOcx47ZP3ruZg1xbUIbb1slP4BhmIGc 8ntqR9tcLqB64CwjQByT458muuY0+c24m5NH6U7Z02qJ+ZImal17U97to0WC3JwAHGOQbJhoD EjeC0lWltm5m8B6MaIiw== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Implement the commands * exception undefined - execute an illegal instruction * exception sigsegv - cause a segment violation Here is a possible output: => exception undefined Illegal instruction pc = 0x55eb8d0a7575, pc_reloc = 0x57575 Resetting ... Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- v2: no change --- cmd/Kconfig | 2 +- cmd/Makefile | 1 + cmd/sandbox/Makefile | 3 +++ cmd/sandbox/exception.c | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 cmd/sandbox/Makefile create mode 100644 cmd/sandbox/exception.c -- 2.28.0 diff --git a/cmd/Kconfig b/cmd/Kconfig index 1595de999b..f9b72449c5 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1682,7 +1682,7 @@ config CMD_EFIDEBUG config CMD_EXCEPTION bool "exception - raise exception" - depends on ARM || RISCV || X86 + depends on ARM || RISCV || SANDBOX || X86 help Enable the 'exception' command which allows to raise an exception. diff --git a/cmd/Makefile b/cmd/Makefile index dd86675bf2..5b3400a840 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -193,6 +193,7 @@ obj-$(CONFIG_CMD_AVB) += avb.o obj-$(CONFIG_ARM) += arm/ obj-$(CONFIG_RISCV) += riscv/ +obj-$(CONFIG_SANDBOX) += sandbox/ obj-$(CONFIG_X86) += x86/ obj-$(CONFIG_ARCH_MVEBU) += mvebu/ diff --git a/cmd/sandbox/Makefile b/cmd/sandbox/Makefile new file mode 100644 index 0000000000..24df023ece --- /dev/null +++ b/cmd/sandbox/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-$(CONFIG_CMD_EXCEPTION) += exception.o diff --git a/cmd/sandbox/exception.c b/cmd/sandbox/exception.c new file mode 100644 index 0000000000..1aa1d673ae --- /dev/null +++ b/cmd/sandbox/exception.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * The 'exception' command can be used for testing exception handling. + * + * Copyright (c) 2020, Heinrich Schuchardt + */ + +#include +#include + +static int do_sigsegv(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + u8 *ptr = NULL; + + *ptr = 0; + return CMD_RET_FAILURE; +} + +static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + asm volatile (".word 0xffff\n"); + return CMD_RET_FAILURE; +} + +static struct cmd_tbl cmd_sub[] = { + U_BOOT_CMD_MKENT(sigsegv, CONFIG_SYS_MAXARGS, 1, do_sigsegv, + "", ""), + U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, + "", ""), +}; + +static char exception_help_text[] = + "\n" + " The following exceptions are available:\n" + " undefined - undefined instruction\n" + " sigsegv - illegal memory access\n" + ; + +#include From patchwork Wed Nov 11 23:29:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1398600 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=WK0ofLvx; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CWgwF059kz9sPB for ; Thu, 12 Nov 2020 10:31:08 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 315D182540; Thu, 12 Nov 2020 00:30:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="WK0ofLvx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E675882540; Thu, 12 Nov 2020 00:30:29 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1CBD08250A for ; Thu, 12 Nov 2020 00:30:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1605137418; bh=5Ba4iJnF4cszM6AHmDCR7xuP1rE3Bbfa0Dkm+i1asec=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=WK0ofLvxrD3At8eOBLbnhTAyTWXf/Gh9QS+e2iY04pHFvDwvZFU6y11cA2nHoaksm 2K7kLqnVSItRYCmstU4WnkSWbtlbSg7o23e9SwlW7x9S4X0SiJYwyN4tL2QKeYeOYt 626ylVrJRDb86crtuIYzh3KWIq8WCCugBlLy6uAk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([178.202.41.135]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1N17UW-1kAzQp4BBq-012V9F; Thu, 12 Nov 2020 00:30:18 +0100 From: Heinrich Schuchardt To: Simon Glass Cc: u-boot@lists.denx.de, Alexander Graf , Heinrich Schuchardt Subject: [PATCH v2 3/4] efi_selftest: implement exception test for sandbox Date: Thu, 12 Nov 2020 00:29:58 +0100 Message-Id: <20201111232959.11241-4-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201111232959.11241-1-xypron.glpk@gmx.de> References: <20201111232959.11241-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:zssFtLt0HI4CswZN9WqPd3ty8w+XwkALSyoXD+AFRFHtISkw+FU EQ2cl97KvYsKQMCcr6MiRKRZ4pbsr+Ke/1ldK82qwXtdUPNxgCwM2iUINmXilYfvS+/maxp RZyVmBsSDBYRPXLDG9hNds9oVpvmMwQ+LvLyPHdh18cEnmJ346nbL40/0Xk5Hjyrd8STd78 NHZ0OM0/d8df+NlREUUfg== X-UI-Out-Filterresults: notjunk:1;V03:K0:4HRgmULJBgA=:tkEXHnDEVRHnc8+fskVaM5 gr6brTwhixjDwFDmRc+DXb4yFPuqF27i/DfOzpS2Wz2758K2San6KazWtOdPCzHplZ1JjxW4y u36mZBjDnnDa6bYf4JFSxlCd13ErYpKvwI/vxnjBuXOQSDq7H5r4fOtBIgHvoyW5Qrb0L+JFc tyOxYM4OI+kxO5RM+DlYoVhG9mcG+DtRCo/HjpXwjv3UMVU7ANkKtbbQV9q+vOdq1ewvQTGlI WBomS/HqoHKeODDAXfHQVFL8rXGlsUGtRShjF5GgoM+OBL4KmosFdk69gV7AFc5RMprISBaw+ 2/7hTgyArCy13MNvUNhjoGwWGpe9Uj7B5EWsCpW1euPG2rZ7nyRzLWyOfIFSXxjM9gyXH19SB IcKU/ayLZd+Hz0EU0X7jANZwbOiQQM2QJ8yyFIdUIMc1ffOSxorCLpVMH9uONhioEZFAraeNn CmasEyWaTG002rtiFLnDYNv8HruAscmrNSN1WF5VmPN8e3TN2VjmjBZvj+kCv7Mrb2bMF8ulq oSk5uaFnAbItm/sBYWyZtfdWv0JHKcOXrKBw3qmtcIN2mrkXImZ2kL+N57DGrleX7nVSqTJeZ p5kkj90M0iZfc1VeSVkkien2XZGNfMS5kIacwl8gNW8eDZLRtFs2ij0+7Q+HXTtzNlA3wQRC7 IQhNeu7/b17CZRZopPTNHP5Q/YVw6ckjBsiWmfLclCy8olRvlVlgyMz0LUMZ+acWCik53MABu O/c0JQl9dYMxxIP9yVSF6x+GfQS42FkCNzAOF39jLJkXEKBnn/7+CRBt20iBgDB9oc3/ENTOU 3C8Vdb15MNj8/eoEggJ3bIbfr3qMsUKHiceOxMOaLtUP8uadsZSjFxyEVrYKU6l2GPaFpyRFr pt2jdkkJh2/vBiekm5Lw== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Provide a unit test that causes an illegal instruction to occur. The test can be run with the following commands: => setenv efi_selftest exception => bootefi selftest This might be the output: Executing 'exception' EFI application triggers exception. Illegal instruction pc = 0x1444d016, pc_reloc = 0xffffaa078e8dd016 UEFI image [0x0000000000000000:0xffffffffffffffff] '/\selftest' UEFI image [0x000000001444b000:0x0000000014451fff] pc=0x2016 '/bug.efi' Resetting ... It would tell us that the exception was triggered by an instruction 0x2016 bytes after the load address of the binary with filename /bug.efi. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- v2: no change --- lib/efi_selftest/efi_selftest_miniapp_exception.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.28.0 diff --git a/lib/efi_selftest/efi_selftest_miniapp_exception.c b/lib/efi_selftest/efi_selftest_miniapp_exception.c index 63c63d75f1..59b7e5100a 100644 --- a/lib/efi_selftest/efi_selftest_miniapp_exception.c +++ b/lib/efi_selftest/efi_selftest_miniapp_exception.c @@ -33,6 +33,8 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle, asm volatile (".word 0xe7f7defb\n"); #elif defined(CONFIG_RISCV) asm volatile (".word 0xffffffff\n"); +#elif defined(CONFIG_SANDBOX) + asm volatile (".word 0xffffffff\n"); #elif defined(CONFIG_X86) asm volatile (".word 0xffff\n"); #endif From patchwork Wed Nov 11 23:29:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1398598 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=WyMooHt6; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CWgvr5P9gz9sPB for ; Thu, 12 Nov 2020 10:30:48 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C2EFA82526; Thu, 12 Nov 2020 00:30:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="WyMooHt6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B635A823F4; Thu, 12 Nov 2020 00:30:24 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E1C68824F7 for ; Thu, 12 Nov 2020 00:30:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1605137418; bh=62hVUlMfMYR9KM6sNuY2GUTxcFqcD2oGjEb2eGrUT+Q=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=WyMooHt6KBQofotKPi+bR7wsMSZxz/ToLSCUNJsKc98BgudPjKqd8kBycLjbc4xVT kfePbXq5hyG6B499kpcn2IeKSRP1WHgfPP7Ob5gU3EgjKBdTVjXoTrr0FGIxhCyJlP uEyUyhaefyI1DWdvLBZsHMtDRhDnbC4574KZfFIY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([178.202.41.135]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MZTmO-1kpWFo16MI-00WSe5; Thu, 12 Nov 2020 00:30:18 +0100 From: Heinrich Schuchardt To: Simon Glass Cc: u-boot@lists.denx.de, Alexander Graf , Heinrich Schuchardt Subject: [PATCH v2 4/4] test: unit test for exception command Date: Thu, 12 Nov 2020 00:29:59 +0100 Message-Id: <20201111232959.11241-5-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201111232959.11241-1-xypron.glpk@gmx.de> References: <20201111232959.11241-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Oy7RynKVOmICBzBxBPBgMRkv/h7ymFpzrxsORqIYml0PYgdUJqO BGFQvV5OH8llUkdZZSqQIifB3ti1Iisc1cgYjTZ9J+qXoW0m0oZT8CQAv/qIjL9BGfKG/jp 3Xj49HR5IrG66xSkR27YbzgS67IpRG5DBZ1IjzT1XWQE20id+oGkfPGTgQGVL1k+CXQ0tJ0 4YLUOf4I7TDrfCUdg4MkQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:x1tirvT3pr8=:sCCxybdCwFpvt8lHW359jt UWLphsdnTIlswHdymCYGcyOUwFLjTp4vSjBPG7a+gNBGYf6fx6wRttEmzSezbxowXAbWWBpdH nXBZBNQiXsk48NlfxQbjsODT+61mFJSs7NxWusa3ZJcx3YO3UxLyBa2Bhm+R2FeYIFOxE+U8M 24tMsNHRRUie97EWwfPEFaV+u8dd0bG7epfWEX0swy7WWj3t700GGG23svPkqlnEoXINwvEkJ WUUZbLmWx/ABXC7J0y8oqe0Z/vjtlH7LK9yKB6/fOaixp4bXmajT4YTZpNfv86KXu8lW8fh6O 8UlUOu+9hS5Gg2QM41ca50GZc69forpJaMHRshjqOcpNWTswondycF10wGTVBsM+JeEv+DhLV B+WFdcgLbTsHySxrmsD4w3GNObJn+vVc6JAJgvvBoMdhpgE69wh7J/U0EV15+VdTYiAX7SMSV woqJhQuAAnPjSCzonkdrTNbUCG4ETVxCWwaqV9t8dVyzIQssmjx+DLjYBxDFNth7IMRrPd05C JbNErUafpJsg86gd6wYFjDWRwiC/QidhNozGjLEo/x3MBzpVNvbmc5lR96ey6Guy3CXnpeByW 4nLMzNvT6zZvBCsZQ01VDuKl2quKyQ9+OB/wd/qzqKmh2L0pgi67Y/lnETrCgFnuwwymo0kM5 Ya56/8GdG5ygEV2vlm09cm6jsjAO+nAXQkh7CfXrd0iplj8t01Cn4v7Fqxwm0TIjZVYPeZ/By WZCnZUTOSJZObVq8D4Aips9CUQHEd4PxxRJR/hofmY806150UbU34XYvrG/9fMnMy/iBXtK4a Cj6C3/Q6Fj0L2lrfmUphg8QijE5ytJMI6qBK5HOFnaXt1hwLntRKZCaW1azI4DRRgIMKxl7z6 Mi2ONjvXryJOtLXMF4FA== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Test that an exception SIGILL is answered by a reset on the sandbox if CONFIG_SANDBOX_CRASH_RESET=y or by exiting to the OS otherwise. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- v2: new patch --- arch/Kconfig | 1 + test/py/tests/test_sandbox_exit.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) -- 2.28.0 diff --git a/arch/Kconfig b/arch/Kconfig index 3aa99e08fc..b936d2dffc 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -112,6 +112,7 @@ config SANDBOX imply BITREVERSE select BLOBLIST imply CMD_DM + imply CMD_EXCEPTION imply CMD_GETTIME imply CMD_HASH imply CMD_IO diff --git a/test/py/tests/test_sandbox_exit.py b/test/py/tests/test_sandbox_exit.py index 2d242ae0f6..706f5fa359 100644 --- a/test/py/tests/test_sandbox_exit.py +++ b/test/py/tests/test_sandbox_exit.py @@ -19,3 +19,27 @@ def test_ctrl_c(u_boot_console): u_boot_console.kill(signal.SIGINT) assert(u_boot_console.validate_exited()) + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_exception') +@pytest.mark.buildconfigspec('sandbox_crash_reset') +def test_exception_reset(u_boot_console): + """Test that SIGILL causes a reset.""" + + u_boot_console.run_command('exception undefined', wait_for_prompt=False) + m = u_boot_console.p.expect(['resetting ...', 'U-Boot']) + if m != 0: + raise Exception('SIGILL did not lead to reset') + m = u_boot_console.p.expect(['U-Boot', '=>']) + if m != 0: + raise Exception('SIGILL did not lead to reset') + u_boot_console.restart_uboot() + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_exception') +@pytest.mark.notbuildconfigspec('sandbox_crash_reset') +def test_exception_exit(u_boot_console): + """Test that SIGILL causes a reset.""" + + u_boot_console.run_command('exception undefined', wait_for_prompt=False) + assert(u_boot_console.validate_exited())