Mayday mechanism broken on x86-64 - simpler approach feasible?
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on return
That that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in entry_64.S.
x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
I was playing with a different approach: Set a flag that mayday is underway, let the interrupt context cause a fault (set ip to 0) and then fix that up if we are in mayday mode. Seems to work fine (after fixing some x86 ipipe issue) and would simplify the mayday logic apparently. So I'm wondering why that approach wasn't chosen initially? IOW, what am I missing?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 12 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on return
Quoted 4 lines
Quoted 4 lines
That that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.
Maybe we can restore it in xnarch_fixup_mayday, if nothing touches it ?
Signature · 1 line
Gilles.
Quoted 20 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnThat that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
Quoted 7 lines
I was playing with a different approach: Set a flag that mayday is underway, let the interrupt context cause a fault (set ip to 0) and then fix that up if we are in mayday mode. Seems to work fine (after fixing some x86 ipipe issue) and would simplify the mayday logic apparently. So I'm wondering why that approach wasn't chosen initially? IOW, what am I missing?
The scheme had to work on MMU-less platforms as well, so jump <foobar> seemed not a reasonable option.
Signature · 1 line
Philippe.
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on return
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
That that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.Maybe we can restore it in
xnarch_fixup_mayday, if nothing touches it ?
The problem is that cx is mangled again on preparing sysret - we are in a syscall return path at that point, but we need an interrupt/exception path in fact.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 29 lines · Philippe Gerum
Quoted 20 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnThat that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
Quoted 7 lines
I was playing with a different approach: Set a flag that mayday is underway, let the interrupt context cause a fault (set ip to 0) and then fix that up if we are in mayday mode. Seems to work fine (after fixing some x86 ipipe issue) and would simplify the mayday logic apparently. So I'm wondering why that approach wasn't chosen initially? IOW, what am I missing?
Quoted 2 lines
The scheme had to work on MMU-less platforms as well, so jump <foobar> seemed not a reasonable option.
True - but at least MMU/MPU-featured platforms could use this.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 19 lines · Jan Kiszka
Quoted 18 lines · Gilles Chanteperdrix
Quoted 16 lines · Philippe Gerum
Quoted 15 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnThat that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.
Quoted 6 lines
Quoted 2 lines
Maybe we can restore it in
xnarch_fixup_mayday, if nothing touches it ?The problem is that cx is mangled again on preparing sysret - we are in a syscall return path at that point, but we need an interrupt/exception path in fact.
ARM had a similar issue with the register holding the syscall return value, the fix was to return __xn_reg_rval(regs) in
the mayday syscall, is not this fix working for x86? How is cx mangled exactly?
Signature · 1 line
Gilles.
Quoted 22 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnQuoted 9 lines
That that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
Quoted 4 lines
The legacy
system_callvector is available unconditionally tox86_64. Xenomai 3 is actually calling int80 unconditionally on mayday traps for these reasons, i.e. always available and not suffering the long-mode syscall registers issue.
Only when setting CONFIG_IA32_EMULATION. That is typcially the case, but not necessarily.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 23 lines · Gilles Chanteperdrix
Quoted 22 lines · Jan Kiszka
Quoted 20 lines · Gilles Chanteperdrix
Quoted 12 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnQuoted 4 lines
Quoted 4 lines
That that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.Maybe we can restore it in
xnarch_fixup_mayday, if nothing touches it ?
Quoted 8 lines
Quoted 3 lines
The problem is that cx is mangled again on preparing sysret - we are in a syscall return path at that point, but we need an interrupt/exception path in fact.
ARM had a similar issue with the register holding the syscall return value, the fix was to return
__xn_reg_rval(regs)in
the mayday syscall, is not this fix working for x86? How is cx mangled exactly?
rcx holds the ip of the context we call from / return to. So the return path loads cx with the ip value saved in the register set on the stack.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 11 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on return
Quoted 9 lines
That that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
The legacy system_call vector is available unconditionally to x86_64. Xenomai 3 is actually calling int80 unconditionally on mayday traps for these reasons, i.e. always available and not suffering the long-mode syscall registers issue.
Signature · 1 line
Philippe.
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Philippe Gerum
Quoted 20 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnThat that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
Quoted 8 lines
Quoted 4 lines
The legacy
system_callvector is available unconditionally tox86_64. Xenomai 3 is actually calling int80 unconditionally on mayday traps for these reasons, i.e. always available and not suffering the long-mode syscall registers issue.Only when setting
CONFIG_IA32_EMULATION. That is typcially the case, but not necessarily.
I mean: the "safe" Xenomai syscall form (the one that binds a process to the real-time core in dual kernel mode) depends on this. Disabling int80 is not an option in the current Xenomai implementation, mayday feature put aside.
So this change would also break the Xenomai ABI (which is ok with x3, but not an option for 2.6.4).
Signature · 1 line
Philippe.
Quoted 29 lines · Philippe Gerum
Quoted 28 lines · Jan Kiszka
Quoted 26 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnQuoted 9 lines
That that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
The legacy
system_callvector is available unconditionally tox86_64. Xenomai 3 is actually calling int80 unconditionally on mayday traps for these reasons, i.e. always available and not suffering the long-mode syscall registers issue.
Quoted 8 lines
Quoted 3 lines
Only when setting
CONFIG_IA32_EMULATION. That is typcially the case, but not necessarily.I mean: the "safe" Xenomai syscall form (the one that binds a process to the real-time core in dual kernel mode) depends on this. Disabling int80 is not an option in the current Xenomai implementation, mayday feature put aside.
Huh? Things worked fine here on X3 when trying out the effect of disabling IA32 emulation. Or do you mean 2.6?
Quoted 3 lines
So this change would also break the Xenomai ABI (which is ok with x3, but not an option for 2.6.4).
Yes, 2.6 requires a compatible solution.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 34 lines · Jan Kiszka
Quoted 33 lines · Philippe Gerum
Quoted 31 lines · Jan Kiszka
Quoted 22 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnQuoted 9 lines
That that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
Quoted 4 lines
The legacy
system_callvector is available unconditionally tox86_64. Xenomai 3 is actually calling int80 unconditionally on mayday traps for these reasons, i.e. always available and not suffering the long-mode syscall registers issue.Only when setting
CONFIG_IA32_EMULATION. That is typcially the case, but not necessarily.
Quoted 7 lines
Quoted 4 lines
I mean: the "safe" Xenomai syscall form (the one that binds a process to the real-time core in dual kernel mode) depends on this. Disabling int80 is not an option in the current Xenomai implementation, mayday feature put aside.
Huh? Things worked fine here on X3 when trying out the effect of disabling IA32 emulation. Or do you mean 2.6?
Can't imagine either: x86-64 does not take 64-bit syscalls via int80, no matter if Linux or Xenomai.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 34 lines · Jan Kiszka
Quoted 33 lines · Philippe Gerum
Quoted 31 lines · Jan Kiszka
Quoted 22 lines · Philippe Gerum
Quoted 11 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnQuoted 9 lines
That that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
Quoted 4 lines
The legacy
system_callvector is available unconditionally tox86_64. Xenomai 3 is actually calling int80 unconditionally on mayday traps for these reasons, i.e. always available and not suffering the long-mode syscall registers issue.Only when setting
CONFIG_IA32_EMULATION. That is typcially the case, but not necessarily.
Quoted 8 lines
Quoted 4 lines
I mean: the "safe" Xenomai syscall form (the one that binds a process to the real-time core in dual kernel mode) depends on this. Disabling int80 is not an option in the current Xenomai implementation, mayday feature put aside.
Huh? Things worked fine here on X3 when trying out the effect of disabling IA32 emulation. Or do you mean 2.6?
I meant to tell crap: x86_64 implies vsyscall available, so there is no "safe" binding prologue there. Only x86_32 has this, so that legacy non-NPTL libc which do not support vsyscall work. So back to the initial discussion.
Signature · 1 line
Philippe.
Quoted 4 lines · Philippe Gerum
I meant to tell crap:
x86_64implies vsyscall available, so there is no "safe" binding prologue there. Onlyx86_32has this, so that legacy non-NPTL libc which do not support vsyscall work. So back to the initial discussion.
OK. Here is a hack that implements fault-based mayday support on x86:
kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +1 -0
@@ -40,6 +40,7 @@ struct xnarchtcb {unsigned long ip;unsigned long ax;unsigned long sp; +bool pending; } mayday; };
kernel/cobalt/arch/x86/mayday.c +4 -98
129 lines not on this page · raw message
kernel/cobalt/posix/process.c +11 -2
@@ -699,6 +699,12 @@ static inline int handle_exception(struct ipipe_trap_data *d)if (xnthread_test_state (thread,XNROOT ))return 0 ; +if (xnthread_archtcb (thread)->mayday.pending) { +xnarch_fixup_mayday (xnthread_archtcb (thread), d->regs); +xnthread_relax (0 ,0 ); +return 1 ; + } +trace_cobalt_thread_fault (thread, d);if (xnarch_fault_fpu_p (d)) {
@@ -1256,10 +1262,13 @@ static inline unsigned long map_mayday_page(void)int ret; mayday_page =xnarch_get_mayday_page (); +if (!mayday_page) +return 0UL ; + ret =rtdm_mmap_to_user (NULL , mayday_page,PAGE_SIZE ,PROT_READ |PROT_EXEC , &u_addr,NULL ,NULL );if (ret) -return 0UL ; +return -1UL ;return (unsigned long )u_addr; }
@@ -1278,7 +1287,7 @@ static int attach_process(struct cobalt_process *process)cobalt_umm_set_name (&p->umm,"private heap[%d]" , current->pid); p->mayday_tramp =map_mayday_page (); -if (p->mayday_tramp ==0 ) { +if (p->mayday_tramp ==-1UL ) {printk (XENO_WARN "%s[%d] cannot map MAYDAY page\n" , current->comm, current->pid);
The test case is in my for-forge queue, i.e. the ported sigdebug. I-pipe bits are pushed to for-upstream/3.14 for reference. I had some troubles with improper root irqs state when running the smokey test under gdb. Not related to mayday, just a side effect of debugging the issue. Should be fixed now.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 40 lines · Philippe Gerum
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Philippe Gerum
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Philippe Gerum
Quoted 20 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnThat that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
Quoted 8 lines
Quoted 4 lines
The legacy
system_callvector is available unconditionally tox86_64. Xenomai 3 is actually calling int80 unconditionally on mayday traps for these reasons, i.e. always available and not suffering the long-mode syscall registers issue.Only when setting
CONFIG_IA32_EMULATION. That is typcially the case, but not necessarily.I mean: the "safe" Xenomai syscall form (the one that binds a process to the real-time core in dual kernel mode) depends on this. Disabling int80 is not an option in the current Xenomai implementation, mayday feature put aside.
Quoted 9 lines
Quoted 3 lines
Huh? Things worked fine here on X3 when trying out the effect of disabling IA32 emulation. Or do you mean 2.6?
I meant to tell crap:
x86_64implies vsyscall available, so there is no "safe" binding prologue there. Onlyx86_32has this, so that legacy non-NPTL libc which do not support vsyscall work. So back to the initial discussion.
As I mentioned earlier, I'd rather fix the MAYDAY implementation for x86_64 instead of forking the implementation between MMU-enabled and MMU-less architectures, also affecting powerpc, arm and x86_32 in the same move. Fortunately, the current implementation allows very specific tweaks to be applied on a per-architecture basis. This one fixes the issue for Cobalt on x86_64, and could be easily backported to 2.6.x:
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=6db20901963d634b9786467c711c2ba526db48a2
Signature · 1 line
Philippe.
Quoted 51 lines · Philippe Gerum
Quoted 40 lines · Philippe Gerum
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Philippe Gerum
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Philippe Gerum
Quoted 20 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnThat that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
Quoted 8 lines
Quoted 4 lines
The legacy
system_callvector is available unconditionally tox86_64. Xenomai 3 is actually calling int80 unconditionally on mayday traps for these reasons, i.e. always available and not suffering the long-mode syscall registers issue.Only when setting
CONFIG_IA32_EMULATION. That is typcially the case, but not necessarily.I mean: the "safe" Xenomai syscall form (the one that binds a process to the real-time core in dual kernel mode) depends on this. Disabling int80 is not an option in the current Xenomai implementation, mayday feature put aside.
Quoted 9 lines
Quoted 3 lines
Huh? Things worked fine here on X3 when trying out the effect of disabling IA32 emulation. Or do you mean 2.6?
I meant to tell crap:
x86_64implies vsyscall available, so there is no "safe" binding prologue there. Onlyx86_32has this, so that legacy non-NPTL libc which do not support vsyscall work. So back to the initial discussion.
Quoted 8 lines
As I mentioned earlier, I'd rather fix the MAYDAY implementation for
x86_64instead of forking the implementation between MMU-enabled and MMU-less architectures, also affecting powerpc, arm andx86_32in the same move. Fortunately, the current implementation allows very specific tweaks to be applied on a per-architecture basis. This one fixes the issue for Cobalt onx86_64, and could be easily backported to 2.6.x:http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=6db20901963d634b9786467c711c2ba526db48a2
Looks almost good - except for the detail that some bits of the instruction pointer are lost on return from the syscall (int vs. long return type). Patches in the making.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 59 lines · Jan Kiszka
Quoted 58 lines · Philippe Gerum
Quoted 40 lines · Philippe Gerum
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Philippe Gerum
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Philippe Gerum
Quoted 20 lines · Jan Kiszka
Hi,
while porting the sigdebug test case to forge I noticed occasional crashes of the test after it received a watchdog signal. It turned out that the problem is in the way mayday works on x86-64:
1. sp/ip/ax of interrupted thread is saved
2. ip is set to mayday page
3. mayday page executes the mayday syscall via the syscall instruction
4. the syscall restores state on original state on returnThat that's the theory. Unfortunately the syscall instructions overwrites the cx register with the caller's instruction pointer. We could save it but there is no way to restore it on syscall return without significant changes to the Linux code in
entry_64.S.x86-32 is fine as it uses the int80 path which does a full state recovery - but that is not available for 64-bit (only via ia32 compat, but that can be turned off).
Quoted 8 lines
Quoted 4 lines
The legacy
system_callvector is available unconditionally tox86_64. Xenomai 3 is actually calling int80 unconditionally on mayday traps for these reasons, i.e. always available and not suffering the long-mode syscall registers issue.Only when setting
CONFIG_IA32_EMULATION. That is typcially the case, but not necessarily.I mean: the "safe" Xenomai syscall form (the one that binds a process to the real-time core in dual kernel mode) depends on this. Disabling int80 is not an option in the current Xenomai implementation, mayday feature put aside.
Quoted 9 lines
Quoted 3 lines
Huh? Things worked fine here on X3 when trying out the effect of disabling IA32 emulation. Or do you mean 2.6?
I meant to tell crap:
x86_64implies vsyscall available, so there is no "safe" binding prologue there. Onlyx86_32has this, so that legacy non-NPTL libc which do not support vsyscall work. So back to the initial discussion.As I mentioned earlier, I'd rather fix the MAYDAY implementation for
x86_64instead of forking the implementation between MMU-enabled and MMU-less architectures, also affecting powerpc, arm andx86_32in the same move. Fortunately, the current implementation allows very specific tweaks to be applied on a per-architecture basis. This one fixes the issue for Cobalt onx86_64, and could be easily backported to 2.6.x:
Quoted 6 lines
Quoted 1 line
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=6db20901963d634b9786467c711c2ba526db48a2
Looks almost good - except for the detail that some bits of the instruction pointer are lost on return from the syscall (int vs. long return type). Patches in the making.
There could be another issue with %rsp. I'm checking this.
Signature · 1 line
Philippe.
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
As I mentioned earlier, I'd rather fix the MAYDAY implementation for
x86_64instead of forking the implementation between MMU-enabled and MMU-less architectures, also affecting powerpc, arm andx86_32in the same move. Fortunately, the current implementation allows very specific tweaks to be applied on a per-architecture basis. This one fixes the issue for Cobalt onx86_64, and could be easily backported to 2.6.x:
Quoted 5 lines
Quoted 1 line
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=6db20901963d634b9786467c711c2ba526db48a2
Looks almost good - except for the detail that some bits of the instruction pointer are lost on return from the syscall (int vs. long return type). Patches in the making.
Will take longer - I need to convert all cobalt syscalls.
We have a sleeping bug there, though likely not seen in practice, with syscalls returning values > INT_MAX (size_t...). The problem is that handle_head/root_syscall only forwarded 32-bits so far.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 14 lines · Jan Kiszka
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
As I mentioned earlier, I'd rather fix the MAYDAY implementation for
x86_64instead of forking the implementation between MMU-enabled and MMU-less architectures, also affecting powerpc, arm andx86_32in the same move. Fortunately, the current implementation allows very specific tweaks to be applied on a per-architecture basis. This one fixes the issue for Cobalt onx86_64, and could be easily backported to 2.6.x:Quoted 5 lines
Quoted 1 line
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=6db20901963d634b9786467c711c2ba526db48a2
Looks almost good - except for the detail that some bits of the instruction pointer are lost on return from the syscall (int vs. long return type). Patches in the making.
Quoted 6 lines
Will take longer - I need to convert all cobalt syscalls.
We have a sleeping bug there, though likely not seen in practice, with syscalls returning values >
INT_MAX(size_t...). The problem is that handle_head/root_syscall only forwarded 32-bits so far.
You mean this, and all the implications of it?
kernel/cobalt/posix/syscall.c +3 -3
@@ -73,9 +73,9 @@/* Shorthand for oneway trap - does not return to call site. */ #define __xn_exec_oneway __xn_exec_norestart -typedef int (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, -unsigned long arg3,unsigned long arg4, -unsigned long arg5); +typedef long (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, +unsigned long arg3,unsigned long arg4, +unsigned long arg5); static void prepare_for_signal(struct task_struct *p, struct xnthread *thread,
Signature · 1 line
Philippe.
Quoted 32 lines · Philippe Gerum
Quoted 14 lines · Jan Kiszka
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
As I mentioned earlier, I'd rather fix the MAYDAY implementation for
x86_64instead of forking the implementation between MMU-enabled and MMU-less architectures, also affecting powerpc, arm andx86_32in the same move. Fortunately, the current implementation allows very specific tweaks to be applied on a per-architecture basis. This one fixes the issue for Cobalt onx86_64, and could be easily backported to 2.6.x:Quoted 5 lines
Quoted 1 line
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=6db20901963d634b9786467c711c2ba526db48a2
Looks almost good - except for the detail that some bits of the instruction pointer are lost on return from the syscall (int vs. long return type). Patches in the making.
Quoted 6 lines
Will take longer - I need to convert all cobalt syscalls.
We have a sleeping bug there, though likely not seen in practice, with syscalls returning values >
INT_MAX(size_t...). The problem is that handle_head/root_syscall only forwarded 32-bits so far.You mean this, and all the implications of it?
kernel/cobalt/posix/syscall.c +0
-0@@ -73,9 +73,9 @@/* Shorthand for oneway trap - does not return to call site. */ #define __xn_exec_oneway __xn_exec_norestart
kernel/cobalt/posix/syscall.c line 81
Quoted 10 lines
kernel/cobalt/posix/syscall.c +3
-3-typedef int (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, -unsigned long arg3,unsigned long arg4, -unsigned long arg5); +typedef long (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, +unsigned long arg3,unsigned long arg4, +unsigned long arg5); static void prepare_for_signal(struct task_struct *p, struct xnthread *thread,
Exactly.
Just done with the mechanics, crossing fingers it won't break things subtly.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Philippe Gerum
Quoted 14 lines · Jan Kiszka
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
As I mentioned earlier, I'd rather fix the MAYDAY implementation for
x86_64instead of forking the implementation between MMU-enabled and MMU-less architectures, also affecting powerpc, arm andx86_32in the same move. Fortunately, the current implementation allows very specific tweaks to be applied on a per-architecture basis. This one fixes the issue for Cobalt onx86_64, and could be easily backported to 2.6.x:Quoted 5 lines
Quoted 1 line
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=6db20901963d634b9786467c711c2ba526db48a2
Looks almost good - except for the detail that some bits of the instruction pointer are lost on return from the syscall (int vs. long return type). Patches in the making.
Quoted 6 lines
Will take longer - I need to convert all cobalt syscalls.
We have a sleeping bug there, though likely not seen in practice, with syscalls returning values >
INT_MAX(size_t...). The problem is that handle_head/root_syscall only forwarded 32-bits so far.You mean this, and all the implications of it?
kernel/cobalt/posix/syscall.c +3
-3@@ -73,9 +73,9 @@/* Shorthand for oneway trap - does not return to call site. */ #define __xn_exec_oneway __xn_exec_norestart -typedef int (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, -unsigned long arg3,unsigned long arg4, -unsigned long arg5); +typedef long (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, +unsigned long arg3,unsigned long arg4, +unsigned long arg5);
Quoted 8 lines
kernel/cobalt/posix/syscall.c line 81
Quoted 3 lines
kernel/cobalt/posix/syscall.c +0
-0static void prepare_for_signal(struct task_struct *p, struct xnthread *thread,Exactly.
Just done with the mechanics, crossing fingers it won't break things subtly.
Ok. While we are at it, we should get rid of the syscall return type in the COBALT_SYSCALL[_DECL] macro helpers, this is pointless.
Signature · 1 line
Philippe.
Quoted 47 lines · Philippe Gerum
Quoted 46 lines · Jan Kiszka
Quoted 32 lines · Philippe Gerum
Quoted 14 lines · Jan Kiszka
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
As I mentioned earlier, I'd rather fix the MAYDAY implementation for
x86_64instead of forking the implementation between MMU-enabled and MMU-less architectures, also affecting powerpc, arm andx86_32in the same move. Fortunately, the current implementation allows very specific tweaks to be applied on a per-architecture basis. This one fixes the issue for Cobalt onx86_64, and could be easily backported to 2.6.x:Quoted 5 lines
Quoted 1 line
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=6db20901963d634b9786467c711c2ba526db48a2
Looks almost good - except for the detail that some bits of the instruction pointer are lost on return from the syscall (int vs. long return type). Patches in the making.
Quoted 6 lines
Will take longer - I need to convert all cobalt syscalls.
We have a sleeping bug there, though likely not seen in practice, with syscalls returning values >
INT_MAX(size_t...). The problem is that handle_head/root_syscall only forwarded 32-bits so far.You mean this, and all the implications of it?
kernel/cobalt/posix/syscall.c +0
-0@@ -73,9 +73,9 @@/* Shorthand for oneway trap - does not return to call site. */ #define __xn_exec_oneway __xn_exec_norestartkernel/cobalt/posix/syscall.c line 81
Quoted 10 lines
kernel/cobalt/posix/syscall.c +3
-3-typedef int (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, -unsigned long arg3,unsigned long arg4, -unsigned long arg5); +typedef long (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, +unsigned long arg3,unsigned long arg4, +unsigned long arg5); static void prepare_for_signal(struct task_struct *p, struct xnthread *thread,Exactly.
Quoted 5 lines
Quoted 2 lines
Just done with the mechanics, crossing fingers it won't break things subtly.
Ok. While we are at it, we should get rid of the syscall return type in the COBALT_SYSCALL[_DECL] macro helpers, this is pointless.
Jep, that's what I did - hard-wired it to long.
First tests look good, just need to split things up into 3 or 4 patches now.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 51 lines · Jan Kiszka
Quoted 50 lines · Philippe Gerum
Quoted 48 lines · Jan Kiszka
Quoted 32 lines · Philippe Gerum
Quoted 14 lines · Jan Kiszka
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
As I mentioned earlier, I'd rather fix the MAYDAY implementation for
x86_64instead of forking the implementation between MMU-enabled and MMU-less architectures, also affecting powerpc, arm andx86_32in the same move. Fortunately, the current implementation allows very specific tweaks to be applied on a per-architecture basis. This one fixes the issue for Cobalt onx86_64, and could be easily backported to 2.6.x:Quoted 5 lines
Quoted 1 line
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=6db20901963d634b9786467c711c2ba526db48a2
Looks almost good - except for the detail that some bits of the instruction pointer are lost on return from the syscall (int vs. long return type). Patches in the making.
Quoted 6 lines
Will take longer - I need to convert all cobalt syscalls.
We have a sleeping bug there, though likely not seen in practice, with syscalls returning values >
INT_MAX(size_t...). The problem is that handle_head/root_syscall only forwarded 32-bits so far.You mean this, and all the implications of it?
kernel/cobalt/posix/syscall.c +0
-0@@ -73,9 +73,9 @@/* Shorthand for oneway trap - does not return to call site. */ #define __xn_exec_oneway __xn_exec_norestartkernel/cobalt/posix/syscall.c line 81
Quoted 10 lines
kernel/cobalt/posix/syscall.c +3
-3-typedef int (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, -unsigned long arg3,unsigned long arg4, -unsigned long arg5); +typedef long (*cobalt_syshand )(unsigned long arg1,unsigned long arg2, +unsigned long arg3,unsigned long arg4, +unsigned long arg5); static void prepare_for_signal(struct task_struct *p, struct xnthread *thread,Exactly.
Just done with the mechanics, crossing fingers it won't break things subtly.
Quoted 6 lines
Quoted 2 lines
Ok. While we are at it, we should get rid of the syscall return type in the COBALT_SYSCALL[_DECL] macro helpers, this is pointless.
Jep, that's what I did - hard-wired it to long.
First tests look good, just need to split things up into 3 or 4 patches now.
Done, see my for-forge branch.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 8 lines · Jan Kiszka
Quoted 6 lines
Quoted 2 lines
Ok. While we are at it, we should get rid of the syscall return type in the COBALT_SYSCALL[_DECL] macro helpers, this is pointless.
Jep, that's what I did - hard-wired it to long.
First tests look good, just need to split things up into 3 or 4 patches now.
Done, see my for-forge branch.
BTW, we should also clean up the 32-bit syscall macros in the same way, just to be consistent (on issue to fix over there). Can do when I ran out of bugs (or need some distraction).
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 6 lines · Jan Kiszka
Quoted 5 lines · Jan Kiszka
Quoted 5 lines
Quoted 2 lines
Ok. While we are at it, we should get rid of the syscall return type in the COBALT_SYSCALL[_DECL] macro helpers, this is pointless.
Jep, that's what I did - hard-wired it to long.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
First tests look good, just need to split things up into 3 or 4 patches now.
Done, see my for-forge branch.
BTW, we should also clean up the 32-bit syscall macros in the same way, just to be consistent (on issue to fix over there). Can do when I ran out of bugs (or need some distraction).
Ack.
Signature · 1 line
Philippe.
Quoted 9 lines · Philippe Gerum
Quoted 8 lines · Jan Kiszka
Quoted 7 lines · Jan Kiszka
Quoted 6 lines
Quoted 2 lines
Ok. While we are at it, we should get rid of the syscall return type in the COBALT_SYSCALL[_DECL] macro helpers, this is pointless.
Jep, that's what I did - hard-wired it to long.
First tests look good, just need to split things up into 3 or 4 patches now.
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Done, see my for-forge branch.
BTW, we should also clean up the 32-bit syscall macros in the same way, just to be consistent (on issue to fix over there). Can do when I ran out of bugs (or need some distraction).
Ack.
Don't bother with this, I'm doing the conversion.
Signature · 1 line
Philippe.