xen: add support for automatic debug key actions in case of crash
v5 cover xen: add support for automatic debug key actions in case of crash
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.
Changes in V4:
- addressed comments (now patch 3)
- added patches 1 and 2
Changes in V5:
- better bug frame construction on Arm (patch 1)
- addressed comments
Juergen Gross (3):
xen/arm: add support for run_in_exception_handler()
xen: enable keyhandlers to work without register set specified
xen: add support for automatic debug key actions in case of crash
docs/misc/xen-command-line.pandoc | 41 ++++++++++++++++++ xen/arch/arm/traps.c | 10 ++++- xen/arch/arm/xen.lds.S | 2 + xen/common/kexec.c | 8 ++-- xen/common/keyhandler.c | 72 +++++++++++++++++++++++++++++-- xen/common/shutdown.c | 4 +- xen/common/virtual_region.c | 2 - xen/drivers/char/console.c | 2 +- xen/include/asm-arm/bug.h | 45 +++++++++---------- xen/include/xen/kexec.h | 10 ++++- xen/include/xen/keyhandler.h | 10 +++++ 11 files changed, 168 insertions(+), 38 deletions(-)
Signature · 1 line
2.26.2
PATCH v5 1/3 xen/arm: add support for run_in_exception_handler()
Add support to run a function in an exception handler for Arm. Do it the same way as on x86 via a bug_frame.
Use the same BUGFRAME_* #defines as on x86 in order to make a future common header file more easily achievable.
---
V4:
- new patch
V5:
- adjust BUG_FRAME() macro (Jan Beulich)
- adjust arm linker script (Jan Beulich)
- drop #ifdef x86 in common/virtual_region.c
I have verified the created bugframes are correct by inspecting the created binary.
--- xen/arch/arm/traps.c | 10 ++++++++- xen/arch/arm/xen.lds.S | 2 ++ xen/common/virtual_region.c | 2 -- xen/include/asm-arm/bug.h | 45 +++++++++++++++++-------------------- 4 files changed, 32 insertions(+), 27 deletions(-)
xen/arch/arm/traps.c +9 -1
@@ -1236,8 +1236,16 @@ int do_bug_frame(const struct cpu_user_regs *regs, vaddr_t pc)if ( !bug )return -ENOENT ; +if ( id == BUGFRAME_run_fn ) + { +void (*fn)(const struct cpu_user_regs *) =bug_ptr (bug); + +fn (regs); +return 0 ; + } +/* WARN, BUG or ASSERT: decode the filename pointer and line number. */ - filename =bug_file (bug); + filename =bug_ptr (bug);if ( !is_kernel (filename) )return -EINVAL ; fixup =strlen (filename);
xen/arch/arm/xen.lds.S +2 -0
@@ -49,6 +49,8 @@ SECTIONS __stop_bug_frames_1 = .; *(.bug_frames.2) __stop_bug_frames_2 = .; + *(.bug_frames.3) + __stop_bug_frames_3 = .; *(.rodata) *(.rodata.*) *(.data.rel.ro)
xen/common/virtual_region.c +0 -2
@@ -123,9 +123,7 @@ void __init setup_virtual_regions(const struct exception_table_entry *start, __stop_bug_frames_0, __stop_bug_frames_1, __stop_bug_frames_2, -#ifdef CONFIG_X86 __stop_bug_frames_3, -#endif NULL };
xen/include/asm-arm/bug.h +21 -24
86 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v5 1/3] xen/arm: add support for run_in_exception_handler()
Quoted 52 lines · Juergen Gross
xen/include/asm-arm/bug.h +10
-16@@ -15,65 +15,62 @@struct bug_frame {signed int loc_disp;/* Relative address to the bug address */ -signed int file_disp;/* Relative address to the filename */ +signed int ptr_disp;/* Relative address to the filename or function */ signed int msg_disp;/* Relative address to the predicate (for ASSERT) */ uint16_t line;/* Line number */ uint32_t pad0:16 ;/* Padding for 8-bytes align */ };#define bug_loc (b) ((const void *)(b) + (b)->loc_disp) -#define bug_file (b) ((const void *)(b) + (b)->file_disp); +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp);#define bug_line (b) ((b)->line)#define bug_msg (b) ((const char *)(b) + (b)->msg_disp) -#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 -#define BUGFRAME_NR 3 +#define BUGFRAME_NR 4/* 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. */ -#define BUG_FRAME (type, line, file, has_msg, msg) do { \ +#define BUG_FRAME (type, line, ptr, msg) do { \ BUILD_BUG_ON((line) >> 16); \ BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm ("1:"BUG_INSTR"\n" \ - ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ - "2:\t.asciz " __stringify(file) "\n" \ - "3:\n" \ - ".if " #has_msg "\n" \ - "\t.asciz " #msg "\n" \ - ".endif\n" \ - ".popsection\n" \ - ".pushsection .bug_frames." __stringify(type) ", \"a\", %progbits\n"\ - "4:\n" \ + ".pushsection .bug_frames." __stringify(type) ", \"a\", %%progbits\n"\ + "2:\n" \ ".p2align 2\n" \
xen/include/asm-arm/bug.h line 53
Quoted 10 lines
xen/include/asm-arm/bug.h +4
-4-".long (1b - 4b)\n" \ -".long (2b - 4b)\n" \ -".long (3b - 4b)\n" \ +".long (1b - 2b)\n" \ +".long (%0 - 2b)\n" \ +".long (%1 - 2b)\n" \ ".hword " __stringify(line) ", 0\n" \ - ".popsection"); \ + ".popsection" :: "i" (ptr), "i" (msg)); \ }while (0 )
The comment ahead of the construct now looks to be at best stale, if not entirely pointless. The reference to %c looks quite strange here to me anyway - I can only guess it appeared here because on x86 one has to use %c to output constants as operands for .long and alike, and this was then tried to use on Arm as well without there really being a need.
Jan
Re: [PATCH v5 1/3] xen/arm: add support for run_in_exception_handler()
Quoted 62 lines · Jan Beulich
Quoted 61 lines · Juergen Gross
xen/include/asm-arm/bug.h +14
-20@@ -15,65 +15,62 @@struct bug_frame {signed int loc_disp;/* Relative address to the bug address */ -signed int file_disp;/* Relative address to the filename */ +signed int ptr_disp;/* Relative address to the filename or function */ signed int msg_disp;/* Relative address to the predicate (for ASSERT) */ uint16_t line;/* Line number */ uint32_t pad0:16 ;/* Padding for 8-bytes align */ };#define bug_loc (b) ((const void *)(b) + (b)->loc_disp) -#define bug_file (b) ((const void *)(b) + (b)->file_disp); +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp);#define bug_line (b) ((b)->line)#define bug_msg (b) ((const char *)(b) + (b)->msg_disp) -#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 -#define BUGFRAME_NR 3 +#define BUGFRAME_NR 4/* 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. */ -#define BUG_FRAME (type, line, file, has_msg, msg) do { \ +#define BUG_FRAME (type, line, ptr, msg) do { \ BUILD_BUG_ON((line) >> 16); \ BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm ("1:"BUG_INSTR"\n" \ - ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ - "2:\t.asciz " __stringify(file) "\n" \ - "3:\n" \ - ".if " #has_msg "\n" \ - "\t.asciz " #msg "\n" \ - ".endif\n" \ - ".popsection\n" \ - ".pushsection .bug_frames." __stringify(type) ", \"a\", %progbits\n"\ - "4:\n" \ + ".pushsection .bug_frames." __stringify(type) ", \"a\", %%progbits\n"\ + "2:\n" \ ".p2align 2\n" \ - ".long (1b - 4b)\n" \ - ".long (2b - 4b)\n" \ - ".long (3b - 4b)\n" \ + ".long (1b - 2b)\n" \ + ".long (%0 - 2b)\n" \ + ".long (%1 - 2b)\n" \ ".hword " __stringify(line) ", 0\n" \ - ".popsection"); \ + ".popsection" :: "i" (ptr), "i" (msg)); \
Quoted 8 lines
xen/include/asm-arm/bug.h line 53
Quoted 1 line
xen/include/asm-arm/bug.h +0
-0}while (0 )The comment ahead of the construct now looks to be at best stale, if not entirely pointless. The reference to %c looks quite strange here to me anyway - I can only guess it appeared here because on x86 one has to use %c to output constants as operands for .long and alike, and this was then tried to use on Arm as well without there really being a need.
Probably so.
I can remove the comment, but would like an Arm maintainer to confirm.
Juergen
Re: [PATCH v5 1/3] xen/arm: add support for run_in_exception_handler()
In reply to Jan BeulichHi Jan,
Quoted 62 lines · Jan Beulich
Quoted 61 lines · Juergen Gross
xen/include/asm-arm/bug.h +14
-20@@ -15,65 +15,62 @@struct bug_frame {signed int loc_disp;/* Relative address to the bug address */ -signed int file_disp;/* Relative address to the filename */ +signed int ptr_disp;/* Relative address to the filename or function */ signed int msg_disp;/* Relative address to the predicate (for ASSERT) */ uint16_t line;/* Line number */ uint32_t pad0:16 ;/* Padding for 8-bytes align */ };#define bug_loc (b) ((const void *)(b) + (b)->loc_disp) -#define bug_file (b) ((const void *)(b) + (b)->file_disp); +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp);#define bug_line (b) ((b)->line)#define bug_msg (b) ((const char *)(b) + (b)->msg_disp) -#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 -#define BUGFRAME_NR 3 +#define BUGFRAME_NR 4/* 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. */ -#define BUG_FRAME (type, line, file, has_msg, msg) do { \ +#define BUG_FRAME (type, line, ptr, msg) do { \ BUILD_BUG_ON((line) >> 16); \ BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm ("1:"BUG_INSTR"\n" \ - ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ - "2:\t.asciz " __stringify(file) "\n" \ - "3:\n" \ - ".if " #has_msg "\n" \ - "\t.asciz " #msg "\n" \ - ".endif\n" \ - ".popsection\n" \ - ".pushsection .bug_frames." __stringify(type) ", \"a\", %progbits\n"\ - "4:\n" \ + ".pushsection .bug_frames." __stringify(type) ", \"a\", %%progbits\n"\ + "2:\n" \ ".p2align 2\n" \ - ".long (1b - 4b)\n" \ - ".long (2b - 4b)\n" \ - ".long (3b - 4b)\n" \ + ".long (1b - 2b)\n" \ + ".long (%0 - 2b)\n" \ + ".long (%1 - 2b)\n" \ ".hword " __stringify(line) ", 0\n" \ - ".popsection"); \ + ".popsection" :: "i" (ptr), "i" (msg)); \
Quoted 8 lines
xen/include/asm-arm/bug.h line 53
Quoted 1 line
xen/include/asm-arm/bug.h +0
-0}while (0 )The comment ahead of the construct now looks to be at best stale, if not entirely pointless. The reference to %c looks quite strange here to me anyway - I can only guess it appeared here because on x86 one has to use %c to output constants as operands for .long and alike, and this was then tried to use on Arm as well without there really being a need.
Well, %c is one the reason why we can't have a common BUG_FRAME implementation. So I would like to retain this information before someone wants to consolidate the code and missed this issue.
Regarding the mergeable string section, I agree that the comment in now stale. However, could someone confirm that "i" will still retain the same behavior as using mergeable string sections?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 1/3] xen/arm: add support for run_in_exception_handler()
Quoted 72 lines · Julien Grall
Quoted 62 lines · Jan Beulich
Quoted 61 lines · Juergen Gross
xen/include/asm-arm/bug.h +14
-20@@ -15,65 +15,62 @@struct bug_frame {signed int loc_disp;/* Relative address to the bug address */ -signed int file_disp;/* Relative address to the filename */ +signed int ptr_disp;/* Relative address to the filename or function */ signed int msg_disp;/* Relative address to the predicate (for ASSERT) */ uint16_t line;/* Line number */ uint32_t pad0:16 ;/* Padding for 8-bytes align */ };#define bug_loc (b) ((const void *)(b) + (b)->loc_disp) -#define bug_file (b) ((const void *)(b) + (b)->file_disp); +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp);#define bug_line (b) ((b)->line)#define bug_msg (b) ((const char *)(b) + (b)->msg_disp) -#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 -#define BUGFRAME_NR 3 +#define BUGFRAME_NR 4/* 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. */ -#define BUG_FRAME (type, line, file, has_msg, msg) do { \ +#define BUG_FRAME (type, line, ptr, msg) do { \ BUILD_BUG_ON((line) >> 16); \ BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm ("1:"BUG_INSTR"\n" \ - ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ - "2:\t.asciz " __stringify(file) "\n" \ - "3:\n" \ - ".if " #has_msg "\n" \ - "\t.asciz " #msg "\n" \ - ".endif\n" \ - ".popsection\n" \ - ".pushsection .bug_frames." __stringify(type) ", \"a\", %progbits\n"\ - "4:\n" \ + ".pushsection .bug_frames." __stringify(type) ", \"a\", %%progbits\n"\ + "2:\n" \ ".p2align 2\n" \ - ".long (1b - 4b)\n" \ - ".long (2b - 4b)\n" \ - ".long (3b - 4b)\n" \ + ".long (1b - 2b)\n" \ + ".long (%0 - 2b)\n" \ + ".long (%1 - 2b)\n" \ ".hword " __stringify(line) ", 0\n" \ - ".popsection"); \ + ".popsection" :: "i" (ptr), "i" (msg)); \Quoted 8 lines
xen/include/asm-arm/bug.h line 53
Quoted 1 line
xen/include/asm-arm/bug.h +0
-0}while (0 )The comment ahead of the construct now looks to be at best stale, if not entirely pointless. The reference to %c looks quite strange here to me anyway - I can only guess it appeared here because on x86 one has to use %c to output constants as operands for .long and alike, and this was then tried to use on Arm as well without there really being a need.
Quoted 3 lines
Well, %c is one the reason why we can't have a common
BUG_FRAMEimplementation. So I would like to retain this information before someone wants to consolidate the code and missed this issue.
Fair enough, albeit I guess this then could do with re-wording.
Quoted 3 lines
Regarding the mergeable string section, I agree that the comment in now stale. However, could someone confirm that "i" will still retain the same behavior as using mergeable string sections?
That's depend on compiler settings / behavior.
Jan
Re: [PATCH v5 1/3] xen/arm: add support for run_in_exception_handler()
Hi Jan,
Quoted 73 lines · Jan Beulich
Quoted 72 lines · Julien Grall
Quoted 70 lines · Jan Beulich
Quoted 52 lines · Juergen Gross
xen/include/asm-arm/bug.h +10
-16@@ -15,65 +15,62 @@struct bug_frame {signed int loc_disp;/* Relative address to the bug address */ -signed int file_disp;/* Relative address to the filename */ +signed int ptr_disp;/* Relative address to the filename or function */ signed int msg_disp;/* Relative address to the predicate (for ASSERT) */ uint16_t line;/* Line number */ uint32_t pad0:16 ;/* Padding for 8-bytes align */ };#define bug_loc (b) ((const void *)(b) + (b)->loc_disp) -#define bug_file (b) ((const void *)(b) + (b)->file_disp); +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp);#define bug_line (b) ((b)->line)#define bug_msg (b) ((const char *)(b) + (b)->msg_disp) -#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 -#define BUGFRAME_NR 3 +#define BUGFRAME_NR 4/* 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. */ -#define BUG_FRAME (type, line, file, has_msg, msg) do { \ +#define BUG_FRAME (type, line, ptr, msg) do { \ BUILD_BUG_ON((line) >> 16); \ BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm ("1:"BUG_INSTR"\n" \ - ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ - "2:\t.asciz " __stringify(file) "\n" \ - "3:\n" \ - ".if " #has_msg "\n" \ - "\t.asciz " #msg "\n" \ - ".endif\n" \ - ".popsection\n" \ - ".pushsection .bug_frames." __stringify(type) ", \"a\", %progbits\n"\ - "4:\n" \ + ".pushsection .bug_frames." __stringify(type) ", \"a\", %%progbits\n"\ + "2:\n" \ ".p2align 2\n" \xen/include/asm-arm/bug.h line 53
Quoted 10 lines
xen/include/asm-arm/bug.h +4
-4-".long (1b - 4b)\n" \ -".long (2b - 4b)\n" \ -".long (3b - 4b)\n" \ +".long (1b - 2b)\n" \ +".long (%0 - 2b)\n" \ +".long (%1 - 2b)\n" \ ".hword " __stringify(line) ", 0\n" \ - ".popsection"); \ + ".popsection" :: "i" (ptr), "i" (msg)); \ }while (0 )The comment ahead of the construct now looks to be at best stale, if not entirely pointless. The reference to %c looks quite strange here to me anyway - I can only guess it appeared here because on x86 one has to use %c to output constants as operands for .long and alike, and this was then tried to use on Arm as well without there really being a need.
Quoted 5 lines
Quoted 3 lines
Well, %c is one the reason why we can't have a common
BUG_FRAMEimplementation. So I would like to retain this information before someone wants to consolidate the code and missed this issue.Fair enough, albeit I guess this then could do with re-wording.
I agree.
Quoted 6 lines
Quoted 4 lines
Regarding the mergeable string section, I agree that the comment in now stale. However, could someone confirm that "i" will still retain the same behavior as using mergeable string sections?
That's depend on compiler settings / behavior.
Ok. I wanted to see the difference between before and after but it looks like I can't compile Xen after applying the patch:
In file included from /home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/lib.h:23:0,
from/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/bitmap.h:6,
from bitmap.c:10:
bitmap.c: In function ‘bitmap_allocate_region’:
/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:44:5: error: asm operand 0 probably doesn’t match constraints [-Werror]
asm ("1:"BUG_INSTR"\n"
\
^
/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:60:5: note: in expansion of macro ‘BUG_FRAME’
BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, ""); \
^~~~~~~~~
/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/lib.h:25:42: note: in expansion of macro ‘BUG’
#define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
^~~bitmap.c:330:2: note: in expansion of macro ‘BUG_ON’
BUG_ON(pages > BITS_PER_LONG);
^~~~~~/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:44:5: error: asm operand 1 probably doesn’t match constraints [-Werror]
asm ("1:"BUG_INSTR"\n"
\
^
/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:60:5: note: in expansion of macro ‘BUG_FRAME’
BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, ""); \
^~~~~~~~~
/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/lib.h:25:42: note: in expansion of macro ‘BUG’
#define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
^~~bitmap.c:330:2: note: in expansion of macro ‘BUG_ON’
BUG_ON(pages > BITS_PER_LONG);
^~~~~~/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:44:5: error: impossible constraint in ‘asm’
asm ("1:"BUG_INSTR"\n"
\
^
/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:60:5: note: in expansion of macro ‘BUG_FRAME’
BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, ""); \
^~~~~~~~~
/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/lib.h:25:42: note: in expansion of macro ‘BUG’
#define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
^~~bitmap.c:330:2: note: in expansion of macro ‘BUG_ON’
BUG_ON(pages > BITS_PER_LONG);
^~~~~~
cc1: all warnings being treated as errors
I am using GCC 7.5.0 built by Linaro (cross-compiler). Native compilation with GCC 10.2.1 leads to the same error.
@Juergen, which compiler did you use?
Signature · 1 line
Julien Grall
Re: [PATCH v5 1/3] xen/arm: add support for run_in_exception_handler()
Quoted 154 lines · Julien Grall
Hi Jan,
Quoted 90 lines · Jan Beulich
Quoted 89 lines · Julien Grall
Quoted 87 lines · Jan Beulich
Quoted 71 lines · Juergen Gross
xen/include/asm-arm/bug.h +0
-0@@ -15,65 +15,62 @@ struct bug_frame {signed int loc_disp; /* Relative address to the bug address */ - signed int file_disp; /* Relative address to the filename */
+ signed int ptr_disp; /* Relative address to the filename or function */
signed int msg_disp; /* Relative address to the predicate (for ASSERT) */uint16_tline; /* Line number */
uint32_tpad0:16; /* Padding for 8-bytes align */
};
#definebug_loc(b)((const void *)(b) + (b)->loc_disp)xen/include/asm-arm/bug.h +1
-1-#define bug_file (b) ((const void *)(b) + (b)->file_disp); +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp);#define
bug_line(b)((b)->line)
#definebug_msg(b)((const char *)(b) + (b)->msg_disp)xen/include/asm-arm/bug.h +5
-4-#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 -#define BUGFRAME_NR 3 +#define BUGFRAME_NR 4/* 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.
*/
-#defineBUG_FRAME(type, line, file, has_msg, msg)do
{ \
+#defineBUG_FRAME(type, line, ptr, msg)do
{ \
BUILD_BUG_ON((line) >> 16); \
BUILD_BUG_ON((type) >= BUGFRAME_NR); \
asm ("1:"BUG_INSTR"\n" \
- ".pushsection .rodata.str, \"aMS\", %progbits,
1\n" \
- "2:\t.asciz "__stringify(file)
"\n" \
-
"3:\n" \
- ".if " #has_msg
"\n" \
- "\t.asciz " #msg
"\n" \
-
".endif\n" \
-
".popsection\n" \
- ".pushsection .bug_frames."__stringify(type)", \"a\", %progbits\n"\
-
"4:\n" \
+ ".pushsection .bug_frames."__stringify(type)", \"a\", %%progbits\n"\
+
"2:\n" \
".p2align 2\n" \
- ".long (1b -
4b)\n" \
- ".long (2b -
4b)\n" \
- ".long (3b -
4b)\n" \
+ ".long (1b -
2b)\n" \
+ ".long (%0 -
2b)\n" \Quoted 8 lines
+ ".long (%1 -
2b)\n" \
".hword "__stringify(line)", 0\n" \
-
".popsection"); \
+ ".popsection" :: "i" (ptr), "i"
(msg)); \
} while (0)The comment ahead of the construct now looks to be at best stale, if not entirely pointless. The reference to %c looks quite strange here to me anyway - I can only guess it appeared here because on x86 one has to use %c to output constants as operands for .long and alike, and this was then tried to use on Arm as well without there really being a need.
Quoted 5 lines
Quoted 3 lines
Well, %c is one the reason why we can't have a common
BUG_FRAMEimplementation. So I would like to retain this information before someone wants to consolidate the code and missed this issue.Fair enough, albeit I guess this then could do with re-wording.
I agree.
Quoted 6 lines
Quoted 4 lines
Regarding the mergeable string section, I agree that the comment in now stale. However, could someone confirm that "i" will still retain the same behavior as using mergeable string sections?
That's depend on compiler settings / behavior.
Ok. I wanted to see the difference between before and after but it looks like I can't compile Xen after applying the patch:
In file included from
/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/lib.h:23:0,
from/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/bitmap.h:6,
from bitmap.c:10:bitmap.c: In function ‘bitmap_allocate_region’:/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:44:5: error: asm operand 0 probably doesn’t match constraints [-Werror]
asm ("1:"BUG_INSTR"\n" \
^/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:60:5: note: in expansion of macro ‘BUG_FRAME’
BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, ""); \
^~~~~~~~~/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/lib.h:25:42: note: in expansion of macro ‘BUG’
#define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
^~~
bitmap.c:330:2: note: in expansion of macro ‘BUG_ON’
BUG_ON(pages > BITS_PER_LONG);
^~~~~~/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:44:5: error: asm operand 1 probably doesn’t match constraints [-Werror]
asm ("1:"BUG_INSTR"\n" \
^/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:60:5: note: in expansion of macro ‘BUG_FRAME’
BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, ""); \
^~~~~~~~~/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/lib.h:25:42: note: in expansion of macro ‘BUG’
#define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
^~~
bitmap.c:330:2: note: in expansion of macro ‘BUG_ON’
BUG_ON(pages > BITS_PER_LONG);
^~~~~~/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:44:5: error: impossible constraint in ‘asm’
asm ("1:"BUG_INSTR"\n" \
^/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/asm/bug.h:60:5: note: in expansion of macro ‘BUG_FRAME’
BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, ""); \
^~~~~~~~~/home/ANT.AMAZON.COM/jgrall/works/oss/xen/xen/include/xen/lib.h:25:42: note: in expansion of macro ‘BUG’
#define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
^~~
bitmap.c:330:2: note: in expansion of macro ‘BUG_ON’
BUG_ON(pages > BITS_PER_LONG);
^~~~~~
cc1: all warnings being treated as errors
Quoted 4 lines
I am using GCC 7.5.0 built by Linaro (cross-compiler). Native compilation with GCC 10.2.1 leads to the same error.
@Juergen, which compiler did you use?
gcc 7.4.0 aarch64 cross-compiler (SUSE)
Juergen
PATCH v5 2/3 xen: enable keyhandlers to work without register set specified
In reply to Juergen GrossThere 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 copy with a NULL regs pointer by using run_in_exception_handler() in that case.
---
V4:
- new patch
--- xen/common/keyhandler.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
xen/common/keyhandler.c +14 -3
@@ -181,7 +181,10 @@ static void dump_registers(unsigned char key, struct cpu_user_regs *regs)cpumask_copy (&dump_execstate_mask, &cpu_online_map);/* 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);/* 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, struct cpu_user_regs *regs)tasklet_schedule (&run_all_keyhandlers_tasklet); } -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);/* Prevent tail call optimisation, which confuses xendbg. */ barrier (); } +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 *regs) { alt_key_handling = !alt_key_handling;
Signature · 1 line
2.26.2
PATCH v5 3/3 xen: add support for automatic debug key actions in case of crash
In reply to Juergen GrossWhen 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-<type>=<string>
with <type> being one of:
panic, hwdom, watchdog, kexeccmd, debugkey
and <string> a sequence of debug key characters with '+' having the special semantics of a 10 millisecond pause.
So "crash-debug-watchdog=0+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.
---
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(-)
docs/misc/xen-command-line.pandoc +37 -0
@@ -574,6 +574,43 @@ reduction of features at Xen's disposal to manage guests. ### cpuinfo (x86) > `= <boolean>` +### crash-debug-debugkey +### crash-debug-hwdom +### crash-debug-kexeccmd +### crash-debug-panic +### crash-debug-watchdog +> `= <string>` + +> Can be modified at runtime + +Specify debug-key actions in cases of crashes. Each of the parameters applies +to a different crash reason. The `<string>` 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_KEXEC. + +`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=0+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. + ### crashinfo_maxaddr > `= <size>`
xen/common/kexec.c +5 -3
@@ -373,10 +373,12 @@ static int kexec_common_shutdown(void)return 0 ; } -void kexec_crash (void ) +void kexec_crash (enum crash_reason reason) {int pos; +keyhandler_crash_action (reason); + pos = (test_bit (KEXEC_FLAG_CRASH_POS , &kexec_flags) !=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" ); }
@@ -840,7 +842,7 @@ static int kexec_exec(XEN_GUEST_HANDLE_PARAM(void) uarg) ret =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 ; }
xen/common/keyhandler.c +55 -0
68 lines not on this page · raw message
xen/common/shutdown.c +2 -2
@@ -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 */
@@ -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 */
xen/drivers/char/console.c +1 -1
@@ -1271,7 +1271,7 @@ void panic(const char *fmt, ...)debugger_trap_immediate (); -kexec_crash (); +kexec_crash (CRASHREASON_PANIC );if ( opt_noreboot )machine_halt ();
xen/include/xen/kexec.h +8 -2
@@ -1,6 +1,8 @@#ifndef __XEN_KEXEC_H__#define __XEN_KEXEC_H__ +#include <xen/keyhandler.h> +#ifdef CONFIG_KEXEC #include <public/kexec.h>
@@ -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 0static 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) {}
xen/include/xen/keyhandler.h +10 -0
@@ -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); +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__ */
Signature · 1 line
2.26.2