introduce generic implementation of macros from bug.h
PATCH v5 2/4 xen: change <asm/bug.h> to <xen/bug.h>
In reply to Oleksii KurochkoThe idea of the patch is to change all <asm/bug.h> to <xen/bug.h> and keep Xen compilable with adding only minimal amount of changes:
1. It was added "#include <xen/types.h>" to ARM's "<asm/bug.h>" as it uses uint_{16,32}t in 'struct bug_frame'.
2. It was added '#define BUG_FRAME_STRUCT' which means that ARM hasn't been switched to generic implementation yet.
3. It was added '#define BUG_FRAME_STRUCT' which means that x86 hasn't been switched to generic implementation yet.
4. BUGFRAME_* and _start_bug_frame[], _stop_bug_frame_*[] were removed for ARM & x86 to deal with compilation errors such as:
redundant redeclaration of ...
In the following two patches x86 and ARM archictectures will be switched fully:
* xen/arm: switch ARM to use generic implementation of bug.h
* xen/x86: switch x86 to use generic implemetation of bug.h
---
Changes in V5:
- Nothing changed
---
Changes in V4:
- defines BUG_DISP_WIDTH, BUG_LINE_LO_WIDTH, BUG_LINE_HI_WIDTH were moved into "ifndef BUG_FRAME_STRUCT" in <xen/bug.h> as they are specific for 'struct bug_frame' and so should co-exist together. So the defines were back to <asm/bug.h> until BUG_FRAME_STRUCT will be defined in <asm/bug.h>.
- Update the comment message.
---
Changes in V3:
* Update patch 2 not to break compilation: move some parts from patches 3 and 4
to patch 2:
* move some generic parts from <asm/bug.h> to <xen/bug.h>
* add define BUG_FRAME_STRUCT in ARM's <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/bug.h | 17 ++++------------- 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/arch/x86/include/asm/bug.h | 15 ++------------- xen/drivers/cpufreq/cpufreq.c | 2 +- xen/include/xen/lib.h | 2 +- 9 files changed, 13 insertions(+), 33 deletions(-)
xen/arch/arm/include/asm/bug.h +4 -13
@@ -1,6 +1,8 @@#ifndef __ARM_BUG_H__#define __ARM_BUG_H__ +#include <xen/types.h> +#if defined(CONFIG_ARM_32 )# include <asm/arm32/bug.h> #elif defined(CONFIG_ARM_64 )
@@ -13,6 +15,8 @@#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 */ signed int file_disp;/* Relative address to the filename */
@@ -26,13 +30,6 @@ struct bug_frame {#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
@@ -89,12 +86,6 @@ struct bug_frame {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/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/arch/x86/include/asm/bug.h +2 -13
@@ -5,15 +5,10 @@#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__ +#define BUG_FRAME_STRUCT + struct bug_frame { signed int loc_disp:BUG_DISP_WIDTH; unsigned int line_hi:BUG_LINE_HI_WIDTH;
@@ -80,12 +75,6 @@ struct bug_frame {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[]; -#else /* !__ASSEMBLY__ */ /*
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
v5 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 BUG_ASM_CONST to make _ASM_BUGFRAME_TEXT reusable between architectures
* Make macros related to bug frame structure more generic.
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 V5:
* Update the cover letter message as the patch, on which the patch series
is based, has been merged to staging
* Remove "#ifdef BUG_FN_REG..." from generic do_bug_frame() as ARM will
use generic implementation fully.
---
Changes in V4:
* Introduce and use generic BUG_DEBUGGER_TRAP_FATAL(regs) mnacros which is used to deal with debugger_trap_fatal(TRAP_invalid_op, regs) where TRAP_invalid_op is x86-specific.
* Add comment what do_bug_frame() returns.
* Do refactoring of do_bug_frame():
* invert the condition 'if ( region )' in do_bug_frame() to reduce the indention.
* change type of variable i from 'unsigned int' to 'size_t' as it is compared with n_bugs which has type 'size_t'
* Remove '#include <xen/stringify.h>' from <xen/bug.h> as it doesn't need any more after switch to x86 implementation.
* Remove '#include <xen/errno.h>' as it isn't needed any more
* Move bug_*() macros inside '#ifndef BUG_FRAME_STRUCT'
* Add <xen/lib.h> to fix compile issue with BUILD_ON()...
* Add documentation for BUG_ASM_CONST.
* Defines BUG_DISP_WIDTH, BUG_LINE_LO_WIDTH, BUG_LINE_HI_WIDTH were moved into "ifndef BUG_FRAME_STRUCT" in <xen/bug.h> as they are specific for 'struct bug_frame' and so should co-exist together. So the defines were back to <asm/bug.h> until BUG_FRAME_STRUCT will be defined in
<asm/bug.h>.
* Switch ARM implementation to generic one
* Remove BUG_FN_REG from arm{16,32}/bug.h as it isn't needed after switch to generic implementation
* Back comment /* !__ASSEMBLY__ */ for #else case in <asm/bug.h>
* Remove changes related to x86/.../asm/debuger.h as do_bug_frame() prototype was updated and cpu_user_regs isn't const any more.
---
Changes in V3:
* Nothing was done with the comment in <xen/bug.h> before run_in_exception_handler
but I think it can be changed during the merge.
* Add debugger_trap_fatal() to do_bug_frame(). It simplifies usage of
do_bug_frame() for x86 so making handle_bug_frame() and find_bug_frame()
not needed anymore.
* Update do_bug_frame() to return -EINVAL if something goes wrong; otherwise
id of bug_frame
* Update _ASM_BUGFRAME_TEXT to make it more portable.
* Drop unnecessary comments.
* Update patch 2 not to break compilation: move some parts from patches 3 and 4
to patch 2
* As prototype and what do_bug_frame() returns was changed so patch 3 and 4
was updated to use a new version of do_bug_frame
* Change debugger_trap_fatal() prototype for x86 to align with prototype in
<xen/debugger.h>
---
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/arm32/traps.c | 2 +- xen/arch/arm/include/asm/arm32/bug.h | 2 - xen/arch/arm/include/asm/arm64/bug.h | 2 - xen/arch/arm/include/asm/bug.h | 88 +-------------- xen/arch/arm/include/asm/div64.h | 2 +- xen/arch/arm/include/asm/traps.h | 2 - xen/arch/arm/traps.c | 81 +------------- 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 | 84 +------------- xen/arch/x86/traps.c | 81 ++------------ xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/bug.c | 103 +++++++++++++++++ xen/drivers/cpufreq/cpufreq.c | 2 +- xen/include/xen/bug.h | 158 +++++++++++++++++++++++++++ xen/include/xen/lib.h | 2 +- 21 files changed, 289 insertions(+), 334 deletions(-) create mode 100644 xen/common/bug.c create mode 100644 xen/include/xen/bug.h
Signature · 1 line
2.39.0
PATCH v5 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 V5:
* Remove "#ifdef BUG_FN_REG..." from generic do_bug_frame() as ARM will
use generic implementation fully.
---
Changes in V4:
* common/bug.c:
- Use BUG_DEBUGGER_TRAP_FATAL(regs) mnacros instead of debugger_trap_fatal(TRAP_invalid_op, regs) in <common/bug.c> as TRAP_invalid_op is x86-specific thereby BUG_DEBUGGER_TRAP_FATAL should be defined for each architecture.
- add information about what do_bug_frame() returns.
- invert the condition 'if ( region )' in do_bug_frame() to reduce the indention.
- change type of variable i from 'unsigned int' to 'size_t' as it is compared with n_bugs which has type 'size_t'
* xen/bug.h:
- Introduce generic BUG_DEBUGGER_TRAP_FATAL(regs) mnacros which is used to deal with debugger_trap_fatal(TRAP_invalid_op, regs) where TRAP_invalid_op is x86-specific
- remove '#include <xen/stringify.h>' as it doesn't need any more after switch to x86 implementation.
- remove '#include <xen/errno.h>' as it isn't needed any more
- move bug_*() macros inside '#ifndef BUG_FRAME_STRUCT'
- add <xen/lib.h> to fix compile issue with BUILD_ON()...
- Add documentation for BUG_ASM_CONST.
* Update the commit message
---
Changes in V3:
* Add debugger_trap_fatal() to do_bug_frame(). It simplifies usage of do_bug_frame() for x86 so making handle_bug_frame() and find_bug_frame()
not needed anymore.
* Update do_bug_frame() to return -EINVAL if something goes wrong; otherwise
id of bug_frame
* Update _ASM_BUGFRAME_TEXT to make it more portable.
* Drop unnecessary comments.
* define stub value for TRAP_invalid_op in case if wasn't defined in
arch-specific folders.
---
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 | 103 +++++++++++++++++++++++++++
xen/include/xen/bug.h | 158 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 265 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 +103 -0
103 lines not on this page · raw message
xen/include/xen/bug.h new file +158 -0
158 lines not on this page · raw message
Signature · 1 line
2.39.0
PATCH v5 3/4 xen/arm: switch ARM to use generic implementation of bug.h
In reply to Oleksii KurochkoThe following changes were made:
* make GENERIC_BUG_FRAME mandatory for ARM
* As do_bug_frame() returns -EINVAL in case something goes wrong otherwise id of bug frame. Thereby 'if' cases where do_bug_frame() was updated to check if the returned value is less than 0
* Switch ARM's implementation of bug.h macros to generic one
---
Changes in V5:
* Nothing changed
---
Changes in V4:
* Switch ARM implementation to generic one
* Remove BUG_FN_REG from arm{16,32}/bug.h as it isn't needed after switch to generic implementation
* Update commit message
---
Changes in V3:
* As prototype and what do_bug_frame() returns was changed so patch 3 and 4
was updated to use a new version of do_bug_frame
---
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/arm32/traps.c | 2 +- xen/arch/arm/include/asm/arm32/bug.h | 2 - xen/arch/arm/include/asm/arm64/bug.h | 2 - xen/arch/arm/include/asm/bug.h | 75 +------------------------- xen/arch/arm/include/asm/traps.h | 2 - xen/arch/arm/traps.c | 81 +--------------------------- 7 files changed, 4 insertions(+), 161 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/arm32/traps.c +1 -1
@@ -48,7 +48,7 @@ void do_trap_undefined_instruction(struct cpu_user_regs *regs)if ( instr !=BUG_OPCODE ) goto die; -if (do_bug_frame (regs, pc) ) +if (do_bug_frame (regs, pc) <0 ) goto die; regs->pc +=4 ;
xen/arch/arm/include/asm/arm32/bug.h +0 -2
@@ -10,6 +10,4 @@#define BUG_INSTR ".word " __stringify(BUG_OPCODE) -#define BUG_FN_REG r0 -#endif /* __ARM_ARM32_BUG_H__ */
xen/arch/arm/include/asm/arm64/bug.h +0 -2
@@ -6,6 +6,4 @@#define BUG_INSTR "brk " __stringify(BRK_BUG_FRAME_IMM) -#define BUG_FN_REG x0 -#endif /* __ARM_ARM64_BUG_H__ */
xen/arch/arm/include/asm/bug.h +1 -74
81 lines not on this page · raw message
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 +1 -80
93 lines not on this page · raw message
Signature · 1 line
2.39.0
PATCH v5 4/4 xen/x86: switch x86 to use generic implemetation of bug.h
In reply to Oleksii KurochkoThe following changes were made:
* Make GENERIC_BUG_FRAME mandatory for X86
* Update asm/bug.h using generic implementation in <xen/bug.h>
* Change prototype of debugger_trap_fatal() in asm/debugger.h to align it with generic prototype in <xen/debugger.h>.
* Update do_invalid_op using generic do_bug_frame()
---
Changes in V5:
* Nothing changed
---
Changes in V4:
* Back comment /* !__ASSEMBLY__ */ for #else case in <asm/bug.h>
* Remove changes related to x86/.../asm/debuger.h as do_bug_frame() prototype was updated and cpu_user_regs isn't const any more.
---
Changes in V3:
* As prototype and what do_bug_frame() returns was changed so patch 3 and 4 was updated to use a new version of do_bug_frame
* MODIFIER was change to BUG_ASM_CONST to align with generic implementation
---
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 | 73 ++----------------------------
xen/arch/x86/traps.c | 81 +++-------------------------------
3 files changed, 11 insertions(+), 144 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 +3 -70
82 lines not on this page · raw message
xen/arch/x86/traps.c +7 -74
108 lines not on this page · raw message
Signature · 1 line
2.39.0
Re: [PATCH v5 3/4] xen/arm: switch ARM to use generic implementation of bug.h
In reply to Oleksii KurochkoQuoted 11 lines · Oleksii Kurochko
The following changes were made:
* makeGENERIC_BUG_FRAMEmandatory for ARM
* Asdo_bug_frame()returns-EINVALin case something goes wrong otherwise id of bug frame. Thereby 'if' cases wheredo_bug_frame()was updated to check if the returned value is less than 0
* Switch ARM's implementation ofbug.hmacros to generic oneSigned-off-by Oleksii Kurochko <[email protected]>---
Changes in V5:
* Nothing changed
I'm glad this isn't true, and the change to common/bug.c ...
Quoted 9 lines
--- xen/arch/arm/Kconfig | 1 + xen/arch/arm/arm32/traps.c | 2 +- xen/arch/arm/include/asm/arm32/bug.h | 2 - xen/arch/arm/include/asm/arm64/bug.h | 2 - xen/arch/arm/include/asm/bug.h | 75 +------------------------- xen/arch/arm/include/asm/traps.h | 2 - xen/arch/arm/traps.c | 81 +--------------------------- 7 files changed, 4 insertions(+), 161 deletions(-)
... is gone.
Jan
Re: [PATCH v5 3/4] xen/arm: switch ARM to use generic implementation of bug.h
Quoted 28 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
The following changes were made:
* makeGENERIC_BUG_FRAMEmandatory for ARM
* Asdo_bug_frame()returns-EINVALin case something goes wrong otherwise id of bug frame. Thereby 'if' cases wheredo_bug_frame()was
updated to check if the returned value is less than 0
* Switch ARM's implementation ofbug.hmacros to generic oneQuoted 4 lines
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V5:
* Nothing changedI'm glad this isn't true, and the change to
common/bug.c...Quoted 11 lines
---
xen/arch/arm/Kconfig | 1 + xen/arch/arm/arm32/traps.c | 2 +-xen/arch/arm/include/asm/arm32/bug.h| 2 -xen/arch/arm/include/asm/arm64/bug.h| 2 - xen/arch/arm/include/asm/bug.h | 75 +----------------------- --
xen/arch/arm/include/asm/traps.h | 2 - xen/arch/arm/traps.c | 81 +-----------------------
----7 files changed, 4 insertions(+), 161 deletions(-)
Quoted 1 line
... is gone.
Thanks for clarification.
I had to add this information.
It is gone because the first patch of the patch series was updated and the changes from common/bug.c which were in the previous version of the patch has been removed so after rebase they disappered in the current patch.
~ Oleksii
Re: [PATCH v5 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
In reply to Oleksii Kurochkoxen/common/Kconfig config ALTERNATIVE_CALL · line 32
Quoted 8 lines · Oleksii Kurochko
xen/common/Kconfig +2
-0@@ -28,6 +28,9 @@ config ALTERNATIVE_CALL config ARCH_MAP_DOMAIN_PAGE bool +config GENERIC_BUG_FRAME + bool
With Arm now also going to use the generic logic, do we actually need this control anymore (provided things have been proven to work on Arm for the compiler range we support there)? It looks like because of the way the series is partitioned it may be necessary transiently, but it should be possible to drop it again in a new 5th patch.
Quoted 7 lines
xen/common/bug.c new file +4
-0@@ -0,0 +1,103 @@ +#include <xen/bug.h> +#include <xen/debugger.h> +#include <xen/errno.h> +#include <xen/kernel.h>
xen/common/bug.c line 14
Quoted 10 lines
xen/common/bug.c new file +10
-0+#include <xen/livepatch.h> +#include <xen/string.h> +#include <xen/types.h> +#include <xen/virtual_region.h> + +#include <asm/processor.h> + +/* +* Returns a negative value in case of an error otherwise the bug type. +*/
Nit: Style (this is a single line comment). But see also below related comment on the function's declaration.
Quoted 9 lines
xen/common/bug.c new file +9
-0+int do_bug_frame (struct cpu_user_regs *regs,unsigned long pc) +{ +const struct bug_frame *bug =NULL ; +const struct virtual_region *region; +const char *prefix ="" , *filename, *predicate; +unsigned long fixup; +unsigned int id =BUGFRAME_NR , lineno; + + region =find_text_region (pc);
xen/common/bug.c line 33
Quoted 10 lines
xen/common/bug.c new file +10
-0+if ( !region ) +return -EINVAL ; + +for ( id =0 ; id <BUGFRAME_NR ; id++ ) + { +const struct bug_frame *b; +size_t i; + +for ( i =0 , b = region->frame[id].bugs; + i < region->frame[id].n_bugs; b++, i++ )
Nit: Indentation (the "i" on the 2nd line wants to align with that on the 1st one).
xen/common/bug.c line 45
Quoted 12 lines
xen/common/bug.c new file +12
-0+ { +if (bug_loc (b) == pc ) + { + bug = b; + goto found; + } + } + } + + found: +if ( !bug ) +return -EINVAL ;
While I'm generally unhappy with many uses of -EINVAL (it's used to indicate way too many different kinds of errors), can we at least consider using -ENOENT here instead? (I'm sorry, I should have asked for this earlier on.)
Quoted 4 lines
xen/include/xen/bug.h new file +1
-0@@ -0,0 +1,158 @@ +#ifndef __XEN_BUG_H__
xen/include/xen/bug.h line 11
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+#define __XEN_BUG_H__ + +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 + +#define BUGFRAME_NR 4 + +#ifndef BUG_FRAME_STRUCT
This check won't help when it comes ahead of ...
xen/include/xen/bug.h line 17
Quoted 6 lines
xen/include/xen/bug.h new file +6
-0+#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) +#endif + +#include <asm/bug.h>
... this. But is the #ifdef actually necessary? Or can the #define-s be moved ...
xen/include/xen/bug.h line 27
Quoted 9 lines
xen/include/xen/bug.h new file +9
-0+#ifndef BUG_DEBUGGER_TRAP_FATAL +#define BUG_DEBUGGER_TRAP_FATAL (regs) 0 +#endif + +#ifndef __ASSEMBLY__ + +#include <xen/lib.h> + +#ifndef BUG_FRAME_STRUCT
... here? (I guess having them defined early, but unconditionally is better. If an arch wants to override them, they can #undef and then #define.)
Above from here the "#ifndef __ASSEMBLY__" also wants to move up, to further enclose BUG_DEBUGGER_TRAP_FATAL (which is useless in assembly code).
Quoted 21 lines
xen/include/xen/bug.h new file +21
-0+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[]; +}; + +#define bug_loc (b) ((unsigned long)(b) + (b)->loc_disp) + +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp) + +#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))) + +#define bug_msg (b) ((const char *)(b) + (b)->msg_disp[1]) + +#endif /* BUG_FRAME_STRUCT */
xen/include/xen/bug.h line 59
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+ +/* +* Generic implementation has been based on x86 implementation where +* '%c' to deal with punctation sign ($, # depending on architecture) +* before immediate. +* +* Not all architecture's compilers have full support of '%c' and not for all +* assemblers punctation sign is used before immediate. +* Thereby it was decided to introduce BUG_ASM_CONST. +*/
I have to admit that I'm not really happy with this comment. At the very least the last sentence imo doesn't belong there. But overall how about something like
"Some architectures mark immediate instruction operands in a special way.
In such cases the special marking may need omitting when specifying directive operands. Allow architectures to specify a suitable modifier."
xen/include/xen/bug.h line 64
Quoted 5 lines
xen/include/xen/bug.h new file +5
-0+#ifndef BUG_ASM_CONST +#define BUG_ASM_CONST "" +#endif + +#if !defined(_ASM_BUGFRAME_TEXT) || !defined(_ASM_BUGFRAME_INFO)
Please don't make the conditional more complicated than necessary:
Checking for just _ASM_BUGFRAME_TEXT is enough here.
Quoted 20 lines
xen/include/xen/bug.h new file +20
-0+#define _ASM_BUGFRAME_TEXT (second_frame) \ + ".Lbug%=:"BUG_INSTR"\n" \ + " .pushsection .bug_frames.%"BUG_ASM_CONST"[bf_type], \"a\", %%progbits\n" \ + " .p2align 2\n" \ + ".Lfrm%=:\n" \ + " .long (.Lbug%= - .Lfrm%=) + %"BUG_ASM_CONST"[bf_line_hi]\n" \ + " .long (%"BUG_ASM_CONST"[bf_ptr] - .Lfrm%=) + %"BUG_ASM_CONST"[bf_line_lo]\n"\ + " .if " #second_frame "\n" \ + " .long 0, %"BUG_ASM_CONST"[bf_msg] - .Lfrm%=\n" \ + " .endif\n" \ + " .popsection\n" + +#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 line 95
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+#endif /* _ASM_BUGFRAME_TEXT || _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) ); \ +} while (0)
Isn't this tied to BUG_FRAME_STRUCT being defined (or not)? At least the 1st BUILD_BUG_ON() looks problematic if an arch wasn't to use the generic struct: With how you have things right now BUG_LINE_{LO,HI}_WIDTH may not be defined, and the check would also be at risk of causing false positives. Perhaps it's appropriate to have a separate #ifdef (incl the distinct identifier used), but that first BUILD_BUG_ON() needs abstracting out.
Also nit: Style (see ...
xen/include/xen/bug.h line 109
Quoted 13 lines
xen/include/xen/bug.h new file +13
-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(). +*/ +#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 )
... here). Also, considering the boolean nature, I guess we're in the process of moving such to be "} while ( false );".
Also please be consistent with formatting of the two adjacent macros, both indentation-wise and where "do {" is placed. Which of the two forms you use is secondary.
Quoted 17 lines
xen/include/xen/bug.h new file +17
-0+#endif /* run_in_exception_handler */ + +#ifndef WARN +#define WARN () BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, NULL) +#endif + +#ifndef BUG +#define BUG () do { \ + BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, 0, NULL); \ + unreachable(); \ +} while (0) +#endif + +#ifndef assert_failed +#define assert_failed (msg) do { \ + BUG_FRAME(BUGFRAME_assert, __LINE__, __FILE__, 1, msg); \ + unreachable(); \
xen/include/xen/bug.h line 137
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+} while (0) +#endif + +#ifdef CONFIG_GENERIC_BUG_FRAME + +struct cpu_user_regs ; + +/* +* Returns a negative value in case of an error otherwise the bug type. +*/
Perhaps add "(BUGFRAME_*)", which would then also make this a properly multi-line comment (right now it's a style violation, as is the case for the function definition as pointed out above)?
Jan
Re: [PATCH v5 2/4] xen: change <asm/bug.h> to <xen/bug.h>
In reply to Oleksii KurochkoQuoted 168 lines · Oleksii Kurochko
The idea of the patch is to change all <
asm/bug.h> to <xen/bug.h> and keep Xen compilable with adding only minimal amount of changes:
1. It was added "#include <xen/types.h>" to ARM's "<asm/bug.h>" as it uses uint_{16,32}t in 'structbug_frame'.
2. It was added '#defineBUG_FRAME_STRUCT' which means that ARM hasn't been switched to generic implementation yet.
3. It was added '#defineBUG_FRAME_STRUCT' which means that x86 hasn't been switched to generic implementation yet.
4. BUGFRAME_* and _start_bug_frame[], _stop_bug_frame_*[] were removed for ARM & x86 to deal with compilation errors such as:
redundant redeclaration of ...In the following two patches x86 and ARM archictectures will be switched fully:
* xen/arm: switch ARM to use generic implementation ofbug.h
* xen/x86: switch x86 to use generic implemetation ofbug.hSigned-off-by Oleksii Kurochko <[email protected]>---
Changes in V5:
- Nothing changed
---
Changes in V4:
- definesBUG_DISP_WIDTH,BUG_LINE_LO_WIDTH,BUG_LINE_HI_WIDTHwere moved into "ifndefBUG_FRAME_STRUCT" in <xen/bug.h> as they are specific for 'structbug_frame' and so should co-exist together. So the defines were back to <asm/bug.h> untilBUG_FRAME_STRUCTwill be defined in <asm/bug.h>.
- Update the comment message.
---
Changes in V3:
* Update patch 2 not to break compilation: move some parts from patches 3 and 4
to patch 2:
* move some generic parts from <asm/bug.h> to <xen/bug.h>
* add defineBUG_FRAME_STRUCTin ARM's <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/bug.h | 17 ++++------------- 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/arch/x86/include/asm/bug.h | 15 ++------------- xen/drivers/cpufreq/cpufreq.c | 2 +- xen/include/xen/lib.h | 2 +- 9 files changed, 13 insertions(+), 33 deletions(-)xen/arch/arm/include/asm/bug.h +4
-13@@ -1,6 +1,8 @@#ifndef __ARM_BUG_H__#define __ARM_BUG_H__ +#include <xen/types.h> +#if defined(CONFIG_ARM_32 )# include <asm/arm32/bug.h> #elif defined(CONFIG_ARM_64 )@@ -13,6 +15,8 @@#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 */ signed int file_disp;/* Relative address to the filename */ @@ -26,13 +30,6 @@ struct bug_frame {#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 @@ -89,12 +86,6 @@ struct bug_frame {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/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 +0
-0
xen/arch/x86/include/asm/asm_defns.h line 12
Quoted 8 lines
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>
While there's an unhelpful mix of asm/ and xen/ here already, may I ask that you try to avoid making things yet worse: Unless there's a reason not to, please move the added line past asm/x86-defns.h, adjacent to xen/stringify.h. Then non-Arm parts
(assuming of course no further large rework is necessary because of the comments on patch 1).
Jan
Re: [PATCH v5 4/4] xen/x86: switch x86 to use generic implemetation of bug.h
In reply to Oleksii KurochkoQuoted 5 lines · Oleksii Kurochko
The following changes were made:
* MakeGENERIC_BUG_FRAMEmandatory for X86
* Updateasm/bug.husing generic implementation in <xen/bug.h>
* Change prototype ofdebugger_trap_fatal()inasm/debugger.hto align it with generic prototype in <xen/debugger.h>.
Is this part of the description stale? The patch ...
Quoted 5 lines
--- xen/arch/x86/Kconfig | 1 + xen/arch/x86/include/asm/bug.h | 73 ++---------------------------- xen/arch/x86/traps.c | 81 +++------------------------------- 3 files changed, 11 insertions(+), 144 deletions(-)
... doesn't touch asm/debugger.h at all.
xen/arch/x86/include/asm/bug.h line 4
Quoted 10 lines
xen/arch/x86/include/asm/bug.h +1
-3@@ -1,79 +1,12 @@#ifndef __X86_BUG_H__#define __X86_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 BUG_DEBUGGER_TRAP_FATAL (regs) debugger_trap_fatal(X86_EXC_GP,regs)
Along the lines of a comment on an earlier patch, please move this ...
xen/arch/x86/include/asm/bug.h line 6
Quoted 1 line
xen/arch/x86/include/asm/bug.h +0
-0#ifndef __ASSEMBLY__
... into the thus guarded section.
xen/arch/x86/include/asm/bug.h void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf, · line 1171
Quoted 11 lines
xen/arch/x86/include/asm/bug.h +1
-5@@ -1166,12 +1167,9 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,void do_invalid_op (struct cpu_user_regs *regs) { -const struct bug_frame *bug =NULL ;u8 bug_insn[2 ]; -const char *prefix ="" , *filename, *predicate, *eip = (char *)regs->rip; -unsigned long fixup; -int id =-1 , lineno; -const struct virtual_region *region; +const char *eip = (char *)regs->rip;
I realize "char" was used before, but now that this is all on its own, can this at least become "unsigned char", but yet better "void"?
Quoted 56 lines
xen/arch/x86/include/asm/bug.h +4
-42@@ -1185,83 +1183,18 @@ void do_invalid_op(struct cpu_user_regs *regs) memcmp(bug_insn, "\xf\xb", sizeof(bug_insn)) ) goto die; - region =find_text_region (regs->rip); -if ( region ) - { -for ( id =0 ; id <BUGFRAME_NR ; id++ ) - { -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) == eip ) - { - bug = b; - goto found; - } - } - } - } - - found: -if ( !bug ) + id =do_bug_frame (regs, regs->rip); +if ( id <0 ) goto die; - eip +=sizeof (bug_insn); -if ( id == BUGFRAME_run_fn ) - { -void (*fn)(struct cpu_user_regs *) =bug_ptr (bug); - -fn (regs); -fixup_exception_return (regs, (unsigned long )eip); -return ; - } -/* WARN, BUG or ASSERT: decode the filename pointer and line number. */ - filename =bug_ptr (bug); -if ( !is_kernel (filename) && !is_patch (filename) ) - goto die; - fixup =strlen (filename); -if ( fixup >50 ) - { - filename += fixup -47 ; - prefix ="..." ; - } - lineno =bug_line (bug); + eip +=sizeof (bug_insn);switch ( id ) { +case BUGFRAME_run_fn:case BUGFRAME_warn:
xen/arch/x86/include/asm/bug.h void do_invalid_op(struct cpu_user_regs *regs) · line 1245
Quoted 10 lines
xen/arch/x86/include/asm/bug.h +0
-8-printk ("Xen WARN at %s%s:%d\n" , prefix, filename, lineno); -show_execution_state (regs);fixup_exception_return (regs, (unsigned long )eip);return ; - -case BUGFRAME_bug: -printk ("Xen BUG at %s%s:%d\n" , prefix, filename, lineno); - -if (debugger_trap_fatal (TRAP_invalid_op, regs) ) -return ;
This and ...
Quoted 4 lines
xen/arch/x86/include/asm/bug.h +0
-4-show_execution_state (regs); -panic ("Xen BUG at %s%s:%d\n" , prefix, filename, lineno); - -case BUGFRAME_assert:
xen/arch/x86/include/asm/bug.h void do_invalid_op(struct cpu_user_regs *regs) · line 1259
Quoted 10 lines
xen/arch/x86/include/asm/bug.h +0
-10-/* ASSERT: decode the predicate string pointer. */ - predicate =bug_msg (bug); -if ( !is_kernel (predicate) && !is_patch (predicate) ) - predicate ="<unknown>" ; - -printk ("Assertion '%s' failed at %s%s:%d\n" , - predicate, prefix, filename, lineno); - -if (debugger_trap_fatal (TRAP_invalid_op, regs) ) -return ;
... this return look to have no proper representation in the new logic; both cases fall through to ...
xen/arch/x86/include/asm/bug.h void do_invalid_op(struct cpu_user_regs *regs) · line 1200
Quoted 6 lines
xen/arch/x86/include/asm/bug.h +0
-3-show_execution_state (regs); -panic ("Assertion '%s' failed at %s%s:%d\n" , - predicate, prefix, filename, lineno); } die:
... here now, which is an unwanted functional change.
Jan
Re: [PATCH v5 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
In reply to Oleksii KurochkoQuoted 79 lines · Oleksii Kurochko
xen/common/bug.c new file +79
-0+int do_bug_frame (struct cpu_user_regs *regs,unsigned long pc) +{ +const struct bug_frame *bug =NULL ; +const struct virtual_region *region; +const char *prefix ="" , *filename, *predicate; +unsigned long fixup; +unsigned int id =BUGFRAME_NR , lineno; + + region =find_text_region (pc); +if ( !region ) +return -EINVAL ; + +for ( id =0 ; id <BUGFRAME_NR ; id++ ) + { +const struct bug_frame *b; +size_t 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; + } + } + } + + found: +if ( !bug ) +return -EINVAL ; + +if ( id == BUGFRAME_run_fn ) + { +void (*fn)(const struct cpu_user_regs *) =bug_ptr (bug); + +fn (regs); + +return id; + } + +/* 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 id; + +case BUGFRAME_bug: +printk ("Xen BUG at %s%s:%d\n" , prefix, filename, lineno); + +if (BUG_DEBUGGER_TRAP_FATAL (regs) ) +return id; + +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) && !is_patch (predicate) ) + predicate ="<unknown>" ; + +printk ("Assertion '%s' failed at %s%s:%d\n" , + predicate, prefix, filename, lineno); +
xen/common/bug.c line 103
Quoted 10 lines
xen/common/bug.c new file +10
-0+if (BUG_DEBUGGER_TRAP_FATAL (regs) ) +return id; + +show_execution_state (regs); +panic ("Assertion '%s' failed at %s%s:%d\n" , + predicate, prefix, filename, lineno); + } + +return id; +}
This final "return" looks like almost dead code (it isn't when an unrecognized id is found). May I suggest to switch all "return id" inside the switch() block to just "break", to make this final "return" be (a) the central one and (b) more obviously a used path?
Jan
Re: [PATCH v5 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
In reply to Jan BeulichQuoted 14 lines · Jan Beulich
Quoted 14 lines · Oleksii Kurochko
Quoted 8 lines
Quoted 8 lines
xen/common/Kconfig +0
-0@@ -28,6 +28,9 @@ config ALTERNATIVE_CALLconfig
ARCH_MAP_DOMAIN_PAGE
bool
+configGENERIC_BUG_FRAME
+ boolWith Arm now also going to use the generic logic, do we actually need
this
control anymore (provided things have been proven to work on Arm
Quoted 8 lines
Quoted 8 lines
for
the
compiler range we support there)? It looks like because of the way the
series is partitioned it may be necessary transiently, but it should
be
possible to drop it again in a new 5th patch.
We still need it because RISC-V doesn't ready yet to use do_bug_frame() from xen/common/bug.c as it requires find_text_region(), virtual_region() and panic().
The mentioned functionality isn't ready now for RISC-V so RISC-V will use only generic things from <xen/bug.h> only for some time.
Another one reason I would like to leave the config it is probably the same situation will be for future architectures.
This is not something mandatory if the config isn't really necessary than it should be removed after RISC-V will be ready to migrate full on generic implementation.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
xen/common/bug.c new file +12
-0@@ -0,0 +1,103 @@ +#include <xen/bug.h> +#include <xen/debugger.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> + +/*
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
xen/common/bug.c new file +1
-0+* Returns a negative value in case of an error otherwise the bug
type.
+ */Nit: Style (this is a single line comment). But see also below related
comment on the function's declaration.
Thanks. I'll fix that.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
xen/common/bug.c new file +14
-0+int do_bug_frame (struct cpu_user_regs *regs,unsigned long pc) +{ + const struct bug_frame *bug = NULL; + const struct virtual_region *region; + const char *prefix = "", *filename, *predicate; + unsigned long fixup; + unsigned int id = BUGFRAME_NR, lineno; + + region = find_text_region(pc); + if ( !region ) + return -EINVAL; + + for ( id = 0; id < BUGFRAME_NR; id++ ) + {
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
+ const struct
bug_frame*b;
+size_ti;
+
+ for ( i = 0, b = region->frame[id].bugs; + i < region->frame[id].n_bugs; b++, i++ )Nit: Indentation (the "i" on the 2nd line wants to align with that on the 1st one).
Thanks. I'll update the indentation.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
+ {
+ if (bug_loc(b)== pc )
+ {
+ bug = b;
+ goto found;
+ }
+ }
+ }
+
+ found:
+ if ( !bug )
+ return-EINVAL;
Quoted 5 lines
Quoted 5 lines
While I'm generally unhappy with many uses of
-EINVAL(it's used to indicate way too many different kinds of errors), can we at least consider using-ENOENThere instead? (I'm sorry, I should have asked
for this earlier on.)
Sure. Done.
Quoted 29 lines
Quoted 29 lines
Quoted 15 lines
Quoted 5 lines
xen/include/xen/bug.h new file +1
-0@@ -0,0 +1,158 @@ +#ifndef __XEN_BUG_H__xen/include/xen/bug.h line 11
Quoted 10 lines
xen/include/xen/bug.h new file +10
-0+#define __XEN_BUG_H__ + +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 + +#define BUGFRAME_NR 4 + +#ifndef BUG_FRAME_STRUCT This check won't help when it comes ahead of ...
Quoted 6 lines
xen/include/xen/bug.h line 17
Quoted 6 lines
xen/include/xen/bug.h new file +6
-0+#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) +#endif + +#include <asm/bug.h> ... this. But is the #ifdef actually necessary? Or can the #define- s
be moved ...
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
xen/include/xen/bug.h new file +6
-0+#ifndef BUG_DEBUGGER_TRAP_FATAL +#define BUG_DEBUGGER_TRAP_FATAL (regs) 0 +#endif + +#ifndef __ASSEMBLY__ +Quoted 8 lines
Quoted 3 lines
xen/include/xen/bug.h line 27
Quoted 3 lines
xen/include/xen/bug.h new file +3
-0+#include <xen/lib.h> + +#ifndef BUG_FRAME_STRUCT ... here? (I guess having them defined early, but unconditionally is
better. If an arch wants to override them, they can #undef and then #define.)
We can't move it to #indef __ASSEMBLY__ because in this case x86 compilation will fail as in x86's <asm/bug.h> BUG_DISP_WIDTH, BUG_LINE_LO_WIDTH, BUG_LINE_HI_WIDTH are used in case when the header is included in assembly code.
I agree that there is no any sense to have the defines under "#ifndef BUG_FRAME_STUCT" before <asm/bug.h> but it is necessary to define them before <asm/bug.h>. The defines were put under "#ifndef BUG_FRAME_STUCT" because it seems to me that logically the defines should go only with definition of 'struct bug_frame'.
So it looks like the only one way we have. It is define them unconditionally before <asm/bug.h> and #undef if it will be necessary for specific architecture.
As an option we can move the defines to #ifndef BUG_FRAME_STRUCT under #ifndef __ASSEMBLY__ and then define them explicitly in x86's <asm/bug.h> for case when the header is included some where in assembly code. But this option looks really weird.
Quoted 6 lines
Quoted 6 lines
Above from here the "#ifndef
__ASSEMBLY__" also wants to move up, to
further encloseBUG_DEBUGGER_TRAP_FATAL(which is useless in assembly
code).
Yeah, sure. Will move up "#ifndef __ASSEMBLY__"
Quoted 47 lines
Quoted 47 lines
Quoted 32 lines
Quoted 32 lines
xen/include/xen/bug.h new file +13
-0+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[]; +}; + +#define bug_loc (b) ((unsigned long)(b) + (b)->loc_disp) + +#define bug_ptr (b) ((const void *)(b) + (b)->ptr_disp) + +#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 +7
-0+ +#define bug_msg (b) ((const char *)(b) + (b)->msg_disp[1]) + +#endif /* BUG_FRAME_STRUCT */ + +/* +* Generic implementation has been based on x86 implementation where
+ * '%c' to deal with punctation sign ($, # depending on architecture)Quoted 8 lines
Quoted 8 lines
+ * before immediate.
+ *
+ * Not all architecture's compilers have full support of '%c' and
not for all
+ * assemblers punctation sign is used before immediate.
+ * Thereby it was decided to introduceBUG_ASM_CONST.
+ */I have to admit that I'm not really happy with this comment. At the very
least the last sentence imo doesn't belong there. But overall how about
something like
Quoted 7 lines
Quoted 7 lines
"Some architectures mark immediate instruction operands in a special
way.
In such cases the special marking may need omitting when specifying
directive operands. Allow architectures to specify a suitable modifier."
Your comment looks really better. So I'll use it.
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
xen/include/xen/bug.h new file +5
-0+#ifndef BUG_ASM_CONST +#define BUG_ASM_CONST "" +#endif + +#if !defined(_ASM_BUGFRAME_TEXT) ||!defined(_ASM_BUGFRAME_INFO)
Please don't make the conditional more complicated than necessary:
Checking for just_ASM_BUGFRAME_TEXTis enough here.
Sure. I'll update that.
Quoted 66 lines
Quoted 66 lines
Quoted 56 lines
Quoted 56 lines
+#define
_ASM_BUGFRAME_TEXT(second_frame)
\
+
".Lbug%=:"BUG_INSTR"\n"
\
+ " .pushsection .bug_frames.%"BUG_ASM_CONST"[bf_type], \"a\",
%%progbits\n" \
+ " .p2align
2\n"
\
+
".Lfrm%=:\n"
\
+ " .long (.Lbug%= - .Lfrm%=) + %"BUG_ASM_CONST"[bf_line_hi]\n" \
+ " .long (%"BUG_ASM_CONST"[bf_ptr] - .Lfrm%=) + %"BUG_ASM_CONST"[bf_line_lo]\n"\
+ " .if " #second_frame
"\n" \
+ " .long 0, %"BUG_ASM_CONST"[bf_msg] - .Lfrm%=\n" \
+ "
.endif\n"
\
+ " .popsection\n"xen/include/xen/bug.h new file +2
-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)xen/include/xen/bug.h new file +6
-0+ +#endif /* _ASM_BUGFRAME_TEXT || _ASM_BUGFRAME_INFO */ + +#ifndef BUG_FRAME + +#define BUG_FRAME (type, line, ptr, second_frame, msg) do{ \
+ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH+Quoted 8 lines
Quoted 8 lines
BUG_LINE_HI_WIDTH)); \
+ BUILD_BUG_ON((type) >=
BUGFRAME_NR); \
+ asm volatile (
_ASM_BUGFRAME_TEXT(second_frame) \
+ ::_ASM_BUGFRAME_INFO(type, line, ptr, msg)); \
+} while (0)Isn't this tied to
BUG_FRAME_STRUCTbeing defined (or not)? At
Quoted 8 lines
Quoted 8 lines
least
the 1stBUILD_BUG_ON()looks problematic if an arch wasn't to use the generic struct: With how you have things right now BUG_LINE_{LO,HI}_WIDTH may not be defined, and the check would also be at risk of causing false positives. Perhaps it's appropriate to have a separate #ifdef (incl the distinct identifier used), but that
firstBUILD_BUG_ON()needs abstracting out.
Missed that. Thanks.
I'll introduce that a separate #ifdef before BUG_FRAME:
#ifndef BUILD_BUG_ON_LINE_WIDTH
#define BUILD_BUG_ON_LINE_WIDTH \
BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH))#endif
Quoted 29 lines
Quoted 29 lines
Also nit: Style (see ...
Quoted 13 lines
Quoted 13 lines
xen/include/xen/bug.h new file +6
-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
offn().
+ */
+#defineQuoted 8 lines
Quoted 8 lines
run_in_exception_handler(fn) \
+ do
{ \
+ (void)((fn) == (void (*)(structcpu_user_regs*))NULL); \
+BUG_FRAME(BUGFRAME_run_fn, 0, fn, 0, NULL); \
+ } while ( 0 )... here). Also, considering the boolean nature, I guess we're in the
process of moving such to be "} while ( false );".
Quoted 4 lines
Quoted 4 lines
Also please be consistent with formatting of the two adjacent macros,
both indentation-wise and where "do {" is placed. Which of the two forms you use is secondary.
Thanks. Done.
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
xen/include/xen/bug.h new file +4
-0+#endif /* run_in_exception_handler */ + +#ifndef WARN +#define WARN () BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0,NULL)
xen/include/xen/bug.h new file +4
-0+#endif + +#ifndef BUG +#define BUG () do{ \
+BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, 0, NULL); \
+
unreachable(); \xen/include/xen/bug.h new file +5
-0+} while (0) +#endif + +#ifndef assert_failed +#define assert_failed (msg) do{ \
+BUG_FRAME(BUGFRAME_assert, __LINE__, __FILE__, 1, msg); \
+
unreachable(); \xen/include/xen/bug.h new file +9
-0+} while (0) +#endif + +#ifdef CONFIG_GENERIC_BUG_FRAME + +struct cpu_user_regs ; + +/* +* Returns a negative value in case of an error otherwise the bug
type.
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
+ */
Perhaps add "(BUGFRAME_*)", which would then also make this a properly
multi-line comment (right now it's a style violation, as is the case
for the function definition as pointed out above)?
Updated. Thanks.
~ Oleksii
Re: [PATCH v5 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
In reply to Jan BeulichQuoted 88 lines · Jan Beulich
Quoted 87 lines · Oleksii Kurochko
xen/common/bug.c new file +42
-0+int do_bug_frame (struct cpu_user_regs *regs,unsigned long pc) +{ + const struct bug_frame *bug = NULL; + const struct virtual_region *region; + const char *prefix = "", *filename, *predicate; + unsigned long fixup; + unsigned int id = BUGFRAME_NR, lineno; + + region = find_text_region(pc); + if ( !region ) + return -EINVAL; + + for ( id = 0; id < BUGFRAME_NR; id++ ) + { + const struct bug_frame *b; + size_t 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; + } + } + } + + found: + if ( !bug ) + return -EINVAL; + + if ( id == BUGFRAME_run_fn ) + { + void (*fn)(const struct cpu_user_regs *) = bug_ptr(bug); + + fn(regs); + + return id; + } + + /* 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 +34
-0+ + switch ( id ) + { + case BUGFRAME_warn: + printk("Xen WARN at %s%s:%d\n", prefix, filename, lineno); + show_execution_state(regs); + + return id; + + case BUGFRAME_bug: + printk("Xen BUG at %s%s:%d\n", prefix, filename, lineno); + + if ( BUG_DEBUGGER_TRAP_FATAL(regs) ) + return id; + + 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) && !is_patch(predicate) ) + predicate = "<unknown>"; + + printk("Assertion '%s' failed at %s%s:%d\n", + predicate, prefix, filename, lineno); + + if ( BUG_DEBUGGER_TRAP_FATAL(regs) ) + return id; + + show_execution_state(regs); + panic("Assertion '%s' failed at %s%s:%d\n", + predicate, prefix, filename, lineno); + }
Quoted 9 lines
xen/common/bug.c line 54
Quoted 3 lines
xen/common/bug.c new file +3
-0+ + return id; +}This final "return" looks like almost dead code (it isn't when an unrecognized id is found). May I suggest to switch all "return id" inside the
switch()block to just "break", to make this final "return" be (a) the central one and (b) more obviously a used path?
Sure It will be much better.
~ Oleksii
Re: [PATCH v5 4/4] xen/x86: switch x86 to use generic implemetation of bug.h
In reply to Jan BeulichQuoted 8 lines · Jan Beulich
Quoted 5 lines · Oleksii Kurochko
The following changes were made:
* MakeGENERIC_BUG_FRAMEmandatory for X86
* Updateasm/bug.husing generic implementation in <xen/bug.h>
* Change prototype ofdebugger_trap_fatal()inasm/debugger.hto align it with generic prototype in <xen/debugger.h>.Is this part of the description stale? The patch ...
It is stale. Updated now.
Quoted 25 lines
Quoted 7 lines
---
xen/arch/x86/Kconfig | 1 +xen/arch/x86/include/asm/bug.h| 73 ++---------------------------- xen/arch/x86/traps.c | 81 +++---------------------------
----3 files changed, 11 insertions(+), 144 deletions(-)... doesn't touch
asm/debugger.hat all.Quoted 11 lines
xen/arch/x86/include/asm/bug.h +0
-0@@ -1,79 +1,12 @@ #ifndef __X86_BUG_H__ #define __X86_BUG_H__xen/arch/x86/include/asm/bug.h +1
-3-#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_DEBUGGER_TRAP_FATAL (regs)
debugger_trap_fatal(X86_EXC_GP,regs)Along the lines of a comment on an earlier patch, please move this
...
Quoted 3 lines
Quoted 1 line
#ifndef
__ASSEMBLY__... into the thus guarded section.
But it was defined there before the patch series and these definies are used in "#else /* !__ASSEMBLY__ */"
Quoted 10 lines
Quoted 10 lines
xen/arch/x86/include/asm/bug.h +0
-0@@ -1166,12 +1167,9 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
voiddo_invalid_op(struct cpu_user_regs *regs)
{
- const structbug_frame*bug = NULL;
u8 bug_insn[2];
- const char *prefix = "", *filename, *predicate, *eip = (char *)regs->rip;
Quoted 8 lines
Quoted 4 lines
- unsigned long fixup;
- int id = -1, lineno;
- const structvirtual_region*region;
+ const char *eip = (char *)regs->rip;I realize "char" was used before, but now that this is all on its own,
can this at least become "unsigned char", but yet better "void"?
If we change it to "void" shouldn't it require additional casts here ( which is not nice ):
eip += sizeof(bug_insn);
Probably 'unsgined char' will be better.
Quoted 90 lines
Quoted 63 lines
xen/arch/x86/include/asm/bug.h +0
-0@@ -1185,83 +1183,18 @@ void do_invalid_op(struct cpu_user_regs *regs) memcmp(bug_insn, "\xf\xb", sizeof(bug_insn)) ) goto die;
- region =find_text_region(regs->rip);
- if ( region )
- {
- for ( id = 0; id <BUGFRAME_NR; id++ )
- {
- const structbug_frame*b;
- unsigned int i;xen/arch/x86/include/asm/bug.h +2
-15- - for ( i = 0, b = region->frame[id].bugs; - i < region->frame[id].n_bugs; b++, i++ ) - { - if ( bug_loc(b) == eip ) - { - bug = b; - goto found; - } - } - } - } - - found: - if ( !bug ) + id = do_bug_frame(regs, regs->rip); + if ( id < 0 )goto die;
- eip +=sizeof(bug_insn);
- if ( id ==BUGFRAME_run_fn)
- {
- void (*fn)(structcpu_user_regs*) =bug_ptr(bug); -
- fn(regs);
-fixup_exception_return(regs, (unsigned long)eip); - return;
- }
- /* WARN, BUG or ASSERT: decode the filename pointer and line number. */
- filename =bug_ptr(bug);
- if ( !is_kernel(filename) && !is_patch(filename) ) - goto die;
- fixup = strlen(filename);
- if ( fixup > 50 )
- {
- filename += fixup - 47;
- prefix = "...";
- }
- lineno =bug_line(bug);
+ eip +=sizeof(bug_insn);
switch ( id )
{
+ caseBUGFRAME_run_fn:
caseBUGFRAME_warn:
-printk("Xen WARN at %s%s:%d\n", prefix, filename, lineno); -show_execution_state(regs);fixup_exception_return(regs, (unsigned long)eip); return;xen/arch/x86/include/asm/bug.h
Quoted 6 lines
xen/arch/x86/include/asm/bug.h +0
-6- - case BUGFRAME_bug: - printk("Xen BUG at %s%s:%d\n", prefix, filename, lineno); - - if ( debugger_trap_fatal(TRAP_invalid_op, regs) ) - return;This and ...
Quoted 4 lines
-
show_execution_state(regs);
-panic("Xen BUG at %s%s:%d\n", prefix, filename, lineno);xen/arch/x86/include/asm/bug.h +0
-2- - case BUGFRAME_assert:xen/arch/x86/include/asm/bug.h
Quoted 10 lines
xen/arch/x86/include/asm/bug.h +0
-10- /* ASSERT: decode the predicate string pointer. */ - predicate = bug_msg(bug); - if ( !is_kernel(predicate) && !is_patch(predicate) ) - predicate = "<unknown>"; - - printk("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); - - if ( debugger_trap_fatal(TRAP_invalid_op, regs) ) - return;... this return look to have no proper representation in the new logic; both cases fall through to ...
Quoted 8 lines
Quoted 6 lines
-
show_execution_state(regs);
- panic("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); }
die:... here now, which is an unwanted functional change.
Oh, you are right. So then in case we have correct id it is needed to do only return:
switch ( id )
{
case BUGFRAME_run_fn:
case BUGFRAME_warn:
fixup_exception_return(regs, (unsigned long)eip);
break;
}
return;Thanks for finding that.
~ Oleksii
Re: [PATCH v5 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
In reply to OleksiiQuoted 23 lines · Oleksii
Quoted 14 lines · Jan Beulich
Quoted 14 lines · Oleksii Kurochko
Quoted 8 lines
Quoted 8 lines
xen/common/Kconfig +0
-0@@ -28,6 +28,9 @@ config ALTERNATIVE_CALLconfig
ARCH_MAP_DOMAIN_PAGE
bool
+configGENERIC_BUG_FRAME
+ boolWith Arm now also going to use the generic logic, do we actually need
this
control anymore (provided things have been proven to work on ArmQuoted 8 lines
Quoted 8 lines
for
the
compiler range we support there)? It looks like because of the way the
series is partitioned it may be necessary transiently, but it should
be
possible to drop it again in a new 5th patch.
Quoted 5 lines
We still need it because RISC-V doesn't ready yet to use
do_bug_frame()fromxen/common/bug.cas it requiresfind_text_region(),virtual_region()andpanic().
The mentioned functionality isn't ready now for RISC-V so RISC-V will use only generic things from <xen/bug.h> only for some time.
Oh, right. So let's leave it for the time being, but consider dropping it once RISC-V is more complete.
Quoted 42 lines
Quoted 28 lines
Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
xen/include/xen/bug.h new file +3
-0@@ -0,0 +1,158 @@ +#ifndef __XEN_BUG_H__ +#define __XEN_BUG_H__ +Quoted 8 lines
xen/include/xen/bug.h line 11
Quoted 8 lines
xen/include/xen/bug.h new file +8
-0+#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 + +#define BUGFRAME_NR 4 + +#ifndef BUG_FRAME_STRUCT This check won't help when it comes ahead of ...
Quoted 6 lines
xen/include/xen/bug.h line 17
Quoted 6 lines
xen/include/xen/bug.h new file +6
-0+#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) +#endif + +#include <asm/bug.h> ... this. But is the #ifdef actually necessary? Or can the #define- s
be moved ...Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
xen/include/xen/bug.h new file +6
-0+#ifndef BUG_DEBUGGER_TRAP_FATAL +#define BUG_DEBUGGER_TRAP_FATAL (regs) 0 +#endif + +#ifndef __ASSEMBLY__ +Quoted 8 lines
Quoted 3 lines
xen/include/xen/bug.h line 27
Quoted 3 lines
xen/include/xen/bug.h new file +3
-0+#include <xen/lib.h> + +#ifndef BUG_FRAME_STRUCT ... here? (I guess having them defined early, but unconditionally is
better. If an arch wants to override them, they can #undef and then #define.)
Quoted 4 lines
We can't move it to #indef
__ASSEMBLY__because in this case x86 compilation will fail as in x86's <asm/bug.h>BUG_DISP_WIDTH,BUG_LINE_LO_WIDTH,BUG_LINE_HI_WIDTHare used in case when the header is included in assembly code.
Oh, of course.
Quoted 6 lines
I agree that there is no any sense to have the defines under "#ifndef
BUG_FRAME_STUCT" before <asm/bug.h> but it is necessary to define them before <asm/bug.h>. The defines were put under "#ifndefBUG_FRAME_STUCT" because it seems to me that logically the defines should go only with definition of 'structbug_frame'.
Quoted 7 lines
So it looks like the only one way we have. It is define them unconditionally before <
asm/bug.h> and #undef if it will be necessary for specific architecture.
As an option we can move the defines to #ifndefBUG_FRAME_STRUCTunder #ifndef__ASSEMBLY__and then define them explicitly in x86's <asm/bug.h> for case when the header is included some where in assembly code. But this option looks really weird.
Indeed.
Quoted 21 lines
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
xen/include/xen/bug.h new file +1
-0+#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)); \
+} while (0)Isn't this tied to
BUG_FRAME_STRUCTbeing defined (or not)? AtQuoted 8 lines
Quoted 8 lines
least
the 1stBUILD_BUG_ON()looks problematic if an arch wasn't to use the generic struct: With how you have things right now BUG_LINE_{LO,HI}_WIDTH may not be defined, and the check would also be at risk of causing false positives. Perhaps it's appropriate to have a separate #ifdef (incl the distinct identifier used), but that
firstBUILD_BUG_ON()needs abstracting out.
Quoted 7 lines
Missed that. Thanks.
I'll introduce that a separate #ifdef beforeBUG_FRAME:#ifndef
BUILD_BUG_ON_LINE_WIDTH#define BUILD_BUG_ON_LINE_WIDTH \ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH))#endif
But then please make this a function-like macro.
I'm also not convinced of the #ifndef - an arch using an entirely different layout should have no need for this check. So I'd rather attach the #define to what's inside #ifndef BUG_FRAME_STRUCT and have an #else there to supply a #define to <empty> alternatively.
Jan
Re: [PATCH v5 4/4] xen/x86: switch x86 to use generic implemetation of bug.h
In reply to OleksiiQuoted 17 lines · Oleksii
Quoted 16 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
xen/arch/x86/include/asm/bug.h +0
-0@@ -1,79 +1,12 @@ #ifndef __X86_BUG_H__ #define __X86_BUG_H__xen/arch/x86/include/asm/bug.h +1
-3-#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_DEBUGGER_TRAP_FATAL (regs)
debugger_trap_fatal(X86_EXC_GP,regs)Along the lines of a comment on an earlier patch, please move this
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
#ifndef
__ASSEMBLY__... into the thus guarded section.
But it was defined there before the patch series and these definies are used in "#else /* !__ASSEMBLY__ */"
Since you use plural, maybe a misunderstanding? My comment was solely on the line you add; the removed lines are there merely as context.
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/include/asm/bug.h +0
-0@@ -1166,12 +1167,9 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
voiddo_invalid_op(struct cpu_user_regs *regs)
{
- const structbug_frame*bug = NULL;
u8 bug_insn[2];
- const char *prefix = "", *filename, *predicate, *eip = (char *)regs->rip;Quoted 8 lines
Quoted 4 lines
- unsigned long fixup;
- int id = -1, lineno;
- const structvirtual_region*region;
+ const char *eip = (char *)regs->rip;I realize "char" was used before, but now that this is all on its own,
can this at least become "unsigned char", but yet better "void"?
Quoted 3 lines
If we change it to "void" shouldn't it require additional casts here ( which is not nice ):
eip += sizeof(bug_insn);
Arithmetic on pointers to void is a GNU extension which we make heavy use of all over the hypervisor.
Quoted 45 lines
Quoted 35 lines
Quoted 8 lines
switch ( id )
{
+ caseBUGFRAME_run_fn:
caseBUGFRAME_warn:
-printk("Xen WARN at %s%s:%d\n", prefix, filename, lineno); -show_execution_state(regs);fixup_exception_return(regs, (unsigned long)eip); return;xen/arch/x86/include/asm/bug.h
Quoted 6 lines
xen/arch/x86/include/asm/bug.h +0
-6- - case BUGFRAME_bug: - printk("Xen BUG at %s%s:%d\n", prefix, filename, lineno); - - if ( debugger_trap_fatal(TRAP_invalid_op, regs) ) - return;This and ...
Quoted 4 lines
-
show_execution_state(regs);
-panic("Xen BUG at %s%s:%d\n", prefix, filename, lineno);xen/arch/x86/include/asm/bug.h +0
-2- - case BUGFRAME_assert:xen/arch/x86/include/asm/bug.h
Quoted 10 lines
xen/arch/x86/include/asm/bug.h +0
-10- /* ASSERT: decode the predicate string pointer. */ - predicate = bug_msg(bug); - if ( !is_kernel(predicate) && !is_patch(predicate) ) - predicate = "<unknown>"; - - printk("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); - - if ( debugger_trap_fatal(TRAP_invalid_op, regs) ) - return;... this return look to have no proper representation in the new logic; both cases fall through to ...
Quoted 8 lines
Quoted 6 lines
-
show_execution_state(regs);
- panic("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); }
die:... here now, which is an unwanted functional change.
Oh, you are right. So then in case we have correct id it is needed to do only return:
Quoted 9 lines
switch ( id )
{
case BUGFRAME_run_fn:
case BUGFRAME_warn:
fixup_exception_return(regs, (unsigned long)eip);
break;
}
return;Except the "return" needs to remain inside the switch; unrecognized id values should still fall through to the "die" label.
Jan
Re: [PATCH v5 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
In reply to OleksiiQuoted 25 lines
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2
-0+ +#define BUG_FRAME(type, line, ptr, second_frame, msg) do{ \
+ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH+
BUG_LINE_HI_WIDTH)); \Quoted 8 lines
Quoted 8 lines
+ BUILD_BUG_ON((type) >=
BUGFRAME_NR); \
+ asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \
+ ::_ASM_BUGFRAME_INFO(type, line, ptr, msg)
); \
+} while (0)Isn't this tied to
BUG_FRAME_STRUCTbeing defined (or not)? At least
the 1stBUILD_BUG_ON()looks problematic if an arch wasn't to useQuoted 8 lines
Quoted 8 lines
the generic struct: With how you have things right now BUG_LINE_{LO,HI}_WIDTH may not be defined, and the check would also
be at risk of causing false positives. Perhaps it's appropriate to
have a separate #ifdef (incl the distinct identifier used), but that
firstBUILD_BUG_ON()needs abstracting out.
Quoted 8 lines
Missed that. Thanks.
I'll introduce that a separate #ifdef beforeBUG_FRAME:#ifndef
BUILD_BUG_ON_LINE_WIDTH
#defineBUILD_BUG_ON_LINE_WIDTH\
BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH))
#endif
I think even better will be to do in the following way:
#ifndef LINE_WIDTH
#define LINE_WIDTH (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH) #endif
#define BUG_FRAME(type, line, ptr, second_frame, msg) do {
\
BUILD_BUG_ON((line) >> LINE_WIDTH);
\
BUILD_BUG_ON((type) >= BUGFRAME_NR);
\
asm volatile ( _ASM_BUGFRAME_TEXT(second_frame)
\
:: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \
} while (false)
~ Oleksii
Re: [PATCH v5 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
Quoted 48 lines · Oleksii
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2
-0+ +#define BUG_FRAME(type, line, ptr, second_frame, msg) do{ \
+ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH+
BUG_LINE_HI_WIDTH)); \Quoted 8 lines
Quoted 8 lines
+ BUILD_BUG_ON((type) >=
BUGFRAME_NR); \
+ asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \
+ ::_ASM_BUGFRAME_INFO(type, line, ptr, msg)
); \
+} while (0)Isn't this tied to
BUG_FRAME_STRUCTbeing defined (or not)? At least
the 1stBUILD_BUG_ON()looks problematic if an arch wasn't to useQuoted 8 lines
Quoted 8 lines
the generic struct: With how you have things right now BUG_LINE_{LO,HI}_WIDTH may not be defined, and the check would also
be at risk of causing false positives. Perhaps it's appropriate to
have a separate #ifdef (incl the distinct identifier used), but that
firstBUILD_BUG_ON()needs abstracting out.Quoted 8 lines
Missed that. Thanks.
I'll introduce that a separate #ifdef beforeBUG_FRAME:#ifndef
BUILD_BUG_ON_LINE_WIDTH
#defineBUILD_BUG_ON_LINE_WIDTH\
BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH))
#endifI think even better will be to do in the following way:
#ifndef
LINE_WIDTH
#defineLINE_WIDTH(BUG_LINE_LO_WIDTH+BUG_LINE_HI_WIDTH) #endif#define
BUG_FRAME(type, line, ptr, second_frame, msg)do {\ BUILD_BUG_ON((line) >> LINE_WIDTH); \ BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \ :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) );
Quoted 2 lines
\
} while (false)
Not sure - that'll still require arches to define LINE_WIDTH. What if they store the line number in a 32-bit field? Then defining LINE_WIDTH to 32 would yield undefined behavior here.
Jan
Re: [PATCH v5 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
Quoted 64 lines · Jan Beulich
Quoted 46 lines · Oleksii
Quoted 32 lines
Quoted 24 lines
Quoted 24 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +2
-0+ +#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); \Quoted 8 lines
Quoted 8 lines
+ asm volatile (
_ASM_BUGFRAME_TEXT(second_frame)
\
+ :: _ASM_BUGFRAME_INFO(type, line, ptr,
msg)
); \
+} while (0)Isn't this tied to
BUG_FRAME_STRUCTbeing defined (or not)? At
least
the 1stBUILD_BUG_ON()looks problematic if an arch wasn't to use
the generic struct: With how you have things right now BUG_LINE_{LO,HI}_WIDTH may not be defined, and the check wouldQuoted 8 lines
Quoted 8 lines
also
be at risk of causing false positives. Perhaps it's appropriate
to
have a separate #ifdef (incl the distinct identifier used), but
that
firstBUILD_BUG_ON()needs abstracting out.Quoted 8 lines
Missed that. Thanks.
I'll introduce that a separate #ifdef beforeBUG_FRAME:#ifndef
BUILD_BUG_ON_LINE_WIDTH
#defineBUILD_BUG_ON_LINE_WIDTH\
BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH))
#endifI think even better will be to do in the following way:
#ifndef
LINE_WIDTH
#defineLINE_WIDTH(BUG_LINE_LO_WIDTH+BUG_LINE_HI_WIDTH) #endifQuoted 16 lines
#define
BUG_FRAME(type, line, ptr, second_frame, msg)do {
\
BUILD_BUG_ON((line) >>LINE_WIDTH);
\
BUILD_BUG_ON((type) >=BUGFRAME_NR);
\
asm volatile (_ASM_BUGFRAME_TEXT(second_frame)
\
::_ASM_BUGFRAME_INFO(type, line, ptr, msg));
\
} while (false)
Quoted 4 lines
Not sure - that'll still require arches to define
LINE_WIDTH. What if they store the line number in a 32-bit field? Then definingLINE_WIDTHto 32 would yield undefined behavior here.
It might be an issue.
Than it will be better to have function-like macros mentioned in previous e-mail.
Thanks
~ Oleksii
Re: [PATCH v5 4/4] xen/x86: switch x86 to use generic implemetation of bug.h
In reply to Jan BeulichQuoted 21 lines · Jan Beulich
Quoted 20 lines · Oleksii
Quoted 19 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
xen/arch/x86/include/asm/bug.h +0
-0@@ -1,79 +1,12 @@ #ifndef __X86_BUG_H__ #define __X86_BUG_H__xen/arch/x86/include/asm/bug.h +1
-3-#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_DEBUGGER_TRAP_FATAL (regs)
debugger_trap_fatal(X86_EXC_GP,regs)Along the lines of a comment on an earlier patch, please move this
...Quoted 1 line
#ifndef
__ASSEMBLY__
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
... into the thus guarded section.
But it was defined there before the patch series and these definies are
used in "#else /* !__ASSEMBLY__ */"Since you use plural, maybe a misunderstanding? My comment was solely on the line you add; the removed lines are there merely as context.
Really. I misunderstood you.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
xen/arch/x86/include/asm/bug.h +0
-0@@ -1166,12 +1167,9 @@ void cpuid_hypervisor_leaves(conststruct
vcpu *v,uint32_tleaf,
voiddo_invalid_op(struct cpu_user_regs *regs)
{
- const structbug_frame*bug = NULL;Quoted 8 lines
u8 bug_insn[2];
- const char *prefix = "", *filename, *predicate, *eip = (char
*)regs->rip;
- unsigned long fixup;
- int id = -1, lineno;
- const structvirtual_region*region;
+ const char *eip = (char *)regs->rip;I realize "char" was used before, but now that this is all on its own,
can this at least become "unsigned char", but yet better "void"?
Quoted 7 lines
Quoted 4 lines
If we change it to "void" shouldn't it require additional casts here (
which is not nice ):
eip +=sizeof(bug_insn);Arithmetic on pointers to void is a GNU extension which we make heavy use of all over the hypervisor.
Got it. Than I'll rework it with 'void *'.
Quoted 58 lines
Quoted 58 lines
Quoted 39 lines
Quoted 17 lines
switch ( id )
{
+ caseBUGFRAME_run_fn:
caseBUGFRAME_warn:
-printk("Xen WARN at %s%s:%d\n", prefix, filename, lineno);
-show_execution_state(regs);fixup_exception_return(regs, (unsigned long)eip); return;
-
- caseBUGFRAME_bug:
-printk("Xen BUG at %s%s:%d\n", prefix, filename, lineno);
-
- if (debugger_trap_fatal(TRAP_invalid_op, regs)) - return;This and ...
Quoted 5 lines
-
show_execution_state(regs);
-panic("Xen BUG at %s%s:%d\n", prefix, filename, lineno);xen/arch/x86/include/asm/bug.h +0
-2- - case BUGFRAME_assert:xen/arch/x86/include/asm/bug.h
Quoted 10 lines
xen/arch/x86/include/asm/bug.h +0
-10- /* ASSERT: decode the predicate string pointer. */ - predicate = bug_msg(bug); - if ( !is_kernel(predicate) && !is_patch(predicate) ) - predicate = "<unknown>"; - - printk("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); - - if ( debugger_trap_fatal(TRAP_invalid_op, regs) ) - return;... this return look to have no proper representation in the new logic; both cases fall through to ...
Quoted 8 lines
Quoted 6 lines
-
show_execution_state(regs);
- panic("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); }
die:... here now, which is an unwanted functional change.
Oh, you are right. So then in case we have correct id it is needed to
do only return:
switch ( id )
{
caseBUGFRAME_run_fn:
caseBUGFRAME_warn:
fixup_exception_return(regs, (unsigned long)eip); break;
}
Quoted 5 lines
Quoted 1 line
return;
Except the "return" needs to remain inside the switch; unrecognized id
values should still fall through to the "die" label.
Yeah, it is still possible to get unrecognized id. Thanks.
Quoted 1 line
~ Oleksii