From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: ACJfBovv2iiICqtSbDUwllZcqzoYPBvhnJ9o1WPhVmA7Z9E/R0SlNvVmwJu77J/r3iO7Kpx7+ncc ARC-Seal: i=1; a=rsa-sha256; t=1516229624; cv=none; d=google.com; s=arc-20160816; b=U4PlmdMj5DJ6XXHxip1S4VeOS+6NCfqn+ypFPkL6g/ar0zR/u92HV85zySlLszZuLS jyRJmn3Pt7qpe3m6vBteUJD7K0u/Dr0UJnOwqNaXLXN6a2OzUVPyXwxaj8jX8elSh6Wj heTtBOVzQepC0xwu3GmVZvVDN35Pp4TK8yutC+2CTkDEpOwoEc0v8gL3FuF2BNKSqSeS K5CTACH3kE49si7prdqkCtla1j812I2+gS/h2uze5iLmBRyVdGOwB0cIvhcVbtVmpx0x 7iEtsGP69URwSQv3Ku/vXEtObNWYe9oiqyeyVerC7tItihS1eJoQxAZNlPQ3mRGZFUN9 naDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=VuiD1l1HHcOItUqyDzLLB8RGS/T1WaEUi13VymSIUiM=; b=Zns++gS0cUtsfhvd0WBBmonNyp2bDAnWjtGcAgvU4GyfqWvxKBX+w7V4Mlik2DY95o BcY3o46gC9/8L1QezRYX3M/btYfpq3DZwPHNt9zoFzsjmqY/EtyNVFK+EpoQ+hmbKjXX EmxPbHr+NSL4c90Mp0PhMuPTLkVuGqZN5rieQ5fzIBTaBzWqZn5SgU/tNPbKskPgtPwb gHRIPAv3MMOjGG9Db2n519J298eTNiMvJtpr8TmwUJTcbrteTNfYml6tgrNVLN7gyP2y pobdUvraOyajLqfN9zhmeMTC5Uz0VK41ba4bS7esM/prNm0JD6iC6DpHpvfXPAPQqjXb aEgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of ak@linux.intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=ak@linux.intel.com Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of ak@linux.intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=ak@linux.intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,374,1511856000"; d="scan'208";a="10562615" From: Andi Kleen 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 Subject: [PATCH] x86/retpoline: Optimize inline assembler for vmexit_fill_RSB Date: Wed, 17 Jan 2018 14:53:28 -0800 Message-Id: <20180117225328.15414-1-andi@firstfloor.org> X-Mailer: git-send-email 2.14.3 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1589881994332121770?= X-GMAIL-MSGID: =?utf-8?q?1589881994332121770?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: From: Andi Kleen 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 --- 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