Where in Linux would you look to find out what registers are saved on a context switch? I’m wondering, for example, if it is safe to use FP or vector registers in kernel-mode driver code (mostly interested in x86-64 and ARM, but I’m hoping for an architecture-independent answer).
Share
Since no one seems to have answered this, let me venture.
Take a look at the _math_restore_cpu and __unlazy_fpu methods.
You can find them here:
The x86 like processors have separate instructions for saving (fnsave) and restore (frstor) FPU state and so it looks like the OS is burdened with saving/restoring them.
I presume unless the FPU unit has been used by the usermode process, linux context switch will not save it for you.
So you need to do it yourself (in your driver) to be sure. You can use kernel_fpu_begin/end to do it in your driver, but is generally not a good idea.
Why it is not a good idea? From Linus himself: http://lkml.indiana.edu/hypermail/linux/kernel/0405.3/1620.html
Quoted:
In any case, do you really want to rely on Intel’s floating point unit? http://en.wikipedia.org/wiki/Pentium_FDIV_bug (just kidding :-)).