aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2018-02-11 05:49:45 -0500
committerIngo Molnar <mingo@kernel.org>2018-02-13 03:04:53 -0500
commit3f01daecd545e818098d84fd1ad43e19a508d705 (patch)
treed70e4a362d5c8c41ef771107726a8e0ff4972d69
parentf7bafa2b05ef25eda1d9179fd930b0330cf2b7d1 (diff)
x86/entry/64: Introduce the PUSH_AND_CLEAN_REGS macro
Those instances where ALLOC_PT_GPREGS_ON_STACK is called just before SAVE_AND_CLEAR_REGS can trivially be replaced by PUSH_AND_CLEAN_REGS. This macro uses PUSH instead of MOV and should therefore be faster, at least on newer CPUs. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: dan.j.williams@intel.com Link: http://lkml.kernel.org/r/20180211104949.12992-5-linux@dominikbrodowski.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/entry/calling.h36
-rw-r--r--arch/x86/entry/entry_64.S6
2 files changed, 38 insertions, 4 deletions
diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index a05cbb81268d..57b1b87a04f0 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -137,6 +137,42 @@ For 32-bit we have the following conventions - kernel is built with
137 UNWIND_HINT_REGS offset=\offset 137 UNWIND_HINT_REGS offset=\offset
138 .endm 138 .endm
139 139
140 .macro PUSH_AND_CLEAR_REGS
141 /*
142 * Push registers and sanitize registers of values that a
143 * speculation attack might otherwise want to exploit. The
144 * lower registers are likely clobbered well before they
145 * could be put to use in a speculative execution gadget.
146 * Interleave XOR with PUSH for better uop scheduling:
147 */
148 pushq %rdi /* pt_regs->di */
149 pushq %rsi /* pt_regs->si */
150 pushq %rdx /* pt_regs->dx */
151 pushq %rcx /* pt_regs->cx */
152 pushq %rax /* pt_regs->ax */
153 pushq %r8 /* pt_regs->r8 */
154 xorq %r8, %r8 /* nospec r8 */
155 pushq %r9 /* pt_regs->r9 */
156 xorq %r9, %r9 /* nospec r9 */
157 pushq %r10 /* pt_regs->r10 */
158 xorq %r10, %r10 /* nospec r10 */
159 pushq %r11 /* pt_regs->r11 */
160 xorq %r11, %r11 /* nospec r11*/
161 pushq %rbx /* pt_regs->rbx */
162 xorl %ebx, %ebx /* nospec rbx*/
163 pushq %rbp /* pt_regs->rbp */
164 xorl %ebp, %ebp /* nospec rbp*/
165 pushq %r12 /* pt_regs->r12 */
166 xorq %r12, %r12 /* nospec r12*/
167 pushq %r13 /* pt_regs->r13 */
168 xorq %r13, %r13 /* nospec r13*/
169 pushq %r14 /* pt_regs->r14 */
170 xorq %r14, %r14 /* nospec r14*/
171 pushq %r15 /* pt_regs->r15 */
172 xorq %r15, %r15 /* nospec r15*/
173 UNWIND_HINT_REGS
174 .endm
175
140 .macro POP_REGS pop_rdi=1 skip_r11rcx=0 176 .macro POP_REGS pop_rdi=1 skip_r11rcx=0
141 popq %r15 177 popq %r15
142 popq %r14 178 popq %r14
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 07692b44800d..cf4a9ae558f3 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -564,8 +564,7 @@ END(irq_entries_start)
564 call switch_to_thread_stack 564 call switch_to_thread_stack
5651: 5651:
566 566
567 ALLOC_PT_GPREGS_ON_STACK 567 PUSH_AND_CLEAR_REGS
568 SAVE_AND_CLEAR_REGS
569 ENCODE_FRAME_POINTER 568 ENCODE_FRAME_POINTER
570 569
571 testb $3, CS(%rsp) 570 testb $3, CS(%rsp)
@@ -1112,8 +1111,7 @@ ENTRY(xen_failsafe_callback)
1112 addq $0x30, %rsp 1111 addq $0x30, %rsp
1113 UNWIND_HINT_IRET_REGS 1112 UNWIND_HINT_IRET_REGS
1114 pushq $-1 /* orig_ax = -1 => not a system call */ 1113 pushq $-1 /* orig_ax = -1 => not a system call */
1115 ALLOC_PT_GPREGS_ON_STACK 1114 PUSH_AND_CLEAR_REGS
1116 SAVE_AND_CLEAR_REGS
1117 ENCODE_FRAME_POINTER 1115 ENCODE_FRAME_POINTER
1118 jmp error_exit 1116 jmp error_exit
1119END(xen_failsafe_callback) 1117END(xen_failsafe_callback)