diff options
author | Jan Beulich <JBeulich@suse.com> | 2011-11-29 06:17:45 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2011-12-05 11:24:41 -0500 |
commit | 46db09d3fd847f185a7d23a96bc8fe7a4be0cd05 (patch) | |
tree | 1134b3244ebe89208856c35bf86138d2b1ed791e /arch/x86 | |
parent | 39e9543344fa3179e346d2b381c6e0cd17b516de (diff) |
x86-64: Slightly shorten line system call entry and exit paths
GET_THREAD_INFO() involves a memory read immediately followed by
an "sub" on the value read, in turn (in several cases)
immediately followed by a use of the calculated value as the
base address of a memory access. This combination of
instructions has a non-negligible potential for stalls.
In the system call entry point code, however, the (fixed) offset
of the stack pointer from the end of the stack is generally
known, and hence we can instead avoid the memory load and
subtract, and instead do the memory reference using %rsp as the
base register. To do so in a legible fashion, introduce a
THREAD_INFO() macro which, provided a register (generally %rsp)
and the known offset from the end of the stack, produces a
suitable memory access operand.
The patch attempts to only touch the fast paths (no auditing and
alike), but manages to do so only in the 64-bit entry point
case; the compatibility mode entry points have so many
interdependencies between their various branch targets that it
was necessary to also adjust the slow paths to eliminate the
risk of having missed some register dependency during code
analysis.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/4ED4CD690200007800064075@nat28.tlf.novell.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86')
-rw-r--r-- | arch/x86/ia32/ia32entry.S | 36 | ||||
-rw-r--r-- | arch/x86/include/asm/thread_info.h | 6 | ||||
-rw-r--r-- | arch/x86/kernel/entry_64.S | 8 |
3 files changed, 24 insertions, 26 deletions
diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S index a6253ec1b284..0d5c279f3732 100644 --- a/arch/x86/ia32/ia32entry.S +++ b/arch/x86/ia32/ia32entry.S | |||
@@ -134,7 +134,7 @@ ENTRY(ia32_sysenter_target) | |||
134 | CFI_REL_OFFSET rsp,0 | 134 | CFI_REL_OFFSET rsp,0 |
135 | pushfq_cfi | 135 | pushfq_cfi |
136 | /*CFI_REL_OFFSET rflags,0*/ | 136 | /*CFI_REL_OFFSET rflags,0*/ |
137 | movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d | 137 | movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d |
138 | CFI_REGISTER rip,r10 | 138 | CFI_REGISTER rip,r10 |
139 | pushq_cfi $__USER32_CS | 139 | pushq_cfi $__USER32_CS |
140 | /*CFI_REL_OFFSET cs,0*/ | 140 | /*CFI_REL_OFFSET cs,0*/ |
@@ -150,9 +150,8 @@ ENTRY(ia32_sysenter_target) | |||
150 | .section __ex_table,"a" | 150 | .section __ex_table,"a" |
151 | .quad 1b,ia32_badarg | 151 | .quad 1b,ia32_badarg |
152 | .previous | 152 | .previous |
153 | GET_THREAD_INFO(%r10) | 153 | orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
154 | orl $TS_COMPAT,TI_status(%r10) | 154 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
155 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10) | ||
156 | CFI_REMEMBER_STATE | 155 | CFI_REMEMBER_STATE |
157 | jnz sysenter_tracesys | 156 | jnz sysenter_tracesys |
158 | cmpq $(IA32_NR_syscalls-1),%rax | 157 | cmpq $(IA32_NR_syscalls-1),%rax |
@@ -162,13 +161,12 @@ sysenter_do_call: | |||
162 | sysenter_dispatch: | 161 | sysenter_dispatch: |
163 | call *ia32_sys_call_table(,%rax,8) | 162 | call *ia32_sys_call_table(,%rax,8) |
164 | movq %rax,RAX-ARGOFFSET(%rsp) | 163 | movq %rax,RAX-ARGOFFSET(%rsp) |
165 | GET_THREAD_INFO(%r10) | ||
166 | DISABLE_INTERRUPTS(CLBR_NONE) | 164 | DISABLE_INTERRUPTS(CLBR_NONE) |
167 | TRACE_IRQS_OFF | 165 | TRACE_IRQS_OFF |
168 | testl $_TIF_ALLWORK_MASK,TI_flags(%r10) | 166 | testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
169 | jnz sysexit_audit | 167 | jnz sysexit_audit |
170 | sysexit_from_sys_call: | 168 | sysexit_from_sys_call: |
171 | andl $~TS_COMPAT,TI_status(%r10) | 169 | andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
172 | /* clear IF, that popfq doesn't enable interrupts early */ | 170 | /* clear IF, that popfq doesn't enable interrupts early */ |
173 | andl $~0x200,EFLAGS-R11(%rsp) | 171 | andl $~0x200,EFLAGS-R11(%rsp) |
174 | movl RIP-R11(%rsp),%edx /* User %eip */ | 172 | movl RIP-R11(%rsp),%edx /* User %eip */ |
@@ -205,7 +203,7 @@ sysexit_from_sys_call: | |||
205 | .endm | 203 | .endm |
206 | 204 | ||
207 | .macro auditsys_exit exit | 205 | .macro auditsys_exit exit |
208 | testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10) | 206 | testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
209 | jnz ia32_ret_from_sys_call | 207 | jnz ia32_ret_from_sys_call |
210 | TRACE_IRQS_ON | 208 | TRACE_IRQS_ON |
211 | sti | 209 | sti |
@@ -215,12 +213,11 @@ sysexit_from_sys_call: | |||
215 | movzbl %al,%edi /* zero-extend that into %edi */ | 213 | movzbl %al,%edi /* zero-extend that into %edi */ |
216 | inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */ | 214 | inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */ |
217 | call audit_syscall_exit | 215 | call audit_syscall_exit |
218 | GET_THREAD_INFO(%r10) | ||
219 | movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */ | 216 | movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */ |
220 | movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi | 217 | movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi |
221 | cli | 218 | cli |
222 | TRACE_IRQS_OFF | 219 | TRACE_IRQS_OFF |
223 | testl %edi,TI_flags(%r10) | 220 | testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
224 | jz \exit | 221 | jz \exit |
225 | CLEAR_RREGS -ARGOFFSET | 222 | CLEAR_RREGS -ARGOFFSET |
226 | jmp int_with_check | 223 | jmp int_with_check |
@@ -238,7 +235,7 @@ sysexit_audit: | |||
238 | 235 | ||
239 | sysenter_tracesys: | 236 | sysenter_tracesys: |
240 | #ifdef CONFIG_AUDITSYSCALL | 237 | #ifdef CONFIG_AUDITSYSCALL |
241 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10) | 238 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
242 | jz sysenter_auditsys | 239 | jz sysenter_auditsys |
243 | #endif | 240 | #endif |
244 | SAVE_REST | 241 | SAVE_REST |
@@ -309,9 +306,8 @@ ENTRY(ia32_cstar_target) | |||
309 | .section __ex_table,"a" | 306 | .section __ex_table,"a" |
310 | .quad 1b,ia32_badarg | 307 | .quad 1b,ia32_badarg |
311 | .previous | 308 | .previous |
312 | GET_THREAD_INFO(%r10) | 309 | orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
313 | orl $TS_COMPAT,TI_status(%r10) | 310 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
314 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10) | ||
315 | CFI_REMEMBER_STATE | 311 | CFI_REMEMBER_STATE |
316 | jnz cstar_tracesys | 312 | jnz cstar_tracesys |
317 | cmpq $IA32_NR_syscalls-1,%rax | 313 | cmpq $IA32_NR_syscalls-1,%rax |
@@ -321,13 +317,12 @@ cstar_do_call: | |||
321 | cstar_dispatch: | 317 | cstar_dispatch: |
322 | call *ia32_sys_call_table(,%rax,8) | 318 | call *ia32_sys_call_table(,%rax,8) |
323 | movq %rax,RAX-ARGOFFSET(%rsp) | 319 | movq %rax,RAX-ARGOFFSET(%rsp) |
324 | GET_THREAD_INFO(%r10) | ||
325 | DISABLE_INTERRUPTS(CLBR_NONE) | 320 | DISABLE_INTERRUPTS(CLBR_NONE) |
326 | TRACE_IRQS_OFF | 321 | TRACE_IRQS_OFF |
327 | testl $_TIF_ALLWORK_MASK,TI_flags(%r10) | 322 | testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
328 | jnz sysretl_audit | 323 | jnz sysretl_audit |
329 | sysretl_from_sys_call: | 324 | sysretl_from_sys_call: |
330 | andl $~TS_COMPAT,TI_status(%r10) | 325 | andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
331 | RESTORE_ARGS 0,-ARG_SKIP,0,0,0 | 326 | RESTORE_ARGS 0,-ARG_SKIP,0,0,0 |
332 | movl RIP-ARGOFFSET(%rsp),%ecx | 327 | movl RIP-ARGOFFSET(%rsp),%ecx |
333 | CFI_REGISTER rip,rcx | 328 | CFI_REGISTER rip,rcx |
@@ -355,7 +350,7 @@ sysretl_audit: | |||
355 | 350 | ||
356 | cstar_tracesys: | 351 | cstar_tracesys: |
357 | #ifdef CONFIG_AUDITSYSCALL | 352 | #ifdef CONFIG_AUDITSYSCALL |
358 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10) | 353 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
359 | jz cstar_auditsys | 354 | jz cstar_auditsys |
360 | #endif | 355 | #endif |
361 | xchgl %r9d,%ebp | 356 | xchgl %r9d,%ebp |
@@ -420,9 +415,8 @@ ENTRY(ia32_syscall) | |||
420 | /* note the registers are not zero extended to the sf. | 415 | /* note the registers are not zero extended to the sf. |
421 | this could be a problem. */ | 416 | this could be a problem. */ |
422 | SAVE_ARGS 0,1,0 | 417 | SAVE_ARGS 0,1,0 |
423 | GET_THREAD_INFO(%r10) | 418 | orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
424 | orl $TS_COMPAT,TI_status(%r10) | 419 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
425 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10) | ||
426 | jnz ia32_tracesys | 420 | jnz ia32_tracesys |
427 | cmpq $(IA32_NR_syscalls-1),%rax | 421 | cmpq $(IA32_NR_syscalls-1),%rax |
428 | ja ia32_badsys | 422 | ja ia32_badsys |
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index 25ebd792725b..185b719ec61a 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h | |||
@@ -232,6 +232,12 @@ static inline struct thread_info *current_thread_info(void) | |||
232 | movq PER_CPU_VAR(kernel_stack),reg ; \ | 232 | movq PER_CPU_VAR(kernel_stack),reg ; \ |
233 | subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg | 233 | subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg |
234 | 234 | ||
235 | /* | ||
236 | * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in | ||
237 | * a certain register (to be used in assembler memory operands). | ||
238 | */ | ||
239 | #define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg) | ||
240 | |||
235 | #endif | 241 | #endif |
236 | 242 | ||
237 | #endif /* !X86_32 */ | 243 | #endif /* !X86_32 */ |
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S index 1581f1990187..75f72a50cf26 100644 --- a/arch/x86/kernel/entry_64.S +++ b/arch/x86/kernel/entry_64.S | |||
@@ -478,8 +478,7 @@ ENTRY(system_call_after_swapgs) | |||
478 | movq %rax,ORIG_RAX-ARGOFFSET(%rsp) | 478 | movq %rax,ORIG_RAX-ARGOFFSET(%rsp) |
479 | movq %rcx,RIP-ARGOFFSET(%rsp) | 479 | movq %rcx,RIP-ARGOFFSET(%rsp) |
480 | CFI_REL_OFFSET rip,RIP-ARGOFFSET | 480 | CFI_REL_OFFSET rip,RIP-ARGOFFSET |
481 | GET_THREAD_INFO(%rcx) | 481 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
482 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx) | ||
483 | jnz tracesys | 482 | jnz tracesys |
484 | system_call_fastpath: | 483 | system_call_fastpath: |
485 | cmpq $__NR_syscall_max,%rax | 484 | cmpq $__NR_syscall_max,%rax |
@@ -496,10 +495,9 @@ ret_from_sys_call: | |||
496 | /* edi: flagmask */ | 495 | /* edi: flagmask */ |
497 | sysret_check: | 496 | sysret_check: |
498 | LOCKDEP_SYS_EXIT | 497 | LOCKDEP_SYS_EXIT |
499 | GET_THREAD_INFO(%rcx) | ||
500 | DISABLE_INTERRUPTS(CLBR_NONE) | 498 | DISABLE_INTERRUPTS(CLBR_NONE) |
501 | TRACE_IRQS_OFF | 499 | TRACE_IRQS_OFF |
502 | movl TI_flags(%rcx),%edx | 500 | movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx |
503 | andl %edi,%edx | 501 | andl %edi,%edx |
504 | jnz sysret_careful | 502 | jnz sysret_careful |
505 | CFI_REMEMBER_STATE | 503 | CFI_REMEMBER_STATE |
@@ -583,7 +581,7 @@ sysret_audit: | |||
583 | /* Do syscall tracing */ | 581 | /* Do syscall tracing */ |
584 | tracesys: | 582 | tracesys: |
585 | #ifdef CONFIG_AUDITSYSCALL | 583 | #ifdef CONFIG_AUDITSYSCALL |
586 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx) | 584 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) |
587 | jz auditsys | 585 | jz auditsys |
588 | #endif | 586 | #endif |
589 | SAVE_REST | 587 | SAVE_REST |