linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Lazy FPU restoration / moving kernel_fpu_end() to context switch
@ 2018-06-15 13:11 Jason A. Donenfeld
  2018-06-15 16:25 ` Thomas Gleixner
  2018-06-15 18:31 ` Andy Lutomirski
  0 siblings, 2 replies; 23+ messages in thread
From: Jason A. Donenfeld @ 2018-06-15 13:11 UTC (permalink / raw)
  To: LKML, X86 ML, Andy Lutomirski

Hi Andy & folks,

Lots of crypto routines look like this:

kernel_fpu_begin();
encrypt();
kernel_fpu_end();

If you call such a routine twice, you get:

kernel_fpu_begin();
encrypt();
kernel_fpu_end();
kernel_fpu_begin();
encrypt();
kernel_fpu_end();

In a loop this looks like:

for (thing) {
  kernel_fpu_begin();
  encrypt(thing);
  kernel_fpu_end();
}

This is obviously very bad, because begin() and end() are slow, so
WireGuard does the obvious:

kernel_fpu_begin();
for (thing)
  encrypt(thing);
kernel_fpu_end();

This is fine and well, and the crypto API I'm working on will enable
this to be done in a clear way, but I do wonder if maybe this is not
something that should be happening at the level of the caller, but
rather in the fpu functions themselves. Namely, what are your thoughts
on modifying kernel_fpu_end() so that it doesn't actually restore the
state, but just reenables preemption and marks that on the next
context switch, the state should be restored? Then, essentially,
kernel_fpu_begin() and end() become free after the first usage of
kernel_fpu_begin().

Is this something feasible? I know that performance-wise, I'm really
gaining a lot from hoisting those functions out of the loops, and API
wise, it'd be slightly simpler to implement if I didn't have to all
for that hoisting.

Regards,
Jason

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2018-07-11 20:10 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-15 13:11 Lazy FPU restoration / moving kernel_fpu_end() to context switch Jason A. Donenfeld
2018-06-15 16:25 ` Thomas Gleixner
2018-06-15 18:33   ` Brian Gerst
2018-06-15 19:34   ` Peter Zijlstra
2018-06-15 20:30     ` Jason A. Donenfeld
2018-06-18  9:44       ` Peter Zijlstra
2018-06-18 15:25         ` Jason A. Donenfeld
2018-06-15 18:31 ` Andy Lutomirski
2018-06-15 18:40   ` Rik van Riel
2018-06-15 18:41   ` Dave Hansen
2018-06-15 18:49     ` Andy Lutomirski
2018-06-15 18:48   ` Dave Hansen
2018-06-15 18:53     ` Andy Lutomirski
2018-06-15 20:27       ` Jason A. Donenfeld
2018-06-15 20:48         ` Jason A. Donenfeld
2018-06-19 11:43       ` David Laight
2018-06-19 13:08         ` Thomas Gleixner
2018-06-15 20:33   ` Jason A. Donenfeld
2018-06-15 20:42     ` Dave Hansen
2018-06-15 20:52       ` Andy Lutomirski
2018-06-15 20:56       ` Rik van Riel
2018-07-11 16:28     ` Sebastian Andrzej Siewior
2018-07-11 20:10       ` Rik van Riel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).