Skip to contentSkip to conversation

FP emulator patch

DISCUSSION Kevin D. Kissell 4 participants 13 messages Aug 16, 2001 MIPS

lore
Share & tools
lore
#0 lore raw

As I wrote last night, it looks to me as if FPU context management in signals was broken in all versions and proposed patches that I've seen. The way I see it is this:

If the current thread "owns" the FPU, we need to save the FPU state in the sigcontext and restore it on return. If the signal handler uses floating point, it already has the FPU, and can do what it wants with it. If it doesn't use the FPU, then we'll save and restore FPU state for nothing, but better safe than sorry. In either case, the current thread retains ownership of the FPU. There is no reason to muck with the ownership data or the Cp0.Status.CU1 enables, apart from the questionable bit of enabling it before the FP context save in case it wasn't enabled. I think that should go away, but I don't have time to test exhastively. In any case, CU1 should have it's pre-signal state going into the signal handler.

If the current thread does *not* own the FPU, we don't need to save the thread FP state. If the signal handler does no FP, so much the better, there's nothing to
be done. If the signal handler uses FP, it will acquire
the FPU by normal means. The FP context will be saved into the thread context of the previous owner, the signalling thread will acquire the FPU, and the signal handler will do it's FP. On return from the signal, we *must* de-allocate the FPU and clear the CU1 bit. If that's done, and the thread (which had not *owned* the FPU prior to the signal) starts doing FP again, normal mechanisms will cause it's FP context to be restored. If we don't, it will start exectuing with a bogus FP context.

The code I sketched last night is essentially correct, though it used a macro that doesn't exist. I attach a patch relative to the current OSS repository's signal.c. The patch includes the stack frame tweak for the FPU emulator that was part of previous patches, but which is orthogonal to the problem under discussion. I have built a kernel using this code and run 20 simultaneous copies of the MontaVista "stressor" program with no problems (though I also had the "v1.5" FPU emulator code).

Regards,

Kevin K.

Index: signal.c
===================================================================
RCS file: /cvs/linux/arch/mips/kernel/signal.c,v retrieving revision 1.36

signal.c +22 -5
diff -u -p -r1.36 signal.c
@@ -221,7 +221,13 @@ restore_sigcontext(struct pt_regs *regs,
 	err |= __get_user(owned_fp, &sc->sc_ownedfp);
 	if (owned_fp) {
 		err |= restore_fp_context(sc);
-		last_task_used_math = current;
+	} else {
+		if (current == last_task_used_math) {
+		/* Signal handler acquired FPU - give it back */
+			last_task_used_math = NULL;
+			current->used_math = 0;
+			regs->cp0_status &= ~ST0_CU1;
+		}
 	}
 
 	return err;
@@ -326,6 +332,7 @@ setup_sigcontext(struct pt_regs *regs, s
 	int owned_fp;
 	int err = 0;
 	u64 reg;
+	u32 tstat;
 
 	err |= __put_user(regs->cp0_epc, &sc->sc_pc);
 	err |= __put_user(regs->cp0_status, &sc->sc_status);
@@ -353,12 +360,12 @@ setup_sigcontext(struct pt_regs *regs, s
 	owned_fp = (current == last_task_used_math);
 	err |= __put_user(owned_fp, &sc->sc_ownedfp);
 
-	if (current->used_math) {	/* fp is active.  */
+	if (owned_fp) {	/* fp is active.  */
+		tstat = regs->cp0_status;
+		/* This enable should not really be necessary */
 		set_cp0_status(ST0_CU1);
 		err |= save_fp_context(sc);
-		last_task_used_math = NULL;
-		regs->cp0_status &= ~ST0_CU1;
-		current->used_math = 0;
+		regs->cp0_status = tstat;
 	}
 
 	return err;
@@ -374,6 +381,16 @@ get_sigframe(struct k_sigaction *ka, str
 
 	/* Default to using normal stack */
 	sp = regs->regs[29];
+
+#ifdef CONFIG_MIPS_FPU_EMULATOR
+	/*
+	 * FPU emulator may have it's own trampoline active just
+	 * above the user stack, 16-bytes before the next lowest
+	 * 16 byte boundary.  Try to avoid trashing it.
+	 */
+	sp -= 32;	/* 32 ought to be enough, but... */
+
+#endif /* CONFIG_MIPS_FPU_EMULATOR */
 
 	/* This is the X/Open sanctioned signal stack switching.  */
 	if ((ka->sa.sa_flags & SA_ONSTACK) && ! on_sig_stack(sp))
#1 lore raw
Quoted 29 lines · Kevin D. Kissell

As I wrote last night, it looks to me as if FPU context management in signals was broken in all versions and proposed patches that I've seen. The way I see it is this:

If the current thread "owns" the FPU, we need to save the FPU state in the sigcontext and restore it on return. If the signal handler uses floating point, it already has the FPU, and can do what it wants with it. If it doesn't use the FPU, then we'll save and restore FPU state for nothing, but better safe than sorry. In either case, the current thread retains ownership of the FPU. There is no reason to muck with the ownership data or the Cp0.Status.CU1 enables, apart from the questionable bit of enabling it before the FP context save in case it wasn't enabled. I think that should go away, but I don't have time to test exhastively. In any case, CU1 should have it's pre-signal state going into the signal handler.

If the current thread does *not* own the FPU, we don't need to save the thread FP state. If the signal handler does no FP, so much the better, there's nothing to
be done. If the signal handler uses FP, it will acquire the FPU by normal means. The FP context will be saved into the thread context of the previous owner, the signalling thread will acquire the FPU, and the signal handler will do it's FP. On return from the signal, we *must* de-allocate the
FPU and clear the CU1 bit. If that's done, and the thread (which had not *owned* the FPU prior to the signal) starts doing FP again, normal mechanisms will cause it's FP context to be restored. If we don't, it will start exectuing with a bogus FP context.

Quoted 10 lines

The code I sketched last night is essentially correct, though it used a macro that doesn't exist. I attach a patch relative to the current OSS repository's signal.c. The patch includes the stack frame tweak for the FPU emulator that was part of previous patches, but which is orthogonal to the problem under discussion. I have built a kernel using this code and run 20 simultaneous copies of the MontaVista "stressor" program with no problems (though I also had the "v1.5" FPU emulator code).

I've lost track of all the patches now :-) Can I trouble you to create a complete patch of your arch/mips/math-emu, and whatever other files you've modifed, against Ralf's tree?

Pete

#2 lore raw
In reply to Kevin D. Kissell
Quoted 4 lines · Kevin D. Kissell

As I wrote last night, it looks to me as if FPU context management in signals was broken in all versions and proposed patches that I've seen. The way I see it is this:

Quoted 14 lines

If the current thread "owns" the FPU, we need to save the FPU state in the sigcontext and restore it on return. If the signal handler uses floating point, it already has the FPU, and can do what it wants with it. If it doesn't use the FPU, then we'll save and restore FPU state for nothing, but better safe than sorry. In either case, the current thread retains ownership of the FPU. There is no reason to muck with the ownership data or the Cp0.Status.CU1 enables, apart from the questionable bit of enabling it before the FP context save in case it wasn't enabled. I think that should go away, but I don't have time to test exhastively. In any case, CU1 should have it's pre-signal state going into the signal handler.

This bit sounds fine to me.

Quoted 5 lines

If the current thread does *not* own the FPU, we don't need to save the thread FP state. If the signal handler does no FP, so much the better, there's nothing to
be done. If the signal handler uses FP, it will acquire
the FPU by normal means. The FP context will be saved

Quoted 8 lines

into the thread context of the previous owner, the signalling thread will acquire the FPU, and the signal handler will do it's FP. On return from the signal, we *must* de-allocate the FPU and clear the CU1 bit. If that's done, and the thread (which had not *owned* the FPU prior to the signal) starts doing FP again, normal mechanisms will cause it's FP context to be restored. If we don't, it will start exectuing with a bogus FP context.

No, this is wrong.

- Current thread has an FPU state saved but does not own the FPU.
- Signal handler uses FP
- Acquires FP through a lazy switch
- (FPU) Context switch occurs while in signal handler.

Where do we put the state now? We save it in the process's thread structure, of course. Overwriting what was there.

If the process has ever used math, the sigcontext must contain a saved FP state.

current->used_math should never be set to zero in this sort of situation. It's not an ownership flag! It marks whether the FP state in the thread structure is valid.

Signature · 2 lines
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer
#3 lore raw
Quoted 44 lines · Daniel Jacobowitz
Quoted 4 lines · Kevin D. Kissell

As I wrote last night, it looks to me as if FPU context management in signals was broken in all versions and proposed patches that I've seen. The way I see it is this:

Quoted 14 lines

If the current thread "owns" the FPU, we need to save the FPU state in the sigcontext and restore it on return. If the signal handler uses floating point, it already has the FPU, and can do what it wants with it. If it doesn't use the FPU, then we'll save and restore FPU state for nothing, but better safe than sorry. In either case, the current thread retains ownership of the FPU. There is no reason to muck with the ownership data or the Cp0.Status.CU1 enables, apart from the questionable bit of enabling it before the FP context save in case it wasn't enabled. I think that should go away, but I don't have time to test exhastively. In any case, CU1 should have it's pre-signal state going into the signal handler.

This bit sounds fine to me.

Quoted 5 lines

If the current thread does *not* own the FPU, we don't need to save the thread FP state. If the signal handler does no FP, so much the better, there's nothing to
be done. If the signal handler uses FP, it will acquire
the FPU by normal means. The FP context will be saved

Quoted 8 lines

into the thread context of the previous owner, the signalling thread will acquire the FPU, and the signal handler will do it's FP. On return from the signal, we *must* de-allocate the FPU and clear the CU1 bit. If that's done, and the thread (which had not *owned* the FPU prior to the signal) starts doing FP again, normal mechanisms will cause it's FP context to be restored. If we don't, it will start exectuing with a bogus FP context.

No, this is wrong.

- Current thread has an FPU state saved but does not own the FPU.
- Signal handler uses FP
- Acquires FP through a lazy switch
- (FPU) Context switch occurs while in signal handler.

Quoted 6 lines

Where do we put the state now? We save it in the process's thread structure, of course. Overwriting what was there.

If the process has ever used math, the sigcontext must contain a saved FP state.

We discovered this bug a while back. The right fix is to copy FP state from thread structure to signal stack *when* the current thread used FPU BUT not own it right now.

Quoted 4 lines

current->used_math should never be set to zero in this sort of situation. It's not an ownership flag! It marks whether the FP state in the thread structure is valid.

Daniel, it is funny that I agree with your last statement but cannot agree with your first one.

Under the above mentioned situation, after we make the copy of FPU state from thread structure to the saved signal context, we need to set used_math bit to zero. This way when the signal handler uses FPU for the first time - if it ever uses it -, the normal lazy FPU switch mechanism can kick in smoothly.

Jun

Jun

#4 lore raw
Quoted 8 lines
Quoted 3 lines

current->used_math should never be set to zero in this sort of situation. It's not an ownership flag! It marks whether the FP state in the thread structure is valid.

Daniel, it is funny that I agree with your last statement but cannot agree with your first one.

Under the above mentioned situation, after we make the copy of FPU state

from

Quoted 1 line

thread structure to the saved signal context, we need to set used_math bit

to

Quoted 1 line

zero. This way when the signal handler uses FPU for the first time - if

it

Quoted 1 line

ever uses it -, the normal lazy FPU switch mechanism can kick in smoothly.

We've had a lot of messages crossing here, but please explain yourself here why clearing used_math helps in this case. If, as has been proposed, the current thread does not own the FPU, and thus CU1 is not enabled, the FPU switch mechanism should kick in during the signal handler regardless. The signal handler will inherit the thread's FPU state from the thread context, and will muck with it, but if, as has been noted, the sigcontext has been loaded from the thread context before the handler is dispatched, and is restored after the handler executes, we're fine. The only thing I can see that clearing used_math would achieve would be to guarantee the signal handler a virgin FPU context.

Regards,

Kevin K.

#5 lore raw
Quoted 16 lines · Kevin D. Kissell
Quoted 9 lines
Quoted 4 lines

current->used_math should never be set to zero in this sort of situation. It's not an ownership flag! It marks whether the FP state in the thread structure is valid.

Daniel, it is funny that I agree with your last statement but cannot agree with your first one.

Under the above mentioned situation, after we make the copy of FPU state

from

Quoted 1 line

thread structure to the saved signal context, we need to set used_math bit

to

Quoted 1 line

zero. This way when the signal handler uses FPU for the first time - if

it

Quoted 1 line

ever uses it -, the normal lazy FPU switch mechanism can kick in smoothly.

Quoted 16 lines

We've had a lot of messages crossing here, but please explain yourself here why clearing used_math helps in this case. If, as has been proposed, the current thread does not own the FPU, and thus CU1 is not enabled, the FPU switch mechanism should kick in during the signal handler regardless. The signal handler will inherit the thread's FPU state from the thread context, and will muck with it, but if, as has been noted, the sigcontext has been loaded from the thread context before the handler is dispatched, and is restored after the handler executes, we're fine. The only thing I can see that clearing used_math would achieve would be to guarantee the signal handler a virgin FPU context.

Yes, that is somewhat the purpose. Essentially we want to see, at the beginning of a signal handler execution, the process appears to have not used FPU at all.

This requirement might be a must, because whether clearing current->used_math bit determine which patch we will take in the do_cpu(), when signal handler uses FPU for the first time. See the code below.

        if (current->used_math) {               /* Using the FPU again.  */
                lazy_fpu_switch(last_task_used_math);
        } else {                                /* First time FPU user.  */
                init_fpu();
                current->used_math = 1;
        }
        last_task_used_math = current;

Clearly the second path is logically the correct one.

BTW, do I see another bug here in do_cpu()? It seems that before we call init_fpu(), we should check last_task_used_math. If it is not NULL, we should save the FP state to the last_task_used_math. Hmm, strange ...

Jun

#6 lore raw
Quoted 16 lines
Quoted 7 lines

We've had a lot of messages crossing here, but please explain yourself here why clearing used_math helps in this case. If, as has been proposed, the current thread does not own the FPU, and thus CU1 is not enabled, the FPU switch mechanism should kick in during the signal handler regardless. The signal handler will inherit the thread's FPU state from

Quoted 8 lines

the thread context, and will muck with it, but if, as has been noted, the sigcontext has been loaded from the thread context before the handler is dispatched, and is restored after the handler executes, we're fine. The only thing I can see that clearing used_math would achieve would be to guarantee the signal handler a virgin FPU context.

Quoted 2 lines

Yes, that is somewhat the purpose. Essentially we want to see, at the beginning of a signal handler execution, the process appears to have not

used

Quoted 3 lines

FPU at all.

This requirement might be a must, because whether clearing

current->used_math

Quoted 1 line

bit determine which patch we will take in the do_cpu(), when signal

handler

Quoted 3 lines

uses FPU for the first time. See the code below.

        if (current->used_math) {               /* Using the FPU again.

*/

Quoted 2 lines
                lazy_fpu_switch(last_task_used_math);
        } else {                                /* First time FPU user.

*/

Quoted 6 lines
                init_fpu();
                current->used_math = 1;
        }
        last_task_used_math = current;

Clearly the second path is logically the correct one.

Not really. See below.

Quoted 2 lines

BTW, do I see another bug here in do_cpu()? It seems that before we call init_fpu(), we should check last_task_used_math. If it is not NULL, we

should

Quoted 1 line

save the FP state to the last_task_used_math. Hmm, strange ...

Strange indeed. And note that if the code were correct, your surmise about the init_fpu() path being "logically the correct" one would no longer be true - we'd be saving the FPU state of the current process for no good reason.

The more I look at the FPU management code, the more I marvel that it even gives an appearance of working...

Regards,

Kevin K.

#7 lore raw

<cut>

Quoted 7 lines

Strange indeed. And note that if the code were correct, your surmise about the init_fpu() path being "logically the correct" one would no longer be true - we'd be saving the FPU state of the current process for no good reason.

The more I look at the FPU management code, the more I marvel that it even gives an appearance of working...

Maybe no one has stress tested it enough up till now. As soon as we put he mips boards in QA we found a few fpu problems immediately. I hope those were it and we weren't just scratching the surface.

Pete

#8 lore raw
In reply to Jun Sun
Quoted 3 lines · Jun Sun

Yes, that is somewhat the purpose. Essentially we want to see, at the beginning of a signal handler execution, the process appears to have not used FPU at all.

Why?

Quoted 12 lines

This requirement might be a must, because whether clearing current->used_math bit determine which patch we will take in the do_cpu(), when signal handler uses FPU for the first time. See the code below.

        if (current->used_math) {               /* Using the FPU again.  */
                lazy_fpu_switch(last_task_used_math);
        } else {                                /* First time FPU user.  */
                init_fpu();
                current->used_math = 1;
        }
        last_task_used_math = current;
Quoted 1 line

Clearly the second path is logically the correct one.

Not really. Why should it get a clean set of FP registers? I think the CORRECT thing would actually be for it to have the app's FP registers. Changes should not propogate back to the app, that's all.

Quoted 3 lines

BTW, do I see another bug here in do_cpu()? It seems that before we call init_fpu(), we should check last_task_used_math. If it is not NULL, we should save the FP state to the last_task_used_math. Hmm, strange ...

I thought I got all of these... <sigh>

Signature · 2 lines
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer
#9 lore raw
Quoted 20 lines · Daniel Jacobowitz
Quoted 3 lines · Jun Sun

Yes, that is somewhat the purpose. Essentially we want to see, at the beginning of a signal handler execution, the process appears to have not used FPU at all.

Why?

Quoted 12 lines

This requirement might be a must, because whether clearing current->used_math bit determine which patch we will take in the do_cpu(), when signal handler uses FPU for the first time. See the code below.

        if (current->used_math) {               /* Using the FPU again.  */
                lazy_fpu_switch(last_task_used_math);
        } else {                                /* First time FPU user.  */
                init_fpu();
                current->used_math = 1;
        }
        last_task_used_math = current;
Quoted 6 lines
Quoted 1 line

Clearly the second path is logically the correct one.

Not really. Why should it get a clean set of FP registers? I think the CORRECT thing would actually be for it to have the app's FP registers. Changes should not propogate back to the app, that's all.

Ah, it seems I need to defend an "obvious" point. :-)

I am from the school which view signal handler as an interrupt context to a normal process. (In fact, some OSes implement signal handling by using a separate thread/process). Under this view, it is natural to provide a fresh new context when a signal handler starts.

In other words, I am thinking in the following semantics: a signal handler starting execution is equivalent to another process starting execution with the same address space, except that the original process won't resume until the "signal handler process" exits.

Thinking from that, I feel we should clear the current->used_math bit.

I think it is not correct for signal handler to inherit the FPU registers. If it wants to check the register values when the signal happens, it should do so by examing the signal context.

Apparently a well code signal handler does not depend on whether we clear current->used_math bit or not, because it should always set a FPU register before it uses it.

Jun

Quoted 9 lines
Quoted 3 lines

BTW, do I see another bug here in do_cpu()? It seems that before we call init_fpu(), we should check last_task_used_math. If it is not NULL, we should save the FP state to the last_task_used_math. Hmm, strange ...

I thought I got all of these... <sigh>

--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer

#10 lore raw
In reply to Daniel Jacobowitz
Quoted 1 line
Quoted 1 line
        if (current->used_math) {               /* Using the FPU again.

*/

Quoted 2 lines
Quoted 2 lines
                lazy_fpu_switch(last_task_used_math);
        } else {                                /* First time FPU user.

*/

Quoted 5 lines
Quoted 5 lines
                init_fpu();
                current->used_math = 1;
        }
        last_task_used_math = current;

...

Quoted 1 line
Quoted 1 line

BTW, do I see another bug here in do_cpu()? It seems that before we

call

Quoted 1 line
Quoted 1 line

init_fpu(), we should check last_task_used_math. If it is not NULL, we

should

Quoted 3 lines
Quoted 1 line

save the FP state to the last_task_used_math. Hmm, strange ...

I thought I got all of these... <sigh>

Looks like that should be:

           } else {
                if (last_task_used_math != NULL)
save_fp(last_task_used_math);
                init_fpu()
                current->used_math = 1;
            }

And things will be OK. What's wierd is that I could have sworn that I looked at this code long ago, and that there was a save there. But even in the 2.2.12-based tree, there is none.

It's quite late here in France. If one (or more) of you guys could sketch a code fragment that would copy FP context back and forth between a thread structure and a sigcontext without passing through the FPU while I'm sleeping, I'll put together an integrated patch tomorrow.

Regards,

Kevin K.

#11 lore raw
In reply to Kevin D. Kissell
Quoted 5 lines

If the current thread does *not* own the FPU, we don't need to save the thread FP state. If the signal handler does no FP, so much the better, there's nothing to
be done. If the signal handler uses FP, it will acquire
the FPU by normal means. The FP context will be saved

Quoted 8 lines

into the thread context of the previous owner, the signalling thread will acquire the FPU, and the signal handler will do it's FP. On return from the signal, we *must* de-allocate the FPU and clear the CU1 bit. If that's done, and the thread (which had not *owned* the FPU prior to the signal) starts doing FP again, normal mechanisms will cause it's FP context to be restored. If we don't, it will start exectuing with a bogus FP context.

There is, actually, one conceptual hole in this scheme (and in every other one we've seen) if the following scenario occurs. The current thread does not own the FPU, the signal handler executes FP instructions and runs for so long that it gets switched out. The thread's FP state will then become that of the signal handler, and, since the thread didn't have the FPU when the signal context was set up, it the pre-signal state will be lost.

Quoted 1 line

From that standpoint, the old code that saved the

contex if current->used_math was almost correct. Almost correct, because the naive dump-the-FPU
code is correct only if the FPU belongs to the thread. If it doesn't, the last saved thead FPU context, and not the FPU contents, needs to be copied into the signal context. Symmetrically, in restore_sigcontext(), the current code restores the FPU if we *owned* the fp prior to the signal, but we must likewise restore the thread FPU context from the sigcontext if we *didn't* own the FPU, but the signal handler subsequently acquired it.

The alternative to doing direct sigcontext<->thread context saves/restores without passing through the FPU would be to force a fpu context switch on every signal dispatch, which I find rather inelegant.

I'll see if I can't come up with a new patch that also takes this into account, but may not have time before I take off on vacation this weekend...

Kevin K.

#12 lore raw
Quoted 42 lines · Kevin D. Kissell
Quoted 14 lines

If the current thread does *not* own the FPU, we don't need to save the thread FP state. If the signal handler does no FP, so much the better, there's nothing to
be done. If the signal handler uses FP, it will acquire
the FPU by normal means. The FP context will be saved into the thread context of the previous owner, the signalling thread will acquire the FPU, and the signal handler will do it's FP. On return from the signal, we *must* de-allocate the FPU and clear the CU1 bit. If that's done, and the thread (which had not *owned* the FPU prior to the signal) starts doing FP again, normal mechanisms will cause it's FP context to be restored. If we don't, it will start exectuing with a bogus FP context.

There is, actually, one conceptual hole in this scheme (and in every other one we've seen) if the following scenario occurs. The current thread does not own the FPU, the signal handler executes FP instructions and runs for so long that it gets switched out. The thread's FP state will then become that of the signal handler, and, since the thread didn't have the FPU when the signal context was set up, it the pre-signal state will be lost.

From that standpoint, the old code that saved the contex if current->used_math was almost correct. Almost correct, because the naive dump-the-FPU
code is correct only if the FPU belongs to the thread. If it doesn't, the last saved thead FPU context, and not the FPU contents, needs to be copied into the signal context. Symmetrically, in restore_sigcontext(), the current code restores the FPU if we *owned* the fp prior to the signal, but we must likewise restore the thread FPU context from the sigcontext if we *didn't* own the FPU, but the signal handler subsequently acquired it.

The alternative to doing direct sigcontext<->thread context saves/restores without passing through the FPU would be to force a fpu context switch on every signal dispatch, which I find rather inelegant.

Quoted 5 lines

I'll see if I can't come up with a new patch that also takes this into account, but may not have time before I take off on vacation this weekend...

Kevin K.

Kevin,

The following pseudo code should take care of that bug.

setup_sigcontext():

...

if (owned_fp) ASSERT(current->used_math); /* my assumption, obvious */

err |= __put_user(owned_fp, &sc->sc_ownedfp); err |= __put_user(current->used_math, &sc->sc_used_math);

if (owned_math) {
	/* save current FP state to signal context */
	current->used_math = 0;
	/* perhaps some other bits need to be modified etc */
} else if (current->used_math) {
	/* copy FP state from thread structure to signal context */
	current->used_math = 0;
	/* perhaps some other bits need to be modified etc */
}

....

restore_context():

..
__get_user(owned_fp, &sc->sc_ownedfp); __get_user(&current->used_math, &sc->sc_used_math);

if (owned_fp) ASSERT(current->used_math); /* my assumption, obvious */

if (owned_fp) {
	restore_fp_context(sc);
	last_task_used_math = current;
} else if (current->used_math) {
	/* copy FP state from signal context to thread structure */
}

(I meant to do that myself, of course, but yeah, yeah, ... :-0)

Jun