linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/retpoline: Optimize inline assembler for vmexit_fill_RSB
@ 2018-01-17 22:53 Andi Kleen
  2018-01-18 12:41 ` David Woodhouse
  2018-01-19 15:49 ` [tip:x86/pti] " tip-bot for Andi Kleen
  0 siblings, 2 replies; 3+ messages in thread
From: Andi Kleen @ 2018-01-17 22:53 UTC (permalink / raw)
  To: tglx; +Cc: dwmw, linux-kernel, gregkh, torvalds, arjan, dave.hansen, Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

I was looking at the generated assembler for the C fill RSB
inline asm operations, and noticed several issues:

- The C code sets up the loop register, which
is then immediately overwritten in __FILL_RETURN_BUFFER
with the same value again.

- The C code also passes in the iteration count
in another register, which is not used at all.

Remove these two unnecessary operations. Just rely on
the single constant passed to the macro for the iterations.

This eliminates several instructions and avoids unnecessarily
clobbering a register.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/include/asm/nospec-branch.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 1e170fd3dc51..fed8703a28b9 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -204,15 +204,15 @@ enum spectre_v2_mitigation {
 static inline void vmexit_fill_RSB(void)
 {
 #ifdef CONFIG_RETPOLINE
-	unsigned long loops = RSB_CLEAR_LOOPS / 2;
+	unsigned long loops;
 
 	asm volatile (ANNOTATE_NOSPEC_ALTERNATIVE
 		      ALTERNATIVE("jmp 910f",
 				  __stringify(__FILL_RETURN_BUFFER(%0, RSB_CLEAR_LOOPS, %1)),
 				  X86_FEATURE_RETPOLINE)
 		      "910:"
-		      : "=&r" (loops), ASM_CALL_CONSTRAINT
-		      : "r" (loops) : "memory" );
+		      : "=r" (loops), ASM_CALL_CONSTRAINT
+		      : : "memory" );
 #endif
 }
 
-- 
2.14.3

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

end of thread, other threads:[~2018-01-19 15:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-17 22:53 [PATCH] x86/retpoline: Optimize inline assembler for vmexit_fill_RSB Andi Kleen
2018-01-18 12:41 ` David Woodhouse
2018-01-19 15:49 ` [tip:x86/pti] " tip-bot for Andi Kleen

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).