Skip to contentSkip to conversation

2.6.10-rc3, i386: fpu handling on sigreturn

DISCUSSION Andi Kleen 2 participants 5 messages Dec 22, 2004 – Dec 23, 2004 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Andi Kleen

author
#1 lore raw
Quoted 2 lines · Bodo Stroesser

Now, the interrupted processes fpu no longer is cleared!

I agree it's a bug, although it's probably pretty obscure so people didn't notice it. The right fix would be to just clear_fpu again in this case. The problem has been in Linux forever.

Here's an untested patch for i386 and x86-64.

-Andi

arch/i386/kernel/signal.c renamed from arch/i386/kernel/signal.c-o +2 -1
diff -u linux-2.6.10rc2-time/arch/i386/kernel/signal.c-o linux-2.6.10rc2-time/arch/i386/kernel/signal.c
@@ -190,7 +190,8 @@
 			if (verify_area(VERIFY_READ, buf, sizeof(*buf)))
 				goto badframe;
 			err |= restore_i387(buf);
-		}
+		} else if (current->used_math) 
+			clear_fpu(current); 
 	}
 
 	err |= __get_user(*peax, &sc->eax);
arch/x86_64/kernel/signal.c renamed from arch/x86_64/kernel/signal.c-o +2 -1
diff -u linux-2.6.10rc2-time/arch/x86_64/kernel/signal.c-o linux-2.6.10rc2-time/arch/x86_64/kernel/signal.c
@@ -125,7 +125,8 @@
 			if (verify_area(VERIFY_READ, buf, sizeof(*buf)))
 				goto badframe;
 			err |= restore_i387(buf);
-		}
+		} else if (current->used_math) 
+			clear_fpu(current); 
 	}
 
 	err |= __get_user(*prax, &sc->rax);
arch/x86_64/ia32/ia32_signal.c renamed from arch/x86_64/ia32/ia32_signal.c-o +2 -1
diff -u linux-2.6.10rc2-time/arch/x86_64/ia32/ia32_signal.c-o linux-2.6.10rc2-time/arch/x86_64/ia32/ia32_signal.c
@@ -261,7 +261,8 @@
 			if (verify_area(VERIFY_READ, buf, sizeof(*buf)))
 				goto badframe;
 			err |= restore_i387_ia32(current, buf, 0);
-		}
+		} else if (current->used_math) 
+			clear_fpu(current); 
 	}
 
 	{ 
#2 lore raw
Quoted 8 lines · Andi Kleen
Quoted 1 line · Bodo Stroesser

Now, the interrupted processes fpu no longer is cleared!

I agree it's a bug, although it's probably pretty obscure so people didn't notice it. The right fix would be to just clear_fpu again in this case. The problem has been in Linux forever.

Wouldn't it be better to also reset used_math to 0? (As it has been, before the sighandler was started)

Bodo

Quoted 4 lines

Here's an untested patch for i386 and x86-64.

-Andi

author
#3 lore raw
Quoted 11 lines · Bodo Stroesser
Quoted 8 lines · Andi Kleen
Quoted 1 line · Bodo Stroesser

Now, the interrupted processes fpu no longer is cleared!

I agree it's a bug, although it's probably pretty obscure so people didn't notice it. The right fix would be to just clear_fpu again in this case. The problem has been in Linux forever.

Wouldn't it be better to also reset used_math to 0? (As it has been, before the sighandler was started)

It would only be an optimization, and i doubt it's worth to optimize for such an obscure case.

-Andi

#4 lore raw
Quoted 14 lines · Andi Kleen
Quoted 12 lines · Bodo Stroesser
Quoted 9 lines · Andi Kleen
Quoted 1 line · Bodo Stroesser

Now, the interrupted processes fpu no longer is cleared!

I agree it's a bug, although it's probably pretty obscure so people didn't notice it. The right fix would be to just clear_fpu again in this case. The problem has been in Linux forever.

Quoted 7 lines
Quoted 2 lines

Wouldn't it be better to also reset used_math to 0? (As it has been, before the sighandler was started)

It would only be an optimization, and i doubt it's worth to optimize for such an obscure case.

-Andi

Sorry, I don't agree. AFAICS, if used_math isn't reset, on the next attempt of the process to use the fpu, it will be reloaded with the values, that come from the sighandler and that still reside in thread.i387. Thus, clear_cpu() without resetting used_math has no effect to the userspace task.
Resetting current->used_math to 0 would make math_state_restore() calling init_fpu(), that clears thread.i387 before the fpu is loaded.

Bodo

author
#5 lore raw
Quoted 7 lines

Sorry, I don't agree. AFAICS, if used_math isn't reset, on the next attempt of the process to use the fpu, it will be reloaded with the values, that come from the sighandler and that still reside in thread.i387. Thus, clear_cpu() without resetting used_math has no effect to the userspace task.
Resetting current->used_math to 0 would make math_state_restore() calling init_fpu(), that clears thread.i387 before the fpu is loaded.

Ok I agree. I revised the patch here.

-Andi