public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC/HACK] x86: Fast return to kernel
@ 2014-05-02 19:04 Andy Lutomirski
  2014-05-02 19:31 ` Linus Torvalds
  0 siblings, 1 reply; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-02 19:04 UTC (permalink / raw)
  To: linux-kernel, x86, H. Peter Anvin, Linus Torvalds; +Cc: Andy Lutomirski

This speeds up my kernel_pf microbenchmark by about 17%.  The cfi
annotations need some work.

Signed-off-by: Andy Lutomirski <luto@amacapital.net>
---

My test case is here:

https://gitorious.org/linux-test-utils/linux-clock-tests/source/kernel_pf.c

This could have some other interesting benefits.  For example, pages faults
that happen during an NMI might not re-enable NMIs.

 arch/x86/kernel/entry_64.S | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 1e96c36..922a057 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -1033,9 +1033,24 @@ retint_swapgs:		/* return to user-space */
 retint_restore_args:	/* return to kernel space */
 	DISABLE_INTERRUPTS(CLBR_ANY)
 	/*
-	 * The iretq could re-enable interrupts:
+	 * The popfq could re-enable interrupts:
 	 */
 	TRACE_IRQS_IRETQ
+
+	/* Fast return to kernel. */
+	movq RSP-ARGOFFSET(%rsp), %rsi
+	subq $16, %rsi
+	movq EFLAGS-ARGOFFSET(%rsp), %rdi
+	movq %rdi, (%rsi)
+	movq RIP-ARGOFFSET(%rsp), %rdi
+	movq %rdi, 8(%rsi)
+	movq %rsi, RIP-ARGOFFSET(%rsp)
+	RESTORE_ARGS 1,8,1
+	popq %rsp
+	popfq
+	/* Interrupts are still off because of the one-insn grace period. */
+	retq
+
 restore_args:
 	RESTORE_ARGS 1,8,1
 
-- 
1.9.0


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

end of thread, other threads:[~2014-05-04 23:49 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-02 19:04 [RFC/HACK] x86: Fast return to kernel Andy Lutomirski
2014-05-02 19:31 ` Linus Torvalds
2014-05-02 19:50   ` Andy Lutomirski
2014-05-04 18:40     ` Ingo Molnar
2014-05-04 19:59       ` H. Peter Anvin
2014-05-04 21:31         ` Linus Torvalds
2014-05-04 22:01           ` H. Peter Anvin
2014-05-02 19:51   ` Linus Torvalds
2014-05-02 20:07     ` H. Peter Anvin
2014-05-02 20:30     ` Thomas Gleixner
2014-05-02 21:01       ` Linus Torvalds
2014-05-02 21:04         ` Andy Lutomirski
2014-05-02 21:07           ` Linus Torvalds
2014-05-02 21:37             ` H. Peter Anvin
2014-05-02 21:42               ` Andy Lutomirski
2014-05-02 21:44                 ` H. Peter Anvin
2014-05-02 21:28         ` Thomas Gleixner
2014-05-04 23:46     ` Paolo Bonzini
2014-05-04 23:49       ` H. Peter Anvin
2014-05-02 20:19   ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox