Alignment exception on powerpc
Hi,
I'm running xenomai-2.4.8, Linux-2.6.26 on a MPC8360 PowerPC.
I enabled nucleus debugging and found out that tasks sometimes switch to secondary mode due to data alignment exceptions (#1536 == 0x600):
<snip>
Xenomai: Switching bgndT30_3 to secondary mode after exception #1536 from user-space at 0x101013f4 (pid 3191)
Xenomai: Switching bgndT30_3 to secondary mode after exception #1536 from user-space at 0x101013f4 (pid 3191)
...
</snip>
I know that we get those exceptions because we pass the -fpack-struct option to gcc and some data in structures are misaligned. It would be quite a lot of work to go through the code to change it so that we don't have to pass the -fpack-struct option.
Is there a way to execute the exception handler from primary mode to prevent the tasks to switch to secondary mode?
Best regards,
Andreas
Quoted 16 lines · Andreas Glatz
Hi,
I'm running xenomai-2.4.8, Linux-2.6.26 on a MPC8360 PowerPC.
I enabled nucleus debugging and found out that tasks sometimes switch to secondary mode due to data alignment exceptions (#1536 ==
0x600):<snip>
Xenomai: SwitchingbgndT30_3to secondary mode after exception #1536 from user-space at0x101013f4(pid 3191)
Xenomai: SwitchingbgndT30_3to secondary mode after exception #1536 from user-space at0x101013f4(pid 3191)
...
</snip>
Quoted 7 lines
I know that we get those exceptions because we pass the -fpack-struct option to gcc and some data in structures are misaligned. It would be quite a lot of work to go through the code to change it so that we don't have to pass the -fpack-struct option.
Is there a way to execute the exception handler from primary mode to prevent the tasks to switch to secondary mode?
I have absolutely no freaking idea whether the following patch will work, but you are welcome to feel lucky:
arch/powerpc/kernel/traps.c +6 -1
@@ -917,7 +917,8 @@ void alignment_exception(struct pt_regs *regs) {int sig, code, fixed =0 ; -if (ipipe_trap_notify (IPIPE_TRAP_ALIGNMENT ,regs)) +if (test_bit (IPIPE_NOSTACK_FLAG , &ipipe_this_cpudom_var (status)) && +ipipe_trap_notify (IPIPE_TRAP_ALIGNMENT , regs))return ;/* we don't implement logging of alignment exceptions */
@@ -930,6 +931,10 @@ void alignment_exception(struct pt_regs *regs)return ; } +if (!ipipe_root_domain_p && +ipipe_trap_notify (IPIPE_TRAP_ALIGNMENT , regs)) +return ; +/* Operand address was bad */ if (fixed == -EFAULT ) { sig =SIGSEGV ;
Quoted 9 lines
Best regards,
Andreas_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help
Signature · 1 line
Philippe.
Quoted 44 lines · Philippe Gerum
Quoted 16 lines · Andreas Glatz
Hi,
I'm running xenomai-2.4.8, Linux-2.6.26 on a MPC8360 PowerPC.
I enabled nucleus debugging and found out that tasks sometimes switch to secondary mode due to data alignment exceptions (#1536 ==
0x600):<snip>
Xenomai: SwitchingbgndT30_3to secondary mode after exception #1536 from user-space at0x101013f4(pid 3191)
Xenomai: SwitchingbgndT30_3to secondary mode after exception #1536 from user-space at0x101013f4(pid 3191)
...
</snip>Quoted 7 lines
I know that we get those exceptions because we pass the -fpack-struct option to gcc and some data in structures are misaligned. It would be quite a lot of work to go through the code to change it so that we don't have to pass the -fpack-struct option.
Is there a way to execute the exception handler from primary mode to prevent the tasks to switch to secondary mode?
I have absolutely no freaking idea whether the following patch will work, but you are welcome to feel lucky:
arch/powerpc/kernel/traps.c +2
-1@@ -917,7 +917,8 @@ void alignment_exception(struct pt_regs *regs) {int sig, code, fixed =0 ; -if (ipipe_trap_notify (IPIPE_TRAP_ALIGNMENT ,regs)) +if (test_bit (IPIPE_NOSTACK_FLAG , &ipipe_this_cpudom_var (status)) && +ipipe_trap_notify (IPIPE_TRAP_ALIGNMENT , regs))return ;/* we don't implement logging of alignment exceptions */
arch/powerpc/kernel/traps.c void alignment_exception(struct pt_regs *regs) · line 940
Quoted 10 lines
arch/powerpc/kernel/traps.c +4
-0@@ -930,6 +931,10 @@ void alignment_exception(struct pt_regs *regs)return ; } +if (!ipipe_root_domain_p && +ipipe_trap_notify (IPIPE_TRAP_ALIGNMENT , regs)) +return ; +/* Operand address was bad */ if (fixed == -EFAULT ) { sig =SIGSEGV ;
This one should require a bit less luck to work in some cases:
arch/powerpc/kernel/align.c +8 -4
@@ -788,10 +788,11 @@ int fix_alignment(struct pt_regs *regs)if (flags &S ) {/* Single-precision FP store requires conversion... */ #ifdef CONFIG_PPC_FPU -preempt_disable (); +unsigned long irqflags; +ipipe_preempt_disable (irqflags);enable_kernel_fp ();cvt_df (&data.dd, (float *)&data.v[4 ], ¤t->thread); -preempt_enable (); +ipipe_preempt_enable (irqflags);#else return 0 ;#endif
@@ -832,10 +833,13 @@ int fix_alignment(struct pt_regs *regs)/* Single-precision FP load requires conversion... */ case LD +F +S :#ifdef CONFIG_PPC_FPU -preempt_disable (); + { +unsigned long irqflags; +ipipe_preempt_disable (irqflags);enable_kernel_fp ();cvt_fd ((float *)&data.v[4 ], &data.dd, ¤t->thread); -preempt_enable (); +ipipe_preempt_enable (irqflags); + }#else return 0 ;#endif
arch/powerpc/kernel/process.c +9 -5
@@ -62,6 +62,8 @@ struct task_struct *last_task_used_spe = NULL;*/ void flush_fp_to_thread (struct task_struct *tsk) { +unsigned long flags; +if (tsk->thread.regs) {/* * We need to disable preemption here because if we didn't,
@@ -71,7 +73,7 @@ void flush_fp_to_thread(struct task_struct *tsk)* FPU, and then when we get scheduled again we would store * bogus values for the remaining FP registers. */ -preempt_disable (); +ipipe_preempt_disable (flags);if (tsk->thread.regs->msr &MSR_FP ) {#ifdef CONFIG_SMP /*
@@ -85,13 +87,13 @@ void flush_fp_to_thread(struct task_struct *tsk)#endif giveup_fpu (tsk); } -preempt_enable (); +ipipe_preempt_enable (flags); } }void enable_kernel_fp (void ) { -WARN_ON (preemptible ()); +WARN_ON (ipipe_root_domain_p &&preemptible ());#ifdef CONFIG_SMP if (current->thread.regs && (current->thread.regs->msr &MSR_FP ))
@@ -198,15 +200,17 @@ EXPORT_SYMBOL(enable_kernel_spe);void flush_spe_to_thread (struct task_struct *tsk) { +unsigned long flags; +if (tsk->thread.regs) { -preempt_disable (); +ipipe_preempt_disable (flags);if (tsk->thread.regs->msr &MSR_SPE ) {#ifdef CONFIG_SMP BUG_ON (tsk != current);#endif giveup_spe (tsk); } -preempt_enable (); +ipipe_preempt_enable (flags); } }
arch/powerpc/kernel/traps.c +6 -1
@@ -917,7 +917,8 @@ void alignment_exception(struct pt_regs *regs) {int sig, code, fixed =0 ; -if (ipipe_trap_notify (IPIPE_TRAP_ALIGNMENT ,regs)) +if (test_bit (IPIPE_NOSTACK_FLAG , &ipipe_this_cpudom_var (status)) && +ipipe_trap_notify (IPIPE_TRAP_ALIGNMENT , regs))return ;/* we don't implement logging of alignment exceptions */
@@ -930,6 +931,10 @@ void alignment_exception(struct pt_regs *regs)return ; } +if (!ipipe_root_domain_p && +ipipe_trap_notify (IPIPE_TRAP_ALIGNMENT , regs)) +return ; +/* Operand address was bad */ if (fixed == -EFAULT ) { sig =SIGSEGV ;
Signature · 1 line
Philippe.
Hi Philippe,
Quoted 6 lines
Quoted 2 lines
Is there a way to execute the exception handler from primary mode to prevent the tasks to switch to secondary mode?
I have absolutely no freaking idea whether the following patch will work, but you are welcome to feel lucky:
The patch seems to work. I even put a printk inside the if(fixed == 1) clause inside of the patched function alignment_exception() to check if things really get fixed... and they do!
I just noticed that u sent out another patch. Do u want me to test that one too?
Of course, now I have the problem that I don't know which one is better... :p
Andreas
Quoted 10 lines · Andreas Glatz
Hi Philippe,
Quoted 6 lines
Quoted 2 lines
Is there a way to execute the exception handler from primary mode to prevent the tasks to switch to secondary mode?
I have absolutely no freaking idea whether the following patch will work, but you are welcome to feel lucky:
Quoted 7 lines
The patch seems to work. I even put a printk inside the if(fixed == 1) clause inside of the patched function
alignment_exception()to check if things really get fixed... and they do!I just noticed that u sent out another patch. Do u want me to test that one too?
Yes please. If that works for you, I will probably merge those bits in the next pipeline release, after some additional testing. 83xx may take various sorts of alignment traps, and there is no reason to suffer secondary mode switches for basic instruction emulation followed by a simple IP fixup.
#2 should definitely be better in some cases, for instance when the cause of the alignment trap requires FP emulation.
Quoted 2 lines
Of course, now I have the problem that I don't know which one is better... :p
Well, in terms of voodoo programming, the latest one is simply better because it changes more lines of code, which gives much more opportunities to break things. Ok, let's look cool and jaunty: let's pick #2.
Quoted 2 lines
Andreas
Signature · 1 line
Philippe.