Fixes related to toolchain / libc update
cover Fixes related to toolchain / libc update
Fixes that where found via the trixie update in xenomai-images and some cleanups. Most affect ARM 32-bit, the last one also 32-bit x86.
While the patches do not change the ABI and would therefore be backport candiates, I will likely only pick patches 3 and 5 for stable.
Which means that current stable versions of Xenomai should remain careful before updating their toolchains or libc versions for ARM and 32-bit x86.
Jan
Jan Kiszka (6):
testsuite/switchtest: Avoid including arch-specific syscall header lib/cobalt: arm: Avoid thumb mode in syscall-issuing modules
arm: fptest: Ensure that fp_regs_set/check functions are truly inline kernel/cobalt: Optimize xndebug_trace_relax implementation lib/cobalt: arm: Skip SIGSHADOW_ACTION_BACKTRACE over asynchronous
signals
lib/cobalt: x86: Fix and simplify 32-bit syscall argument setup
configure.ac | 1 + .../arm/include/asm/xenomai/uapi/fptest.h | 8 ++- kernel/cobalt/debug.c | 11 ++- kernel/cobalt/debug.h | 5 +- kernel/cobalt/thread.c | 2 +- .../arch/arm/include/asm/xenomai/Makefile.am | 1 + .../arch/arm/include/asm/xenomai/debug.h | 27 +++++++ .../arch/arm/include/asm/xenomai/syscall.h | 17 +++-- .../arm64/include/asm/xenomai/Makefile.am | 1 + .../arch/arm64/include/asm/xenomai/debug.h | 18 +++++ .../arch/x86/include/asm/xenomai/Makefile.am | 1 + .../arch/x86/include/asm/xenomai/debug.h | 18 +++++ .../arch/x86/include/asm/xenomai/syscall.h | 71 ++----------------- lib/cobalt/sigshadow.c | 12 ++-- testsuite/switchtest/switchtest.c | 2 +- 15 files changed, 110 insertions(+), 85 deletions(-) create mode 100644 lib/cobalt/arch/arm/include/asm/xenomai/debug.h create mode 100644 lib/cobalt/arch/arm64/include/asm/xenomai/debug.h create mode 100644 lib/cobalt/arch/x86/include/asm/xenomai/debug.h
Signature · 1 line
2.51.0
PATCH 1/6 testsuite/switchtest: Avoid including arch-specific syscall header
From: Jan Kiszka <[email protected]>
We only need the generic one, and the arch-specific one will soon require non-thumb mode from its users.
--- testsuite/switchtest/switchtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testsuite/switchtest/switchtest.c +1 -1
@@ -37,8 +37,8 @@#include <getopt.h> #include <asm/unistd.h> #include <asm/xenomai/features.h> -#include <asm/xenomai/syscall.h> #include <asm/xenomai/uapi/fptest.h> +#include <cobalt/uapi/asm-generic/syscall.h> #include <cobalt/trace.h> #include <rtdm/testing.h> #include <sys/cobalt.h>
Signature · 1 line
2.51.0
PATCH 2/6 lib/cobalt: arm: Avoid thumb mode in syscall-issuing modules
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
In 4abd59b4e3e4, we noticed the clash between r7 usage for setting up Xenomai syscalls and the compiler suddenly refusing this. What we was not clear at that point was the origin of the clash: if the compiler is configured to prefer thumb mode over regular 32-bit ARM instructions, it also starts to claim r7 as frame pointer.
Now, the solution taken back then turned out to have a problem: It broke stack unwinding. That is not only an issue when debugging, it is actually required for pthread_cancel and pthread_exit. The glibc will use unwinding to call destructors of the terminating context to call them before shutting down. This broke when we were inside a syscall because r7 was then pointing to the syscall number.
Most glibc versions detected the broken call chain and simply skipped the destructors - which was still a problem, just unnoticed. But with recent glibc from trixie, we are now even crashing while unwinding, and that is even less acceptable.
We could now either use the pattern of glibc to push the syscall invocation into an assembly function - or simply enforce ARM mode for libcobalt so that r7 become usable again. Take the latter approach as it is leaner.
--- configure.ac | 1 + .../arch/arm/include/asm/xenomai/syscall.h | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-)
configure.ac +1 -0
@@ -937,6 +937,7 @@ if test $rtcore_type = cobalt; then XENO_COBALT_CFLAGS="$XENO_USER_CFLAGS" case "$build_for" in i*86*-*) XENO_COBALT_CFLAGS="$XENO_COBALT_CFLAGS -fno-omit-frame-pointer";; + arm*-*) XENO_COBALT_CFLAGS="$XENO_COBALT_CFLAGS -marm";; esac dnl Build wrapping information. XENO_POSIX_WRAPPERS lists all wrapping
lib/cobalt/arch/arm/include/asm/xenomai/syscall.h +11 -6
@@ -29,6 +29,10 @@#error "ARM OABI support has been removed with Xenomai 3.3.x"#endif +#ifdef __thumb__ +#error "Xenomai syscalls cannot be issued in Thumb mode" +#endif +/* * Some of the following macros have been adapted from Linux's * implementation of the syscall mechanism in <asm-arm/unistd.h>:
@@ -54,8 +58,8 @@LOADARGS_4 (syscode, arg1, arg2, arg3, arg4); \ __a4 = (unsigned long) (arg5) -#define CLOBBER_REGS_0 -#define CLOBBER_REGS_1 "r0" +#define CLOBBER_REGS_0 "r7" +#define CLOBBER_REGS_1 CLOBBER_REGS_0, "r0"#define CLOBBER_REGS_2 CLOBBER_REGS_1, "r1"#define CLOBBER_REGS_3 CLOBBER_REGS_2, "r2"#define CLOBBER_REGS_4 CLOBBER_REGS_3, "r3"
@@ -69,7 +73,8 @@#define LOADREGS_5 LOADREGS_4; __r4 = __a4#define ASM_INDECL_0 \ - register unsigned long __r0 __asm__ ("r0"); + register unsigned long __r0 __asm__ ("r0"); \ + register unsigned long __r7 __asm__ ("r7");#define ASM_INDECL_1 ASM_INDECL_0; \ unsigned long __a0;#define ASM_INDECL_2 ASM_INDECL_1; \
@@ -91,15 +96,15 @@ #define XENOMAI_DO_SYSCALL(nr, op, args...) \ ({ \ ASM_INDECL_##nr; \ - unsigned long __r7 = __xn_syscode(op); \ LOADARGS_##nr(__xn_syscode(op), args); \ __asm__ __volatile__ ("" : /* */ : /* */ : \CLOBBER_REGS_ ##nr); \ LOADREGS_##nr; \ + __r7 = __xn_syscode(op); \ __asm__ __volatile__ ( \ - "push {r7}; mov %%r7,%[__r7]; swi\t0; pop {r7}" \ + "swi 0" \ : "=r" (__r0) \ - : ASM_INPUT_##nr, [__r7] "r" (__r7) \ + : ASM_INPUT_##nr, "r" (__r7) \ : "memory"); \ (int) __r0; \ })
Signature · 1 line
2.51.0
Re: [PATCH 2/6] lib/cobalt: arm: Avoid thumb mode in syscall-issuing modules
Quoted 4 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
In
4abd59b4e3e4, we noticed the clash between r7 usage for setting up Xenomai syscalls and the compiler suddenly refusing this. What we was
^
"we" seems superfluous.
Quoted 11 lines
not clear at that point was the origin of the clash: if the compiler is configured to prefer thumb mode over regular 32-bit ARM instructions, it also starts to claim r7 as frame pointer.
Now, the solution taken back then turned out to have a problem: It broke stack unwinding. That is not only an issue when debugging, it is actually required for
pthread_cancelandpthread_exit. The glibc will use unwinding to call destructors of the terminating context to call them before shutting down. This broke when we were inside a syscall because r7 was then pointing to the syscall number.
Quoted 4 lines
Most glibc versions detected the broken call chain and simply skipped the destructors - which was still a problem, just unnoticed. But with recent glibc from trixie, we are now even crashing while unwinding, and that is even less acceptable.
Ok, so not a trixie regression, but something that was never correct on our end. Good to know as trixie will get more traction soon.
Quoted 5 lines
We could now either use the pattern of glibc to push the syscall invocation into an assembly function - or simply enforce ARM mode for libcobalt so that r7 become usable again. Take the latter approach as it is leaner.
As it broke again - and as already written as comment to the series - we might think of reviving the syscall() series. That would allow us to simply remove that code here. Seems hard to maintain and hard to debug...
Quoted 77 lines
Fixes 4abd59b4e3e4 ("lib/cobalt: arm: Account for register allocation clash")Signed-off-by Jan Kiszka <[email protected]>--- configure.ac | 1 + .../arch/arm/include/asm/xenomai/syscall.h | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-)configure.ac +1
-0@@ -937,6 +937,7 @@ if test $rtcore_type = cobalt; then XENO_COBALT_CFLAGS="$XENO_USER_CFLAGS" case "$build_for" in i*86*-*) XENO_COBALT_CFLAGS="$XENO_COBALT_CFLAGS -fno-omit-frame-pointer";; + arm*-*) XENO_COBALT_CFLAGS="$XENO_COBALT_CFLAGS -marm";; esac dnl Build wrapping information. XENO_POSIX_WRAPPERS lists all wrappinglib/cobalt/arch/arm/include/asm/xenomai/syscall.h +11
-6@@ -29,6 +29,10 @@#error "ARM OABI support has been removed with Xenomai 3.3.x"#endif +#ifdef __thumb__ +#error "Xenomai syscalls cannot be issued in Thumb mode" +#endif +/* * Some of the following macros have been adapted from Linux's * implementation of the syscall mechanism in <asm-arm/unistd.h>: @@ -54,8 +58,8 @@LOADARGS_4 (syscode, arg1, arg2, arg3, arg4); \ __a4 = (unsigned long) (arg5) -#define CLOBBER_REGS_0 -#define CLOBBER_REGS_1 "r0" +#define CLOBBER_REGS_0 "r7" +#define CLOBBER_REGS_1 CLOBBER_REGS_0, "r0"#define CLOBBER_REGS_2 CLOBBER_REGS_1, "r1"#define CLOBBER_REGS_3 CLOBBER_REGS_2, "r2"#define CLOBBER_REGS_4 CLOBBER_REGS_3, "r3"@@ -69,7 +73,8 @@#define LOADREGS_5 LOADREGS_4; __r4 = __a4#define ASM_INDECL_0 \ - register unsigned long __r0 __asm__ ("r0"); + register unsigned long __r0 __asm__ ("r0"); \ + register unsigned long __r7 __asm__ ("r7");#define ASM_INDECL_1 ASM_INDECL_0; \ unsigned long __a0;#define ASM_INDECL_2 ASM_INDECL_1; \@@ -91,15 +96,15 @@ #define XENOMAI_DO_SYSCALL(nr, op, args...) \ ({ \ ASM_INDECL_##nr; \ - unsigned long __r7 = __xn_syscode(op); \ LOADARGS_##nr(__xn_syscode(op), args); \ __asm__ __volatile__ ("" : /* */ : /* */ : \CLOBBER_REGS_ ##nr); \ LOADREGS_##nr; \ + __r7 = __xn_syscode(op); \ __asm__ __volatile__ ( \ - "push {r7}; mov %%r7,%[__r7]; swi\t0; pop {r7}" \ + "swi 0" \ : "=r" (__r0) \ - : ASM_INPUT_##nr, [__r7] "r" (__r7) \ + : ASM_INPUT_##nr, "r" (__r7) \ : "memory"); \ (int) __r0; \ })Signature · 1 line
2.51.0
Re: [PATCH 2/6] lib/cobalt: arm: Avoid thumb mode in syscall-issuing modules
Quoted 8 lines · Florian Bezdeka
Quoted 4 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
In
4abd59b4e3e4, we noticed the clash between r7 usage for setting up Xenomai syscalls and the compiler suddenly refusing this. What we was^"we" seems superfluous.
Thanks, will fix.
Quoted 25 lines
Quoted 11 lines
not clear at that point was the origin of the clash: if the compiler is configured to prefer thumb mode over regular 32-bit ARM instructions, it also starts to claim r7 as frame pointer.
Now, the solution taken back then turned out to have a problem: It broke stack unwinding. That is not only an issue when debugging, it is actually required for
pthread_cancelandpthread_exit. The glibc will use unwinding to call destructors of the terminating context to call them before shutting down. This broke when we were inside a syscall because r7 was then pointing to the syscall number.Quoted 4 lines
Most glibc versions detected the broken call chain and simply skipped the destructors - which was still a problem, just unnoticed. But with recent glibc from trixie, we are now even crashing while unwinding, and that is even less acceptable.
Ok, so not a trixie regression, but something that was never correct on our end. Good to know as trixie will get more traction soon.
Quoted 5 lines
We could now either use the pattern of glibc to push the syscall invocation into an assembly function - or simply enforce ARM mode for libcobalt so that r7 become usable again. Take the latter approach as it is leaner.
Quoted 5 lines
As it broke again - and as already written as comment to the series - we might think of reviving the
syscall()series. That would allow us to simply remove that code here. Seems hard to maintain and hard to debug...
I'm not very keen on adding that overhead anymore to the low-end ARM 32 platform. I think they should retire with the existing inline model. For more powerful 64-bit targets, it takes at least the benchmarks we discussed.
But when benchmarking syscall() already, why not including prctl() as well?
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Re: [PATCH 2/6] lib/cobalt: arm: Avoid thumb mode in syscall-issuing modules
Quoted 43 lines · Jan Kiszka
Quoted 8 lines · Florian Bezdeka
Quoted 4 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
In
4abd59b4e3e4, we noticed the clash between r7 usage for setting up Xenomai syscalls and the compiler suddenly refusing this. What we was^"we" seems superfluous.
Thanks, will fix.
Quoted 25 lines
Quoted 11 lines
not clear at that point was the origin of the clash: if the compiler is configured to prefer thumb mode over regular 32-bit ARM instructions, it also starts to claim r7 as frame pointer.
Now, the solution taken back then turned out to have a problem: It broke stack unwinding. That is not only an issue when debugging, it is actually required for
pthread_cancelandpthread_exit. The glibc will use unwinding to call destructors of the terminating context to call them before shutting down. This broke when we were inside a syscall because r7 was then pointing to the syscall number.Quoted 4 lines
Most glibc versions detected the broken call chain and simply skipped the destructors - which was still a problem, just unnoticed. But with recent glibc from trixie, we are now even crashing while unwinding, and that is even less acceptable.
Ok, so not a trixie regression, but something that was never correct on our end. Good to know as trixie will get more traction soon.
Quoted 5 lines
We could now either use the pattern of glibc to push the syscall invocation into an assembly function - or simply enforce ARM mode for libcobalt so that r7 become usable again. Take the latter approach as it is leaner.
Quoted 5 lines
As it broke again - and as already written as comment to the series - we might think of reviving the
syscall()series. That would allow us to simply remove that code here. Seems hard to maintain and hard to debug...
Quoted 5 lines
I'm not very keen on adding that overhead anymore to the low-end ARM 32 platform. I think they should retire with the existing inline model. For more powerful 64-bit targets, it takes at least the benchmarks we discussed.
But when benchmarking
syscall()already, why not includingprctl()as well?
We would need to refactor select() first - or in addition. prctl() is able to handle 4 arguments - if memory is correct - select() needs one more.
Quoted 6 lines
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
PATCH 3/6 arm: fptest: Ensure that fp_regs_set/check functions are truly inline
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
If they aren't, d8-d15 will be saved/restored, and that is ruining our tests.
--- kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +5 -3
@@ -20,7 +20,8 @@#define __COBALT_HAVE_VFP 0x1 -static inline void fp_regs_set (int features,unsigned int val) +static inline void __attribute__ ((always_inline)) +fp_regs_set (int features,unsigned int val) {unsigned long long e[16 ];unsigned int i;
@@ -41,8 +42,9 @@ static inline void fp_regs_set(int features, unsigned int val) } } -static inline unsigned int fp_regs_check (int features,unsigned int val, -int (*report)(const char *fmt, ...)) +static inline unsigned int __attribute__ ((always_inline)) +fp_regs_check (int features,unsigned int val, +int (*report)(const char *fmt, ...)) {unsigned int result = val, i;unsigned long long e[16 ];
Signature · 1 line
2.51.0
Re: [PATCH 3/6] arm: fptest: Ensure that fp_regs_set/check functions are truly inline
Quoted 25 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
If they aren't, d8-d15 will be saved/restored, and that is ruining our tests.
Signed-off-by Jan Kiszka <[email protected]>--- kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +2
-1@@ -20,7 +20,8 @@#define __COBALT_HAVE_VFP 0x1 -static inline void fp_regs_set (int features,unsigned int val) +static inline void __attribute__ ((always_inline)) +fp_regs_set (int features,unsigned int val) {unsigned long long e[16 ];unsigned int i;
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h static inline void fp_regs_set(int features, unsigned int val) · line 43
Quoted 2 lines
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +0
-0@@ -41,8 +42,9 @@ static inline void fp_regs_set(int features, unsigned int val) } }
Could we use the __always_inline macro from Linux here?
Quoted 11 lines
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +3
-2-static inline unsigned int fp_regs_check (int features,unsigned int val, -int (*report)(const char *fmt, ...)) +static inline unsigned int __attribute__ ((always_inline)) +fp_regs_check (int features,unsigned int val, +int (*report)(const char *fmt, ...)) {unsigned int result = val, i;unsigned long long e[16 ];Signature · 1 line
2.51.0
Re: [PATCH 3/6] arm: fptest: Ensure that fp_regs_set/check functions are truly inline
Quoted 19 lines · Florian Bezdeka
Quoted 18 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
If they aren't, d8-d15 will be saved/restored, and that is ruining our tests.
Signed-off-by Jan Kiszka <[email protected]>--- kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +0
-0@@ -20,7 +20,8 @@#define __COBALT_HAVE_VFP 0x1
Quoted 12 lines
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h static inline void fp_regs_set(int features, unsigned int val) · line 43
Quoted 9 lines
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +2
-1-static inline void fp_regs_set (int features,unsigned int val) +static inline void __attribute__ ((always_inline)) +fp_regs_set (int features,unsigned int val) {unsigned long long e[16 ];unsigned int i;@@ -41,8 +42,9 @@ static inline void fp_regs_set(int features, unsigned int val) } }Could we use the
__always_inlinemacro from Linux here?
This is (also) userland code (uapi...).
Jan
Quoted 11 lines
Quoted 11 lines
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +3
-2-static inline unsigned int fp_regs_check (int features,unsigned int val, -int (*report)(const char *fmt, ...)) +static inline unsigned int __attribute__ ((always_inline)) +fp_regs_check (int features,unsigned int val, +int (*report)(const char *fmt, ...)) {unsigned int result = val, i;unsigned long long e[16 ];Signature · 1 line
2.51.0
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Re: [PATCH 3/6] arm: fptest: Ensure that fp_regs_set/check functions are truly inline
Quoted 33 lines · Jan Kiszka
Quoted 19 lines · Florian Bezdeka
Quoted 18 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
If they aren't, d8-d15 will be saved/restored, and that is ruining our tests.
Signed-off-by Jan Kiszka <[email protected]>--- kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +0
-0@@ -20,7 +20,8 @@#define __COBALT_HAVE_VFP 0x1Quoted 12 lines
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h static inline void fp_regs_set(int features, unsigned int val) · line 43
Quoted 9 lines
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +2
-1-static inline void fp_regs_set (int features,unsigned int val) +static inline void __attribute__ ((always_inline)) +fp_regs_set (int features,unsigned int val) {unsigned long long e[16 ];unsigned int i;@@ -41,8 +42,9 @@ static inline void fp_regs_set(int features, unsigned int val) } }Could we use the
__always_inlinemacro from Linux here?
Quoted 1 line
This is (also) userland code (uapi...).
That's clear. I thought __always_inline is available for both worlds, but that might not be the case for all kernel versions we have here.
Btw: Which path (user or kernel) was the problem? Both or just one of them?
Quoted 19 lines
Jan
Quoted 11 lines
Quoted 11 lines
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +3
-2-static inline unsigned int fp_regs_check (int features,unsigned int val, -int (*report)(const char *fmt, ...)) +static inline unsigned int __attribute__ ((always_inline)) +fp_regs_check (int features,unsigned int val, +int (*report)(const char *fmt, ...)) {unsigned int result = val, i;unsigned long long e[16 ];Signature · 1 line
2.51.0Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Re: [PATCH 3/6] arm: fptest: Ensure that fp_regs_set/check functions are truly inline
Quoted 34 lines · Florian Bezdeka
Quoted 33 lines · Jan Kiszka
Quoted 31 lines · Florian Bezdeka
Quoted 25 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
If they aren't, d8-d15 will be saved/restored, and that is ruining our tests.
Signed-off-by Jan Kiszka <[email protected]>--- kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +2
-1@@ -20,7 +20,8 @@#define __COBALT_HAVE_VFP 0x1 -static inline void fp_regs_set (int features,unsigned int val) +static inline void __attribute__ ((always_inline)) +fp_regs_set (int features,unsigned int val) {unsigned long long e[16 ];unsigned int i;kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h static inline void fp_regs_set(int features, unsigned int val) · line 43
Quoted 2 lines
kernel/cobalt/arch/arm/include/asm/xenomai/uapi/fptest.h +0
-0@@ -41,8 +42,9 @@ static inline void fp_regs_set(int features, unsigned int val) } }Could we use the
__always_inlinemacro from Linux here?
Quoted 5 lines
Quoted 1 line
This is (also) userland code (uapi...).
That's clear. I thought
__always_inlineis available for both worlds, but that might not be the case for all kernel versions we have here.
Seems like we could get it from <linux/stddef.h>. I'll rework the path.
Quoted 3 lines
Btw: Which path (user or kernel) was the problem? Both or just one of them?
I only saw the issue in the userland usage. Maybe the kernel's build switches prevented un-inlining otherwise.
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
PATCH 4/6 kernel/cobalt: Optimize xndebug_trace_relax implementation
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
There is no need to use xnthread_signal with its irq_work_queue here because the only caller of xndebug_trace_relax is already relaxed, and it is invoked over the target thread as well.
--- kernel/cobalt/debug.c | 11 ++++++++--- kernel/cobalt/debug.h | 5 ++--- kernel/cobalt/thread.c | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-)
kernel/cobalt/debug.c +8 -3
@@ -196,10 +196,15 @@ DEFINE_PRIVATE_XNLOCK(relax_lock);* executable mappings that could be involved). */ -void xndebug_notify_relax (struct xnthread *thread,int reason) +void xndebug_notify_relax (int reason) { -xnthread_signal (thread,SIGSHADOW , -sigshadow_int (SIGSHADOW_ACTION_BACKTRACE , reason)); +kernel_siginfo_t si; + +memset (&si,0 ,sizeof (si)); + si.si_signo =SIGSHADOW ; + si.si_code =SI_QUEUE ; + si.si_int =sigshadow_int (SIGSHADOW_ACTION_BACKTRACE , reason); +send_sig_info (SIGSHADOW , &si, current); } void xndebug_trace_relax(int nr, unsigned long *backtrace,
kernel/cobalt/debug.h +2 -3
@@ -52,13 +52,12 @@ static inline void xndebug_shadow_init(struct xnthread *thread)#endif /* !XENO_OPT_DEBUG */ #ifdef CONFIG_XENO_OPT_DEBUG_TRACE_RELAX -void xndebug_notify_relax (struct xnthread *thread, -int reason); +void xndebug_notify_relax (int reason);void xndebug_trace_relax (int nr,unsigned long *backtrace,int reason);#else static inline -void xndebug_notify_relax (struct xnthread *thread,int reason) +void xndebug_notify_relax (int reason) { } static inline
kernel/cobalt/thread.c +1 -1
@@ -2116,7 +2116,7 @@ void xnthread_relax(int notify, int reason)if (xnthread_test_state (thread,XNUSER ) && notify) {if (xnthread_test_state (thread,XNWARN )) {/* Help debugging spurious relaxes. */ -xndebug_notify_relax (thread, reason); +xndebug_notify_relax (reason);memset (&si,0 ,sizeof (si)); si.si_signo =SIGDEBUG ; si.si_code =SI_QUEUE ;
Signature · 1 line
2.51.0
PATCH 5/6 lib/cobalt: arm: Skip SIGSHADOW_ACTION_BACKTRACE over asynchronous signals
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
The unwinders of libgcc and libunwind prefer the ARM exception handling table over debug information. Unwinding this way is not designed to handle asynchronous signals, causing wrong backtraces in the best case but also too often even crashes.
Avoid running into that trap by skipping the request to create a backtrace via SIGSHADOW on ARM in case either the migration reason was a signal, or PTHREAD_WARNSW is enabled for the current thread. In both cases, the SIGSHADOW could be raised over the first instruction of another signal handler, causing the unwinder to fail.
Improving the unwinding libraries themselves is likely no longer with the effort for this phase-out architecture.
--- .../arch/arm/include/asm/xenomai/Makefile.am | 1 + .../arch/arm/include/asm/xenomai/debug.h | 27 +++++++++++++++++++ .../arm64/include/asm/xenomai/Makefile.am | 1 + .../arch/arm64/include/asm/xenomai/debug.h | 18 +++++++++++++ .../arch/x86/include/asm/xenomai/Makefile.am | 1 + .../arch/x86/include/asm/xenomai/debug.h | 18 +++++++++++++ lib/cobalt/sigshadow.c | 12 ++++++--- 7 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 lib/cobalt/arch/arm/include/asm/xenomai/debug.h create mode 100644 lib/cobalt/arch/arm64/include/asm/xenomai/debug.h create mode 100644 lib/cobalt/arch/x86/include/asm/xenomai/debug.h
lib/cobalt/arch/arm/include/asm/xenomai/Makefile.am +1 -0
@@ -1,4 +1,5 @@ noinst_HEADERS = \ + debug.h \ features.h \ syscall.h
lib/cobalt/arch/arm/include/asm/xenomai/debug.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (c) Siemens, 2025 +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +*/ + +#ifndef _LIB_COBALT_ARM_DEBUG_H +#define _LIB_COBALT_ARM_DEBUG_H + +#include <signal.h> +#include "current.h" + +static inline int cobalt_avoid_backtrace (int reason) +{ +if (reason ==SIGDEBUG_MIGRATE_SIGNAL ) +return 1 ; + +if (cobalt_get_current_mode () &PTHREAD_WARNSW ) +return 1 ; + +return 0 ; +} + +#endif /* !_LIB_COBALT_ARM_DEBUG_H */
lib/cobalt/arch/arm64/include/asm/xenomai/Makefile.am +1 -0
@@ -1,4 +1,5 @@ noinst_HEADERS = \ + debug.h \ features.h \ syscall.h
lib/cobalt/arch/arm64/include/asm/xenomai/debug.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright (c) Siemens, 2025 +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +*/ + +#ifndef _LIB_COBALT_ARM64_DEBUG_H +#define _LIB_COBALT_ARM64_DEBUG_H + +static inline int cobalt_avoid_backtrace (int reason) +{ +return 0 ; +} + +#endif /* !_LIB_COBALT_ARM64_DEBUG_H */
lib/cobalt/arch/x86/include/asm/xenomai/Makefile.am +1 -0
@@ -1,4 +1,5 @@ noinst_HEADERS = \ + debug.h \ features.h \ syscall.h
lib/cobalt/arch/x86/include/asm/xenomai/debug.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright (c) Siemens, 2025 +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +*/ + +#ifndef _LIB_COBALT_X86_DEBUG_H +#define _LIB_COBALT_X86_DEBUG_H + +static inline int cobalt_avoid_backtrace (int reason) +{ +return 0 ; +} + +#endif /* !_LIB_COBALT_X86_DEBUG_H */
lib/cobalt/sigshadow.c +8 -4
@@ -18,6 +18,7 @@#include <pthread.h> #include <signal.h> +#include <asm/xenomai/debug.h> #include <asm/xenomai/syscall.h> #include "internal.h"
@@ -43,7 +44,7 @@ static bool past_constructors;int cobalt_sigshadow_handler (int sig,siginfo_t *si,void *ctxt) {void *frames[SIGSHADOW_BACKTRACE_DEPTH ]; -int action, arg, nr, skip; +int action, reason, nr, skip;if (si->si_code !=SI_QUEUE )return 0 ;
@@ -55,11 +56,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void *ctxt)XENOMAI_SYSCALL1 (sc_cobalt_migrate,COBALT_PRIMARY );break ;case SIGSHADOW_ACTION_BACKTRACE : - arg =sigshadow_arg (si->si_int); - nr =backtrace (frames,ARRAY_SIZE (frames)); + reason =sigshadow_arg (si->si_int); + nr =0 ; +if (!cobalt_avoid_backtrace (reason)) + nr =backtrace (frames,ARRAY_SIZE (frames));/* Skip the sighandler context. */ skip = nr >3 ?3 :0 ; -XENOMAI_SYSCALL3 (sc_cobalt_backtrace, nr - skip, frames + skip, arg); +XENOMAI_SYSCALL3 (sc_cobalt_backtrace, nr - skip, frames + skip, + reason);break ;case SIGSHADOW_ACTION_HOME :/*
Signature · 1 line
2.51.0
Re: [PATCH 5/6] lib/cobalt: arm: Skip SIGSHADOW_ACTION_BACKTRACE over asynchronous signals
Quoted 6 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
The unwinders of libgcc and libunwind prefer the ARM exception handling table over debug information. Unwinding this way is not designed to handle asynchronous signals, causing wrong backtraces in the best case but also too often even crashes.
Has that changed with trixie or why did this problem not manifest earlier?
Quoted 6 lines
Avoid running into that trap by skipping the request to create a backtrace via SIGSHADOW on ARM in case either the migration reason was a signal, or
PTHREAD_WARNSWis enabled for the current thread. In both cases, the SIGSHADOW could be raised over the first instruction of another signal handler, causing the unwinder to fail.
Hm. Adding more arch specific code... Not nice, but well...
Does that have any effect on how debugging works or feels on arm now? Especially any difference to arm64? I'm concerned about gdb showing different information for the same issue. (In terms of different instruction shown as root cause of a migration, or things alike)
Quoted 2 lines
Improving the unwinding libraries themselves is likely no longer with
^^^^
Typo with -> worth?
Quoted 168 lines
the effort for this phase-out architecture.
Signed-off-by Jan Kiszka <[email protected]>--- .../arch/arm/include/asm/xenomai/Makefile.am | 1 + .../arch/arm/include/asm/xenomai/debug.h | 27 +++++++++++++++++++ .../arm64/include/asm/xenomai/Makefile.am | 1 + .../arch/arm64/include/asm/xenomai/debug.h | 18 +++++++++++++ .../arch/x86/include/asm/xenomai/Makefile.am | 1 + .../arch/x86/include/asm/xenomai/debug.h | 18 +++++++++++++ lib/cobalt/sigshadow.c | 12 ++++++--- 7 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 lib/cobalt/arch/arm/include/asm/xenomai/debug.h create mode 100644 lib/cobalt/arch/arm64/include/asm/xenomai/debug.h create mode 100644 lib/cobalt/arch/x86/include/asm/xenomai/debug.hlib/cobalt/arch/arm/include/asm/xenomai/Makefile.am +1
-0@@ -1,4 +1,5 @@ noinst_HEADERS = \ + debug.h \ features.h \ syscall.hlib/cobalt/arch/arm/include/asm/xenomai/debug.h new file +27
-0@@ -0,0 +1,27 @@ +/* +* Copyright (c) Siemens, 2025 +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +*/ + +#ifndef _LIB_COBALT_ARM_DEBUG_H +#define _LIB_COBALT_ARM_DEBUG_H + +#include <signal.h> +#include "current.h" + +static inline int cobalt_avoid_backtrace (int reason) +{ +if (reason ==SIGDEBUG_MIGRATE_SIGNAL ) +return 1 ; + +if (cobalt_get_current_mode () &PTHREAD_WARNSW ) +return 1 ; + +return 0 ; +} + +#endif /* !_LIB_COBALT_ARM_DEBUG_H */ lib/cobalt/arch/arm64/include/asm/xenomai/Makefile.am +1
-0@@ -1,4 +1,5 @@ noinst_HEADERS = \ + debug.h \ features.h \ syscall.hlib/cobalt/arch/arm64/include/asm/xenomai/debug.h new file +18
-0@@ -0,0 +1,18 @@ +/* +* Copyright (c) Siemens, 2025 +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +*/ + +#ifndef _LIB_COBALT_ARM64_DEBUG_H +#define _LIB_COBALT_ARM64_DEBUG_H + +static inline int cobalt_avoid_backtrace (int reason) +{ +return 0 ; +} + +#endif /* !_LIB_COBALT_ARM64_DEBUG_H */ lib/cobalt/arch/x86/include/asm/xenomai/Makefile.am +1
-0@@ -1,4 +1,5 @@ noinst_HEADERS = \ + debug.h \ features.h \ syscall.hlib/cobalt/arch/x86/include/asm/xenomai/debug.h new file +18
-0@@ -0,0 +1,18 @@ +/* +* Copyright (c) Siemens, 2025 +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +*/ + +#ifndef _LIB_COBALT_X86_DEBUG_H +#define _LIB_COBALT_X86_DEBUG_H + +static inline int cobalt_avoid_backtrace (int reason) +{ +return 0 ; +} + +#endif /* !_LIB_COBALT_X86_DEBUG_H */ lib/cobalt/sigshadow.c +8
-4@@ -18,6 +18,7 @@#include <pthread.h> #include <signal.h> +#include <asm/xenomai/debug.h> #include <asm/xenomai/syscall.h> #include "internal.h" @@ -43,7 +44,7 @@ static bool past_constructors;int cobalt_sigshadow_handler (int sig,siginfo_t *si,void *ctxt) {void *frames[SIGSHADOW_BACKTRACE_DEPTH ]; -int action, arg, nr, skip; +int action, reason, nr, skip;if (si->si_code !=SI_QUEUE )return 0 ;@@ -55,11 +56,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void *ctxt)XENOMAI_SYSCALL1 (sc_cobalt_migrate,COBALT_PRIMARY );break ;case SIGSHADOW_ACTION_BACKTRACE : - arg =sigshadow_arg (si->si_int); - nr =backtrace (frames,ARRAY_SIZE (frames)); + reason =sigshadow_arg (si->si_int); + nr =0 ; +if (!cobalt_avoid_backtrace (reason)) + nr =backtrace (frames,ARRAY_SIZE (frames));/* Skip the sighandler context. */ skip = nr >3 ?3 :0 ; -XENOMAI_SYSCALL3 (sc_cobalt_backtrace, nr - skip, frames + skip, arg); +XENOMAI_SYSCALL3 (sc_cobalt_backtrace, nr - skip, frames + skip, + reason);break ;case SIGSHADOW_ACTION_HOME :/* Signature · 1 line
2.51.0
Re: [PATCH 5/6] lib/cobalt: arm: Skip SIGSHADOW_ACTION_BACKTRACE over asynchronous signals
Quoted 11 lines · Florian Bezdeka
Quoted 6 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
The unwinders of libgcc and libunwind prefer the ARM exception handling table over debug information. Unwinding this way is not designed to handle asynchronous signals, causing wrong backtraces in the best case but also too often even crashes.
Has that changed with trixie or why did this problem not manifest earlier?
The problem is older again, but only with the trixie setup, I saw real crashes so far. We already got wrong backtraces before.
Quoted 9 lines
Quoted 6 lines
Avoid running into that trap by skipping the request to create a backtrace via SIGSHADOW on ARM in case either the migration reason was a signal, or
PTHREAD_WARNSWis enabled for the current thread. In both cases, the SIGSHADOW could be raised over the first instruction of another signal handler, causing the unwinder to fail.Hm. Adding more arch specific code... Not nice, but well...
Will get dropped again when we once phase out arm32.
Quoted 4 lines
Does that have any effect on how debugging works or feels on arm now? Especially any difference to arm64? I'm concerned about gdb showing different information for the same issue. (In terms of different instruction shown as root cause of a migration, or things alike)
gdb is not affected by this issue and happily back-traces through the complete stack. This only affects the results in /proc/xenomai/debug/relax.
Quoted 6 lines
Quoted 3 lines
Improving the unwinding libraries themselves is likely no longer with
^^^^Typo with -> worth?
Right.
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
PATCH 6/6 lib/cobalt: x86: Fix and simplify 32-bit syscall argument setup
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
This ancient code to constructing the argument setup of 32-bit syscalls now fail with recent compilers plus debug settings. Why the code was once designed in such a complex way is 20 years+ later no longer clear, but it seems that simply stating which register should contain which argument as assembler constraints is just working today.
Fixes assembly sequences like these (__cobalt_timer_gettime):
...
1395d: c7 45 f4 75 00 00 00 movl $0x75,-0xc(%ebp) 13964: 8b 45 f4 mov -0xc(%ebp),%eax 13967: 0d 00 00 00 10 or $0x10000000,%eax 1396c: 89 c3 mov %eax,%ebx 1396e: 8b 45 08 mov 0x8(%ebp),%eax 13971: 8b 4d 0c mov 0xc(%ebp),%ecx 13974: 53 push %ebx 13975: 89 c3 mov %eax,%ebx 13977: 89 d8 mov %ebx,%eax 13979: 65 ff 15 10 00 00 00 call *%gs:0x10
--- .../arch/x86/include/asm/xenomai/syscall.h | 71 ++----------------- 1 file changed, 7 insertions(+), 64 deletions(-)
lib/cobalt/arch/x86/include/asm/xenomai/syscall.h +7 -64
@@ -41,50 +41,13 @@/* The one that cannot fail. */ #define DOSYSCALLSAFE "int $0x80\n\t" -asm (".L__X'%ebx = 1\n\t" -".L__X'%ecx = 2\n\t" -".L__X'%edx = 2\n\t" -".L__X'%eax = 3\n\t" -".L__X'%esi = 3\n\t" -".L__X'%edi = 3\n\t" -".L__X'%ebp = 3\n\t" -".L__X'%esp = 3\n\t" -".macro bpushl name reg\n\t" -".if 1 - \\name\n\t" -".if 2 - \\name\n\t" -"pushl %ebx\n\t" -".else\n\t" -"xchgl \\reg, %ebx\n\t" -".endif\n\t" -".endif\n\t" -".endm\n\t" -".macro bpopl name reg\n\t" -".if 1 - \\name\n\t" -".if 2 - \\name\n\t" -"popl %ebx\n\t" -".else\n\t" -"xchgl \\reg, %ebx\n\t" -".endif\n\t" -".endif\n\t" -".endm\n\t" -".macro bmovl name reg\n\t" -".if 1 - \\name\n\t" -".if 2 - \\name\n\t" -"movl \\reg, %ebx\n\t" -".endif\n\t" -".endif\n\t" -".endm\n\t" ); - #define XENOMAI_DO_SYSCALL(nr, op, args...) \ ({ \ unsigned __resultvar; \ asm volatile ( \ - LOADARGS_##nr \ - "movl %1, %%eax\n\t" \ DOSYSCALL \ - RESTOREARGS_##nr \ : "=a" (__resultvar) \ - : "g" (__xn_syscode(op)) ASMFMT_##nr(args) \ + : "a" (__xn_syscode(op)) ASMFMT_##nr(args) \ : "memory", "cc"); \ (int) __resultvar; \ })
@@ -93,44 +56,24 @@ asm (".L__X'%ebx = 1\n\t" ({ \ unsigned __resultvar; \ asm volatile ( \ - LOADARGS_##nr \ - "movl %1, %%eax\n\t" \ DOSYSCALLSAFE \ - RESTOREARGS_##nr \ : "=a" (__resultvar) \ - : "g" (__xn_syscode(op)) ASMFMT_##nr(args) \ + : "a" (__xn_syscode(op)) ASMFMT_##nr(args) \ : "memory", "cc"); \ (int) __resultvar; \ }) -#define LOADARGS_0 -#define LOADARGS_1 \ - "bpushl .L__X'%k2, %k2\n\t" \ - "bmovl .L__X'%k2, %k2\n\t" -#define LOADARGS_2 LOADARGS_1 -#define LOADARGS_3 LOADARGS_1 -#define LOADARGS_4 LOADARGS_1 -#define LOADARGS_5 LOADARGS_1 - -#define RESTOREARGS_0 -#define RESTOREARGS_1 \ - "bpopl .L__X'%k2, %k2\n\t" -#define RESTOREARGS_2 RESTOREARGS_1 -#define RESTOREARGS_3 RESTOREARGS_1 -#define RESTOREARGS_4 RESTOREARGS_1 -#define RESTOREARGS_5 RESTOREARGS_1 - #define ASMFMT_0() #define ASMFMT_1(arg1) \ - , "acdSD" (arg1) + ASMFMT_0(), "b" (arg1) #define ASMFMT_2(arg1, arg2) \ - , "adSD" (arg1), "c" (arg2) + ASMFMT_1(arg1), "c" (arg2) #define ASMFMT_3(arg1, arg2, arg3) \ - , "aSD" (arg1), "c" (arg2), "d" (arg3) + ASMFMT_2(arg1, arg2), "d" (arg3) #define ASMFMT_4(arg1, arg2, arg3, arg4) \ - , "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4) + ASMFMT_3(arg1, arg2, arg3), "S" (arg4) #define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \ - , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5) + ASMFMT_4(arg1, arg2, arg3, arg4), "D" (arg5) #define XENOMAI_SYSBIND(breq) \ XENOMAI_DO_SYSCALL_SAFE(1, sc_cobalt_bind, breq)
Signature · 1 line
2.51.0
Quoted 9 lines · Jan Kiszka
Fixes that where found via the trixie update in xenomai-images and some cleanups. Most affect ARM 32-bit, the last one also 32-bit x86.
While the patches do not change the ABI and would therefore be backport candiates, I will likely only pick patches 3 and 5 for stable.
Which means that current stable versions of Xenomai should remain careful before updating their toolchains or libc versions for ARM and 32-bit x86.
Looking at patches 3 and 6, fixing problems in the low level syscall entry path, I'm wondering if we should revive [1] instead. Basically moving to libc syscall(), avoding the arch specific register dances in Xenomai.
That would also help moving forward to prctl(), which has one blocking point right now: The select() syscall has one argument to much.
evl does it the same way already...
There were some concerns about the additional function call, that would require some more measurement first.
[1] https://lore.kernel.org/xenomai/[email protected]/T/#t
Florian
Quoted 19 lines · Florian Bezdeka
Quoted 9 lines · Jan Kiszka
Fixes that where found via the trixie update in xenomai-images and some cleanups. Most affect ARM 32-bit, the last one also 32-bit x86.
While the patches do not change the ABI and would therefore be backport candiates, I will likely only pick patches 3 and 5 for stable.
Which means that current stable versions of Xenomai should remain careful before updating their toolchains or libc versions for ARM and 32-bit x86.
Looking at patches 3 and 6, fixing problems in the low level syscall entry path, I'm wondering if we should revive [1] instead. Basically moving to libc
syscall(), avoding the arch specific register dances in Xenomai.That would also help moving forward to
prctl(), which has one blocking point right now: Theselect()syscall has one argument to much.
Quoted 7 lines
evl does it the same way already...
There were some concerns about the additional function call, that would require some more measurement first.
As already mentioned in the patch: The strong arguments against that are
A) arm 32 is low-end and will likely suffer most and B) glibc is doing inline syscalls as well.
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center