Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752875AbbBXAiA (ORCPT ); Mon, 23 Feb 2015 19:38:00 -0500 Received: from mail-qg0-f43.google.com ([209.85.192.43]:60216 "EHLO mail-qg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752562AbbBXAh6 (ORCPT ); Mon, 23 Feb 2015 19:37:58 -0500 MIME-Version: 1.0 In-Reply-To: <1424736744-13414-2-git-send-email-dvlasenk@redhat.com> References: <1424736744-13414-1-git-send-email-dvlasenk@redhat.com> <1424736744-13414-2-git-send-email-dvlasenk@redhat.com> From: Andy Lutomirski Date: Mon, 23 Feb 2015 16:37:37 -0800 Message-ID: Subject: Re: [PATCH 2/6] x86: entry_64.S: move save_paranoid and ret_from_fork closer to their users To: Denys Vlasenko Cc: Linus Torvalds , Oleg Nesterov , Borislav Petkov , "H. Peter Anvin" , Frederic Weisbecker , X86 ML , Alexei Starovoitov , Will Drewry , Kees Cook , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5079 Lines: 171 On Mon, Feb 23, 2015 at 4:12 PM, Denys Vlasenko wrote: > For some odd reason, these two functions are at the very top of the file. > save_paranoid's caller is approximately in the middle of it, move it there. > Move ret_from_fork to be right after fork/exec helpers. > > This is a pure block move, nothing is changed in the function bodies. Applied. > > Signed-off-by: Denys Vlasenko > CC: Linus Torvalds > CC: Oleg Nesterov > CC: Borislav Petkov > CC: "H. Peter Anvin" > CC: Andy Lutomirski > CC: Frederic Weisbecker > CC: X86 ML > CC: Alexei Starovoitov > CC: Will Drewry > CC: Kees Cook > CC: linux-kernel@vger.kernel.org > --- > arch/x86/kernel/entry_64.S | 106 ++++++++++++++++++++++----------------------- > 1 file changed, 53 insertions(+), 53 deletions(-) > > diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S > index 63e7ccd..71b549a 100644 > --- a/arch/x86/kernel/entry_64.S > +++ b/arch/x86/kernel/entry_64.S > @@ -202,59 +202,6 @@ ENDPROC(native_usergs_sysret64) > CFI_REL_OFFSET r15, R15+\offset > .endm > > -ENTRY(save_paranoid) > - XCPT_FRAME 1 RDI+8 > - cld > - SAVE_C_REGS 8 > - SAVE_EXTRA_REGS 8 > - movl $1,%ebx > - movl $MSR_GS_BASE,%ecx > - rdmsr > - testl %edx,%edx > - js 1f /* negative -> in kernel */ > - SWAPGS > - xorl %ebx,%ebx > -1: ret > - CFI_ENDPROC > -END(save_paranoid) > - > -/* > - * A newly forked process directly context switches into this address. > - * > - * rdi: prev task we switched from > - */ > -ENTRY(ret_from_fork) > - DEFAULT_FRAME > - > - LOCK ; btr $TIF_FORK,TI_flags(%r8) > - > - pushq_cfi $0x0002 > - popfq_cfi # reset kernel eflags > - > - call schedule_tail # rdi: 'prev' task parameter > - > - GET_THREAD_INFO(%rcx) > - > - RESTORE_EXTRA_REGS > - > - testl $3,CS(%rsp) # from kernel_thread? > - jz 1f > - > - testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET > - jnz int_ret_from_sys_call > - > - RESTORE_TOP_OF_STACK %rdi > - jmp ret_from_sys_call # go to the SYSRET fastpath > - > -1: > - movq %rbp, %rdi > - call *%rbx > - movl $0, RAX(%rsp) > - RESTORE_EXTRA_REGS > - jmp int_ret_from_sys_call > - CFI_ENDPROC > -END(ret_from_fork) > - > /* > * 64bit SYSCALL instruction entry. Up to 6 arguments in registers. > * > @@ -581,6 +528,43 @@ END(stub_x32_execveat) > #endif > > /* > + * A newly forked process directly context switches into this address. > + * > + * rdi: prev task we switched from > + */ > +ENTRY(ret_from_fork) > + DEFAULT_FRAME > + > + LOCK ; btr $TIF_FORK,TI_flags(%r8) > + > + pushq_cfi $0x0002 > + popfq_cfi # reset kernel eflags > + > + call schedule_tail # rdi: 'prev' task parameter > + > + GET_THREAD_INFO(%rcx) > + > + RESTORE_EXTRA_REGS > + > + testl $3,CS(%rsp) # from kernel_thread? > + jz 1f > + > + testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET > + jnz int_ret_from_sys_call > + > + RESTORE_TOP_OF_STACK %rdi > + jmp ret_from_sys_call # go to the SYSRET fastpath > + > +1: > + movq %rbp, %rdi > + call *%rbx > + movl $0, RAX(%rsp) > + RESTORE_EXTRA_REGS > + jmp int_ret_from_sys_call > + CFI_ENDPROC > +END(ret_from_fork) > + > +/* > * Build the entry stubs and pointer table with some assembler magic. > * We pack 7 stubs into a single 32-byte chunk, which will fit in a > * single cache line on all modern x86 implementations. > @@ -1269,6 +1253,22 @@ idtentry async_page_fault do_async_page_fault has_error_code=1 > idtentry machine_check has_error_code=0 paranoid=1 do_sym=*machine_check_vector(%rip) > #endif > > +ENTRY(save_paranoid) > + XCPT_FRAME 1 RDI+8 > + cld > + SAVE_C_REGS 8 > + SAVE_EXTRA_REGS 8 > + movl $1,%ebx > + movl $MSR_GS_BASE,%ecx > + rdmsr > + testl %edx,%edx > + js 1f /* negative -> in kernel */ > + SWAPGS > + xorl %ebx,%ebx > +1: ret > + CFI_ENDPROC > +END(save_paranoid) > + > /* > * "Paranoid" exit path from exception stack. This is invoked > * only on return from non-NMI IST interrupts that came > -- > 1.8.1.4 > -- Andy Lutomirski AMA Capital Management, LLC -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/