Other fixes from UBSAN enablement
cover Other fixes from UBSAN enablement
Patch 1 is a long outstanding bug, and hopefully still qualifies for 4.20 at this point.
Patches 2 and 3 probably don't, seeing as I can't seem to get UBSAN working for PPC (for which patch 3 at least would be a prerequisite to compile). They can wait until 4.21 now.
Andrew Cooper (4):
ARM32/traps: Fix do_trap_undefined_instruction()'s detection of kernel text
ARM: Fix register constraints in run_in_exception_handler()
xen: Centralise the declaration of dump_execution_state() [BROKEN] PPC: Activate UBSAN in testing
automation/gitlab-ci/build.yaml | 3 +++ xen/arch/arm/arm32/traps.c | 3 +-- xen/arch/arm/include/asm/bug.h | 6 +++--- xen/arch/arm/include/asm/processor.h | 3 --- xen/arch/ppc/Kconfig | 1 + xen/arch/ppc/stubs.c | 2 +- xen/arch/riscv/include/asm/processor.h | 2 -- xen/arch/x86/include/asm/processor.h | 1 - xen/common/ubsan/ubsan.c | 1 - xen/include/xen/bug.h | 3 +++ xen/include/xen/kernel.h | 2 -- 11 files changed, 12 insertions(+), 15 deletions(-)
Signature · 1 line
2.39.5
PATCH 1/4 ARM32/traps: Fix do_trap_undefined_instruction()'s detection of kernel text
While fixing some common/arch boundaries for UBSAN support on other architectures, the following debugging patch:
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index c1f2d1b89d43..58d1d048d339 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -504,6 +504,8 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr)
system_state = SYS_STATE_active;
+ dump_execution_state();
+
for_each_domain( d )
domain_unpause_by_systemcontroller(d);
fails with:
(XEN) *** Serial input to DOM0 (type 'CTRL-a' three times to switch input) (XEN) CPU0: Unexpected Trap: Undefined Instruction
(XEN) ----[ Xen-4.20-rc arm32 debug=n Not tainted ]----
(XEN) CPU: 0
<snip>
(XEN)
(XEN) ****************************************
(XEN) Panic on CPU 0:
(XEN) CPU0: Unexpected Trap: Undefined Instruction
(XEN) ****************************************
This is because the condition for init text is wrong. While there's nothing interesting from that point onwards in start_xen(), it's also wrong for any livepatch which brings in an adjusted BUG_FRAME().
Use is_active_kernel_text() which is the correct test for this purpose, and is aware of init and livepatch regions too.
Commit c8d4b6304a5e ("xen/arm: add support for run_in_exception_handler()"), made run_in_exception_handler() work, but didn't complete the TODO left in commit 3e802c6ca1fb ("xen/arm: Correctly support WARN_ON"). Do so, to make ARM consistent with other architectures.
---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
Sample run going wrong:
https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/9078570105
Sample run with dump_execution_state() working:
https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/9079185111
--- xen/arch/arm/arm32/traps.c | 3 +-- xen/arch/arm/include/asm/processor.h | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
xen/arch/arm/arm32/traps.c +1 -2
@@ -36,8 +36,7 @@ void do_trap_undefined_instruction(struct cpu_user_regs *regs)uint32_t pc = regs->pc;uint32_t instr; -if ( !is_kernel_text (pc) && - (system_state >= SYS_STATE_active || !is_kernel_inittext (pc)) ) +if ( !is_active_kernel_text (pc) ) goto die;/* PC should be always a multiple of 4, as Xen is using ARM instruction set */
xen/arch/arm/include/asm/processor.h +1 -2
@@ -577,8 +577,7 @@ void panic_PAR(uint64_t par);void show_registers (const struct cpu_user_regs *regs);void show_stack (const struct cpu_user_regs *regs); -//#define dump_execution_state() run_in_exception_handler(show_execution_state) -#define dump_execution_state () WARN() +#define dump_execution_state () run_in_exception_handler(show_execution_state)#define cpu_relax () barrier()/* Could yield? */
Signature · 1 line
2.39.5
Re: [PATCH for-4.20? 1/4] ARM32/traps: Fix do_trap_undefined_instruction()'s detection of kernel text
Quoted 38 lines · Andrew Cooper
While fixing some common/arch boundaries for UBSAN support on other architectures, the following debugging patch:
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index c1f2d1b89d43..58d1d048d339 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -504,6 +504,8 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr)system_state = SYS_STATE_active;+
dump_execution_state();
+
for_each_domain( d )
domain_unpause_by_systemcontroller(d);fails with:
(XEN) *** Serial input to DOM0 (type 'CTRL-a' three times to switch input) (XEN) CPU0: Unexpected Trap: Undefined Instruction
(XEN) ----[ Xen-4.20-rc arm32 debug=n Not tainted ]----
(XEN) CPU: 0
<snip>
(XEN)
(XEN) ****************************************
(XEN) Panic on CPU 0:
(XEN) CPU0: Unexpected Trap: Undefined Instruction
(XEN) ****************************************This is because the condition for init text is wrong. While there's nothing interesting from that point onwards in
start_xen(), it's also wrong for any livepatch which brings in an adjustedBUG_FRAME().Use
is_active_kernel_text()which is the correct test for this purpose, and is aware of init and livepatch regions too.
Quoted 7 lines
Commit
c8d4b6304a5e("xen/arm: add support forrun_in_exception_handler()"), maderun_in_exception_handler()work, but didn't complete the TODO left in commit3e802c6ca1fb("xen/arm: Correctly supportWARN_ON"). Do so, to make ARM consistent with other architectures.Fixes 3e802c6ca1fb ("xen/arm: Correctly support WARN_ON")Signed-off-by Andrew Cooper <[email protected]>
You should have mentioned that this patch requires [1] as a prerequisite. Otherwise this patch fails to build on both arm64 and arm32 with UBSAN enabled.
[1]
https://lore.kernel.org/xen-devel/[email protected]/T/#mc75e1b1ff6ccf4b0c7e10f55eedb7cacffca1c3d
With this handled:
As for taking this patch into 4.20, I don't think this qualifies as a serious bug. At the same time I don't see how it could cause issues, so I'd be ok to take it in. That said, at least one more Arm maintainer should take a vote.
~Michal
Quoted 49 lines
---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>Sample run going wrong:
https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/9078570105Sample run with
dump_execution_state()working:
https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/9079185111--- xen/arch/arm/arm32/traps.c | 3 +-- xen/arch/arm/include/asm/processor.h | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)xen/arch/arm/arm32/traps.c +1
-2@@ -36,8 +36,7 @@ void do_trap_undefined_instruction(struct cpu_user_regs *regs)uint32_t pc = regs->pc;uint32_t instr; -if ( !is_kernel_text (pc) && - (system_state >= SYS_STATE_active || !is_kernel_inittext (pc)) ) +if ( !is_active_kernel_text (pc) ) goto die;/* PC should be always a multiple of 4, as Xen is using ARM instruction set */ xen/arch/arm/include/asm/processor.h +1
-3@@ -577,8 +577,7 @@ void panic_PAR(uint64_t par);void show_registers (const struct cpu_user_regs *regs);void show_stack (const struct cpu_user_regs *regs); -//#define dump_execution_state() run_in_exception_handler(show_execution_state) -#define dump_execution_state () WARN() +#define dump_execution_state () run_in_exception_handler(show_execution_state)#define cpu_relax () barrier()/* Could yield? */ --2.39.5
Re: [PATCH for-4.20? 1/4] ARM32/traps: Fix do_trap_undefined_instruction()'s detection of kernel text
Quoted 44 lines · Michal
Quoted 42 lines · Andrew Cooper
While fixing some common/arch boundaries for UBSAN support on other architectures, the following debugging patch:
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index c1f2d1b89d43..58d1d048d339 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -504,6 +504,8 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr)system_state = SYS_STATE_active;+
dump_execution_state();
+
for_each_domain( d )
domain_unpause_by_systemcontroller(d);fails with:
(XEN) *** Serial input to DOM0 (type 'CTRL-a' three times to switch input) (XEN) CPU0: Unexpected Trap: Undefined Instruction
(XEN) ----[ Xen-4.20-rc arm32 debug=n Not tainted ]----
(XEN) CPU: 0
<snip>
(XEN)
(XEN) ****************************************
(XEN) Panic on CPU 0:
(XEN) CPU0: Unexpected Trap: Undefined Instruction
(XEN) ****************************************This is because the condition for init text is wrong. While there's nothing interesting from that point onwards in
start_xen(), it's also wrong for any livepatch which brings in an adjustedBUG_FRAME().Use
is_active_kernel_text()which is the correct test for this purpose, and is aware of init and livepatch regions too.Commit
c8d4b6304a5e("xen/arm: add support forrun_in_exception_handler()"), maderun_in_exception_handler()work, but didn't complete the TODO left in commit3e802c6ca1fb("xen/arm: Correctly supportWARN_ON"). Do so, to make ARM consistent with other architectures.
Quoted 7 lines
Quoted 2 lines
Fixes 3e802c6ca1fb ("xen/arm: Correctly support WARN_ON")Signed-off-by Andrew Cooper <[email protected]>You should have mentioned that this patch requires [1] as a prerequisite. Otherwise this patch fails to build on both arm64 and arm32 with UBSAN enabled.
[1]
https://lore.kernel.org/xen-devel/[email protected]/T/#mc75e1b1ff6ccf4b0c7e10f55eedb7cacffca1c3d
That is unintentional.
I'm going to split this patch in half, because it's clear that the run_in_exception_handler() problems are more complicated than I expected.
The fix in do_trap_undefined_instruction() genuinely is entirely independent of UBSAN.
~Andrew
Re: [PATCH for-4.20? 1/4] ARM32/traps: Fix do_trap_undefined_instruction()'s detection of kernel text
In reply to Andrew CooperHi Andrew,
Quoted 33 lines · Andrew Cooper
While fixing some common/arch boundaries for UBSAN support on other architectures, the following debugging patch:
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index c1f2d1b89d43..58d1d048d339 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -504,6 +504,8 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr)system_state = SYS_STATE_active;+
dump_execution_state();
+
for_each_domain( d )
domain_unpause_by_systemcontroller(d);fails with:
(XEN) *** Serial input to DOM0 (type 'CTRL-a' three times to switch input) (XEN) CPU0: Unexpected Trap: Undefined Instruction (XEN) ----[ Xen-4.20-rc arm32 debug=n Not tainted ]---- (XEN) CPU: 0 <snip> (XEN) (XEN) **************************************** (XEN) Panic on CPU 0: (XEN) CPU0: Unexpected Trap: Undefined Instruction (XEN) ****************************************This is because the condition for init text is wrong. While there's nothing interesting from that point onwards in
start_xen(), it's also wrong for any livepatch which brings in an adjustedBUG_FRAME().
Quoted 7 lines
Use
is_active_kernel_text()which is the correct test for this purpose, and is aware of init and livepatch regions too.Commit
c8d4b6304a5e("xen/arm: add support forrun_in_exception_handler()"), maderun_in_exception_handler()work, but didn't complete the TODO left in commit3e802c6ca1fb("xen/arm: Correctly supportWARN_ON"). Do so, to make ARM consistent with other architectures.
This was done on purpose. If you look at the current implementation of run_in_exception_handler(), it will clobber some registers.
With your patch #2, the function should only clobber one. It is a bit better, but it still not great. So I think we need to stick with WARN() on Arm (+ maybe a comment explaning why it is implemented differently).
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH for-4.20? 1/4] ARM32/traps: Fix do_trap_undefined_instruction()'s detection of kernel text
Quoted 52 lines · Julien Grall
Hi Andrew,
Quoted 41 lines · Andrew Cooper
While fixing some common/arch boundaries for UBSAN support on other architectures, the following debugging patch:
diff --git
a/xen/arch/arm/setup.cb/xen/arch/arm/setup.cindexc1f2d1b89d43..58d1d048d339100644
---a/xen/arch/arm/setup.c
+++b/xen/arch/arm/setup.c
@@ -504,6 +504,8 @@ void asmlinkage__initstart_xen(unsigned long fdt_paddr)
system_state=SYS_STATE_active;+
dump_execution_state();
+
for_each_domain( d )domain_unpause_by_systemcontroller(d);fails with:
(XEN) *** Serial input to DOM0 (type 'CTRL-a' three times to switch input)
(XEN) CPU0: Unexpected Trap: Undefined Instruction (XEN) ----[ Xen-4.20-rc arm32 debug=n Not tainted ]---- (XEN) CPU: 0
<snip>
(XEN)
(XEN) **************************************** (XEN) Panic on CPU 0:
(XEN) CPU0: Unexpected Trap: Undefined Instruction (XEN) ****************************************This is because the condition for init text is wrong. While there's nothing
interesting from that point onwards instart_xen(), it's also wrong for any
livepatch which brings in an adjustedBUG_FRAME().Use
is_active_kernel_text()which is the correct test for this purpose, and is
aware of init and livepatch regions too.Quoted 7 lines
Commit
c8d4b6304a5e("xen/arm: add support forrun_in_exception_handler()"),
maderun_in_exception_handler()work, but didn't complete the TODO left in
commit3e802c6ca1fb("xen/arm: Correctly support WARN_ON"). Do so, to make
ARM consistent with other architectures.
Quoted 7 lines
This was done on purpose. If you look at the current implementation of
run_in_exception_handler(), it will clobber some registers.With your patch #2, the function should only clobber one. It is a bit better, but it still not great. So I think we need to stick with
WARN()on Arm (+ maybe a comment explaning why it is implemented differently).
I'm sorry but I don't follow.
run_in_exception_handler() only uses 1 register (after patch 2), but it's fully described to the invoking context, so nothing is clobbered from the compilers point of view.
Are you concerned about losing r0/x0 in the resulting trace?
I can certainly split the patch in half. The do_trap_undefined_instruction() change isn't related, although the second hunk is needed for patch 3 to consolidate dump_execution_state() across architectures.
~Andrew
Re: [PATCH for-4.20? 1/4] ARM32/traps: Fix do_trap_undefined_instruction()'s detection of kernel text
Hi Andrew,
Quoted 61 lines · Andrew Cooper
Quoted 52 lines · Julien Grall
Hi Andrew,
Quoted 41 lines · Andrew Cooper
While fixing some common/arch boundaries for UBSAN support on other architectures, the following debugging patch:
diff --git
a/xen/arch/arm/setup.cb/xen/arch/arm/setup.cindexc1f2d1b89d43..58d1d048d339100644
---a/xen/arch/arm/setup.c
+++b/xen/arch/arm/setup.c
@@ -504,6 +504,8 @@ void asmlinkage__initstart_xen(unsigned longfdt_paddr)
system_state=SYS_STATE_active;+
dump_execution_state();
+
for_each_domain( d )domain_unpause_by_systemcontroller(d);fails with:
(XEN) *** Serial input to DOM0 (type 'CTRL-a' three times to
switch input)
(XEN) CPU0: Unexpected Trap: Undefined Instruction (XEN) ----[ Xen-4.20-rc arm32 debug=n Not tainted ]---- (XEN) CPU: 0
<snip>
(XEN)
(XEN) **************************************** (XEN) Panic on CPU 0:
(XEN) CPU0: Unexpected Trap: Undefined Instruction (XEN) ****************************************This is because the condition for init text is wrong. While there's nothing
interesting from that point onwards instart_xen(), it's also wrong for any
livepatch which brings in an adjustedBUG_FRAME().Use
is_active_kernel_text()which is the correct test for this purpose, and is
aware of init and livepatch regions too.Quoted 7 lines
Commit
c8d4b6304a5e("xen/arm: add support forrun_in_exception_handler()"),
maderun_in_exception_handler()work, but didn't complete the TODO left in
commit3e802c6ca1fb("xen/arm: Correctly support WARN_ON"). Do so, to make
ARM consistent with other architectures.Quoted 7 lines
This was done on purpose. If you look at the current implementation of
run_in_exception_handler(), it will clobber some registers.With your patch #2, the function should only clobber one. It is a bit better, but it still not great. So I think we need to stick with
WARN()on Arm (+ maybe a comment explaning why it is implemented differently).
Quoted 5 lines
I'm sorry but I don't follow.
run_in_exception_handler()only uses 1 register (after patch 2), but it's fully described to the invoking context, so nothing is clobbered from the compilers point of view.
Maybe "clobbered" was the wrong word. I was comparing the existing implementation (WARN()) with your proposed one. You don't mention in the commit message that r0/x0 will be missing. It wasn't clear to me whether this was intended.
Quoted 2 lines
Are you concerned about losing r0/x0 in the resulting trace?
I think the consolidation is not a strong enough reason to end up losing some registers in the dump. See below a proposal.
Quoted 5 lines
I can certainly split the patch in half. The
do_trap_undefined_instruction()change isn't related, although the second hunk is needed for patch 3 to consolidatedump_execution_state()across architectures.
What about checking if the arch is already providing a dump_execution_state() helper? This should allow the consolidation until we managed to convert Arm over to the generic bug infrastructure.
Cheers,
Signature · 1 line
Julien Grall
PATCH 2/4 ARM: Fix register constraints in run_in_exception_handler()
In reply to Andrew CooperRight now, run_in_exception_handler() takes an input in an arbitrary register, and clobbers BUG_FN_REG. This causes the compiler to calculate fn in the wrong regsiter.
Instead, use register asm() which is the normal way of tying register constraints to exact registers.
Bloat-o-meter reports:
ARM64:
Function old new delta
dump_registers 356 348 -8 ARM32:
ns16550_poll 52 48 -4
dump_registers 432 428 -4
The other instruction dropped in ARM64's dump_registers() is an alignment nop.
No functional change.
----
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
--- xen/arch/arm/include/asm/bug.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/bug.h +3 -3
@@ -59,15 +59,15 @@ struct bug_frame {* be called function in a fixed register. */ #define run_in_exception_handler (fn) do { \ - asm ("mov " __stringify(BUG_FN_REG) ", %0\n" \ - "1:"BUG_INSTR"\n" \ + register unsigned long _fn asm (STR(BUG_FN_REG)) = (unsigned long)(fn); \ + asm ("1:"BUG_INSTR"\n" \ ".pushsection .bug_frames." __stringify(BUGFRAME_run_fn) "," \ " \"a\", %%progbits\n" \ "2:\n" \ ".p2align 2\n" \ ".long (1b - 2b)\n" \ ".long 0, 0, 0\n" \ - ".popsection" :: "r" (fn) : __stringify(BUG_FN_REG) ); \ + ".popsection" :: "r" (_fn) ); \ } while (0)#define WARN () BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, "")
Signature · 1 line
2.39.5
Re: [PATCH 2/4] ARM: Fix register constraints in run_in_exception_handler()
Quoted 3 lines · Andrew Cooper
Right now,
run_in_exception_handler()takes an input in an arbitrary register, and clobbersBUG_FN_REG. This causes the compiler to calculate fn in the wrong regsiter.
Probably, we should give a chance for the patch which suggests to use GENERIC_BUG_FRAME:
https://lore.kernel.org/xen-devel/8fdb98350ae4fc6029738d0aabe13a57e1945a50.1680086655.git.oleksii.kurochko@gmail.com/
~ Oleksii
Quoted 52 lines
Instead, use
register asm()which is the normal way of tying register constraints to exact registers.Bloat-o-meter reports:
ARM64:
Function old new delta dump_registers 356 348 -8ARM32:
ns16550_poll52 48 -4
dump_registers432 428 -4The other instruction dropped in ARM64's
dump_registers()is an alignment nop.No functional change.
Signed-off-by Andrew Cooper<[email protected]>----
CC: Stefano Stabellini<[email protected]>
CC: Julien Grall<[email protected]>
CC: Volodymyr Babchuk<[email protected]>
CC: Bertrand Marquis<[email protected]>
CC: Michal Orzel<[email protected]>
CC: Oleksii Kurochko<[email protected]>--- xen/arch/arm/include/asm/bug.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)xen/arch/arm/include/asm/bug.h +3
-3@@ -59,15 +59,15 @@ struct bug_frame {* be called function in a fixed register. */ #define run_in_exception_handler (fn) do { \ - asm ("mov " __stringify(BUG_FN_REG) ", %0\n" \ - "1:"BUG_INSTR"\n" \ + register unsigned long _fn asm (STR(BUG_FN_REG)) = (unsigned long)(fn); \ + asm ("1:"BUG_INSTR"\n" \ ".pushsection .bug_frames." __stringify(BUGFRAME_run_fn) "," \ " \"a\", %%progbits\n" \ "2:\n" \ ".p2align 2\n" \ ".long (1b - 2b)\n" \ ".long 0, 0, 0\n" \ - ".popsection" :: "r" (fn) : __stringify(BUG_FN_REG) ); \ + ".popsection" :: "r" (_fn) ); \ } while (0)#define WARN () BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, "")
Re: [PATCH 2/4] ARM: Fix register constraints in run_in_exception_handler()
Quoted 9 lines · Oleksii Kurochko
Quoted 3 lines · Andrew Cooper
Right now,
run_in_exception_handler()takes an input in an arbitrary register, and clobbersBUG_FN_REG. This causes the compiler to calculate fn in the wrong regsiter.Probably, we should give a chance for the patch which suggests to use
GENERIC_BUG_FRAME:
https://lore.kernel.org/xen-
devel/8fdb98350ae4fc6029738d0aabe13a57e1945a50.1680086655.git.oleksii.kurochko@gmail.com/
That would be the ideal if someone has time for it. Otherwise, patch #3 needs to be modified (see my answer on patch #2).
But I would also be ok with this as a stop-gap for the time being.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 2/4] ARM: Fix register constraints in run_in_exception_handler()
Quoted 16 lines · Julien Grall
Quoted 8 lines · Oleksii Kurochko
Quoted 5 lines · Andrew Cooper
Right now,
run_in_exception_handler()takes an input in an arbitrary register,
and clobbers BUG_FN_REG. This causes the compiler to calculate fn in the
wrong regsiter.Quoted 4 lines
Probably, we should give a chance for the patch which suggests to use
GENERIC_BUG_FRAME:
https://lore.kernel.org/xen-
devel/8fdb98350ae4fc6029738d0aabe13a57e1945a50.1680086655.git.oleksii.kurochko@gmail.com/
Quoted 4 lines
That would be the ideal if someone has time for it. Otherwise, patch #3 needs to be modified (see my answer on patch #2).
But I would also be ok with this as a stop-gap for the time being.
Getting ARM onto GENERIC_BUG_FRAME would definitely be best all around, but that is an almost-2-year-old patch with an open "it doesn't compile on ARM32" issue.
I presume that all which is wanted is *a* solution that compiles (and works) everywhere we support?
~Andrew
Re: [PATCH 2/4] ARM: Fix register constraints in run_in_exception_handler()
Hi Andrew,
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Julien Grall
Quoted 8 lines · Oleksii Kurochko
Quoted 5 lines · Andrew Cooper
Right now,
run_in_exception_handler()takes an input in an arbitrary register,
and clobbers BUG_FN_REG. This causes the compiler to calculate fn in the
wrong regsiter.Quoted 4 lines
Probably, we should give a chance for the patch which suggests to use
GENERIC_BUG_FRAME:
https://lore.kernel.org/xen-
devel/8fdb98350ae4fc6029738d0aabe13a57e1945a50.1680086655.git.oleksii.kurochko@gmail.com/That would be the ideal if someone has time for it. Otherwise, patch #3 needs to be modified (see my answer on patch #2).
Quoted 8 lines
Quoted 1 line
But I would also be ok with this as a stop-gap for the time being.
Getting ARM onto
GENERIC_BUG_FRAMEwould definitely be best all around, but that is an almost-2-year-old patch with an open "it doesn't compile on ARM32" issue.I presume that all which is wanted is *a* solution that compiles (and works) everywhere we support?
Correct. Looking at the previous e-mail, it sounds like the patch was meant to work but it wasn't tested with older compilers and the commit message needed some rewording to mention what was tested.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 2/4] ARM: Fix register constraints in run_in_exception_handler()
In reply to Andrew CooperQuoted 19 lines · Andrew Cooper
Right now,
run_in_exception_handler()takes an input in an arbitrary register, and clobbersBUG_FN_REG. This causes the compiler to calculate fn in the wrong regsiter.Instead, use
register asm()which is the normal way of tying register constraints to exact registers.Bloat-o-meter reports:
ARM64:
Function old new delta dump_registers 356 348 -8ARM32:
ns16550_poll52 48 -4
dump_registers432 428 -4
Quoted 5 lines
The other instruction dropped in ARM64's
dump_registers()is an alignment nop.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
~Michal
Re: [PATCH 2/4] ARM: Fix register constraints in run_in_exception_handler()
In reply to Andrew CooperHi,
Quoted 3 lines · Andrew Cooper
Right now,
run_in_exception_handler()takes an input in an arbitrary register, and clobbersBUG_FN_REG. This causes the compiler to calculate fn in the wrong regsiter.
Just to confirm, you mean, the compiler is not clever enough to notice that the value should be in the register BUG_FN_REG and therefore, two registers will be clobbered. Is that correct?
Quoted 51 lines
Quoted 1 line
Instead, use
register asm()which is the normal way of tying registerconstraints to exact registers.
Bloat-o-meter reports:
ARM64:
Function old new delta dump_registers 356 348 -8ARM32:
ns16550_poll52 48 -4
dump_registers432 428 -4The other instruction dropped in ARM64's
dump_registers()is an alignment nop.No functional change.
Signed-off-by Andrew Cooper <[email protected]>----> CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>--- xen/arch/arm/include/asm/bug.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)xen/arch/arm/include/asm/bug.h +3
-3@@ -59,15 +59,15 @@ struct bug_frame {* be called function in a fixed register. */ #define run_in_exception_handler (fn) do { \ - asm ("mov " __stringify(BUG_FN_REG) ", %0\n" \ - "1:"BUG_INSTR"\n" \ + register unsigned long _fn asm (STR(BUG_FN_REG)) = (unsigned long)(fn); \ + asm ("1:"BUG_INSTR"\n" \ ".pushsection .bug_frames." __stringify(BUGFRAME_run_fn) "," \ " \"a\", %%progbits\n" \ "2:\n" \ ".p2align 2\n" \ ".long (1b - 2b)\n" \ ".long 0, 0, 0\n" \ - ".popsection" :: "r" (fn) : __stringify(BUG_FN_REG) ); \ + ".popsection" :: "r" (_fn) ); \ } while (0)#define WARN () BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, "")
Signature · 1 line
Julien Grall
Re: [PATCH 2/4] ARM: Fix register constraints in run_in_exception_handler()
Quoted 9 lines · Julien Grall
Hi,
Quoted 5 lines · Andrew Cooper
Right now,
run_in_exception_handler()takes an input in an arbitrary register,
and clobbers BUG_FN_REG. This causes the compiler to calculate fn in the
wrong regsiter.
Quoted 3 lines
Just to confirm, you mean, the compiler is not clever enough to notice that the value should be in the register
BUG_FN_REGand therefore, two registers will be clobbered. Is that correct?
Not quite.
The clobbered register set is always disjoint from inputs and outputs, so the combination of one clobbered + one input always means two different registers.
For "here's an input but it gets modified", you need to express that as an output into a variable which isn't subsequently used.
For ARM, that is best spelt "+r" (foo) so it can also be used with register asm() to tie to a single register. On x86, you can use "=a" (tmp) : "a" (input). In principle you can do it with named parameters, so [fn] "=r" (tmp) : "[fn]" (input) I believe works too.
Here is a contrived example https://godbolt.org/z/WjqTKjWWb showing how the output (discard only) is forced into r0, causing the compiler to copy a into r3 around the asm block. Notice that GCC and Clang pick the input operand differently, as both r0 and r3 are valid candidates in this case.
However, for run_in_exception_handler(), "fn" isn't even modified (AFAICT), so it's correct to describe it as an input only.
~Andrew
PATCH 3/4 xen: Centralise the declaration of dump_execution_state()
In reply to Andrew CooperThree architectures have an identical dump_execution_state(), and PPC has a stub for show_execution_state() that just isn't wired up yet.
show_execution_state() is declared in a common header, meaning that dump_execution_state() really ought to be too. Move them both into xen/bug.h as they're tightly tied to run_in_exception_handler(). Drop the include of xen/kernel.h from ubsan.c which was required reviously for RISC-V to compile.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
--- xen/arch/arm/include/asm/processor.h | 2 -- xen/arch/riscv/include/asm/processor.h | 2 -- xen/arch/x86/include/asm/processor.h | 1 - xen/common/ubsan/ubsan.c | 1 - xen/include/xen/bug.h | 3 +++ xen/include/xen/kernel.h | 2 -- 6 files changed, 3 insertions(+), 8 deletions(-)
xen/arch/arm/include/asm/processor.h +0 -2
@@ -577,8 +577,6 @@ void panic_PAR(uint64_t par);void show_registers (const struct cpu_user_regs *regs);void show_stack (const struct cpu_user_regs *regs); -#define dump_execution_state () run_in_exception_handler(show_execution_state) -#define cpu_relax () barrier()/* Could yield? */ /* All a bit UP for the moment */
xen/arch/riscv/include/asm/processor.h +0 -2
@@ -91,8 +91,6 @@ static inline void sfence_vma(void) asmvolatile ("sfence.vma" :::"memory" ); } -#define dump_execution_state () run_in_exception_handler(show_execution_state) -#endif /* __ASSEMBLY__ */ #endif /* ASM__RISCV__PROCESSOR_H */
xen/arch/x86/include/asm/processor.h +0 -1
@@ -405,7 +405,6 @@ static always_inline void rep_nop(void)void show_code (const struct cpu_user_regs *regs);void show_stack_overflow (unsigned int cpu,const struct cpu_user_regs *regs);void show_registers (const struct cpu_user_regs *regs); -#define dump_execution_state () run_in_exception_handler(show_execution_state)void show_page_walk (unsigned long addr);void noreturnfatal_trap (const struct cpu_user_regs *regs,bool show_remote);
xen/common/ubsan/ubsan.c +0 -1
@@ -11,7 +11,6 @@*/ #include <xen/bitops.h> -#include <xen/kernel.h> #include <xen/lib.h> #include <xen/percpu.h> #include <xen/spinlock.h>
xen/include/xen/bug.h +3 -0
@@ -155,6 +155,9 @@ int do_bug_frame(const struct cpu_user_regs *regs, unsigned long pc);#endif /* CONFIG_GENERIC_BUG_FRAME */ +void cf_check show_execution_state(const struct cpu_user_regs *regs); +#define dump_execution_state () run_in_exception_handler(show_execution_state) +#endif /* !__ASSEMBLY__ */ #endif /* __XEN_BUG_H__ */
xen/include/xen/kernel.h +0 -2
@@ -94,10 +94,8 @@ bool is_active_kernel_text(unsigned long addr);extern const char xen_config_data[];extern const unsigned int xen_config_data_size; -struct cpu_user_regs ;struct vcpu ; -void cf_check show_execution_state(const struct cpu_user_regs *regs);void vcpu_show_execution_state (struct vcpu *v);#endif /* _LINUX_KERNEL_H */
Signature · 1 line
2.39.5
Re: [PATCH 3/4] xen: Centralise the declaration of dump_execution_state()
Quoted 21 lines · Andrew Cooper
Three architectures have an identical
dump_execution_state(), and PPC has a stub forshow_execution_state()that just isn't wired up yet.
show_execution_state()is declared in a common header, meaning thatdump_execution_state()really ought to be too. Move them both intoxen/bug.has they're tightly tied torun_in_exception_handler(). Drop the include ofxen/kernel.hfromubsan.cwhich was required reviously for RISC-V to compile.No functional change.
Signed-off-by Andrew Cooper<[email protected]>---
CC: Jan Beulich<[email protected]>
CC: Roger Pau Monné<[email protected]>
CC: Stefano Stabellini<[email protected]>
CC: Julien Grall<[email protected]>
CC: Volodymyr Babchuk<[email protected]>
CC: Bertrand Marquis<[email protected]>
CC: Michal Orzel<[email protected]>
CC: Oleksii Kurochko<[email protected]>
CC: Shawn Anastasio<[email protected]>
Quoted 3 lines
--- xen/arch/arm/include/asm/processor.h | 2 -- xen/arch/riscv/include/asm/processor.h | 2 --
Thanks.
~ Oleksii
Quoted 85 lines
xen/arch/x86/include/asm/processor.h | 1 - xen/common/ubsan/ubsan.c | 1 - xen/include/xen/bug.h | 3 +++ xen/include/xen/kernel.h | 2 -- 6 files changed, 3 insertions(+), 8 deletions(-)xen/arch/arm/include/asm/processor.h +0
-2@@ -577,8 +577,6 @@ void panic_PAR(uint64_t par);void show_registers (const struct cpu_user_regs *regs);void show_stack (const struct cpu_user_regs *regs); -#define dump_execution_state () run_in_exception_handler(show_execution_state) -#define cpu_relax () barrier()/* Could yield? */ /* All a bit UP for the moment */ xen/arch/riscv/include/asm/processor.h +0
-2@@ -91,8 +91,6 @@ static inline void sfence_vma(void) asmvolatile ("sfence.vma" :::"memory" ); } -#define dump_execution_state () run_in_exception_handler(show_execution_state) -#endif /* __ASSEMBLY__ */ #endif /* ASM__RISCV__PROCESSOR_H */ xen/arch/x86/include/asm/processor.h +0
-1@@ -405,7 +405,6 @@ static always_inline void rep_nop(void)void show_code (const struct cpu_user_regs *regs);void show_stack_overflow (unsigned int cpu,const struct cpu_user_regs *regs);void show_registers (const struct cpu_user_regs *regs); -#define dump_execution_state () run_in_exception_handler(show_execution_state)void show_page_walk (unsigned long addr);void noreturnfatal_trap (const struct cpu_user_regs *regs,bool show_remote);xen/common/ubsan/ubsan.c +0
-1@@ -11,7 +11,6 @@*/ #include <xen/bitops.h> -#include <xen/kernel.h> #include <xen/lib.h> #include <xen/percpu.h> #include <xen/spinlock.h> xen/include/xen/bug.h +3
-0@@ -155,6 +155,9 @@ int do_bug_frame(const struct cpu_user_regs *regs, unsigned long pc);#endif /* CONFIG_GENERIC_BUG_FRAME */ +void cf_check show_execution_state(const struct cpu_user_regs *regs); +#define dump_execution_state () run_in_exception_handler(show_execution_state) +#endif /* !__ASSEMBLY__ */ #endif /* __XEN_BUG_H__ */ xen/include/xen/kernel.h +0
-2@@ -94,10 +94,8 @@ bool is_active_kernel_text(unsigned long addr);extern const char xen_config_data[];extern const unsigned int xen_config_data_size; -struct cpu_user_regs ;struct vcpu ; -void cf_check show_execution_state(const struct cpu_user_regs *regs);void vcpu_show_execution_state (struct vcpu *v);#endif /* _LINUX_KERNEL_H */
Re: [PATCH 3/4] xen: Centralise the declaration of dump_execution_state()
In reply to Andrew CooperQuoted 6 lines · Andrew Cooper
Three architectures have an identical
dump_execution_state(), and PPC has a stub forshow_execution_state()that just isn't wired up yet.
show_execution_state()is declared in a common header, meaning thatdump_execution_state()really ought to be too. Move them both intoxen/bug.has they're tightly tied torun_in_exception_handler().
Hmm, show_execution_state() certainly has wider use than just with run_in_exception_handler(). I don't think kernel.h was a great home for its decl, but I'm thinking the same of bug.h. Nevertheless (not the least short of having any better suggestion) ...
Quoted 6 lines
Drop the include of
xen/kernel.hfromubsan.cwhich was required reviously for RISC-V to compile.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Jan
PATCH 4/4 PPC: Activate UBSAN in testing
In reply to Andrew Cooper---
CC: Shawn Anastasio <[email protected]>
This compiles, but something is up with the console and nothing useful comes out.
Sample:
https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/9079440897
--- automation/gitlab-ci/build.yaml | 3 +++ xen/arch/ppc/Kconfig | 1 + xen/arch/ppc/stubs.c | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
automation/gitlab-ci/build.yaml +3 -0
@@ -352,6 +352,9 @@ debian-12-ppc64le-gcc-debug: CONTAINER: debian:12-ppc64le KBUILD_DEFCONFIG: ppc64_defconfig HYPERVISOR_ONLY: y + EXTRA_XEN_CONFIG: | + CONFIG_UBSAN=y + CONFIG_UBSAN_FATAL=y debian-12-riscv64-gcc-debug: extends: .gcc-riscv64-cross-build-debug
xen/arch/ppc/Kconfig +1 -0
@@ -2,6 +2,7 @@ config PPC def_bool y select FUNCTION_ALIGNMENT_4B select HAS_DEVICE_TREE + select HAS_UBSAN select HAS_VMAP config PPC64
xen/arch/ppc/stubs.c +1 -1
@@ -47,7 +47,7 @@ void send_timer_event(struct vcpu *v)void show_execution_state (const struct cpu_user_regs *regs) { -BUG_ON ("unimplemented" ); +printk ("TODO: Implement show_execution_state(regs)\n" ); }void arch_hypercall_tasklet_result (struct vcpu *v,long res)
Signature · 1 line
2.39.5
Re: [PATCH 4/4] [BROKEN] PPC: Activate UBSAN in testing
Hi Andrew,
Quoted 6 lines · Andrew Cooper
Signed-off-by Andrew Cooper <[email protected]>---
CC: Shawn Anastasio <[email protected]>This compiles, but something is up with the console and nothing useful comes out.
I tracked this down to ubsan tripping due to an unaligned access in opal.c, before the serial console is set up. I'll be sending a patch set soon to the ML with the fix for this to enable ubsan on PPC.
Thanks,
Shawn