introduce generic implementation of macros from bug.h
v2 cover introduce generic implementation of macros from bug.h
A large part of the content of the bug.h is repeated among all architectures (especially x86 and RISCV have the same implementation), so it was created a new config CONFIG_GENERIC_BUG_FRAME which is used to introduce generic implementation of do_bug_frame() and move x86's <asm/bug.h> to <xen/common/...> with the following changes:
* Add inclusion of arch-specific header <asm/bug.h>
* Rename the guard and remove x86 specific changes
* Wrap macros BUG_FRAME/run_in_exception_handler/WARN/BUG/assert_failed/etc into #ifndef "BUG_FRAME/run_in_exception_handler/WARN/BUG/assert_failed/etc" thereby each architecture can override the generic implementation of macros.
* Add #if{n}def __ASSEMBLY__ ... #endif
* Introduce BUG_FRAME_STRUCTURE define to be able to change the structure of bug frame
* Introduce BUG_INSTR and MODIFIER to make _ASM_BUGFRAME_TEXT reusable between x86 and
RISC-V.
* Make macros related to bug frame structure more generic.
For ARM only common parts were removed from <asm/bug.h> and re-use generic do_bug_frame() for ARM.
RISC-V will be switched to use <xen/bug.h> and in the future, it will use common the version of do_bug_frame() when xen/common will work for RISC-V.
---
Changes in V2:
* Update cover letter.
* Switch to x86 implementation as generic as it is more compact ( at least from the point of view of bug frame structure).
* Put [PATCH v1 4/4] xen: change <asm/bug.h> to <xen/bug.h> as second patch,
update the patch to change all <asm/bug.h> to <xen/bug.h> among the whole project
to not break compilation.
* Rename CONFIG_GENERIC_DO_BUG_FRAME to CONFIG_GENERIC_BUG_FRAME.
* Change the macro bug_loc(b) to avoid the need for a cast:
#define bug_loc(b) ((unsigned long)(b) + (b)->loc_disp)
* Rename BUG_FRAME_STUFF to BUG_FRAME_STRUCT
* Make macros related to bug frame structure more generic.
* Rename bug_file() in ARM implementation to bug_ptr() as generic do_bug_frame() uses
bug_ptr().
* Introduce BUG_INSTR and MODIFIER to make _ASM_BUGFRAME_TEXT reusable between x86 and
RISC-V. * Rework do_invalid_op() in x86 ( re-use handle_bug_frame() and find_bug_frame() )
---
Oleksii Kurochko (4):
xen: introduce CONFIG_GENERIC_BUG_FRAME
xen: change <asm/bug.h> to <xen/bug.h>
xen/arm: switch ARM to use generic implementation of bug.h
xen/x86: switch x86 to use generic implemetation of bug.h
xen/arch/arm/Kconfig | 1 + xen/arch/arm/include/asm/bug.h | 32 +----- xen/arch/arm/include/asm/div64.h | 2 +- xen/arch/arm/include/asm/traps.h | 2 - xen/arch/arm/traps.c | 79 ------------- xen/arch/arm/vgic/vgic-v2.c | 2 +- xen/arch/arm/vgic/vgic.c | 2 +- xen/arch/x86/Kconfig | 1 + xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 +- xen/arch/x86/include/asm/asm_defns.h | 2 +- xen/arch/x86/include/asm/bug.h | 88 +-------------- xen/arch/x86/traps.c | 81 +++----------- xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/bug.c | 113 +++++++++++++++++++ xen/drivers/cpufreq/cpufreq.c | 2 +- xen/include/xen/bug.h | 161 +++++++++++++++++++++++++++ xen/include/xen/lib.h | 2 +- 18 files changed, 306 insertions(+), 270 deletions(-) create mode 100644 xen/common/bug.c create mode 100644 xen/include/xen/bug.h
Signature · 1 line
2.39.0
PATCH v2 1/4 xen: introduce CONFIG_GENERIC_BUG_FRAME
A large part of the content of the bug.h is repeated among all architectures, so it was decided to create a new config CONFIG_GENERIC_BUG_FRAME.
The version of <bug.h> from x86 was taken as the base version.
The patch introduces the following stuff:
* common bug.h header
* generic implementation of do_bug_frame()
* new config CONFIG_GENERIC_BUG_FRAME
---
Changes in V2:
- Switch to x86 implementation as generic as it is more compact ( at least from the point of view of bug frame structure ).
- Rename CONFIG_GENERIC_DO_BUG_FRAME to CONFIG_GENERIC_BUG_FRAME.
- Change the macro bug_loc(b) to avoid the need for a cast:
#define bug_loc(b) ((unsigned long)(b) + (b)->loc_disp)
- Rename BUG_FRAME_STUFF to BUG_FRAME_STRUCT
- Make macros related to bug frame structure more generic.
- Introduce BUG_INSTR and MODIFIER to make _ASM_BUGFRAME_TEXT reusable
between x86 and RISC-V.
- Rework do_bug_frame() and introduce find_bug_frame() and handle_bug_frame()
functions to make it reusable by x86.
- code style fixes
---
xen/common/Kconfig | 3 +
xen/common/Makefile | 1 +
xen/common/bug.c | 113 +++++++++++++++++++++++++++++
xen/include/xen/bug.h | 161 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 278 insertions(+)
create mode 100644 xen/common/bug.c
create mode 100644 xen/include/xen/bug.hxen/common/Kconfig +3 -0
@@ -28,6 +28,9 @@ config ALTERNATIVE_CALL config ARCH_MAP_DOMAIN_PAGE bool +config GENERIC_BUG_FRAME + bool + config HAS_ALTERNATIVE bool
xen/common/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_ARGO) += argo.o obj-y += bitmap.o +obj-$(CONFIG_GENERIC_BUG_FRAME) += bug.o obj-$(CONFIG_HYPFS_CONFIG) += config_data.o obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o
xen/common/bug.c new file +113 -0
113 lines not on this page · raw message
xen/include/xen/bug.h new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
2.39.0
Re: [PATCH v2 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
Quoted 19 lines · Oleksii Kurochko
A large part of the content of the
bug.his repeated among all architectures, so it was decided to create a new configCONFIG_GENERIC_BUG_FRAME.The version of <
bug.h> from x86 was taken as the base version.The patch introduces the following stuff:
* commonbug.hheader
* generic implementation ofdo_bug_frame()
* new configCONFIG_GENERIC_BUG_FRAMESigned-off-by Oleksii Kurochko <[email protected]>---
Changes in V2:
- Switch to x86 implementation as generic as it is more compact ( at least from the point of view of bug frame structure ).
- RenameCONFIG_GENERIC_DO_BUG_FRAMEtoCONFIG_GENERIC_BUG_FRAME.
- Change the macrobug_loc(b)to avoid the need for a cast:
Quoted 5 lines
#define bug_loc(b) ((unsigned long)(b) + (b)->loc_disp)- Rename
BUG_FRAME_STUFFtoBUG_FRAME_STRUCT
- Make macros related to bug frame structure more generic.
- IntroduceBUG_INSTRand MODIFIER to make_ASM_BUGFRAME_TEXTreusable between x86 and RISC-V.
Hmm, below I see it's really just "MODIFIER". I see two issues with this:
For one the name is too generic for something which cannot be #undef-ed after use inside the header. And then it also doesn't really say what is being modified. While ending up longer, how about BUG_ASM_CONST or alike?
I also think this should default to something if not overridden by an arch. Perhaps simply to an expansion to nothing (at which point you won't need to define it for RISC-V, aiui).
xen/common/bug.c line 9
Quoted 12 lines
xen/common/bug.c new file +9
-0@@ -0,0 +1,113 @@ +#include <xen/bug.h> +#include <xen/errno.h> +#include <xen/kernel.h> +#include <xen/livepatch.h> +#include <xen/string.h> +#include <xen/types.h> +#include <xen/virtual_region.h> + +#include <asm/processor.h>
Is this really needed here?
xen/common/bug.c line 11
Quoted 1 line
xen/common/bug.c new file +1
-0+const struct bug_frame *find_bug_frame (unsigned long pc,unsigned int *id)
Is this function going to be needed outside of this CU? IOW why is it not static?
Also, nit: Left most star wants changing places with the adjacent blank.
Quoted 9 lines
xen/common/bug.c new file +9
-0+{ +const struct bug_frame *bug =NULL ; +const struct virtual_region *region; + + region =find_text_region (pc); +if ( region ) + { +for ( *id =0 ; *id <BUGFRAME_NR ; (*id)++ ) + {
xen/common/bug.c line 30
Quoted 10 lines
xen/common/bug.c new file +10
-0+const struct bug_frame *b; +unsigned int i; + +for ( i =0 , b = region->frame[*id].bugs; + i < region->frame[*id].n_bugs; b++, i++ ) + { +if (bug_loc (b) == pc ) + { + bug = b; + goto found;
While in the original code the goto is kind of warranted, it isn't really here imo. You can simply "return b" here and ...
xen/common/bug.c line 37
Quoted 7 lines
xen/common/bug.c new file +7
-0+ } + } + } + } + + found: +return bug;
... "return NULL" here. That'll allow the function scope "bug" to go away, at which point the inner scope "b" can become "bug".
xen/common/bug.c line 42
Quoted 5 lines
xen/common/bug.c new file +5
-0+} + +int handle_bug_frame (const struct cpu_user_regs *regs, +const struct bug_frame *bug, +unsigned int id)
Nit: Indentation is off by one here. Also same question regarding the lack of static here.
xen/common/bug.c line 50
Quoted 8 lines
xen/common/bug.c new file +8
-0+{ +const char *prefix ="" , *filename, *predicate; +unsigned long fixup; +unsigned int lineno; + +if ( id == BUGFRAME_run_fn ) + { +#ifdef ARM
Who or what defines ARM? Anyway, seeing ...
xen/common/bug.c line 51
Quoted 1 line
xen/common/bug.c new file +1
-0+void (*fn)(const struct cpu_user_regs *) = (void *)regs->BUG_FN_REG;
... this, wouldn't it be better (and independent of the specific arch) if you checked for BUG_FN_REG being defined?
Another (#ifdef-free) variant would be to have bug_ptr() take a 2nd argument and then uniformly use ...
xen/common/bug.c line 53
Quoted 2 lines
xen/common/bug.c new file +2
-0+#else +void (*fn)(const struct cpu_user_regs *) =bug_ptr (bug);
... this, slightly altered to
void (*fn)(const struct cpu_user_regs *) = bug_ptr(bug, regs);
Quoted 41 lines
xen/common/bug.c new file +41
-0+#endif + +fn (regs); +return 0 ; + } + +/* WARN, BUG or ASSERT: decode the filename pointer and line number. */ + filename =bug_ptr (bug); +if ( !is_kernel (filename) && !is_patch (filename) ) +return -EINVAL ; + fixup =strlen (filename); +if ( fixup >50 ) + { + filename += fixup -47 ; + prefix ="..." ; + } + lineno =bug_line (bug); + +switch ( id ) + { +case BUGFRAME_warn: +printk ("Xen WARN at %s%s:%d\n" , prefix, filename, lineno); +show_execution_state (regs); +return 0 ; + +case BUGFRAME_bug: +printk ("Xen BUG at %s%s:%d\n" , prefix, filename, lineno); + +show_execution_state (regs); +panic ("Xen BUG at %s%s:%d\n" , prefix, filename, lineno); + +case BUGFRAME_assert: +/* ASSERT: decode the predicate string pointer. */ + predicate =bug_msg (bug); +if ( !is_kernel (predicate) ) + predicate ="<unknown>" ; + +printk ("Assertion '%s' failed at %s%s:%d\n" , + predicate, prefix, filename, lineno); + +show_execution_state (regs);
xen/common/bug.c line 104
Quoted 10 lines
xen/common/bug.c new file +10
-0+panic ("Assertion '%s' failed at %s%s:%d\n" , + predicate, prefix, filename, lineno); + } + +return -EINVAL ; +} + +int do_bug_frame (const struct cpu_user_regs *regs,unsigned long pc) +{ +const struct bug_frame *bug =NULL ;
Nit: pointless initializer. You could of course have the assignment below become the initializer here.
xen/common/bug.c line 108
Quoted 4 lines
xen/common/bug.c new file +4
-0+unsigned int id; + + bug =find_bug_frame (pc, &id); +if (!bug)
Nit: Style (missing blanks).
Quoted 15 lines
xen/include/xen/bug.h new file +12
-0@@ -0,0 +1,161 @@ +#ifndef __XEN_BUG_H__ +#define __XEN_BUG_H__ + +#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) + +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 +
xen/include/xen/bug.h line 22
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+#define BUGFRAME_NR 4 + +#ifndef __ASSEMBLY__ + +#include <xen/errno.h> +#include <xen/lib.h> +#include <xen/stringify.h> +#include <xen/types.h> + +#include <asm/bug.h>
Any reason this cannot live ahead of the #ifndef, eliminating the need for an #else further down?
Quoted 5 lines
xen/include/xen/bug.h new file +5
-0+#ifndef BUG_FRAME_STRUCT + +struct bug_frame { + signed int loc_disp:BUG_DISP_WIDTH; + unsigned int line_hi:BUG_LINE_HI_WIDTH;
xen/include/xen/bug.h line 38
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+ signed int ptr_disp:BUG_DISP_WIDTH; + unsigned int line_lo:BUG_LINE_LO_WIDTH; + signed int msg_disp[]; +}; + +#endif /* BUG_FRAME_STRUCT */ + +#ifndef bug_loc +#define bug_loc (b) ((unsigned long)(b) + (b)->loc_disp) +#endif /* bug_loc */
For short #if / #ifdef I don't think such comments are necessary on the #else or #endif; personally I consider such to hamper readability.
Quoted 11 lines
xen/include/xen/bug.h new file +11
-0+#ifndef bug_ptr +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp) +#endif /* bug_ptr */ + +#ifndef bug_line +#define bug_line (b) (((((b)->line_hi + ((b)->loc_disp < 0)) & \ + ((1 << BUG_LINE_HI_WIDTH) - 1)) << \ + BUG_LINE_LO_WIDTH) + \ + (((b)->line_lo + ((b)->ptr_disp < 0)) & \ + ((1 << BUG_LINE_LO_WIDTH) - 1))) +#endif /* bug_line */
xen/include/xen/bug.h line 60
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+ +#ifndef bug_msg +#define bug_msg (b) ((const char *)(b) + (b)->msg_disp[1]) +#endif /* bug_msg */ + +#ifndef _ASM_BUGFRAME_TEXT + +#define _ASM_BUGFRAME_TEXT (second_frame) \ + ".Lbug%=:"BUG_INSTR"\n" \ + ".pushsection .bug_frames.%"MODIFIER"[bf_type], \"a\", @progbits\n" \
You may want to use %progbits here right away, as being the more portable form.
xen/include/xen/bug.h line 68
Quoted 8 lines
xen/include/xen/bug.h new file +8
-0+".p2align 2\n" \ +".Lfrm%=:\n" \ +".long (.Lbug%= - .Lfrm%=) + %" MODIFIER "[bf_line_hi]\n" \ +".long (%" MODIFIER "[bf_ptr] - .Lfrm%=) + %" MODIFIER "[bf_line_lo]\n" \ + ".if " #second_frame "\n" \ + ".long 0, %"MODIFIER"[bf_msg] - .Lfrm%=\n" \ + ".endif\n" \ + ".popsection\n"
I think I said so in reply to an earlier version already: The moment assembly code moves to a common header, it should be adjusted to be as portable as possible. In particular directives should never start at the beginning of a line, while labels always should. (Whether .long is actually portable is another question, which I'll be happy to leave aside for now.)
Also nit (style): The line continuation characters want to all line up.
xen/include/xen/bug.h line 72
Quoted 3 lines
xen/include/xen/bug.h new file +3
-0+#endif /* _ASM_BUGFRAME_TEXT */ + +#ifndef _ASM_BUGFRAME_INFO
I don't think these two make sense for an arch to define independently. INFO absolutely has to match TEXT, so I think an arch should always define (or not) both together.
Quoted 17 lines
xen/include/xen/bug.h new file +17
-0+#define _ASM_BUGFRAME_INFO (type, line, ptr, msg) \ + [bf_type] "i" (type), \ + [bf_ptr] "i" (ptr), \ + [bf_msg] "i" (msg), \ + [bf_line_lo] "i" ((line & ((1 << BUG_LINE_LO_WIDTH) - 1)) \ + << BUG_DISP_WIDTH), \ + [bf_line_hi] "i" (((line) >> BUG_LINE_LO_WIDTH) << BUG_DISP_WIDTH) + +#endif /* _ASM_BUGFRAME_INFO */ + +#ifndef BUG_FRAME + +#define BUG_FRAME (type, line, ptr, second_frame, msg) do { \ + BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \ + BUILD_BUG_ON((type) >= BUGFRAME_NR); \ + asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \ + :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \
xen/include/xen/bug.h line 100
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+} while (0) + +#endif + +#ifndef run_in_exception_handler + +/* +* TODO: untangle header dependences, break BUILD_BUG_ON() out of xen/lib.h, +* and use a real static inline here to get proper type checking of fn(). +*/
I realize you only copy this comment, but I'm having a hard time seeing the connection to BUILD_BUG_ON() here. Would be nice if the comment was "generalized" in a form that actually can be understood. Andrew?
xen/include/xen/bug.h line 111
Quoted 11 lines
xen/include/xen/bug.h new file +11
-0+#define run_in_exception_handler (fn) \ + do { \ + (void)((fn) == (void (*)(struct cpu_user_regs *))NULL); \ + BUG_FRAME(BUGFRAME_run_fn, 0, fn, 0, NULL); \ + } while ( 0 ) + +#endif /* run_in_exception_handler */ + +#ifndef WARN +#define WARN () BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, NULL) +#endif /* WARN */
No real need for the comment here; you also have none below for e.g. BUG().
Jan
Re: [PATCH v2 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
Hello Jan,
Quoted 27 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
A large part of the content of the
bug.his repeated among all architectures, so it was decided to create a new configCONFIG_GENERIC_BUG_FRAME.The version of <
bug.h> from x86 was taken as the base version.The patch introduces the following stuff:
* commonbug.hheader
* generic implementation ofdo_bug_frame()
* new configCONFIG_GENERIC_BUG_FRAMESigned-off-by Oleksii Kurochko <[email protected]>Quoted 12 lines
---
Changes in V2:
- Switch to x86 implementation as generic as it is more compact ( at least from the point of view of bug frame structure ).
- RenameCONFIG_GENERIC_DO_BUG_FRAMEtoCONFIG_GENERIC_BUG_FRAME.
- Change the macrobug_loc(b)to avoid the need for a cast:
#definebug_loc(b)((unsigned long)(b) + (b)->loc_disp)
- RenameBUG_FRAME_STUFFtoBUG_FRAME_STRUCT
- Make macros related to bug frame structure more generic.
- IntroduceBUG_INSTRand MODIFIER to make_ASM_BUGFRAME_TEXTreusable
between x86 and RISC-V.
Quoted 8 lines
Hmm, below I see it's really just "MODIFIER". I see two issues with this:
For one the name is too generic for something which cannot be #undef- ed
after use inside the header. And then it also doesn't really say what is
being modified. While ending up longer, how aboutBUG_ASM_CONSTor alike?
BUG_ASM_CONST will be much better.
Quoted 5 lines
I also think this should default to something if not overridden by an arch. Perhaps simply to an expansion to nothing (at which point you won't need to define it for RISC-V, aiui).
Agree.
Initially, I thought about that too but couldn't estimate how well the modifier '%c' is supported, deciding that each architecture has to define it.
But we can make it equal to nothing (at least for 2 architectures ) it doesn't have the same support as in x86.
Quoted 6 lines
Quoted 6 lines
xen/common/bug.c new file +3
-0@@ -0,0 +1,113 @@ +#include <xen/bug.h> +#include <xen/errno.h> +#include <xen/kernel.h>
Quoted 8 lines
xen/common/bug.c line 9
Quoted 6 lines
xen/common/bug.c new file +6
-0+#include <xen/livepatch.h> +#include <xen/string.h> +#include <xen/types.h> +#include <xen/virtual_region.h> + +#include <asm/processor.h> Is this really needed here?
Yes, it is.
Function show_execution_state() is declared in this header for all architectures and is used by handle_bug_frame().
Quoted 8 lines
Quoted 3 lines
xen/common/bug.c new file +1
-0+const struct bug_frame* find_bug_frame(unsigned long pc, unsignedint *id)
Is this function going to be needed outside of this CU? IOW why is it not
static?
It's not static because there is not possible to use do_bug_frame() as is for x86 as x86 has some additional checks for some cases which aren't in generic implementation:
[1]
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/x86/traps.c#L1217
[2]
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/x86/traps.c#L1238
[3]
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/x86/traps.c#L1259
Probably to make generic do_bug_frame() more re-usable for x86 we can implement as stubs fixup_exception_return() and debugger_trap_fatal() under #ifndef X86 ... #endif inside common/bug.c.
Could you please share your thoughts about that?
Quoted 2 lines
Also, nit: Left most star wants changing places with the adjacent blank.
Thanks. I'll update in the next version of the patch series.
Quoted 33 lines
Quoted 10 lines
xen/common/bug.c new file +9
-0+{ + const struct bug_frame *bug = NULL; + const struct virtual_region *region; + + region = find_text_region(pc); + if ( region ) + { + for ( *id = 0; *id < BUGFRAME_NR; (*id)++ ) + {xen/common/bug.c line 30
Quoted 10 lines
xen/common/bug.c new file +10
-0+ const struct bug_frame *b; + unsigned int i; + + for ( i = 0, b = region->frame[*id].bugs; + i < region->frame[*id].n_bugs; b++, i++ ) + { + if ( bug_loc(b) == pc ) + { + bug = b; + goto found;While in the original code the goto is kind of warranted, it isn't really
here imo. You can simply "return b" here and ...Quoted 7 lines
+ }
+ }
+ }
+ }
+
+ found:
+ return bug;
Quoted 3 lines
... "return NULL" here. That'll allow the function scope "bug" to go away,
at which point the inner scope "b" can become "bug".
Agree, missed that when decided to move that part of the code to separate function.
Quoted 10 lines
xen/common/bug.c line 42
Quoted 6 lines
xen/common/bug.c new file +5
-0+} + +int handle_bug_frame (const struct cpu_user_regs *regs, + const struct bug_frame *bug, + unsigned int id)Nit: Indentation is off by one here. Also same question regarding the lack
of static here.
Regarding static an answer is the same as with previous one static question.
Quoted 11 lines
xen/common/bug.c line 50
Quoted 9 lines
xen/common/bug.c new file +8
-0+{ + const char *prefix = "", *filename, *predicate; + unsigned long fixup; + unsigned int lineno; + + if ( id == BUGFRAME_run_fn ) + { +#ifdef ARMWho or what defines ARM? Anyway, seeing ...
it is defined by default in Kconfig:
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/arm/Kconfig#L13
Quoted 7 lines
Quoted 3 lines
+ void (*fn)(const struct
cpu_user_regs*) = (void *)regs-Quoted 1 line
BUG_FN_REG;... this, wouldn't it be better (and independent of the specific arch) if
you checked forBUG_FN_REGbeing defined?
If I understand Kconfig correctly than there is no significant difference what check. But probably BUG_FN_REG would be a little bit better if someone will decide to change a way how pointer to function will be passed in case of ARM than we will get compilation error and so won't miss to fix the line in do_bug_frame().
Quoted 5 lines
Another (#ifdef-free) variant would be to have
bug_ptr()take a 2nd argument
and then uniformly use ...
Quoted 7 lines
Quoted 2 lines
+#else
+ void (*fn)(const structcpu_user_regs*) =bug_ptr(bug);... this, slightly altered to
void (*fn)(const struct
cpu_user_regs*) =bug_ptr(bug, regs);
Probably this one option will be the most universal and we have to stick to it.
Quoted 50 lines
Quoted 50 lines
xen/common/bug.c new file +7
-0+#endif + + fn(regs); + return 0; + } + + /* WARN, BUG or ASSERT: decode the filename pointer and linenumber. */
+ filename =bug_ptr(bug);
+ if ( !is_kernel(filename) && !is_patch(filename) ) + return-EINVAL;
+ fixup = strlen(filename);
+ if ( fixup > 50 )
+ {
+ filename += fixup - 47;
+ prefix = "...";
+ }
+ lineno =bug_line(bug);xen/common/bug.c new file +31
-0+ + switch ( id ) + { + case BUGFRAME_warn: + printk("Xen WARN at %s%s:%d\n", prefix, filename, lineno); + show_execution_state(regs); + return 0; + + case BUGFRAME_bug: + printk("Xen BUG at %s%s:%d\n", prefix, filename, lineno); + + show_execution_state(regs); + panic("Xen BUG at %s%s:%d\n", prefix, filename, lineno); + + case BUGFRAME_assert: + /* ASSERT: decode the predicate string pointer. */ + predicate = bug_msg(bug); + if ( !is_kernel(predicate) ) + predicate = "<unknown>"; + + printk("Assertion '%s' failed at %s%s:%d\n", + predicate, prefix, filename, lineno); + + show_execution_state(regs); + panic("Assertion '%s' failed at %s%s:%d\n", + predicate, prefix, filename, lineno); + } + + return -EINVAL; +} +
Quoted 8 lines
Quoted 4 lines
+int
do_bug_frame(const struct cpu_user_regs *regs, unsigned long pc)
+{
+ const structbug_frame*bug = NULL;Nit: pointless initializer. You could of course have the assignment below
become the initializer here.
Thanks. I'll update it the next version of the patch.
Quoted 7 lines
Quoted 5 lines
+ unsigned int id;
+
+ bug =find_bug_frame(pc, &id);
+ if (!bug)Nit: Style (missing blanks).
Thanks. I'll update it the next version of the patch.
Quoted 22 lines
Quoted 22 lines
xen/include/xen/bug.h new file +18
-0@@ -0,0 +1,161 @@ +#ifndef __XEN_BUG_H__ +#define __XEN_BUG_H__ + +#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) + +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 + +#define BUGFRAME_NR 4 + +#ifndef __ASSEMBLY__ + +#include <xen/errno.h> +#include <xen/lib.h>
Quoted 8 lines
xen/include/xen/bug.h line 22
Quoted 4 lines
xen/include/xen/bug.h new file +4
-0+#include <xen/stringify.h> +#include <xen/types.h> + +#include <asm/bug.h> Any reason this cannot live ahead of the #ifndef, eliminating the need for
an #else further down?
It should be fine.
Probably I had some issues during the initial stage of making bug.h more generic...
Quoted 12 lines
Quoted 12 lines
xen/include/xen/bug.h new file +11
-0+#ifndef BUG_FRAME_STRUCT + +struct bug_frame { + signed int loc_disp:BUG_DISP_WIDTH; + unsigned int line_hi:BUG_LINE_HI_WIDTH; + signed int ptr_disp:BUG_DISP_WIDTH; + unsigned int line_lo:BUG_LINE_LO_WIDTH; + signed int msg_disp[]; +}; + +#endif /* BUG_FRAME_STRUCT */
Quoted 8 lines
xen/include/xen/bug.h line 38
Quoted 4 lines
xen/include/xen/bug.h new file +4
-0+ +#ifndef bug_loc +#define bug_loc (b) ((unsigned long)(b) + (b)->loc_disp) +#endif /* bug_loc */ For short #if / #ifdef I don't think such comments are necessary on the
#else or #endif; personally I consider such to hamper readability.
Thanks. I'll take it into account.
Quoted 27 lines
Quoted 27 lines
xen/include/xen/bug.h new file +6
-0+#ifndef bug_ptr +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp) +#endif /* bug_ptr */ + +#ifndef bug_line +#define bug_line (b) (((((b)->line_hi + ((b)->loc_disp < 0))& \
+ ((1 <<BUG_LINE_HI_WIDTH) - 1)) << \
+BUG_LINE_LO_WIDTH)
+ \
+ (((b)->line_lo + ((b)->ptr_disp < 0)) & \
+ ((1 <<BUG_LINE_LO_WIDTH) - 1)))xen/include/xen/bug.h new file +9
-0+#endif /* bug_line */ + +#ifndef bug_msg +#define bug_msg (b) ((const char *)(b) + (b)->msg_disp[1]) +#endif /* bug_msg */ + +#ifndef _ASM_BUGFRAME_TEXT + +#define
_ASM_BUGFRAME_TEXT(second_frame)
\
+
Quoted 8 lines
Quoted 4 lines
".Lbug%=:"BUG_INSTR"\n"
\
+ ".pushsection .bug_frames.%"MODIFIER"[bf_type], \"a\", @progbits\n" \You may want to use %progbits here right away, as being the more portable
form.
Sure. Thanks. I'll take that into account.
Quoted 19 lines
Quoted 10 lines
+ ".p2align
2\n" \
+
".Lfrm%=:\n"
\
+ ".long (.Lbug%= - .Lfrm%=) + %"MODIFIER"[bf_line_hi]\n" \
+ ".long (%"MODIFIER"[bf_ptr] - .Lfrm%=) + %"MODIFIER"[bf_line_lo]\n" \Quoted 8 lines
+ ".if " #second_frame
"\n" \
+ ".long 0, %"MODIFIER"[bf_msg] - .Lfrm%=\n" \
+
".endif\n"
\
+ ".popsection\n"
Quoted 8 lines
I think I said so in reply to an earlier version already: The moment assembly code moves to a common header, it should be adjusted to be as
portable as possible. In particular directives should never start at the
beginning of a line, while labels always should. (Whether .long is actually portable is another question, which I'll be happy to leave aside for now.)
I am not sure that I understand about which one directive we are talking about... Are we talking about .{push/pop}section and .p2align? Probably you can show me an example in Xen or other project?
Quoted 4 lines
Also nit (style): The line continuation characters want to all line up.
Quoted 8 lines
xen/include/xen/bug.h line 72
Quoted 3 lines
xen/include/xen/bug.h new file +3
-0+#endif /* _ASM_BUGFRAME_TEXT */ + +#ifndef _ASM_BUGFRAME_INFOI don't think these two make sense for an arch to define independently.
INFO absolutely has to match TEXT, so I think an arch should always define (or not) both together.
You are right. I'll take into account that.
Quoted 49 lines
Quoted 38 lines
+#define _ASM_BUGFRAME_INFO(type, line, ptr,
msg) \
+ [bf_type] "i"
(type), \
+ [bf_ptr] "i"
(ptr), \
+ [bf_msg] "i"
(msg), \
+ [bf_line_lo] "i" ((line & ((1 <<BUG_LINE_LO_WIDTH) - 1)) \
+ <<
BUG_DISP_WIDTH), \
+ [bf_line_hi] "i" (((line) >>BUG_LINE_LO_WIDTH) <<BUG_DISP_WIDTH)xen/include/xen/bug.h new file +6
-0+ +#endif /* _ASM_BUGFRAME_INFO */ + +#ifndef BUG_FRAME + +#define BUG_FRAME (type, line, ptr, second_frame, msg) do{ \
+BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \
+ BUILD_BUG_ON((type) >=
BUGFRAME_NR); \
+ asm volatile (
_ASM_BUGFRAME_TEXT(second_frame) \
+ ::_ASM_BUGFRAME_INFO(type, line, ptr, msg)); \xen/include/xen/bug.h new file +8
-0+} while (0) + +#endif + +#ifndef run_in_exception_handler + +/* +* TODO: untangle header dependences, break BUILD_BUG_ON() out of Quoted 4 lines
xen/lib.h,
+ * and use a real static inline here to get proper type checking offn().
+ */I realize you only copy this comment, but I'm having a hard time seeing
the connection toBUILD_BUG_ON()here. Would be nice if the comment was
"generalized" in a form that actually can be understood. Andrew?
Quoted 15 lines
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+#define run_in_exception_handler (fn) \ + do { \ + (void)((fn) == (void (*)(struct cpu_user_regs *))NULL); \ + BUG_FRAME(BUGFRAME_run_fn, 0, fn, 0, NULL); \ + } while ( 0 ) + +#endif /* run_in_exception_handler */ + +#ifndef WARN +#define WARN () BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0,Quoted 2 lines
NULL)
+#endif /* WARN */No real need for the comment here; you also have none below for e.g.
BUG().
Thanks.
Quoted 2 lines
Jan
~ Oleksii
Re: [PATCH v2 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
Quoted 16 lines · Oleksii
Quoted 15 lines · Jan Beulich
xen/common/bug.c line 9
Quoted 12 lines · Oleksii Kurochko
xen/common/bug.c new file +9
-0@@ -0,0 +1,113 @@ +#include <xen/bug.h> +#include <xen/errno.h> +#include <xen/kernel.h> +#include <xen/livepatch.h> +#include <xen/string.h> +#include <xen/types.h> +#include <xen/virtual_region.h> + +#include <asm/processor.h> Is this really needed here?
Quoted 4 lines
Yes, it is.
Function
show_execution_state()is declared in this header for all architectures and is used byhandle_bug_frame().
Ugly, but yes, you're right.
Quoted 17 lines
Quoted 7 lines
Quoted 2 lines
xen/common/bug.c new file +1
-0+const struct bug_frame* find_bug_frame(unsigned long pc, unsignedint *id)
Is this function going to be needed outside of this CU? IOW why is it not
static?It's not static because there is not possible to use
do_bug_frame()as is for x86 as x86 has some additional checks for some cases which aren't in generic implementation:
[1]
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/x86/traps.c#L1217
[2]
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/x86/traps.c#L1238
[3]
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/x86/traps.c#L1259
Quoted 5 lines
Probably to make generic
do_bug_frame()more re-usable for x86 we can implement as stubsfixup_exception_return()anddebugger_trap_fatal()under #ifndef X86 ... #endif insidecommon/bug.c.Could you please share your thoughts about that?
Isn't all that's needed a suitable return value from the function, for the caller to take appropriate further action? (Maybe even that isn't really necessary.)
That said, debugger_trap_fatal() imo may sensibly be generalized, and hence could be left in common code. Arm may simply stub this to nothing then for the time being.
Quoted 10 lines
Quoted 10 lines
xen/common/bug.c line 50
Quoted 8 lines
xen/common/bug.c new file +8
-0+{ + const char *prefix = "", *filename, *predicate; + unsigned long fixup; + unsigned int lineno; + + if ( id == BUGFRAME_run_fn ) + { +#ifdef ARMWho or what defines ARM? Anyway, seeing ...
Quoted 2 lines
it is defined by default in
Kconfig:
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/arm/Kconfig#L13
That'll be CONFIG_ARM then in uses in C code.
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
+ void (*fn)(const struct
cpu_user_regs*) = (void *)regs-Quoted 1 line
BUG_FN_REG;... this, wouldn't it be better (and independent of the specific arch) if
you checked forBUG_FN_REGbeing defined?If I understand
Kconfigcorrectly than there is no significant difference what check. But probablyBUG_FN_REGwould be a little bit better if someone will decide to change a way how pointer to function will be passed in case of ARM than we will get compilation error and so won't miss to fix the line indo_bug_frame().
Indeed - #ifdef like this one generally want to check for the precise aspect in question, without making assumptions about something implying something else. (Pretty certainly there are exceptions to this rule, but it holds here.)
Quoted 26 lines
Quoted 18 lines
Quoted 9 lines
+ ".p2align
2\n" \
+
".Lfrm%=:\n"
\
+ ".long (.Lbug%= - .Lfrm%=) + %"MODIFIER"[bf_line_hi]\n" \
+ ".long (%"MODIFIER"[bf_ptr] - .Lfrm%=) + %"MODIFIER"[bf_line_lo]\n" \Quoted 8 lines
+ ".if " #second_frame
"\n" \
+ ".long 0, %"MODIFIER"[bf_msg] - .Lfrm%=\n" \
+
".endif\n"
\
+ ".popsection\n"Quoted 8 lines
I think I said so in reply to an earlier version already: The moment assembly code moves to a common header, it should be adjusted to be as
portable as possible. In particular directives should never start at the
beginning of a line, while labels always should. (Whether .long is actually portable is another question, which I'll be happy to leave aside for now.)
Quoted 3 lines
I am not sure that I understand about which one directive we are talking about... Are we talking about .{push/pop}section and .p2align? Probably you can show me an example in Xen or other project?
I'm talking about all directives here. Fundamentally assembly language source lines are like this (assuming colons follow labels):
[<label>:|<blank>][<directive>|<insn>]
Both parts can optionally be empty, but if the right one isn't, then the left one also shouldn't be (and hence minimally a blank is needed; commonly it would be a tab). Directives, unlike insns, start with a dot in most dialects. Labels can also start with a dot, but are disambiguated by the colon after them (yet more strict placement of items is therefore required when labels are not followed by colons - there are such dialects -, which is why it is generally a good idea to follow that simple formatting rule). Also, ftaod,
- <insn> covers both actual insns as well as assembler macro invocations,
- there can of course be multiple labels on a single line (iirc this requires that colons follow labels).
As to examples: I'm afraid I'm unaware of arch-independent assembly code anywhere in Xen so far.
Jan
Re: [PATCH v2 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
Quoted 52 lines · Jan Beulich
Quoted 16 lines · Oleksii
Quoted 15 lines · Jan Beulich
xen/common/bug.c line 9
Quoted 12 lines · Oleksii Kurochko
xen/common/bug.c new file +9
-0@@ -0,0 +1,113 @@ +#include <xen/bug.h> +#include <xen/errno.h> +#include <xen/kernel.h> +#include <xen/livepatch.h> +#include <xen/string.h> +#include <xen/types.h> +#include <xen/virtual_region.h> + +#include <asm/processor.h> Is this really needed here?
Quoted 4 lines
Yes, it is.
Function
show_execution_state()is declared in this header for all architectures and is used byhandle_bug_frame().Ugly, but yes, you're right.
Quoted 20 lines
Quoted 9 lines
Quoted 3 lines
xen/common/bug.c new file +1
-0+const struct bug_frame* find_bug_frame(unsigned long pc,unsigned
int *id)Is this function going to be needed outside of this CU? IOW why is it
not
static?It's not static because there is not possible to use
do_bug_frame()as
is for x86 as x86 has some additional checks for some cases which aren't in generic implementation:
[1]
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/x86/traps.c#L1217
[2]
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/x86/traps.c#L1238
[3]
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/x86/traps.c#L1259Quoted 7 lines
Probably to make generic
do_bug_frame()more re-usable for x86 we can
implement as stubsfixup_exception_return()anddebugger_trap_fatal()
under #ifndef X86 ... #endif insidecommon/bug.c.Could you please share your thoughts about that?
Quoted 7 lines
Isn't all that's needed a suitable return value from the function, for the caller to take appropriate further action? (Maybe even that isn't really necessary.)
That said,
debugger_trap_fatal()imo may sensibly be generalized, and hence could be left in common code. Arm may simply stub this to nothing then for the time being.
I checked the source code I found that debugger_trap_fatal() is generalized:
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/include/xen/debugger.h
So we can use in generic version of do_bug_frame().
About fixup_exception_return() you are right as we can it handle(call) by the caller so it's needed only to return a suitable return value for do_bug_frame().
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
xen/common/bug.c line 50
Quoted 9 lines
xen/common/bug.c new file +8
-0+{ + const char *prefix = "", *filename, *predicate; + unsigned long fixup; + unsigned int lineno; + + if ( id == BUGFRAME_run_fn ) + { +#ifdef ARMWho or what defines ARM? Anyway, seeing ...
Quoted 4 lines
Quoted 2 lines
it is defined by default in
Kconfig:
https://gitlab.com/xen-project/people/olkur/xen/-/blob/staging/xen/arch/arm/Kconfig#L13That'll be
CONFIG_ARMthen in uses in C code.
Ahh, yeah. I am always missing CONFIG_...
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
+ void (*fn)(const struct
cpu_user_regs*) = (void *)regs-Quoted 1 line
BUG_FN_REG;... this, wouldn't it be better (and independent of the specific arch) if
you checked forBUG_FN_REGbeing defined?Quoted 8 lines
If I understand
Kconfigcorrectly than there is no significant difference what check. But probablyBUG_FN_REGwould be a little bit
better if someone will decide to change a way how pointer to function
will be passed in case of ARM than we will get compilation error and so
won't miss to fix the line indo_bug_frame().
Quoted 5 lines
Indeed - #ifdef like this one generally want to check for the precise aspect in question, without making assumptions about something implying
something else. (Pretty certainly there are exceptions to this rule, but it holds here.)
Thanks for the explanation.
Quoted 59 lines
Quoted 34 lines
Quoted 21 lines
Quoted 12 lines
+ ".p2align
2\n" \
+
".Lfrm%=:\n"
\
+ ".long (.Lbug%= - .Lfrm%=) + %"MODIFIER"[bf_line_hi]\n" \
+ ".long (%"MODIFIER"[bf_ptr] - .Lfrm%=) + %"MODIFIER"[bf_line_lo]\n" \
+ ".if " #second_frameQuoted 8 lines
"\n" \
+ ".long 0, %"MODIFIER"[bf_msg] - .Lfrm%=\n" \
+
".endif\n"
\
+ ".popsection\n"Quoted 13 lines
I think I said so in reply to an earlier version already: The moment
assembly code moves to a common header, it should be adjusted to be
as
portable as possible. In particular directives should never start at
the
beginning of a line, while labels always should. (Whether .long is
actually portable is another question, which I'll be happy to leave
aside for now.)Quoted 4 lines
I am not sure that I understand about which one directive we are talking about... Are we talking about .{push/pop}section and .p2align?
Probably you can show me an example in Xen or other project?I'm talking about all directives here. Fundamentally assembly language
source lines are like this (assuming colons follow labels):[<label>:|<blank>][<directive>|<insn>]
Both parts can optionally be empty, but if the right one isn't, then the left one also shouldn't be (and hence minimally a blank is needed;
commonly it would be a tab). Directives, unlike insns, start with a dot in most dialects. Labels can also start with a dot, but are disambiguated by the colon after them (yet more strict placement of items is therefore required when labels are not followed by colons - there are such dialects -, which is why it is generally a good idea to follow that simple formatting rule). Also, ftaod,
- <insn> covers both actual insns as well as assembler macro invocations,
- there can of course be multiple labels on a single line (iirc this requires that colons follow labels).
Quoted 2 lines
As to examples: I'm afraid I'm unaware of arch-independent assembly code anywhere in Xen so far.
Thank you very much for the explanation.
Quoted 2 lines
Jan
~ Oleksii
Re: [PATCH v2 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
In reply to Jan BeulichQuoted 12 lines
Quoted 3 lines
+ void (*fn)(const struct
cpu_user_regs*) = (void *)regs-Quoted 1 line
BUG_FN_REG;... this, wouldn't it be better (and independent of the specific arch) if
you checked forBUG_FN_REGbeing defined?Another (#ifdef-free) variant would be to have
bug_ptr()take a 2nd argument
and then uniformly use ...
Quoted 7 lines
Quoted 2 lines
+#else
+ void (*fn)(const structcpu_user_regs*) =bug_ptr(bug);... this, slightly altered to
void (*fn)(const struct
cpu_user_regs*) =bug_ptr(bug, regs);
I think that I will go with BUG_FN_REG instead of changing bug_ptr()'s arguments as bug_ptr() is used below to get file name so it won't be clear what bug_ptr() should return either an address of file name or regs->BUG_FN_REG.
Quoted 12 lines
Quoted 11 lines
xen/common/bug.c new file +7
-0+#endif + + fn(regs); + return 0; + } + + /* WARN, BUG or ASSERT: decode the filename pointer and linenumber. */
+ filename =bug_ptr(bug);
+ if ( !is_kernel(filename) && !is_patch(filename) )
~ Oleksii
Re: [PATCH v2 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
Quoted 15 lines · Oleksii
Quoted 15 lines
Quoted 3 lines
+ void (*fn)(const struct
cpu_user_regs*) = (void *)regs-Quoted 1 line
BUG_FN_REG;... this, wouldn't it be better (and independent of the specific arch) if
you checked forBUG_FN_REGbeing defined?Another (#ifdef-free) variant would be to have
bug_ptr()take a 2nd argument
and then uniformly use ...Quoted 2 lines
+#else
+ void (*fn)(const structcpu_user_regs*) =bug_ptr(bug);
Quoted 8 lines
Quoted 4 lines
... this, slightly altered to
void (*fn)(const struct
cpu_user_regs*) =bug_ptr(bug, regs);I think that I will go with
BUG_FN_REGinstead of changing bug_ptr()'s arguments asbug_ptr()is used below to get file name so it won't be clear whatbug_ptr()should return either an address of file name orregs->BUG_FN_REG.
Oh, indeed - I'm sorry that I didn't pay attention to ...
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
xen/common/bug.c new file +7
-0+#endif + + fn(regs); + return 0; + } + + /* WARN, BUG or ASSERT: decode the filename pointer and linenumber. */
+ filename =bug_ptr(bug);
+ if ( !is_kernel(filename) && !is_patch(filename) )
... this 2nd use.
Jan
Re: [PATCH v2 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
In reply to Oleksii KurochkoQuoted 15 lines · Oleksii Kurochko
xen/include/xen/bug.h new file +12
-0@@ -0,0 +1,161 @@ +#ifndef __XEN_BUG_H__ +#define __XEN_BUG_H__ + +#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) + +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 +
xen/include/xen/bug.h line 22
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+#define BUGFRAME_NR 4 + +#ifndef __ASSEMBLY__ + +#include <xen/errno.h> +#include <xen/lib.h> +#include <xen/stringify.h> +#include <xen/types.h> + +#include <asm/bug.h>
Looking at patch 2 onwards I came to wonder: How does that work without you first removing stuff from the respective asm/bug.h (or adding suitable #define-s to limit what gets defined below)? From all I can tell the compiler should object to ...
xen/include/xen/bug.h line 32
Quoted 9 lines
xen/include/xen/bug.h new file +9
-0+#ifndef BUG_FRAME_STRUCT + +struct bug_frame { +signed int loc_disp:BUG_DISP_WIDTH ; +unsigned int line_hi:BUG_LINE_HI_WIDTH ; +signed int ptr_disp:BUG_DISP_WIDTH ; +unsigned int line_lo:BUG_LINE_LO_WIDTH ; +signed int msg_disp[]; +};
... this, as asm/bug.h will have declared such a struct already. The #define-s further down may not be a problem if what they expand to matches in both places, but that's then still a latent trap to fall into.
Jan
Re: [PATCH v2 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
Quoted 33 lines · Jan Beulich
Quoted 15 lines · Oleksii Kurochko
xen/include/xen/bug.h new file +12
-0@@ -0,0 +1,161 @@ +#ifndef __XEN_BUG_H__ +#define __XEN_BUG_H__ + +#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) + +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 +xen/include/xen/bug.h line 22
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+#define BUGFRAME_NR 4 + +#ifndef __ASSEMBLY__ + +#include <xen/errno.h> +#include <xen/lib.h> +#include <xen/stringify.h> +#include <xen/types.h> + +#include <asm/bug.h> Looking at patch 2 onwards I came to wonder: How does that work without
you first removing stuff from the respectiveasm/bug.h(or adding suitable #define-s to limit what gets defined below)? From all I can tell the compiler should object to ...
Quoted 14 lines
xen/include/xen/bug.h line 32
Quoted 9 lines
xen/include/xen/bug.h new file +9
-0+#ifndef BUG_FRAME_STRUCT + +struct bug_frame { + signed int loc_disp:BUG_DISP_WIDTH; + unsigned int line_hi:BUG_LINE_HI_WIDTH; + signed int ptr_disp:BUG_DISP_WIDTH; + unsigned int line_lo:BUG_LINE_LO_WIDTH; + signed int msg_disp[]; +};... this, as
asm/bug.hwill have declared such a struct already. The #define-s further down may not be a problem if what they expand to matches in both places, but that's then still a latent trap to fall into.
My fault. It doesn't work. I checked only RISC-V arch before and didn't start all the test for patch 2...
So yeah, in patch 2 should be updated asm/bug.h headers with define BUG_FRAME_STRUCT and remove all common parts [ BUG_DISP_WIDTH, BUG_LINE_LO_WIDTH, BUG_LINE_HI_WIDTH, BUGFRAME_run_fn, BUGFRAME_warn, BUGFRAME_bug, BUGFRAME_assert, BUGFRAME_NR, {__start|__stop}_bug_frames{ | _{0-3} }[], ].
Thanks for noticing that.
Quoted 2 lines
Jan
~ Oleksii
PATCH v2 2/4 xen: change <asm/bug.h> to <xen/bug.h>
In reply to Oleksii KurochkoSince the generic version of bug.h stuff was introduced use <xen/bug.h> instead of unnecessary <asm/bug.h>
---
Changes in V2:
* Put [PATCH v1 4/4] xen: change <asm/bug.h> to <xen/bug.h> as second patch, update the patch to change all <asm/bug.h> to <xen/bug.h> among the whole project to not break build.
* Update the commit message.
--- xen/arch/arm/include/asm/div64.h | 2 +- xen/arch/arm/vgic/vgic-v2.c | 2 +- xen/arch/arm/vgic/vgic.c | 2 +- xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 +- xen/arch/x86/include/asm/asm_defns.h | 2 +- xen/drivers/cpufreq/cpufreq.c | 2 +- xen/include/xen/lib.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-)
xen/arch/arm/include/asm/div64.h +1 -1
@@ -74,7 +74,7 @@#elif __GNUC__ >=4 -#include <asm/bug.h> +#include <xen/bug.h> /* * If the divisor happens to be constant, we determine the appropriate
xen/arch/arm/vgic/vgic-v2.c +1 -1
@@ -16,8 +16,8 @@*/ #include <asm/new_vgic.h> -#include <asm/bug.h> #include <asm/gic.h> +#include <xen/bug.h> #include <xen/sched.h> #include <xen/sizes.h>
xen/arch/arm/vgic/vgic.c +1 -1
@@ -15,9 +15,9 @@* along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <xen/bug.h> #include <xen/list_sort.h> #include <xen/sched.h> -#include <asm/bug.h> #include <asm/event.h> #include <asm/new_vgic.h>
xen/arch/x86/acpi/cpufreq/cpufreq.c +1 -1
@@ -27,6 +27,7 @@* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#include <xen/bug.h> #include <xen/types.h> #include <xen/errno.h> #include <xen/delay.h>
@@ -35,7 +36,6 @@#include <xen/sched.h> #include <xen/timer.h> #include <xen/xmalloc.h> -#include <asm/bug.h> #include <asm/msr.h> #include <asm/io.h> #include <asm/processor.h>
xen/arch/x86/include/asm/asm_defns.h +1 -1
@@ -6,7 +6,7 @@/* NB. Auto-generated from arch/.../asm-offsets.c */ #include <asm/asm-offsets.h> #endif -#include <asm/bug.h> +#include <xen/bug.h> #include <asm/x86-defns.h> #include <xen/stringify.h> #include <asm/cpufeature.h>
xen/drivers/cpufreq/cpufreq.c +1 -1
@@ -26,6 +26,7 @@* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#include <xen/bug.h> #include <xen/types.h> #include <xen/errno.h> #include <xen/delay.h>
@@ -39,7 +40,6 @@#include <xen/guest_access.h> #include <xen/domain.h> #include <xen/cpu.h> -#include <asm/bug.h> #include <asm/io.h> #include <asm/processor.h>
xen/include/xen/lib.h +1 -1
@@ -24,12 +24,12 @@#ifndef __ASSEMBLY__ +#include <xen/bug.h> #include <xen/inttypes.h> #include <xen/stdarg.h> #include <xen/types.h> #include <xen/xmalloc.h> #include <xen/string.h> -#include <asm/bug.h> #define BUG_ON (p) do { if (unlikely(p)) BUG(); } while (0)#define WARN_ON (p) ({ \
Signature · 1 line
2.39.0
Re: [PATCH v2 2/4] xen: change <asm/bug.h> to <xen/bug.h>
Quoted 6 lines · Oleksii Kurochko
xen/include/xen/lib.h +0
-0@@ -24,12 +24,12 @@#ifndef __ASSEMBLY__
xen/include/xen/lib.h line 35
Quoted 10 lines
xen/include/xen/lib.h +1
-1+#include <xen/bug.h> #include <xen/inttypes.h> #include <xen/stdarg.h> #include <xen/types.h> #include <xen/xmalloc.h> #include <xen/string.h> -#include <asm/bug.h> #define BUG_ON (p) do { if (unlikely(p)) BUG(); } while (0)#define WARN_ON (p) ({ \
As just said in reply to patch 1 - I can't see how this would build at this point. There looks to be an ordering problem; you first need to remove from asm/bug.h what's now also available from xen/bug.h. Possibly parts of patches 3 and 4 need to move here.
Jan
Re: [PATCH v2 2/4] xen: change <asm/bug.h> to <xen/bug.h>
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
xen/include/xen/lib.h +0
-0@@ -24,12 +24,12 @@
#ifndef__ASSEMBLY__
+#include <xen/bug.h>
#include <xen/inttypes.h>
#include <xen/stdarg.h>
#include <xen/types.h>
#include <xen/xmalloc.h>
#include <xen/string.h>
-#include <asm/bug.h>
Quoted 8 lines
Quoted 3 lines
#define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0) #define WARN_ON(p) ({ \As just said in reply to patch 1 - I can't see how this would build at this point. There looks to be an ordering problem; you first need to remove from
asm/bug.hwhat's now also available fromxen/bug.h. Possibly parts of patches 3 and 4 need to move here.
Yeah, you are right as I answared to your reply to patch 1. I missed that because I tested only RISC-V and didn't run tests for all architectures.
I'll remove generic parts from patches 3 and 4 to patch 2 and will add define BUG_FRAME_STRUCT to asm/bug.h specific headers.
Quoted 2 lines
Jan
~ Oleksii
PATCH v2 3/4 xen/arm: switch ARM to use generic implementation of bug.h
In reply to Oleksii Kurochko---
Changes in V2:
* Rename bug_file() in ARM implementation to bug_ptr() as generic do_bug_frame() uses bug_ptr().
* Remove generic parts from bug.h
* Remove declaration of 'int do_bug_frame(...)' from <asm/traps.h> as it was introduced in <xen/bug.h>
--- xen/arch/arm/Kconfig | 1 + xen/arch/arm/include/asm/bug.h | 32 +------------ xen/arch/arm/include/asm/traps.h | 2 - xen/arch/arm/traps.c | 79 -------------------------------- 4 files changed, 3 insertions(+), 111 deletions(-)
xen/arch/arm/Kconfig +1 -0
@@ -12,6 +12,7 @@ config ARM_64 config ARM def_bool y + select GENERIC_BUG_FRAME select HAS_ALTERNATIVE select HAS_DEVICE_TREE select HAS_PASSTHROUGH
xen/arch/arm/include/asm/bug.h +2 -30
@@ -9,9 +9,7 @@# error "unknown ARM variant"#endif -#define BUG_DISP_WIDTH 24 -#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) -#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_FRAME_STRUCT struct bug_frame {signed int loc_disp;/* Relative address to the bug address */
@@ -21,18 +19,10 @@ struct bug_frame { 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)->file_disp)#define bug_line (b) ((b)->line)#define bug_msg (b) ((const char *)(b) + (b)->msg_disp) -#define BUGFRAME_run_fn 0 -#define BUGFRAME_warn 1 -#define BUGFRAME_bug 2 -#define BUGFRAME_assert 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
@@ -77,24 +67,6 @@ struct bug_frame { ".popsection" :: "r" (fn) : __stringify(BUG_FN_REG) ); \ } while (0) -#define WARN () BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, "") - -#define BUG () do { \ - BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, 0, ""); \ - unreachable(); \ -} while (0) - -#define assert_failed (msg) do { \ - BUG_FRAME(BUGFRAME_assert, __LINE__, __FILE__, 1, msg); \ - unreachable(); \ -} while (0) - -extern const struct bug_frame __start_bug_frames[], - __stop_bug_frames_0[], - __stop_bug_frames_1[], - __stop_bug_frames_2[], - __stop_bug_frames_3[]; -#endif /* __ARM_BUG_H__ */ /* * Local variables:
xen/arch/arm/include/asm/traps.h +0 -2
@@ -69,8 +69,6 @@ void do_cp(struct cpu_user_regs *regs, const union hsr hsr);void do_trap_smc (struct cpu_user_regs *regs,const union hsr hsr);void do_trap_hvc_smccc (struct cpu_user_regs *regs); -int do_bug_frame (const struct cpu_user_regs *regs,vaddr_t pc); -void noreturndo_unexpected_trap (const char *msg,const struct cpu_user_regs *regs);void do_trap_hyp_sync (struct cpu_user_regs *regs);
xen/arch/arm/traps.c +0 -79
85 lines not on this page · raw message
Signature · 1 line
2.39.0
PATCH v2 4/4 xen/x86: switch x86 to use generic implemetation of bug.h
In reply to Oleksii Kurochko---
Changes in V2:
* Remove all unnecessary things from <asm/bug.h> as they were introduced in
<xen/bug.h>.
* Define BUG_INSTR = 'ud2' and MODIFIER = 'c' ( it is needed to skip '$'
when use an imidiate in x86 assembly )
* Update do_invalid_op() to re-use handle_bug_frame() and find_bug_frame()
from generic implemetation of CONFIG_GENERIC_BUG_FRAME
* Code style fixes.
---
xen/arch/x86/Kconfig | 1 +
xen/arch/x86/include/asm/bug.h | 88 ++--------------------------------
xen/arch/x86/traps.c | 81 +++++--------------------------
3 files changed, 18 insertions(+), 152 deletions(-)xen/arch/x86/Kconfig +1 -0
@@ -11,6 +11,7 @@ config X86 select ARCH_MAP_DOMAIN_PAGE select ARCH_SUPPORTS_INT128 select CORE_PARKING + select GENERIC_BUG_FRAME select HAS_ALTERNATIVE select HAS_COMPAT select HAS_CPUFREQ
xen/arch/x86/include/asm/bug.h +4 -84
102 lines not on this page · raw message
xen/arch/x86/traps.c +13 -68
112 lines not on this page · raw message
Signature · 1 line
2.39.0