linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Tom Lendacky <thomas.lendacky@amd.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	David Woodhouse <dwmw@amazon.co.uk>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Rik van Riel <riel@redhat.com>, Andi Kleen <ak@linux.intel.com>,
	Paul Turner <pjt@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Jiri Kosina <jikos@kernel.org>,
	Dave Hansen <dave.hansen@intel.com>,
	Andy Lutomirski <luto@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Kees Cook <keescook@google.com>,
	Greg Kroah-Hartman <gregkh@linux-foundation.org>
Subject: [PATCH 4.4 30/53] x86/retpoline: Add LFENCE to the retpoline/RSB filling RSB macros
Date: Mon, 22 Jan 2018 09:40:22 +0100	[thread overview]
Message-ID: <20180122083911.629117807@linuxfoundation.org> (raw)
In-Reply-To: <20180122083910.299610926@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Tom Lendacky <thomas.lendacky@amd.com>

commit 28d437d550e1e39f805d99f9f8ac399c778827b7 upstream.

The PAUSE instruction is currently used in the retpoline and RSB filling
macros as a speculation trap.  The use of PAUSE was originally suggested
because it showed a very, very small difference in the amount of
cycles/time used to execute the retpoline as compared to LFENCE.  On AMD,
the PAUSE instruction is not a serializing instruction, so the pause/jmp
loop will use excess power as it is speculated over waiting for return
to mispredict to the correct target.

The RSB filling macro is applicable to AMD, and, if software is unable to
verify that LFENCE is serializing on AMD (possible when running under a
hypervisor), the generic retpoline support will be used and, so, is also
applicable to AMD.  Keep the current usage of PAUSE for Intel, but add an
LFENCE instruction to the speculation trap for AMD.

The same sequence has been adopted by GCC for the GCC generated retpolines.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Borislav Petkov <bp@alien8.de>
Acked-by: David Woodhouse <dwmw@amazon.co.uk>
Acked-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linux-foundation.org>
Cc: Kees Cook <keescook@google.com>
Link: https://lkml.kernel.org/r/20180113232730.31060.36287.stgit@tlendack-t1.amdoffice.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/x86/include/asm/nospec-branch.h |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -11,7 +11,7 @@
  * Fill the CPU return stack buffer.
  *
  * Each entry in the RSB, if used for a speculative 'ret', contains an
- * infinite 'pause; jmp' loop to capture speculative execution.
+ * infinite 'pause; lfence; jmp' loop to capture speculative execution.
  *
  * This is required in various cases for retpoline and IBRS-based
  * mitigations for the Spectre variant 2 vulnerability. Sometimes to
@@ -38,11 +38,13 @@
 	call	772f;				\
 773:	/* speculation trap */			\
 	pause;					\
+	lfence;					\
 	jmp	773b;				\
 772:						\
 	call	774f;				\
 775:	/* speculation trap */			\
 	pause;					\
+	lfence;					\
 	jmp	775b;				\
 774:						\
 	dec	reg;				\
@@ -60,6 +62,7 @@
 	call	.Ldo_rop_\@
 .Lspec_trap_\@:
 	pause
+	lfence
 	jmp	.Lspec_trap_\@
 .Ldo_rop_\@:
 	mov	\reg, (%_ASM_SP)
@@ -142,6 +145,7 @@
 	"       .align 16\n"					\
 	"901:	call   903f;\n"					\
 	"902:	pause;\n"					\
+	"    	lfence;\n"					\
 	"       jmp    902b;\n"					\
 	"       .align 16\n"					\
 	"903:	addl   $4, %%esp;\n"				\

  parent reply	other threads:[~2018-01-22  8:40 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22  8:39 [PATCH 4.4 00/53] 4.4.113-stable review Greg Kroah-Hartman
2018-01-22  8:39 ` [PATCH 4.4 01/53] gcov: disable for COMPILE_TEST Greg Kroah-Hartman
2018-01-22  8:39 ` [PATCH 4.4 02/53] x86/cpu/AMD: Make LFENCE a serializing instruction Greg Kroah-Hartman
2018-01-22  8:39 ` [PATCH 4.4 03/53] x86/cpu/AMD: Use LFENCE_RDTSC in preference to MFENCE_RDTSC Greg Kroah-Hartman
2018-01-22  8:39 ` [PATCH 4.4 04/53] x86/mm/32: Move setup_clear_cpu_cap(X86_FEATURE_PCID) earlier Greg Kroah-Hartman
2018-01-22  8:39 ` [PATCH 4.4 05/53] x86/asm: Use register variable to get stack pointer value Greg Kroah-Hartman
2018-02-06 21:59   ` Matthias Kaehlcke
2018-02-06 22:37     ` Greg Kroah-Hartman
2018-02-06 22:48       ` Matthias Kaehlcke
2018-02-06 22:52         ` Greg Kroah-Hartman
2018-01-22  8:39 ` [PATCH 4.4 06/53] x86/kbuild: enable modversions for symbols exported from asm Greg Kroah-Hartman
2018-01-22  8:39 ` [PATCH 4.4 07/53] x86/asm: Make asm/alternative.h safe from assembly Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 08/53] EXPORT_SYMBOL() for asm Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 09/53] kconfig.h: use __is_defined() to check if MODULE is defined Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 10/53] x86/retpoline: Add initial retpoline support Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 11/53] x86/spectre: Add boot time option to select Spectre v2 mitigation Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 12/53] x86/retpoline/crypto: Convert crypto assembler indirect jumps Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 13/53] x86/retpoline/entry: Convert entry " Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 14/53] x86/retpoline/ftrace: Convert ftrace " Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 15/53] x86/retpoline/hyperv: Convert " Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 16/53] x86/retpoline/xen: Convert Xen hypercall " Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 17/53] x86/retpoline/checksum32: Convert assembler " Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 18/53] x86/retpoline/irq32: " Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 19/53] x86/retpoline: Fill return stack buffer on vmexit Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 20/53] x86/retpoline: Remove compile time warning Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 21/53] scsi: sg: disable SET_FORCE_LOW_DMA Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 22/53] futex: Prevent overflow by strengthen input validation Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 23/53] ALSA: pcm: Remove yet superfluous WARN_ON() Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 24/53] ALSA: hda - Apply headphone noise quirk for another Dell XPS 13 variant Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 25/53] ALSA: hda - Apply the existing quirk to iMac 14,1 Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 26/53] af_key: fix buffer overread in verify_address_len() Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 27/53] af_key: fix buffer overread in parse_exthdrs() Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 28/53] scsi: hpsa: fix volume offline state Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 29/53] sched/deadline: Zero out positive runtime after throttling constrained tasks Greg Kroah-Hartman
2018-01-22  8:40 ` Greg Kroah-Hartman [this message]
2018-01-22  8:40 ` [PATCH 4.4 31/53] module: Add retpoline tag to VERMAGIC Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 32/53] pipe: avoid round_pipe_size() nr_pages overflow on 32-bit Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 33/53] x86/apic/vector: Fix off by one in error path Greg Kroah-Hartman
2018-02-16 20:57   ` Ben Hutchings
2018-02-17 13:34     ` Thomas Gleixner
2018-02-28 16:49       ` Thomas Gleixner
2018-01-22  8:40 ` [PATCH 4.4 34/53] Input: 88pm860x-ts - fix child-node lookup Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 35/53] Input: twl6040-vibra - fix DT node memory management Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 36/53] Input: twl6040-vibra - fix child-node lookup Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 37/53] Input: twl4030-vibra - fix sibling-node lookup Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 38/53] tracing: Fix converting enums from the map in trace_event_eval_update() Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 39/53] phy: work around phys references to usb-nop-xceiv devices Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 40/53] ARM: dts: kirkwood: fix pin-muxing of MPP7 on OpenBlocks A7 Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 41/53] can: peak: fix potential bug in packet fragmentation Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 42/53] libata: apply MAX_SEC_1024 to all LITEON EP1 series devices Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 43/53] dm btree: fix serious bug in btree_split_beneath() Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 44/53] dm thin metadata: THIN_MAX_CONCURRENT_LOCKS should be 6 Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 45/53] arm64: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 46/53] x86/cpu, x86/pti: Do not enable PTI on AMD processors Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 47/53] kbuild: modversions for EXPORT_SYMBOL() for asm Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 48/53] x86/mce: Make machine check speculation protected Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 49/53] retpoline: Introduce start/end markers of indirect thunk Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 50/53] kprobes/x86: Blacklist indirect thunk functions for kprobes Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 51/53] kprobes/x86: Disable optimizing on the function jumps to indirect thunk Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 52/53] x86/pti: Document fix wrong index Greg Kroah-Hartman
2018-01-22  8:40 ` [PATCH 4.4 53/53] x86/retpoline: Optimize inline assembler for vmexit_fill_RSB Greg Kroah-Hartman
2018-01-22 13:09 ` [PATCH 4.4 00/53] 4.4.113-stable review Nathan Chancellor
2018-01-22 14:20   ` Greg Kroah-Hartman
2018-01-22 19:08 ` Guenter Roeck
2018-01-22 19:49 ` Naresh Kamboju
2018-01-23  6:39   ` Greg Kroah-Hartman
2018-01-23  6:55     ` Sumit Semwal
2018-01-22 20:07 ` Shuah Khan
2018-01-23  6:37   ` Greg Kroah-Hartman
2018-01-22 23:48 ` kernelci.org bot

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=20180122083911.629117807@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ak@linux.intel.com \
    --cc=arjan@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gregkh@linux-foundation.org \
    --cc=jikos@kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=riel@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=tim.c.chen@linux.intel.com \
    --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).