Subject: Re: Floating point in the kernel
To: None <eeh@one-o.com>
From: Andrei Petrov <and@genesyslab.com>
List: tech-kern
Date: 09/18/1998 15:23:49
 > Date: Fri, 18 Sep 1998 14:27:09 -0700 (PDT)
 > From: "Eduardo E. Horvath" <eeh@one-o.com>
 > cc: tech-kern@netbsd.org
 > 
 > On Fri, 18 Sep 1998, Andrei Petrov wrote:
 > 
 > > I would expect that kernel saves/restores user's FPU state so it should be
 > > safe just use FP in kernel mode assuming that you are the only part of kernel
 > > who does that. Don't know what to do with interrupts from FP in kernel mode.
 > 
 > No.
 > 
 > First of all it is not safe to do so.  Unless you know how floating pont
 > registers are managed you can cause all sorts of problems.  If the
 > registers are disabled then using them will cause a trap.  This may cause
 > the dirty contents to be stored away properly, or it may cause a panic.
 > Let's say you managed to get the registers saved off and enabled properly.
 > If you switch back to user mode with the registers enabled then you have a
 > silent user code data corruption.  If you disable the fp regs you need to
 > make sure that when user code attempts to access them again that the dirty
 > registers you created are not mistakenly written to some process' fp
 > register save area.  And then what happens if your code is pre-empted and
 > called back again?  Or someone else comes up with your brilliant idea and
 > wants to use fp code later?
 > 
 > =========================================================================
 > Eduardo Horvath				eeh@one-o.com
 > 	"I need to find a pithy new quote." -- me
 > 
 > 
I assume if you use fp in kernel you should be responsible for all what you mentioned before,
also I don't think kernel is the good place for math. One thing I wouldn't do is fp save/restore
during process context switch only; I think that safer to mark processes which use fpu and make
fp save/restore only for them, shouldn't be much overhead; then you would be more protected from lkm who wants math.
May be idea is not that brilliant but it could be fun

BTW, who is sparc64 going

---andrey