linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: tglx@linutronix.de
Cc: dwmw@amazon.co.uk, linux-kernel@vger.kernel.org,
	gregkh@linuxfoundation.org, torvalds@linux-foundation.org,
	arjan@linux.intel.com, dave.hansen@intel.com,
	Andi Kleen <ak@linux.intel.com>
Subject: [PATCH] x86/retpoline: Optimize inline assembler for vmexit_fill_RSB
Date: Wed, 17 Jan 2018 14:53:28 -0800	[thread overview]
Message-ID: <20180117225328.15414-1-andi@firstfloor.org> (raw)

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

             reply	other threads:[~2018-01-17 22:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-17 22:53 Andi Kleen [this message]
2018-01-18 12:41 ` [PATCH] x86/retpoline: Optimize inline assembler for vmexit_fill_RSB David Woodhouse
2018-01-19 15:49 ` [tip:x86/pti] " tip-bot for Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180117225328.15414-1-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --cc=arjan@linux.intel.com \
    --cc=dave.hansen@intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).