From nobody Mon Apr 29 05:47:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610793252; cv=none; d=zohomail.com; s=zohoarc; b=b6quuyUzf65dD/IkY0xeiOKTLGRm5QRyK4FVf5llnUkWakvjUCUrw8Q5/KgikgeYnf3DDkUiLlMJpBc1/AVTn3+IDbE51NTl0RRcxu8HKRTmMmZaebmFBwo6NmXfq2izJu5emNWRi/4AuBD7J60tB8XbWqLpiLyPhbZ4Un0uKI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610793252; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zAaEKFd+UVmLUtUOB8vH8lgK68eWLXdf9gU5ZOXZ0o4=; b=JF4BMdLdWJ0GaJ9yS4uAWT9YB2FlpVpNWXZQ5tZzxza+or9+SPqHJL/brXcO9it9ZYeAqf75i/f7yRJJaYa3eK7iv75uNcEH/SkCJQtRtk29v6lg+ut+BT4oIjFyKMqTZ9btHyrnDMwVsY3UDsyu1YJB/m7Mzo/ENGPoB7322AY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610793252333358.4021530116602; Sat, 16 Jan 2021 02:34:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.68968.123635 (Exim 4.92) (envelope-from ) id 1l0iu4-0005zn-58; Sat, 16 Jan 2021 10:33:56 +0000 Received: by outflank-mailman (output) from mailman id 68968.123635; Sat, 16 Jan 2021 10:33:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0iu3-0005zf-W5; Sat, 16 Jan 2021 10:33:55 +0000 Received: by outflank-mailman (input) for mailman id 68968; Sat, 16 Jan 2021 10:33:55 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0iu3-0005tA-1c for xen-devel@lists.xenproject.org; Sat, 16 Jan 2021 10:33:55 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ad9e1843-02ac-45c6-83c8-a64b5fda3e87; Sat, 16 Jan 2021 10:33:43 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A6FDBAA6F; Sat, 16 Jan 2021 10:33:42 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ad9e1843-02ac-45c6-83c8-a64b5fda3e87 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610793222; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zAaEKFd+UVmLUtUOB8vH8lgK68eWLXdf9gU5ZOXZ0o4=; b=YfzZXFP3iO2354hjepjAZB7ySUlQ6AmhcT3LRpS2eHVTwDFIC5XDFuRvJmSbvbYdrDAIR/ ZEG4XvGZSpuDtgOvnijWzh5jjse6NBsVm3tFisVbuNCa3eiI7yXms3teY4La9L1A8FLWIw hM+WTtCSzUUNjxwi6fReMhM3BvGtqOo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Wei Liu Subject: [PATCH v6 1/3] xen/arm: add support for run_in_exception_handler() Date: Sat, 16 Jan 2021 11:33:37 +0100 Message-Id: <20210116103339.21708-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210116103339.21708-1-jgross@suse.com> References: <20210116103339.21708-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add support to run a function in an exception handler for Arm. Do it as on x86 via a bug_frame, but pass the function pointer via a register (this needs to be done that way, because inline asm support for 32-bit Arm lacks the needed functionality to reference an arbitrary function via the bugframe). Use the same BUGFRAME_* #defines as on x86 in order to make a future common header file more easily achievable. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- V4: - new patch V5: - adjust BUG_FRAME() macro (Jan Beulich) - adjust arm linker script (Jan Beulich) - drop #ifdef x86 in common/virtual_region.c V6: - use register for function address (Arm32 build failure noticed by Julien Grall) --- xen/arch/arm/traps.c | 8 ++++++++ xen/arch/arm/xen.lds.S | 2 ++ xen/common/virtual_region.c | 2 -- xen/include/asm-arm/arm32/bug.h | 2 ++ xen/include/asm-arm/arm64/bug.h | 2 ++ xen/include/asm-arm/bug.h | 31 +++++++++++++++++++++++++------ 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 1af1bb9f1b..d0df33b218 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1236,6 +1236,14 @@ int do_bug_frame(const struct cpu_user_regs *regs, v= addr_t pc) if ( !bug ) return -ENOENT; =20 + if ( id =3D=3D BUGFRAME_run_fn ) + { + void (*fn)(const struct cpu_user_regs *) =3D (void *)regs->BUG_FN_= REG; + + fn(regs); + return 0; + } + /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ filename =3D bug_file(bug); if ( !is_kernel(filename) ) diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 6342ac4ead..004b182acb 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -49,6 +49,8 @@ SECTIONS __stop_bug_frames_1 =3D .; *(.bug_frames.2) __stop_bug_frames_2 =3D .; + *(.bug_frames.3) + __stop_bug_frames_3 =3D .; *(.rodata) *(.rodata.*) *(.data.rel.ro) diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c index 4fbc02e35a..30b0b4ab9c 100644 --- a/xen/common/virtual_region.c +++ b/xen/common/virtual_region.c @@ -123,9 +123,7 @@ void __init setup_virtual_regions(const struct exceptio= n_table_entry *start, __stop_bug_frames_0, __stop_bug_frames_1, __stop_bug_frames_2, -#ifdef CONFIG_X86 __stop_bug_frames_3, -#endif NULL }; =20 diff --git a/xen/include/asm-arm/arm32/bug.h b/xen/include/asm-arm/arm32/bu= g.h index 3e66f35969..25cce151dc 100644 --- a/xen/include/asm-arm/arm32/bug.h +++ b/xen/include/asm-arm/arm32/bug.h @@ -10,4 +10,6 @@ =20 #define BUG_INSTR ".word " __stringify(BUG_OPCODE) =20 +#define BUG_FN_REG r0 + #endif /* __ARM_ARM32_BUG_H__ */ diff --git a/xen/include/asm-arm/arm64/bug.h b/xen/include/asm-arm/arm64/bu= g.h index 59f664d7de..5e11c0dfd5 100644 --- a/xen/include/asm-arm/arm64/bug.h +++ b/xen/include/asm-arm/arm64/bug.h @@ -6,4 +6,6 @@ =20 #define BUG_INSTR "brk " __stringify(BRK_BUG_FRAME_IMM) =20 +#define BUG_FN_REG x0 + #endif /* __ARM_ARM64_BUG_H__ */ diff --git a/xen/include/asm-arm/bug.h b/xen/include/asm-arm/bug.h index 36c803357c..e9341daef1 100644 --- a/xen/include/asm-arm/bug.h +++ b/xen/include/asm-arm/bug.h @@ -26,16 +26,17 @@ struct bug_frame { #define bug_line(b) ((b)->line) #define bug_msg(b) ((const char *)(b) + (b)->msg_disp) =20 -#define BUGFRAME_warn 0 -#define BUGFRAME_bug 1 -#define BUGFRAME_assert 2 +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 =20 -#define BUGFRAME_NR 3 +#define BUGFRAME_NR 4 =20 /* Many versions of GCC doesn't support the asm %c parameter which would * be preferable to this unpleasantness. We use mergeable string * sections to avoid multiple copies of the string appearing in the - * Xen image. + * Xen image. BUGFRAME_run_fn needs to be handled separately. */ #define BUG_FRAME(type, line, file, has_msg, msg) do { = \ BUILD_BUG_ON((line) >> 16); = \ @@ -58,6 +59,23 @@ struct bug_frame { ".popsection"); = \ } while (0) =20 +/* + * Unfortunately gcc for arm 32-bit doesn't support the "i" constraint, so + * the easiest way to implement run_in_exception_handler() is to pass the + * to be called function in a fixed register. + */ +#define run_in_exception_handler(fn) do { = \ + asm ("mov " __stringify(BUG_FN_REG) ", %0\n" = \ + "1:"BUG_INSTR"\n" = \ + ".pushsection .bug_frames." __stringify(BUGFRAME_run_fn) "," = \ + " \"a\", %%progbits\n" = \ + "2:\n" = \ + ".p2align 2\n" = \ + ".long (1b - 2b)\n" = \ + ".long 0, 0, 0\n" = \ + ".popsection" :: "r" (fn) : __stringify(BUG_FN_REG) ); = \ +} while (0) + #define WARN() BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, "") =20 #define BUG() do { \ @@ -73,7 +91,8 @@ struct bug_frame { extern const struct bug_frame __start_bug_frames[], __stop_bug_frames_0[], __stop_bug_frames_1[], - __stop_bug_frames_2[]; + __stop_bug_frames_2[], + __stop_bug_frames_3[]; =20 #endif /* __ARM_BUG_H__ */ /* --=20 2.26.2 From nobody Mon Apr 29 05:47:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610793245; cv=none; d=zohomail.com; s=zohoarc; b=ZAqK72Jqh+RejmjGMNCSk+j7TNmckcKAfpz/l4NecB1DQvfmByCKHpTYY8DFE0BgE68zClf0BOPRpEfGr/oitmkyj/CVCkb1mUEP4GHQpJaQGkU84D+QP2PfwQtHvZh24ecErsc3DRmU4VvPvvKUHimsq3L4FqlOFfx4uL36lXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610793245; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ejIblnGVIKaqvxho3ySwDkDHenm4tozwF4FuC3LBKQo=; b=CJ5qWSRJDBXskPUWHMBwxLOgXhpQ5qRzpc4aIiQEiWU7L8yhNSOEQuLmPYCSJJjTuIY8f/HyrQxRgeiQ0iMqX+02U1zaSC9KHybyaafMglkQ9izLPiRdO0CXwNR2RXfXnXwcRyA/+NVe0aYduaFMviP1G9fut4LQOhv93wCmO8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610793245012866.2893338839953; Sat, 16 Jan 2021 02:34:05 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.68964.123599 (Exim 4.92) (envelope-from ) id 1l0itu-0005r8-0z; Sat, 16 Jan 2021 10:33:46 +0000 Received: by outflank-mailman (output) from mailman id 68964.123599; Sat, 16 Jan 2021 10:33:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0itt-0005r1-Tp; Sat, 16 Jan 2021 10:33:45 +0000 Received: by outflank-mailman (input) for mailman id 68964; Sat, 16 Jan 2021 10:33:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0its-0005qw-L0 for xen-devel@lists.xenproject.org; Sat, 16 Jan 2021 10:33:44 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0b60d93b-0b18-4ab7-af31-101cbb20f8c6; Sat, 16 Jan 2021 10:33:43 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E6D78AD26; Sat, 16 Jan 2021 10:33:42 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0b60d93b-0b18-4ab7-af31-101cbb20f8c6 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610793223; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ejIblnGVIKaqvxho3ySwDkDHenm4tozwF4FuC3LBKQo=; b=c+ZAY/7RAlQLE8Lung8xyPl5Uje3LzIYh3Nwpx98EdaGULW2qbEDzjm3NWmCOIx8JTIayr FfwrSlzei59t/c2SpWPCL/qiBzig2t4r9OC1pDtE35Xc+JxbIWUUW3ur6uaCVKShSVZcfi SOFlN7rctJk61YUPlQCgoy/1+HRhdGg= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v6 2/3] xen: enable keyhandlers to work without register set specified Date: Sat, 16 Jan 2021 11:33:38 +0100 Message-Id: <20210116103339.21708-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210116103339.21708-1-jgross@suse.com> References: <20210116103339.21708-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" There are only two keyhandlers which make use of the cpu_user_regs struct passed to them. In order to be able to call any keyhandler in non-interrupt contexts, too, modify those two handlers to cope with a NULL regs pointer by using run_in_exception_handler() in that case. Suggested-by: Julien Grall Signed-off-by: Juergen Gross Acked-by: Julien Grall --- V4: - new patch --- xen/common/keyhandler.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 68364e987d..38020a1360 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -181,7 +181,10 @@ static void dump_registers(unsigned char key, struct c= pu_user_regs *regs) cpumask_copy(&dump_execstate_mask, &cpu_online_map); =20 /* Get local execution state out immediately, in case we get stuck. */ - dump_execstate(regs); + if ( regs ) + dump_execstate(regs); + else + run_in_exception_handler(dump_execstate); =20 /* Alt. handling: remaining CPUs are dumped asynchronously one-by-one.= */ if ( alt_key_handling ) @@ -481,15 +484,23 @@ static void run_all_keyhandlers(unsigned char key, st= ruct cpu_user_regs *regs) tasklet_schedule(&run_all_keyhandlers_tasklet); } =20 -static void do_debug_key(unsigned char key, struct cpu_user_regs *regs) +static void do_debugger_trap_fatal(struct cpu_user_regs *regs) { - printk("'%c' pressed -> trapping into debugger\n", key); (void)debugger_trap_fatal(0xf001, regs); =20 /* Prevent tail call optimisation, which confuses xendbg. */ barrier(); } =20 +static void do_debug_key(unsigned char key, struct cpu_user_regs *regs) +{ + printk("'%c' pressed -> trapping into debugger\n", key); + if ( regs ) + do_debugger_trap_fatal(regs); + else + run_in_exception_handler(do_debugger_trap_fatal); +} + static void do_toggle_alt_key(unsigned char key, struct cpu_user_regs *reg= s) { alt_key_handling =3D !alt_key_handling; --=20 2.26.2 From nobody Mon Apr 29 05:47:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610793247; cv=none; d=zohomail.com; s=zohoarc; b=O8vn9Sa3N+EUWnSJP7Txm3/QQsYFE4LIhjdRUs5yb2TK238r+2KxySW4G0SBiT74GUxPFRC86MaeDvzrwZOwhDsb1hj3q096KfDlAEV57DTgq+1UoXqoVFtmVqqZJ8ZD00Kn67KSD8sA9YI73ycQEqmgsxEsHrbl9+GBBcu9HQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610793247; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9sC8s2UbRLRwYw/s2NJTMA/PXEr+dZ1Vo7q+V2nvQus=; b=ZtCR0LUj1jYB1sf1FVgau9+yvpvRtQmGsAS91n7p2MJviVIAWp83wlJ8lj2senZJc56a0NtYAK/pAKZHTZZSmhW1AJZkPAoy1Z7EGDnUsQn1kosrw7AXrBAZQZx7CGo+sJ4yxaMvtDZfernpLjr00ztPj7N1T08AL5pbavgZVzs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610793247399103.14456151546153; Sat, 16 Jan 2021 02:34:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.68965.123611 (Exim 4.92) (envelope-from ) id 1l0itz-0005tf-8S; Sat, 16 Jan 2021 10:33:51 +0000 Received: by outflank-mailman (output) from mailman id 68965.123611; Sat, 16 Jan 2021 10:33:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0itz-0005tY-55; Sat, 16 Jan 2021 10:33:51 +0000 Received: by outflank-mailman (input) for mailman id 68965; Sat, 16 Jan 2021 10:33:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0itx-0005qw-Ja for xen-devel@lists.xenproject.org; Sat, 16 Jan 2021 10:33:49 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 850273b0-dbc1-4a1f-bf62-960d0199750c; Sat, 16 Jan 2021 10:33:44 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 32F54ADC1; Sat, 16 Jan 2021 10:33:43 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 850273b0-dbc1-4a1f-bf62-960d0199750c X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610793223; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9sC8s2UbRLRwYw/s2NJTMA/PXEr+dZ1Vo7q+V2nvQus=; b=bPm1blrHY4XTLxSwmucFG1bCqF7kHm2KEb+5zWJyo4xKlXGxrUQHi7YYX9Egtkxem7wDjx bp1+yMTrGHxl5wW0OJBfvhtEggr6VcYP+rdWz0JVKlib+s9tvCmVOQ6zoAs3l1vASzo2oR dlIsHZaHDIBJT4NFzrSlNHWSp8EFjIw= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v6 3/3] xen: add support for automatic debug key actions in case of crash Date: Sat, 16 Jan 2021 11:33:39 +0100 Message-Id: <20210116103339.21708-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210116103339.21708-1-jgross@suse.com> References: <20210116103339.21708-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" When the host crashes it would sometimes be nice to have additional debug data available which could be produced via debug keys, but halting the server for manual intervention might be impossible due to the need to reboot/kexec rather sooner than later. Add support for automatic debug key actions in case of crashes which can be activated via boot- or runtime-parameter. Depending on the type of crash the desired data might be different, so support different settings for the possible types of crashes. The parameter is "crash-debug" with the following syntax: crash-debug-=3D with being one of: panic, hwdom, watchdog, kexeccmd, debugkey and a sequence of debug key characters with '+' having the special semantics of a 10 millisecond pause. So "crash-debug-watchdog=3D0+0qr" would result in special output in case of watchdog triggered crash (dom0 state, 10 ms pause, dom0 state, domain info, run queues). Don't call key handlers in early boot, as some (e.g. for 'd') require some initializations to be finished, like scheduler or idle domain. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - switched special character '.' to '+' (Jan Beulich) - 10 ms instead of 1 s pause (Jan Beulich) - added more text to the boot parameter description (Jan Beulich) V3: - added const (Jan Beulich) - thorough test of crash reason parameter (Jan Beulich) - kexeccmd case should depend on CONFIG_KEXEC (Jan Beulich) - added dummy get_irq_regs() helper on Arm V4: - call keyhandlers with NULL for regs - use ARRAY_SIZE() (Jan Beulich) - don't activate handlers in early boot (Jan Beulich) - avoid recursion - extend documentation a bit V5: - move recursion check down a little bit (Jan Beulich) --- docs/misc/xen-command-line.pandoc | 41 +++++++++++++++++++++++ xen/common/kexec.c | 8 +++-- xen/common/keyhandler.c | 55 +++++++++++++++++++++++++++++++ xen/common/shutdown.c | 4 +-- xen/drivers/char/console.c | 2 +- xen/include/xen/kexec.h | 10 ++++-- xen/include/xen/keyhandler.h | 10 ++++++ 7 files changed, 122 insertions(+), 8 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 7ec1e804b7..a713a0535c 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -574,6 +574,47 @@ reduction of features at Xen's disposal to manage gues= ts. ### cpuinfo (x86) > `=3D ` =20 +### crash-debug-debugkey +### crash-debug-hwdom +### crash-debug-kexeccmd +### crash-debug-panic +### crash-debug-watchdog +> `=3D ` + +> Can be modified at runtime + +Specify debug-key actions in cases of crashes. Each of the parameters appl= ies +to a different crash reason. The `` is a sequence of debug key +characters, with `+` having the special meaning of a 10 millisecond pause. + +`crash-debug-debugkey` will be used for crashes induced by the `C` debug +key (i.e. manually induced crash). + +`crash-debug-hwdom` denotes a crash of dom0. + +`crash-debug-kexeccmd` is an explicit request of dom0 to continue with the +kdump kernel via kexec. Only available on hypervisors built with CONFIG_KE= XEC. + +`crash-debug-panic` is a crash of the hypervisor. + +`crash-debug-watchdog` is a crash due to the watchdog timer expiring. + +It should be noted that dumping diagnosis data to the console can fail in +multiple ways (missing data, hanging system, ...) depending on the reason +of the crash, which might have left the hypervisor in a bad state. In case +a debug-key action leads to another crash recursion will be avoided, so no +additional debug-key actions will be performed in this case. A crash in the +early boot phase will not result in any debug-key action, as the system +might not yet be in a state where the handlers can work. + +So e.g. `crash-debug-watchdog=3D0+0r` would dump dom0 state twice with 10 +milliseconds between the two state dumps, followed by the run queues of the +hypervisor, if the system crashes due to a watchdog timeout. + +Depending on the reason of the system crash it might happen that triggering +some debug key action will result in a hang instead of dumping data and th= en +doing a reboot or crash dump. + ### crashinfo_maxaddr > `=3D ` =20 diff --git a/xen/common/kexec.c b/xen/common/kexec.c index 52cdc4ebc3..ebeee6405a 100644 --- a/xen/common/kexec.c +++ b/xen/common/kexec.c @@ -373,10 +373,12 @@ static int kexec_common_shutdown(void) return 0; } =20 -void kexec_crash(void) +void kexec_crash(enum crash_reason reason) { int pos; =20 + keyhandler_crash_action(reason); + pos =3D (test_bit(KEXEC_FLAG_CRASH_POS, &kexec_flags) !=3D 0); if ( !test_bit(KEXEC_IMAGE_CRASH_BASE + pos, &kexec_flags) ) return; @@ -409,7 +411,7 @@ static long kexec_reboot(void *_image) static void do_crashdump_trigger(unsigned char key) { printk("'%c' pressed -> triggering crashdump\n", key); - kexec_crash(); + kexec_crash(CRASHREASON_DEBUGKEY); printk(" * no crash kernel loaded!\n"); } =20 @@ -840,7 +842,7 @@ static int kexec_exec(XEN_GUEST_HANDLE_PARAM(void) uarg) ret =3D continue_hypercall_on_cpu(0, kexec_reboot, image); break; case KEXEC_TYPE_CRASH: - kexec_crash(); /* Does not return */ + kexec_crash(CRASHREASON_KEXECCMD); /* Does not return */ break; } =20 diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 38020a1360..8b9f378371 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -3,7 +3,9 @@ */ =20 #include +#include #include +#include #include #include #include @@ -518,6 +520,59 @@ void __init initialize_keytable(void) } } =20 +#define CRASHACTION_SIZE 32 +static char crash_debug_panic[CRASHACTION_SIZE]; +string_runtime_param("crash-debug-panic", crash_debug_panic); +static char crash_debug_hwdom[CRASHACTION_SIZE]; +string_runtime_param("crash-debug-hwdom", crash_debug_hwdom); +static char crash_debug_watchdog[CRASHACTION_SIZE]; +string_runtime_param("crash-debug-watchdog", crash_debug_watchdog); +#ifdef CONFIG_KEXEC +static char crash_debug_kexeccmd[CRASHACTION_SIZE]; +string_runtime_param("crash-debug-kexeccmd", crash_debug_kexeccmd); +#else +#define crash_debug_kexeccmd NULL +#endif +static char crash_debug_debugkey[CRASHACTION_SIZE]; +string_runtime_param("crash-debug-debugkey", crash_debug_debugkey); + +void keyhandler_crash_action(enum crash_reason reason) +{ + static const char *const crash_action[] =3D { + [CRASHREASON_PANIC] =3D crash_debug_panic, + [CRASHREASON_HWDOM] =3D crash_debug_hwdom, + [CRASHREASON_WATCHDOG] =3D crash_debug_watchdog, + [CRASHREASON_KEXECCMD] =3D crash_debug_kexeccmd, + [CRASHREASON_DEBUGKEY] =3D crash_debug_debugkey, + }; + static bool ignore; + const char *action; + + /* Some handlers are not functional too early. */ + if ( system_state < SYS_STATE_smp_boot ) + return; + + if ( (unsigned int)reason >=3D ARRAY_SIZE(crash_action) ) + return; + action =3D crash_action[reason]; + if ( !action ) + return; + + /* Avoid recursion. */ + if ( ignore ) + return; + ignore =3D true; + + while ( *action ) + { + if ( *action =3D=3D '+' ) + mdelay(10); + else + handle_keypress(*action, NULL); + action++; + } +} + /* * Local variables: * mode: C diff --git a/xen/common/shutdown.c b/xen/common/shutdown.c index 912593915b..abde48aa4c 100644 --- a/xen/common/shutdown.c +++ b/xen/common/shutdown.c @@ -43,7 +43,7 @@ void hwdom_shutdown(u8 reason) case SHUTDOWN_crash: debugger_trap_immediate(); printk("Hardware Dom%u crashed: ", hardware_domain->domain_id); - kexec_crash(); + kexec_crash(CRASHREASON_HWDOM); maybe_reboot(); break; /* not reached */ =20 @@ -56,7 +56,7 @@ void hwdom_shutdown(u8 reason) case SHUTDOWN_watchdog: printk("Hardware Dom%u shutdown: watchdog rebooting machine\n", hardware_domain->domain_id); - kexec_crash(); + kexec_crash(CRASHREASON_WATCHDOG); machine_restart(0); break; /* not reached */ =20 diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index e3c483fd13..2358375170 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1271,7 +1271,7 @@ void panic(const char *fmt, ...) =20 debugger_trap_immediate(); =20 - kexec_crash(); + kexec_crash(CRASHREASON_PANIC); =20 if ( opt_noreboot ) machine_halt(); diff --git a/xen/include/xen/kexec.h b/xen/include/xen/kexec.h index e85ba16405..9f7a912e97 100644 --- a/xen/include/xen/kexec.h +++ b/xen/include/xen/kexec.h @@ -1,6 +1,8 @@ #ifndef __XEN_KEXEC_H__ #define __XEN_KEXEC_H__ =20 +#include + #ifdef CONFIG_KEXEC =20 #include @@ -48,7 +50,7 @@ void machine_kexec_unload(struct kexec_image *image); void machine_kexec_reserved(xen_kexec_reserve_t *reservation); void machine_reboot_kexec(struct kexec_image *image); void machine_kexec(struct kexec_image *image); -void kexec_crash(void); +void kexec_crash(enum crash_reason reason); void kexec_crash_save_cpu(void); struct crash_xen_info *kexec_crash_save_info(void); void machine_crash_shutdown(void); @@ -82,7 +84,11 @@ void vmcoreinfo_append_str(const char *fmt, ...) #define kexecing 0 =20 static inline void kexec_early_calculations(void) {} -static inline void kexec_crash(void) {} +static inline void kexec_crash(enum crash_reason reason) +{ + keyhandler_crash_action(reason); +} + static inline void kexec_crash_save_cpu(void) {} static inline void set_kexec_crash_area_size(u64 system_ram) {} =20 diff --git a/xen/include/xen/keyhandler.h b/xen/include/xen/keyhandler.h index 5131e86cbc..9c5830a037 100644 --- a/xen/include/xen/keyhandler.h +++ b/xen/include/xen/keyhandler.h @@ -48,4 +48,14 @@ void register_irq_keyhandler(unsigned char key, /* Inject a keypress into the key-handling subsystem. */ extern void handle_keypress(unsigned char key, struct cpu_user_regs *regs); =20 +enum crash_reason { + CRASHREASON_PANIC, + CRASHREASON_HWDOM, + CRASHREASON_WATCHDOG, + CRASHREASON_KEXECCMD, + CRASHREASON_DEBUGKEY, +}; + +void keyhandler_crash_action(enum crash_reason reason); + #endif /* __XEN_KEYHANDLER_H__ */ --=20 2.26.2