Skip to content

Commit 977a300

Browse files
author
Al Viro
committed
alpha: fix FEN fault handling
Type 3 instruction fault (FPU insn with FPU disabled) is handled by quietly enabling FPU and returning. Which is fine, except that we need to do that both for fault in userland and in the kernel; the latter *can* legitimately happen - all it takes is this: .global _start _start: call_pal 0xae lda $0, 0 ldq $0, 0($0) - call_pal CLRFEN to clear "FPU enabled" flag and arrange for a signal delivery (SIGSEGV in this case). Fixed by moving the handling of type 3 into the common part of do_entIF(), before we check for kernel vs. user mode. Incidentally, the check for kernel mode is unidiomatic; the normal way to do that is !user_mode(regs). The difference is that the open-coded variant treats any of bits 63..3 of regs->ps being set as "it's user mode" while the normal approach is to check just the bit 3. PS is a 4-bit register and regs->ps always will have bits 63..4 clear, so the open-coded variant here is actually equivalent to !user_mode(regs). Harder to follow, though... Cc: [email protected] Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent b7bfaa7 commit 977a300

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

arch/alpha/kernel/traps.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,21 @@ do_entIF(unsigned long type, struct pt_regs *regs)
233233
{
234234
int signo, code;
235235

236-
if ((regs->ps & ~IPL_MAX) == 0) {
236+
if (type == 3) { /* FEN fault */
237+
/* Irritating users can call PAL_clrfen to disable the
238+
FPU for the process. The kernel will then trap in
239+
do_switch_stack and undo_switch_stack when we try
240+
to save and restore the FP registers.
241+
242+
Given that GCC by default generates code that uses the
243+
FP registers, PAL_clrfen is not useful except for DoS
244+
attacks. So turn the bleeding FPU back on and be done
245+
with it. */
246+
current_thread_info()->pcb.flags |= 1;
247+
__reload_thread(&current_thread_info()->pcb);
248+
return;
249+
}
250+
if (!user_mode(regs)) {
237251
if (type == 1) {
238252
const unsigned int *data
239253
= (const unsigned int *) regs->pc;
@@ -366,20 +380,6 @@ do_entIF(unsigned long type, struct pt_regs *regs)
366380
}
367381
break;
368382

369-
case 3: /* FEN fault */
370-
/* Irritating users can call PAL_clrfen to disable the
371-
FPU for the process. The kernel will then trap in
372-
do_switch_stack and undo_switch_stack when we try
373-
to save and restore the FP registers.
374-
375-
Given that GCC by default generates code that uses the
376-
FP registers, PAL_clrfen is not useful except for DoS
377-
attacks. So turn the bleeding FPU back on and be done
378-
with it. */
379-
current_thread_info()->pcb.flags |= 1;
380-
__reload_thread(&current_thread_info()->pcb);
381-
return;
382-
383383
case 5: /* illoc */
384384
default: /* unexpected instruction-fault type */
385385
;

0 commit comments

Comments
 (0)